mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-12-27 05:18:50 +00:00
67 lines
2.2 KiB
Dart
67 lines
2.2 KiB
Dart
import 'package:comunic/helpers/database/database_contract.dart';
|
|
import 'package:comunic/models/cache_model.dart';
|
|
import 'package:comunic/models/displayed_content.dart';
|
|
import 'package:comunic/utils/account_utils.dart' as account;
|
|
import 'package:meta/meta.dart';
|
|
|
|
/// Single conversation message
|
|
///
|
|
/// @author Pierre HUBERT
|
|
|
|
class ConversationMessage extends CacheModel implements Comparable {
|
|
final int id;
|
|
final int conversationID;
|
|
final int userID;
|
|
final int timeInsert;
|
|
final DisplayedString message;
|
|
final String imageURL;
|
|
|
|
const ConversationMessage({
|
|
@required this.id,
|
|
@required this.conversationID,
|
|
@required this.userID,
|
|
@required this.timeInsert,
|
|
@required this.message,
|
|
@required this.imageURL,
|
|
}) : assert(id != null),
|
|
assert(userID != null),
|
|
assert(timeInsert != null),
|
|
assert(message != null),
|
|
super(id: id);
|
|
|
|
DateTime get date => DateTime.fromMillisecondsSinceEpoch(timeInsert * 1000);
|
|
|
|
bool get hasMessage => !message.isNull && message.length > 0;
|
|
|
|
bool get hasImage => imageURL != null && imageURL != "null";
|
|
|
|
bool get isOwner => account.userID() == userID;
|
|
|
|
@override
|
|
int compareTo(other) {
|
|
return id.compareTo(other.id);
|
|
}
|
|
|
|
@override
|
|
Map<String, dynamic> toMap() {
|
|
return {
|
|
ConversationsMessagesTableContract.C_ID: id,
|
|
ConversationsMessagesTableContract.C_CONVERSATION_ID: conversationID,
|
|
ConversationsMessagesTableContract.C_USER_ID: userID,
|
|
ConversationsMessagesTableContract.C_TIME_INSERT: timeInsert,
|
|
ConversationsMessagesTableContract.C_MESSAGE: message.content,
|
|
ConversationsMessagesTableContract.C_IMAGE_URL: imageURL
|
|
};
|
|
}
|
|
|
|
ConversationMessage.fromMap(Map<String, dynamic> map)
|
|
: id = map[ConversationsMessagesTableContract.C_ID],
|
|
conversationID =
|
|
map[ConversationsMessagesTableContract.C_CONVERSATION_ID],
|
|
userID = map[ConversationsMessagesTableContract.C_USER_ID],
|
|
timeInsert = map[ConversationsMessagesTableContract.C_TIME_INSERT],
|
|
message = DisplayedString(map[ConversationsMessagesTableContract.C_MESSAGE]),
|
|
imageURL = map[ConversationsMessagesTableContract.C_IMAGE_URL],
|
|
super.fromMap(map);
|
|
}
|