diff --git a/src/__tests__/chat/chatService/addReaction.test.ts b/src/__tests__/chat/chatService/addReaction.test.ts index dfc18f0b9..c9ce919f5 100644 --- a/src/__tests__/chat/chatService/addReaction.test.ts +++ b/src/__tests__/chat/chatService/addReaction.test.ts @@ -7,6 +7,7 @@ describe('ChatService.addReaction() test suite', () => { let chatService: ChatService; const chatMessageBuilder = ChatBuilderFactory.getBuilder('ChatMessage'); const chatModel = ChatModule.getChatModel(); + const mockSenderId = '60f7c2d9a2d3c7b7e56d01df'; const senderId = new ObjectId(); const reactPlayerName = 'ReactMan420'; @@ -27,11 +28,12 @@ describe('ChatService.addReaction() test suite', () => { chat._id.toString(), reactPlayerName, '👍', + mockSenderId, ); expect(err).toBeNull(); expect(updated.reactions).toEqual([ - { playerName: reactPlayerName, emoji: '👍' }, + { playerName: reactPlayerName, emoji: '👍', sender_id: mockSenderId }, ]); }); @@ -42,11 +44,12 @@ describe('ChatService.addReaction() test suite', () => { chat._id.toString(), reactPlayerName, '😂', + mockSenderId, ); expect(err).toBeNull(); expect(updated.reactions).toEqual([ - { playerName: reactPlayerName, emoji: '😂' }, + { playerName: reactPlayerName, emoji: '😂', sender_id: mockSenderId }, ]); }); @@ -57,6 +60,7 @@ describe('ChatService.addReaction() test suite', () => { chat._id.toString(), reactPlayerName, '', + mockSenderId, ); expect(err).toBeNull(); @@ -69,6 +73,7 @@ describe('ChatService.addReaction() test suite', () => { fakeId, 'NoPlayer', '🔥', + mockSenderId, ); expect(updated).toBeNull(); diff --git a/src/__tests__/chat/data/builder/ReactionDtoBuilder.ts b/src/__tests__/chat/data/builder/ReactionDtoBuilder.ts index a3fb92007..d35b3f0fa 100644 --- a/src/__tests__/chat/data/builder/ReactionDtoBuilder.ts +++ b/src/__tests__/chat/data/builder/ReactionDtoBuilder.ts @@ -5,6 +5,7 @@ export default class ReactionDtoBuilder implements IDataBuilder { private readonly base: ReactionDto = { playerName: 'TestPlayer420', emoji: '👍', + sender_id: '60f7c2d9a2d3c7b7e56d01df', }; build(): ReactionDto { diff --git a/src/chat/dto/reaction.dto.ts b/src/chat/dto/reaction.dto.ts index 26e7b234a..3ca58b450 100644 --- a/src/chat/dto/reaction.dto.ts +++ b/src/chat/dto/reaction.dto.ts @@ -17,4 +17,11 @@ export class ReactionDto { */ @Expose() emoji: string; + + /** + * Player id of the user + * @example "123456789" + */ + @Expose() + sender_id: string; } diff --git a/src/chat/schema/reaction.schema.ts b/src/chat/schema/reaction.schema.ts index 1e7cc5387..fa2e1edf4 100644 --- a/src/chat/schema/reaction.schema.ts +++ b/src/chat/schema/reaction.schema.ts @@ -6,4 +6,7 @@ export class Reaction { @Prop({ type: String, required: true }) emoji: string; + + @Prop({ type: String, required: true }) + sender_id: string; } diff --git a/src/chat/service/baseChat.service.ts b/src/chat/service/baseChat.service.ts index 339359103..987196113 100644 --- a/src/chat/service/baseChat.service.ts +++ b/src/chat/service/baseChat.service.ts @@ -113,6 +113,7 @@ export abstract class BaseChatService { reaction.message_id, client.user.name, reaction.emoji, + client.user.playerId, ); if (error) { diff --git a/src/chat/service/chat.service.ts b/src/chat/service/chat.service.ts index 74a7d47d2..80b832bc9 100644 --- a/src/chat/service/chat.service.ts +++ b/src/chat/service/chat.service.ts @@ -1,6 +1,5 @@ import { Injectable } from '@nestjs/common'; import { InjectModel } from '@nestjs/mongoose'; -import {} from '../../common/base/decorator/AddBasicService.decorator'; import { ChatMessage } from '../schema/chatMessage.schema'; import { Model } from 'mongoose'; import BasicService from '../../common/service/basicService/BasicService'; @@ -16,6 +15,7 @@ import { SEReason } from '../../common/service/basicService/SEReason'; @Injectable() export class ChatService { + private readonly basicService: BasicService; public constructor( @InjectModel(ChatMessage.name) public readonly model: Model, @@ -23,10 +23,8 @@ export class ChatService { this.basicService = new BasicService(model); } - private readonly basicService: BasicService; - /** - * Creates a message in database. + * Creates a message in the database. * * @param message - Message data to create. * @returns Created message. @@ -38,17 +36,19 @@ export class ChatService { } /** - * Adds an reaction to chat message. + * Adds a reaction to the chat message. * * @param messageId - ID of the message reaction is to. * @param playerName - Name of the player who reacted. * @param emoji - String representation of the emoji. + * @param sender_id - Unique ID of the player reacting. * @returns Message with added reaction. */ async addReaction( messageId: string, playerName: string, emoji: string, + sender_id: string, ): Promise> { const [message, error] = await this.basicService.readOneById(messageId); @@ -59,7 +59,7 @@ export class ChatService { (r) => r.playerName !== playerName, ); - if (emoji) message.reactions.push({ playerName, emoji }); + if (emoji) message.reactions.push({ playerName, emoji, sender_id }); const [, updateError] = await this.basicService.updateOneById( message._id, @@ -72,7 +72,7 @@ export class ChatService { } /** - * Retrieves messages from database. + * Retrieves messages from the database. * * @param options - Database query options. * @returns An array of chat messages. @@ -88,7 +88,7 @@ export class ChatService { } /** - * Updates a ChatMessage by its _id in DB. The _id field is read-only and must be found from the parameter + * Updates a ChatMessage by its _id in the DB. The _id field is read-only and must be found from the parameter * * @param chat - The data needs to be updated of the ChatMessage. * @returns _true_ if ChatMessage was updated successfully, _false_ if nothing was updated for the ChatMessage,