1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2025-06-19 00:05:16 +00:00

Show cached conversations list before getting list from the server

This commit is contained in:
2019-04-24 15:03:36 +02:00
parent eb34ed5c3d
commit 4be5a1b5a8
5 changed files with 79 additions and 16 deletions

View File

@ -43,6 +43,13 @@ class ConversationsHelper {
}
}
/// Get the local list of conversations
Future<ConversationsList> getCachedList() async {
final list = await _conversationsDatabaseHelper.getAll();
list.sort();
return list;
}
/// Get the name of a [conversation]. This requires information about the
/// users of this conversation
static String getConversationName(

View File

@ -1,5 +1,6 @@
import 'package:comunic/helpers/database/database_contract.dart';
import 'package:comunic/helpers/database/model_database_helper.dart';
import 'package:comunic/lists/conversations_list.dart';
import 'package:comunic/models/conversation.dart';
/// Conversations database helper
@ -17,4 +18,12 @@ class ConversationsDatabaseHelper extends ModelDatabaseHelper<Conversation> {
return ConversationTableContract.TABLE_NAME;
}
@override
Future<ConversationsList> getAll() async {
ConversationsList list = ConversationsList();
list.addAll(await super.getAll());
return list;
}
}

View File

@ -36,8 +36,8 @@ abstract class ModelDatabaseHelper<T extends CacheModel> {
/// Returns null if none found
Future<T> get(int id) async {
List<Map> maps = await (await DatabaseHelper.get()).query(
UserTableContract.TABLE_NAME,
where: '${UserTableContract.C_ID} = ?',
tableName(),
where: '${BaseTableContract.C_ID} = ?',
whereArgs: [id],
);
@ -46,6 +46,12 @@ abstract class ModelDatabaseHelper<T extends CacheModel> {
return null;
}
/// Get all the entries from the table
Future<List<T>> getAll() async {
List<Map> maps = await(await DatabaseHelper.get()).query(tableName());
return maps.map((f) => initializeFromMap(f)).toList();
}
/// Empty the table
Future<void> clearTable() async {
await (await DatabaseHelper.get()).execute("DELETE FROM ${tableName()}");