mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-23 05:19:22 +00:00
89 lines
3.0 KiB
Dart
89 lines
3.0 KiB
Dart
import 'package:comunic/helpers/database/database_contract.dart';
|
|
import 'package:comunic/models/cache_model.dart';
|
|
import 'package:comunic/utils/account_utils.dart';
|
|
import 'package:comunic/utils/list_utils.dart';
|
|
import 'package:meta/meta.dart';
|
|
|
|
/// Conversation model
|
|
///
|
|
/// @author Pierre HUBERT
|
|
|
|
enum CallCapabilities { NONE, AUDIO, VIDEO }
|
|
|
|
class Conversation extends CacheModel implements Comparable {
|
|
final int ownerID;
|
|
final int lastActive;
|
|
final String name;
|
|
final bool following;
|
|
final bool sawLastMessage;
|
|
final List<int> members;
|
|
final bool canEveryoneAddMembers;
|
|
final CallCapabilities callCapabilities;
|
|
final bool isHavingCall;
|
|
|
|
const Conversation({
|
|
@required int id,
|
|
@required this.ownerID,
|
|
@required this.lastActive,
|
|
@required this.name,
|
|
@required this.following,
|
|
@required this.sawLastMessage,
|
|
@required this.members,
|
|
@required this.canEveryoneAddMembers,
|
|
this.callCapabilities = CallCapabilities.NONE,
|
|
this.isHavingCall = false,
|
|
}) : assert(id != null),
|
|
assert(ownerID != null),
|
|
assert(lastActive != null),
|
|
assert(following != null),
|
|
assert(sawLastMessage != null),
|
|
assert(members != null),
|
|
assert(canEveryoneAddMembers != null),
|
|
assert(callCapabilities != null),
|
|
assert(isHavingCall != null),
|
|
super(id: id);
|
|
|
|
/// Check out whether a conversation has a fixed name or not
|
|
bool get hasName => this.name != null;
|
|
|
|
/// Check out whether current user of the application is the owner of it or
|
|
/// not
|
|
bool get isOwner => this.ownerID == userID();
|
|
|
|
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 =
|
|
listToIntList(map[ConversationTableContract.C_MEMBERS].split(",")),
|
|
canEveryoneAddMembers =
|
|
map[ConversationTableContract.C_CAN_EVERYONE_ADD_MEMBERS] == 1,
|
|
|
|
// By default, we can not do any call
|
|
callCapabilities = CallCapabilities.NONE,
|
|
isHavingCall = false,
|
|
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(","),
|
|
ConversationTableContract.C_CAN_EVERYONE_ADD_MEMBERS:
|
|
canEveryoneAddMembers ? 1 : 0
|
|
};
|
|
}
|
|
|
|
@override
|
|
int compareTo(other) {
|
|
return other.lastActive.compareTo(this.lastActive);
|
|
}
|
|
}
|