summaryrefslogtreecommitdiff
path: root/packages/backend/src/server/api/stream/channels/messaging.ts
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2023-02-15 13:06:06 +0900
committerGitHub <noreply@github.com>2023-02-15 13:06:06 +0900
commit8f2049bcd261c3fb10afdc8c15cf4edffe1baa71 (patch)
treedc5aa1cefc24d3f6eb36bb1723d7433f8a19e5a2 /packages/backend/src/server/api/stream/channels/messaging.ts
parentMerge branch 'develop' of https://github.com/misskey-dev/misskey into develop (diff)
downloadmisskey-8f2049bcd261c3fb10afdc8c15cf4edffe1baa71.tar.gz
misskey-8f2049bcd261c3fb10afdc8c15cf4edffe1baa71.tar.bz2
misskey-8f2049bcd261c3fb10afdc8c15cf4edffe1baa71.zip
drop messaging (#9919)
* drop messaging (from backend) * wip
Diffstat (limited to 'packages/backend/src/server/api/stream/channels/messaging.ts')
-rw-r--r--packages/backend/src/server/api/stream/channels/messaging.ts159
1 files changed, 0 insertions, 159 deletions
diff --git a/packages/backend/src/server/api/stream/channels/messaging.ts b/packages/backend/src/server/api/stream/channels/messaging.ts
deleted file mode 100644
index b544e297c5..0000000000
--- a/packages/backend/src/server/api/stream/channels/messaging.ts
+++ /dev/null
@@ -1,159 +0,0 @@
-import { Inject, Injectable } from '@nestjs/common';
-import type { UserGroupJoiningsRepository, UsersRepository, MessagingMessagesRepository } from '@/models/index.js';
-import type { User, LocalUser, RemoteUser } from '@/models/entities/User.js';
-import type { UserGroup } from '@/models/entities/UserGroup.js';
-import { MessagingService } from '@/core/MessagingService.js';
-import { UserEntityService } from '@/core/entities/UserEntityService.js';
-import { DI } from '@/di-symbols.js';
-import { bindThis } from '@/decorators.js';
-import Channel from '../channel.js';
-import type { StreamMessages } from '../types.js';
-
-class MessagingChannel extends Channel {
- public readonly chName = 'messaging';
- public static shouldShare = false;
- public static requireCredential = true;
-
- private otherpartyId: string | null;
- private otherparty: User | null;
- private groupId: string | null;
- private subCh: `messagingStream:${User['id']}-${User['id']}` | `messagingStream:${UserGroup['id']}`;
- private typers: Record<User['id'], Date> = {};
- private emitTypersIntervalId: ReturnType<typeof setInterval>;
-
- constructor(
- private usersRepository: UsersRepository,
- private userGroupJoiningsRepository: UserGroupJoiningsRepository,
- private messagingMessagesRepository: MessagingMessagesRepository,
- private userEntityService: UserEntityService,
- private messagingService: MessagingService,
-
- id: string,
- connection: Channel['connection'],
- ) {
- super(id, connection);
- //this.onEvent = this.onEvent.bind(this);
- //this.onMessage = this.onMessage.bind(this);
- //this.emitTypers = this.emitTypers.bind(this);
- }
-
- @bindThis
- public async init(params: any) {
- this.otherpartyId = params.otherparty;
- this.otherparty = this.otherpartyId ? await this.usersRepository.findOneByOrFail({ id: this.otherpartyId }) : null;
- this.groupId = params.group;
-
- // Check joining
- if (this.groupId) {
- const joining = await this.userGroupJoiningsRepository.findOneBy({
- userId: this.user!.id,
- userGroupId: this.groupId,
- });
-
- if (joining == null) {
- return;
- }
- }
-
- this.emitTypersIntervalId = setInterval(this.emitTypers, 5000);
-
- this.subCh = this.otherpartyId
- ? `messagingStream:${this.user!.id}-${this.otherpartyId}`
- : `messagingStream:${this.groupId}`;
-
- // Subscribe messaging stream
- this.subscriber.on(this.subCh, this.onEvent);
- }
-
- @bindThis
- private onEvent(data: StreamMessages['messaging']['payload'] | StreamMessages['groupMessaging']['payload']) {
- if (data.type === 'typing') {
- const id = data.body;
- const begin = this.typers[id] == null;
- this.typers[id] = new Date();
- if (begin) {
- this.emitTypers();
- }
- } else {
- this.send(data);
- }
- }
-
- @bindThis
- public onMessage(type: string, body: any) {
- switch (type) {
- case 'read':
- if (this.otherpartyId) {
- this.messagingService.readUserMessagingMessage(this.user!.id, this.otherpartyId, [body.id]);
-
- // リモートユーザーからのメッセージだったら既読配信
- if (this.userEntityService.isLocalUser(this.user!) && this.userEntityService.isRemoteUser(this.otherparty!)) {
- this.messagingMessagesRepository.findOneBy({ id: body.id }).then(message => {
- if (message) this.messagingService.deliverReadActivity(this.user as LocalUser, this.otherparty as RemoteUser, message);
- });
- }
- } else if (this.groupId) {
- this.messagingService.readGroupMessagingMessage(this.user!.id, this.groupId, [body.id]);
- }
- break;
- }
- }
-
- @bindThis
- private async emitTypers() {
- const now = new Date();
-
- // Remove not typing users
- for (const [userId, date] of Object.entries(this.typers)) {
- if (now.getTime() - date.getTime() > 5000) delete this.typers[userId];
- }
-
- const users = await this.userEntityService.packMany(Object.keys(this.typers), null, { detail: false });
-
- this.send({
- type: 'typers',
- body: users,
- });
- }
-
- @bindThis
- public dispose() {
- this.subscriber.off(this.subCh, this.onEvent);
-
- clearInterval(this.emitTypersIntervalId);
- }
-}
-
-@Injectable()
-export class MessagingChannelService {
- public readonly shouldShare = MessagingChannel.shouldShare;
- public readonly requireCredential = MessagingChannel.requireCredential;
-
- constructor(
- @Inject(DI.usersRepository)
- private usersRepository: UsersRepository,
-
- @Inject(DI.userGroupJoiningsRepository)
- private userGroupJoiningsRepository: UserGroupJoiningsRepository,
-
- @Inject(DI.messagingMessagesRepository)
- private messagingMessagesRepository: MessagingMessagesRepository,
-
- private userEntityService: UserEntityService,
- private messagingService: MessagingService,
- ) {
- }
-
- @bindThis
- public create(id: string, connection: Channel['connection']): MessagingChannel {
- return new MessagingChannel(
- this.usersRepository,
- this.userGroupJoiningsRepository,
- this.messagingMessagesRepository,
- this.userEntityService,
- this.messagingService,
- id,
- connection,
- );
- }
-}