From e307a4c01e8bafcd5480891f68e2b6ae79df8039 Mon Sep 17 00:00:00 2001 From: cjho0316 Date: Wed, 13 Dec 2023 17:58:07 +0900 Subject: [PATCH 1/2] fix(channel): recover joinChannelRoom logic also add notice dto --- src/channels/channels.controller.ts | 14 ++++++++++++++ src/channels/channels.gateway.ts | 7 +++++-- src/channels/dto/event-message-on.dto.ts | 7 ++++++- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/channels/channels.controller.ts b/src/channels/channels.controller.ts index a30f496..1901ee0 100644 --- a/src/channels/channels.controller.ts +++ b/src/channels/channels.controller.ts @@ -70,6 +70,13 @@ export class ChannelsController { const createChannelResponseDto = await this.channelsService.createChannel(user.id, channelInfo); + if (user.channelSocketId) { + this.channelsGateway.joinChannelRoom( + createChannelResponseDto.channelId.toString(), + user.channelSocketId, + ); + } + return createChannelResponseDto; } @@ -132,6 +139,13 @@ export class ChannelsController { const channelUsersResponseDto = await this.channelsService.createChannelUser(channelUserParamDto); + + if (user.channelSocketId) { + this.channelsGateway.joinChannelRoom( + channelId.toString(), + user.channelSocketId, + ); + } return channelUsersResponseDto ; } diff --git a/src/channels/channels.gateway.ts b/src/channels/channels.gateway.ts index d1936a5..41bb968 100644 --- a/src/channels/channels.gateway.ts +++ b/src/channels/channels.gateway.ts @@ -258,11 +258,14 @@ export class ChannelsGateway const invitedUser = await this.usersRepository.findOne({ where: { id: data.invitedUserId }, }); - const invitationId = data.invitationId; + const invitationEmitDto = { + invitationId: data.invitationId, + }; + if (!invitedUser || invitedUser.status === UserStatus.OFFLINE || !invitedUser.channelSocketId) { throw WSBadRequestException('유저가 유효하지 않습니다.'); } - this.server.to(invitedUser.channelSocketId).emit('privateAlert', invitationId); + this.server.to(invitedUser.channelSocketId).emit('privateAlert', invitationEmitDto); } } diff --git a/src/channels/dto/event-message-on.dto.ts b/src/channels/dto/event-message-on.dto.ts index 26b126c..2eaedc7 100644 --- a/src/channels/dto/event-message-on.dto.ts +++ b/src/channels/dto/event-message-on.dto.ts @@ -2,11 +2,16 @@ import { IsNotEmpty, IsNumber, IsPositive, IsString } from 'class-validator'; export class EventMessageOnDto { @IsString() - @IsNotEmpty() + // @IsNotEmpty() message: string; @IsNumber() @IsPositive() @IsNotEmpty() channelId: number; + + @IsString() + @IsNotEmpty() + // 따로 리터럴이 지정되지 않으면 디폴트로 'MESSAGE'가 들어간다. + notice: 'ADMIN' | 'BAN' | 'KICK' | 'MUTE'| 'JOIN' | 'EXIT' | 'MESSAGE' = 'MESSAGE'; } From a633ffa8acb3e74f7ae2ccec1ee6069665dd0919 Mon Sep 17 00:00:00 2001 From: cjho0316 Date: Wed, 13 Dec 2023 18:10:25 +0900 Subject: [PATCH 2/2] fix(eventmsgDTO): unmask IsNotEmpty decorator --- src/channels/dto/event-message-on.dto.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/channels/dto/event-message-on.dto.ts b/src/channels/dto/event-message-on.dto.ts index 2eaedc7..6d6fef0 100644 --- a/src/channels/dto/event-message-on.dto.ts +++ b/src/channels/dto/event-message-on.dto.ts @@ -2,7 +2,7 @@ import { IsNotEmpty, IsNumber, IsPositive, IsString } from 'class-validator'; export class EventMessageOnDto { @IsString() - // @IsNotEmpty() + @IsNotEmpty() message: string; @IsNumber()