mirror of
https://gitlab.com/comunic/comunicmobile
synced 2025-09-19 05:48:54 +00:00
Store locally the list of conversations
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
import 'package:comunic/helpers/database/database_contract.dart';
|
||||
import 'package:comunic/models/cache_model.dart';
|
||||
import 'package:comunic/utils/list_utils.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
/// Conversation model
|
||||
///
|
||||
/// @author Pierre HUBERT
|
||||
|
||||
class Conversation {
|
||||
final int id;
|
||||
class Conversation extends CacheModel {
|
||||
final int ownerID;
|
||||
final int lastActive;
|
||||
final String name;
|
||||
@@ -14,7 +16,7 @@ class Conversation {
|
||||
final List<int> members;
|
||||
|
||||
const Conversation({
|
||||
@required this.id,
|
||||
@required int id,
|
||||
@required this.ownerID,
|
||||
@required this.lastActive,
|
||||
@required this.name,
|
||||
@@ -26,8 +28,32 @@ class Conversation {
|
||||
assert(lastActive != null),
|
||||
assert(following != null),
|
||||
assert(sawLastMessage != null),
|
||||
assert(members != null);
|
||||
assert(members != null),
|
||||
super(id: id);
|
||||
|
||||
/// Check out whether a conversation has a fixed name or not
|
||||
bool get has_name => this.name != null;
|
||||
|
||||
Conversation.fromMap(Map<String, dynamic> map)
|
||||
: ownerID = map[ConversationTableContract.C_OWNER_ID],
|
||||
lastActive = map[ConversationTableContract.C_LAST_ACTIVE],
|
||||
name = map[ConversationTableContract.C_NAME],
|
||||
following = map[ConversationTableContract.C_FOLLOWING] == 1,
|
||||
sawLastMessage = map[ConversationTableContract.C_SAW_LAST_MESSAGE] == 1,
|
||||
members = stringListToIntList(
|
||||
map[ConversationTableContract.C_MEMBERS].split(",")),
|
||||
super.fromMap(map);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toMap() {
|
||||
return {
|
||||
ConversationTableContract.C_ID: id,
|
||||
ConversationTableContract.C_OWNER_ID: ownerID,
|
||||
ConversationTableContract.C_LAST_ACTIVE: lastActive,
|
||||
ConversationTableContract.C_NAME: name,
|
||||
ConversationTableContract.C_FOLLOWING: following ? 1 : 0,
|
||||
ConversationTableContract.C_SAW_LAST_MESSAGE: sawLastMessage ? 1 : 0,
|
||||
ConversationTableContract.C_MEMBERS: members.join(","),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user