cofounderella/lib/models/message.dart

41 lines
1.1 KiB
Dart

import 'package:cloud_firestore/cloud_firestore.dart';
import '../constants.dart';
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 {
Constants.dbFieldMessageSenderId: senderID,
Constants.dbFieldMessageSenderEmail: senderEmail,
Constants.dbFieldMessageReceiverId: receiverID,
Constants.dbFieldMessageText: message,
Constants.dbFieldMessageTimestamp: timestamp,
};
}
// 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],
);
}
}