clean up
This commit is contained in:
58
lib/domain/vo/message.dart
Normal file
58
lib/domain/vo/message.dart
Normal file
@@ -0,0 +1,58 @@
|
||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
|
||||
class Message {
|
||||
String id;
|
||||
String message;
|
||||
DateTime date;
|
||||
String receiverID;
|
||||
String receiverName;
|
||||
String senderID;
|
||||
String senderName;
|
||||
String messageType;
|
||||
String messageID;
|
||||
|
||||
Message(
|
||||
{this.id,
|
||||
this.message,
|
||||
this.date,
|
||||
this.receiverID,
|
||||
this.receiverName,
|
||||
this.senderID,
|
||||
this.senderName,
|
||||
this.messageType,
|
||||
this.messageID});
|
||||
bool fromToday() {
|
||||
var now = DateTime.now();
|
||||
return date.day == now.day &&
|
||||
date.month == now.month &&
|
||||
date.year == now.year;
|
||||
}
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
return {
|
||||
'message': message,
|
||||
"receiver_id": receiverID,
|
||||
};
|
||||
}
|
||||
|
||||
bool sameDay(Message another) {
|
||||
return date.year == another.date.year &&
|
||||
date.month == another.date.month &&
|
||||
date.day == another.date.day;
|
||||
}
|
||||
|
||||
factory Message.fromMap(Map<String, dynamic> map, String id) {
|
||||
var date = (map['date'] as Timestamp);
|
||||
return Message(
|
||||
id: id,
|
||||
message: map['message'],
|
||||
senderID: map['sender_id'],
|
||||
senderName: map['sender_name'],
|
||||
receiverID: map['receiver_id'],
|
||||
receiverName: map['receiver_name'],
|
||||
messageType: map['msg_type'],
|
||||
messageID: map['msg_id'],
|
||||
date: date != null ? date.toDate() : null,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user