diff --git a/src/blurting/blurting.consumer.ts b/src/blurting/blurting.consumer.ts index 37f5a4f..b789c66 100644 --- a/src/blurting/blurting.consumer.ts +++ b/src/blurting/blurting.consumer.ts @@ -10,12 +10,14 @@ import { Job, Queue } from 'bull'; import { BlurtingService } from './blurting.service'; import { BlurtingGroupEntity } from 'src/entities'; import { FcmService } from 'src/firebase/fcm.service'; +import { ChatService } from 'src/chat/chat.service'; @Processor('blurtingQuestions') export class BlurtingConsumer { constructor( private blurtingService: BlurtingService, private fcmService: FcmService, + private chatService: ChatService, @InjectQueue('blurtingQuestions') private readonly queue: Queue, ) {} @@ -35,6 +37,7 @@ export class BlurtingConsumer { ); }), ); + await this.chatService.blockWhispers(group.createdAt, users); return; } await this.blurtingService.insertQuestionToGroup( diff --git a/src/chat/chat.service.ts b/src/chat/chat.service.ts index b600d87..fa70d2d 100644 --- a/src/chat/chat.service.ts +++ b/src/chat/chat.service.ts @@ -109,6 +109,7 @@ export class ChatService { blur: 0, connected: true, connectedAt: getDateTimeOfNow(), + continued: true, }); await room.save(); @@ -328,4 +329,16 @@ export class ChatService { const otherUser = room.users.find((user) => user.userId != userId); this.fcmService.sendPush(otherUser.userId, MESSAGES.NEW_MESSAGE, 'whisper'); } + + async blockWhispers(createdAt: Date, groupUsers: number[]): Promise { + await this.roomModel.updateMany( + { + users: { + $elemMatch: { userId: { $in: groupUsers } }, + }, + connectedAt: { $gt: createdAt }, + }, + { $set: { continued: false } }, + ); + } } diff --git a/src/chat/models/room.model.ts b/src/chat/models/room.model.ts index 50f03b2..39f48cb 100644 --- a/src/chat/models/room.model.ts +++ b/src/chat/models/room.model.ts @@ -25,7 +25,6 @@ export class Room extends Document { required: true, type: String, }) - @IsNotEmpty() @IsString() id: string; @@ -42,7 +41,6 @@ export class Room extends Document { type: Boolean, default: true, }) - @IsNotEmpty() @IsBoolean() connected: boolean; @@ -53,6 +51,14 @@ export class Room extends Document { }) @IsDate() connectedAt: Date; + + @Prop({ + required: true, + type: Boolean, + default: true, + }) + @IsBoolean() + continued: boolean; } export const RoomSchema = SchemaFactory.createForClass(Room); diff --git a/src/dtos/chat.dto.ts b/src/dtos/chat.dto.ts index 4c25d7a..1452d59 100644 --- a/src/dtos/chat.dto.ts +++ b/src/dtos/chat.dto.ts @@ -116,12 +116,12 @@ export class RoomChatDto { blur: number; @IsBoolean() - @ApiProperty({ description: 'connected' }) + @ApiProperty({ description: '상대방의 신고, 나가기 등으로 연결 해제' }) connected: boolean; - @IsDate() - @ApiProperty({ description: 'point 써서 귓속말 건 시각' }) - readonly connectedAt: Date; + @IsBoolean() + @ApiProperty({ description: 'point를 써서 대화를 지속하는지 여부' }) + continued: boolean; @ValidateIf((o) => o.blurChange != null) @ApiProperty({ description: 'blur step 별 처음 바뀔 때 blur step' }) @@ -148,8 +148,10 @@ export class RoomChatDto { otherImage: othereSocketUser?.userImage ?? null, hasRead: otherUser.hasRead, blur: otherUser.blur ?? 1, - connected: othereSocketUser.isDeleted ? false : roomInfo.connected ?? true, - connectedAt: roomInfo.connectedAt ?? null, + connected: othereSocketUser.isDeleted + ? false + : roomInfo.connected ?? true, + continued: roomInfo.continued, blurChange: blurChange ?? null, chats: chattings, };