diff --git a/status/contacts.nim b/status/contacts.nim index c8ba94d..124b82d 100644 --- a/status/contacts.nim +++ b/status/contacts.nim @@ -36,15 +36,11 @@ proc getContactByID*(self: ContactModel, id: string): Profile = return status_contacts.getContactByID(id) proc blockContact*(self: ContactModel, id: string) = - var contact = self.getContactByID(id) - contact.blocked = true - self.saveContact(contact) + status_contacts.blockContact(id) self.events.emit("contactBlocked", ContactIdArgs(id: id)) proc unblockContact*(self: ContactModel, id: string) = - var contact = self.getContactByID(id) - contact.blocked = false - self.saveContact(contact) + status_contacts.unblockContact(id) self.events.emit("contactUnblocked", ContactIdArgs(id: id)) proc getContacts*(self: ContactModel, useCache: bool = true): seq[Profile] = @@ -83,7 +79,7 @@ proc setNickName*(self: ContactModel, id: string, localNickname: string, account localNickname contact.localNickname = nickname - self.saveContact(contact) + status_contacts.setContactLocalNickname(id, nickname); self.events.emit("contactAdded", Args()) sendContactUpdate(contact.id, accountKeyUID) @@ -119,11 +115,7 @@ proc addContact*(self: ContactModel, id: string, accountKeyUID: string) = self.events.emit("contactUpdate", ContactUpdateArgs(contacts: @[profile])) proc removeContact*(self: ContactModel, id: string) = - let contact = self.getContactByID(id) - contact.added = false - contact.hasAddedUs = false - - self.saveContact(contact) + status_contacts.removeContact(id) self.events.emit("contactRemoved", Args()) proc isAdded*(self: ContactModel, id: string): bool = diff --git a/status/statusgo_backend/contacts.nim b/status/statusgo_backend/contacts.nim index 0cddd3e..ffc3642 100644 --- a/status/statusgo_backend/contacts.nim +++ b/status/statusgo_backend/contacts.nim @@ -47,25 +47,44 @@ proc getContactsIndex*(): (Table[string, Profile], bool)= discard getContacts() return (contactsIndex, false) +proc blockContact*(id: string) = + discard callPrivateRPC("blockContact".prefix, %* [id]) + dirty.store(true) + +proc unblockContact*(id: string) = + discard callPrivateRPC("unblockContact".prefix, %* [id]) + dirty.store(true) + +proc removeContact*(id: string) = + discard callPrivateRPC("removeContact".prefix, %* [id]) + dirty.store(true) + +proc rejectContactRequest*(id: string) = + let payload = %*[{ + "id": id + }] + discard callPrivateRPC("rejectContactRequest".prefix, payload) + dirty.store(true) + +proc setContactLocalNickname*(id: string, name: string) = + let payload = %* [{ + "id": id, + "nickname": name + }] + discard callPrivateRPC("setContactLocalNickname".prefix, payload) + dirty.store(true) + proc saveContact*(id: string, ensVerified: bool, ensName: string, alias: string, identicon: string, thumbnail: string, largeImage: string, added: bool, blocked: bool, hasAddedUs: bool, localNickname: string) = + # TODO: Most of these method arguments aren't used anymore + # as status-go's RPC API became smarter. Should remove those. let payload = %* [{ "id": id, - "name": ensName, - "ensVerified": ensVerified, - "alias": alias, - "identicon": identicon, - "images": { - "thumbnail": {"Payload": thumbnail.partition(",")[2]}, - "large": {"Payload": largeImage.partition(",")[2]} - }, - "added": added, - "blocked": blocked, - "hasAddedUs": hasAddedUs, - "localNickname": localNickname + "ensName": ensName }] - discard callPrivateRPC("saveContact".prefix, payload) + + discard callPrivateRPC("addContact".prefix, payload) dirty.store(true) proc sendContactUpdate*(publicKey: string, accountKeyUID: string) = diff --git a/status/statusgo_backend_new/contacts.nim b/status/statusgo_backend_new/contacts.nim index 1dd2f9c..5c99dac 100644 --- a/status/statusgo_backend_new/contacts.nim +++ b/status/statusgo_backend_new/contacts.nim @@ -12,30 +12,43 @@ proc getContactById*(id: string): RpcResponse[JsonNode] {.raises: [Exception].} let payload = %* [id] result = callPrivateRPC("getContactByID".prefix, payload) +proc blockContact*(id: string) = + discard callPrivateRPC("blockContact".prefix, %* [id]) + +proc unblockContact*(id: string) = + discard callPrivateRPC("unblockContact".prefix, %* [id]) + +proc removeContact*(id: string) = + discard callPrivateRPC("removeContact".prefix, %* [id]) + +proc rejectContactRequest*(id: string) = + let payload = %*[{ + "id": id + }] + discard callPrivateRPC("rejectContactRequest".prefix, payload) + +proc setContactLocalNickname*(id: string, name: string) = + let payload = %* [{ + "id": id, + "nickname": name + }] + discard callPrivateRPC("setContactLocalNickname".prefix, payload) + proc saveContact*(id: string, ensVerified: bool, ensName: string, alias: string, identicon: string, thumbnail: string, largeImage: string, added: bool, blocked: bool, hasAddedUs: bool, localNickname: string) {.raises: [Exception].} = + # TODO: Most of these method arguments aren't used anymore + # as status-go's RPC API became smarter. Should remove those. let payload = %* [{ - "id": id, - "name": ensName, - "ensVerified": ensVerified, - "alias": alias, - "identicon": identicon, - "images": { - "thumbnail": {"Payload": thumbnail.partition(",")[2]}, - "large": {"Payload": largeImage.partition(",")[2]} - }, - "added": added, - "blocked": blocked, - "hasAddedUs": hasAddedUs, - "localNickname": localNickname - }] + "id": id, + "ensName": ensName + }] - discard callPrivateRPC("saveContact".prefix, payload) + discard callPrivateRPC("addContact".prefix, payload) proc sendContactUpdate*(publicKey, ensName, thumbnail: string) {.raises: [Exception].} = let payload = %* [publicKey, ensName, thumbnail] discard callPrivateRPC("sendContactUpdate".prefix, payload) - \ No newline at end of file + diff --git a/vendor/status-go b/vendor/status-go index 6099380..ded81b7 160000 --- a/vendor/status-go +++ b/vendor/status-go @@ -1 +1 @@ -Subproject commit 6099380d9c461be82763f2467272caa54cf5df2e +Subproject commit ded81b7a51a7609b3b45588adbac471d3db64759