Skip to content

Commit

Permalink
fix(@desktop/onboarding): refetching backed up data added
Browse files Browse the repository at this point in the history
  • Loading branch information
saledjenic committed Jan 4, 2023
1 parent 6b6aaf3 commit b81f4dd
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/app/modules/startup/controller.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/app/modules/startup/io_interface.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion src/app/modules/startup/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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:
Expand Down
11 changes: 10 additions & 1 deletion src/app_service/service/general/service.nim
Original file line number Diff line number Diff line change
@@ -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]
Expand Down Expand Up @@ -84,4 +85,12 @@ QtObject:
if self.timeoutInMilliseconds <= 0:
self.events.emit(SIGNAL_GENERAL_TIMEOUT, Args())
else:
self.runTimer()
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
3 changes: 3 additions & 0 deletions src/backend/mailservers.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
6 changes: 6 additions & 0 deletions ui/app/AppLayouts/Onboarding/views/ProfileFetchingView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b81f4dd

Please sign in to comment.