Skip to content

Commit 52d14c3

Browse files
authored
feat: delete message reaction socket 구현 (#206)
* fix: lastReplyAt 동작 버그 수정 * feat: message reaction delete socket 구현 * feat: limit을 10개에서 20개로 수정 magic number 수정
1 parent b0f257d commit 52d14c3

File tree

4 files changed

+37
-7
lines changed

4 files changed

+37
-7
lines changed

server/src/service/message-reaction-service.ts

+24-6
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ class MessageReactionService {
5959

6060
const createdMessageReaction = await this.messageReactionRepository.save(newMessageReaction);
6161
const customMessageReaction = this.customMessageReaction(createdMessageReaction);
62-
const displayNames = await this.addAuthorMessageReaction(customMessageReaction);
63-
return { ...customMessageReaction, displayNames };
62+
const authors = await this.addAuthorMessageReaction(customMessageReaction);
63+
return { ...customMessageReaction, authors };
6464
}
6565

6666
customMessageReaction(messageReaction) {
@@ -78,11 +78,12 @@ class MessageReactionService {
7878
.addSelect('user')
7979
.where('messageReaction.reactionId = :reactionId', { reactionId })
8080
.getMany();
81-
const displayNames = AuthorMessageReaction.map((MessageReaction) => {
82-
const { displayName } = MessageReaction.user;
83-
return displayName;
81+
const author = AuthorMessageReaction.map((MessageReaction) => {
82+
const { displayName, userId } = MessageReaction.user;
83+
return { displayName, userId };
8484
});
85-
return displayNames;
85+
86+
return author;
8687
}
8788

8889
async deleteMessageReaction(userId: number, messageId: number, reactionId: number) {
@@ -99,6 +100,23 @@ class MessageReactionService {
99100

100101
await this.messageReactionRepository.softDelete(messageReaction.messageReactionId);
101102
}
103+
104+
async getMessageReaction(messageId: number, reactionId: number) {
105+
const messageReactions = await this.messageReactionRepository
106+
.createQueryBuilder('messageReaction')
107+
.leftJoin('messageReaction.user', 'user')
108+
.select('messageReaction')
109+
.addSelect('user')
110+
.where('messageReaction.messageId = :messageId', { messageId })
111+
.andWhere('messageReaction.reactionId = :reactionId', { reactionId })
112+
.getMany();
113+
const authors = messageReactions.map((messageReaction) => {
114+
const { userId, displayName } = messageReaction.user;
115+
return { userId, displayName };
116+
});
117+
const { title, emoji } = await this.reactionRepository.findOne({ reactionId });
118+
return { reactionId, title, emoji, messageId, authors };
119+
}
102120
}
103121

104122
export default MessageReactionService;

server/src/service/reply-service.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class ReplyService {
7777
}
7878

7979
async getReplies(messageId: number, offsetId: number) {
80+
const limit = 20;
8081
let where = 'reply.messageId = :messageId';
8182
where += offsetId ? ' AND reply.replyId < :offsetId' : '';
8283
const replies = await this.replyRepository
@@ -90,7 +91,7 @@ class ReplyService {
9091
.addSelect(['replyReactions', 'user', 'reaction'])
9192
.where(where, { messageId, offsetId })
9293
.orderBy('reply.replyId', 'DESC')
93-
.take(10)
94+
.take(limit)
9495
.getMany();
9596
const formattedReplies = replies.map((reply) => {
9697
const { replyReactions } = { ...reply };

server/src/socket/event/message-reaction-event.ts

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import eventName from '@constants/event-name';
33

44
const messageReactionEvent = (io, socket) => {
55
socket.on(eventName.CREATE_REACTION, (messageReaction) => messageReactionHandler.createMessageReaction(io, socket, messageReaction));
6+
socket.on(eventName.DELETE_REACTION, (messageReaction) => messageReactionHandler.deleteMessageReaction(io, socket, messageReaction));
67
};
78

89
export default messageReactionEvent;

server/src/socket/handler/message-reaction-handler.ts

+10
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ const messageHandler = {
1010
const newMessageReaction = await MessageReactionService.getInstance().createMessageReaction(Number(userId), Number(messageId), title, emoji);
1111
const { chatroomId } = (await MessageServie.getInstance().getMessage(messageId)).chatroom;
1212
io.to(String(chatroomId)).emit(eventName.CREATE_REACTION, { ...newMessageReaction, chatroomId });
13+
},
14+
15+
async deleteMessageReaction(io, socket, messageReaction) {
16+
const req = socket.request;
17+
const { userId } = req.user;
18+
const { messageId, reactionId } = messageReaction;
19+
await MessageReactionService.getInstance().deleteMessageReaction(Number(userId), Number(messageId), Number(reactionId));
20+
const newMessageReaction = await MessageReactionService.getInstance().getMessageReaction(Number(messageId), Number(reactionId));
21+
const { chatroomId } = (await MessageServie.getInstance().getMessage(messageId)).chatroom;
22+
io.to(String(chatroomId)).emit(eventName.DELETE_REACTION, { ...newMessageReaction, chatroomId });
1323
}
1424
};
1525

0 commit comments

Comments
 (0)