fix(1-1): fix contact label not updating when mutual contact changes

Fixes #5709
This commit is contained in:
Jonathan Rainville 2022-05-11 14:17:31 -04:00
parent e6f809b921
commit 416cedd033
7 changed files with 67 additions and 11 deletions

View File

@ -17,6 +17,7 @@ QtObject:
notificationsCount: int
muted: bool
position: int
isMutualContact: bool
proc delete*(self: ChatDetails) =
self.QObject.delete
@ -26,8 +27,9 @@ QtObject:
result.QObject.setup
proc setChatDetails*(self: ChatDetails, id: string, `type`: int, belongsToCommunity,
isUsersListAvailable: bool, name, icon: string, color, description,
emoji: string, hasUnreadMessages: bool, notificationsCount: int, muted: bool, position: int) =
isUsersListAvailable: bool, name, icon: string, color, description,
emoji: string, hasUnreadMessages: bool, notificationsCount: int, muted: bool, position: int,
isMutualContact: bool = false) =
self.id = id
self.`type` = `type`
self.belongsToCommunity = belongsToCommunity
@ -41,6 +43,7 @@ QtObject:
self.notificationsCount = notificationsCount
self.muted = muted
self.position = position
self.isMutualContact = isMutualContact
proc getId(self: ChatDetails): string {.slot.} =
return self.id
@ -160,3 +163,14 @@ QtObject:
proc setPotion*(self: ChatDetails, value: int) = # this is not a slot
self.position = value
self.positionChanged()
proc isMutualContactChanged(self: ChatDetails) {.signal.}
proc getIsMutualContact(self: ChatDetails): bool {.slot.} =
return self.isMutualContact
QtProperty[bool] isMutualContact:
read = getIsMutualContact
notify = isMutualContactChanged
proc setIsMutualContact*(self: ChatDetails, value: bool) = # this is not a slot
self.isMutualContact = value
self.isMutualContactChanged()

View File

@ -30,6 +30,9 @@ type
communityService: community_service.Service
messageService: message_service.Service
# Forward declaration
proc getChatDetails*(self: Controller): ChatDto
proc newController*(delegate: io_interface.AccessInterface, events: EventEmitter, sectionId: string, chatId: string,
belongsToCommunity: bool, isUsersListAvailable: bool, settingsService: settings_service.Service,
contactService: contact_service.Service, chatService: chat_service.Service,
@ -106,6 +109,30 @@ proc init*(self: Controller) =
self.events.on(SIGNAL_CONTACT_UPDATED) do(e: Args):
var args = ContactArgs(e)
self.delegate.onContactDetailsUpdated(args.contactId)
if (args.contactId == self.chatId):
self.delegate.onMutualContactChanged()
let chatDto = self.getChatDetails()
if(chatDto.chatType == ChatType.OneToOne):
self.events.on(SIGNAL_CONTACT_ADDED) do(e: Args):
var args = ContactArgs(e)
if (args.contactId == self.chatId):
self.delegate.onMutualContactChanged()
self.events.on(SIGNAL_CONTACT_REMOVED) do(e: Args):
var args = ContactArgs(e)
if (args.contactId == self.chatId):
self.delegate.onMutualContactChanged()
self.events.on(SIGNAL_CONTACT_BLOCKED) do(e: Args):
var args = ContactArgs(e)
if (args.contactId == self.chatId):
self.delegate.onMutualContactChanged()
self.events.on(SIGNAL_CONTACT_UNBLOCKED) do(e: Args):
var args = ContactArgs(e)
if (args.contactId == self.chatId):
self.delegate.onMutualContactChanged()
self.events.on(SIGNAL_MESSAGE_DELETION) do(e: Args):
let args = MessageDeletedArgs(e)

View File

@ -111,3 +111,6 @@ method amIChatAdmin*(self: AccessInterface): bool {.base.} =
method downloadMessages*(self: AccessInterface, filePath: string) =
raise newException(ValueError, "No implementation available")
method onMutualContactChanged*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -75,13 +75,18 @@ method load*(self: Module) =
let notificationsCount = chatDto.unviewedMentionsCount
var chatName = chatDto.name
var chatImage = chatDto.icon
var isMutualContact = false
if(chatDto.chatType == ChatType.OneToOne):
(chatName, chatImage) = self.controller.getOneToOneChatNameAndImage()
let contactDto = self.controller.getContactById(self.controller.getMyChatId())
chatName = contactDto.userNameOrAlias()
isMutualContact = contactDto.isMutualContact
if(contactDto.image.thumbnail.len > 0):
chatImage = contactDto.image.thumbnail
self.view.load(chatDto.id, chatDto.chatType.int, self.controller.belongsToCommunity(),
self.controller.isUsersListAvailable(), chatName, chatImage,
chatDto.color, chatDto.description, chatDto.emoji, hasNotification, notificationsCount,
chatDto.muted, chatDto.position)
chatDto.muted, chatDto.position, isMutualContact)
self.inputAreaModule.load()
self.messagesModule.load()
@ -335,3 +340,8 @@ method onChatRenamed*(self: Module, newName: string) =
method downloadMessages*(self: Module, filePath: string) =
let messages = self.messagesModule.getMessages()
self.controller.downloadMessages(messages, filePath)
method onMutualContactChanged*(self: Module) =
let contactDto = self.controller.getContactById(self.controller.getMyChatId())
let isMutualContact = contactDto.isMutualContact
self.view.onMutualContactChanged(isMutualContact)

