fix(@desktop/profile): Contact requests should support a message

Close #5846
This commit is contained in:
mishkarogachev 2022-05-27 11:57:18 +03:00 committed by Iuri Matias
parent c754cf1aaa
commit 7a14cf5640
17 changed files with 117 additions and 81 deletions

View File

@ -277,11 +277,11 @@ proc getContacts*(self: Controller, group: ContactsGroup): seq[ContactsDto] =
proc getContactDetails*(self: Controller, id: string): ContactDetails = proc getContactDetails*(self: Controller, id: string): ContactDetails =
return self.contactService.getContactDetails(id) return self.contactService.getContactDetails(id)
proc addContact*(self: Controller, publicKey: string) = proc acceptContactRequest*(self: Controller, publicKey: string) =
self.contactService.addContact(publicKey) self.contactService.acceptContactRequest(publicKey)
proc rejectContactRequest*(self: Controller, publicKey: string) = proc dismissContactRequest*(self: Controller, publicKey: string) =
self.contactService.rejectContactRequest(publicKey) self.contactService.dismissContactRequest(publicKey)
proc blockContact*(self: Controller, publicKey: string) = proc blockContact*(self: Controller, publicKey: string) =
self.contactService.blockContact(publicKey) self.contactService.blockContact(publicKey)

View File

@ -190,10 +190,10 @@ method acceptContactRequest*(self: AccessInterface, publicKey: string) {.base.}
method acceptAllContactRequests*(self: AccessInterface) {.base.} = method acceptAllContactRequests*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method rejectContactRequest*(self: AccessInterface, publicKey: string) {.base.} = method dismissContactRequest*(self: AccessInterface, publicKey: string) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method rejectAllContactRequests*(self: AccessInterface) {.base.} = method dismissAllContactRequests*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method blockContact*(self: AccessInterface, publicKey: string) {.base.} = method blockContact*(self: AccessInterface, publicKey: string) {.base.} =

View File

@ -595,7 +595,7 @@ method getCurrentFleet*(self: Module): string =
return self.controller.getCurrentFleet() return self.controller.getCurrentFleet()
method acceptContactRequest*(self: Module, publicKey: string) = method acceptContactRequest*(self: Module, publicKey: string) =
self.controller.addContact(publicKey) self.controller.acceptContactRequest(publicKey)
method onContactAccepted*(self: Module, publicKey: string) = method onContactAccepted*(self: Module, publicKey: string) =
self.view.contactRequestsModel().removeItemById(publicKey) self.view.contactRequestsModel().removeItemById(publicKey)
@ -606,17 +606,17 @@ method acceptAllContactRequests*(self: Module) =
for pk in pubKeys: for pk in pubKeys:
self.acceptContactRequest(pk) self.acceptContactRequest(pk)
method rejectContactRequest*(self: Module, publicKey: string) = method dismissContactRequest*(self: Module, publicKey: string) =
self.controller.rejectContactRequest(publicKey) self.controller.dismissContactRequest(publicKey)
method onContactRejected*(self: Module, publicKey: string) = method onContactRejected*(self: Module, publicKey: string) =
self.view.contactRequestsModel().removeItemById(publicKey) self.view.contactRequestsModel().removeItemById(publicKey)
self.updateParentBadgeNotifications() self.updateParentBadgeNotifications()
method rejectAllContactRequests*(self: Module) = method dismissAllContactRequests*(self: Module) =
let pubKeys = self.view.contactRequestsModel().getItemIds() let pubKeys = self.view.contactRequestsModel().getItemIds()
for pk in pubKeys: for pk in pubKeys:
self.rejectContactRequest(pk) self.dismissContactRequest(pk)
method blockContact*(self: Module, publicKey: string) = method blockContact*(self: Module, publicKey: string) =
self.controller.blockContact(publicKey) self.controller.blockContact(publicKey)

View File

@ -169,11 +169,11 @@ QtObject:
proc acceptAllContactRequests*(self: View) {.slot.} = proc acceptAllContactRequests*(self: View) {.slot.} =
self.delegate.acceptAllContactRequests() self.delegate.acceptAllContactRequests()
proc rejectContactRequest*(self: View, publicKey: string) {.slot.} = proc dismissContactRequest*(self: View, publicKey: string) {.slot.} =
self.delegate.rejectContactRequest(publicKey) self.delegate.dismissContactRequest(publicKey)
proc rejectAllContactRequests*(self: View) {.slot.} = proc dismissAllContactRequests*(self: View) {.slot.} =
self.delegate.rejectAllContactRequests() self.delegate.dismissAllContactRequests()
proc blockContact*(self: View, publicKey: string) {.slot.} = proc blockContact*(self: View, publicKey: string) {.slot.} =
self.delegate.blockContact(publicKey) self.delegate.blockContact(publicKey)

