diff --git a/src/app/chat/view.nim b/src/app/chat/view.nim index c409acbce3..e57bacf621 100644 --- a/src/app/chat/view.nim +++ b/src/app/chat/view.nim @@ -156,6 +156,9 @@ QtObject: proc addContact*(self: ChatsView, id: string): string {.slot.} = return self.status.contacts.addContact(id) + proc removeContact*(self: ChatsView, id: string) {.slot.} = + self.status.contacts.removeContact(id) + proc createGroup*(self: ChatsView, groupName: string, pubKeys: string) {.slot.} = let pubKeysSeq = map(parseJson(pubKeys).getElems(), proc(x:JsonNode):string = x.getStr) self.status.chat.createGroup(groupName, pubKeysSeq) diff --git a/src/app/profile/core.nim b/src/app/profile/core.nim index 09f14786b0..1f5f12b26b 100644 --- a/src/app/profile/core.nim +++ b/src/app/profile/core.nim @@ -50,6 +50,10 @@ proc init*(self: ProfileController, account: Account) = let contacts = self.status.contacts.getContacts() self.view.setContactList(contacts) + self.status.events.on("contactRemoved") do(e: Args): + let contacts = self.status.contacts.getContacts() + self.view.setContactList(contacts) + method onSignal(self: ProfileController, data: Signal) = let msgData = MessageSignal(data); if msgData.contacts.len > 0: diff --git a/src/app/profile/view.nim b/src/app/profile/view.nim index 01fc0a062f..eea8945530 100644 --- a/src/app/profile/view.nim +++ b/src/app/profile/view.nim @@ -4,6 +4,7 @@ import views/contact_list import views/profile_info import ../../status/profile/[mailserver, profile] import ../../status/profile as status_profile +import ../../status/contacts as status_contacts import ../../status/accounts as status_accounts import ../../status/status import ../../status/chat/chat @@ -71,3 +72,7 @@ QtObject: proc nodeVersion*(self: ProfileView): string {.slot.} = self.status.getNodeVersion() + + proc isAdded*(self: ProfileView, id: string): bool {.slot.} = + if id == "": return false + self.status.contacts.isAdded(id) diff --git a/src/status/contacts.nim b/src/status/contacts.nim index 76d21cc5a8..1926522410 100644 --- a/src/status/contacts.nim +++ b/src/status/contacts.nim @@ -34,3 +34,13 @@ proc addContact*(self: ContactModel, id: string): string = contact.systemTags.add(":contact/added") result = status_contacts.saveContact(contact.id, contact.ensVerified, contact.ensVerifiedAt, contact.ensVerificationRetries, contact.alias, contact.identicon, contact.systemTags) self.events.emit("contactAdded", Args()) + +proc removeContact*(self: ContactModel, id: string) = + let contact = self.getContactByID(id) + contact.systemTags.delete(contact.systemTags.find(":contact/added")) + discard status_contacts.saveContact(contact.id, contact.ensVerified, contact.ensVerifiedAt, contact.ensVerificationRetries, contact.alias, contact.identicon, contact.systemTags) + self.events.emit("contactRemoved", Args()) + +proc isAdded*(self: ContactModel, id: string): bool = + var contact = self.getContactByID(id) + contact.systemTags.contains(":contact/added") diff --git a/ui/app/AppLayouts/Chat/components/ProfilePopup.qml b/ui/app/AppLayouts/Chat/components/ProfilePopup.qml index 7e5601e64a..fd9da52f10 100644 --- a/ui/app/AppLayouts/Chat/components/ProfilePopup.qml +++ b/ui/app/AppLayouts/Chat/components/ProfilePopup.qml @@ -240,12 +240,14 @@ ModalPopup { id: addToContactsButton anchors.right: parent.right anchors.rightMargin: Theme.smallPadding - label: qsTr("Add to contacts") + label: profileModel.isAdded(fromAuthor) ? qsTr("Remove Contact") : qsTr("Add to contacts") anchors.bottom: parent.bottom onClicked: { - chatsModel.addContact(fromAuthor) - // TODO(iuri): Change add contact button state based - // on contact already added or not + if (profileModel.isAdded(fromAuthor)) { + chatsModel.removeContact(fromAuthor) + } else { + chatsModel.addContact(fromAuthor) + } profilePopup.close() } }