From f24297e213094cd5b7e3bdc59512769cff99504b Mon Sep 17 00:00:00 2001 From: MishkaRogachev Date: Tue, 20 Jun 2023 15:28:07 +0400 Subject: [PATCH] fix: Fix behaviour issues with CRs and mutual update events Close #11121 --- .../profile_section/contacts/controller.nim | 4 +- src/app_service/common/types.nim | 4 +- src/app_service/service/contacts/service.nim | 14 ++--- src/app_service/service/message/service.nim | 11 ++-- .../src/StatusQ/Components/StatusMessage.qml | 8 ++- ui/imports/shared/views/chat/MessageView.qml | 54 ++++++++++++++++--- ui/imports/utils/Constants.qml | 4 +- vendor/status-go | 2 +- 8 files changed, 76 insertions(+), 25 deletions(-) diff --git a/src/app/modules/main/profile_section/contacts/controller.nim b/src/app/modules/main/profile_section/contacts/controller.nim index a2a25f60240..412defb6a16 100644 --- a/src/app/modules/main/profile_section/contacts/controller.nim +++ b/src/app/modules/main/profile_section/contacts/controller.nim @@ -109,9 +109,7 @@ proc blockContact*(self: Controller, publicKey: string) = self.contactsService.blockContact(publicKey) proc removeContact*(self: Controller, publicKey: string) = - let response = self.contactsService.removeContact(publicKey) - # TODO: segfault if using SIGNAL_CHAT_REQUEST_UPDATE_AFTER_SEND - discard self.chatService.processMessageUpdateAfterSend(response) + self.contactsService.removeContact(publicKey) proc changeContactNickname*(self: Controller, publicKey: string, nickname: string) = self.contactsService.changeContactNickname(publicKey, nickname) diff --git a/src/app_service/common/types.nim b/src/app_service/common/types.nim index 75e9a474eb2..da13c5d7d1c 100644 --- a/src/app_service/common/types.nim +++ b/src/app_service/common/types.nim @@ -19,7 +19,9 @@ type ContactIdentityVerification = 13 # Local only SystemMessagePinnedMessage = 14 - SystemMessageMutualStateUpdate = 15 + SystemMessageMutualEventSent = 15 + SystemMessageMutualEventAccepted = 16 + SystemMessageMutualEventRemoved = 17 proc toContentType*(value: int): ContentType = try: diff --git a/src/app_service/service/contacts/service.nim b/src/app_service/service/contacts/service.nim index 1c09aeb5ac6..6e012031568 100644 --- a/src/app_service/service/contacts/service.nim +++ b/src/app_service/service/contacts/service.nim @@ -54,6 +54,9 @@ type RpcResponseArgs* = ref object of Args response*: RpcResponse[JsonNode] + ReloadOneToOneArgs* = ref object of Args + sectionId*: string + # Signals which may be emitted by this service: const SIGNAL_ENS_RESOLVED* = "ensResolved" const SIGNAL_CONTACT_ADDED* = "contactAdded" @@ -76,7 +79,7 @@ const SIGNAL_CONTACT_VERIFICATION_ACCEPTED* = "contactVerificationRequestAccepte const SIGNAL_CONTACT_VERIFICATION_ADDED* = "contactVerificationRequestAdded" const SIGNAL_CONTACT_VERIFICATION_UPDATED* = "contactVerificationRequestUpdated" const SIGNAL_CONTACT_INFO_REQUEST_FINISHED* = "contactInfoRequestFinished" -const SIGNAL_CHAT_REQUEST_UPDATE_AFTER_SEND* = "chatRequestUpdateAfterSend" +const SIGNAL_RELOAD_ONE_TO_ONE_CHAT* = "reloadOneToOneChat" type ContactsGroup* {.pure.} = enum @@ -469,7 +472,7 @@ QtObject: self.parseContactsResponse(response) self.activityCenterService.parseActivityCenterResponse(response) - self.events.emit(SIGNAL_CHAT_REQUEST_UPDATE_AFTER_SEND, RpcResponseArgs(response: response)) + self.events.emit(SIGNAL_RELOAD_ONE_TO_ONE_CHAT, ReloadOneToOneArgs(sectionId: publicKey)) except Exception as e: error "an error occurred while sending contact request", msg = e.msg @@ -489,7 +492,7 @@ QtObject: self.parseContactsResponse(response) self.activityCenterService.parseActivityCenterResponse(response) - self.events.emit(SIGNAL_CHAT_REQUEST_UPDATE_AFTER_SEND, RpcResponseArgs(response: response)) + self.events.emit(SIGNAL_RELOAD_ONE_TO_ONE_CHAT, ReloadOneToOneArgs(sectionId: publicKey)) except Exception as e: error "an error occurred while accepting contact request", msg=e.msg @@ -509,7 +512,6 @@ QtObject: self.parseContactsResponse(response) self.activityCenterService.parseActivityCenterResponse(response) - self.events.emit(SIGNAL_CHAT_REQUEST_UPDATE_AFTER_SEND, RpcResponseArgs(response: response)) except Exception as e: error "an error occurred while dismissing contact request", msg=e.msg @@ -549,15 +551,15 @@ QtObject: self.parseContactsResponse(response) self.events.emit(SIGNAL_CONTACT_BLOCKED, ContactArgs(contactId: contact.id)) - proc removeContact*(self: Service, publicKey: string): RpcResponse[JsonNode] = + proc removeContact*(self: Service, publicKey: string) = let response = status_contacts.retractContactRequest(publicKey) if not response.error.isNil: error "error removing contact ", msg = response.error.message return + self.events.emit(SIGNAL_RELOAD_ONE_TO_ONE_CHAT, ReloadOneToOneArgs(sectionId: publicKey)) self.parseContactsResponse(response) self.activityCenterService.parseActivityCenterResponse(response) - return response proc ensResolved*(self: Service, jsonObj: string) {.slot.} = let jsonObj = jsonObj.parseJson() diff --git a/src/app_service/service/message/service.nim b/src/app_service/service/message/service.nim index fdb63243c1e..b79d524af58 100644 --- a/src/app_service/service/message/service.nim +++ b/src/app_service/service/message/service.nim @@ -260,11 +260,8 @@ QtObject: error "error: received `chats` array for handling messages update is empty" return - # Temporary commented until we provide appropriate flags on the `status-go` side to cover all sections. - # blocking contact deletes the chat on the `status-go` side, after unblocking it, `active` prop is still false - # that's the reason why the following check is commented out here. - # if (not chats[0].active): - # return + if (not chats[0].active): + return self.bulkReplacePubKeysWithDisplayNames(messages) @@ -378,6 +375,10 @@ QtObject: let data = EnvelopeExpiredArgs(messagesIds: receivedData.messageIds) self.events.emit(SIGNAL_ENVELOPE_EXPIRED, data) + self.events.on(SIGNAL_RELOAD_ONE_TO_ONE_CHAT) do(e: Args): + let args = ReloadOneToOneArgs(e) + self.resetMessageCursor(args.sectionId) + self.asyncLoadMoreMessagesForChat(args.sectionId) self.events.on(SignalType.Message.event) do(e: Args): var receivedData = MessageSignal(e) diff --git a/ui/StatusQ/src/StatusQ/Components/StatusMessage.qml b/ui/StatusQ/src/StatusQ/Components/StatusMessage.qml index 07e7462ed8f..fa620394a7a 100644 --- a/ui/StatusQ/src/StatusQ/Components/StatusMessage.qml +++ b/ui/StatusQ/src/StatusQ/Components/StatusMessage.qml @@ -23,7 +23,9 @@ Control { Invitation = 7, DiscordMessage = 8, SystemMessagePinnedMessage = 14, - SystemMessageMutualStateUpdate = 15 + SystemMessageMutualEventSent = 15, + SystemMessageMutualEventAccepted = 16, + SystemMessageMutualEventRemoved = 17 } property list quickActions @@ -191,7 +193,9 @@ Control { Layout.fillWidth: true active: isAReply && root.messageDetails.contentType !== StatusMessage.ContentType.SystemMessagePinnedMessage && - root.messageDetails.contentType !== StatusMessage.ContentType.SystemMessageMutualStateUpdate + root.messageDetails.contentType !== StatusMessage.ContentType.SystemMessageMutualEventSent && + root.messageDetails.contentType !== StatusMessage.ContentType.SystemMessageMutualEventAccepted && + root.messageDetails.contentType !== StatusMessage.ContentType.SystemMessageMutualEventRemoved visible: active sourceComponent: StatusMessageReply { diff --git a/ui/imports/shared/views/chat/MessageView.qml b/ui/imports/shared/views/chat/MessageView.qml index aa86885ac43..6e966c38385 100644 --- a/ui/imports/shared/views/chat/MessageView.qml +++ b/ui/imports/shared/views/chat/MessageView.qml @@ -195,8 +195,11 @@ Loader { case Constants.messageContentType.fetchMoreMessagesButton: return fetchMoreMessagesButtonComponent case Constants.messageContentType.systemMessagePrivateGroupType: // no break - case Constants.messageContentType.systemMessageMutualStateUpdate: - return systemMessageComponent + return systemMessageGroupComponent + case Constants.messageContentType.systemMessageMutualEventSent: + case Constants.messageContentType.systemMessageMutualEventAccepted: + case Constants.messageContentType.systemMessageMutualEventRemoved: + return systemMessageMutualEventComponent case Constants.messageContentType.systemMessagePinnedMessage: return systemMessagePinnedMessageComponent case Constants.messageContentType.gapType: @@ -271,8 +274,12 @@ Loader { return StatusMessage.ContentType.DiscordMessage; case Constants.messageContentType.systemMessagePinnedMessage: return StatusMessage.ContentType.SystemMessagePinnedMessage; - case Constants.messageContentType.systemMessageMutualStateUpdate: - return StatusMessage.ContentType.SystemMessageMutualStateUpdate; + case Constants.messageContentType.systemMessageMutualEventSent: + return StatusMessage.ContentType.SystemMessageMutualEventSent; + case Constants.messageContentType.systemMessageMutualEventAccepted: + return StatusMessage.ContentType.SystemMessageMutualEventAccepted; + case Constants.messageContentType.systemMessageMutualEventRemoved: + return StatusMessage.ContentType.SystemMessageMutualEventRemoved; case Constants.messageContentType.fetchMoreMessagesButton: case Constants.messageContentType.chatIdentifier: case Constants.messageContentType.unknownContentType: @@ -348,7 +355,7 @@ Loader { } Component { - id: systemMessageComponent + id: systemMessageGroupComponent StyledText { wrapMode: Text.Wrap @@ -379,6 +386,39 @@ Loader { } } + Component{ + id: systemMessageMutualEventComponent + + StyledText { + text: { + var displayName = root.amISender ? Utils.getContactDetailsAsJson(chatId, false).displayName : root.senderDisplayName + switch (root.messageContentType) { + case Constants.messageContentType.systemMessageMutualEventSent: + return root.amISender ? + qsTr("You sent a contact request to %1").arg(displayName) : + qsTr("%1 sent you a contact request").arg(displayName) + case Constants.messageContentType.systemMessageMutualEventAccepted: + return root.amISender ? + qsTr("You accepted %1's contact request").arg(displayName) : + qsTr("%1 accepted your contact request").arg(displayName) + case Constants.messageContentType.systemMessageMutualEventRemoved: + return root.amISender ? + qsTr("You removed %1 as a contact").arg(displayName) : + qsTr("%1 removed you as a contact").arg(displayName) + default: + return root.messageText + } + } + font.pixelSize: 14 + color: Style.current.secondaryText + width: parent.width - 120 + horizontalAlignment: Text.AlignHCenter + anchors.horizontalCenter: parent.horizontalCenter + textFormat: Text.RichText + topPadding: root.prevMessageIndex === 1 ? Style.current.bigPadding : 0 + } + } + Component { id: systemMessagePinnedMessageComponent @@ -481,7 +521,9 @@ Loader { showHeader: root.shouldRepeatHeader || dateGroupLabel.visible || isAReply || root.prevMessageContentType === Constants.messageContentType.systemMessagePrivateGroupType || root.prevMessageContentType === Constants.messageContentType.systemMessagePinnedMessage || - root.prevMessageContentType === Constants.messageContentType.systemMessageMutualStateUpdate || + root.prevMessageContentType === Constants.messageContentType.systemMessageMutualEventSent || + root.prevMessageContentType === Constants.messageContentType.systemMessageMutualEventAccepted || + root.prevMessageContentType === Constants.messageContentType.systemMessageMutualEventRemoved || root.senderId !== root.prevMessageSenderId isActiveMessage: d.isMessageActive topPadding: showHeader ? Style.current.halfPadding : 0 diff --git a/ui/imports/utils/Constants.qml b/ui/imports/utils/Constants.qml index 69daa1d74f4..93cb1588d39 100644 --- a/ui/imports/utils/Constants.qml +++ b/ui/imports/utils/Constants.qml @@ -430,7 +430,9 @@ QtObject { readonly property int contactRequestType: 11 readonly property int discordMessageType: 12 readonly property int systemMessagePinnedMessage: 14 - readonly property int systemMessageMutualStateUpdate: 15 + readonly property int systemMessageMutualEventSent: 15 + readonly property int systemMessageMutualEventAccepted: 16 + readonly property int systemMessageMutualEventRemoved: 17 } readonly property QtObject messageModelRoles: QtObject { diff --git a/vendor/status-go b/vendor/status-go index 61527f8c787..26d42bf6972 160000 --- a/vendor/status-go +++ b/vendor/status-go @@ -1 +1 @@ -Subproject commit 61527f8c7870331bc3c6b61f3adb1c68111e9188 +Subproject commit 26d42bf6972610df5fcf6a3d4ad70e940f1799f0