diff --git a/src/app/chat/view.nim b/src/app/chat/view.nim index 4d80d2772e..6e1d52843f 100644 --- a/src/app/chat/view.nim +++ b/src/app/chat/view.nim @@ -253,6 +253,9 @@ QtObject: else: self.newMessagePushed() + proc addEmojiReaction*(self: ChatsView, messageId: string, emojiId: int) {.slot.} = + self.status.chat.addEmojiReaction(self.activeChannel.id, messageId, emojiId) + proc pushReactions*(self:ChatsView, reactions: var seq[Reaction]) = let t = reactions.len for reaction in reactions.mitems: diff --git a/src/status/chat.nim b/src/status/chat.nim index c351339eda..ddf5f12a8a 100644 --- a/src/status/chat.nim +++ b/src/status/chat.nim @@ -277,6 +277,9 @@ proc chatReactions*(self: ChatModel, chatId: string, initialLoad:bool = true) = except Exception as e: error "Error reactions", msg = e.msg +proc addEmojiReaction*(self: ChatModel, chatId: string, messageId: string, emojiId: int) = + let reactions = status_chat.addEmojiReaction(chatId, messageId, emojiId) + self.events.emit("reactionsLoaded", ReactionsLoadedArgs(reactions: reactions)) proc markAllChannelMessagesRead*(self: ChatModel, chatId: string): JsonNode = var response = status_chat.markAllRead(chatId) diff --git a/src/status/libstatus/chat.nim b/src/status/libstatus/chat.nim index cf43fb0937..c926d2c092 100644 --- a/src/status/libstatus/chat.nim +++ b/src/status/libstatus/chat.nim @@ -83,6 +83,15 @@ proc getEmojiReactionsByChatId*(chatId: string, cursor: string = ""): (string, s return (rpcResult{"cursor"}.getStr, reactions) +proc addEmojiReaction*(chatId: string, messageId: string, emojiId: int): seq[Reaction] = + let rpcResult = parseJson(callPrivateRPC("sendEmojiReaction".prefix, %* [chatId, messageId, emojiId]))["result"] + + var reactions: seq[Reaction] = @[] + if rpcResult != nil and rpcResult["emojiReactions"] != nil and rpcResult["emojiReactions"].len != 0: + for jsonMsg in rpcResult["emojiReactions"]: + reactions.add(jsonMsg.toReaction) + + result = reactions # TODO this probably belongs in another file proc generateSymKeyFromPassword*(): string = result = ($parseJson(callPrivateRPC("waku_generateSymKeyFromPassword", %* [ diff --git a/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/EmojiReactions.qml b/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/EmojiReactions.qml index dad2243e4b..648dab31ca 100644 --- a/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/EmojiReactions.qml +++ b/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/EmojiReactions.qml @@ -28,7 +28,7 @@ Item { } } byEmoji[reaction.emojiId].count++; - if (!byEmoji[reaction.emojiId].currentUserReacted && reaction.fromAuthor === profileModel.profile.pubKey) { + if (!byEmoji[reaction.emojiId].currentUserReacted && reaction.from === profileModel.profile.pubKey) { byEmoji[reaction.emojiId].currentUserReacted = true } diff --git a/ui/app/AppLayouts/Chat/components/EmojiReaction.qml b/ui/app/AppLayouts/Chat/components/EmojiReaction.qml index 17d0f865aa..f61144a84c 100644 --- a/ui/app/AppLayouts/Chat/components/EmojiReaction.qml +++ b/ui/app/AppLayouts/Chat/components/EmojiReaction.qml @@ -3,7 +3,9 @@ import "../../../../imports" import "../../../../shared" SVGImage { + property var closeModal: function () {} property int emojiId + id: reactionImage width: 32 fillMode: Image.PreserveAspectFit @@ -11,8 +13,8 @@ SVGImage { anchors.fill: parent cursorShape: Qt.PointingHandCursor onClicked: { - console.log('Clicked on Emoji', emojiId) - console.log('This feature will be implmented at a later date') + chatsModel.addEmojiReaction(SelectedMessage.messageId, emojiId) + reactionImage.closeModal() } } diff --git a/ui/app/AppLayouts/Chat/components/MessageContextMenu.qml b/ui/app/AppLayouts/Chat/components/MessageContextMenu.qml index 64d7d386f8..34bc54a5e7 100644 --- a/ui/app/AppLayouts/Chat/components/MessageContextMenu.qml +++ b/ui/app/AppLayouts/Chat/components/MessageContextMenu.qml @@ -30,6 +30,9 @@ PopupMenu { delegate: EmojiReaction { source: "../../../img/" + filename emojiId: model.emojiId + closeModal: function () { + messageContextMenu.close() + } } } }