2019-04-27 06:42:27 +00:00
|
|
|
import 'package:comunic/helpers/database/database_contract.dart';
|
|
|
|
import 'package:comunic/models/cache_model.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;
|
|
|
|
final String message;
|
|
|
|
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
|
|
|
|
2019-04-26 09:28:33 +00:00
|
|
|
bool get hasMessage => message != null && message.length > 0;
|
|
|
|
|
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,
|
|
|
|
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);
|
2019-04-25 06:56:16 +00:00
|
|
|
}
|