delete annotations object when no more annotations left

This commit is contained in:
Bruno Windels 2021-06-03 19:10:29 +02:00
parent b05345ee27
commit b94ab42c90

View file

@ -171,6 +171,9 @@ export class RelationWriter {
const relations = await txn.timelineRelations.getForTargetAndType(this._roomId, targetId, ANNOTATION_RELATION_TYPE); const relations = await txn.timelineRelations.getForTargetAndType(this._roomId, targetId, ANNOTATION_RELATION_TYPE);
log.set("relations", relations.length); log.set("relations", relations.length);
delete target.annotations[key]; delete target.annotations[key];
if (isObjectEmpty(target.annotations)) {
delete target.annotations;
}
await Promise.all(relations.map(async relation => { await Promise.all(relations.map(async relation => {
const annotation = await txn.timelineEvents.getByEventId(this._roomId, relation.sourceEventId); const annotation = await txn.timelineEvents.getByEventId(this._roomId, relation.sourceEventId);
if (!annotation) { 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 // copied over from matrix-js-sdk, copyright 2016 OpenMarket Ltd
/* _REDACT_KEEP_KEY_MAP gives the keys we keep when an event is redacted /* _REDACT_KEEP_KEY_MAP gives the keys we keep when an event is redacted
* *