fix(ActivityCenter): Use ContactRequestId for accpeting and declining CRs from AC

Close #10127
This commit is contained in:
MishkaRogachev 2023-04-03 20:27:56 +04:00 committed by Mikhail Rogachev
parent 0ae1881564
commit 2160b53e33
18 changed files with 84 additions and 56 deletions

View File

@ -90,7 +90,7 @@ proc createMessageItemFromDto(self: Module, message: MessageDto, communityId: st
quotedMessageAuthorDetails = contactDetails
else:
quotedMessageAuthorDetails = self.controller.getContactDetails(message.quotedMessage.`from`)
return msg_item_qobj.newMessageItem(msg_item.initItem(
message.id,
communityId, # we don't received community id via `activityCenterNotifications` api call

View File

@ -474,11 +474,11 @@ proc getContactDetails*(self: Controller, id: string): ContactDetails =
proc getStatusForContactWithId*(self: Controller, publicKey: string): StatusUpdateDto =
return self.contactService.getStatusForContactWithId(publicKey)
proc acceptContactRequest*(self: Controller, publicKey: string) =
self.contactService.acceptContactRequest(publicKey)
proc acceptContactRequest*(self: Controller, publicKey: string, contactRequestId: string) =
self.contactService.acceptContactRequest(publicKey, contactRequestId)
proc dismissContactRequest*(self: Controller, publicKey: string) =
self.contactService.dismissContactRequest(publicKey)
proc dismissContactRequest*(self: Controller, publicKey: string, contactRequestId: string) =
self.contactService.dismissContactRequest(publicKey, contactRequestId)
proc blockContact*(self: Controller, publicKey: string) =
self.contactService.blockContact(publicKey)

View File

@ -228,13 +228,13 @@ method clearChatHistory*(self: AccessInterface, chatId: string) {.base.} =
method getCurrentFleet*(self: AccessInterface): string {.base.} =
raise newException(ValueError, "No implementation available")
method acceptContactRequest*(self: AccessInterface, publicKey: string) {.base.} =
method acceptContactRequest*(self: AccessInterface, publicKey: string, contactRequestId: string) {.base.} =
raise newException(ValueError, "No implementation available")
method acceptAllContactRequests*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method dismissContactRequest*(self: AccessInterface, publicKey: string) {.base.} =
method dismissContactRequest*(self: AccessInterface, publicKey: string, contactRequestId: string) {.base.} =
raise newException(ValueError, "No implementation available")
method dismissAllContactRequests*(self: AccessInterface) {.base.} =

View File

@ -852,8 +852,8 @@ method clearChatHistory*(self: Module, chatId: string) =
method getCurrentFleet*(self: Module): string =
return self.controller.getCurrentFleet()
method acceptContactRequest*(self: Module, publicKey: string) =
self.controller.acceptContactRequest(publicKey)
method acceptContactRequest*(self: Module, publicKey: string, contactRequestId: string) =
self.controller.acceptContactRequest(publicKey, contactRequestId)
method onContactAdded*(self: Module, publicKey: string) =
self.view.contactRequestsModel().removeItemById(publicKey)
@ -865,10 +865,10 @@ method onContactAdded*(self: Module, publicKey: string) =
method acceptAllContactRequests*(self: Module) =
let pubKeys = self.view.contactRequestsModel().getItemIds()
for pk in pubKeys:
self.acceptContactRequest(pk)
self.acceptContactRequest(pk, "")
method dismissContactRequest*(self: Module, publicKey: string) =
self.controller.dismissContactRequest(publicKey)
method dismissContactRequest*(self: Module, publicKey: string, contactRequestId: string) =
self.controller.dismissContactRequest(publicKey, contactRequestId)
method onContactRejected*(self: Module, publicKey: string) =
self.view.contactRequestsModel().removeItemById(publicKey)
@ -876,7 +876,7 @@ method onContactRejected*(self: Module, publicKey: string) =
method dismissAllContactRequests*(self: Module) =
let pubKeys = self.view.contactRequestsModel().getItemIds()
for pk in pubKeys:
self.dismissContactRequest(pk)
self.dismissContactRequest(pk, "")
method blockContact*(self: Module, publicKey: string) =
self.controller.blockContact(publicKey)

View File

@ -217,14 +217,14 @@ QtObject:
proc getCurrentFleet*(self: View): string {.slot.} =
self.delegate.getCurrentFleet()
proc acceptContactRequest*(self: View, publicKey: string) {.slot.} =
self.delegate.acceptContactRequest(publicKey)
proc acceptContactRequest*(self: View, publicKey: string, contactRequestId: string) {.slot.} =
self.delegate.acceptContactRequest(publicKey, contactRequestId)
proc acceptAllContactRequests*(self: View) {.slot.} =
self.delegate.acceptAllContactRequests()
proc dismissContactRequest*(self: View, publicKey: string) {.slot.} =
self.delegate.dismissContactRequest(publicKey)
proc dismissContactRequest*(self: View, publicKey: string, contactRequestId: string) {.slot.} =
self.delegate.dismissContactRequest(publicKey, contactRequestId)
proc dismissAllContactRequests*(self: View) {.slot.} =
self.delegate.dismissAllContactRequests()

View File

@ -121,11 +121,11 @@ proc changeContactNickname*(self: Controller, publicKey: string, nickname: strin
proc sendContactRequest*(self: Controller, publicKey: string, message: string) =
self.contactsService.sendContactRequest(publicKey, message)
proc acceptContactRequest*(self: Controller, publicKey: string) =
self.contactsService.acceptContactRequest(publicKey)
proc acceptContactRequest*(self: Controller, publicKey: string, contactRequestId: string) =
self.contactsService.acceptContactRequest(publicKey, contactRequestId)
proc dismissContactRequest*(self: Controller, publicKey: string) =
self.contactsService.dismissContactRequest(publicKey)
proc dismissContactRequest*(self: Controller, publicKey: string, contactRequestId: string) =
self.contactsService.dismissContactRequest(publicKey, contactRequestId)
proc removeContactRequestRejection*(self: Controller, publicKey: string) =
self.contactsService.removeContactRequestRejection(publicKey)

View File

@ -30,10 +30,10 @@ method switchToOrCreateOneToOneChat*(self: AccessInterface, publicKey: string) {
method sendContactRequest*(self: AccessInterface, publicKey: string, message: string) {.base.} =
raise newException(ValueError, "No implementation available")
method acceptContactRequest*(self: AccessInterface, publicKey: string) {.base.} =
method acceptContactRequest*(self: AccessInterface, publicKey: string, contactRequestId: string) {.base.} =
raise newException(ValueError, "No implementation available")
method dismissContactRequest*(self: AccessInterface, publicKey: string) {.base.} =
method dismissContactRequest*(self: AccessInterface, publicKey: string, contactRequestId: string) {.base.} =
raise newException(ValueError, "No implementation available")
method dismissContactRequests*(self: AccessInterface, publicKeysJSON: string) {.base.} =

View File

@ -104,11 +104,11 @@ method getModuleAsVariant*(self: Module): QVariant =
method sendContactRequest*(self: Module, publicKey: string, message: string) =
self.controller.sendContactRequest(publicKey, message)
method acceptContactRequest*(self: Module, publicKey: string) =
self.controller.acceptContactRequest(publicKey)
method acceptContactRequest*(self: Module, publicKey: string, contactRequestId: string) =
self.controller.acceptContactRequest(publicKey, contactRequestId)
method dismissContactRequest*(self: Module, publicKey: string) =
self.controller.dismissContactRequest(publicKey)
method dismissContactRequest*(self: Module, publicKey: string, contactRequestId: string) =
self.controller.dismissContactRequest(publicKey, contactRequestId)
method switchToOrCreateOneToOneChat*(self: Module, publicKey: string) =
self.controller.switchToOrCreateOneToOneChat(publicKey)

View File

@ -137,11 +137,11 @@ QtObject:
proc switchToOrCreateOneToOneChat*(self: View, publicKey: string) {.slot.} =
self.delegate.switchToOrCreateOneToOneChat(publicKey)
proc acceptContactRequest*(self: View, publicKey: string) {.slot.} =
self.delegate.acceptContactRequest(publicKey)
proc acceptContactRequest*(self: View, publicKey: string, contactRequestId: string) {.slot.} =
self.delegate.acceptContactRequest(publicKey, contactRequestId)
proc dismissContactRequest*(self: View, publicKey: string) {.slot.} =
self.delegate.dismissContactRequest(publicKey)
proc dismissContactRequest*(self: View, publicKey: string, contactRequestId: string) {.slot.} =
self.delegate.dismissContactRequest(publicKey, contactRequestId)
proc changeContactNickname*(self: View, publicKey: string, nickname: string) {.slot.} =
self.delegate.changeContactNickname(publicKey, nickname)

View File

@ -22,6 +22,10 @@ QtObject:
proc setMessageItem*(self: MessageItem, messageItem: message_item.Item) =
self.messageItem = messageItem
proc id*(self: MessageItem): string {.slot.} = result = ?.self.messageItem.id
QtProperty[string] id:
read = id
proc responseToMessageWithId*(self: MessageItem): string {.slot.} = result = ?.self.messageItem.responseToMessageWithId
QtProperty[string] responseToMessageWithId:
read = responseToMessageWithId

View File

@ -429,11 +429,16 @@ QtObject:
except Exception as e:
error "an error occurred while sending contact request", msg=e.msg
proc acceptContactRequest*(self: Service, publicKey: string) =
proc acceptContactRequest*(self: Service, publicKey: string, contactRequestId: string) =
try:
# NOTE: publicKey used for accepting last request
let response = status_contacts.acceptLatestContactRequestForContact(publicKey)
if(not response.error.isNil):
let response =
if contactRequestId.len > 0:
status_contacts.acceptContactRequest(contactRequestId)
else:
status_contacts.acceptLatestContactRequestForContact(publicKey)
if (not response.error.isNil):
let msg = response.error.message
error "error accepting contact request", msg
return
@ -448,10 +453,15 @@ QtObject:
except Exception as e:
error "an error occurred while accepting contact request", msg=e.msg
proc dismissContactRequest*(self: Service, publicKey: string) =
proc dismissContactRequest*(self: Service, publicKey: string, contactRequestId: string) =
try:
# NOTE: publicKey used for dismissing last request
let response = status_contacts.dismissLatestContactRequestForContact(publicKey)
let response =
if contactRequestId.len > 0:
status_contacts.declineContactRequest(contactRequestId)
else:
status_contacts.dismissLatestContactRequestForContact(publicKey)
if(not response.error.isNil):
let msg = response.error.message
error "error dismissing contact ", msg

View File

@ -41,12 +41,24 @@ proc acceptLatestContactRequestForContact*(id: string): RpcResponse[JsonNode] {.
}]
result = callPrivateRPC("acceptLatestContactRequestForContact".prefix, payload)
proc acceptContactRequest*(id: string): RpcResponse[JsonNode] {.raises: [Exception].} =
let payload = %* [{
"id": id
}]
result = callPrivateRPC("acceptContactRequest".prefix, payload)
proc dismissLatestContactRequestForContact*(id: string): RpcResponse[JsonNode] {.raises: [Exception].} =
let payload = %*[{
"id": id
}]
result = callPrivateRPC("dismissLatestContactRequestForContact".prefix, payload)
proc declineContactRequest*(id: string): RpcResponse[JsonNode] {.raises: [Exception].} =
let payload = %*[{
"id": id
}]
result = callPrivateRPC("declineContactRequest".prefix, payload)
proc sendContactUpdate*(publicKey, ensName, thumbnail: string): RpcResponse[JsonNode] {.raises: [Exception].} =
let payload = %* [publicKey, ensName, thumbnail]
result = callPrivateRPC("sendContactUpdate".prefix, payload)

View File

@ -153,12 +153,12 @@ SplitView {
logs.logEvent("contactsStore::removeContact", ["publicKey"], arguments)
}
function acceptContactRequest(publicKey) {
logs.logEvent("contactsStore::acceptContactRequest", ["publicKey"], arguments)
function acceptContactRequest(publicKey, contactRequestId) {
logs.logEvent("contactsStore::acceptContactRequest", ["publicKey, contactRequestId"], arguments)
}
function dismissContactRequest(publicKey) {
logs.logEvent("contactsStore::dismissContactRequest", ["publicKey"], arguments)
function dismissContactRequest(publicKey, contactRequestId) {
logs.logEvent("contactsStore::dismissContactRequest", ["publicKey, contactRequestId"], arguments)
}
function removeTrustStatus(publicKey) {

View File

@ -100,16 +100,16 @@ QtObject {
return currentChatContentModule().amIChatAdmin()
}
function acceptContactRequest(pubKey) {
chatCommunitySectionModule.acceptContactRequest(pubKey)
function acceptContactRequest(pubKey, contactRequestId) {
chatCommunitySectionModule.acceptContactRequest(pubKey, contactRequestId)
}
function acceptAllContactRequests() {
chatCommunitySectionModule.acceptAllContactRequests()
}
function dismissContactRequest(pubKey) {
chatCommunitySectionModule.dismissContactRequest(pubKey)
function dismissContactRequest(pubKey, contactRequestId) {
chatCommunitySectionModule.dismissContactRequest(pubKey, contactRequestId)
}
function dismissAllContactRequests() {

View File

@ -69,12 +69,12 @@ QtObject {
root.contactsModule.sendContactRequest(pubKey, message)
}
function acceptContactRequest(pubKey) {
root.contactsModule.acceptContactRequest(pubKey)
function acceptContactRequest(pubKey, contactRequestId) {
root.contactsModule.acceptContactRequest(pubKey, contactRequestId)
}
function dismissContactRequest(pubKey) {
root.contactsModule.dismissContactRequest(pubKey)
function dismissContactRequest(pubKey, contactRequestId) {
root.contactsModule.dismissContactRequest(pubKey, contactRequestId)
}
function removeContactRequestRejection(pubKey) {

View File

@ -202,11 +202,11 @@ SettingsContentBase {
}
onContactRequestAccepted: {
root.contactsStore.acceptContactRequest(publicKey)
root.contactsStore.acceptContactRequest(publicKey, "")
}
onContactRequestRejected: {
root.contactsStore.dismissContactRequest(publicKey)
root.contactsStore.dismissContactRequest(publicKey, "")
}
onShowVerificationRequest: {

View File

@ -19,6 +19,8 @@ ActivityNotificationMessage {
readonly property bool accepted: notification && notification.message.contactRequestState === Constants.contactRequestStateAccepted
readonly property bool dismissed: notification && notification.message.contactRequestState === Constants.contactRequestStateDismissed
readonly property string contactRequestId: notification && notification.message ? notification.message.id : ""
Connections {
target: root.isOutgoingMessage ? root.store.contactsStore.sentContactRequestsModel :
root.store.contactsStore.receivedContactRequestsModel
@ -48,11 +50,11 @@ ActivityNotificationMessage {
accepted: root.accepted
dismissed: root.dismissed
blocked: contactDetails && contactDetails.isBlocked
onAcceptClicked: root.store.contactsStore.acceptContactRequest(root.contactId)
onDeclineClicked: root.store.contactsStore.dismissContactRequest(root.contactId)
onAcceptClicked: root.store.contactsStore.acceptContactRequest(root.contactId, root.contactRequestId)
onDeclineClicked: root.store.contactsStore.dismissContactRequest(root.contactId, root.contactRequestId)
onProfileClicked: Global.openProfilePopup(root.contactId)
onBlockClicked: {
root.store.contactsStore.dismissContactRequest(root.contactId)
root.store.contactsStore.dismissContactRequest(root.contactId, root.contactRequestId)
root.store.contactsStore.blockContact(root.contactId)
}
onDetailsClicked: {
@ -68,8 +70,8 @@ ActivityNotificationMessage {
ReviewContactRequestPopup {
id: reviewRequestPopup
onAccepted: root.store.contactsStore.acceptContactRequest(root.contactId)
onDeclined: root.store.contactsStore.dismissContactRequest(root.contactId)
onAccepted: root.store.contactsStore.acceptContactRequest(root.contactId, root.contactRequestId)
onDeclined: root.store.contactsStore.dismissContactRequest(root.contactId, root.contactRequestId)
}
}
}

View File

@ -180,7 +180,7 @@ Pane {
AcceptRejectOptionsButtonsPanel {
menuButton.visible: false
onAcceptClicked: {
root.contactsStore.acceptContactRequest(root.publicKey)
root.contactsStore.acceptContactRequest(root.publicKey, "")
d.reload()
}
onDeclineClicked: {