fix(group-chats): remove user from user list when they leave chat

This commit is contained in:
Jonathan Rainville 2022-04-12 12:18:51 -04:00 committed by Iuri Matias
parent a633d33ec5
commit 1fdef43d18
2 changed files with 22 additions and 3 deletions

View File

@ -111,10 +111,16 @@ method loggedInUserImageChanged*(self: Module) =
self.view.model().setIcon(singletonInstance.userProfile.getPubKey(), singletonInstance.userProfile.getIcon())
method addChatMember*(self: Module, member: ChatMember) =
if(member.id == "" or self.view.model().isContactWithIdAdded(member.id)):
if member.id == "":
return
if (not member.joined):
if not member.joined:
if self.view.model().isContactWithIdAdded(member.id):
# Member is no longer joined
self.view.model().removeItemById(member.id)
return
if self.view.model().isContactWithIdAdded(member.id):
return
let isMe = member.id == singletonInstance.userProfile.getPubKey()
@ -148,6 +154,16 @@ method onChatUpdated*(self: Module, chat: ChatDto) =
for member in chat.members:
self.addChatMember(self.controller.getChatMember(member.id))
let ids = self.view.model.getItemIds()
for id in ids:
var found = false
for member in chat.members:
if (member.id == id):
found = true
break
if (not found):
self.view.model().removeItemById(id)
method onChatMemberRemoved*(self: Module, id: string) =
self.view.model().removeItemById(id)

View File

@ -1,4 +1,4 @@
import NimQml, Tables, strformat
import NimQml, Tables, strformat, sequtils, sugar
import user_item
@ -221,3 +221,6 @@ QtObject:
return
self.removeItemWithIndex(ind)
proc getItemIds*(self: Model): seq[string] =
return self.items.map(i => i.id)