View File

@ -63,9 +63,6 @@ proc getContactNameAndImage*(self: Controller, contactId: string):
tuple[name: string, image: string] = tuple[name: string, image: string] =
return self.contactsService.getContactNameAndImage(contactId) return self.contactsService.getContactNameAndImage(contactId)
proc addContact*(self: Controller, publicKey: string) =
self.contactsService.addContact(publicKey)
proc unblockContact*(self: Controller, publicKey: string) = proc unblockContact*(self: Controller, publicKey: string) =
self.contactsService.unblockContact(publicKey) self.contactsService.unblockContact(publicKey)
@ -78,8 +75,14 @@ proc removeContact*(self: Controller, publicKey: string) =
proc changeContactNickname*(self: Controller, publicKey: string, nickname: string) = proc changeContactNickname*(self: Controller, publicKey: string, nickname: string) =
self.contactsService.changeContactNickname(publicKey, nickname) self.contactsService.changeContactNickname(publicKey, nickname)
proc rejectContactRequest*(self: Controller, publicKey: string) = proc sendContactRequest*(self: Controller, publicKey: string, message: string) =
self.contactsService.rejectContactRequest(publicKey) self.contactsService.sendContactRequest(publicKey, message)
proc acceptContactRequest*(self: Controller, publicKey: string) =
self.contactsService.acceptContactRequest(publicKey)
proc dismissContactRequest*(self: Controller, publicKey: string) =
self.contactsService.dismissContactRequest(publicKey)
proc removeContactRequestRejection*(self: Controller, publicKey: string) = proc removeContactRequestRejection*(self: Controller, publicKey: string) =
self.contactsService.removeContactRequestRejection(publicKey) self.contactsService.removeContactRequestRejection(publicKey)

View File

@ -22,19 +22,19 @@ method isLoaded*(self: AccessInterface): bool {.base.} =
method viewDidLoad*(self: AccessInterface) {.base.} = method viewDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method addContact*(self: AccessInterface, publicKey: string) {.base.} =
raise newException(ValueError, "No implementation available")
method switchToOrCreateOneToOneChat*(self: AccessInterface, publicKey: string) {.base.} = method switchToOrCreateOneToOneChat*(self: AccessInterface, publicKey: string) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method acceptContactRequests*(self: AccessInterface, publicKeysJSON: string) {.base.} = method sendContactRequest*(self: AccessInterface, publicKey: string, message: string) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method rejectContactRequest*(self: AccessInterface, publicKey: string) {.base.} = method acceptContactRequest*(self: AccessInterface, publicKey: string) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method rejectContactRequests*(self: AccessInterface, publicKeysJSON: string) {.base.} = method dismissContactRequest*(self: AccessInterface, publicKey: string) {.base.} =
raise newException(ValueError, "No implementation available")
method dismissContactRequests*(self: AccessInterface, publicKeysJSON: string) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method changeContactNickname*(self: AccessInterface, publicKey: string, nickname: string) {.base.} = method changeContactNickname*(self: AccessInterface, publicKey: string, nickname: string) {.base.} =

View File

@ -83,15 +83,18 @@ method viewDidLoad*(self: Module) =
method getModuleAsVariant*(self: Module): QVariant = method getModuleAsVariant*(self: Module): QVariant =
return self.viewVariant return self.viewVariant
method addContact*(self: Module, publicKey: string) = method sendContactRequest*(self: Module, publicKey: string, message: string) =
self.controller.addContact(publicKey) self.controller.sendContactRequest(publicKey, message)
method acceptContactRequest*(self: Module, publicKey: string) =
self.controller.acceptContactRequest(publicKey)
method dismissContactRequest*(self: Module, publicKey: string) =
self.controller.dismissContactRequest(publicKey)
method switchToOrCreateOneToOneChat*(self: Module, publicKey: string) = method switchToOrCreateOneToOneChat*(self: Module, publicKey: string) =
self.controller.switchToOrCreateOneToOneChat(publicKey) self.controller.switchToOrCreateOneToOneChat(publicKey)
method rejectContactRequest*(self: Module, publicKey: string) =
self.controller.rejectContactRequest(publicKey)
method unblockContact*(self: Module, publicKey: string) = method unblockContact*(self: Module, publicKey: string) =
self.controller.unblockContact(publicKey) self.controller.unblockContact(publicKey)

