From 653883a22d97552419a7db30ed54ebd926b0cfef Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Fri, 24 Jan 2020 16:42:51 +0000 Subject: [PATCH] =?UTF-8?q?[Store]=C2=A0Make=20lightweight=20store=20possi?= =?UTF-8?q?ble?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/src/client.dart | 23 +++++++++++++---------- lib/src/store_api.dart | 15 +++++++++++++-- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/lib/src/client.dart b/lib/src/client.dart index 06b9683..cb97bee 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -61,10 +61,11 @@ class Client { Client get connection => this; /// Optional persistent store for all data. - StoreAPI store; + ExtendedStoreAPI get store => (storeAPI?.extended ?? false) ? storeAPI : null; - Client(this.clientName, {this.debug = false, this.store}) { - if (this.clientName != "testclient") store = null; //Store(this); + StoreAPI storeAPI; + + Client(this.clientName, {this.debug = false, this.storeAPI}) { this.onLoginStateChanged.stream.listen((loginState) { print("LoginState: ${loginState.toString()}"); }); @@ -647,12 +648,14 @@ class Client { this._lazyLoadMembers = newLazyLoadMembers; this.prevBatch = newPrevBatch; - if (this.store != null) { - await this.store.storeClient(); - this._rooms = await this.store.getRoomList(onlyLeft: false); - this._sortRooms(); - this.accountData = await this.store.getAccountData(); - this.presences = await this.store.getPresences(); + if (this.storeAPI != null) { + await this.storeAPI.storeClient(); + if (this.store != null) { + this._rooms = await this.store.getRoomList(onlyLeft: false); + this._sortRooms(); + this.accountData = await this.store.getAccountData(); + this.presences = await this.store.getPresences(); + } } _userEventSub ??= onUserEvent.stream.listen(this.handleUserUpdate); @@ -666,7 +669,7 @@ class Client { /// Resets all settings and stops the synchronisation. void clear() { - this.store?.clear(); + this.storeAPI?.clear(); this._accessToken = this._homeserver = this._userID = this._deviceID = this ._deviceName = this._matrixVersions = this._lazyLoadMembers = this.prevBatch = null; diff --git a/lib/src/store_api.dart b/lib/src/store_api.dart index ab19281..58ac190 100644 --- a/lib/src/store_api.dart +++ b/lib/src/store_api.dart @@ -33,9 +33,12 @@ import 'sync/event_update.dart'; import 'sync/room_update.dart'; import 'sync/user_update.dart'; -/// Responsible to store all data persistent and to query objects from the -/// database. abstract class StoreAPI { + /// Whether this is a simple store which only stores the client credentials and + /// end to end encryption stuff or the whole sync payloads. + final bool extended = false; + + /// Link back to the client. Client client; /// Will be automatically called when the client is logged in successfully. @@ -43,6 +46,14 @@ abstract class StoreAPI { /// Clears all tables from the database. Future clear(); +} + +/// Responsible to store all data persistent and to query objects from the +/// database. +abstract class ExtendedStoreAPI extends StoreAPI { + /// Whether this is a simple store which only stores the client credentials and + /// end to end encryption stuff or the whole sync payloads. + final bool extended = true; /// The current trans Future setRoomPrevBatch(String roomId, String prevBatch);