diff --git a/src/abstractions/sync.service.ts b/src/abstractions/sync.service.ts index 694c0517ea3..264e6ecbf95 100644 --- a/src/abstractions/sync.service.ts +++ b/src/abstractions/sync.service.ts @@ -9,8 +9,8 @@ export abstract class SyncService { getLastSync: () => Promise; setLastSync: (date: Date) => Promise; fullSync: (forceSync: boolean) => Promise; - syncUpsertFolder: (notification: SyncFolderNotification) => Promise; + syncUpsertFolder: (notification: SyncFolderNotification, isEdit: boolean) => Promise; syncDeleteFolder: (notification: SyncFolderNotification) => Promise; - syncUpsertCipher: (notification: SyncCipherNotification) => Promise; + syncUpsertCipher: (notification: SyncCipherNotification, isEdit: boolean) => Promise; syncDeleteCipher: (notification: SyncFolderNotification) => Promise; } diff --git a/src/services/notifications.service.ts b/src/services/notifications.service.ts index 65abd9dda5f..be33b067f71 100644 --- a/src/services/notifications.service.ts +++ b/src/services/notifications.service.ts @@ -56,7 +56,8 @@ export class NotificationsService implements NotificationsServiceAbstraction { switch (notification.type) { case NotificationType.SyncCipherCreate: case NotificationType.SyncCipherUpdate: - await this.syncService.syncUpsertCipher(notification.payload as SyncCipherNotification); + await this.syncService.syncUpsertCipher(notification.payload as SyncCipherNotification, + notification.type === NotificationType.SyncCipherUpdate); break; case NotificationType.SyncCipherDelete: case NotificationType.SyncLoginDelete: @@ -64,7 +65,8 @@ export class NotificationsService implements NotificationsServiceAbstraction { break; case NotificationType.SyncFolderCreate: case NotificationType.SyncFolderUpdate: - await this.syncService.syncUpsertFolder(notification.payload as SyncFolderNotification); + await this.syncService.syncUpsertFolder(notification.payload as SyncFolderNotification, + notification.type === NotificationType.SyncFolderUpdate); break; case NotificationType.SyncFolderDelete: await this.syncService.syncDeleteFolder(notification.payload as SyncFolderNotification); diff --git a/src/services/sync.service.ts b/src/services/sync.service.ts index ae1a8fa7ca4..a1b294a1a22 100644 --- a/src/services/sync.service.ts +++ b/src/services/sync.service.ts @@ -99,18 +99,20 @@ export class SyncService implements SyncServiceAbstraction { } } - async syncUpsertFolder(notification: SyncFolderNotification): Promise { + async syncUpsertFolder(notification: SyncFolderNotification, isEdit: boolean): Promise { this.syncStarted(); if (await this.userService.isAuthenticated()) { try { - const remoteFolder = await this.apiService.getFolder(notification.id); const localFolder = await this.folderService.get(notification.id); - if (remoteFolder != null && - (localFolder == null || localFolder.revisionDate < notification.revisionDate)) { - const userId = await this.userService.getUserId(); - await this.folderService.upsert(new FolderData(remoteFolder, userId)); - this.messagingService.send('syncedUpsertedFolder', { folderId: notification.id }); - return this.syncCompleted(true); + if ((!isEdit && localFolder == null) || + (isEdit && localFolder != null && localFolder.revisionDate < notification.revisionDate)) { + const remoteFolder = await this.apiService.getFolder(notification.id); + if (remoteFolder != null) { + const userId = await this.userService.getUserId(); + await this.folderService.upsert(new FolderData(remoteFolder, userId)); + this.messagingService.send('syncedUpsertedFolder', { folderId: notification.id }); + return this.syncCompleted(true); + } } } catch { } } @@ -128,18 +130,20 @@ export class SyncService implements SyncServiceAbstraction { return this.syncCompleted(false); } - async syncUpsertCipher(notification: SyncCipherNotification): Promise { + async syncUpsertCipher(notification: SyncCipherNotification, isEdit: boolean): Promise { this.syncStarted(); if (await this.userService.isAuthenticated()) { try { - const remoteCipher = await this.apiService.getCipher(notification.id); const localCipher = await this.cipherService.get(notification.id); - if (remoteCipher != null && - (localCipher == null || localCipher.revisionDate < notification.revisionDate)) { - const userId = await this.userService.getUserId(); - await this.cipherService.upsert(new CipherData(remoteCipher, userId)); - this.messagingService.send('syncedUpsertedCipher', { cipherId: notification.id }); - return this.syncCompleted(true); + if ((!isEdit && localCipher == null) || + (isEdit && localCipher != null && localCipher.revisionDate < notification.revisionDate)) { + const remoteCipher = await this.apiService.getCipher(notification.id); + if (remoteCipher != null) { + const userId = await this.userService.getUserId(); + await this.cipherService.upsert(new CipherData(remoteCipher, userId)); + this.messagingService.send('syncedUpsertedCipher', { cipherId: notification.id }); + return this.syncCompleted(true); + } } } catch { } }