diff --git a/packages/models/src/Domain/Runtime/Collection/Collection.ts b/packages/models/src/Domain/Runtime/Collection/Collection.ts index 14827d6aa..9f3664af5 100644 --- a/packages/models/src/Domain/Runtime/Collection/Collection.ts +++ b/packages/models/src/Domain/Runtime/Collection/Collection.ts @@ -187,7 +187,16 @@ export abstract class Collection< const conflictOf = element.content.conflict_of if (conflictOf) { 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) } @@ -205,7 +214,7 @@ export abstract class Collection< if (element.deleted) { 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) } } else { diff --git a/packages/utils/src/Domain/Uuid/UuidMap.ts b/packages/utils/src/Domain/Uuid/UuidMap.ts index cd9d1cf23..2c2c93a61 100644 --- a/packages/utils/src/Domain/Uuid/UuidMap.ts +++ b/packages/utils/src/Domain/Uuid/UuidMap.ts @@ -25,6 +25,14 @@ export class UuidMap { 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[] { return this.directMap[uuid] || [] }