From b94ab42c90eddd62ffb95a2fb4957cf5588a2ca7 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Thu, 3 Jun 2021 19:10:29 +0200 Subject: [PATCH] delete annotations object when no more annotations left --- .../room/timeline/persistence/RelationWriter.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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 *