1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-30 00:36:28 +00:00
comunicmobile/lib/models/conversation.dart

65 lines
2.0 KiB
Dart
Raw Normal View History

import 'package:comunic/helpers/database/database_contract.dart';
import 'package:comunic/models/cache_model.dart';
import 'package:comunic/utils/list_utils.dart';
2019-04-23 12:35:41 +00:00
import 'package:meta/meta.dart';
/// Conversation model
///
/// @author Pierre HUBERT
class Conversation extends CacheModel implements Comparable {
2019-04-23 12:35:41 +00:00
final int ownerID;
final int lastActive;
final String name;
final bool following;
final bool sawLastMessage;
final List<int> members;
const Conversation({
@required int id,
2019-04-23 12:35:41 +00:00
@required this.ownerID,
@required this.lastActive,
@required this.name,
@required this.following,
@required this.sawLastMessage,
@required this.members,
}) : assert(id != null),
assert(ownerID != null),
assert(lastActive != null),
assert(following != null),
assert(sawLastMessage != null),
assert(members != null),
super(id: id);
/// Check out whether a conversation has a fixed name or not
2019-04-25 09:14:05 +00:00
bool get hasName => 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,
2019-04-24 15:46:25 +00:00
members = listToIntList(
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(","),
};
}
@override
int compareTo(other) {
return other.lastActive.compareTo(this.lastActive);
}
2019-04-23 12:35:41 +00:00
}