fix: add MatrixSdkDatabase — timeline was empty without event storage
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) <noreply@anthropic.com>
This commit is contained in:
@@ -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.
|
// Matrix SDK client singleton provider.
|
||||||
// The Matrix client is kept alive for the full app lifetime once initialised.
|
// 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
|
/// keepAlive: true — the Matrix client must never be disposed while the app
|
||||||
/// is running; it holds the sync loop and all room state.
|
/// is running; it holds the sync loop and all room state.
|
||||||
///
|
///
|
||||||
/// Phase 1: no databaseBuilder — uses in-memory store only (no persistence
|
/// Uses [MatrixSdkDatabase] for event storage — without a database, the SDK
|
||||||
/// across restarts). Phase 2 will wire in a drift-backed DatabaseApi.
|
/// 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)
|
@Riverpod(keepAlive: true)
|
||||||
Client matrixClient(Ref ref) {
|
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;
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user