2019-02-05 14:14:23 +09:00
|
|
|
import redis from '../db/redis';
|
2019-04-07 21:50:36 +09:00
|
|
|
import { User } from '../models/entities/user';
|
|
|
|
import { Note } from '../models/entities/note';
|
|
|
|
import { UserList } from '../models/entities/user-list';
|
|
|
|
import { ReversiGame } from '../models/entities/games/reversi/game';
|
2017-03-20 13:54:59 +09:00
|
|
|
|
2018-09-12 02:48:19 +09:00
|
|
|
class Publisher {
|
2019-04-13 01:43:22 +09:00
|
|
|
private publish = (channel: string, type: string | null, value?: any): void => {
|
2018-09-12 02:48:19 +09:00
|
|
|
const message = type == null ? value : value == null ?
|
2018-10-08 01:56:36 +09:00
|
|
|
{ type: type, body: null } :
|
2018-09-12 02:48:19 +09:00
|
|
|
{ type: type, body: value };
|
2018-04-17 14:52:28 +09:00
|
|
|
|
2019-04-13 19:19:32 +09:00
|
|
|
redis.publish('misskey', JSON.stringify({
|
|
|
|
channel: channel,
|
|
|
|
message: message
|
|
|
|
}));
|
2018-09-12 02:48:19 +09:00
|
|
|
}
|
2018-07-11 09:36:30 +09:00
|
|
|
|
2019-04-07 21:50:36 +09:00
|
|
|
public publishMainStream = (userId: User['id'], type: string, value?: any): void => {
|
2018-10-07 11:06:17 +09:00
|
|
|
this.publish(`mainStream:${userId}`, type, typeof value === 'undefined' ? null : value);
|
2018-09-12 02:48:19 +09:00
|
|
|
}
|
2018-04-17 14:52:28 +09:00
|
|
|
|
2019-04-07 21:50:36 +09:00
|
|
|
public publishDriveStream = (userId: User['id'], type: string, value?: any): void => {
|
2018-10-07 11:06:17 +09:00
|
|
|
this.publish(`driveStream:${userId}`, type, typeof value === 'undefined' ? null : value);
|
2018-09-12 02:48:19 +09:00
|
|
|
}
|
2017-05-24 20:50:17 +09:00
|
|
|
|
2019-04-07 21:50:36 +09:00
|
|
|
public publishNoteStream = (noteId: Note['id'], type: string, value: any): void => {
|
2018-10-07 11:06:17 +09:00
|
|
|
this.publish(`noteStream:${noteId}`, type, {
|
|
|
|
id: noteId,
|
|
|
|
body: value
|
|
|
|
});
|
2018-09-12 02:48:19 +09:00
|
|
|
}
|
2016-12-29 07:49:51 +09:00
|
|
|
|
2019-04-07 21:50:36 +09:00
|
|
|
public publishUserListStream = (listId: UserList['id'], type: string, value?: any): void => {
|
2018-10-07 11:06:17 +09:00
|
|
|
this.publish(`userListStream:${listId}`, type, typeof value === 'undefined' ? null : value);
|
2018-09-12 02:48:19 +09:00
|
|
|
}
|
2016-12-29 07:49:51 +09:00
|
|
|
|
2019-04-07 21:50:36 +09:00
|
|
|
public publishMessagingStream = (userId: User['id'], otherpartyId: User['id'], type: string, value?: any): void => {
|
2018-10-07 11:06:17 +09:00
|
|
|
this.publish(`messagingStream:${userId}-${otherpartyId}`, type, typeof value === 'undefined' ? null : value);
|
2018-09-12 02:48:19 +09:00
|
|
|
}
|
|
|
|
|
2019-04-07 21:50:36 +09:00
|
|
|
public publishMessagingIndexStream = (userId: User['id'], type: string, value?: any): void => {
|
2018-10-07 11:06:17 +09:00
|
|
|
this.publish(`messagingIndexStream:${userId}`, type, typeof value === 'undefined' ? null : value);
|
2018-09-12 02:48:19 +09:00
|
|
|
}
|
|
|
|
|
2019-04-07 21:50:36 +09:00
|
|
|
public publishReversiStream = (userId: User['id'], type: string, value?: any): void => {
|
2018-10-07 11:06:17 +09:00
|
|
|
this.publish(`reversiStream:${userId}`, type, typeof value === 'undefined' ? null : value);
|
2018-09-12 02:48:19 +09:00
|
|
|
}
|
|
|
|
|
2019-04-07 21:50:36 +09:00
|
|
|
public publishReversiGameStream = (gameId: ReversiGame['id'], type: string, value?: any): void => {
|
2018-10-07 11:06:17 +09:00
|
|
|
this.publish(`reversiGameStream:${gameId}`, type, typeof value === 'undefined' ? null : value);
|
|
|
|
}
|
|
|
|
|
2019-04-07 21:50:36 +09:00
|
|
|
public publishNotesStream = (note: any): void => {
|
|
|
|
this.publish('notesStream', null, note);
|
2018-09-17 09:00:20 +09:00
|
|
|
}
|
2018-11-03 11:38:00 +09:00
|
|
|
|
|
|
|
public publishApLogStream = (log: any): void => {
|
|
|
|
this.publish('apLog', null, log);
|
|
|
|
}
|
2019-01-27 14:55:02 +09:00
|
|
|
|
2019-04-07 21:50:36 +09:00
|
|
|
public publishAdminStream = (userId: User['id'], type: string, value?: any): void => {
|
2019-01-27 14:55:02 +09:00
|
|
|
this.publish(`adminStream:${userId}`, type, typeof value === 'undefined' ? null : value);
|
|
|
|
}
|
2018-07-30 07:20:27 +09:00
|
|
|
}
|
2018-09-12 02:48:19 +09:00
|
|
|
|
|
|
|
const publisher = new Publisher();
|
|
|
|
|
|
|
|
export default publisher;
|
|
|
|
|
2018-10-07 11:06:17 +09:00
|
|
|
export const publishMainStream = publisher.publishMainStream;
|
2018-09-12 02:48:19 +09:00
|
|
|
export const publishDriveStream = publisher.publishDriveStream;
|
|
|
|
export const publishNoteStream = publisher.publishNoteStream;
|
2019-04-07 21:50:36 +09:00
|
|
|
export const publishNotesStream = publisher.publishNotesStream;
|
2018-09-12 02:48:19 +09:00
|
|
|
export const publishUserListStream = publisher.publishUserListStream;
|
|
|
|
export const publishMessagingStream = publisher.publishMessagingStream;
|
|
|
|
export const publishMessagingIndexStream = publisher.publishMessagingIndexStream;
|
|
|
|
export const publishReversiStream = publisher.publishReversiStream;
|
|
|
|
export const publishReversiGameStream = publisher.publishReversiGameStream;
|
2018-11-03 11:38:00 +09:00
|
|
|
export const publishApLogStream = publisher.publishApLogStream;
|
2019-01-27 14:55:02 +09:00
|
|
|
export const publishAdminStream = publisher.publishAdminStream;
|