From d53548f68cf0bc486a6111bf2789a29d28e416e3 Mon Sep 17 00:00:00 2001 From: Sale Djenic Date: Tue, 2 Nov 2021 12:58:36 +0100 Subject: [PATCH] fix(@refactoring/base_01): crash on recovering account Fixes: #3953 --- src/app_service/service/contacts/service.nim | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/app_service/service/contacts/service.nim b/src/app_service/service/contacts/service.nim index 69a5c06990..e394fc54c7 100644 --- a/src/app_service/service/contacts/service.nim +++ b/src/app_service/service/contacts/service.nim @@ -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()