Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(onboarding): add AC notif for importing old accounts #17078

Open
wants to merge 1 commit into
base: feat/new-onboarding-metrics
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions src/app/modules/main/activity_center/controller.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import ./io_interface

import ../../../global/app_signals
import ../../../core/eventemitter
import ../../../../app_service/service/activity_center/service as activity_center_service
import ../../../../app_service/service/contacts/service as contacts_service
import ../../../../app_service/service/message/service as message_service
import ../../../../app_service/service/community/service as community_service
import ../../../../app_service/service/chat/service as chat_service
import ../../../../app_service/service/devices/service as devices_service
import app_service/service/activity_center/service as activity_center_service
import app_service/service/contacts/service as contacts_service
import app_service/service/message/service as message_service
import app_service/service/community/service as community_service
import app_service/service/chat/service as chat_service
import app_service/service/devices/service as devices_service
import app_service/service/general/service as general_service

type
Controller* = ref object of RootObj
Expand All @@ -19,6 +20,7 @@ type
chatService: chat_service.Service
communityService: community_service.Service
devicesService: devices_service.Service
generalService: general_service.Service

proc newController*(
delegate: io_interface.AccessInterface,
Expand All @@ -29,6 +31,7 @@ proc newController*(
chatService: chat_service.Service,
communityService: community_service.Service,
devicesService: devices_service.Service,
generalService: general_service.Service,
): Controller =
result = Controller()
result.delegate = delegate
Expand All @@ -39,6 +42,7 @@ proc newController*(
result.chatService = chatService
result.communityService = communityService
result.devicesService = devicesService
result.generalService = generalService

proc delete*(self: Controller) =
discard
Expand Down Expand Up @@ -169,3 +173,6 @@ proc getActivityCenterReadType*(self: Controller): ActivityCenterReadType =

proc enableInstallationAndSync*(self: Controller, installationId: string) =
self.devicesService.enableInstallationAndSync(installationId)

proc tryFetchingAgain*(self: Controller) =
self.generalService.asyncFetchWakuBackupMessages()
3 changes: 3 additions & 0 deletions src/app/modules/main/activity_center/io_interface.nim
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,6 @@ method setActivityGroupCounters*(self: AccessInterface, counters: Table[Activity

method enableInstallationAndSync*(self: AccessInterface, installationId: string) {.base.} =
raise newException(ValueError, "No implementation available")

method tryFetchingAgain*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
18 changes: 12 additions & 6 deletions src/app/modules/main/activity_center/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ import ../../shared_models/message_item_qobject as msg_item_qobj
import ../../../global/global_singleton
import ../../../global/app_sections_config as conf
import ../../../core/eventemitter
import ../../../../app_service/service/activity_center/service as activity_center_service
import ../../../../app_service/service/contacts/service as contacts_service
import ../../../../app_service/service/message/service as message_service
import ../../../../app_service/service/chat/service as chat_service
import ../../../../app_service/service/community/service as community_service
import ../../../../app_service/service/devices/service as devices_service
import app_service/service/activity_center/service as activity_center_service
import app_service/service/contacts/service as contacts_service
import app_service/service/message/service as message_service
import app_service/service/chat/service as chat_service
import app_service/service/community/service as community_service
import app_service/service/devices/service as devices_service
import app_service/service/general/service as general_service

export io_interface

Expand All @@ -35,6 +36,7 @@ proc newModule*(
chatService: chat_service.Service,
communityService: community_service.Service,
devicesService: devices_service.Service,
generalService: general_service.Service,
): Module =
result = Module()
result.delegate = delegate
Expand All @@ -49,6 +51,7 @@ proc newModule*(
chatService,
communityService,
devicesService,
generalService,
)
result.moduleLoaded = false

Expand Down Expand Up @@ -288,3 +291,6 @@ method setActivityGroupCounters*(self: Module, counters: Table[ActivityCenterGro

method enableInstallationAndSync*(self: Module, installationId: string) =
self.controller.enableInstallationAndSync(installationId)

method tryFetchingAgain*(self: Module) =
self.controller.tryFetchingAgain()
3 changes: 3 additions & 0 deletions src/app/modules/main/activity_center/view.nim
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,6 @@ QtObject:

proc enableInstallationAndSync*(self: View, installationId: string) {.slot.} =
self.delegate.enableInstallationAndSync(installationId)

proc tryFetchingAgain*(self: View) {.slot.} =
self.delegate.tryFetchingAgain()
2 changes: 1 addition & 1 deletion src/app/modules/main/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ proc newModule*[T](
networkService, tokenService)
result.gifsModule = gifs_module.newModule(result, events, gifService)
result.activityCenterModule = activity_center_module.newModule(result, events, activityCenterService, contactsService,
messageService, chatService, communityService, devicesService)
messageService, chatService, communityService, devicesService, generalService)
result.communitiesModule = communities_module.newModule(result, events, communityService, contactsService, communityTokensService,
networkService, transactionService, tokenService, chatService, walletAccountService, keycardService)
result.appSearchModule = app_search_module.newModule(result, events, contactsService, chatService, communityService,
Expand Down
1 change: 1 addition & 0 deletions src/app/modules/onboarding/io_interface.nim
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,6 @@ type
DelegateInterface* = concept c
c.onboardingDidLoad()
c.appReady()
c.userLoggedIn()
c.finishAppLoading()
c.userLoggedIn()
14 changes: 9 additions & 5 deletions src/app/modules/onboarding/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ method finishOnboardingFlow*[T](self: Module[T], flowInt: int, dataJson: string)
seedPhrase,
recoverAccount = true,
keycardInstanceUID = "",
)
)
of SecondaryFlow.LoginWithSyncing:
# The pairing was already done directly through inputConnectionStringForBootstrapping, we can login
self.controller.loginLocalPairingAccount(
Expand Down Expand Up @@ -169,14 +169,18 @@ proc finishAppLoading2[T](self: Module[T]) =

self.delegate.finishAppLoading()

method onNodeLogin*[T](self: Module[T], error: string, account: AccountDto, settings: SettingsDto) =
if error.len != 0:
# TODO: Handle error
echo "ERROR from onNodeLogin: ", error
method onNodeLogin*[T](self: Module[T], err: string, account: AccountDto, settings: SettingsDto) =
if err.len != 0:
error "error from onNodeLogin", err
return

self.controller.setLoggedInAccount(account)

let err2 = self.delegate.userLoggedIn()
if err2.len != 0:
error "error from userLoggedIn", err2
return

if self.localPairingStatus != nil and self.localPairingStatus.installation != nil and self.localPairingStatus.installation.id != "":
# We tried to login by pairing, so finilize the process
self.controller.finishPairingThroughSeedPhraseProcess(self.localPairingStatus.installation.id)
Expand Down
4 changes: 2 additions & 2 deletions src/app/modules/startup/controller.nim
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ proc generateImage*(self: Controller, imageUrl: string, aX: int, aY: int, bX: in
)
return img.uri

proc fetchWakuMessages*(self: Controller) =
self.generalService.fetchWakuMessages()
proc asyncFetchWakuBackupMessages*(self: Controller) =
self.generalService.asyncFetchWakuBackupMessages()

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,7 @@ proc delete*(self: ProfileFetchingAnnouncementState) =
method executePrimaryCommand*(self: ProfileFetchingAnnouncementState, controller: Controller) =
if self.flowType == FlowType.FirstRunOldUserImportSeedPhrase or
self.flowType == FlowType.FirstRunOldUserKeycardImport:
controller.fetchWakuMessages()
controller.asyncFetchWakuBackupMessages()

method getNextPrimaryState*(self: ProfileFetchingAnnouncementState, controller: Controller): State =
if self.flowType == FlowType.FirstRunOldUserImportSeedPhrase or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ type ActivityCenterNotificationType* {.pure.}= enum
CommunityUnbanned = 22
NewInstallationReceived = 23
NewInstallationCreated = 24
BackupSyncingFetching = 25
BackupSyncingSuccess = 26
BackupSyncingPartialFailure = 27
BackupSyncingFailure = 28

type ActivityCenterGroup* {.pure.}= enum
All = 0,
Expand Down Expand Up @@ -178,6 +182,10 @@ proc activityCenterNotificationTypesByGroup*(group: ActivityCenterGroup) : seq[i
ActivityCenterNotificationType.CommunityUnbanned.int,
ActivityCenterNotificationType.NewInstallationReceived.int,
ActivityCenterNotificationType.NewInstallationCreated.int,
ActivityCenterNotificationType.BackupSyncingFetching.int,
ActivityCenterNotificationType.BackupSyncingSuccess.int,
ActivityCenterNotificationType.BackupSyncingPartialFailure.int,
ActivityCenterNotificationType.BackupSyncingFailure.int,
]
of ActivityCenterGroup.Mentions:
return @[ActivityCenterNotificationType.Mention.int]
Expand Down
16 changes: 16 additions & 0 deletions src/app_service/service/general/async_tasks.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

type
AsyncFetchBackupWakuMessagesTaskArg = ref object of QObjectTaskArg

proc asyncFetchWakuBackupMessagesTask(argEncoded: string) {.gcsafe, nimcall.} =
let arg = decode[AsyncFetchBackupWakuMessagesTaskArg](argEncoded)
try:
let response = status_mailservers.requestAllHistoricMessagesWithRetries(forceFetchingBackup = true)
arg.finish(%* {
"response": response,
"error": "",
})
except Exception as e:
arg.finish(%* {
"error": e.msg,
})
37 changes: 31 additions & 6 deletions src/app_service/service/general/service.nim
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ import ../../../app/core/eventemitter
import ../../../app/core/tasks/[qt, threadpool]
import ../../../constants as app_constants

from app_service/service/activity_center/service import SIGNAL_ACTIVITY_CENTER_NOTIFICATIONS_LOADED, ActivityCenterNotificationsArgs
from app_service/service/activity_center/dto/notification import parseActivityCenterNotifications

import ../accounts/dto/accounts

include async_tasks

const TimerIntervalInMilliseconds = 1000 # 1 second

const SIGNAL_GENERAL_TIMEOUT* = "timeoutSignal"
Expand Down Expand Up @@ -37,7 +42,12 @@ QtObject:
createDir(app_constants.ROOTKEYSTOREDIR)

proc startMessenger*(self: Service) =
discard status_general.startMessenger()
let response = status_general.startMessenger()
if response.result.contains("activityCenterNotifications"):
let notifications = JsonNode(%{"notifications": response.result["activityCenterNotifications"]})
let activityCenterNotificationsTuple = parseActivityCenterNotifications(notifications)
self.events.emit(SIGNAL_ACTIVITY_CENTER_NOTIFICATIONS_LOADED,
ActivityCenterNotificationsArgs(activityCenterNotifications: activityCenterNotificationsTuple[1]))

proc logout*(self: Service) =
discard status_general.logout()
Expand Down Expand Up @@ -87,13 +97,28 @@ QtObject:
else:
self.runTimer()

proc fetchWakuMessages*(self: Service) =
proc asyncFetchWakuBackupMessages*(self: Service) =
let arg = AsyncFetchBackupWakuMessagesTaskArg(
tptr: asyncFetchWakuBackupMessagesTask,
vptr: cast[uint](self.vptr),
slot: "onFetchWakuBackupMessagesDone",
)
self.threadpool.start(arg)

proc onFetchWakuBackupMessagesDone(self: Service, response: string) {.slot.} =
try:
let response = status_mailservers.requestAllHistoricMessagesWithRetries(forceFetchingBackup = true)
if(not response.error.isNil):
error "could not set display name"
let rpcResponseObj = response.parseJson

if rpcResponseObj{"error"}.kind != JNull and rpcResponseObj{"error"}.getStr != "":
raise newException(CatchableError, rpcResponseObj{"error"}.getStr)

if rpcResponseObj["response"]["result"].contains("activityCenterNotifications"):
let notifications = JsonNode(%{"notifications": rpcResponseObj["response"]["result"]["activityCenterNotifications"]})
let activityCenterNotificationsTuple = parseActivityCenterNotifications(notifications)
self.events.emit(SIGNAL_ACTIVITY_CENTER_NOTIFICATIONS_LOADED,
ActivityCenterNotificationsArgs(activityCenterNotifications: activityCenterNotificationsTuple[1]))
except Exception as e:
error "error: ", procName="fetchWakuMessages", errName = e.name, errDesription = e.msg
error "error:", procName="asyncFetchWakuBackupMessages", errName = e.name, errDesription = e.msg

proc backupData*(self: Service): int64 =
try:
Expand Down
22 changes: 22 additions & 0 deletions ui/app/mainui/activitycenter/popups/ActivityCenterPopup.qml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ Popup {
case ActivityCenterStore.ActivityCenterNotificationType.NewInstallationReceived:
case ActivityCenterStore.ActivityCenterNotificationType.NewInstallationCreated:
return newDeviceDetectedComponent
case ActivityCenterStore.ActivityCenterNotificationType.BackupSyncingFetching:
case ActivityCenterStore.ActivityCenterNotificationType.BackupSyncingSuccess:
case ActivityCenterStore.ActivityCenterNotificationType.BackupSyncingPartialFailure:
case ActivityCenterStore.ActivityCenterNotificationType.BackupSyncingFailure:
return backupSyncingComponent
default:
return null
}
Expand Down Expand Up @@ -338,6 +343,23 @@ Popup {
}
}

Component {
id: backupSyncingComponent

ActivityNotificationProfileFetching {
id: activityNotificationProfileFetching
type: setType(notification)
filteredIndex: parent.filteredIndex
notification: parent.notification
onTryAgainClicked: {
// Force the type back to in progress since the fetching is async and the state will not update imediately
activityNotificationProfileFetching.type = ActivityNotificationProfileFetching.FetchingState.Fetching

root.activityCenterStore.tryFetchingAgain()
}
}
}

Component {
id: communityTokenReceivedComponent

Expand Down
10 changes: 9 additions & 1 deletion ui/app/mainui/activitycenter/stores/ActivityCenterStore.qml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ QtObject {
CommunityBanned = 21,
CommunityUnbanned = 22,
NewInstallationReceived = 23,
NewInstallationCreated = 24
NewInstallationCreated = 24,
BackupSyncingFetching = 25,
BackupSyncingSuccess = 26,
BackupSyncingPartialFailure = 27,
BackupSyncingFailure = 28
}

enum ActivityCenterReadType {
Expand Down Expand Up @@ -123,4 +127,8 @@ QtObject {
function enableInstallationAndSync(installationId) {
root.activityCenterModuleInst.enableInstallationAndSync(installationId)
}

function tryFetchingAgain() {
root.activityCenterModuleInst.tryFetchingAgain()
}
}
Loading