fix(@desktop/community): Decrease amount of chat_getMembers calls

This commit is contained in:
mprakhov 2022-12-27 01:37:55 +02:00 committed by Mykhailo Prakhov
parent 3a26799781
commit 76b6fba5ad
2 changed files with 13 additions and 10 deletions

View File

@ -57,8 +57,11 @@ proc handleCommunityOnlyConnections(self: Controller) =
for community in args.communities:
if (community.id != self.sectionId):
continue
let membersPubKeys = community.members.map(x => x.id)
self.delegate.onChatMembersAddedOrRemoved(membersPubKeys)
# If we didn't join the community, all members in the list will have status
# joined=false. No need to try add them to the model
if community.isMember:
let membersPubKeys = community.members.map(x => x.id)
self.delegate.onChatMembersAddedOrRemoved(membersPubKeys)
self.events.on(SIGNAL_COMMUNITY_MEMBER_REMOVED) do(e: Args):
let args = CommunityMemberArgs(e)
@ -161,12 +164,6 @@ proc getChatMembers*(self: Controller): seq[ChatMember] =
communityId = self.sectionId
return self.chatService.getMembers(communityId, self.chatId)
proc getChatMember*(self: Controller, id: string): ChatMember =
let members = self.getChatMembers()
for member in members:
if (member.id == id):
return member
proc getMembersPublicKeys*(self: Controller): seq[string] =
if(self.belongsToCommunity):
let communityDto = self.communityService.getCommunityById(self.sectionId)

View File

@ -162,12 +162,18 @@ method addChatMember*(self: Module, member: ChatMember) =
))
method onChatMembersAdded*(self: Module, ids: seq[string]) =
let members = self.controller.getChatMembers()
for id in ids:
self.addChatMember(self.controller.getChatMember(id))
for member in members:
if (member.id == id):
self.addChatMember(member)
method onChatUpdated*(self: Module, chat: ChatDto) =
let members = self.controller.getChatMembers()
for member in chat.members:
self.addChatMember(self.controller.getChatMember(member.id))
for existingMember in members:
if existingMember.id == member.id:
self.addChatMember(member)
if chat.members.len > 0:
let ids = self.view.model.getItemIds()