You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-26 17:03:12 +03:00
Emit an event when a local-echo is turned into a proper event
We need to trigger an update of the timeline when this happens, so raise an event for it.
This commit is contained in:
@@ -595,18 +595,22 @@ Room.prototype._addLiveEvents = function(events) {
|
||||
// remote echo of an event we sent earlier
|
||||
var existingEvent = this._txnToEvent[events[i].getUnsigned().transaction_id];
|
||||
if (existingEvent) {
|
||||
var oldEventId = existingEvent.getId();
|
||||
|
||||
// no longer pending
|
||||
delete this._txnToEvent[events[i].getUnsigned().transaction_id];
|
||||
|
||||
// update the timeline map, because the event id has changed
|
||||
var existingTimeline = this._eventIdToTimeline[existingEvent.getId()];
|
||||
var existingTimeline = this._eventIdToTimeline[oldEventId];
|
||||
if (existingTimeline) {
|
||||
delete this._eventIdToTimeline[existingEvent.getId()];
|
||||
delete this._eventIdToTimeline[oldEventId];
|
||||
this._eventIdToTimeline[events[i].getId()] = existingTimeline;
|
||||
}
|
||||
|
||||
// replace the event source
|
||||
existingEvent.event = events[i].event;
|
||||
|
||||
this.emit("Room.localEchoUpdated", existingEvent, this, oldEventId);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -1315,3 +1319,21 @@ module.exports = Room;
|
||||
* }
|
||||
* });
|
||||
*/
|
||||
|
||||
/**
|
||||
* Fires when a local-echo of a transmitted event is replaced by its remote-echo.
|
||||
*
|
||||
* <p>When an event is first transmitted, then (assuming the /send completes
|
||||
* before the event comes back from /sync), a temporary copy of the event is
|
||||
* inserted into the timeline, with a temporary event id. Once the echo comes
|
||||
* back from the server, the event is replaced by the complete event from the
|
||||
* homeserver, thus updating its event id.
|
||||
*
|
||||
* <p>If the event comes back from /sync before the /send completes, the
|
||||
* temporary event id is never stored, and this event is not raised.
|
||||
*
|
||||
* @event module:client~MatrixClient#"Room.localEchoUpdated"
|
||||
* @param {MatrixEvent} event The matrix event which has been updated
|
||||
* @param {Room} room The room containing the redacted event
|
||||
* @param {string} oldEventId The temporary event id which has been replaced
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user