add capability to remove reactions

This commit is contained in:
marlon-erler
2026-04-07 18:48:01 +00:00
parent ad978807dc
commit 4bd7126a76
6 changed files with 81 additions and 64 deletions
+16 -11
View File
@@ -76,26 +76,31 @@ export default class ChatMessageViewModel {
};
// reactions
addReaction = (reaction: ChatMessageReaction): void => {
handleReaction = (reaction: ChatMessageReaction): void => {
function setReaction(mapState: React.MapState<any>) {
if (reaction.isDeleting) {
mapState.remove(reaction.sender);
} else {
mapState.set(reaction.sender, reaction);
}
}
switch (reaction.content) {
case ReactionSymbols.ThumbsUp:
return this.reactionsThumbsUp.set(reaction.sender, reaction);
return setReaction(this.reactionsThumbsUp);
case ReactionSymbols.Check:
return this.reactionsCheck.set(reaction.sender, reaction);
return setReaction(this.reactionsCheck);
case ReactionSymbols.Attention:
return this.reactionsAttention.set(reaction.sender, reaction);
return setReaction(this.reactionsAttention);
case ReactionSymbols.DoubleAttention:
return this.reactionsDoubleAttention.set(
reaction.sender,
reaction,
);
return setReaction(this.reactionsDoubleAttention);
case ReactionSymbols.Question:
return this.reactionsQuestion.set(reaction.sender, reaction);
return setReaction(this.reactionsQuestion);
}
};
sendReaction = (content: ReactionSymbols): void => {
this.messagePageViewModel.sendReaction(this.chatMessage.id, content);
sendReaction = (content: ReactionSymbols, isDeleting: boolean): void => {
this.messagePageViewModel.sendReaction(this.chatMessage.id, content, isDeleting);
};
// load
+1 -1
View File
@@ -181,7 +181,7 @@ export default class ChatViewModel {
);
chatModel.reactionHandlerManager.addHandler(
(reaction: ChatMessageReaction) => {
this.messagePageViewModel.showReaction(reaction);
this.messagePageViewModel.handleReaction(reaction);
},
);
+5 -5
View File
@@ -41,8 +41,8 @@ export default class MessagePageViewModel {
messageViewModel.loadData();
};
sendReaction = (messageId: string, content: ReactionSymbols): void => {
this.chatViewModel.chatModel.sendReaction(messageId, content);
sendReaction = (messageId: string, content: ReactionSymbols, isDeleting: boolean): void => {
this.chatViewModel.chatModel.sendReaction(messageId, content, isDeleting);
};
// view
@@ -68,11 +68,11 @@ export default class MessagePageViewModel {
}
};
showReaction = (reaction: ChatMessageReaction): void => {
handleReaction = (reaction: ChatMessageReaction): void => {
const messageViewModel: ChatMessageViewModel | undefined =
this.chatMessageViewModels.value.get(reaction.messageId);
if (messageViewModel == undefined) return;
messageViewModel.addReaction(reaction);
messageViewModel.handleReaction(reaction);
};
// load
@@ -82,7 +82,7 @@ export default class MessagePageViewModel {
this.showChatMessage(chatMessage);
}
for (const reaction of this.chatViewModel.chatModel.reactions) {
this.showReaction(reaction);
this.handleReaction(reaction);
}
};