fix(@refactoring/base_01): crash on recovering account

Fixes: #3953
This commit is contained in:
Sale Djenic 2021-11-02 12:58:36 +01:00 committed by Iuri Matias
parent 0b2ce88fcc
commit d53548f68c
1 changed files with 16 additions and 4 deletions

View File

@ -40,13 +40,25 @@ QtObject:
result.threadpool = threadpool
result.contacts = initTable[string, ContactsDto]()
proc fetchContacts(self: Service) =
try:
let response = status_contacts.getContacts()
let contacts = map(response.result.getElems(), proc(x: JsonNode): ContactsDto = x.toContactsDto())
for contact in contacts:
self.contacts[contact.id] = contact
except Exception as e:
let errDesription = e.msg
error "error: ", errDesription
return
proc init*(self: Service) =
discard
self.fetchContacts()
proc getContacts*(self: Service): seq[ContactsDto] =
let profiles = status_contacts.getContacts()
for profile in profiles.result:
result.add(profile.toContactsDto)
return toSeq(self.contacts.values)
proc getContact*(self: Service, id: string): ContactsDto =
return status_contacts.getContactByID(id).result.toContactsDto()