Merge pull request #232 from matrixgpt/leave-room-on-crypto-error

Leave room when room key error occurs.
This commit is contained in:
bertybuttface 2023-10-27 17:24:05 +01:00 committed by GitHub
commit 5110281185
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -76,7 +76,12 @@ async function main() {
client.on("room.failed_decryption", async (roomId, event, error) => { client.on("room.failed_decryption", async (roomId, event, error) => {
// handle `m.room.encrypted` event that could not be decrypted // handle `m.room.encrypted` event that could not be decrypted
LogService.error("index", `Failed decryption event!\n${{ roomId, event, error }}`); LogService.error("index", `Failed decryption event!\n${{ roomId, event, error }}`);
await client.sendText(roomId, `I couldn't decrypt the message :( Please add me to an unencrypted room.`); await client.sendText(roomId, `Room key error. I will leave the room, please reinvite me!`);
try {
await client.leaveRoom(roomId);
} catch (e) {
LogService.error("index", `Failed to leave room ${roomId} after failed decryption!`);
}
}); });
client.on("room.join", async (roomId: string, _event: any) => { client.on("room.join", async (roomId: string, _event: any) => {