fix: introduce missing contact related RPC APIs (#110)

There was a breaking change in status-go that has removed the
`saveContact` API which `status-lib` has used in various places to perform
changes on contact data.

There are now more dedicated APIs for contact related actions,
such as: `AddContact`, `RemoveContact`, `BlockContact` etc.

This commit introduces APIs for these RPC calls and adjusts other
APIs that relied on `saveContact` before.
This commit is contained in:
r4bbit.eth 2021-11-23 14:15:06 +01:00 committed by GitHub
parent 6c7deb85a0
commit 4ff2b6857c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 66 additions and 42 deletions

View File

@ -36,15 +36,11 @@ proc getContactByID*(self: ContactModel, id: string): Profile =
return status_contacts.getContactByID(id) return status_contacts.getContactByID(id)
proc blockContact*(self: ContactModel, id: string) = proc blockContact*(self: ContactModel, id: string) =
var contact = self.getContactByID(id) status_contacts.blockContact(id)
contact.blocked = true
self.saveContact(contact)
self.events.emit("contactBlocked", ContactIdArgs(id: id)) self.events.emit("contactBlocked", ContactIdArgs(id: id))
proc unblockContact*(self: ContactModel, id: string) = proc unblockContact*(self: ContactModel, id: string) =
var contact = self.getContactByID(id) status_contacts.unblockContact(id)
contact.blocked = false
self.saveContact(contact)
self.events.emit("contactUnblocked", ContactIdArgs(id: id)) self.events.emit("contactUnblocked", ContactIdArgs(id: id))
proc getContacts*(self: ContactModel, useCache: bool = true): seq[Profile] = proc getContacts*(self: ContactModel, useCache: bool = true): seq[Profile] =
@ -83,7 +79,7 @@ proc setNickName*(self: ContactModel, id: string, localNickname: string, account
localNickname localNickname
contact.localNickname = nickname contact.localNickname = nickname
self.saveContact(contact) status_contacts.setContactLocalNickname(id, nickname);
self.events.emit("contactAdded", Args()) self.events.emit("contactAdded", Args())
sendContactUpdate(contact.id, accountKeyUID) sendContactUpdate(contact.id, accountKeyUID)
@ -119,11 +115,7 @@ proc addContact*(self: ContactModel, id: string, accountKeyUID: string) =
self.events.emit("contactUpdate", ContactUpdateArgs(contacts: @[profile])) self.events.emit("contactUpdate", ContactUpdateArgs(contacts: @[profile]))
proc removeContact*(self: ContactModel, id: string) = proc removeContact*(self: ContactModel, id: string) =
let contact = self.getContactByID(id) status_contacts.removeContact(id)
contact.added = false
contact.hasAddedUs = false
self.saveContact(contact)
self.events.emit("contactRemoved", Args()) self.events.emit("contactRemoved", Args())
proc isAdded*(self: ContactModel, id: string): bool = proc isAdded*(self: ContactModel, id: string): bool =

View File

@ -47,25 +47,44 @@ proc getContactsIndex*(): (Table[string, Profile], bool)=
discard getContacts() discard getContacts()
return (contactsIndex, false) 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, proc saveContact*(id: string, ensVerified: bool, ensName: string, alias: string,
identicon: string, thumbnail: string, largeImage: string, added: bool, blocked: bool, identicon: string, thumbnail: string, largeImage: string, added: bool, blocked: bool,
hasAddedUs: bool, localNickname: string) = 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 = %* [{ let payload = %* [{
"id": id, "id": id,
"name": ensName, "ensName": 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
}] }]
discard callPrivateRPC("saveContact".prefix, payload)
discard callPrivateRPC("addContact".prefix, payload)
dirty.store(true) dirty.store(true)
proc sendContactUpdate*(publicKey: string, accountKeyUID: string) = proc sendContactUpdate*(publicKey: string, accountKeyUID: string) =

View File

@ -12,27 +12,40 @@ proc getContactById*(id: string): RpcResponse[JsonNode] {.raises: [Exception].}
let payload = %* [id] let payload = %* [id]
result = callPrivateRPC("getContactByID".prefix, payload) 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, proc saveContact*(id: string, ensVerified: bool, ensName: string, alias: string,
identicon: string, thumbnail: string, largeImage: string, added: bool, identicon: string, thumbnail: string, largeImage: string, added: bool,
blocked: bool, hasAddedUs: bool, localNickname: string) blocked: bool, hasAddedUs: bool, localNickname: string)
{.raises: [Exception].} = {.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 = %* [{ let payload = %* [{
"id": id, "id": id,
"name": ensName, "ensName": 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
}] }]
discard callPrivateRPC("saveContact".prefix, payload) discard callPrivateRPC("addContact".prefix, payload)
proc sendContactUpdate*(publicKey, ensName, thumbnail: string) proc sendContactUpdate*(publicKey, ensName, thumbnail: string)
{.raises: [Exception].} = {.raises: [Exception].} =

2
vendor/status-go vendored

@ -1 +1 @@
Subproject commit 6099380d9c461be82763f2467272caa54cf5df2e Subproject commit ded81b7a51a7609b3b45588adbac471d3db64759