From 88670ec5d0cefe97b2102bd7b9fba7313ef0d341 Mon Sep 17 00:00:00 2001 From: Pascal Precht <445106+PascalPrecht@users.noreply.github.com> Date: Wed, 9 Nov 2022 13:40:26 +0100 Subject: [PATCH] fix(Contacts): use `ContactRequestState` to filter out rejected requests There's a bug in determining pending incoming contact requests where we don't honor already rejected ones. Simply checking if a contact in question `hasAddedUs` isn't enough because that only tells us if the contact has sent us a request in the past. It doesn't tell is whether the request was rejected already. As a result, rejected contact requests keep popping up in the UI after restarting the app. See #8156 for more information. This commit introduces a `ContactRequestState` enum in Status Desktop, similar to how it exists in status-go. Using this as `requestState` on `ContactDto`, we can easily figure out what's the request state for any given contact. Notices that this only makes use of `ContactRequestState` to check for whether a request was rejected. We probably want to consider using this for all other states as well (instead of relying on system tags). Closes #8156 --- .../service/contacts/dto/contacts.nim | 28 +++++++++++++++---- src/app_service/service/contacts/service.nim | 13 ++++----- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/src/app_service/service/contacts/dto/contacts.nim b/src/app_service/service/contacts/dto/contacts.nim index 542756eba0..18b42abd3c 100644 --- a/src/app_service/service/contacts/dto/contacts.nim +++ b/src/app_service/service/contacts/dto/contacts.nim @@ -16,6 +16,14 @@ type TrustStatus* {.pure.}= enum Trusted = 1, Untrustworthy = 2 + +type ContactRequestState* {.pure.} = enum + None = 0 + Mutual = 1 + Sent = 2 + Received = 3 + Dismissed = 4 + type VerificationStatus* {.pure.}= enum Unverified = 0 Verifying = 1 @@ -51,6 +59,7 @@ type ContactsDto* = object isSyncing*: bool removed*: bool trustStatus*: TrustStatus + requestState*: ContactRequestState verificationStatus*: VerificationStatus proc `$`(self: Images): string = @@ -92,6 +101,11 @@ proc toImages(jsonObj: JsonNode): Images = if(jsonObj.getProp("thumbnail", thumbnailObj)): discard thumbnailObj.getProp("uri", result.thumbnail) +proc toContactRequestState*(value: int): ContactRequestState = + result = ContactRequestState.None + if value >= ord(low(ContactRequestState)) or value <= ord(high(ContactRequestState)): + result = ContactRequestState(value) + proc toTrustStatus*(value: int): TrustStatus = result = TrustStatus.Unknown if value >= ord(low(TrustStatus)) or value <= ord(high(TrustStatus)): @@ -126,6 +140,12 @@ proc toContactsDto*(jsonObj: JsonNode): ContactsDto = discard jsonObj.getProp("localNickname", result.localNickname) discard jsonObj.getProp("bio", result.bio) + + result.requestState = ContactRequestState.None + var requestState: int + discard jsonObj.getProp("contactRequestState", requestState) + result.requestState = requestState.toContactRequestState() + result.trustStatus = TrustStatus.Unknown var trustStatusInt: int discard jsonObj.getProp("trustStatus", trustStatusInt) @@ -170,6 +190,9 @@ proc userOptionalName*(contact: ContactsDto): string = proc isContactRequestReceived*(self: ContactsDto): bool = return self.hasAddedUs +proc isReceivedContactRequestRejected*(self: ContactsDto): bool = + return self.requestState == ContactRequestState.Dismissed + proc isContactRequestSent*(self: ContactsDto): bool = return self.added @@ -182,11 +205,6 @@ proc isContactRemoved*(self: ContactsDto): bool = # # We don't have this prop for now. # return false -# Temporary commented until we provide appropriate flags on the `status-go` side to cover all sections. -# proc isReceivedContactRequestRejected*(self: ContactsDto): bool = -# # We need to check this. -# return self.removed - proc isBlocked*(self: ContactsDto): bool = return self.blocked diff --git a/src/app_service/service/contacts/service.nim b/src/app_service/service/contacts/service.nim index e8d128286b..65d4494bd8 100644 --- a/src/app_service/service/contacts/service.nim +++ b/src/app_service/service/contacts/service.nim @@ -233,7 +233,7 @@ QtObject: x.isContactRequestReceived() and not x.isContactRequestSent() and not x.isContactRemoved() and - # not x.isReceivedContactRequestRejected() and + not x.isReceivedContactRequestRejected() and not x.isBlocked()) elif (group == ContactsGroup.OutgoingPendingContactRequests): return contacts.filter(x => x.id != myPubKey and @@ -242,12 +242,11 @@ QtObject: # not x.isSentContactRequestRejected() and not x.isContactRemoved() and not x.isBlocked()) - # Temporary commented until we provide appropriate flags on the `status-go` side to cover all sections. - # elif (group == ContactsGroup.IncomingRejectedContactRequests): - # return contacts.filter(x => x.id != myPubKey and - # x.isContactRequestReceived() and - # x.isReceivedContactRequestRejected() and - # not x.isBlocked()) + elif (group == ContactsGroup.IncomingRejectedContactRequests): + return contacts.filter(x => x.id != myPubKey and + x.isContactRequestReceived() and + x.isReceivedContactRequestRejected() and + not x.isBlocked()) # elif (group == ContactsGroup.OutgoingRejectedContactRequests): # return contacts.filter(x => x.id != myPubKey and # x.isContactRequestSent() and