refactor(@desktop/chat-communities): a list of users who reacted with an emoji updated
A list of users who reacted with an emoji now displays names instead of users' public key
This commit is contained in:
parent
6c76974985
commit
6ae88cf1cc
|
@ -81,3 +81,7 @@ method pinUnpinMessage*(self: Controller, messageId: string, pin: bool) =
|
|||
|
||||
method getContactById*(self: Controller, contactId: string): ContactsDto =
|
||||
return self.contactService.getContactById(contactId)
|
||||
|
||||
method getContactNameAndImage*(self: Controller, contactId: string):
|
||||
tuple[name: string, image: string, isIdenticon: bool] =
|
||||
return self.contactService.getContactNameAndImage(contactId)
|
|
@ -27,3 +27,7 @@ method pinUnpinMessage*(self: AccessInterface, messageId: string, pin: bool) {.b
|
|||
|
||||
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")
|
|
@ -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)
|
||||
self.view.model().pinUnpinMessage(messageId, pin)
|
|
@ -6,3 +6,7 @@ method toggleReaction*(self: AccessInterface, messageId: string, emojiId: int) {
|
|||
|
||||
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")
|
|
@ -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)
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue