1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-07-31 15:24:23 +03:00

Support for cancelling pending events

Implement client.cancelPendingEvent which will cancel queued or not_sent events
This commit is contained in:
Richard van der Hoff
2016-03-17 20:34:58 +00:00
parent fdbc7a3112
commit 02be0f659a
5 changed files with 168 additions and 5 deletions

View File

@ -1225,4 +1225,76 @@ describe("Room", function() {
);
});
});
describe("updatePendingEvent", function() {
it("should remove cancelled events from the pending list", function() {
var room = new Room(roomId, {
pendingEventOrdering: "detached"
});
var eventA = utils.mkMessage({
room: roomId, user: userA, event: true
});
eventA.status = EventStatus.SENDING;
var eventId = eventA.getId();
room.addPendingEvent(eventA, "TXN1");
expect(room.getPendingEvents()).toEqual(
[eventA]
);
// the event has to have been failed or queued before it can be
// cancelled
room.updatePendingEvent(eventA, EventStatus.NOT_SENT);
var callCount = 0;
room.on("Room.localEchoUpdated",
function(event, emitRoom, oldEventId, oldStatus) {
expect(event).toEqual(eventA);
expect(event.status).toEqual(EventStatus.CANCELLED);
expect(emitRoom).toEqual(room);
expect(oldEventId).toEqual(eventId);
expect(oldStatus).toEqual(EventStatus.NOT_SENT);
callCount++;
});
room.updatePendingEvent(eventA, EventStatus.CANCELLED);
expect(room.getPendingEvents()).toEqual([]);
expect(callCount).toEqual(1);
});
it("should remove cancelled events from the timeline", function() {
var room = new Room(roomId);
var eventA = utils.mkMessage({
room: roomId, user: userA, event: true
});
eventA.status = EventStatus.SENDING;
var eventId = eventA.getId();
room.addPendingEvent(eventA, "TXN1");
expect(room.getLiveTimeline().getEvents()).toEqual(
[eventA]
);
// the event has to have been failed or queued before it can be
// cancelled
room.updatePendingEvent(eventA, EventStatus.NOT_SENT);
var callCount = 0;
room.on("Room.localEchoUpdated",
function(event, emitRoom, oldEventId, oldStatus) {
expect(event).toEqual(eventA);
expect(event.status).toEqual(EventStatus.CANCELLED);
expect(emitRoom).toEqual(room);
expect(oldEventId).toEqual(eventId);
expect(oldStatus).toEqual(EventStatus.NOT_SENT);
callCount++;
});
room.updatePendingEvent(eventA, EventStatus.CANCELLED);
expect(room.getLiveTimeline().getEvents()).toEqual([]);
expect(callCount).toEqual(1);
});
});
});