diff --git a/src/app/modules/main/chat_section/chat_content/messages/controller.nim b/src/app/modules/main/chat_section/chat_content/messages/controller.nim index 2c58ff6fc2..b2e2ac4e54 100644 --- a/src/app/modules/main/chat_section/chat_content/messages/controller.nim +++ b/src/app/modules/main/chat_section/chat_content/messages/controller.nim @@ -80,4 +80,8 @@ method pinUnpinMessage*(self: Controller, messageId: string, pin: bool) = self.messageService.pinUnpinMessage(self.chatId, messageId, pin) method getContactById*(self: Controller, contactId: string): ContactsDto = - return self.contactService.getContactById(contactId) \ No newline at end of file + return self.contactService.getContactById(contactId) + +method getContactNameAndImage*(self: Controller, contactId: string): + tuple[name: string, image: string, isIdenticon: bool] = + return self.contactService.getContactNameAndImage(contactId) \ No newline at end of file diff --git a/src/app/modules/main/chat_section/chat_content/messages/controller_interface.nim b/src/app/modules/main/chat_section/chat_content/messages/controller_interface.nim index d734d9cc82..e2cf822301 100644 --- a/src/app/modules/main/chat_section/chat_content/messages/controller_interface.nim +++ b/src/app/modules/main/chat_section/chat_content/messages/controller_interface.nim @@ -26,4 +26,8 @@ method pinUnpinMessage*(self: AccessInterface, messageId: string, pin: bool) {.b raise newException(ValueError, "No implementation available") method getContactById*(self: AccessInterface, contactId: string): ContactsDto {.base.} = + raise newException(ValueError, "No implementation available") + +method getContactNameAndImage*(self: AccessInterface, contactId: string): + tuple[name: string, image: string, isIdenticon: bool] {.base.} = raise newException(ValueError, "No implementation available") \ No newline at end of file diff --git a/src/app/modules/main/chat_section/chat_content/messages/module.nim b/src/app/modules/main/chat_section/chat_content/messages/module.nim index a0b0e50ff6..e1aa3edf94 100644 --- a/src/app/modules/main/chat_section/chat_content/messages/module.nim +++ b/src/app/modules/main/chat_section/chat_content/messages/module.nim @@ -70,7 +70,6 @@ method newMessagesLoaded*(self: Module, messages: seq[MessageDto], reactions: se for r in reactions: if(r.messageId == m.id): - # m.`from` should be replaced by appropriate ens/alias when we have that part refactored item.addReaction(r.emojiId, m.`from`, r.id) for p in pinnedMessages: @@ -80,10 +79,10 @@ method newMessagesLoaded*(self: Module, messages: seq[MessageDto], reactions: se # messages are sorted from the most recent to the least recent one viewItems = item & viewItems - self.view.model.prependItems(viewItems) + self.view.model().prependItems(viewItems) method toggleReaction*(self: Module, messageId: string, emojiId: int) = - let item = self.view.model.getItemWithMessageId(messageId) + let item = self.view.model().getItemWithMessageId(messageId) let myName = singletonInstance.userProfile.getName() if(item.shouldAddReaction(emojiId, myName)): self.controller.addReaction(messageId, emojiId) @@ -93,13 +92,19 @@ method toggleReaction*(self: Module, messageId: string, emojiId: int) = method onReactionAdded*(self: Module, messageId: string, emojiId: int, reactionId: string) = let myName = singletonInstance.userProfile.getName() - self.view.model.addReaction(messageId, emojiId, myName, reactionId) + self.view.model().addReaction(messageId, emojiId, myName, reactionId) method onReactionRemoved*(self: Module, messageId: string, reactionId: string) = - self.view.model.removeReaction(messageId, reactionId) + self.view.model().removeReaction(messageId, reactionId) + +method getNamesReactedWithEmojiIdForMessageId*(self: Module, messageId: string, emojiId: int): seq[string] = + let pubKeysForEmojiId = self.view.model().getPubKeysReactedWithEmojiIdForMessageId(messageId, emojiId) + for pk in pubKeysForEmojiId: + let (name, _, _) = self.controller.getContactNameAndImage(pk) + result.add(name) method pinUnpinMessage*(self: Module, messageId: string, pin: bool) = self.controller.pinUnpinMessage(messageId, pin) method onPinUnpinMessage*(self: Module, messageId: string, pin: bool) = - self.view.model.pinUnpinMessage(messageId, pin) \ No newline at end of file + self.view.model().pinUnpinMessage(messageId, pin) \ No newline at end of file diff --git a/src/app/modules/main/chat_section/chat_content/messages/private_interfaces/module_view_delegate_interface.nim b/src/app/modules/main/chat_section/chat_content/messages/private_interfaces/module_view_delegate_interface.nim index fd61471703..7259ca79d5 100644 --- a/src/app/modules/main/chat_section/chat_content/messages/private_interfaces/module_view_delegate_interface.nim +++ b/src/app/modules/main/chat_section/chat_content/messages/private_interfaces/module_view_delegate_interface.nim @@ -5,4 +5,8 @@ method toggleReaction*(self: AccessInterface, messageId: string, emojiId: int) { raise newException(ValueError, "No implementation available") method pinUnpinMessage*(self: AccessInterface, messageId: string, pin: bool) {.base.} = + raise newException(ValueError, "No implementation available") + +method getNamesReactedWithEmojiIdForMessageId*(self: AccessInterface, messageId: string, emojiId: int): seq[string] + {.base.} = raise newException(ValueError, "No implementation available") \ No newline at end of file diff --git a/src/app/modules/main/chat_section/chat_content/messages/view.nim b/src/app/modules/main/chat_section/chat_content/messages/view.nim index 4e588c56ed..3767e0ff75 100644 --- a/src/app/modules/main/chat_section/chat_content/messages/view.nim +++ b/src/app/modules/main/chat_section/chat_content/messages/view.nim @@ -6,7 +6,7 @@ QtObject: type View* = ref object of QObject delegate: io_interface.AccessInterface - model*: Model + model: Model modelVariant: QVariant proc delete*(self: View) = @@ -24,6 +24,9 @@ QtObject: proc load*(self: View) = self.delegate.viewDidLoad() + proc model*(self: View): Model = + return self.model + proc getModel(self: View): QVariant {.slot.} = return self.modelVariant @@ -33,8 +36,8 @@ QtObject: proc toggleReaction*(self: View, messageId: string, emojiId: int) {.slot.} = self.delegate.toggleReaction(messageId, emojiId) - proc getNamesForReaction*(self: View, messageId: string, emojiId: int): string {.slot.} = - return $(%* self.model.getNamesForReaction(messageId, emojiId)) + proc getNamesReactedWithEmojiIdForMessageId*(self: View, messageId: string, emojiId: int): string {.slot.} = + return $(%* self.delegate.getNamesReactedWithEmojiIdForMessageId(messageId, emojiId)) proc pinMessage*(self: View, messageId: string) {.slot.} = self.delegate.pinUnpinMessage(messageId, true) diff --git a/src/app/modules/shared_models/message_item.nim b/src/app/modules/shared_models/message_item.nim index 2ad143df8f..55b6b000ed 100644 --- a/src/app/modules/shared_models/message_item.nim +++ b/src/app/modules/shared_models/message_item.nim @@ -38,7 +38,7 @@ type timestamp: int64 contentType: ContentType messageType: int - reactions: OrderedTable[int, seq[tuple[name: string, reactionId: string]]] # [emojiId, list of [names reacted with the emojiId, reaction id]] + reactions: OrderedTable[int, seq[tuple[publicKey: string, reactionId: string]]] # [emojiId, list of [user publicKey reacted with the emojiId, reaction id]] reactionIds: seq[string] pinned: bool @@ -113,38 +113,38 @@ proc pinned*(self: Item): bool {.inline.} = proc `pinned=`*(self: Item, value: bool) {.inline.} = self.pinned = value -proc shouldAddReaction*(self: Item, emojiId: int, name: string): bool = +proc shouldAddReaction*(self: Item, emojiId: int, publicKey: string): bool = for k, values in self.reactions: if(k != emojiId): continue for t in values: - if(t.name == name): + if(t.publicKey == publicKey): return false return true -proc getReactionId*(self: Item, emojiId: int, name: string): string = +proc getReactionId*(self: Item, emojiId: int, publicKey: string): string = for k, values in self.reactions: if(k != emojiId): continue for t in values: - if(t.name == name): + if(t.publicKey == publicKey): return t.reactionId # we should never be here, since this is a controlled call return "" -proc addReaction*(self: Item, emojiId: int, name: string, reactionId: string) = +proc addReaction*(self: Item, emojiId: int, publicKey: string, reactionId: string) = if(not self.reactions.contains(emojiId)): self.reactions[emojiId] = @[] - self.reactions[emojiId].add((name, reactionId)) + self.reactions[emojiId].add((publicKey, reactionId)) proc removeReaction*(self: Item, reactionId: string) = - var key: int - var index: int + var key = -1 + var index = -1 for k, values in self.reactions: var i = -1 for t in values: @@ -152,17 +152,21 @@ proc removeReaction*(self: Item, reactionId: string) = if(t.reactionId == reactionId): key = k index = i + break + + if(key == -1 or index == -1): + return self.reactions[key].del(index) if(self.reactions[key].len == 0): self.reactions.del(key) -proc getNamesForReactions*(self: Item, emojiId: int): seq[string] = +proc getPubKeysReactedWithEmojiId*(self: Item, emojiId: int): seq[string] = if(not self.reactions.contains(emojiId)): return for v in self.reactions[emojiId]: - result.add(v.name) + result.add(v.publicKey) proc getCountsForReactions*(self: Item): seq[JsonNode] = for k, v in self.reactions: diff --git a/src/app/modules/shared_models/message_model.nim b/src/app/modules/shared_models/message_model.nim index 0fdfc186e5..1a4f8e559e 100644 --- a/src/app/modules/shared_models/message_model.nim +++ b/src/app/modules/shared_models/message_model.nim @@ -198,10 +198,10 @@ QtObject: let index = self.createIndex(ind, 0, nil) self.dataChanged(index, index, @[ModelRole.CountsForReactions.int]) - proc getNamesForReaction*(self: Model, messageId: string, emojiId: int): seq[string] = + proc getPubKeysReactedWithEmojiIdForMessageId*(self: Model, messageId: string, emojiId: int): seq[string] = for i in 0 ..< self.items.len: if(self.items[i].id == messageId): - return self.items[i].getNamesForReactions(emojiId) + return self.items[i].getPubKeysReactedWithEmojiId(emojiId) proc pinUnpinMessage*(self: Model, messageId: string, pin: bool) = let ind = self.findIndexForMessageId(messageId)