1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2025-07-03 15:13:29 +00:00

Store locally the list of conversations

This commit is contained in:
2019-04-24 14:25:46 +02:00
parent 7f41f0dae1
commit eb34ed5c3d
7 changed files with 121 additions and 18 deletions

View File

@ -1,3 +1,4 @@
import 'package:comunic/helpers/database/conversations_database_helper.dart';
import 'package:comunic/lists/conversations_list.dart';
import 'package:comunic/lists/users_list.dart';
import 'package:comunic/models/api_request.dart';
@ -9,6 +10,9 @@ import 'package:comunic/utils/account_utils.dart';
/// @author Pierre HUBERT
class ConversationsHelper {
final ConversationsDatabaseHelper _conversationsDatabaseHelper =
ConversationsDatabaseHelper();
/// Download the list of conversations from the server
Future<ConversationsList> downloadList() async {
final response =
@ -28,6 +32,10 @@ class ConversationsHelper {
members: f["members"].map<int>((f) => int.parse(f)).toList(),
)));
// Update the database
await _conversationsDatabaseHelper.clearTable();
await _conversationsDatabaseHelper.insertAll(list);
return list;
} on Exception catch (e) {
print(e.toString());
@ -46,14 +54,11 @@ class ConversationsHelper {
for (int i = 0; i < 3 && i < conversation.members.length; i++)
if (conversation.members[i] != userID()) {
name += (count > 0 ? ", " : "") +
users
.getUser(conversation.members[i])
.fullName;
users.getUser(conversation.members[i]).fullName;
count++;
}
if(conversation.members.length > 3)
name += ", ...";
if (conversation.members.length > 3) name += ", ...";
return name;
}