Files
fcs/lib/domain/vo/message.dart

62 lines
1.4 KiB
Dart
Raw Normal View History

2020-09-20 05:34:49 +06:30
import 'package:cloud_firestore/cloud_firestore.dart';
class Message {
2021-09-10 14:27:38 +06:30
String? id;
String? message;
DateTime? date;
String? receiverID;
String? receiverName;
String? senderID;
String? senderName;
String? messageType;
String? messageID;
2020-09-20 05:34:49 +06:30
Message(
{this.id,
this.message,
this.date,
this.receiverID,
this.receiverName,
this.senderID,
this.senderName,
this.messageType,
this.messageID});
2021-09-10 14:27:38 +06:30
2020-09-20 05:34:49 +06:30
bool fromToday() {
2021-09-10 14:27:38 +06:30
if (date == null) return false;
2020-09-20 05:34:49 +06:30
var now = DateTime.now();
2021-09-10 14:27:38 +06:30
return date!.day == now.day &&
date!.month == now.month &&
date!.year == now.year;
2020-09-20 05:34:49 +06:30
}
Map<String, dynamic> toMap() {
return {
'message': message,
"receiver_id": receiverID,
};
}
bool sameDay(Message another) {
2021-09-10 14:27:38 +06:30
if (date == null) return false;
return date!.year == another.date!.year &&
date!.month == another.date!.month &&
date!.day == another.date!.day;
2020-09-20 05:34:49 +06:30
}
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'],
2021-09-10 14:27:38 +06:30
date: date.toDate(),
2020-09-20 05:34:49 +06:30
);
}
}