Files
TravelMate/lib/models/message.dart
Dayron 4edbd1cf34 feat: Add User and UserBalance models with serialization methods
feat: Implement BalanceRepository for group balance calculations

feat: Create ExpenseRepository for managing expenses

feat: Add services for handling expenses and storage operations

fix: Update import paths for models in repositories and services

refactor: Rename CountContent to AccountContent in HomePage

chore: Add StorageService for image upload and management
2025-10-21 16:02:58 +02:00

81 lines
2.3 KiB
Dart

import 'package:cloud_firestore/cloud_firestore.dart';
class Message {
final String id;
final String text;
final DateTime timestamp;
final String senderId;
final String senderName;
final String groupId;
final Map<String, String> reactions; // userId -> emoji
final DateTime? editedAt;
final bool isEdited;
Message({
this.id = '',
required this.text,
required this.timestamp,
required this.senderId,
required this.senderName,
required this.groupId,
this.reactions = const {},
this.editedAt,
this.isEdited = false,
});
factory Message.fromFirestore(DocumentSnapshot doc) {
final data = doc.data() as Map<String, dynamic>;
final timestamp = data['timestamp'] as Timestamp?;
final editedAtTimestamp = data['editedAt'] as Timestamp?;
final reactionsData = data['reactions'] as Map<String, dynamic>?;
return Message(
id: doc.id,
text: data['text'] ?? '',
timestamp: timestamp?.toDate() ?? DateTime.now(),
senderId: data['senderId'] ?? '',
senderName: data['senderName'] ?? 'Anonyme',
groupId: data['groupId'] ?? '',
reactions: reactionsData?.map((key, value) => MapEntry(key, value.toString())) ?? {},
editedAt: editedAtTimestamp?.toDate(),
isEdited: data['isEdited'] ?? false,
);
}
Map<String, dynamic> toFirestore() {
return {
'text': text,
'senderId': senderId,
'senderName': senderName,
'timestamp': Timestamp.fromDate(timestamp),
'groupId': groupId,
'reactions': reactions,
'editedAt': editedAt != null ? Timestamp.fromDate(editedAt!) : null,
'isEdited': isEdited,
};
}
Message copyWith({
String? id,
String? text,
DateTime? timestamp,
String? senderId,
String? senderName,
String? groupId,
Map<String, String>? reactions,
DateTime? editedAt,
bool? isEdited,
}) {
return Message(
id: id ?? this.id,
text: text ?? this.text,
timestamp: timestamp ?? this.timestamp,
senderId: senderId ?? this.senderId,
senderName: senderName ?? this.senderName,
groupId: groupId ?? this.groupId,
reactions: reactions ?? this.reactions,
editedAt: editedAt ?? this.editedAt,
isEdited: isEdited ?? this.isEdited,
);
}
}