View File

@ -31,10 +31,10 @@ QtObject:
result.chatDetailsVariant = newQVariant(result.chatDetails)
proc load*(self: View, id: string, `type`: int, belongsToCommunity, isUsersListAvailable: bool,
name, icon: string, color, description, emoji: string,
hasUnreadMessages: bool, notificationsCount: int, muted: bool, position: int) =
name, icon: string, color, description, emoji: string, hasUnreadMessages: bool,
notificationsCount: int, muted: bool, position: int, isMutualContact: bool) =
self.chatDetails.setChatDetails(id, `type`, belongsToCommunity, isUsersListAvailable, name, icon,
color, description, emoji, hasUnreadMessages, notificationsCount, muted, position)
color, description, emoji, hasUnreadMessages, notificationsCount, muted, position, isMutualContact)
self.delegate.viewDidLoad()
self.chatDetailsChanged()
@ -123,5 +123,8 @@ QtObject:
self.chatDetails.setName(name)
self.chatDetailsChanged()
proc onMutualContactChanged*(self: View, value: bool) =
self.chatDetails.setIsMutualContact(value)
proc downloadMessages*(self: View, filePath: string) {.slot.} =
self.delegate.downloadMessages(filePath)

View File

@ -120,7 +120,7 @@ proc isBlocked*(self: ContactsDto): bool =
proc isMutualContact*(self: ContactsDto): bool =
# TODO not implemented in `status-go` yet
# But for now we consider that contact is mutual contact if I added him and he added me.
return self.hasAddedUs and self.added
return self.hasAddedUs and self.added and not self.removed and not self.blocked
proc isContactVerified*(self: ContactsDto): bool =
# TODO not implemented in `status-go` yet

View File

@ -197,9 +197,7 @@ QtObject:
elif (group == ContactsGroup.MyMutualContacts):
# we need to revise this when we introduce "identity verification" feature
return contacts.filter(x => x.id != myPubKey and
x.isMutualContact() and
not x.isContactRemoved() and
not x.isBlocked())
x.isMutualContact())
elif (group == ContactsGroup.AllKnownContacts):
return contacts
@ -322,6 +320,7 @@ QtObject:
var contact = self.getContactById(publicKey)
contact.added = true
contact.removed = false
self.saveContact(contact)
self.events.emit(SIGNAL_CONTACT_ADDED, ContactArgs(contactId: contact.id))