diff options
Diffstat (limited to 'src/server/api/stream/channels/messaging.ts')
| -rw-r--r-- | src/server/api/stream/channels/messaging.ts | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/src/server/api/stream/channels/messaging.ts b/src/server/api/stream/channels/messaging.ts index ce766e28e9..1e5e94c1c8 100644 --- a/src/server/api/stream/channels/messaging.ts +++ b/src/server/api/stream/channels/messaging.ts @@ -1,20 +1,39 @@ import autobind from 'autobind-decorator'; -import read from '../../common/read-messaging-message'; +import { readUserMessagingMessage, readGroupMessagingMessage } from '../../common/read-messaging-message'; import Channel from '../channel'; +import { UserGroupJoinings } from '../../../../models'; export default class extends Channel { public readonly chName = 'messaging'; public static shouldShare = false; public static requireCredential = true; - private otherpartyId: string; + private otherpartyId: string | null; + private groupId: string | null; @autobind public async init(params: any) { this.otherpartyId = params.otherparty as string; + this.groupId = params.group as string; + + // Check joining + if (this.groupId) { + const joining = await UserGroupJoinings.findOne({ + userId: this.user!.id, + userGroupId: this.groupId + }); + + if (joining == null) { + return; + } + } + + const subCh = this.otherpartyId + ? `messagingStream:${this.user!.id}-${this.otherpartyId}` + : `messagingStream:${this.groupId}`; // Subscribe messaging stream - this.subscriber.on(`messagingStream:${this.user!.id}-${this.otherpartyId}`, data => { + this.subscriber.on(subCh, data => { this.send(data); }); } @@ -23,7 +42,11 @@ export default class extends Channel { public onMessage(type: string, body: any) { switch (type) { case 'read': - read(this.user!.id, this.otherpartyId, [body.id]); + if (this.otherpartyId) { + readUserMessagingMessage(this.user!.id, this.otherpartyId, [body.id]); + } else if (this.groupId) { + readGroupMessagingMessage(this.user!.id, this.groupId, [body.id]); + } break; } } |