fix(user-list): 1-1 mentions not updating nickname + rearrange events

Fixes #5462
This commit is contained in:
Jonathan Rainville 2022-04-15 12:02:31 -04:00 committed by Iuri Matias
parent d87e03e969
commit 24a662676e
5 changed files with 30 additions and 22 deletions

View File

@ -21,6 +21,9 @@ type
communityService: community_service.Service
messageService: message_service.Service
# Forward declaration
proc getChat*(self: Controller): ChatDto
proc newController*(
delegate: io_interface.AccessInterface, events: EventEmitter, sectionId: string, chatId: string,
belongsToCommunity: bool, isUsersListAvailable: bool, contactService: contact_service.Service,
@ -58,31 +61,40 @@ proc handleCommunityOnlyConnections(self: Controller) =
self.delegate.onChatMembersAdded(membersPubKeys)
proc init*(self: Controller) =
if(self.isUsersListAvailable):
# Events that are needed for all chats because of mentions
self.events.on(SIGNAL_CONTACT_NICKNAME_CHANGED) do(e: Args):
let args = ContactArgs(e)
self.delegate.contactNicknameChanged(args.contactId)
self.events.on(SIGNAL_CONTACT_UPDATED) do(e: Args):
let args = ContactArgs(e)
self.delegate.contactUpdated(args.contactId)
self.events.on(SIGNAL_LOGGEDIN_USER_IMAGE_CHANGED) do(e: Args):
self.delegate.loggedInUserImageChanged()
let chat = self.getChat()
# Events only for public chats
if chat.isPublicChat():
self.events.on(SIGNAL_MESSAGES_LOADED) do(e:Args):
let args = MessagesLoadedArgs(e)
if(self.chatId != args.chatId):
return
self.delegate.newMessagesLoaded(args.messages)
self.delegate.onNewMessagesLoaded(args.messages)
self.events.on(SIGNAL_NEW_MESSAGE_RECEIVED) do(e:Args):
let args = MessagesArgs(e)
if(self.chatId != args.chatId):
return
self.delegate.newMessagesLoaded(args.messages)
self.events.on(SIGNAL_CONTACT_NICKNAME_CHANGED) do(e: Args):
let args = ContactArgs(e)
self.delegate.contactNicknameChanged(args.contactId)
self.delegate.onNewMessagesLoaded(args.messages)
# Events only for the user list, so not needed in public and one to one chats
if(self.isUsersListAvailable):
self.events.on(SIGNAL_CONTACTS_STATUS_UPDATED) do(e: Args):
let args = ContactsStatusUpdatedArgs(e)
self.delegate.contactsStatusUpdated(args.statusUpdates)
self.events.on(SIGNAL_CONTACT_UPDATED) do(e: Args):
let args = ContactArgs(e)
self.delegate.contactUpdated(args.contactId)
self.events.on(SIGNAL_CONTACT_ADDED) do(e: Args):
let args = ContactArgs(e)
self.delegate.contactUpdated(args.contactId)
@ -95,9 +107,6 @@ proc init*(self: Controller) =
let args = ContactArgs(e)
self.delegate.contactUpdated(args.contactId)
self.events.on(SIGNAL_LOGGEDIN_USER_IMAGE_CHANGED) do(e: Args):
self.delegate.loggedInUserImageChanged()
self.events.on(SIGNAL_CHAT_MEMBERS_ADDED) do(e: Args):
let args = ChatMembersAddedArgs(e)
if (args.chatId == self.chatId):
@ -119,6 +128,7 @@ proc init*(self: Controller) =
if (args.chatId == self.chatId):
self.delegate.onChatMemberUpdated(args.id, args.admin, args.joined)
# Events only for community channel
if (self.belongsToCommunity):
self.handleCommunityOnlyConnections()

View File

@ -19,7 +19,7 @@ method isLoaded*(self: AccessInterface): bool {.base.} =
method getModuleAsVariant*(self: AccessInterface): QVariant {.base.} =
raise newException(ValueError, "No implementation available")
method newMessagesLoaded*(self: AccessInterface, messages: seq[MessageDto]) {.base.} =
method onNewMessagesLoaded*(self: AccessInterface, messages: seq[MessageDto]) {.base.} =
raise newException(ValueError, "No implementation available")
method contactNicknameChanged*(self: AccessInterface, publicKey: string) {.base.} =

View File

@ -62,11 +62,7 @@ method viewDidLoad*(self: Module) =
method getModuleAsVariant*(self: Module): QVariant =
return self.viewVariant
method newMessagesLoaded*(self: Module, messages: seq[MessageDto]) =
let chat = self.controller.getChat()
if not chat.isPublicChat():
return
method onNewMessagesLoaded*(self: Module, messages: seq[MessageDto]) =
for m in messages:
if(self.view.model().isContactWithIdAdded(m.`from`)):
continue

View File

@ -115,10 +115,9 @@ proc buildChatUI(self: Module, events: EventEmitter,
var chatImage = ""
var colorHash: ColorHashDto = @[]
var colorId: int = 0
var isUsersListAvailable = true
let isUsersListAvailable = (c.chatType != ChatType.OneToOne and c.chatType != ChatType.Public)
var blocked = false
if(c.chatType == ChatType.OneToOne):
isUsersListAvailable = false
let contactDetails = self.controller.getContactDetails(c.id)
chatName = contactDetails.displayName
chatImage = contactDetails.icon

View File

@ -259,3 +259,6 @@ proc toChatDto*(jsonObj: JsonNode, communityId: string): ChatDto =
proc isPublicChat*(chatDto: ChatDto): bool =
return chatDto.chatType == ChatType.Public
proc isOneToOneChat*(chatDto: ChatDto): bool =
return chatDto.chatType == ChatType.OneToOne