cofounderella/lib/models/message.dart

41 lines
1.1 KiB
Dart
Raw Permalink Normal View History

import 'package:cloud_firestore/cloud_firestore.dart';
2024-06-03 16:35:33 +02:00
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 {
2024-06-03 16:35:33 +02:00
Constants.dbFieldMessageSenderId: senderID,
Constants.dbFieldMessageSenderEmail: senderEmail,
Constants.dbFieldMessageReceiverId: receiverID,
Constants.dbFieldMessageText: message,
Constants.dbFieldMessageTimestamp: timestamp,
};
}
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],
);
}
}