From 061f44f475e07970255bd8c7296d90b44a3baea9 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Thu, 24 Jun 2021 12:56:23 +0200 Subject: [PATCH] extract methods here --- .../room/timeline/entries/BaseEventEntry.js | 54 ++++++++++++------- 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/src/matrix/room/timeline/entries/BaseEventEntry.js b/src/matrix/room/timeline/entries/BaseEventEntry.js index 9302e009..2e681104 100644 --- a/src/matrix/room/timeline/entries/BaseEventEntry.js +++ b/src/matrix/room/timeline/entries/BaseEventEntry.js @@ -64,17 +64,7 @@ export class BaseEventEntry extends BaseEntry { const relationEntry = entry.redactingEntry || entry; if (relationEntry.isRelatedToId(this.id)) { if (relationEntry.relation.rel_type === ANNOTATION_RELATION_TYPE) { - if (!this._pendingAnnotations) { - this._pendingAnnotations = new Map(); - } - const {key} = (entry.redactingEntry || entry).relation; - if (key) { - let annotation = this._pendingAnnotations.get(key); - if (!annotation) { - annotation = new PendingAnnotation(); - this._pendingAnnotations.set(key, annotation); - } - annotation.add(entry); + if (this._addPendingAnnotation(entry)) { return "pendingAnnotations"; } } @@ -100,15 +90,7 @@ export class BaseEventEntry extends BaseEntry { const relationEntry = entry.redactingEntry || entry; if (relationEntry.isRelatedToId(this.id)) { if (relationEntry.relation?.rel_type === ANNOTATION_RELATION_TYPE && this._pendingAnnotations) { - const {key} = (entry.redactingEntry || entry).relation; - if (key) { - let annotation = this._pendingAnnotations.get(key); - if (annotation.remove(entry) && annotation.isEmpty) { - this._pendingAnnotations.delete(key); - } - if (this._pendingAnnotations.size === 0) { - this._pendingAnnotations = null; - } + if (this._removePendingAnnotation(entry)) { return "pendingAnnotations"; } } @@ -116,6 +98,38 @@ export class BaseEventEntry extends BaseEntry { } } + _addPendingAnnotation(entry) { + if (!this._pendingAnnotations) { + this._pendingAnnotations = new Map(); + } + const {key} = (entry.redactingEntry || entry).relation; + if (key) { + let annotation = this._pendingAnnotations.get(key); + if (!annotation) { + annotation = new PendingAnnotation(); + this._pendingAnnotations.set(key, annotation); + } + annotation.add(entry); + return true; + } + return false; + } + + _removePendingAnnotation(entry) { + const {key} = (entry.redactingEntry || entry).relation; + if (key) { + let annotation = this._pendingAnnotations.get(key); + if (annotation.remove(entry) && annotation.isEmpty) { + this._pendingAnnotations.delete(key); + } + if (this._pendingAnnotations.size === 0) { + this._pendingAnnotations = null; + } + return true; + } + return false; + } + async abortPendingRedaction() { if (this._pendingRedactions) { for (const pee of this._pendingRedactions) {