mirror of
https://github.com/bitwarden/browser.git
synced 2024-09-27 04:03:00 +02:00
only sync on edit if they already have the item/folder
This commit is contained in:
parent
50666a761d
commit
9cfd693576
@ -9,8 +9,8 @@ export abstract class SyncService {
|
||||
getLastSync: () => Promise<Date>;
|
||||
setLastSync: (date: Date) => Promise<any>;
|
||||
fullSync: (forceSync: boolean) => Promise<boolean>;
|
||||
syncUpsertFolder: (notification: SyncFolderNotification) => Promise<boolean>;
|
||||
syncUpsertFolder: (notification: SyncFolderNotification, isEdit: boolean) => Promise<boolean>;
|
||||
syncDeleteFolder: (notification: SyncFolderNotification) => Promise<boolean>;
|
||||
syncUpsertCipher: (notification: SyncCipherNotification) => Promise<boolean>;
|
||||
syncUpsertCipher: (notification: SyncCipherNotification, isEdit: boolean) => Promise<boolean>;
|
||||
syncDeleteCipher: (notification: SyncFolderNotification) => Promise<boolean>;
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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();
|
||||
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<boolean> {
|
||||
async syncUpsertCipher(notification: SyncCipherNotification, isEdit: boolean): Promise<boolean> {
|
||||
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 { }
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user