View File

@ -123,14 +123,14 @@ QtObject:
proc isMyMutualContact*(self: View, publicKey: string): bool {.slot.} = proc isMyMutualContact*(self: View, publicKey: string): bool {.slot.} =
return self.myMutualContactsModel.isContactWithIdAdded(publicKey) return self.myMutualContactsModel.isContactWithIdAdded(publicKey)
proc addContact*(self: View, publicKey: string) {.slot.} = proc sendContactRequest*(self: View, publicKey: string, message: string) {.slot.} =
self.delegate.addContact(publicKey) self.delegate.sendContactRequest(publicKey, message)
proc switchToOrCreateOneToOneChat*(self: View, publicKey: string) {.slot.} = proc switchToOrCreateOneToOneChat*(self: View, publicKey: string) {.slot.} =
self.delegate.switchToOrCreateOneToOneChat(publicKey) self.delegate.switchToOrCreateOneToOneChat(publicKey)
proc rejectContactRequest*(self: View, publicKey: string) {.slot.} = proc dismissContactRequest*(self: View, publicKey: string) {.slot.} =
self.delegate.rejectContactRequest(publicKey) self.delegate.dismissContactRequest(publicKey)
proc changeContactNickname*(self: View, publicKey: string, nickname: string) {.slot.} = proc changeContactNickname*(self: View, publicKey: string, nickname: string) {.slot.} =
self.delegate.changeContactNickname(publicKey, nickname) self.delegate.changeContactNickname(publicKey, nickname)

View File

@ -10,8 +10,9 @@ type ActivityCenterNotificationType* {.pure.}= enum
Unknown = 0, Unknown = 0,
NewOneToOne = 1, NewOneToOne = 1,
NewPrivateGroupChat = 2, NewPrivateGroupChat = 2,
Mention = 3 Mention = 3,
Reply = 4 Reply = 4,
ContactRequest = 5
type ActivityCenterNotificationDto* = ref object of RootObj type ActivityCenterNotificationDto* = ref object of RootObj
id*: string # ID is the id of the chat, for public chats it is the name e.g. status, for one-to-one is the hex encoded public key and for group chats is a random uuid appended with the hex encoded pk of the creator of the chat id*: string # ID is the id of the chat, for public chats it is the name e.g. status, for one-to-one is the hex encoded public key and for group chats is a random uuid appended with the hex encoded pk of the creator of the chat

View File

@ -202,7 +202,7 @@ QtObject:
not x.isBlocked()) not x.isBlocked())
elif (group == ContactsGroup.AllKnownContacts): elif (group == ContactsGroup.AllKnownContacts):
return contacts return contacts
proc fetchContact(self: Service, id: string): ContactsDto = proc fetchContact(self: Service, id: string): ContactsDto =
try: try:
let response = status_contacts.getContactByID(id) let response = status_contacts.getContactByID(id)
@ -288,34 +288,53 @@ QtObject:
# we must keep local contacts updated # we must keep local contacts updated
self.contacts[contact.id] = contact self.contacts[contact.id] = contact
proc addContact*(self: Service, chatKey: string) = proc sendContactRequest*(self: Service, chatKey: string, message: string) =
try: try:
let publicKey = status_accounts.decompressPk(chatKey).result let publicKey = status_accounts.decompressPk(chatKey).result
let response = status_contacts.sendContactRequest(publicKey, message)
if(not response.error.isNil):
let msg = response.error.message
error "error sending contact request", msg
return
var contact = self.getContactById(publicKey) var contact = self.getContactById(publicKey)
if not contact.added: if not contact.added:
contact.added = true contact.added = true
else: else:
contact.blocked = false contact.blocked = false
let response = status_contacts.addContact(contact.id, contact.name)
if(not response.error.isNil):
let msg = response.error.message
error "error adding contact ", msg
return
self.saveContact(contact) self.saveContact(contact)
self.events.emit(SIGNAL_CONTACT_ADDED, ContactArgs(contactId: contact.id)) self.events.emit(SIGNAL_CONTACT_ADDED, ContactArgs(contactId: contact.id))
except Exception as e: except Exception as e:
error "an error occurred while edding contact ", msg=e.msg error "an error occurred while sending contact request", msg=e.msg
proc rejectContactRequest*(self: Service, publicKey: string) = proc acceptContactRequest*(self: Service, publicKey: string) =
var contact = self.getContactById(publicKey) try:
contact.removed = true # NOTE: publicKey used for accepting last request
let response = status_contacts.acceptLatestContactRequestForContact(publicKey)
if(not response.error.isNil):
let msg = response.error.message
error "error accepting contact request", msg
return
let response = status_contacts.rejectContactRequest(contact.id) var contact = self.getContactById(publicKey)
contact.added = true
self.saveContact(contact)
self.events.emit(SIGNAL_CONTACT_ADDED, ContactArgs(contactId: contact.id))
except Exception as e:
error "an error occurred while accepting contact request", msg=e.msg
proc dismissContactRequest*(self: Service, publicKey: string) =
# NOTE: publicKey used for dismissing last request
let response = status_contacts.dismissLatestContactRequestForContact(publicKey)
if(not response.error.isNil): if(not response.error.isNil):
let msg = response.error.message let msg = response.error.message
error "error rejecting contact ", msg error "error dismissing contact ", msg
return return
var contact = self.getContactById(publicKey)
contact.removed = true
self.saveContact(contact) self.saveContact(contact)
self.events.emit(SIGNAL_CONTACT_REMOVED, ContactArgs(contactId: contact.id)) self.events.emit(SIGNAL_CONTACT_REMOVED, ContactArgs(contactId: contact.id))

