fix(@desktop/chat): cannot unpin last message in modal

fixes #2659

1 - Change call from remove to deleteMessage
Remove were not updating the index and was causing the issue

2 - Erase the remove proc as the deleteMessage should always be used
This commit is contained in:
Anthony Laibe 2021-07-19 10:50:18 +02:00 committed by Iuri Matias
parent 4213f953e0
commit a811ee215c
4 changed files with 7 additions and 15 deletions

View File

@ -61,7 +61,7 @@ proc handleChatEvents(self: ChatController) =
if (evArgs.communityMembershipRequests.len > 0):
self.view.communities.addMembershipRequests(evArgs.communityMembershipRequests)
if (evArgs.pinnedMessages.len > 0):
self.view.addPinnedMessages(evArgs.pinnedMessages)
self.view.refreshPinnedMessages(evArgs.pinnedMessages)
if (evArgs.activityCenterNotifications.len > 0):
self.view.addActivityCenterNotification(evArgs.activityCenterNotifications)
self.view.communities.updateNotifications(evArgs.activityCenterNotifications)

View File

@ -441,8 +441,8 @@ QtObject:
proc deleteMessageWhichReplacedMessageWithId*(self: ChatsView, channelId: string, messageId: string): bool =
result = self.messageView.deleteMessageWhichReplacedMessageWithId(channelId, messageId)
proc addPinnedMessages*(self: ChatsView, pinnedMessages: seq[Message]) =
self.messageView.addPinnedMessages(pinnedMessages)
proc refreshPinnedMessages*(self: ChatsView, pinnedMessages: seq[Message]) =
self.messageView.refreshPinnedMessages(pinnedMessages)
proc clearMessages*(self: ChatsView, id: string) =
self.messageView.clearMessages(id)

View File

@ -313,16 +313,6 @@ QtObject:
self.countChanged()
self.endInsertRows()
proc remove*(self: ChatMessageList, messageId: string) =
if not self.messageIndex.hasKey(messageId): return
let index = self.getMessageIndex(messageId)
self.beginRemoveRows(newQModelIndex(), index, index)
self.messages.delete(index)
self.messageIndex.del(messageId)
self.countChanged()
self.endRemoveRows()
proc getMessageById*(self: ChatMessageList, messageId: string): Message =
if (not self.messageIndex.hasKey(messageId)): return
return self.messages[self.messageIndex[messageId]]
@ -344,9 +334,11 @@ QtObject:
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

View File

@ -463,7 +463,7 @@ QtObject:
self.upsertChannel(chatId)
if self.messageList[chatId].changeMessagePinned(messageId, false, ""):
try:
self.pinnedMessagesList[chatId].remove(messageId)
discard self.pinnedMessagesList[chatId].deleteMessage(messageId)
except Exception as e:
error "Error removing ", msg = e.msg
@ -475,7 +475,7 @@ QtObject:
self.status.chat.setPinMessage(messageId, chatId, false)
self.removePinMessage(messageId, chatId)
proc addPinnedMessages*(self: MessageView, pinnedMessages: seq[Message]) =
proc refreshPinnedMessages*(self: MessageView, pinnedMessages: seq[Message]) =
for pinnedMessage in pinnedMessages:
if (pinnedMessage.isPinned):
self.addPinMessage(pinnedMessage.id, pinnedMessage.localChatId, pinnedMessage.pinnedBy)