1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-12-28 13:58:51 +00:00
comunicmobile/lib/models/conversation_message.dart

67 lines
2.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/models/cache_model.dart';
2020-04-16 13:10:47 +00:00
import 'package:comunic/models/displayed_content.dart';
2019-05-04 06:58:14 +00:00
import 'package:comunic/utils/account_utils.dart' as account;
2019-04-25 06:56:16 +00:00
import 'package:meta/meta.dart';
/// Single conversation message
///
/// @author Pierre HUBERT
2019-04-27 06:42:27 +00:00
class ConversationMessage extends CacheModel implements Comparable {
2019-04-25 06:56:16 +00:00
final int id;
2019-04-27 06:42:27 +00:00
final int conversationID;
2019-04-25 06:56:16 +00:00
final int userID;
final int timeInsert;
2020-04-16 13:10:47 +00:00
final DisplayedString message;
2019-04-25 06:56:16 +00:00
final String imageURL;
const ConversationMessage({
@required this.id,
2019-04-27 06:42:27 +00:00
@required this.conversationID,
2019-04-25 06:56:16 +00:00
@required this.userID,
@required this.timeInsert,
@required this.message,
@required this.imageURL,
}) : assert(id != null),
assert(userID != null),
assert(timeInsert != null),
2019-04-27 06:42:27 +00:00
assert(message != null),
super(id: id);
2019-04-25 06:56:16 +00:00
2019-04-26 06:58:18 +00:00
DateTime get date => DateTime.fromMillisecondsSinceEpoch(timeInsert * 1000);
2019-04-27 06:42:27 +00:00
2020-04-16 13:10:47 +00:00
bool get hasMessage => !message.isNull && message.length > 0;
2019-04-26 09:28:33 +00:00
2019-04-27 06:42:27 +00:00
bool get hasImage => imageURL != null && imageURL != "null";
2019-04-26 06:58:18 +00:00
2019-05-04 06:58:14 +00:00
bool get isOwner => account.userID() == userID;
2019-04-25 06:56:16 +00:00
@override
int compareTo(other) {
return id.compareTo(other.id);
}
2019-04-27 06:42:27 +00:00
@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,
2020-04-16 13:10:47 +00:00
ConversationsMessagesTableContract.C_MESSAGE: message.content,
2019-04-27 06:42:27 +00:00
ConversationsMessagesTableContract.C_IMAGE_URL: imageURL
};
}
ConversationMessage.fromMap(Map<String, dynamic> map)
: id = map[ConversationsMessagesTableContract.C_ID],
2020-04-16 13:10:47 +00:00
conversationID =
map[ConversationsMessagesTableContract.C_CONVERSATION_ID],
2019-04-27 06:42:27 +00:00
userID = map[ConversationsMessagesTableContract.C_USER_ID],
timeInsert = map[ConversationsMessagesTableContract.C_TIME_INSERT],
2020-04-16 13:10:47 +00:00
message = DisplayedString(map[ConversationsMessagesTableContract.C_MESSAGE]),
2019-04-27 06:42:27 +00:00
imageURL = map[ConversationsMessagesTableContract.C_IMAGE_URL],
super.fromMap(map);
2019-04-25 06:56:16 +00:00
}