mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 19:45:05 +01:00
delete annotations object when no more annotations left
This commit is contained in:
parent
b05345ee27
commit
b94ab42c90
@ -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
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user