mirror of
https://github.com/bitwarden/browser
synced 2025-12-16 08:13:42 +00:00
only sync on edit if they already have the item/folder
This commit is contained in:
@@ -9,8 +9,8 @@ export abstract class SyncService {
|
|||||||
getLastSync: () => Promise<Date>;
|
getLastSync: () => Promise<Date>;
|
||||||
setLastSync: (date: Date) => Promise<any>;
|
setLastSync: (date: Date) => Promise<any>;
|
||||||
fullSync: (forceSync: boolean) => Promise<boolean>;
|
fullSync: (forceSync: boolean) => Promise<boolean>;
|
||||||
syncUpsertFolder: (notification: SyncFolderNotification) => Promise<boolean>;
|
syncUpsertFolder: (notification: SyncFolderNotification, isEdit: boolean) => Promise<boolean>;
|
||||||
syncDeleteFolder: (notification: SyncFolderNotification) => Promise<boolean>;
|
syncDeleteFolder: (notification: SyncFolderNotification) => Promise<boolean>;
|
||||||
syncUpsertCipher: (notification: SyncCipherNotification) => Promise<boolean>;
|
syncUpsertCipher: (notification: SyncCipherNotification, isEdit: boolean) => Promise<boolean>;
|
||||||
syncDeleteCipher: (notification: SyncFolderNotification) => Promise<boolean>;
|
syncDeleteCipher: (notification: SyncFolderNotification) => Promise<boolean>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,7 +56,8 @@ export class NotificationsService implements NotificationsServiceAbstraction {
|
|||||||
switch (notification.type) {
|
switch (notification.type) {
|
||||||
case NotificationType.SyncCipherCreate:
|
case NotificationType.SyncCipherCreate:
|
||||||
case NotificationType.SyncCipherUpdate:
|
case NotificationType.SyncCipherUpdate:
|
||||||
await this.syncService.syncUpsertCipher(notification.payload as SyncCipherNotification);
|
await this.syncService.syncUpsertCipher(notification.payload as SyncCipherNotification,
|
||||||
|
notification.type === NotificationType.SyncCipherUpdate);
|
||||||
break;
|
break;
|
||||||
case NotificationType.SyncCipherDelete:
|
case NotificationType.SyncCipherDelete:
|
||||||
case NotificationType.SyncLoginDelete:
|
case NotificationType.SyncLoginDelete:
|
||||||
@@ -64,7 +65,8 @@ export class NotificationsService implements NotificationsServiceAbstraction {
|
|||||||
break;
|
break;
|
||||||
case NotificationType.SyncFolderCreate:
|
case NotificationType.SyncFolderCreate:
|
||||||
case NotificationType.SyncFolderUpdate:
|
case NotificationType.SyncFolderUpdate:
|
||||||
await this.syncService.syncUpsertFolder(notification.payload as SyncFolderNotification);
|
await this.syncService.syncUpsertFolder(notification.payload as SyncFolderNotification,
|
||||||
|
notification.type === NotificationType.SyncFolderUpdate);
|
||||||
break;
|
break;
|
||||||
case NotificationType.SyncFolderDelete:
|
case NotificationType.SyncFolderDelete:
|
||||||
await this.syncService.syncDeleteFolder(notification.payload as SyncFolderNotification);
|
await this.syncService.syncDeleteFolder(notification.payload as SyncFolderNotification);
|
||||||
|
|||||||
@@ -99,18 +99,20 @@ export class SyncService implements SyncServiceAbstraction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async syncUpsertFolder(notification: SyncFolderNotification): Promise<boolean> {
|
async syncUpsertFolder(notification: SyncFolderNotification, isEdit: boolean): Promise<boolean> {
|
||||||
this.syncStarted();
|
this.syncStarted();
|
||||||
if (await this.userService.isAuthenticated()) {
|
if (await this.userService.isAuthenticated()) {
|
||||||
try {
|
try {
|
||||||
const remoteFolder = await this.apiService.getFolder(notification.id);
|
|
||||||
const localFolder = await this.folderService.get(notification.id);
|
const localFolder = await this.folderService.get(notification.id);
|
||||||
if (remoteFolder != null &&
|
if ((!isEdit && localFolder == null) ||
|
||||||
(localFolder == null || localFolder.revisionDate < notification.revisionDate)) {
|
(isEdit && localFolder != null && localFolder.revisionDate < notification.revisionDate)) {
|
||||||
const userId = await this.userService.getUserId();
|
const remoteFolder = await this.apiService.getFolder(notification.id);
|
||||||
await this.folderService.upsert(new FolderData(remoteFolder, userId));
|
if (remoteFolder != null) {
|
||||||
this.messagingService.send('syncedUpsertedFolder', { folderId: notification.id });
|
const userId = await this.userService.getUserId();
|
||||||
return this.syncCompleted(true);
|
await this.folderService.upsert(new FolderData(remoteFolder, userId));
|
||||||
|
this.messagingService.send('syncedUpsertedFolder', { folderId: notification.id });
|
||||||
|
return this.syncCompleted(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch { }
|
} catch { }
|
||||||
}
|
}
|
||||||
@@ -128,18 +130,20 @@ export class SyncService implements SyncServiceAbstraction {
|
|||||||
return this.syncCompleted(false);
|
return this.syncCompleted(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
async syncUpsertCipher(notification: SyncCipherNotification): Promise<boolean> {
|
async syncUpsertCipher(notification: SyncCipherNotification, isEdit: boolean): Promise<boolean> {
|
||||||
this.syncStarted();
|
this.syncStarted();
|
||||||
if (await this.userService.isAuthenticated()) {
|
if (await this.userService.isAuthenticated()) {
|
||||||
try {
|
try {
|
||||||
const remoteCipher = await this.apiService.getCipher(notification.id);
|
|
||||||
const localCipher = await this.cipherService.get(notification.id);
|
const localCipher = await this.cipherService.get(notification.id);
|
||||||
if (remoteCipher != null &&
|
if ((!isEdit && localCipher == null) ||
|
||||||
(localCipher == null || localCipher.revisionDate < notification.revisionDate)) {
|
(isEdit && localCipher != null && localCipher.revisionDate < notification.revisionDate)) {
|
||||||
const userId = await this.userService.getUserId();
|
const remoteCipher = await this.apiService.getCipher(notification.id);
|
||||||
await this.cipherService.upsert(new CipherData(remoteCipher, userId));
|
if (remoteCipher != null) {
|
||||||
this.messagingService.send('syncedUpsertedCipher', { cipherId: notification.id });
|
const userId = await this.userService.getUserId();
|
||||||
return this.syncCompleted(true);
|
await this.cipherService.upsert(new CipherData(remoteCipher, userId));
|
||||||
|
this.messagingService.send('syncedUpsertedCipher', { cipherId: notification.id });
|
||||||
|
return this.syncCompleted(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch { }
|
} catch { }
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user