mirror of
https://gitlab.com/comunic/comunicmobile
synced 2025-06-19 00:05:16 +00:00
Do not use SQLite anymore for users
This commit is contained in:
@ -102,6 +102,8 @@ abstract class BaseSerializationHelper<T extends SerializableElement> {
|
||||
return _cache.any((element) => isContained(element));
|
||||
}
|
||||
|
||||
Future<bool> has(T el) => any((t) => t == el);
|
||||
|
||||
/// Check if any entry in the last match the predicate
|
||||
Future<T> first(bool filter(T t)) async {
|
||||
await _loadCache();
|
||||
@ -120,10 +122,26 @@ abstract class BaseSerializationHelper<T extends SerializableElement> {
|
||||
await _saveCache();
|
||||
}
|
||||
|
||||
/// Insert or replace many elements
|
||||
Future<void> insertOrReplaceElements(List<T> list) async {
|
||||
await _loadCache();
|
||||
|
||||
_cache.removeWhere((element) => list.any((newEl) => element == newEl));
|
||||
_cache.addAll(list);
|
||||
|
||||
await _saveCache();
|
||||
}
|
||||
|
||||
/// Remove elements
|
||||
Future<void> removeElement(bool isToRemove(T t)) async {
|
||||
await _loadCache();
|
||||
_cache.removeWhere((element) => isToRemove(element));
|
||||
await _saveCache();
|
||||
}
|
||||
|
||||
/// Remove all elements
|
||||
Future<void> removeAll() async {
|
||||
_cache = [];
|
||||
await _saveCache();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,28 @@
|
||||
import 'package:comunic/helpers/serialization/base_serialization_helper.dart';
|
||||
import 'package:comunic/models/user.dart';
|
||||
|
||||
/// User serialization helper
|
||||
///
|
||||
/// @author Pierre Hubert
|
||||
|
||||
UsersListSerialisationHelper _singleton;
|
||||
|
||||
class UsersListSerialisationHelper extends BaseSerializationHelper<User> {
|
||||
UsersListSerialisationHelper._();
|
||||
|
||||
factory UsersListSerialisationHelper() {
|
||||
if (_singleton == null) _singleton = UsersListSerialisationHelper._();
|
||||
|
||||
return _singleton;
|
||||
}
|
||||
|
||||
@override
|
||||
String get type => "users-list";
|
||||
|
||||
@override
|
||||
User parse(Map<String, dynamic> m) => User.fromJson(m);
|
||||
|
||||
/// Remove a user by its ID
|
||||
Future<void> removeUserByID(int userID) =>
|
||||
removeElement((t) => t.id == userID);
|
||||
}
|
Reference in New Issue
Block a user