diff --git a/src/app/modules/main/chat_section/controller.nim b/src/app/modules/main/chat_section/controller.nim index 770983b6b3..32c9870a79 100644 --- a/src/app/modules/main/chat_section/controller.nim +++ b/src/app/modules/main/chat_section/controller.nim @@ -277,11 +277,11 @@ proc getContacts*(self: Controller, group: ContactsGroup): seq[ContactsDto] = proc getContactDetails*(self: Controller, id: string): ContactDetails = return self.contactService.getContactDetails(id) -proc addContact*(self: Controller, publicKey: string) = - self.contactService.addContact(publicKey) +proc acceptContactRequest*(self: Controller, publicKey: string) = + self.contactService.acceptContactRequest(publicKey) -proc rejectContactRequest*(self: Controller, publicKey: string) = - self.contactService.rejectContactRequest(publicKey) +proc dismissContactRequest*(self: Controller, publicKey: string) = + self.contactService.dismissContactRequest(publicKey) proc blockContact*(self: Controller, publicKey: string) = self.contactService.blockContact(publicKey) diff --git a/src/app/modules/main/chat_section/io_interface.nim b/src/app/modules/main/chat_section/io_interface.nim index 88a2cb6c8c..f05f9edb38 100644 --- a/src/app/modules/main/chat_section/io_interface.nim +++ b/src/app/modules/main/chat_section/io_interface.nim @@ -190,10 +190,10 @@ method acceptContactRequest*(self: AccessInterface, publicKey: string) {.base.} method acceptAllContactRequests*(self: AccessInterface) {.base.} = 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") -method rejectAllContactRequests*(self: AccessInterface) {.base.} = +method dismissAllContactRequests*(self: AccessInterface) {.base.} = raise newException(ValueError, "No implementation available") method blockContact*(self: AccessInterface, publicKey: string) {.base.} = diff --git a/src/app/modules/main/chat_section/module.nim b/src/app/modules/main/chat_section/module.nim index 66fa600e0a..62b2ad4c84 100644 --- a/src/app/modules/main/chat_section/module.nim +++ b/src/app/modules/main/chat_section/module.nim @@ -595,7 +595,7 @@ method getCurrentFleet*(self: Module): string = return self.controller.getCurrentFleet() method acceptContactRequest*(self: Module, publicKey: string) = - self.controller.addContact(publicKey) + self.controller.acceptContactRequest(publicKey) method onContactAccepted*(self: Module, publicKey: string) = self.view.contactRequestsModel().removeItemById(publicKey) @@ -606,17 +606,17 @@ method acceptAllContactRequests*(self: Module) = for pk in pubKeys: self.acceptContactRequest(pk) -method rejectContactRequest*(self: Module, publicKey: string) = - self.controller.rejectContactRequest(publicKey) +method dismissContactRequest*(self: Module, publicKey: string) = + self.controller.dismissContactRequest(publicKey) method onContactRejected*(self: Module, publicKey: string) = self.view.contactRequestsModel().removeItemById(publicKey) self.updateParentBadgeNotifications() -method rejectAllContactRequests*(self: Module) = +method dismissAllContactRequests*(self: Module) = let pubKeys = self.view.contactRequestsModel().getItemIds() for pk in pubKeys: - self.rejectContactRequest(pk) + self.dismissContactRequest(pk) method blockContact*(self: Module, publicKey: string) = self.controller.blockContact(publicKey) diff --git a/src/app/modules/main/chat_section/view.nim b/src/app/modules/main/chat_section/view.nim index ae46382319..8afaef832a 100644 --- a/src/app/modules/main/chat_section/view.nim +++ b/src/app/modules/main/chat_section/view.nim @@ -169,11 +169,11 @@ QtObject: proc acceptAllContactRequests*(self: View) {.slot.} = self.delegate.acceptAllContactRequests() - proc rejectContactRequest*(self: View, publicKey: string) {.slot.} = - self.delegate.rejectContactRequest(publicKey) + proc dismissContactRequest*(self: View, publicKey: string) {.slot.} = + self.delegate.dismissContactRequest(publicKey) - proc rejectAllContactRequests*(self: View) {.slot.} = - self.delegate.rejectAllContactRequests() + proc dismissAllContactRequests*(self: View) {.slot.} = + self.delegate.dismissAllContactRequests() proc blockContact*(self: View, publicKey: string) {.slot.} = self.delegate.blockContact(publicKey) diff --git a/src/app/modules/main/profile_section/contacts/controller.nim b/src/app/modules/main/profile_section/contacts/controller.nim index aed6884b95..f0491a3a9d 100644 --- a/src/app/modules/main/profile_section/contacts/controller.nim +++ b/src/app/modules/main/profile_section/contacts/controller.nim @@ -63,9 +63,6 @@ proc getContactNameAndImage*(self: Controller, contactId: string): tuple[name: string, image: string] = return self.contactsService.getContactNameAndImage(contactId) -proc addContact*(self: Controller, publicKey: string) = - self.contactsService.addContact(publicKey) - proc unblockContact*(self: Controller, publicKey: string) = self.contactsService.unblockContact(publicKey) @@ -78,8 +75,14 @@ proc removeContact*(self: Controller, publicKey: string) = proc changeContactNickname*(self: Controller, publicKey: string, nickname: string) = self.contactsService.changeContactNickname(publicKey, nickname) -proc rejectContactRequest*(self: Controller, publicKey: string) = - self.contactsService.rejectContactRequest(publicKey) +proc sendContactRequest*(self: Controller, publicKey: string, message: string) = + 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) = self.contactsService.removeContactRequestRejection(publicKey) diff --git a/src/app/modules/main/profile_section/contacts/io_interface.nim b/src/app/modules/main/profile_section/contacts/io_interface.nim index d0b25ef5d9..c0f44de98f 100644 --- a/src/app/modules/main/profile_section/contacts/io_interface.nim +++ b/src/app/modules/main/profile_section/contacts/io_interface.nim @@ -22,19 +22,19 @@ method isLoaded*(self: AccessInterface): bool {.base.} = method viewDidLoad*(self: AccessInterface) {.base.} = 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.} = 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") -method rejectContactRequest*(self: AccessInterface, publicKey: string) {.base.} = +method acceptContactRequest*(self: AccessInterface, publicKey: string) {.base.} = 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") method changeContactNickname*(self: AccessInterface, publicKey: string, nickname: string) {.base.} = diff --git a/src/app/modules/main/profile_section/contacts/module.nim b/src/app/modules/main/profile_section/contacts/module.nim index 306a1b76d7..a9d86f6f72 100644 --- a/src/app/modules/main/profile_section/contacts/module.nim +++ b/src/app/modules/main/profile_section/contacts/module.nim @@ -83,15 +83,18 @@ method viewDidLoad*(self: Module) = method getModuleAsVariant*(self: Module): QVariant = return self.viewVariant -method addContact*(self: Module, publicKey: string) = - self.controller.addContact(publicKey) +method sendContactRequest*(self: Module, publicKey: string, message: string) = + 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) = self.controller.switchToOrCreateOneToOneChat(publicKey) -method rejectContactRequest*(self: Module, publicKey: string) = - self.controller.rejectContactRequest(publicKey) - method unblockContact*(self: Module, publicKey: string) = self.controller.unblockContact(publicKey) diff --git a/src/app/modules/main/profile_section/contacts/view.nim b/src/app/modules/main/profile_section/contacts/view.nim index ab4c73ecb7..5c8a80301f 100644 --- a/src/app/modules/main/profile_section/contacts/view.nim +++ b/src/app/modules/main/profile_section/contacts/view.nim @@ -123,14 +123,14 @@ QtObject: proc isMyMutualContact*(self: View, publicKey: string): bool {.slot.} = return self.myMutualContactsModel.isContactWithIdAdded(publicKey) - proc addContact*(self: View, publicKey: string) {.slot.} = - self.delegate.addContact(publicKey) + proc sendContactRequest*(self: View, publicKey: string, message: string) {.slot.} = + self.delegate.sendContactRequest(publicKey, message) proc switchToOrCreateOneToOneChat*(self: View, publicKey: string) {.slot.} = self.delegate.switchToOrCreateOneToOneChat(publicKey) - proc rejectContactRequest*(self: View, publicKey: string) {.slot.} = - self.delegate.rejectContactRequest(publicKey) + proc dismissContactRequest*(self: View, publicKey: string) {.slot.} = + self.delegate.dismissContactRequest(publicKey) proc changeContactNickname*(self: View, publicKey: string, nickname: string) {.slot.} = self.delegate.changeContactNickname(publicKey, nickname) diff --git a/src/app_service/service/activity_center/dto/notification.nim b/src/app_service/service/activity_center/dto/notification.nim index 83970586ba..587f9e435b 100644 --- a/src/app_service/service/activity_center/dto/notification.nim +++ b/src/app_service/service/activity_center/dto/notification.nim @@ -10,8 +10,9 @@ type ActivityCenterNotificationType* {.pure.}= enum Unknown = 0, NewOneToOne = 1, NewPrivateGroupChat = 2, - Mention = 3 - Reply = 4 + Mention = 3, + Reply = 4, + ContactRequest = 5 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 diff --git a/src/app_service/service/contacts/service.nim b/src/app_service/service/contacts/service.nim index 6558f1810c..f96870f26d 100644 --- a/src/app_service/service/contacts/service.nim +++ b/src/app_service/service/contacts/service.nim @@ -202,7 +202,7 @@ QtObject: not x.isBlocked()) elif (group == ContactsGroup.AllKnownContacts): return contacts - + proc fetchContact(self: Service, id: string): ContactsDto = try: let response = status_contacts.getContactByID(id) @@ -288,34 +288,53 @@ QtObject: # we must keep local contacts updated self.contacts[contact.id] = contact - proc addContact*(self: Service, chatKey: string) = + proc sendContactRequest*(self: Service, chatKey: string, message: string) = try: 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) if not contact.added: contact.added = true else: 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.events.emit(SIGNAL_CONTACT_ADDED, ContactArgs(contactId: contact.id)) 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) = - var contact = self.getContactById(publicKey) - contact.removed = true + proc acceptContactRequest*(self: Service, publicKey: string) = + try: + # 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): let msg = response.error.message - error "error rejecting contact ", msg + error "error dismissing contact ", msg return + + var contact = self.getContactById(publicKey) + contact.removed = true self.saveContact(contact) self.events.emit(SIGNAL_CONTACT_REMOVED, ContactArgs(contactId: contact.id)) diff --git a/src/backend/contacts.nim b/src/backend/contacts.nim index 7d9ad40f63..8c4db60fab 100644 --- a/src/backend/contacts.nim +++ b/src/backend/contacts.nim @@ -21,12 +21,6 @@ proc unblockContact*(id: string): RpcResponse[JsonNode] {.raises: [Exception].} proc removeContact*(id: string): RpcResponse[JsonNode] {.raises: [Exception].} = 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].} = let payload = %* [{ "id": id, @@ -34,12 +28,24 @@ proc setContactLocalNickname*(id: string, name: string): RpcResponse[JsonNode] { }] 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 = %* [{ "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].} = let payload = %* [publicKey, ensName, thumbnail] diff --git a/ui/app/AppLayouts/Chat/popups/ContactRequestsPopup.qml b/ui/app/AppLayouts/Chat/popups/ContactRequestsPopup.qml index f7d14a3d2f..5ee8282b73 100644 --- a/ui/app/AppLayouts/Chat/popups/ContactRequestsPopup.qml +++ b/ui/app/AppLayouts/Chat/popups/ContactRequestsPopup.qml @@ -47,7 +47,7 @@ ModalPopup { popup.store.acceptContactRequest(model.pubKey) } 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" confirmationText: qsTrId("are-you-sure-you-want-to-decline-all-these-contact-requests") onConfirmButtonClicked: { - popup.store.rejectAllContactRequests() + popup.store.dismissAllContactRequests() declineAllDialog.close() popup.close() } diff --git a/ui/app/AppLayouts/Chat/stores/RootStore.qml b/ui/app/AppLayouts/Chat/stores/RootStore.qml index 1c633e7d02..e231ad7973 100644 --- a/ui/app/AppLayouts/Chat/stores/RootStore.qml +++ b/ui/app/AppLayouts/Chat/stores/RootStore.qml @@ -62,12 +62,12 @@ QtObject { chatCommunitySectionModule.acceptAllContactRequests() } - function rejectContactRequest(pubKey) { - chatCommunitySectionModule.rejectContactRequest(pubKey) + function dismissContactRequest(pubKey) { + chatCommunitySectionModule.dismissContactRequest(pubKey) } - function rejectAllContactRequests() { - chatCommunitySectionModule.rejectAllContactRequests() + function dismissAllContactRequests() { + chatCommunitySectionModule.dismissAllContactRequests() } function blockContact(pubKey) { diff --git a/ui/app/AppLayouts/Profile/popups/SendContactRequestModal.qml b/ui/app/AppLayouts/Profile/popups/SendContactRequestModal.qml index 306ba48bd0..8a792e0a5b 100644 --- a/ui/app/AppLayouts/Profile/popups/SendContactRequestModal.qml +++ b/ui/app/AppLayouts/Profile/popups/SendContactRequestModal.qml @@ -19,10 +19,12 @@ StatusModal { QtObject { id: d + 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 contentSpacing: 0 + readonly property int contentSpacing: 5 + readonly property int contentMargins: 16 property int minChatKeyLength: 4 // ens or chat key property string realChatKey: "" @@ -83,7 +85,9 @@ StatusModal { contentItem: Item { Column { id: content - anchors.horizontalCenter: parent.horizontalCenter + anchors.left: parent.left + anchors.right: parent.right + anchors.margins: d.contentMargins spacing: d.contentSpacing StatusInput { @@ -143,7 +147,7 @@ StatusModal { enabled: d.validChatKey && messageInput.valid text: qsTr("Send Contact Request") onClicked: { - root.contactsStore.addContact(d.realChatKey) + root.contactsStore.sendContactRequest(d.realChatKey, messageInput.text) root.close() } } diff --git a/ui/app/AppLayouts/Profile/stores/ContactsStore.qml b/ui/app/AppLayouts/Profile/stores/ContactsStore.qml index 3460271396..8807527e5c 100644 --- a/ui/app/AppLayouts/Profile/stores/ContactsStore.qml +++ b/ui/app/AppLayouts/Profile/stores/ContactsStore.qml @@ -41,10 +41,6 @@ QtObject { root.contactsModule.switchToOrCreateOneToOneChat(pubKey) } - function addContact(pubKey) { - root.contactsModule.addContact(pubKey) - } - function unblockContact(pubKey) { root.contactsModule.unblockContact(pubKey) } @@ -60,13 +56,17 @@ QtObject { function changeContactNickname(pubKey, nickname) { root.contactsModule.changeContactNickname(pubKey, nickname) } - - function acceptContactRequest(pubKey) { - root.contactsModule.addContact(pubKey) + + function sendContactRequest(pubKey, message) { + root.contactsModule.sendContactRequest(pubKey, message) } - function rejectContactRequest(pubKey) { - root.contactsModule.rejectContactRequest(pubKey) + function acceptContactRequest(pubKey) { + root.contactsModule.acceptContactRequest(pubKey) + } + + function dismissContactRequest(pubKey) { + root.contactsModule.dismissContactRequest(pubKey) } function removeContactRequestRejection(pubKey) { diff --git a/ui/app/AppLayouts/Profile/views/ContactsView.qml b/ui/app/AppLayouts/Profile/views/ContactsView.qml index 35d4e33cbf..67b92c0cb6 100644 --- a/ui/app/AppLayouts/Profile/views/ContactsView.qml +++ b/ui/app/AppLayouts/Profile/views/ContactsView.qml @@ -192,7 +192,7 @@ SettingsContentBase { } onContactRequestRejected: { - root.contactsStore.rejectContactRequest(publicKey) + root.contactsStore.dismissContactRequest(publicKey) } } diff --git a/ui/imports/shared/popups/ProfilePopup.qml b/ui/imports/shared/popups/ProfilePopup.qml index 3d9854b8c5..6ab7f0ce9f 100644 --- a/ui/imports/shared/popups/ProfilePopup.qml +++ b/ui/imports/shared/popups/ProfilePopup.qml @@ -331,7 +331,7 @@ StatusModal { text: qsTr("Add to contacts") visible: !userIsBlocked && !isAddedContact onClicked: { - popup.contactsStore.addContact(userPublicKey); + popup.contactsStore.sendContactRequest(userPublicKey); popup.contactAdded(userPublicKey); popup.close(); }