From 027d3d214060c136626482711f9a5004111d3b6e Mon Sep 17 00:00:00 2001 From: Till-JS <101404291+Till-JS@users.noreply.github.com> Date: Thu, 12 Feb 2026 14:07:05 +0100 Subject: [PATCH] feat(matrix): restore last selected chat on app load Save the last selected room ID to localStorage and automatically restore it when the app loads and sync is prepared. Co-Authored-By: Claude Opus 4.5 --- .../apps/web/src/lib/matrix/store.svelte.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/apps/matrix/apps/web/src/lib/matrix/store.svelte.ts b/apps/matrix/apps/web/src/lib/matrix/store.svelte.ts index be806daf8..a1ba8c312 100644 --- a/apps/matrix/apps/web/src/lib/matrix/store.svelte.ts +++ b/apps/matrix/apps/web/src/lib/matrix/store.svelte.ts @@ -29,6 +29,7 @@ import type { } from './types'; const STORAGE_KEY = 'matrix_credentials'; +const LAST_ROOM_KEY = 'matrix_last_room'; /** * Reactive Matrix store using Svelte 5 runes @@ -260,6 +261,14 @@ class MatrixStore { if (state === 'PREPARED') { this._rooms = this._client!.getRooms(); console.log(`Matrix sync prepared, ${this._rooms.length} rooms loaded`); + + // Restore last selected room + if (browser && !this._currentRoomId) { + const lastRoomId = localStorage.getItem(LAST_ROOM_KEY); + if (lastRoomId && this._client!.getRoom(lastRoomId)) { + this.selectRoom(lastRoomId); + } + } } if (state === 'ERROR') { @@ -471,6 +480,11 @@ class MatrixStore { if (lastEvent) { this._client?.sendReadReceipt(lastEvent).catch(console.error); } + + // Save last room to localStorage + if (browser) { + localStorage.setItem(LAST_ROOM_KEY, roomId); + } } else { this._timeline = []; } @@ -1684,6 +1698,7 @@ class MatrixStore { this.destroy(); if (browser) { localStorage.removeItem(STORAGE_KEY); + localStorage.removeItem(LAST_ROOM_KEY); } }