Skip to content

Commit

Permalink
fix: Fix behaviour issues with CRs and mutual update messages (#11178)
Browse files Browse the repository at this point in the history
Close #11121
  • Loading branch information
MishkaRogachev authored Jul 12, 2023
1 parent 42f2546 commit 1a7532d
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 25 deletions.
4 changes: 1 addition & 3 deletions src/app/modules/main/profile_section/contacts/controller.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion src/app_service/common/types.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
14 changes: 8 additions & 6 deletions src/app_service/service/contacts/service.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand Down
11 changes: 6 additions & 5 deletions src/app_service/service/message/service.nim
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,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)

Expand Down Expand Up @@ -383,6 +380,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)
Expand Down
8 changes: 6 additions & 2 deletions ui/StatusQ/src/StatusQ/Components/StatusMessage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ Control {
Invitation = 7,
DiscordMessage = 8,
SystemMessagePinnedMessage = 14,
SystemMessageMutualStateUpdate = 15
SystemMessageMutualEventSent = 15,
SystemMessageMutualEventAccepted = 16,
SystemMessageMutualEventRemoved = 17
}

property list<Item> quickActions
Expand Down Expand Up @@ -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 {
Expand Down
54 changes: 48 additions & 6 deletions ui/imports/shared/views/chat/MessageView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -348,7 +355,7 @@ Loader {
}

Component {
id: systemMessageComponent
id: systemMessageGroupComponent

StyledText {
wrapMode: Text.Wrap
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion ui/imports/utils/Constants.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 1a7532d

Please sign in to comment.