mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-14 20:21:09 +02:00
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 <noreply@anthropic.com>
This commit is contained in:
parent
7a2acd4bbe
commit
027d3d2140
1 changed files with 15 additions and 0 deletions
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue