2016-12-29 07:49:51 +09:00
|
|
|
import * as mongo from 'mongodb';
|
2018-07-30 07:20:27 +09:00
|
|
|
import Xev from 'xev';
|
2016-12-29 07:49:51 +09:00
|
|
|
|
2018-07-30 07:20:27 +09:00
|
|
|
const ev = new Xev();
|
2017-11-16 23:46:36 +09:00
|
|
|
|
2018-07-30 07:20:27 +09:00
|
|
|
type ID = string | mongo.ObjectID;
|
2017-03-20 13:54:59 +09:00
|
|
|
|
2018-07-30 07:20:27 +09:00
|
|
|
function publish(channel: string, type: string, value?: any): void {
|
|
|
|
const message = type == null ? value : value == null ?
|
|
|
|
{ type: type } :
|
|
|
|
{ type: type, body: value };
|
2018-04-25 18:04:16 +09:00
|
|
|
|
2018-09-12 01:48:30 +09:00
|
|
|
ev.emit(channel, message);
|
2018-07-30 07:20:27 +09:00
|
|
|
}
|
2017-05-24 20:50:17 +09:00
|
|
|
|
2018-07-30 07:20:27 +09:00
|
|
|
export function publishUserStream(userId: ID, type: string, value?: any): void {
|
|
|
|
publish(`user-stream:${userId}`, type, typeof value === 'undefined' ? null : value);
|
|
|
|
}
|
2017-11-14 00:54:16 +09:00
|
|
|
|
2018-07-30 07:20:27 +09:00
|
|
|
export function publishDriveStream(userId: ID, type: string, value?: any): void {
|
|
|
|
publish(`drive-stream:${userId}`, type, typeof value === 'undefined' ? null : value);
|
|
|
|
}
|
2018-03-07 11:40:40 +09:00
|
|
|
|
2018-07-30 07:20:27 +09:00
|
|
|
export function publishNoteStream(noteId: ID, type: string): void {
|
2018-07-30 07:23:44 +09:00
|
|
|
publish(`note-stream:${noteId}`, null, noteId);
|
2018-07-30 07:20:27 +09:00
|
|
|
}
|
2018-03-07 17:48:32 +09:00
|
|
|
|
2018-07-30 07:20:27 +09:00
|
|
|
export function publishUserListStream(listId: ID, type: string, value?: any): void {
|
|
|
|
publish(`user-list-stream:${listId}`, type, typeof value === 'undefined' ? null : value);
|
|
|
|
}
|
2018-04-17 14:52:28 +09:00
|
|
|
|
2018-07-30 07:20:27 +09:00
|
|
|
export function publishMessagingStream(userId: ID, otherpartyId: ID, type: string, value?: any): void {
|
|
|
|
publish(`messaging-stream:${userId}-${otherpartyId}`, type, typeof value === 'undefined' ? null : value);
|
|
|
|
}
|
2018-07-11 09:36:30 +09:00
|
|
|
|
2018-07-30 07:20:27 +09:00
|
|
|
export function publishMessagingIndexStream(userId: ID, type: string, value?: any): void {
|
|
|
|
publish(`messaging-index-stream:${userId}`, type, typeof value === 'undefined' ? null : value);
|
|
|
|
}
|
2018-04-17 14:52:28 +09:00
|
|
|
|
2018-07-30 07:20:27 +09:00
|
|
|
export function publishReversiStream(userId: ID, type: string, value?: any): void {
|
|
|
|
publish(`reversi-stream:${userId}`, type, typeof value === 'undefined' ? null : value);
|
|
|
|
}
|
2017-05-24 20:50:17 +09:00
|
|
|
|
2018-07-30 07:20:27 +09:00
|
|
|
export function publishReversiGameStream(gameId: ID, type: string, value?: any): void {
|
|
|
|
publish(`reversi-game-stream:${gameId}`, type, typeof value === 'undefined' ? null : value);
|
2016-12-29 07:49:51 +09:00
|
|
|
}
|
|
|
|
|
2018-07-30 07:20:27 +09:00
|
|
|
export function publishLocalTimelineStream(note: any): void {
|
|
|
|
publish('local-timeline', null, note);
|
|
|
|
}
|
2016-12-29 07:49:51 +09:00
|
|
|
|
2018-07-30 07:20:27 +09:00
|
|
|
export function publishHybridTimelineStream(userId: ID, note: any): void {
|
|
|
|
publish(userId ? `hybrid-timeline:${userId}` : 'hybrid-timeline', null, note);
|
|
|
|
}
|
2016-12-29 07:49:51 +09:00
|
|
|
|
2018-07-30 07:20:27 +09:00
|
|
|
export function publishGlobalTimelineStream(note: any): void {
|
|
|
|
publish('global-timeline', null, note);
|
|
|
|
}
|