/* * Copyright (c) 2019 Zender & Kurtz GbR. * * Authors: * Christian Pauly * Marcel Radzio * * This file is part of famedlysdk. * * famedlysdk is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * famedlysdk is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with famedlysdk. If not, see . */ import 'dart:async'; import 'dart:core'; import 'dart:typed_data'; import 'package:famedlysdk/src/account_data.dart'; import 'package:famedlysdk/src/presence.dart'; import 'package:famedlysdk/src/utils/device_keys_list.dart'; import 'client.dart'; import 'event.dart'; import 'room.dart'; import 'user.dart'; import 'sync/event_update.dart'; import 'sync/room_update.dart'; import 'sync/user_update.dart'; 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. Future storeClient(); /// Clears all tables from the database. Future clear(); Future getItem(String key); Future setItem(String key, String value); Future> getUserDeviceKeys(); Future storeUserDeviceKeys(Map userDeviceKeys); } /// Responsible to store all data persistent and to query objects from the /// database. abstract class ExtendedStoreAPI extends StoreAPI { /// The maximum size of files which should be stored in bytes. static const int MAX_FILE_SIZE = 10 * 1024 * 1024; /// 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); /// Performs these query or queries inside of an transaction. Future transaction(void queries()); /// Will be automatically called on every synchronisation. Must be called inside of // /// [transaction]. void storePrevBatch(String prevBatch); Future storeRoomPrevBatch(Room room); /// Stores a RoomUpdate object in the database. Must be called inside of /// [transaction]. Future storeRoomUpdate(RoomUpdate roomUpdate); /// Stores an UserUpdate object in the database. Must be called inside of /// [transaction]. Future storeUserEventUpdate(UserUpdate userUpdate); /// Stores an EventUpdate object in the database. Must be called inside of /// [transaction]. Future storeEventUpdate(EventUpdate eventUpdate); /// Returns a User object by a given Matrix ID and a Room. Future getUser({String matrixID, Room room}); /// Returns a list of events for the given room and sets all participants. Future> getEventList(Room room); /// Returns all rooms, the client is participating. Excludes left rooms. Future> getRoomList({bool onlyLeft = false}); /// Deletes this room from the database. Future forgetRoom(String roomID); /// Sets notification and highlight count to 0 for this room. Future resetNotificationCount(String roomID); /// Searches for the event in the store. Future getEventById(String eventID, Room room); /// Returns all account data for this client. Future> getAccountData(); /// Returns all stored presences for this client. Future> getPresences(); /// Removes this event from the store. Future removeEvent(String eventId); /// Stores the bytes of this file indexed by the [mxcUri]. Throws an /// exception if the bytes are more than [MAX_FILE_SIZE]. Future storeFile(Uint8List bytes, String mxcUri); /// Returns the file bytes indexed by [mxcUri]. Returns null if not found. Future getFile(String mxcUri); }