chore: fix conflict map addition/removal
This commit is contained in:
@@ -187,7 +187,16 @@ export abstract class Collection<
|
|||||||
const conflictOf = element.content.conflict_of
|
const conflictOf = element.content.conflict_of
|
||||||
if (conflictOf) {
|
if (conflictOf) {
|
||||||
this.conflictMap.establishRelationship(conflictOf, element.uuid)
|
this.conflictMap.establishRelationship(conflictOf, element.uuid)
|
||||||
} else if (this.conflictMap.getInverseRelationships(element.uuid).length > 0) {
|
}
|
||||||
|
|
||||||
|
const isInConflictMapButIsNotConflictOf =
|
||||||
|
!conflictOf && this.conflictMap.getInverseRelationships(element.uuid).length > 0
|
||||||
|
|
||||||
|
const isInConflictMapButDoesNotHaveConflicts =
|
||||||
|
this.conflictMap.existsInDirectMap(element.uuid) &&
|
||||||
|
this.conflictMap.getDirectRelationships(element.uuid).length === 0
|
||||||
|
|
||||||
|
if (isInConflictMapButIsNotConflictOf || isInConflictMapButDoesNotHaveConflicts) {
|
||||||
this.conflictMap.removeFromMap(element.uuid)
|
this.conflictMap.removeFromMap(element.uuid)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -205,7 +214,7 @@ export abstract class Collection<
|
|||||||
|
|
||||||
if (element.deleted) {
|
if (element.deleted) {
|
||||||
this.nondeletedIndex.delete(element.uuid)
|
this.nondeletedIndex.delete(element.uuid)
|
||||||
if (this.conflictMap.getInverseRelationships(element.uuid).length > 0) {
|
if (this.conflictMap.existsInDirectMap(element.uuid) || this.conflictMap.existsInInverseMap(element.uuid)) {
|
||||||
this.conflictMap.removeFromMap(element.uuid)
|
this.conflictMap.removeFromMap(element.uuid)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -25,6 +25,14 @@ export class UuidMap {
|
|||||||
return copy
|
return copy
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public existsInDirectMap(uuid: string): boolean {
|
||||||
|
return uuid in this.directMap
|
||||||
|
}
|
||||||
|
|
||||||
|
public existsInInverseMap(uuid: string): boolean {
|
||||||
|
return uuid in this.inverseMap
|
||||||
|
}
|
||||||
|
|
||||||
public getDirectRelationships(uuid: string): string[] {
|
public getDirectRelationships(uuid: string): string[] {
|
||||||
return this.directMap[uuid] || []
|
return this.directMap[uuid] || []
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user