fix: handle message reactions for old messages not loaded
This commit is contained in:
parent
507f510c62
commit
84df214f6f
|
@ -259,11 +259,10 @@ QtObject:
|
|||
self.newMessagePushed()
|
||||
|
||||
proc messageEmojiReactionId(self: ChatsView, chatId: string, messageId: string, emojiId: int): string =
|
||||
let message = self.messageList[chatId].getMessageById(messageId)
|
||||
if (message.emojiReactions == "") :
|
||||
if (self.messageList[chatId].getReactions(messageId) == "") :
|
||||
return ""
|
||||
|
||||
let oldReactions = parseJson(message.emojiReactions)
|
||||
let oldReactions = parseJson(self.messageList[chatId].getReactions(messageId))
|
||||
|
||||
for pair in oldReactions.pairs:
|
||||
if (pair[1]["emojiId"].getInt == emojiId and pair[1]["from"].getStr == self.pubKey):
|
||||
|
@ -281,12 +280,12 @@ QtObject:
|
|||
let t = reactions.len
|
||||
for reaction in reactions.mitems:
|
||||
let messageList = self.messageList[reaction.chatId]
|
||||
var message = messageList.getMessageById(reaction.messageId)
|
||||
var emojiReactions = messageList.getReactions(reaction.messageId)
|
||||
var oldReactions: JsonNode
|
||||
if (message.emojiReactions == "") :
|
||||
if (emojiReactions == "") :
|
||||
oldReactions = %*{}
|
||||
else:
|
||||
oldReactions = parseJson(message.emojiReactions)
|
||||
oldReactions = parseJson(emojiReactions)
|
||||
|
||||
if (oldReactions.hasKey(reaction.id)):
|
||||
if (reaction.retracted):
|
||||
|
|
|
@ -38,6 +38,7 @@ QtObject:
|
|||
messages*: seq[Message]
|
||||
status: Status
|
||||
messageIndex: Table[string, int]
|
||||
messageReactions*: Table[string, string]
|
||||
timedoutMessages: HashSet[string]
|
||||
|
||||
proc delete(self: ChatMessageList) =
|
||||
|
@ -87,6 +88,10 @@ QtObject:
|
|||
method rowCount(self: ChatMessageList, index: QModelIndex = nil): int =
|
||||
return self.messages.len
|
||||
|
||||
proc getReactions*(self:ChatMessageList, messageId: string):string =
|
||||
if not self.messageReactions.hasKey(messageId): return ""
|
||||
result = self.messageReactions[messageId]
|
||||
|
||||
method data(self: ChatMessageList, index: QModelIndex, role: int): QVariant =
|
||||
if not index.isValid:
|
||||
return
|
||||
|
@ -116,7 +121,7 @@ QtObject:
|
|||
of ChatMessageRoles.Image: result = newQVariant(message.image)
|
||||
of ChatMessageRoles.Audio: result = newQVariant(message.audio)
|
||||
of ChatMessageRoles.AudioDurationMs: result = newQVariant(message.audioDurationMs)
|
||||
of ChatMessageRoles.EmojiReactions: result = newQVariant(message.emojiReactions)
|
||||
of ChatMessageRoles.EmojiReactions: result = newQVariant(self.getReactions(message.id))
|
||||
|
||||
method roleNames(self: ChatMessageList): Table[int, string] =
|
||||
{
|
||||
|
@ -188,8 +193,9 @@ QtObject:
|
|||
self.endResetModel()
|
||||
|
||||
proc setMessageReactions*(self: ChatMessageList, messageId: string, newReactions: string)=
|
||||
self.messageReactions[messageId] = newReactions
|
||||
if not self.messageIndex.hasKey(messageId): return
|
||||
let msgIdx = self.messageIndex[messageId]
|
||||
self.messages[msgIdx].emojiReactions = newReactions
|
||||
let topLeft = self.createIndex(msgIdx, 0, nil)
|
||||
let bottomRight = self.createIndex(msgIdx, 0, nil)
|
||||
self.dataChanged(topLeft, bottomRight, @[ChatMessageRoles.EmojiReactions.int])
|
||||
|
|
|
@ -48,7 +48,6 @@ type Message* = object
|
|||
image*: string
|
||||
audio*: string
|
||||
audioDurationMs*: int
|
||||
emojiReactions*: string
|
||||
|
||||
type Reaction* = object
|
||||
id*: string
|
||||
|
|
Loading…
Reference in New Issue