fix(Contacts): Resolve edge cases while addind/removing a contact

This commit is contained in:
MishkaRogachev 2023-04-18 15:43:28 +04:00 committed by Jonathan Rainville
parent e160e70121
commit 8ff42d0868
3 changed files with 18 additions and 20 deletions

View File

@ -129,22 +129,20 @@ proc addItemToAppropriateModel(self: Module, item: UserItem) =
if(singletonInstance.userProfile.getPubKey() == item.pubKey): if(singletonInstance.userProfile.getPubKey() == item.pubKey):
return return
let contact = self.controller.getContact(item.pubKey()) let contact = self.controller.getContact(item.pubKey())
if(contact.isContactRemoved()):
return if contact.isBlocked():
elif(contact.isBlocked()):
self.view.blockedContactsModel().addItem(item) self.view.blockedContactsModel().addItem(item)
elif(contact.isContact()): return
self.view.myMutualContactsModel().addItem(item)
else: case contact.requestState:
if(contact.isContactRequestReceived() and not contact.isContactRequestSent()): of ContactRequestState.Received:
self.view.receivedContactRequestsModel().addItem(item) self.view.receivedContactRequestsModel().addItem(item)
elif(contact.isContactRequestSent() and not contact.isContactRequestReceived()): of ContactRequestState.Sent:
self.view.sentContactRequestsModel().addItem(item) self.view.sentContactRequestsModel().addItem(item)
# Temporary commented until we provide appropriate flags on the `status-go` side to cover all sections. of ContactRequestState.Mutual:
# elif(contact.isContactRequestReceived() and contact.isReceivedContactRequestRejected()): self.view.myMutualContactsModel().addItem(item)
# self.view.receivedButRejectedContactRequestsModel().addItem(item) else:
# elif(contact.isContactRequestSent() and contact.isSentContactRequestRejected()): return
# self.view.sentButRejectedContactRequestsModel().addItem(item)
proc removeItemWithPubKeyFromAllModels(self: Module, publicKey: string) = proc removeItemWithPubKeyFromAllModels(self: Module, publicKey: string) =
self.view.myMutualContactsModel().removeItemById(publicKey) self.view.myMutualContactsModel().removeItemById(publicKey)
@ -172,9 +170,6 @@ method contactUnblocked*(self: Module, publicKey: string) =
method contactRemoved*(self: Module, publicKey: string) = method contactRemoved*(self: Module, publicKey: string) =
self.removeIfExistsAndAddToAppropriateModel(publicKey) self.removeIfExistsAndAddToAppropriateModel(publicKey)
method contactRequestRejectionRemoved*(self: Module, publicKey: string) =
self.removeIfExistsAndAddToAppropriateModel(publicKey)
method contactUpdated*(self: Module, publicKey: string) = method contactUpdated*(self: Module, publicKey: string) =
self.removeIfExistsAndAddToAppropriateModel(publicKey) self.removeIfExistsAndAddToAppropriateModel(publicKey)

View File

@ -48,6 +48,9 @@ QtObject:
self.endResetModel() self.endResetModel()
self.countChanged() self.countChanged()
for item in items:
self.itemChanged(item.pubKey)
proc `$`*(self: Model): string = proc `$`*(self: Model): string =
for i in 0 ..< self.items.len: for i in 0 ..< self.items.len:
result &= fmt"""User Model: result &= fmt"""User Model:

View File

@ -358,6 +358,10 @@ Pane {
if (d.isCurrentUser) if (d.isCurrentUser)
return btnEditProfileComponent return btnEditProfileComponent
// blocked contact
if (d.isBlocked)
return btnUnblockUserComponent
// contact request, outgoing, rejected // contact request, outgoing, rejected
if (!d.isContact && d.isContactRequestSent && d.outgoingVerificationStatus === Constants.verificationStatus.declined) if (!d.isContact && d.isContactRequestSent && d.outgoingVerificationStatus === Constants.verificationStatus.declined)
return txtRejectedContactRequestComponent return txtRejectedContactRequestComponent
@ -388,10 +392,6 @@ Pane {
if (!d.isContact && !d.isBlocked && !d.isContactRequestSent) if (!d.isContact && !d.isBlocked && !d.isContactRequestSent)
return btnSendContactRequestComponent return btnSendContactRequestComponent
// blocked contact
if (d.isBlocked)
return btnUnblockUserComponent
// send message // send message
if (d.isContact && !d.isBlocked) if (d.isContact && !d.isBlocked)
return btnSendMessageComponent return btnSendMessageComponent