mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-12-27 21:38:51 +00:00
62 lines
2.0 KiB
Dart
62 lines
2.0 KiB
Dart
import 'package:comunic/helpers/database/database_contract.dart';
|
|
import 'package:comunic/models/cache_model.dart';
|
|
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 String 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 != null && message.length > 0;
|
|
|
|
bool get hasImage => imageURL != null && imageURL != "null";
|
|
|
|
@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,
|
|
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 = map[ConversationsMessagesTableContract.C_MESSAGE],
|
|
imageURL = map[ConversationsMessagesTableContract.C_IMAGE_URL],
|
|
super.fromMap(map);
|
|
}
|