fix(@desktop/profile): chat confirmation notification

fixes #2637

When changing a contact, the notification about being able to chat was sent again.
Prevent this behaviour by ensuring the contact hasn't already been added
This commit is contained in:
Anthony Laibe 2021-07-13 10:33:32 +02:00 committed by Iuri Matias
parent d10ffd56ce
commit b31bd265c5
3 changed files with 14 additions and 11 deletions

View File

@ -119,9 +119,8 @@ proc init*(self: ProfileController, account: Account) =
let msgData = MessageSignal(e);
if msgData.contacts.len > 0:
# TODO: view should react to model changes
self.status.chat.updateContacts(msgData.contacts)
self.view.contacts.updateContactList(msgData.contacts)
self.view.contacts.notifyOnNewContactRequests(msgData.contacts)
self.status.chat.updateContacts(msgData.contacts)
if msgData.installations.len > 0:
self.view.devices.addDevices(msgData.installations)

View File

@ -137,6 +137,7 @@ QtObject:
c.ensName = contact.ensName
c.ensVerified = contact.ensVerified
c.identityImage = contact.identityImage
c.systemTags = contact.systemTags
if not found:
self.addContactToList(contact)

View File

@ -64,16 +64,26 @@ QtObject:
result.setup
proc contactListChanged*(self: ContactsView) {.signal.}
proc contactRequestAdded*(self: ContactsView, name: string, address: string) {.signal.}
proc updateContactList*(self: ContactsView, contacts: seq[Profile]) =
for contact in contacts:
var requestAlreadyAdded = false
for existingContact in self.contactList.contacts:
if existingContact.address == contact.address and existingContact.requestReceived():
requestAlreadyAdded = true
break
self.contactList.updateContact(contact)
if contact.systemTags.contains(contactAdded):
self.addedContacts.updateContact(contact)
if contact.systemTags.contains(contactBlocked):
if contact.isBlocked():
self.blockedContacts.updateContact(contact)
if contact.systemTags.contains(contactRequest) and not contact.systemTags.contains(contactAdded) and not contact.systemTags.contains(contactBlocked):
if contact.requestReceived() and not contact.systemTags.contains(contactAdded) and not contact.systemTags.contains(contactBlocked):
self.contactRequests.updateContact(contact)
if not requestAlreadyAdded and contact.requestReceived():
self.contactRequestAdded(status_ens.userNameOrAlias(contact), contact.address)
self.contactListChanged()
proc getContactList(self: ContactsView): QVariant {.slot.} =
@ -86,13 +96,6 @@ QtObject:
self.contactRequests.setNewData(contactList.filter(c => c.systemTags.contains(contactRequest) and not c.systemTags.contains(contactAdded) and not c.systemTags.contains(contactBlocked)))
self.contactListChanged()
proc contactRequestAdded*(self: ContactsView, name: string, address: string) {.signal.}
proc notifyOnNewContactRequests*(self: ContactsView, contacts: seq[Profile]) =
for contact in contacts:
if contact.systemTags.contains(contactRequest) and not contact.systemTags.contains(contactBlocked):
self.contactRequestAdded(status_ens.userNameOrAlias(contact), contact.address)
QtProperty[QVariant] list:
read = getContactList
write = setContactList