Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit a7a7cb5

Browse files
authored
Cancel pending events in virtual room when call placed (#7583)
As the comment hopefully explains. Also add public qualifiers to the methods in Resend which lacked any visibility specifiers. Fixes element-hq/element-web#17594
1 parent 73a5870 commit a7a7cb5

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/CallHandler.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import { WidgetLayoutStore, Container } from './stores/widgets/WidgetLayoutStore
5454
import { getIncomingCallToastKey } from './toasts/IncomingCallToast';
5555
import ToastStore from './stores/ToastStore';
5656
import IncomingCallToast from "./toasts/IncomingCallToast";
57+
import Resend from './Resend';
5758

5859
export const PROTOCOL_PSTN = 'm.protocol.pstn';
5960
export const PROTOCOL_PSTN_PREFIXED = 'im.vector.protocol.pstn';
@@ -737,6 +738,18 @@ export default class CallHandler extends EventEmitter {
737738
const mappedRoomId = (await VoipUserMapper.sharedInstance().getOrCreateVirtualRoomForRoom(roomId)) || roomId;
738739
logger.debug("Mapped real room " + roomId + " to room ID " + mappedRoomId);
739740

741+
// If we're using a virtual room nd there are any events pending, try to resend them,
742+
// otherwise the call will fail and because its a virtual room, the user won't be able
743+
// to see it to either retry or clear the pending events. There will only be call events
744+
// in this queue, and since we're about to place a new call, they can only be events from
745+
// previous calls that are probably stale by now, so just cancel them.
746+
if (mappedRoomId !== roomId) {
747+
const mappedRoom = MatrixClientPeg.get().getRoom(mappedRoomId);
748+
if (mappedRoom.getPendingEvents().length > 0) {
749+
Resend.cancelUnsentEvents(mappedRoom);
750+
}
751+
}
752+
740753
const timeUntilTurnCresExpire = MatrixClientPeg.get().getTurnServersExpiry() - Date.now();
741754
logger.log("Current turn creds expire in " + timeUntilTurnCresExpire + " ms");
742755
const call = MatrixClientPeg.get().createCall(mappedRoomId);

src/Resend.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,23 @@ import { MatrixClientPeg } from './MatrixClientPeg';
2222
import dis from './dispatcher/dispatcher';
2323

2424
export default class Resend {
25-
static resendUnsentEvents(room: Room): Promise<void[]> {
25+
public static resendUnsentEvents(room: Room): Promise<void[]> {
2626
return Promise.all(room.getPendingEvents().filter(function(ev: MatrixEvent) {
2727
return ev.status === EventStatus.NOT_SENT;
2828
}).map(function(event: MatrixEvent) {
2929
return Resend.resend(event);
3030
}));
3131
}
3232

33-
static cancelUnsentEvents(room: Room): void {
33+
public static cancelUnsentEvents(room: Room): void {
3434
room.getPendingEvents().filter(function(ev: MatrixEvent) {
3535
return ev.status === EventStatus.NOT_SENT;
3636
}).forEach(function(event: MatrixEvent) {
3737
Resend.removeFromQueue(event);
3838
});
3939
}
4040

41-
static resend(event: MatrixEvent): Promise<void> {
41+
public static resend(event: MatrixEvent): Promise<void> {
4242
const room = MatrixClientPeg.get().getRoom(event.getRoomId());
4343
return MatrixClientPeg.get().resendEvent(event, room).then(function(res) {
4444
dis.dispatch({
@@ -52,7 +52,7 @@ export default class Resend {
5252
});
5353
}
5454

55-
static removeFromQueue(event: MatrixEvent): void {
55+
public static removeFromQueue(event: MatrixEvent): void {
5656
MatrixClientPeg.get().cancelPendingEvent(event);
5757
}
5858
}

0 commit comments

Comments
 (0)