2016-12-28 16:49:51 -06:00
|
|
|
import * as mongo from 'mongodb';
|
|
|
|
import * as redis from 'redis';
|
2018-07-07 05:19:00 -05:00
|
|
|
import config from './config';
|
2016-12-28 16:49:51 -06:00
|
|
|
|
|
|
|
type ID = string | mongo.ObjectID;
|
|
|
|
|
|
|
|
class MisskeyEvent {
|
|
|
|
private redisClient: redis.RedisClient;
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
// Connect to Redis
|
|
|
|
this.redisClient = redis.createClient(
|
|
|
|
config.redis.port, config.redis.host);
|
|
|
|
}
|
|
|
|
|
2017-03-01 02:37:01 -06:00
|
|
|
public publishUserStream(userId: ID, type: string, value?: any): void {
|
2016-12-28 16:49:51 -06:00
|
|
|
this.publish(`user-stream:${userId}`, type, typeof value === 'undefined' ? null : value);
|
|
|
|
}
|
|
|
|
|
2017-11-16 08:46:36 -06:00
|
|
|
public publishDriveStream(userId: ID, type: string, value?: any): void {
|
|
|
|
this.publish(`drive-stream:${userId}`, type, typeof value === 'undefined' ? null : value);
|
|
|
|
}
|
|
|
|
|
2018-04-07 12:30:37 -05:00
|
|
|
public publishNoteStream(noteId: ID, type: string, value?: any): void {
|
|
|
|
this.publish(`note-stream:${noteId}`, type, typeof value === 'undefined' ? null : value);
|
2017-03-19 23:54:59 -05:00
|
|
|
}
|
|
|
|
|
2018-04-25 04:04:16 -05:00
|
|
|
public publishUserListStream(listId: ID, type: string, value?: any): void {
|
|
|
|
this.publish(`user-list-stream:${listId}`, type, typeof value === 'undefined' ? null : value);
|
|
|
|
}
|
|
|
|
|
2017-03-01 02:37:01 -06:00
|
|
|
public publishMessagingStream(userId: ID, otherpartyId: ID, type: string, value?: any): void {
|
2016-12-28 16:49:51 -06:00
|
|
|
this.publish(`messaging-stream:${userId}-${otherpartyId}`, type, typeof value === 'undefined' ? null : value);
|
|
|
|
}
|
2017-05-24 06:50:17 -05:00
|
|
|
|
2017-11-13 09:54:16 -06:00
|
|
|
public publishMessagingIndexStream(userId: ID, type: string, value?: any): void {
|
|
|
|
this.publish(`messaging-index-stream:${userId}`, type, typeof value === 'undefined' ? null : value);
|
|
|
|
}
|
|
|
|
|
2018-06-16 18:10:54 -05:00
|
|
|
public publishReversiStream(userId: ID, type: string, value?: any): void {
|
|
|
|
this.publish(`reversi-stream:${userId}`, type, typeof value === 'undefined' ? null : value);
|
2018-03-06 20:40:40 -06:00
|
|
|
}
|
|
|
|
|
2018-06-16 18:10:54 -05:00
|
|
|
public publishReversiGameStream(gameId: ID, type: string, value?: any): void {
|
|
|
|
this.publish(`reversi-game-stream:${gameId}`, type, typeof value === 'undefined' ? null : value);
|
2018-03-07 02:48:32 -06:00
|
|
|
}
|
|
|
|
|
2018-04-17 00:52:28 -05:00
|
|
|
public publishLocalTimelineStream(note: any): void {
|
|
|
|
this.redisClient.publish('misskey:local-timeline', JSON.stringify(note));
|
|
|
|
}
|
|
|
|
|
|
|
|
public publishGlobalTimelineStream(note: any): void {
|
|
|
|
this.redisClient.publish('misskey:global-timeline', JSON.stringify(note));
|
|
|
|
}
|
|
|
|
|
2017-05-24 06:50:17 -05:00
|
|
|
private publish(channel: string, type: string, value?: any): void {
|
|
|
|
const message = value == null ?
|
|
|
|
{ type: type } :
|
|
|
|
{ type: type, body: value };
|
|
|
|
|
|
|
|
this.redisClient.publish(`misskey:${channel}`, JSON.stringify(message));
|
|
|
|
}
|
2016-12-28 16:49:51 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
const ev = new MisskeyEvent();
|
|
|
|
|
|
|
|
export default ev.publishUserStream.bind(ev);
|
|
|
|
|
2018-04-17 00:52:28 -05:00
|
|
|
export const publishLocalTimelineStream = ev.publishLocalTimelineStream.bind(ev);
|
|
|
|
export const publishGlobalTimelineStream = ev.publishGlobalTimelineStream.bind(ev);
|
2017-11-16 08:46:36 -06:00
|
|
|
export const publishDriveStream = ev.publishDriveStream.bind(ev);
|
2018-04-25 04:04:16 -05:00
|
|
|
export const publishUserListStream = ev.publishUserListStream.bind(ev);
|
2018-04-07 12:30:37 -05:00
|
|
|
export const publishNoteStream = ev.publishNoteStream.bind(ev);
|
2016-12-28 16:49:51 -06:00
|
|
|
export const publishMessagingStream = ev.publishMessagingStream.bind(ev);
|
2017-11-13 09:54:16 -06:00
|
|
|
export const publishMessagingIndexStream = ev.publishMessagingIndexStream.bind(ev);
|
2018-06-16 18:10:54 -05:00
|
|
|
export const publishReversiStream = ev.publishReversiStream.bind(ev);
|
|
|
|
export const publishReversiGameStream = ev.publishReversiGameStream.bind(ev);
|