2024-04-30 19:25:16 +02:00
|
|
|
import 'package:cloud_firestore/cloud_firestore.dart';
|
2024-06-03 16:35:33 +02:00
|
|
|
import '../constants.dart';
|
2024-04-30 19:25:16 +02:00
|
|
|
|
|
|
|
class Message {
|
|
|
|
final String senderID;
|
|
|
|
final String senderEmail;
|
|
|
|
final String receiverID;
|
|
|
|
final String message;
|
|
|
|
final Timestamp timestamp;
|
|
|
|
|
|
|
|
Message({
|
|
|
|
required this.senderID,
|
|
|
|
required this.senderEmail,
|
|
|
|
required this.receiverID,
|
|
|
|
required this.message,
|
|
|
|
required this.timestamp,
|
|
|
|
});
|
|
|
|
|
|
|
|
// convert to a map
|
|
|
|
Map<String, dynamic> toMap() {
|
|
|
|
return {
|
2024-06-03 16:35:33 +02:00
|
|
|
Constants.dbFieldMessageSenderId: senderID,
|
|
|
|
Constants.dbFieldMessageSenderEmail: senderEmail,
|
|
|
|
Constants.dbFieldMessageReceiverId: receiverID,
|
|
|
|
Constants.dbFieldMessageText: message,
|
|
|
|
Constants.dbFieldMessageTimestamp: timestamp,
|
2024-04-30 19:25:16 +02:00
|
|
|
};
|
|
|
|
}
|
2024-06-03 16:35:33 +02:00
|
|
|
|
|
|
|
// create Message from map
|
|
|
|
factory Message.fromMap(Map<String, dynamic> map) {
|
|
|
|
return Message(
|
|
|
|
senderID: map[Constants.dbFieldMessageSenderId],
|
|
|
|
senderEmail: map[Constants.dbFieldMessageSenderEmail],
|
|
|
|
receiverID: map[Constants.dbFieldMessageReceiverId],
|
|
|
|
message: map[Constants.dbFieldMessageText],
|
|
|
|
timestamp: map[Constants.dbFieldMessageTimestamp],
|
|
|
|
);
|
|
|
|
}
|
2024-04-30 19:25:16 +02:00
|
|
|
}
|