Skip to content

Commit

Permalink
feat: block whisper after blurting end
Browse files Browse the repository at this point in the history
  • Loading branch information
kyeahxx19 committed May 16, 2024
1 parent 2c92163 commit 4da3227
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
3 changes: 3 additions & 0 deletions src/blurting/blurting.consumer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {}

Expand All @@ -35,6 +37,7 @@ export class BlurtingConsumer {
);
}),
);
await this.chatService.blockWhispers(group.createdAt, users);
return;
}
await this.blurtingService.insertQuestionToGroup(
Expand Down
13 changes: 13 additions & 0 deletions src/chat/chat.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export class ChatService {
blur: 0,
connected: true,
connectedAt: getDateTimeOfNow(),
continued: true,
});
await room.save();

Expand Down Expand Up @@ -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<void> {
await this.roomModel.updateMany(
{
users: {
$elemMatch: { userId: { $in: groupUsers } },
},
connectedAt: { $gt: createdAt },
},
{ $set: { continued: false } },
);
}
}
10 changes: 8 additions & 2 deletions src/chat/models/room.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export class Room extends Document {
required: true,
type: String,
})
@IsNotEmpty()
@IsString()
id: string;

Expand All @@ -42,7 +41,6 @@ export class Room extends Document {
type: Boolean,
default: true,
})
@IsNotEmpty()
@IsBoolean()
connected: boolean;

Expand All @@ -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);
14 changes: 8 additions & 6 deletions src/dtos/chat.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' })
Expand All @@ -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,
};
Expand Down

0 comments on commit 4da3227

Please sign in to comment.