38 lines
842 B
Dart
38 lines
842 B
Dart
class Message {
|
|
final String id;
|
|
final String fromUser;
|
|
final String toUser;
|
|
final String content;
|
|
final bool isRead;
|
|
final DateTime createdAt;
|
|
|
|
Message({
|
|
required this.id,
|
|
required this.fromUser,
|
|
required this.toUser,
|
|
required this.content,
|
|
required this.isRead,
|
|
required this.createdAt,
|
|
});
|
|
|
|
factory Message.fromMap(Map<String, dynamic> map) {
|
|
return Message(
|
|
id: map['id'] ?? '',
|
|
fromUser: map['from_user'] ?? '',
|
|
toUser: map['to_user'] ?? '',
|
|
content: map['content'] ?? '',
|
|
isRead: map['is_read'] ?? false,
|
|
createdAt: DateTime.tryParse(map['created_at'] ?? '') ?? DateTime.now(),
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toMap() {
|
|
return {
|
|
'from_user': fromUser,
|
|
'to_user': toUser,
|
|
'content': content,
|
|
'is_read': isRead,
|
|
};
|
|
}
|
|
}
|