perf(@desktop/chat): avoid query when switching chat

As we keep a local list of contact request and contact added
we should not need to query this data each time we switch chat as
we already have this data in memory.

This data should be maintained each time there is a change

fixes #1642

Also: Remove what seems to be duplicated and dead code about
getContactById
This commit is contained in:
Anthony Laibe 2021-08-30 14:53:28 +02:00 committed by Iuri Matias
parent f47ddbc955
commit 0d5cf71df5
2 changed files with 10 additions and 9 deletions

View File

@ -152,13 +152,17 @@ QtObject:
read = getContactToAddPubKey
notify = contactToAddChanged
proc isAdded*(self: ContactsView, id: string): bool {.slot.} =
if id == "": return false
self.status.contacts.isAdded(id)
proc isAdded*(self: ContactsView, pubkey: string): bool {.slot.} =
for contact in self.addedContacts.contacts:
if contact.id == pubkey:
return true
return false
proc contactRequestReceived*(self: ContactsView, id: string): bool {.slot.} =
if id == "": return false
self.status.contacts.contactRequestReceived(id)
proc contactRequestReceived*(self: ContactsView, pubkey: string): bool {.slot.} =
for contact in self.contactRequests.contacts:
if contact.id == pubkey:
return true
return false
proc lookupContact*(self: ContactsView, value: string) {.slot.} =
if value == "":

View File

@ -42,9 +42,6 @@ proc removePeer*(peer: string) =
proc markTrustedPeer*(peer: string) =
discard callPrivateRPC("markTrustedPeer".prefix(false), %* [peer])
proc getContactByID*(id: string): string =
result = callPrivateRPC("getContactByID".prefix, %* [id])
proc getBlockByNumber*(blockNumber: string): string =
result = callPrivateRPC("eth_getBlockByNumber", %* [blockNumber, false])