From d7e4ee2395376e8e1c050a0ac72fa963c3d0e6c9 Mon Sep 17 00:00:00 2001 From: Sale Djenic Date: Sat, 7 Jan 2023 22:05:26 +0100 Subject: [PATCH] fix(@desktop/onboarding): fetching waku data ui improvements - icon added to the ui items we're syncing - in case data are fetched during 30 seconds timeframe the app is staying in success state --- .../startup/models/fetching_data_item.nim | 7 +++++- .../startup/models/fetching_data_model.nim | 10 +++++--- src/app/modules/startup/module.nim | 23 +++++++++++++------ src/app/modules/startup/view.nim | 2 +- 4 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/app/modules/startup/models/fetching_data_item.nim b/src/app/modules/startup/models/fetching_data_item.nim index a507b6b34d..fc9ce4e9d2 100644 --- a/src/app/modules/startup/models/fetching_data_item.nim +++ b/src/app/modules/startup/models/fetching_data_item.nim @@ -1,18 +1,23 @@ type Item* = ref object entity: string + icon: string trackOfLoadedMessages: seq[bool] totalMessages: int -proc newItem*(entity: string, totalMessages: int = 0): Item = +proc newItem*(entity: string, icon: string, totalMessages: int = 0): Item = result = Item() result.entity = entity + result.icon = icon result.trackOfLoadedMessages = @[] result.totalMessages = totalMessages proc entity*(self: Item): string = return self.entity +proc icon*(self: Item): string = + return self.icon + proc loadedMessages*(self: Item): int = if self.trackOfLoadedMessages.len == 0: return 0 diff --git a/src/app/modules/startup/models/fetching_data_model.nim b/src/app/modules/startup/models/fetching_data_model.nim index bbe0354d38..9d04e5612d 100644 --- a/src/app/modules/startup/models/fetching_data_model.nim +++ b/src/app/modules/startup/models/fetching_data_model.nim @@ -5,6 +5,7 @@ import fetching_data_item type ModelRole {.pure.} = enum Entity = UserRole + 1 + Icon LoadedMessages TotalMessages @@ -39,6 +40,7 @@ QtObject: method roleNames(self: Model): Table[int, string] = { ModelRole.Entity.int:"entity", + ModelRole.Icon.int:"icon", ModelRole.LoadedMessages.int:"loadedMessages", ModelRole.TotalMessages.int:"totalMessages" }.toTable @@ -56,6 +58,8 @@ QtObject: case enumRole: of ModelRole.Entity: result = newQVariant(item.entity()) + of ModelRole.Icon: + result = newQVariant(item.icon()) of ModelRole.LoadedMessages: result = newQVariant(item.loadedMessages()) of ModelRole.TotalMessages: @@ -67,10 +71,10 @@ QtObject: return i return -1 - proc init*(self: Model, entities: seq[string]) = + proc init*(self: Model, entities: seq[tuple[entity: string, icon: string]]) = self.beginResetModel() - for s in entities: - self.items.add(newItem(s)) + for e in entities: + self.items.add(newItem(e.entity, e.icon)) self.endResetModel() self.countChanged() diff --git a/src/app/modules/startup/module.nim b/src/app/modules/startup/module.nim index 7ab88accd7..68b758f921 100644 --- a/src/app/modules/startup/module.nim +++ b/src/app/modules/startup/module.nim @@ -23,9 +23,13 @@ logScope: topics = "startup-module" const FetchingFromWakuProfile = "profile" +const FetchingFromWakuProfileIcon = "profile" const FetchingFromWakuContacts = "contacts" +const FetchingFromWakuContactsIcon = "contact-book" const FetchingFromWakuCommunities = "communities" +const FetchingFromWakuCommunitiesIcon = "communities" const FetchingFromWakuSettings = "settings" +const FetchingFromWakuSettingsIcon = "settings" type Module*[T: io_interface.DelegateInterface] = ref object of io_interface.AccessInterface @@ -319,8 +323,12 @@ method onFetchingFromWakuMessageReceived*[T](self: Module[T], section: string, t proc prepareAndInitFetchingData[T](self: Module[T]) = # fetching data from waku starts when messenger starts - const listOfEntitiesWeExpectToBeSynced = @[FetchingFromWakuProfile, FetchingFromWakuContacts, FetchingFromWakuCommunities, - FetchingFromWakuSettings] + const listOfEntitiesWeExpectToBeSynced = @[ + (FetchingFromWakuProfile, FetchingFromWakuProfileIcon), + (FetchingFromWakuContacts, FetchingFromWakuContactsIcon), + (FetchingFromWakuCommunities, FetchingFromWakuCommunitiesIcon), + (FetchingFromWakuSettings, FetchingFromWakuSettingsIcon) + ] self.view.createAndInitFetchingDataModel(listOfEntitiesWeExpectToBeSynced) proc delayStartingApp[T](self: Module[T]) = @@ -331,11 +339,12 @@ proc delayStartingApp[T](self: Module[T]) = self.controller.connectToTimeoutEventAndStratTimer(timeoutInMilliseconds = 30000) # delay for 30 seconds method startAppAfterDelay*[T](self: Module[T]) = - let currStateObj = self.view.currentStartupStateObj() - if currStateObj.isNil: - error "cannot determine current startup state" - quit() # quit the app - self.view.setCurrentStartupState(newProfileFetchingState(currStateObj.flowType(), nil)) + if not self.view.fetchingDataModel().allMessagesLoaded(): + let currStateObj = self.view.currentStartupStateObj() + if currStateObj.isNil: + error "cannot determine current startup state" + quit() # quit the app + self.view.setCurrentStartupState(newProfileFetchingState(currStateObj.flowType(), nil)) self.moveToStartupState() proc logoutAndDisplayError[T](self: Module[T], error: string) = diff --git a/src/app/modules/startup/view.nim b/src/app/modules/startup/view.nim index 5706c087e6..1c9bf4a1bd 100644 --- a/src/app/modules/startup/view.nim +++ b/src/app/modules/startup/view.nim @@ -291,7 +291,7 @@ QtObject: read = getFetchingDataModel notify = fetchingDataModelChanged - proc createAndInitFetchingDataModel*(self: View, sections: seq[string]) = + proc createAndInitFetchingDataModel*(self: View, sections: seq[tuple[entity: string, icon: string]]) = if self.fetchingDataModel.isNil: self.fetchingDataModel = fetch_model.newModel() if self.fetchingDataModelVariant.isNil: