update notification sync logic for collectionids
This commit is contained in:
parent
75d4db81f7
commit
953970498e
|
@ -38,12 +38,14 @@ export class SyncCipherNotification {
|
||||||
id: string;
|
id: string;
|
||||||
userId: string;
|
userId: string;
|
||||||
organizationId: string;
|
organizationId: string;
|
||||||
|
collectionIds: string[];
|
||||||
revisionDate: Date;
|
revisionDate: Date;
|
||||||
|
|
||||||
constructor(response: any) {
|
constructor(response: any) {
|
||||||
this.id = response.Id;
|
this.id = response.Id;
|
||||||
this.userId = response.UserId;
|
this.userId = response.UserId;
|
||||||
this.organizationId = response.OrganizationId;
|
this.organizationId = response.OrganizationId;
|
||||||
|
this.collectionIds = response.CollectionIds;
|
||||||
this.revisionDate = new Date(response.RevisionDate);
|
this.revisionDate = new Date(response.RevisionDate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -134,9 +134,41 @@ export class SyncService implements SyncServiceAbstraction {
|
||||||
this.syncStarted();
|
this.syncStarted();
|
||||||
if (await this.userService.isAuthenticated()) {
|
if (await this.userService.isAuthenticated()) {
|
||||||
try {
|
try {
|
||||||
|
let shouldUpdate = true;
|
||||||
const localCipher = await this.cipherService.get(notification.id);
|
const localCipher = await this.cipherService.get(notification.id);
|
||||||
if ((!isEdit && localCipher == null) ||
|
if (localCipher != null && localCipher.revisionDate >= notification.revisionDate) {
|
||||||
(isEdit && localCipher != null && localCipher.revisionDate < notification.revisionDate)) {
|
shouldUpdate = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
let checkCollections = false;
|
||||||
|
if (shouldUpdate) {
|
||||||
|
if (isEdit) {
|
||||||
|
shouldUpdate = localCipher != null;
|
||||||
|
checkCollections = true;
|
||||||
|
} else {
|
||||||
|
if (notification.collectionIds == null || notification.organizationId == null) {
|
||||||
|
shouldUpdate = localCipher == null;
|
||||||
|
} else {
|
||||||
|
shouldUpdate = false;
|
||||||
|
checkCollections = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!shouldUpdate && checkCollections && notification.organizationId != null &&
|
||||||
|
notification.collectionIds != null && notification.collectionIds.length > 0) {
|
||||||
|
const collections = await this.collectionService.getAll();
|
||||||
|
if (collections != null) {
|
||||||
|
for (let i = 0; i < collections.length; i++) {
|
||||||
|
if (notification.collectionIds.indexOf(collections[i].id)) {
|
||||||
|
shouldUpdate = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (shouldUpdate) {
|
||||||
const remoteCipher = await this.apiService.getCipher(notification.id);
|
const remoteCipher = await this.apiService.getCipher(notification.id);
|
||||||
if (remoteCipher != null) {
|
if (remoteCipher != null) {
|
||||||
const userId = await this.userService.getUserId();
|
const userId = await this.userService.getUserId();
|
||||||
|
|
Loading…
Reference in New Issue