fix(@desktop/chat): crash when pinning a message for a chat with cleared history
This commit is contained in:
parent
a69c2aea73
commit
0eab4009ba
|
@ -338,9 +338,11 @@ QtObject:
|
|||
let bottomRight = self.createIndex(msgIdx, 0, nil)
|
||||
self.dataChanged(topLeft, bottomRight, @[ChatMessageRoles.EmojiReactions.int])
|
||||
|
||||
proc changeMessagePinned*(self: ChatMessageList, messageId: string, pinned: bool, pinnedBy: string) =
|
||||
if not self.messageIndex.hasKey(messageId): return
|
||||
proc changeMessagePinned*(self: ChatMessageList, messageId: string, pinned: bool, pinnedBy: string): bool {.discardable.} =
|
||||
if not self.messageIndex.hasKey(messageId): return false
|
||||
let msgIdx = self.messageIndex[messageId]
|
||||
if msgIdx < 0: return false
|
||||
if msgIdx >= self.messages.len: return false
|
||||
var message = self.messages[msgIdx]
|
||||
message.isPinned = pinned
|
||||
message.pinnedBy = pinnedBy
|
||||
|
@ -348,6 +350,7 @@ QtObject:
|
|||
let topLeft = self.createIndex(msgIdx, 0, nil)
|
||||
let bottomRight = self.createIndex(msgIdx, 0, nil)
|
||||
self.dataChanged(topLeft, bottomRight, @[ChatMessageRoles.IsPinned.int, ChatMessageRoles.PinnedBy.int])
|
||||
return true
|
||||
|
||||
proc markMessageAsSent*(self: ChatMessageList, messageId: string)=
|
||||
let topLeft = self.createIndex(0, 0, nil)
|
||||
|
|
|
@ -399,14 +399,14 @@ QtObject:
|
|||
|
||||
proc addPinMessage*(self: MessageView, messageId: string, chatId: string, pinnedBy: string) =
|
||||
self.upsertChannel(chatId)
|
||||
self.messageList[chatId].changeMessagePinned(messageId, true, pinnedBy)
|
||||
if self.messageList[chatId].changeMessagePinned(messageId, true, pinnedBy):
|
||||
var message = self.messageList[chatId].getMessageById(messageId)
|
||||
message.pinnedBy = pinnedBy
|
||||
self.pinnedMessagesList[chatId].add(message)
|
||||
|
||||
proc removePinMessage*(self: MessageView, messageId: string, chatId: string) =
|
||||
self.upsertChannel(chatId)
|
||||
self.messageList[chatId].changeMessagePinned(messageId, false, "")
|
||||
if self.messageList[chatId].changeMessagePinned(messageId, false, ""):
|
||||
try:
|
||||
self.pinnedMessagesList[chatId].remove(messageId)
|
||||
except Exception as e:
|
||||
|
|
Loading…
Reference in New Issue