fix(users): user not added when joining group + only show joined users

Fixes #5202
This commit is contained in:
Jonathan Rainville 2022-03-30 15:50:10 -04:00 committed by Iuri Matias
parent 57b731198f
commit 2d44d53bec
3 changed files with 55 additions and 48 deletions

View File

@ -103,6 +103,12 @@ proc init*(self: Controller) =
if (args.chatId == self.chatId):
self.delegate.onChatMembersAdded(args.ids)
self.events.on(SIGNAL_CHAT_UPDATE) do(e: Args):
var args = ChatUpdateArgsNew(e)
for chat in args.chats:
if (chat.id == self.chatId):
self.delegate.onChatUpdated(chat)
self.events.on(SIGNAL_CHAT_MEMBER_REMOVED) do(e: Args):
let args = ChatMemberRemovedArgs(e)
if (args.chatId == self.chatId):
@ -124,13 +130,11 @@ proc init*(self: Controller) =
proc getChat*(self: Controller): ChatDto =
return self.chatService.getChatById(self.chatId)
proc getChatMemberInfo*(self: Controller, id: string): (bool, bool) =
proc getChatMember*(self: Controller, id: string): ChatMember =
let chat = self.getChat()
for member in chat.members:
if (member.id == id):
return (member.admin, member.joined)
return (false, false)
return member
proc getChatMembers*(self: Controller): seq[ChatMember] =
var communityId = ""

View File

@ -1,5 +1,6 @@
import NimQml
import ../../../../../../app_service/service/chat/service as chat_service
import ../../../../../../app_service/service/message/dto/[message]
import ../../../../../../app_service/service/contacts/dto/[status_update]
@ -33,9 +34,15 @@ method contactUpdated*(self: AccessInterface, publicKey: string) {.base.} =
method loggedInUserImageChanged*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method addChatMember*(self: AccessInterface, member: ChatMember) {.base.} =
raise newException(ValueError, "No implementation available")
method onChatMembersAdded*(self: AccessInterface, ids: seq[string]) {.base.} =
raise newException(ValueError, "No implementation available")
method onChatUpdated*(self: AccessInterface, chat: ChatDto) {.base.} =
raise newException(ValueError, "No implementation available")
method onChatMemberRemoved*(self: AccessInterface, ids: string) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -20,6 +20,9 @@ type
controller: Controller
moduleLoaded: bool
# Forward declaration
method addChatMember*(self: Module, member: ChatMember)
proc newModule*(
delegate: delegate_interface.AccessInterface, events: EventEmitter, sectionId: string, chatId: string,
belongsToCommunity: bool, isUsersListAvailable: bool, contactService: contact_service.Service,
@ -51,30 +54,7 @@ method isLoaded*(self: Module): bool =
method viewDidLoad*(self: Module) =
let members = self.controller.getChatMembers()
for member in members:
let isMe = member.id == singletonInstance.userProfile.getPubKey()
let contactDetails = self.controller.getContactDetails(member.id)
var status = OnlineStatus.Online
if (not isMe):
let statusUpdateDto = self.controller.getStatusForContact(member.id)
status = statusUpdateDto.statusType.int.OnlineStatus
self.view.model().addItem(initItem(
member.id,
if (isMe):
contactDetails.displayName & " (You)"
else:
contactDetails.displayName,
contactDetails.details.name,
contactDetails.details.localNickname,
contactDetails.details.alias,
status,
contactDetails.icon,
contactDetails.details.identicon,
contactDetails.isidenticon,
contactDetails.details.added,
member.admin,
member.joined
))
self.addChatMember(member)
self.moduleLoaded = true
self.delegate.usersDidLoad()
@ -138,29 +118,45 @@ method loggedInUserImageChanged*(self: Module) =
self.view.model().setIcon(singletonInstance.userProfile.getPubKey(), singletonInstance.userProfile.getIcon(),
singletonInstance.userProfile.getIsIdenticon())
method addChatMember*(self: Module, member: ChatMember) =
if(member.id == "" or self.view.model().isContactWithIdAdded(member.id)):
return
if (not member.joined):
return
let isMe = member.id == singletonInstance.userProfile.getPubKey()
let contactDetails = self.controller.getContactDetails(member.id)
var status = OnlineStatus.Online
if (not isMe):
let statusUpdateDto = self.controller.getStatusForContact(member.id)
status = statusUpdateDto.statusType.int.OnlineStatus
self.view.model().addItem(initItem(
member.id,
if (isMe):
contactDetails.displayName & " (You)"
else:
contactDetails.displayName,
contactDetails.details.name,
contactDetails.details.localNickname,
contactDetails.details.alias,
status,
contactDetails.icon,
contactDetails.details.identicon,
contactDetails.isidenticon,
contactDetails.details.added,
member.admin,
member.joined
))
method onChatMembersAdded*(self: Module, ids: seq[string]) =
for id in ids:
if(self.view.model().isContactWithIdAdded(id)):
continue
self.addChatMember(self.controller.getChatMember(id))
let (admin, joined) = self.controller.getChatMemberInfo(id)
let contactDetails = self.controller.getContactDetails(id)
let statusUpdateDto = self.controller.getStatusForContact(id)
let status = statusUpdateDto.statusType.int.OnlineStatus
self.view.model().addItem(initItem(
id,
contactDetails.displayName,
contactDetails.details.name,
contactDetails.details.localNickname,
contactDetails.details.alias,
status,
contactDetails.icon,
contactDetails.details.identicon,
contactDetails.isidenticon,
contactDetails.details.added,
admin,
joined
))
method onChatUpdated*(self: Module, chat: ChatDto) =
for member in chat.members:
self.addChatMember(self.controller.getChatMember(member.id))
method onChatMemberRemoved*(self: Module, id: string) =
self.view.model().removeItemById(id)