This commit is contained in:
syuilo
2025-03-17 15:38:18 +09:00
parent a90b3b7e67
commit 9e5fb89408
4 changed files with 74 additions and 5 deletions

View File

@@ -19,6 +19,7 @@ import { AntennaChannelService } from './channels/antenna.js';
import { DriveChannelService } from './channels/drive.js';
import { HashtagChannelService } from './channels/hashtag.js';
import { RoleTimelineChannelService } from './channels/role-timeline.js';
import { ChatChannelService } from './channels/chat.js';
import { ReversiChannelService } from './channels/reversi.js';
import { ReversiGameChannelService } from './channels/reversi-game.js';
import { type MiChannelService } from './channel.js';
@@ -40,6 +41,7 @@ export class ChannelsService {
private serverStatsChannelService: ServerStatsChannelService,
private queueStatsChannelService: QueueStatsChannelService,
private adminChannelService: AdminChannelService,
private chatChannelService: ChatChannelService,
private reversiChannelService: ReversiChannelService,
private reversiGameChannelService: ReversiGameChannelService,
) {
@@ -62,6 +64,7 @@ export class ChannelsService {
case 'serverStats': return this.serverStatsChannelService;
case 'queueStats': return this.queueStatsChannelService;
case 'admin': return this.adminChannelService;
case 'chat': return this.chatChannelService;
case 'reversi': return this.reversiChannelService;
case 'reversiGame': return this.reversiGameChannelService;

View File

@@ -0,0 +1,63 @@
/*
* SPDX-FileCopyrightText: syuilo and misskey-project
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { Injectable } from '@nestjs/common';
import { bindThis } from '@/decorators.js';
import type { GlobalEvents } from '@/core/GlobalEventService.js';
import type { JsonObject } from '@/misc/json-value.js';
import Channel, { type MiChannelService } from '../channel.js';
class ChatChannel extends Channel {
public readonly chName = 'chat';
public static shouldShare = false;
public static requireCredential = true as const;
public static kind = 'read:chat';
private otherId: string;
constructor(
id: string,
connection: Channel['connection'],
) {
super(id, connection);
}
@bindThis
public async init(params: JsonObject) {
if (typeof params.otherId !== 'string') return;
this.otherId = params.otherId;
this.subscriber.on(`chatStream:${this.user.id}-${this.otherId}`, this.onEvent);
}
@bindThis
private async onEvent(data: GlobalEvents['chat']['payload']) {
this.send(data.type, data.body);
}
@bindThis
public dispose() {
// Unsubscribe events
this.subscriber.off(`chatStream:${this.user.id}-${this.otherId}`, this.onEvent);
}
}
@Injectable()
export class ChatChannelService implements MiChannelService<true> {
public readonly shouldShare = ChatChannel.shouldShare;
public readonly requireCredential = ChatChannel.requireCredential;
public readonly kind = ChatChannel.kind;
constructor(
) {
}
@bindThis
public create(id: string, connection: Channel['connection']): ChatChannel {
return new ChatChannel(
id,
connection,
);
}
}