Fix(Contacts): fix weird behaviour in some contacts flows edge cases (#10613)
* fix(Chat): Fix displaying CR messages in the chat * fix(Contacts): Relay on actual status-go state during contact state manipulation Close #10500
This commit is contained in:
parent
41c6addc3e
commit
3a030102fe
|
@ -88,6 +88,7 @@ proc `$`*(self: ContactsDto): string =
|
||||||
isSyncing:{self.isSyncing},
|
isSyncing:{self.isSyncing},
|
||||||
removed:{self.removed},
|
removed:{self.removed},
|
||||||
trustStatus:{self.trustStatus},
|
trustStatus:{self.trustStatus},
|
||||||
|
contactRequestState:{self.contactRequestState},
|
||||||
verificationStatus:{self.verificationStatus},
|
verificationStatus:{self.verificationStatus},
|
||||||
)"""
|
)"""
|
||||||
|
|
||||||
|
|
|
@ -101,6 +101,7 @@ QtObject:
|
||||||
proc getContactById*(self: Service, id: string): ContactsDto
|
proc getContactById*(self: Service, id: string): ContactsDto
|
||||||
proc saveContact(self: Service, contact: ContactsDto)
|
proc saveContact(self: Service, contact: ContactsDto)
|
||||||
proc fetchReceivedVerificationRequests*(self: Service) : seq[VerificationRequest]
|
proc fetchReceivedVerificationRequests*(self: Service) : seq[VerificationRequest]
|
||||||
|
proc requestContactInfo*(self: Service, pubkey: string)
|
||||||
|
|
||||||
proc delete*(self: Service) =
|
proc delete*(self: Service) =
|
||||||
self.closingApp = true
|
self.closingApp = true
|
||||||
|
@ -361,16 +362,17 @@ QtObject:
|
||||||
|
|
||||||
let alias = self.generateAlias(pubkey)
|
let alias = self.generateAlias(pubkey)
|
||||||
let trustStatus = self.getTrustStatus(pubkey)
|
let trustStatus = self.getTrustStatus(pubkey)
|
||||||
result = ContactsDto(
|
let contact = ContactsDto(
|
||||||
id: pubkey,
|
id: pubkey,
|
||||||
alias: alias,
|
alias: alias,
|
||||||
ensVerified: false,
|
ensVerified: result.ensVerified,
|
||||||
added: false,
|
added: result.added,
|
||||||
blocked: false,
|
blocked: result.blocked,
|
||||||
hasAddedUs: false,
|
hasAddedUs: result.hasAddedUs,
|
||||||
trustStatus: trustStatus
|
trustStatus: trustStatus
|
||||||
)
|
)
|
||||||
self.addContact(result)
|
self.addContact(contact)
|
||||||
|
return contact
|
||||||
|
|
||||||
proc getStatusForContactWithId*(self: Service, publicKey: string): StatusUpdateDto =
|
proc getStatusForContactWithId*(self: Service, publicKey: string): StatusUpdateDto =
|
||||||
if publicKey == singletonInstance.userProfile.getPubKey():
|
if publicKey == singletonInstance.userProfile.getPubKey():
|
||||||
|
@ -407,28 +409,39 @@ QtObject:
|
||||||
# we must keep local contacts updated
|
# we must keep local contacts updated
|
||||||
self.contacts[contact.id] = contact
|
self.contacts[contact.id] = contact
|
||||||
|
|
||||||
proc sendContactRequest*(self: Service, chatKey: string, message: string) =
|
proc updateContact(self: Service, contact: ContactsDto) =
|
||||||
try:
|
var signal = SIGNAL_CONTACT_ADDED
|
||||||
let publicKey = status_accounts.decompressPk(chatKey).result
|
let publicKey = contact.id
|
||||||
|
if self.contacts.hasKey(publicKey):
|
||||||
|
if self.contacts[publicKey].added and not self.contacts[publicKey].removed and contact.added and not contact.removed:
|
||||||
|
signal = SIGNAL_CONTACT_UPDATED
|
||||||
|
if contact.removed:
|
||||||
|
signal = SIGNAL_CONTACT_REMOVED
|
||||||
|
|
||||||
let response = status_contacts.sendContactRequest(publicKey, message)
|
self.contacts[publicKey] = contact
|
||||||
if(not response.error.isNil):
|
self.events.emit(signal, ContactArgs(contactId: publicKey))
|
||||||
let msg = response.error.message
|
|
||||||
error "error sending contact request", msg
|
|
||||||
return
|
|
||||||
|
|
||||||
var contact = self.getContactById(publicKey)
|
proc parseContactsResponse*(self: Service, response: RpcResponse[JsonNode]) =
|
||||||
contact.added = true
|
if response.result["contacts"] != nil:
|
||||||
contact.blocked = false
|
for contactJson in response.result["contacts"]:
|
||||||
contact.removed = false
|
self.updateContact(contactJson.toContactsDto())
|
||||||
contact.contactRequestState = ContactRequestState.Sent
|
# NOTE: this response may also contain chats and messages
|
||||||
|
|
||||||
self.saveContact(contact)
|
|
||||||
self.events.emit(SIGNAL_CONTACT_ADDED, ContactArgs(contactId: contact.id))
|
|
||||||
self.activityCenterService.parseActivityCenterResponse(response)
|
self.activityCenterService.parseActivityCenterResponse(response)
|
||||||
|
|
||||||
|
proc sendContactRequest*(self: Service, publicKey: string, message: string) =
|
||||||
|
# Prefetch contact to avoid race condition with AC notification
|
||||||
|
discard self.getContactById(publicKey)
|
||||||
|
|
||||||
|
try:
|
||||||
|
let response = status_contacts.sendContactRequest(publicKey, message)
|
||||||
|
if not response.error.isNil:
|
||||||
|
error "error sending contact request", msg = response.error.message
|
||||||
|
return
|
||||||
|
|
||||||
|
self.parseContactsResponse(response)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
error "an error occurred while sending contact request", msg=e.msg
|
error "an error occurred while sending contact request", msg = e.msg
|
||||||
|
|
||||||
proc acceptContactRequest*(self: Service, publicKey: string, contactRequestId: string) =
|
proc acceptContactRequest*(self: Service, publicKey: string, contactRequestId: string) =
|
||||||
try:
|
try:
|
||||||
|
@ -439,19 +452,11 @@ QtObject:
|
||||||
else:
|
else:
|
||||||
status_contacts.acceptLatestContactRequestForContact(publicKey)
|
status_contacts.acceptLatestContactRequestForContact(publicKey)
|
||||||
|
|
||||||
if (not response.error.isNil):
|
if not response.error.isNil:
|
||||||
let msg = response.error.message
|
error "error accepting contact request", msg = response.error.message
|
||||||
error "error accepting contact request", msg
|
|
||||||
return
|
return
|
||||||
|
|
||||||
var contact = self.getContactById(publicKey)
|
self.parseContactsResponse(response)
|
||||||
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)
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
error "an error occurred while accepting contact request", msg=e.msg
|
error "an error occurred while accepting contact request", msg=e.msg
|
||||||
|
@ -465,17 +470,12 @@ QtObject:
|
||||||
else:
|
else:
|
||||||
status_contacts.dismissLatestContactRequestForContact(publicKey)
|
status_contacts.dismissLatestContactRequestForContact(publicKey)
|
||||||
|
|
||||||
if(not response.error.isNil):
|
if not response.error.isNil:
|
||||||
let msg = response.error.message
|
error "error dismissing contact ", msg = response.error.message
|
||||||
error "error dismissing contact ", msg
|
|
||||||
return
|
return
|
||||||
var contact = self.getContactById(publicKey)
|
|
||||||
contact.removed = true
|
|
||||||
contact.contactRequestState = ContactRequestState.Dismissed
|
|
||||||
|
|
||||||
self.saveContact(contact)
|
self.parseContactsResponse(response)
|
||||||
self.events.emit(SIGNAL_CONTACT_REMOVED, ContactArgs(contactId: contact.id))
|
|
||||||
self.activityCenterService.parseActivityCenterResponse(response)
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
error "an error occurred while dismissing contact request", msg=e.msg
|
error "an error occurred while dismissing contact request", msg=e.msg
|
||||||
|
|
||||||
|
@ -484,9 +484,8 @@ QtObject:
|
||||||
contact.localNickname = nickname
|
contact.localNickname = nickname
|
||||||
|
|
||||||
let response = status_contacts.setContactLocalNickname(contact.id, contact.localNickname)
|
let response = status_contacts.setContactLocalNickname(contact.id, contact.localNickname)
|
||||||
if(not response.error.isNil):
|
if not response.error.isNil:
|
||||||
let msg = response.error.message
|
error "error setting local name ", msg = response.error.message
|
||||||
error "error setting local name ", msg
|
|
||||||
return
|
return
|
||||||
self.saveContact(contact)
|
self.saveContact(contact)
|
||||||
let data = ContactArgs(contactId: contact.id)
|
let data = ContactArgs(contactId: contact.id)
|
||||||
|
@ -496,9 +495,8 @@ QtObject:
|
||||||
var contact = self.getContactById(publicKey)
|
var contact = self.getContactById(publicKey)
|
||||||
|
|
||||||
let response = status_contacts.unblockContact(contact.id)
|
let response = status_contacts.unblockContact(contact.id)
|
||||||
if(not response.error.isNil):
|
if not response.error.isNil:
|
||||||
let msg = response.error.message
|
error "error unblocking contact ", msg = response.error.message
|
||||||
error "error unblocking contact ", msg
|
|
||||||
return
|
return
|
||||||
|
|
||||||
contact.blocked = false
|
contact.blocked = false
|
||||||
|
@ -509,9 +507,8 @@ QtObject:
|
||||||
var contact = self.getContactById(publicKey)
|
var contact = self.getContactById(publicKey)
|
||||||
|
|
||||||
let response = status_contacts.blockContact(contact.id)
|
let response = status_contacts.blockContact(contact.id)
|
||||||
if(not response.error.isNil):
|
if not response.error.isNil:
|
||||||
let msg = response.error.message
|
error "error blocking contact ", msg = response.error.message
|
||||||
error "error blocking contact ", msg
|
|
||||||
return
|
return
|
||||||
|
|
||||||
contact.blocked = true
|
contact.blocked = true
|
||||||
|
@ -520,19 +517,11 @@ QtObject:
|
||||||
|
|
||||||
proc removeContact*(self: Service, publicKey: string) =
|
proc removeContact*(self: Service, publicKey: string) =
|
||||||
let response = status_contacts.retractContactRequest(publicKey)
|
let response = status_contacts.retractContactRequest(publicKey)
|
||||||
if(not response.error.isNil):
|
if not response.error.isNil:
|
||||||
let msg = response.error.message
|
error "error removing contact ", msg = response.error.message
|
||||||
error "error removing contact ", msg
|
|
||||||
return
|
return
|
||||||
|
|
||||||
var contact = self.getContactById(publicKey)
|
self.parseContactsResponse(response)
|
||||||
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))
|
|
||||||
|
|
||||||
proc ensResolved*(self: Service, jsonObj: string) {.slot.} =
|
proc ensResolved*(self: Service, jsonObj: string) {.slot.} =
|
||||||
let jsonObj = jsonObj.parseJson()
|
let jsonObj = jsonObj.parseJson()
|
||||||
|
@ -581,8 +570,7 @@ QtObject:
|
||||||
proc markUntrustworthy*(self: Service, publicKey: string) =
|
proc markUntrustworthy*(self: Service, publicKey: string) =
|
||||||
let response = status_contacts.markUntrustworthy(publicKey)
|
let response = status_contacts.markUntrustworthy(publicKey)
|
||||||
if not response.error.isNil:
|
if not response.error.isNil:
|
||||||
let msg = response.error.message
|
error "error marking as untrustworthy ", msg = response.error.message
|
||||||
error "error marking as untrustworthy ", msg
|
|
||||||
return
|
return
|
||||||
|
|
||||||
if self.contacts.hasKey(publicKey):
|
if self.contacts.hasKey(publicKey):
|
||||||
|
@ -643,9 +631,8 @@ QtObject:
|
||||||
|
|
||||||
proc removeTrustStatus*(self: Service, publicKey: string) =
|
proc removeTrustStatus*(self: Service, publicKey: string) =
|
||||||
let response = status_contacts.removeTrustStatus(publicKey)
|
let response = status_contacts.removeTrustStatus(publicKey)
|
||||||
if(not response.error.isNil):
|
if not response.error.isNil:
|
||||||
let msg = response.error.message
|
error "error removing trust status", msg = response.error.message
|
||||||
error "error removing trust status", msg
|
|
||||||
return
|
return
|
||||||
|
|
||||||
if self.contacts.hasKey(publicKey):
|
if self.contacts.hasKey(publicKey):
|
||||||
|
@ -694,9 +681,8 @@ QtObject:
|
||||||
proc sendVerificationRequest*(self: Service, publicKey: string, challenge: string) =
|
proc sendVerificationRequest*(self: Service, publicKey: string, challenge: string) =
|
||||||
try:
|
try:
|
||||||
let response = status_contacts.sendVerificationRequest(publicKey, challenge)
|
let response = status_contacts.sendVerificationRequest(publicKey, challenge)
|
||||||
if(not response.error.isNil):
|
if not response.error.isNil:
|
||||||
let msg = response.error.message
|
error "error sending contact verification request", msg = response.error.message
|
||||||
error "error sending contact verification request", msg
|
|
||||||
return
|
return
|
||||||
|
|
||||||
var contact = self.getContactById(publicKey)
|
var contact = self.getContactById(publicKey)
|
||||||
|
@ -719,8 +705,7 @@ QtObject:
|
||||||
|
|
||||||
response = status_contacts.cancelVerificationRequest(request.id)
|
response = status_contacts.cancelVerificationRequest(request.id)
|
||||||
if not response.error.isNil:
|
if not response.error.isNil:
|
||||||
let msg = response.error.message
|
error "error sending contact verification request", msg = response.error.message
|
||||||
error "error sending contact verification request", msg
|
|
||||||
return
|
return
|
||||||
|
|
||||||
var contact = self.getContactById(publicKey)
|
var contact = self.getContactById(publicKey)
|
||||||
|
|
|
@ -218,6 +218,7 @@ Loader {
|
||||||
case Constants.messageContentType.audioType:
|
case Constants.messageContentType.audioType:
|
||||||
case Constants.messageContentType.communityInviteType:
|
case Constants.messageContentType.communityInviteType:
|
||||||
case Constants.messageContentType.discordMessageType:
|
case Constants.messageContentType.discordMessageType:
|
||||||
|
case Constants.messageContentType.contactRequestType:
|
||||||
return messageComponent
|
return messageComponent
|
||||||
case Constants.messageContentType.unknownContentType:
|
case Constants.messageContentType.unknownContentType:
|
||||||
// NOTE: We could display smth like "unknown message type, please upgrade Status to see it".
|
// NOTE: We could display smth like "unknown message type, please upgrade Status to see it".
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit ac837365be321df8443cafd4c89f256eefde3e1d
|
Subproject commit d55adaf3a486246fa7f266cf0d864cad853db179
|
Loading…
Reference in New Issue