Skip to content

Commit

Permalink
fix: Fix behaviour issues with CRs and mutual update events
Browse files Browse the repository at this point in the history
Close #11121
  • Loading branch information
MishkaRogachev committed Jul 12, 2023
1 parent 9629a14 commit f24297e
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 @@ -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)

Expand Down Expand Up @@ -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)
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
2 changes: 1 addition & 1 deletion vendor/status-go
Submodule status-go updated 62 files
+1 −1 VERSION
+4 −0 api/defaults.go
+45 −9 api/geth_backend.go
+8 −8 appdatabase/database.go
+2 −2 go.mod
+4 −4 go.sum
+2 −1 node/status_node_services.go
+1 −1 protocol/anonmetrics/client.go
+9 −11 protocol/common/message_sender.go
+3 −3 protocol/common/message_sender_test.go
+1 −1 protocol/common/raw_message.go
+2 −2 protocol/common/raw_messages_persistence.go
+13 −0 protocol/communities_messenger_test.go
+0 −124 protocol/encryption/encryption_test.go
+4 −2 protocol/message_validator.go
+3 −3 protocol/messenger.go
+1 −1 protocol/messenger_backup.go
+43 −26 protocol/messenger_communities.go
+23 −38 protocol/messenger_contact_requests_test.go
+48 −98 protocol/messenger_contacts.go
+36 −39 protocol/messenger_handler.go
+105 −95 protocol/protobuf/chat_message.pb.go
+6 −1 protocol/protobuf/chat_message.proto
+5 −5 protocol/pushnotificationclient/client.go
+3 −3 protocol/pushnotificationserver/server.go
+2 −1 protocol/requests/create_account.go
+16 −10 services/wallet/activity/activity.go
+1 −1 services/wallet/api.go
+28 −0 services/wallet/decoder.go
+3 −4 services/wallet/service.go
+103 −0 services/wallet/thirdparty/fourbytegithub/client.go
+34 −0 services/wallet/thirdparty/fourbytegithub/client_test.go
+52 −3 services/wallet/transfer/transaction.go
+2 −1 services/wallet/transfer/transaction_test.go
+10 −3 signal/events_node.go
+3 −1 signal/events_wakuv2.go
+21 −13 sqlite/sqlite.go
+0 −36 vendor/github.com/waku-org/go-waku/waku/try/try.go
+48 −8 vendor/github.com/waku-org/go-waku/waku/v2/discovery_connector.go
+26 −14 vendor/github.com/waku-org/go-waku/waku/v2/discv5/discover.go
+0 −1 vendor/github.com/waku-org/go-waku/waku/v2/node/keepalive.go
+61 −0 vendor/github.com/waku-org/go-waku/waku/v2/node/localnode.go
+0 −6 vendor/github.com/waku-org/go-waku/waku/v2/node/service.go
+6 −70 vendor/github.com/waku-org/go-waku/waku/v2/node/wakunode2.go
+2 −15 vendor/github.com/waku-org/go-waku/waku/v2/node/wakuoptions.go
+0 −1 vendor/github.com/waku-org/go-waku/waku/v2/protocol/enr/localnode.go
+13 −3 vendor/github.com/waku-org/go-waku/waku/v2/protocol/enr/shards.go
+9 −10 vendor/github.com/waku-org/go-waku/waku/v2/protocol/filter/client.go
+5 −1 vendor/github.com/waku-org/go-waku/waku/v2/protocol/peer_exchange/client.go
+5 −4 vendor/github.com/waku-org/go-waku/waku/v2/protocol/peer_exchange/protocol.go
+48 −2 vendor/github.com/waku-org/go-waku/waku/v2/protocol/relay/waku_relay.go
+2 −2 vendor/github.com/waku-org/go-waku/waku/v2/protocol/shard.go
+0 −1 vendor/github.com/waku-org/go-waku/waku/v2/protocol/topic.go
+8 −8 vendor/github.com/waku-org/go-waku/waku/v2/rendezvous/rendezvous.go
+8 −0 vendor/golang.org/x/crypto/cryptobyte/asn1.go
+6 −93 vendor/golang.org/x/crypto/curve25519/curve25519.go
+105 −0 vendor/golang.org/x/crypto/curve25519/curve25519_compat.go
+46 −0 vendor/golang.org/x/crypto/curve25519/curve25519_go120.go
+2 −3 vendor/modules.txt
+1 −1 wakuv2/api_test.go
+74 −40 wakuv2/waku.go
+4 −4 wakuv2/waku_test.go

0 comments on commit f24297e

Please sign in to comment.