feat: delete messages on block
This commit is contained in:
parent
636b39d082
commit
fdf6be5f64
|
@ -902,6 +902,10 @@ QtObject:
|
|||
ChatViewRoles.MessageList.int:"messages"
|
||||
}.toTable
|
||||
|
||||
proc removeMessagesByUserId(self: ChatsView, publicKey: string) {.slot.} =
|
||||
for k in self.messageList.keys:
|
||||
self.messageList[k].removeMessagesByUserId(publicKey)
|
||||
|
||||
proc getMessageListIndex(self: ChatsView): int {.slot.} =
|
||||
var idx = -1
|
||||
for msg in toSeq(self.messageList.values):
|
||||
|
|
|
@ -286,6 +286,21 @@ QtObject:
|
|||
|
||||
self.dataChanged(topLeft, bottomRight, @[ChatMessageRoles.Username.int])
|
||||
|
||||
proc removeMessagesByUserId*(self: ChatMessageList, publicKey: string) =
|
||||
var msgIdxToDelete: seq[int] = @[]
|
||||
var msgIdToDelete: seq[string] = @[]
|
||||
for m in self.messages.mitems:
|
||||
if m.fromAuthor == publicKey:
|
||||
# Can't delete on a loop
|
||||
msgIdxToDelete.add(self.messageIndex[m.id])
|
||||
msgIdToDelete.add(m.id)
|
||||
for m in msgIdxToDelete:
|
||||
self.beginRemoveRows(newQModelIndex(), m, m)
|
||||
self.messages.delete(m)
|
||||
self.endRemoveRows()
|
||||
for m in msgIdToDelete:
|
||||
self.messageIndex.del(m)
|
||||
|
||||
|
||||
proc getID*(self: ChatMessageList):string {.slot.} =
|
||||
self.id
|
|
@ -174,8 +174,11 @@ QtObject:
|
|||
self.contactListChanged()
|
||||
discard self.status.contacts.unblockContact(publicKey)
|
||||
|
||||
proc contactBlocked*(self: ContactsView, publicKey: string) {.signal.}
|
||||
|
||||
proc blockContact*(self: ContactsView, publicKey: string): string {.slot.} =
|
||||
self.contactListChanged()
|
||||
self.contactBlocked(publicKey)
|
||||
return self.status.contacts.blockContact(publicKey)
|
||||
|
||||
proc removeContact*(self: ContactsView, publicKey: string) {.slot.} =
|
||||
|
|
|
@ -124,6 +124,9 @@ StackLayout {
|
|||
onContactListChanged: {
|
||||
isBlocked = profileModel.contacts.isContactBlocked(activeChatId);
|
||||
}
|
||||
onContactBlocked: {
|
||||
chatsModel.removeMessagesByUserId(publicKey)
|
||||
}
|
||||
}
|
||||
|
||||
Timer {
|
||||
|
|
Loading…
Reference in New Issue