1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-23 05:19:22 +00:00
comunicmobile/lib/helpers/database/conversation_messages_database_helper.dart

38 lines
1.2 KiB
Dart
Raw Normal View History

2019-04-27 06:42:27 +00:00
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';
2019-04-27 06:42:27 +00:00
import 'package:comunic/models/conversation_message.dart';
/// Conversation messages database helper
///
/// @author Pierre HUBERT
class ConversationMessagesDatabaseHelper
extends ModelDatabaseHelper<ConversationMessage> {
2019-04-27 06:42:27 +00:00
@override
ConversationMessage initializeFromMap(Map<String, dynamic> map) {
return ConversationMessage.fromMap(map);
}
@override
String tableName() {
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;
}
}