From b81f4dd150645419345b58119cb1a52e0d8dd36d Mon Sep 17 00:00:00 2001 From: Sale Djenic Date: Mon, 26 Dec 2022 17:35:47 +0100 Subject: [PATCH] fix(@desktop/onboarding): refetching backed up data added --- src/app/modules/startup/controller.nim | 5 ++++- .../internal/profile_fetching_announcement_state.nim | 7 ++++++- src/app/modules/startup/io_interface.nim | 3 +++ src/app/modules/startup/module.nim | 9 ++++++++- src/app_service/service/general/service.nim | 11 ++++++++++- src/backend/mailservers.nim | 3 +++ .../Onboarding/views/ProfileFetchingView.qml | 6 ++++++ 7 files changed, 40 insertions(+), 4 deletions(-) diff --git a/src/app/modules/startup/controller.nim b/src/app/modules/startup/controller.nim index 76cadf4836..cb17834fb1 100644 --- a/src/app/modules/startup/controller.nim +++ b/src/app/modules/startup/controller.nim @@ -109,7 +109,7 @@ proc connectToFetchingFromWakuEvents*(self: Controller) = proc connectToTimeoutEventAndStratTimer*(self: Controller, timeoutInMilliseconds: int) = var handlerId = self.events.onWithUUID(SIGNAL_GENERAL_TIMEOUT) do(e: Args): - self.delegate.moveToStartupState() + self.delegate.startAppAfterDelay() self.connectionIds.add(handlerId) self.generalService.runTimer(timeoutInMilliseconds) @@ -190,6 +190,9 @@ proc generateImage*(self: Controller, imageUrl: string, aX: int, aY: int, bX: in self.tmpProfileImageDetails = ProfileImageDetails(url: imageUrl, croppedImage: img.uri, x1: aX, y1: aY, x2: bX, y2: bY) return img.uri +proc fetchWakuMessages*(self: Controller) = + self.generalService.fetchWakuMessages() + proc getCroppedProfileImage*(self: Controller): string = return self.tmpProfileImageDetails.croppedImage diff --git a/src/app/modules/startup/internal/profile_fetching_announcement_state.nim b/src/app/modules/startup/internal/profile_fetching_announcement_state.nim index edf11d0c57..06c4bbaa97 100644 --- a/src/app/modules/startup/internal/profile_fetching_announcement_state.nim +++ b/src/app/modules/startup/internal/profile_fetching_announcement_state.nim @@ -11,7 +11,12 @@ proc delete*(self: ProfileFetchingAnnouncementState) = method executePrimaryCommand*(self: ProfileFetchingAnnouncementState, controller: Controller) = if self.flowType == FlowType.FirstRunOldUserImportSeedPhrase or self.flowType == FlowType.FirstRunOldUserKeycardImport: - echo "TODO: Try to fetch profile again..." + controller.fetchWakuMessages() + +method getNextPrimaryState*(self: ProfileFetchingAnnouncementState, controller: Controller): State = + if self.flowType == FlowType.FirstRunOldUserImportSeedPhrase or + self.flowType == FlowType.FirstRunOldUserKeycardImport: + return createState(StateType.ProfileFetching, self.flowType, nil) method getNextSecondaryState*(self: ProfileFetchingAnnouncementState, controller: Controller): State = if self.flowType == FlowType.FirstRunOldUserImportSeedPhrase or diff --git a/src/app/modules/startup/io_interface.nim b/src/app/modules/startup/io_interface.nim index 24f3b6ef06..de5ae86fbe 100644 --- a/src/app/modules/startup/io_interface.nim +++ b/src/app/modules/startup/io_interface.nim @@ -154,6 +154,9 @@ method finishAppLoading*(self: AccessInterface) {.base.} = method checkFetchingStatusAndProceedWithAppLoading*(self: AccessInterface) {.base.} = raise newException(ValueError, "No implementation available") +method startAppAfterDelay*(self: AccessInterface) {.base.} = + raise newException(ValueError, "No implementation available") + # This way (using concepts) is used only for the modules managed by AppController type DelegateInterface* = concept c diff --git a/src/app/modules/startup/module.nim b/src/app/modules/startup/module.nim index a73a6477ab..7ab88accd7 100644 --- a/src/app/modules/startup/module.nim +++ b/src/app/modules/startup/module.nim @@ -330,6 +330,14 @@ proc delayStartingApp[T](self: Module[T]) = ## we want to delay app start just to be sure that messages from waku will be received 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)) + self.moveToStartupState() + proc logoutAndDisplayError[T](self: Module[T], error: string) = self.delegate.logout() self.moveToStartupState() @@ -346,7 +354,6 @@ method onNodeLogin*[T](self: Module[T], error: string) = currStateObj.flowType() == FlowType.FirstRunOldUserKeycardImport: self.prepareAndInitFetchingData() self.controller.connectToFetchingFromWakuEvents() - self.view.setCurrentStartupState(newProfileFetchingState(currStateObj.flowType(), nil)) self.delayStartingApp() let err = self.delegate.userLoggedIn() if err.len > 0: diff --git a/src/app_service/service/general/service.nim b/src/app_service/service/general/service.nim index 3daefa9d69..9e7731aa24 100644 --- a/src/app_service/service/general/service.nim +++ b/src/app_service/service/general/service.nim @@ -1,5 +1,6 @@ import NimQml, os, json, chronicles +import ../../../backend/mailservers as status_mailservers import ../../../backend/general as status_general import ../../../app/core/eventemitter import ../../../app/core/tasks/[qt, threadpool] @@ -84,4 +85,12 @@ QtObject: if self.timeoutInMilliseconds <= 0: self.events.emit(SIGNAL_GENERAL_TIMEOUT, Args()) else: - self.runTimer() \ No newline at end of file + self.runTimer() + + proc fetchWakuMessages*(self: Service) = + try: + let response = status_mailservers.requestAllHistoricMessages() + if(not response.error.isNil): + error "could not set display name" + except Exception as e: + error "error: ", procName="fetchWakuMessages", errName = e.name, errDesription = e.msg \ No newline at end of file diff --git a/src/backend/mailservers.nim b/src/backend/mailservers.nim index bfddcd6aeb..7c2b02eb13 100644 --- a/src/backend/mailservers.nim +++ b/src/backend/mailservers.nim @@ -29,3 +29,6 @@ proc fillGaps*(chatId: string, messageIds: seq[string]): RpcResponse[JsonNode] { let payload = %*[chatId, messageIds] result = core.callPrivateRPC("fillGaps".prefix, payload) info "fillGaps", topics="mailserver-interaction", rpc_method="wakuext_fillGaps", chatId, messageIds, result + +proc requestAllHistoricMessages*(): RpcResponse[JsonNode] {.raises: [Exception].} = + result = core.callPrivateRPC("requestAllHistoricMessages".prefix) \ No newline at end of file diff --git a/ui/app/AppLayouts/Onboarding/views/ProfileFetchingView.qml b/ui/app/AppLayouts/Onboarding/views/ProfileFetchingView.qml index a41827b7c1..bdbf1d0e26 100644 --- a/ui/app/AppLayouts/Onboarding/views/ProfileFetchingView.qml +++ b/ui/app/AppLayouts/Onboarding/views/ProfileFetchingView.qml @@ -24,6 +24,12 @@ Item { property int counter: d.timeout } + onStateChanged: { + if (root.startupStore.currentStartupState.stateType === Constants.startupState.profileFetching) { + d.counter = d.timeout + } + } + ColumnLayout { anchors.centerIn: parent height: Constants.keycard.general.onboardingHeight