From 6b7eaae49271acbb41d7fa814c74085ef12c4a58 Mon Sep 17 00:00:00 2001 From: gbubemismith Date: Tue, 26 Nov 2024 14:55:10 -0500 Subject: [PATCH] Required userid to be passed from notification service --- .../src/platform/sync/core-sync.service.ts | 22 +++++++++---------- libs/common/src/platform/sync/sync.service.ts | 3 ++- .../src/services/notifications.service.ts | 6 ++++- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/libs/common/src/platform/sync/core-sync.service.ts b/libs/common/src/platform/sync/core-sync.service.ts index 92d5da65223..031262c5596 100644 --- a/libs/common/src/platform/sync/core-sync.service.ts +++ b/libs/common/src/platform/sync/core-sync.service.ts @@ -37,8 +37,6 @@ const LAST_SYNC_DATE = new UserKeyDefinition(SYNC_DISK, "lastSync", { export abstract class CoreSyncService implements SyncService { syncInProgress = false; - private activeUserId$ = this.accountService.activeAccount$.pipe(map((a) => a?.id)); - constructor( protected readonly stateService: StateService, protected readonly folderService: InternalFolderService, @@ -85,22 +83,25 @@ export abstract class CoreSyncService implements SyncService { await this.stateProvider.getUser(userId, LAST_SYNC_DATE).update(() => date); } - async syncUpsertFolder(notification: SyncFolderNotification, isEdit: boolean): Promise { + async syncUpsertFolder( + notification: SyncFolderNotification, + isEdit: boolean, + userId: UserId, + ): Promise { this.syncStarted(); - const activeUserId = await firstValueFrom(this.activeUserId$); - const authStatus = await firstValueFrom(this.authService.authStatusFor$(activeUserId)); + const authStatus = await firstValueFrom(this.authService.authStatusFor$(userId)); if (authStatus >= AuthenticationStatus.Locked) { try { - const localFolder = await this.folderService.get(notification.id, activeUserId); + const localFolder = await this.folderService.get(notification.id, userId); if ( (!isEdit && localFolder == null) || (isEdit && localFolder != null && localFolder.revisionDate < notification.revisionDate) ) { const remoteFolder = await this.folderApiService.get(notification.id); if (remoteFolder != null) { - await this.folderService.upsert(new FolderData(remoteFolder), activeUserId); + await this.folderService.upsert(new FolderData(remoteFolder), userId); this.messageSender.send("syncedUpsertedFolder", { folderId: notification.id }); return this.syncCompleted(true); } @@ -112,14 +113,13 @@ export abstract class CoreSyncService implements SyncService { return this.syncCompleted(false); } - async syncDeleteFolder(notification: SyncFolderNotification): Promise { + async syncDeleteFolder(notification: SyncFolderNotification, userId: UserId): Promise { this.syncStarted(); - const activeUserId = await firstValueFrom(this.activeUserId$); - const authStatus = await firstValueFrom(this.authService.authStatusFor$(activeUserId)); + const authStatus = await firstValueFrom(this.authService.authStatusFor$(userId)); if (authStatus >= AuthenticationStatus.Locked) { - await this.folderService.delete(notification.id, activeUserId); + await this.folderService.delete(notification.id, userId); this.messageSender.send("syncedDeletedFolder", { folderId: notification.id }); this.syncCompleted(true); return true; diff --git a/libs/common/src/platform/sync/sync.service.ts b/libs/common/src/platform/sync/sync.service.ts index 733b7beaff5..6763e01cab7 100644 --- a/libs/common/src/platform/sync/sync.service.ts +++ b/libs/common/src/platform/sync/sync.service.ts @@ -56,8 +56,9 @@ export abstract class SyncService { abstract syncUpsertFolder( notification: SyncFolderNotification, isEdit: boolean, + userId: UserId, ): Promise; - abstract syncDeleteFolder(notification: SyncFolderNotification): Promise; + abstract syncDeleteFolder(notification: SyncFolderNotification, userId: UserId): Promise; abstract syncUpsertCipher( notification: SyncCipherNotification, isEdit: boolean, diff --git a/libs/common/src/services/notifications.service.ts b/libs/common/src/services/notifications.service.ts index d443193c9b7..0cab71b47cb 100644 --- a/libs/common/src/services/notifications.service.ts +++ b/libs/common/src/services/notifications.service.ts @@ -166,10 +166,14 @@ export class NotificationsService implements NotificationsServiceAbstraction { await this.syncService.syncUpsertFolder( notification.payload as SyncFolderNotification, notification.type === NotificationType.SyncFolderUpdate, + payloadUserId, ); break; case NotificationType.SyncFolderDelete: - await this.syncService.syncDeleteFolder(notification.payload as SyncFolderNotification); + await this.syncService.syncDeleteFolder( + notification.payload as SyncFolderNotification, + payloadUserId, + ); break; case NotificationType.SyncVault: case NotificationType.SyncCiphers: