From 8cfc25a139a2932e7c6c92bcd698aa69b105dde3 Mon Sep 17 00:00:00 2001 From: krille-chan Date: Mon, 24 Nov 2025 16:41:36 +0100 Subject: [PATCH] chore: Request keys for last room messages after bootstrap --- lib/pages/bootstrap/bootstrap_dialog.dart | 29 ++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/lib/pages/bootstrap/bootstrap_dialog.dart b/lib/pages/bootstrap/bootstrap_dialog.dart index e1cdca0b9..7d91593c0 100644 --- a/lib/pages/bootstrap/bootstrap_dialog.dart +++ b/lib/pages/bootstrap/bootstrap_dialog.dart @@ -89,8 +89,31 @@ class BootstrapDialogState extends State { _goBackAction(false); } - void _goBackAction(bool success) => - context.canPop() ? context.pop(success) : context.go('/rooms'); + void _goBackAction(bool success) { + if (success) _decryptLastEvents(); + + context.canPop() ? context.pop(success) : context.go('/rooms'); + } + + void _decryptLastEvents() async { + for (final room in client.rooms) { + final event = room.lastEvent; + if (event != null && + event.type == EventTypes.Encrypted && + event.messageType == MessageTypes.BadEncrypted && + event.content['can_request_session'] == true) { + final sessionId = event.content.tryGet('session_id'); + final senderKey = event.content.tryGet('sender_key'); + if (sessionId != null && senderKey != null) { + room.client.encryption?.keyManager.maybeAutoRequest( + room.id, + sessionId, + senderKey, + ); + } + } + } + } void _createBootstrap(bool wipe) async { await client.roomsLoading; @@ -536,7 +559,7 @@ class BootstrapDialogState extends State { ); buttons.add( ElevatedButton( - onPressed: () => _goBackAction(false), + onPressed: () => _goBackAction(true), child: Text(L10n.of(context).close), ), );