fix(Contacts): Use contactRequestState enum for determinating correct contact state
This commit is contained in:
parent
8ff42d0868
commit
206800bd5b
|
@ -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,
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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 : ""
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue