diff --git a/src/matrix/room/sending/PendingEvent.js b/src/matrix/room/sending/PendingEvent.js index ef5d086e..a0e5f4f2 100644 --- a/src/matrix/room/sending/PendingEvent.js +++ b/src/matrix/room/sending/PendingEvent.js @@ -16,6 +16,7 @@ limitations under the License. import {createEnum} from "../../../utils/enum.js"; import {AbortError} from "../../../utils/error.js"; import {REDACTION_TYPE} from "../common.js"; +import {getRelationFromContent} from "../timeline/relations.js"; export const SendStatus = createEnum( "Waiting", @@ -49,10 +50,23 @@ export class PendingEvent { get remoteId() { return this._data.remoteId; } get content() { return this._data.content; } get relatedTxnId() { return this._data.relatedTxnId; } - get relatedEventId() { return this._data.relatedEventId; } + get relatedEventId() { + const relation = getRelationFromContent(this.content); + if (relation) { + // may be null when target is not sent yet, is indented + return relation.event_id; + } else { + return this._data.relatedEventId; + } + } setRelatedEventId(eventId) { - this._data.relatedEventId = eventId; + const relation = getRelationFromContent(this.content); + if (relation) { + relation.event_id = eventId; + } else { + this._data.relatedEventId = eventId; + } } get data() { return this._data; } diff --git a/src/matrix/room/sending/SendQueue.js b/src/matrix/room/sending/SendQueue.js index 0e1b116d..914ee1fd 100644 --- a/src/matrix/room/sending/SendQueue.js +++ b/src/matrix/room/sending/SendQueue.js @@ -19,6 +19,7 @@ import {ConnectionError} from "../../error.js"; import {PendingEvent, SendStatus} from "./PendingEvent.js"; import {makeTxnId, isTxnId} from "../../common.js"; import {REDACTION_TYPE} from "../common.js"; +import {getRelationFromContent} from "../timeline/relations.js"; export class SendQueue { constructor({roomId, storage, hsApi, pendingEvents}) { @@ -197,7 +198,13 @@ export class SendQueue { } async enqueueEvent(eventType, content, attachments, log) { - await this._enqueueEvent(eventType, content, attachments, null, null, log); + const relation = getRelationFromContent(content); + let relatedTxnId = null; + if (relation && isTxnId(relation.event_id)) { + relatedTxnId = relation.event_id; + relation.event_id = null; + } + await this._enqueueEvent(eventType, content, attachments, relatedTxnId, null, log); } async _enqueueEvent(eventType, content, attachments, relatedTxnId, relatedEventId, log) { diff --git a/src/matrix/room/timeline/relations.js b/src/matrix/room/timeline/relations.js index ed9da586..5bf0f490 100644 --- a/src/matrix/room/timeline/relations.js +++ b/src/matrix/room/timeline/relations.js @@ -41,7 +41,11 @@ export function getRelatedEventId(event) { return null; } -export function getRelation(event) { - return event.content?.["m.relates_to"]; +export function getRelationFromContent(content) { + return content?.["m.relates_to"]; +} + +export function getRelation(event) { + return getRelationFromContent(event.content); }