diff --git a/src/matrix/room/timeline/persistence/RelationWriter.js b/src/matrix/room/timeline/persistence/RelationWriter.js index b15f2800..3838c494 100644 --- a/src/matrix/room/timeline/persistence/RelationWriter.js +++ b/src/matrix/room/timeline/persistence/RelationWriter.js @@ -171,6 +171,9 @@ export class RelationWriter { const relations = await txn.timelineRelations.getForTargetAndType(this._roomId, targetId, ANNOTATION_RELATION_TYPE); log.set("relations", relations.length); delete target.annotations[key]; + if (isObjectEmpty(target.annotations)) { + delete target.annotations; + } await Promise.all(relations.map(async relation => { const annotation = await txn.timelineEvents.getByEventId(this._roomId, relation.sourceEventId); if (!annotation) { @@ -184,6 +187,15 @@ export class RelationWriter { } } +function isObjectEmpty(obj) { + for (const key in obj) { + if (obj.hasOwnProperty(key)) { + return false; + } + } + return true; +} + // copied over from matrix-js-sdk, copyright 2016 OpenMarket Ltd /* _REDACT_KEEP_KEY_MAP gives the keys we keep when an event is redacted *