feat: enable removing emoji reactions from the context menu

This commit is contained in:
Jonathan Rainville 2020-08-12 14:49:52 -04:00 committed by Iuri Matias
parent 99ca0e9e55
commit 5f119e1ead
5 changed files with 39 additions and 4 deletions

View File

@ -5,6 +5,7 @@ import ../../status/messages as messages_model
import ../../signals/types
import ../../status/libstatus/types as status_types
import ../../status/libstatus/wallet as status_wallet
import ../../status/libstatus/settings as status_settings
import ../../status/[chat, contacts, status]
import view, views/channels_list, views/message_list
@ -34,8 +35,9 @@ proc init*(self: ChatController) =
self.handleChatEvents()
self.status.mailservers.init()
self.status.chat.init()
self.view.obtainAvailableStickerPacks()
let pubKey = status_settings.getSetting[string](Setting.PublicKey, "0x0")
self.view.pubKey = pubKey
let recentStickers = self.status.chat.getRecentStickers()
for sticker in recentStickers:

View File

@ -31,6 +31,7 @@ QtObject:
stickerPacks*: StickerPackList
recentStickers*: StickerList
replyTo: string
pubKey*: string
channelOpenTime*: Table[string, int64]
connected: bool
unreadMessageCnt: int
@ -58,6 +59,7 @@ QtObject:
result.stickerPacks = newStickerPackList()
result.recentStickers = newStickerList()
result.unreadMessageCnt = 0
result.pubKey = ""
result.setup()
proc addStickerPackToList*(self: ChatsView, stickerPack: StickerPack, isInstalled, isBought: bool) =
@ -253,8 +255,24 @@ QtObject:
else:
self.newMessagePushed()
proc addEmojiReaction*(self: ChatsView, messageId: string, emojiId: int) {.slot.} =
self.status.chat.addEmojiReaction(self.activeChannel.id, messageId, emojiId)
proc messageEmojiReactionId(self: ChatsView, chatId: string, messageId: string, emojiId: int): string =
let message = self.messageList[chatId].getMessageById(messageId)
if (message.emojiReactions == "") :
return ""
let oldReactions = parseJson(message.emojiReactions)
for pair in oldReactions.pairs:
if (pair[1]["emojiId"].getInt == emojiId and pair[1]["from"].getStr == self.pubKey):
return pair[0]
return ""
proc toggleEmojiReaction*(self: ChatsView, messageId: string, emojiId: int) {.slot.} =
let emojiReactionId = self.messageEmojiReactionId(self.activeChannel.id, messageId, emojiId)
if (emojiReactionId == ""):
self.status.chat.addEmojiReaction(self.activeChannel.id, messageId, emojiId)
else:
self.status.chat.removeEmojiReaction(emojiReactionId)
proc pushReactions*(self:ChatsView, reactions: var seq[Reaction]) =
let t = reactions.len

View File

@ -281,6 +281,10 @@ proc addEmojiReaction*(self: ChatModel, chatId: string, messageId: string, emoji
let reactions = status_chat.addEmojiReaction(chatId, messageId, emojiId)
self.events.emit("reactionsLoaded", ReactionsLoadedArgs(reactions: reactions))
proc removeEmojiReaction*(self: ChatModel, emojiReactionId: string) =
let reactions = status_chat.removeEmojiReaction(emojiReactionId)
self.events.emit("reactionsLoaded", ReactionsLoadedArgs(reactions: reactions))
proc markAllChannelMessagesRead*(self: ChatModel, chatId: string): JsonNode =
var response = status_chat.markAllRead(chatId)
result = parseJson(response)

View File

@ -92,6 +92,17 @@ proc addEmojiReaction*(chatId: string, messageId: string, emojiId: int): seq[Rea
reactions.add(jsonMsg.toReaction)
result = reactions
proc removeEmojiReaction*(emojiReactionId: string): seq[Reaction] =
let rpcResult = parseJson(callPrivateRPC("sendEmojiReactionRetraction".prefix, %* [emojiReactionId]))["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", %* [

View File

@ -13,7 +13,7 @@ SVGImage {
anchors.fill: parent
cursorShape: Qt.PointingHandCursor
onClicked: {
chatsModel.addEmojiReaction(SelectedMessage.messageId, emojiId)
chatsModel.toggleEmojiReaction(SelectedMessage.messageId, emojiId)
reactionImage.closeModal()
}