fix #119 add /discardsession command

This commit is contained in:
7w1 committed 2026-03-04 14:49:32 -06:00
1 parent ae1122035b
commit 3cdc92f3d0
1 file changed
+30
+30
View File
@@ -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]
);