[Store] Make lightweight store possible
This commit is contained in:
parent
7643969db7
commit
653883a22d
|
@ -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;
|
||||
|
|
|
@ -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<void> 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<void> setRoomPrevBatch(String roomId, String prevBatch);
|
||||
|
|
Loading…
Reference in a new issue