diff --git a/src/matrix/room/timeline/Timeline.js b/src/matrix/room/timeline/Timeline.js index bb6554b8..56920c6f 100644 --- a/src/matrix/room/timeline/Timeline.js +++ b/src/matrix/room/timeline/Timeline.js @@ -101,6 +101,7 @@ export class Timeline { pe => this._mapPendingEventToEntry(pe), (pee, params) => { // is sending but redacted, who do we detect that here to remove the relation? + this._loadContextEntriesWhereNeeded([pee]); pee.notifyUpdate(params); }, pee => this._applyAndEmitLocalRelationChange(pee, target => target.removeLocalRelation(pee)) @@ -124,6 +125,7 @@ export class Timeline { pendingEvent: pe, member: this._ownMember, clock: this._clock, redactingEntry }); + this._loadContextEntriesWhereNeeded([pee]); this._applyAndEmitLocalRelationChange(pee, target => target.addRelation(pee)); return pee; } diff --git a/src/matrix/room/timeline/entries/BaseEventEntry.js b/src/matrix/room/timeline/entries/BaseEventEntry.js index 4ee23b50..eeda4464 100644 --- a/src/matrix/room/timeline/entries/BaseEventEntry.js +++ b/src/matrix/room/timeline/entries/BaseEventEntry.js @@ -27,6 +27,8 @@ export class BaseEventEntry extends BaseEntry { super(fragmentIdComparer); this._pendingRedactions = null; this._pendingAnnotations = null; + this._contextEntry = null; + this._contextForEntries = null; } get isReply() { @@ -52,6 +54,26 @@ export class BaseEventEntry extends BaseEntry { return null; } + setContextEntry(entry) { + this._contextEntry = entry; + entry._setAsContextOf(this); + } + + _setAsContextOf(entry) { + if (!this._contextForEntries) { + this._contextForEntries = []; + } + this._contextForEntries.push(entry); + } + + get contextForEntries() { + return this._contextForEntries; + } + + get contextEntry() { + return this._contextEntry; + } + /** Aggregates relation or redaction of remote relation. Used in two situations: diff --git a/src/matrix/room/timeline/entries/EventEntry.js b/src/matrix/room/timeline/entries/EventEntry.js index 032c26c4..0d493825 100644 --- a/src/matrix/room/timeline/entries/EventEntry.js +++ b/src/matrix/room/timeline/entries/EventEntry.js @@ -24,8 +24,6 @@ export class EventEntry extends BaseEventEntry { this._eventEntry = eventEntry; this._decryptionError = null; this._decryptionResult = null; - this._contextEntry = null; - this._contextForEntries = null; } clone() { @@ -45,20 +43,8 @@ export class EventEntry extends BaseEventEntry { this._contextEntry = other.contextEntry; } - setContextEntry(entry) { - this._contextEntry = entry; - entry._setAsContextOf(this); - } - - _setAsContextOf(entry) { - if (!this._contextForEntries) { - this._contextForEntries = []; - } - this._contextForEntries.push(entry); - } - - get contextForEntries() { - return this._contextForEntries; + setRelatedEntry(entry) { + this._relatedEntry = entry; } get event() { @@ -142,18 +128,13 @@ export class EventEntry extends BaseEventEntry { return getRelatedEventId(this.event); } - // similar to relatedEventID but only for replies - get contextEventId() { - if (this.isReply) { - return this.relatedEventId; + get threadEventId() { + if (this.isThread) { + return this.relation?.event_id; } return null; } - get contextEntry() { - return this._contextEntry; - } - get isRedacted() { return super.isRedacted || isRedacted(this._eventEntry.event); } @@ -176,6 +157,15 @@ export class EventEntry extends BaseEventEntry { const originalRelation = originalContent && getRelationFromContent(originalContent); return originalRelation || getRelationFromContent(this.content); } + + // similar to relatedEventID but only for replies + get contextEventId() { + if (this.isReply) { + return this.relatedEventId; + } + return null; + } + } import {withTextBody, withContent, createEvent} from "../../../../mocks/event.js"; diff --git a/src/matrix/room/timeline/entries/PendingEventEntry.js b/src/matrix/room/timeline/entries/PendingEventEntry.js index 4bc3c47e..bb4ed407 100644 --- a/src/matrix/room/timeline/entries/PendingEventEntry.js +++ b/src/matrix/room/timeline/entries/PendingEventEntry.js @@ -100,4 +100,11 @@ export class PendingEventEntry extends BaseEventEntry { get redactingEntry() { return this._redactingEntry; } + + get contextEventId() { + if (this.isReply) { + return this._pendingEvent.relatedEventId ?? this._pendingEvent.relatedTxnId; + } + return null; + } }