diff --git a/src/app/hooks/useCommands.ts b/src/app/hooks/useCommands.ts index 89cd86a9..4322c62b 100644 --- a/src/app/hooks/useCommands.ts +++ b/src/app/hooks/useCommands.ts @@ -238,6 +238,7 @@ export enum Command { DelAcc = 'delacc', SetExt = 'setext', DelExt = 'delext', + DiscardSession = 'discardsession', } export type CommandContent = { @@ -1255,6 +1256,35 @@ export const useCommands = (mx: MatrixClient, room: Room): CommandRecord => { } }, }, + [Command.DiscardSession]: { + name: Command.DiscardSession, + description: 'Force discard the current outbound E2EE session in this room.', + exe: async () => { + const userId = mx.getSafeUserId(); + const sendFeedback = (msg: string) => { + const localNotice = new MatrixEvent({ + type: 'm.room.message', + content: { msgtype: 'm.notice', body: msg }, + event_id: `~discard-${Date.now()}`, + room_id: room.roomId, + sender: userId, + }); + room.addLiveEvents([localNotice], { duplicateStrategy: 'ignore' } as any); + }; + + try { + const crypto = mx.getCrypto(); + if (!crypto) { + sendFeedback('Encryption is not enabled on this client.'); + return; + } + await crypto.forceDiscardSession(room.roomId); + sendFeedback('Outbound encryption session discarded.'); + } catch (e: any) { + sendFeedback(`Failed to discard session: ${e.message}`); + } + }, + }, }), [mx, room, navigateRoom, developerTools] );