From 327cd36b6dc6c565ca123fca864c9e6bab9148c5 Mon Sep 17 00:00:00 2001 From: help4bis Date: Fri, 3 Apr 2026 16:04:09 +1000 Subject: [PATCH] =?UTF-8?q?fix:=20add=20MatrixSdkDatabase=20=E2=80=94=20ti?= =?UTF-8?q?meline=20was=20empty=20without=20event=20storage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Without a databaseBuilder, the Matrix SDK has no event storage. The initial sync populates room metadata but timeline events are not retained in any queryable form. room.getTimeline() returns empty. Added MatrixSdkDatabase('m8chat_matrix') which uses IndexedDB on web and SQLite on mobile via Hive. Events are now persisted and timeline loads room history correctly. Co-Authored-By: Claude Opus 4.6 (1M context) --- lib/core/network/matrix_client.dart | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/core/network/matrix_client.dart b/lib/core/network/matrix_client.dart index a7f96f7..637aa9f 100644 --- a/lib/core/network/matrix_client.dart +++ b/lib/core/network/matrix_client.dart @@ -1,4 +1,4 @@ -// Version: 1.0.1 | Created: 2026-04-01 +// Version: 1.1.0 | Created: 2026-04-01 | Updated: 2026-04-03 // Matrix SDK client singleton provider. // The Matrix client is kept alive for the full app lifetime once initialised. @@ -14,9 +14,17 @@ part 'matrix_client.g.dart'; /// keepAlive: true — the Matrix client must never be disposed while the app /// is running; it holds the sync loop and all room state. /// -/// Phase 1: no databaseBuilder — uses in-memory store only (no persistence -/// across restarts). Phase 2 will wire in a drift-backed DatabaseApi. +/// Uses [MatrixSdkDatabase] for event storage — without a database, the SDK +/// doesn't store timeline events and room.getTimeline() returns empty. +/// On web this uses IndexedDB via Hive; on mobile it uses SQLite. @Riverpod(keepAlive: true) Client matrixClient(Ref ref) { - return Client(AppConfig.appName); + return Client( + AppConfig.appName, + databaseBuilder: (client) async { + final db = MatrixSdkDatabase('m8chat_matrix'); + await db.open(); + return db; + }, + ); }