diff --git a/src/app/modules/main/module.nim b/src/app/modules/main/module.nim index fa2731adea..a6b1a29a2d 100644 --- a/src/app/modules/main/module.nim +++ b/src/app/modules/main/module.nim @@ -959,6 +959,7 @@ method getContactDetailsAsJson*[T](self: Module[T], publicKey: string, getVerifi "removed": contact.removed, "trustStatus": contact.trustStatus.int, # TODO rename verificationStatus to outgoingVerificationStatus + "contactRequestState": contact.contactRequestState.int, "verificationStatus": contact.verificationStatus.int, "incomingVerificationStatus": requestStatus, "hasAddedUs": contact.hasAddedUs, diff --git a/src/app/modules/main/profile_section/contacts/module.nim b/src/app/modules/main/profile_section/contacts/module.nim index e90f202fed..7cc72effba 100644 --- a/src/app/modules/main/profile_section/contacts/module.nim +++ b/src/app/modules/main/profile_section/contacts/module.nim @@ -134,7 +134,7 @@ proc addItemToAppropriateModel(self: Module, item: UserItem) = self.view.blockedContactsModel().addItem(item) return - case contact.requestState: + case contact.contactRequestState: of ContactRequestState.Received: self.view.receivedContactRequestsModel().addItem(item) of ContactRequestState.Sent: diff --git a/src/app_service/service/contacts/dto/contacts.nim b/src/app_service/service/contacts/dto/contacts.nim index aa3f5c02f3..88d04523fe 100644 --- a/src/app_service/service/contacts/dto/contacts.nim +++ b/src/app_service/service/contacts/dto/contacts.nim @@ -60,7 +60,7 @@ type ContactsDto* = object isSyncing*: bool removed*: bool trustStatus*: TrustStatus - requestState*: ContactRequestState + contactRequestState*: ContactRequestState verificationStatus*: VerificationStatus proc `$`(self: Images): string = @@ -144,10 +144,10 @@ 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.contactRequestState = ContactRequestState.None + var contactRequestState: int + discard jsonObj.getProp("contactRequestState", contactRequestState) + result.contactRequestState = contactRequestState.toContactRequestState() result.trustStatus = TrustStatus.Unknown var trustStatusInt: int @@ -194,7 +194,7 @@ proc isContactRequestReceived*(self: ContactsDto): bool = return self.hasAddedUs proc isReceivedContactRequestRejected*(self: ContactsDto): bool = - return self.requestState == ContactRequestState.Dismissed + return self.contactRequestState == ContactRequestState.Dismissed proc isContactRequestSent*(self: ContactsDto): bool = return self.added diff --git a/src/app_service/service/contacts/service.nim b/src/app_service/service/contacts/service.nim index ae94491537..df1f68f8b4 100644 --- a/src/app_service/service/contacts/service.nim +++ b/src/app_service/service/contacts/service.nim @@ -421,6 +421,8 @@ QtObject: contact.added = true contact.blocked = false contact.removed = false + contact.contactRequestState = ContactRequestState.Sent + self.saveContact(contact) self.events.emit(SIGNAL_CONTACT_ADDED, ContactArgs(contactId: contact.id)) self.activityCenterService.parseActivityCenterResponse(response) @@ -445,6 +447,8 @@ QtObject: var contact = self.getContactById(publicKey) contact.added = true contact.removed = false + contact.contactRequestState = ContactRequestState.Mutual + self.saveContact(contact) self.events.emit(SIGNAL_CONTACT_ADDED, ContactArgs(contactId: contact.id)) self.activityCenterService.parseActivityCenterResponse(response) @@ -467,6 +471,8 @@ QtObject: return var contact = self.getContactById(publicKey) contact.removed = true + contact.contactRequestState = ContactRequestState.Dismissed + self.saveContact(contact) self.events.emit(SIGNAL_CONTACT_REMOVED, ContactArgs(contactId: contact.id)) self.activityCenterService.parseActivityCenterResponse(response) @@ -523,6 +529,7 @@ QtObject: contact.removed = true contact.added = false contact.hasAddedUs = false + contact.contactRequestState = ContactRequestState.None self.saveContact(contact) self.events.emit(SIGNAL_CONTACT_REMOVED, ContactArgs(contactId: contact.id)) diff --git a/ui/app/mainui/activitycenter/stores/ActivityCenterStore.qml b/ui/app/mainui/activitycenter/stores/ActivityCenterStore.qml index c413bc787f..ed4c56b642 100644 --- a/ui/app/mainui/activitycenter/stores/ActivityCenterStore.qml +++ b/ui/app/mainui/activitycenter/stores/ActivityCenterStore.qml @@ -43,6 +43,12 @@ QtObject { Declined = 3 } + enum ActivityCenterContactRequestState { + Pending = 1, + Accepted = 2, + Dismissed = 3 + } + readonly property var activityCenterModuleInst: activityCenterModule readonly property var activityCenterNotifications: activityCenterModuleInst.activityNotificationsModel diff --git a/ui/app/mainui/activitycenter/views/ActivityNotificationContactRequest.qml b/ui/app/mainui/activitycenter/views/ActivityNotificationContactRequest.qml index 7bf8864530..3796f26736 100644 --- a/ui/app/mainui/activitycenter/views/ActivityNotificationContactRequest.qml +++ b/ui/app/mainui/activitycenter/views/ActivityNotificationContactRequest.qml @@ -11,13 +11,14 @@ import utils 1.0 import "../panels" import "../popups" +import "../stores" ActivityNotificationMessage { id: root - readonly property bool pending: notification && notification.message.contactRequestState === Constants.contactRequestStatePending - readonly property bool accepted: notification && notification.message.contactRequestState === Constants.contactRequestStateAccepted - readonly property bool dismissed: notification && notification.message.contactRequestState === Constants.contactRequestStateDismissed + readonly property bool pending: notification && notification.message.contactRequestState === ActivityCenterStore.ActivityCenterContactRequestState.Pending + readonly property bool accepted: notification && notification.message.contactRequestState === ActivityCenterStore.ActivityCenterContactRequestState.Accepted + readonly property bool dismissed: notification && notification.message.contactRequestState === ActivityCenterStore.ActivityCenterContactRequestState.Dismissed readonly property string contactRequestId: notification && notification.message ? notification.message.id : "" diff --git a/ui/imports/shared/views/ProfileDialogView.qml b/ui/imports/shared/views/ProfileDialogView.qml index 60802c3c31..10c136ae1e 100644 --- a/ui/imports/shared/views/ProfileDialogView.qml +++ b/ui/imports/shared/views/ProfileDialogView.qml @@ -66,8 +66,7 @@ Pane { readonly property bool isContact: contactDetails.isContact readonly property bool isBlocked: contactDetails.isBlocked - readonly property bool isContactRequestSent: contactDetails.isAdded - readonly property bool isContactRequestReceived: contactDetails.hasAddedUs + readonly property int contactRequestState: contactDetails.contactRequestState readonly property int outgoingVerificationStatus: contactDetails.verificationStatus readonly property int incomingVerificationStatus: contactDetails.incomingVerificationStatus @@ -362,41 +361,31 @@ Pane { if (d.isBlocked) return btnUnblockUserComponent - // contact request, outgoing, rejected - if (!d.isContact && d.isContactRequestSent && d.outgoingVerificationStatus === Constants.verificationStatus.declined) - return txtRejectedContactRequestComponent - - // contact request, outgoing, pending - if (!d.isContact && d.isContactRequestSent) - return txtPendingContactRequestComponent - - // contact request, incoming, pending - if (!d.isContact && d.isContactRequestReceived) { - return btnAcceptContactRequestComponent - } - - // contact request, incoming, rejected - if (d.isContactRequestSent && d.incomingVerificationStatus === Constants.verificationStatus.declined) - return btnBlockUserComponent - - // verified contact request, incoming, pending - if (d.isContact && !d.isTrusted && d.isVerificationRequestReceived) - return btnRespondToIdRequestComponent - // block user - if (!d.isContact && !d.isBlocked && - (d.contactDetails.trustStatus === Constants.trustStatus.untrustworthy || d.outgoingVerificationStatus === Constants.verificationStatus.declined)) + if (d.contactDetails.trustStatus === Constants.trustStatus.untrustworthy) return btnBlockUserComponent - // send contact request - if (!d.isContact && !d.isBlocked && !d.isContactRequestSent) - return btnSendContactRequestComponent - - // send message - if (d.isContact && !d.isBlocked) + // depend on contactRequestState + switch (d.contactRequestState) { + case Constants.ContactRequestState.Sent: + return txtPendingContactRequestComponent + case Constants.ContactRequestState.Received: + return btnAcceptContactRequestComponent + case Constants.ContactRequestState.Mutual: { + if (d.incomingVerificationStatus === Constants.verificationStatus.declined) { + return btnBlockUserComponent + } else if (!d.isTrusted && d.isVerificationRequestReceived) { + return btnRespondToIdRequestComponent + } return btnSendMessageComponent - - console.warn("!!! UNHANDLED CONTACT ACTION BUTTON; PUBKEY", root.publicKey) + } + case Constants.ContactRequestState.None: + case Constants.ContactRequestState.Dismissed: + return btnSendContactRequestComponent + default: + console.warn("!!! UNHANDLED CONTACT ACTION BUTTON; PUBKEY", root.publicKey) + return null + } } } @@ -417,9 +406,9 @@ Pane { StatusMenu { id: moreMenu width: 230 - + // FIXME: raly on contactRequestState !!! SendContactRequestMenuItem { - enabled: !d.isContact && !d.isBlocked && !d.isContactRequestSent && !d.contactDetails.removed && + enabled: !d.isContact && !d.isBlocked && !d.contactRequestState === Constants.ContactRequestState.Sent && d.contactDetails.trustStatus === Constants.trustStatus.untrustworthy // we have an action button otherwise onTriggered: { moreMenu.close() @@ -513,7 +502,7 @@ Pane { text: qsTr("Remove Contact") icon.name: "remove-contact" type: StatusAction.Type.Danger - enabled: d.isContact && !d.isBlocked + enabled: d.isContact && !d.isBlocked && d.contactRequestState !== Constants.ContactRequestState.Sent onTriggered: { moreMenu.close() removeContactConfirmationDialog.open() diff --git a/ui/imports/utils/Constants.qml b/ui/imports/utils/Constants.qml index ea8c39b7ef..a4957cc5e2 100644 --- a/ui/imports/utils/Constants.qml +++ b/ui/imports/utils/Constants.qml @@ -705,11 +705,6 @@ QtObject { readonly property int communityChatInvitationOnlyAccess: 2 readonly property int communityChatOnRequestAccess: 3 - readonly property int contactRequestStateNone: 0 - readonly property int contactRequestStatePending: 1 - readonly property int contactRequestStateAccepted: 2 - readonly property int contactRequestStateDismissed: 3 - readonly property int maxNbDaysToFetch: 30 readonly property int fetchRangeLast24Hours: 86400 readonly property int fetchRangeLast2Days: 172800 @@ -898,6 +893,14 @@ QtObject { Deployed } + enum ContactRequestState { + None = 0, + Mutual = 1, + Sent = 2, + Received = 3, + Dismissed = 4 + } + readonly property QtObject walletSection: QtObject { readonly property string cancelledMessage: "cancelled" }