View File

@ -21,12 +21,6 @@ proc unblockContact*(id: string): RpcResponse[JsonNode] {.raises: [Exception].}
proc removeContact*(id: string): RpcResponse[JsonNode] {.raises: [Exception].} = proc removeContact*(id: string): RpcResponse[JsonNode] {.raises: [Exception].} =
result = callPrivateRPC("removeContact".prefix, %* [id]) result = callPrivateRPC("removeContact".prefix, %* [id])
proc rejectContactRequest*(id: string): RpcResponse[JsonNode] {.raises: [Exception].} =
let payload = %*[{
"id": id
}]
result = callPrivateRPC("rejectContactRequest".prefix, payload)
proc setContactLocalNickname*(id: string, name: string): RpcResponse[JsonNode] {.raises: [Exception].} = proc setContactLocalNickname*(id: string, name: string): RpcResponse[JsonNode] {.raises: [Exception].} =
let payload = %* [{ let payload = %* [{
"id": id, "id": id,
@ -34,12 +28,24 @@ proc setContactLocalNickname*(id: string, name: string): RpcResponse[JsonNode] {
}] }]
result = callPrivateRPC("setContactLocalNickname".prefix, payload) result = callPrivateRPC("setContactLocalNickname".prefix, payload)
proc addContact*(id: string, ensName: string): RpcResponse[JsonNode] {.raises: [Exception].} = proc sendContactRequest*(id: string, message: string): RpcResponse[JsonNode] {.raises: [Exception].} =
let payload = %* [{ let payload = %* [{
"id": id, "id": id,
"ensName": ensName "message": message
}] }]
result = callPrivateRPC("addContact".prefix, payload) result = callPrivateRPC("sendContactRequest".prefix, payload)
proc acceptLatestContactRequestForContact*(id: string): RpcResponse[JsonNode] {.raises: [Exception].} =
let payload = %* [{
"id": id
}]
result = callPrivateRPC("acceptLatestContactRequestForContact".prefix, payload)
proc dismissLatestContactRequestForContact*(id: string): RpcResponse[JsonNode] {.raises: [Exception].} =
let payload = %*[{
"id": id
}]
result = callPrivateRPC("dismissLatestContactRequestForContact".prefix, payload)
proc sendContactUpdate*(publicKey, ensName, thumbnail: string): RpcResponse[JsonNode] {.raises: [Exception].} = proc sendContactUpdate*(publicKey, ensName, thumbnail: string): RpcResponse[JsonNode] {.raises: [Exception].} =
let payload = %* [publicKey, ensName, thumbnail] let payload = %* [publicKey, ensName, thumbnail]

View File

@ -47,7 +47,7 @@ ModalPopup {
popup.store.acceptContactRequest(model.pubKey) popup.store.acceptContactRequest(model.pubKey)
} }
onDeclineClicked: { onDeclineClicked: {
popup.store.rejectContactRequest(model.pubKey) popup.store.dismissContactRequest(model.pubKey)
} }
} }
} }
@ -71,7 +71,7 @@ ModalPopup {
//% "Are you sure you want to decline all these contact requests" //% "Are you sure you want to decline all these contact requests"
confirmationText: qsTrId("are-you-sure-you-want-to-decline-all-these-contact-requests") confirmationText: qsTrId("are-you-sure-you-want-to-decline-all-these-contact-requests")
onConfirmButtonClicked: { onConfirmButtonClicked: {
popup.store.rejectAllContactRequests() popup.store.dismissAllContactRequests()
declineAllDialog.close() declineAllDialog.close()
popup.close() popup.close()
} }

View File

@ -62,12 +62,12 @@ QtObject {
chatCommunitySectionModule.acceptAllContactRequests() chatCommunitySectionModule.acceptAllContactRequests()
} }
function rejectContactRequest(pubKey) { function dismissContactRequest(pubKey) {
chatCommunitySectionModule.rejectContactRequest(pubKey) chatCommunitySectionModule.dismissContactRequest(pubKey)
} }
function rejectAllContactRequests() { function dismissAllContactRequests() {
chatCommunitySectionModule.rejectAllContactRequests() chatCommunitySectionModule.dismissAllContactRequests()
} }
function blockContact(pubKey) { function blockContact(pubKey) {

View File

@ -19,10 +19,12 @@ StatusModal {
QtObject { QtObject {
id: d id: d
readonly property int maxMsgLength: 280 readonly property int maxMsgLength: 280
readonly property int minMsgLength: 0 //TODO: update this to 1 later, when we introduce "say who you are" feature readonly property int minMsgLength: 1
readonly property int msgHeight: 152 readonly property int msgHeight: 152
readonly property int contentSpacing: 0 readonly property int contentSpacing: 5
readonly property int contentMargins: 16
property int minChatKeyLength: 4 // ens or chat key property int minChatKeyLength: 4 // ens or chat key
property string realChatKey: "" property string realChatKey: ""
@ -83,7 +85,9 @@ StatusModal {
contentItem: Item { contentItem: Item {
Column { Column {
id: content id: content
anchors.horizontalCenter: parent.horizontalCenter anchors.left: parent.left
anchors.right: parent.right
anchors.margins: d.contentMargins
spacing: d.contentSpacing spacing: d.contentSpacing
StatusInput { StatusInput {
@ -143,7 +147,7 @@ StatusModal {
enabled: d.validChatKey && messageInput.valid enabled: d.validChatKey && messageInput.valid
text: qsTr("Send Contact Request") text: qsTr("Send Contact Request")
onClicked: { onClicked: {
root.contactsStore.addContact(d.realChatKey) root.contactsStore.sendContactRequest(d.realChatKey, messageInput.text)
root.close() root.close()
} }
} }

View File

@ -41,10 +41,6 @@ QtObject {
root.contactsModule.switchToOrCreateOneToOneChat(pubKey) root.contactsModule.switchToOrCreateOneToOneChat(pubKey)
} }
function addContact(pubKey) {
root.contactsModule.addContact(pubKey)
}
function unblockContact(pubKey) { function unblockContact(pubKey) {
root.contactsModule.unblockContact(pubKey) root.contactsModule.unblockContact(pubKey)
} }
@ -60,13 +56,17 @@ QtObject {
function changeContactNickname(pubKey, nickname) { function changeContactNickname(pubKey, nickname) {
root.contactsModule.changeContactNickname(pubKey, nickname) root.contactsModule.changeContactNickname(pubKey, nickname)
} }
function acceptContactRequest(pubKey) { function sendContactRequest(pubKey, message) {
root.contactsModule.addContact(pubKey) root.contactsModule.sendContactRequest(pubKey, message)
} }
function rejectContactRequest(pubKey) { function acceptContactRequest(pubKey) {
root.contactsModule.rejectContactRequest(pubKey) root.contactsModule.acceptContactRequest(pubKey)
}
function dismissContactRequest(pubKey) {
root.contactsModule.dismissContactRequest(pubKey)
} }
function removeContactRequestRejection(pubKey) { function removeContactRequestRejection(pubKey) {

View File

@ -192,7 +192,7 @@ SettingsContentBase {
} }
onContactRequestRejected: { onContactRequestRejected: {
root.contactsStore.rejectContactRequest(publicKey) root.contactsStore.dismissContactRequest(publicKey)
} }
} }

View File

@ -331,7 +331,7 @@ StatusModal {
text: qsTr("Add to contacts") text: qsTr("Add to contacts")
visible: !userIsBlocked && !isAddedContact visible: !userIsBlocked && !isAddedContact
onClicked: { onClicked: {
popup.contactsStore.addContact(userPublicKey); popup.contactsStore.sendContactRequest(userPublicKey);
popup.contactAdded(userPublicKey); popup.contactAdded(userPublicKey);
popup.close(); popup.close();
} }