fix: fix clearing history removing the fake messages
This commit is contained in:
parent
ac6d55ae2d
commit
3f012dbf00
|
@ -298,7 +298,10 @@ QtObject:
|
|||
proc messagesCleared*(self: ChatsView) {.signal.}
|
||||
|
||||
proc clearMessages*(self: ChatsView, id: string) =
|
||||
self.messageList[id].clear()
|
||||
let channel = self.chats.getChannelById(id)
|
||||
if (channel == nil):
|
||||
return
|
||||
self.messageList[id].clear(not channel.isNil and channel.chatType != ChatType.Profile)
|
||||
self.messagesCleared()
|
||||
|
||||
proc pushMessages*(self:ChatsView, messages: var seq[Message]) =
|
||||
|
|
|
@ -41,6 +41,7 @@ QtObject:
|
|||
ChatMessageList* = ref object of QAbstractListModel
|
||||
messages*: seq[Message]
|
||||
status: Status
|
||||
id: string
|
||||
messageIndex: Table[string, int]
|
||||
messageReactions*: Table[string, string]
|
||||
timedoutMessages: HashSet[string]
|
||||
|
@ -65,12 +66,16 @@ QtObject:
|
|||
result.contentType = ContentType.ChatIdentifier;
|
||||
result.chatId = chatId
|
||||
|
||||
proc addFakeMessages*(self: ChatMessageList) =
|
||||
self.messages.add(self.chatIdentifier(self.id))
|
||||
self.messages.add(self.fetchMoreMessagesButton())
|
||||
|
||||
proc newChatMessageList*(chatId: string, status: Status, addFakeMessages: bool = true): ChatMessageList =
|
||||
new(result, delete)
|
||||
result.messages = @[]
|
||||
result.id = chatId
|
||||
if addFakeMessages:
|
||||
result.messages.add(result.chatIdentifier(chatId))
|
||||
result.messages.add(result.fetchMoreMessagesButton())
|
||||
result.addFakeMessages()
|
||||
result.messageIndex = initTable[string, int]()
|
||||
result.timedoutMessages = initHashSet[string]()
|
||||
result.status = status
|
||||
|
@ -232,9 +237,11 @@ QtObject:
|
|||
if (not self.messageIndex.hasKey(messageId)): return
|
||||
return self.messages[self.messageIndex[messageId]]
|
||||
|
||||
proc clear*(self: ChatMessageList) =
|
||||
proc clear*(self: ChatMessageList, addFakeMessages: bool = true) =
|
||||
self.beginResetModel()
|
||||
self.messages = @[]
|
||||
if (addFakeMessages):
|
||||
self.addFakeMessages()
|
||||
self.endResetModel()
|
||||
|
||||
proc setMessageReactions*(self: ChatMessageList, messageId: string, newReactions: string)=
|
||||
|
|
Loading…
Reference in New Issue