mirror of
https://gitlab.com/comunic/comunicmobile
synced 2025-06-18 15:58:04 +00:00
Use the conversation messages cache before going online
This commit is contained in:
@ -1,13 +1,14 @@
|
||||
import 'package:comunic/helpers/database/database_contract.dart';
|
||||
import 'package:comunic/helpers/database/model_database_helper.dart';
|
||||
import 'package:comunic/lists/conversation_messages_list.dart';
|
||||
import 'package:comunic/models/conversation_message.dart';
|
||||
|
||||
/// Conversation messages database helper
|
||||
///
|
||||
/// @author Pierre HUBERT
|
||||
|
||||
class ConversationMessagesDatabaseHelper extends ModelDatabaseHelper<ConversationMessage> {
|
||||
|
||||
class ConversationMessagesDatabaseHelper
|
||||
extends ModelDatabaseHelper<ConversationMessage> {
|
||||
@override
|
||||
ConversationMessage initializeFromMap(Map<String, dynamic> map) {
|
||||
return ConversationMessage.fromMap(map);
|
||||
@ -18,4 +19,19 @@ class ConversationMessagesDatabaseHelper extends ModelDatabaseHelper<Conversatio
|
||||
return ConversationsMessagesTableContract.TABLE_NAME;
|
||||
}
|
||||
|
||||
}
|
||||
/// Get all the message cached for a given conversation
|
||||
Future<ConversationMessagesList> getAllMessagesConversations(
|
||||
int conversationID,
|
||||
{int lastMessageID = 0}) async {
|
||||
final list = await getMultiple(
|
||||
where: "${ConversationsMessagesTableContract.C_CONVERSATION_ID} = ? "
|
||||
"AND ${BaseTableContract.C_ID} > ?",
|
||||
whereArgs: [conversationID, lastMessageID],
|
||||
);
|
||||
|
||||
// Turn the list into a conversation messages list
|
||||
ConversationMessagesList finalList = ConversationMessagesList();
|
||||
finalList.addAll(list);
|
||||
return finalList;
|
||||
}
|
||||
}
|
||||
|
@ -48,7 +48,33 @@ abstract class ModelDatabaseHelper<T extends CacheModel> {
|
||||
|
||||
/// Get all the entries from the table
|
||||
Future<List<T>> getAll() async {
|
||||
List<Map> maps = await(await DatabaseHelper.get()).query(tableName());
|
||||
List<Map> maps = await (await DatabaseHelper.get()).query(tableName());
|
||||
return maps.map((f) => initializeFromMap(f)).toList();
|
||||
}
|
||||
|
||||
/// Get some entries from the table based on some conditions
|
||||
Future<List<T>> getMultiple(
|
||||
{bool distinct,
|
||||
List<String> columns,
|
||||
String where,
|
||||
List<dynamic> whereArgs,
|
||||
String groupBy,
|
||||
String having,
|
||||
String orderBy,
|
||||
int limit,
|
||||
int offset}) async {
|
||||
List<Map> maps = await (await DatabaseHelper.get()).query(
|
||||
tableName(),
|
||||
distinct: distinct,
|
||||
columns: columns,
|
||||
where: where,
|
||||
whereArgs: whereArgs,
|
||||
groupBy: groupBy,
|
||||
having: having,
|
||||
orderBy: orderBy,
|
||||
limit: limit,
|
||||
offset: offset,
|
||||
);
|
||||
return maps.map((f) => initializeFromMap(f)).toList();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user