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
Support for cancelling pending events
Implement client.cancelPendingEvent which will cancel queued or not_sent events
This commit is contained in:
@@ -729,13 +729,16 @@ ALLOWED_TRANSITIONS[EventStatus.SENDING] =
|
||||
[EventStatus.QUEUED, EventStatus.NOT_SENT, EventStatus.SENT];
|
||||
|
||||
ALLOWED_TRANSITIONS[EventStatus.QUEUED] =
|
||||
[EventStatus.SENDING];
|
||||
[EventStatus.SENDING, EventStatus.CANCELLED];
|
||||
|
||||
ALLOWED_TRANSITIONS[EventStatus.SENT] =
|
||||
[];
|
||||
|
||||
ALLOWED_TRANSITIONS[EventStatus.NOT_SENT] =
|
||||
[EventStatus.SENDING, EventStatus.QUEUED];
|
||||
[EventStatus.SENDING, EventStatus.QUEUED, EventStatus.CANCELLED];
|
||||
|
||||
ALLOWED_TRANSITIONS[EventStatus.CANCELLED] =
|
||||
[];
|
||||
|
||||
/**
|
||||
* Update the status / event id on a pending event, to reflect its transmission
|
||||
@@ -797,6 +800,17 @@ Room.prototype.updatePendingEvent = function(event, newStatus, newEventId) {
|
||||
this._eventIdToTimeline[newEventId] = existingTimeline;
|
||||
}
|
||||
}
|
||||
else if (newStatus == EventStatus.CANCELLED) {
|
||||
// remove it from the pending event list, or the timeline.
|
||||
if (this._pendingEventList) {
|
||||
utils.removeElement(
|
||||
this._pendingEventList,
|
||||
function(ev) { return ev.getId() == oldEventId; },
|
||||
false
|
||||
);
|
||||
}
|
||||
this.removeEvent(oldEventId);
|
||||
}
|
||||
|
||||
this.emit("Room.localEchoUpdated", event, this, event.getId(), oldStatus);
|
||||
};
|
||||
@@ -1479,9 +1493,10 @@ module.exports = Room;
|
||||
* arrived, the event is updated with a new event id and the status is set to
|
||||
* 'SENT'. The server-generated fields are of course not updated yet.
|
||||
*
|
||||
* <p>Finally, the /send might fail. In this case, the event's status is set to
|
||||
* <p>If the /send fails, In this case, the event's status is set to
|
||||
* 'NOT_SENT'. If it is later resent, the process starts again, setting the
|
||||
* status to 'SENDING'.
|
||||
* status to 'SENDING'. Alternatively, the message may be cancelled, which
|
||||
* removes the event from the room, and sets the status to 'CANCELLED'.
|
||||
*
|
||||
* <p>This event is raised to reflect each of the transitions above.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user