Update mahjong-room.ts

This commit is contained in:
syuilo 2026-01-22 11:47:25 +09:00
parent 069e48972a
commit 08969aaf60
1 changed files with 14 additions and 34 deletions

View File

@ -3,14 +3,15 @@
* SPDX-License-Identifier: AGPL-3.0-only * SPDX-License-Identifier: AGPL-3.0-only
*/ */
import { Inject, Injectable } from '@nestjs/common'; import { Inject, Injectable, Scope } from '@nestjs/common';
import { DI } from '@/di-symbols.js'; import { REQUEST } from '@nestjs/core';
import { bindThis } from '@/decorators.js'; import { bindThis } from '@/decorators.js';
import { MahjongService } from '@/core/MahjongService.js'; import { MahjongService } from '@/core/MahjongService.js';
import { GlobalEvents } from '@/core/GlobalEventService.js'; import { GlobalEvents } from '@/core/GlobalEventService.js';
import Channel, { type MiChannelService } from '../channel.js'; import Channel, { type ChannelRequest } from '../channel.js';
class MahjongRoomChannel extends Channel { @Injectable({ scope: Scope.TRANSIENT })
export class MahjongRoomChannel extends Channel {
public readonly chName = 'mahjongRoom'; public readonly chName = 'mahjongRoom';
public static shouldShare = false; public static shouldShare = false;
public static requireCredential = true as const; public static requireCredential = true as const;
@ -18,12 +19,12 @@ class MahjongRoomChannel extends Channel {
private roomId: string | null = null; private roomId: string | null = null;
constructor( constructor(
private mahjongService: MahjongService, @Inject(REQUEST)
request: ChannelRequest,
id: string, private mahjongService: MahjongService,
connection: Channel['connection'],
) { ) {
super(id, connection); super(request);
} }
@bindThis @bindThis
@ -141,7 +142,7 @@ class MahjongRoomChannel extends Channel {
this.mahjongService.commit_cii(this.roomId!, this.user, pattern); this.mahjongService.commit_cii(this.roomId!, this.user, pattern);
} }
@bindThis @bindThis
private async kan() { private async kan() {
if (this.user == null) return; if (this.user == null) return;
@ -149,11 +150,11 @@ class MahjongRoomChannel extends Channel {
} }
@bindThis @bindThis
private async ankan(tile: number) { private async ankan(tile: number) {
if (this.user == null) return; if (this.user == null) return;
this.mahjongService.commit_ankan(this.roomId!, this.user, tile); this.mahjongService.commit_ankan(this.roomId!, this.user, tile);
} }
@bindThis @bindThis
private async kakan(tile: number) { private async kakan(tile: number) {
@ -182,24 +183,3 @@ private async ankan(tile: number) {
this.subscriber.off(`mahjongRoomStream:${this.roomId}`, this.onMahjongRoomStreamMessage); this.subscriber.off(`mahjongRoomStream:${this.roomId}`, this.onMahjongRoomStreamMessage);
} }
} }
@Injectable()
export class MahjongRoomChannelService implements MiChannelService<true> {
public readonly shouldShare = MahjongRoomChannel.shouldShare;
public readonly requireCredential = MahjongRoomChannel.requireCredential;
public readonly kind = MahjongRoomChannel.kind;
constructor(
private mahjongService: MahjongService,
) {
}
@bindThis
public create(id: string, connection: Channel['connection']): MahjongRoomChannel {
return new MahjongRoomChannel(
this.mahjongService,
id,
connection,
);
}
}