···1818 const ctx = dbRegistry.get(dbname);
1919 if (ctx) {
2020 console.log(`Notifying listeners for database: ${dbname}`);
2121-2222- // Get all tables in the database
2323- // For simplicity, we'll just use the todos table since we know it exists
2421 const tables = ["todos"];
25222626- // Create synthetic changes for each table
2727- // This tells the system that each table has been updated
2823 const changes: [number, string, bigint][] = tables.map(table => [
2924 UPDATE_TYPE.UPDATE, // We use UPDATE as a general change type
3025 table, // Table name
···6055// Store active crypto key pairs (in memory for the session)
6156const activeKeyPairs: Record<string, CryptoKeyPair> = {};
62576363-// Function to generate a WebCrypto key pair
6458async function generateKeyPair() {
6559 try {
6660 const keyPair = await window.crypto.subtle.generateKey(
···9589 }
9690}
97919292+// Helper function to load all visited rooms
9393+function loadAllRooms(): Set<string> {
9494+ const allRoomsJSON = localStorage.getItem('allRooms');
9595+ if (allRoomsJSON) {
9696+ try {
9797+ return new Set(JSON.parse(allRoomsJSON));
9898+ } catch (error) {
9999+ console.error('Error parsing allRooms from localStorage:', error);
100100+ }
101101+ }
102102+ return new Set<string>();
103103+}
104104+105105+// Helper function to save all visited rooms
106106+function saveAllRooms(rooms: Set<string>): void {
107107+ localStorage.setItem('allRooms', JSON.stringify(Array.from(rooms)));
108108+}
109109+98110// Function to get room ID from URL hash or generate a new one
99111async function getRoomId(): Promise<{ roomId: string, keyPair?: CryptoKeyPair, publicKeyBase64?: string }> {
100112 // Check URL hash for room parameter
···103115 const roomFromHash = params.get('room');
104116105117 if (roomFromHash) {
118118+ // Room exists in URL, add it to the list of all visited rooms
119119+ const allRooms = loadAllRooms();
120120+ allRooms.add(roomFromHash);
121121+ saveAllRooms(allRooms);
122122+ console.log(`Added ${roomFromHash} to visited rooms list`);
123123+106124 // Room exists in URL, check if we have keys for it in localStorage
107125 const storedKeys = localStorage.getItem(`keys-${roomFromHash}`);
108126 if (storedKeys) {
···147165 // Check localStorage for room
148166 const storedRoom = localStorage.getItem("room");
149167 if (storedRoom) {
168168+ // Update URL with the room ID from localStorage
169169+ updateUrlWithRoom(storedRoom);
170170+171171+ // Add to the list of all visited rooms
172172+ const allRooms = loadAllRooms();
173173+ allRooms.add(storedRoom);
174174+ saveAllRooms(allRooms);
175175+ console.log(`Added ${storedRoom} to visited rooms list`);
150176 // Room exists in localStorage, check if we have keys for it
151177 const storedKeys = localStorage.getItem(`keys-${storedRoom}`);
152178 if (storedKeys) {
···190216 // Generate a new room ID and key pair
191217 const newRoomId = crypto.randomUUID().replaceAll("-", "");
192218 localStorage.setItem("room", newRoomId);
219219+220220+ // Add to the list of all visited rooms
221221+ const allRooms = loadAllRooms();
222222+ allRooms.add(newRoomId);
223223+ saveAllRooms(allRooms);
224224+ console.log(`Added ${newRoomId} to visited rooms list`);
193225194226 // Generate a new key pair for this room
195227 const { keyPair, publicKeyBase64 } = await generateKeyPair();