feat: synchronisation mode deconnecte fin chat et stats

This commit is contained in:
2025-08-31 18:21:20 +02:00
parent 41a4505b4b
commit 604294af96
149 changed files with 285769 additions and 250633 deletions

View File

@@ -29,6 +29,15 @@ class Message extends HiveObject {
@HiveField(7)
final bool isRead;
@HiveField(8)
final String? senderFirstName;
@HiveField(9)
final int? readCount;
@HiveField(10)
final bool isSynced;
Message({
required this.id,
required this.roomId,
@@ -38,19 +47,25 @@ class Message extends HiveObject {
required this.sentAt,
this.isMe = false,
this.isRead = false,
this.senderFirstName,
this.readCount,
this.isSynced = true,
});
// Simple factory depuis JSON
factory Message.fromJson(Map<String, dynamic> json, int currentUserId) {
factory Message.fromJson(Map<String, dynamic> json, int currentUserId, {String? roomId}) {
return Message(
id: json['id'],
roomId: json['fk_room'],
id: json['id'] ?? '',
roomId: roomId ?? json['room_id'] ?? json['fk_room'] ?? '',
content: json['content'] ?? '',
senderId: json['fk_user'] ?? 0,
senderId: json['sender_id'] ?? json['fk_user'] ?? 0,
senderName: json['sender_name'] ?? 'Anonyme',
sentAt: DateTime.parse(json['date_sent']),
isMe: json['fk_user'] == currentUserId,
isRead: json['statut'] == 'lu',
sentAt: DateTime.parse(json['sent_at'] ?? json['date_sent']),
isMe: json['is_mine'] ?? (json['sender_id'] == currentUserId || json['fk_user'] == currentUserId),
isRead: json['is_read'] ?? json['statut'] == 'lu' ?? false,
senderFirstName: json['sender_first_name'],
readCount: json['read_count'],
isSynced: json['is_synced'] ?? true,
);
}
@@ -60,4 +75,33 @@ class Message extends HiveObject {
'content': content,
'fk_user': senderId,
};
// Méthode copyWith pour faciliter les mises à jour
Message copyWith({
String? id,
String? roomId,
String? content,
int? senderId,
String? senderName,
DateTime? sentAt,
bool? isMe,
bool? isRead,
String? senderFirstName,
int? readCount,
bool? isSynced,
}) {
return Message(
id: id ?? this.id,
roomId: roomId ?? this.roomId,
content: content ?? this.content,
senderId: senderId ?? this.senderId,
senderName: senderName ?? this.senderName,
sentAt: sentAt ?? this.sentAt,
isMe: isMe ?? this.isMe,
isRead: isRead ?? this.isRead,
senderFirstName: senderFirstName ?? this.senderFirstName,
readCount: readCount ?? this.readCount,
isSynced: isSynced ?? this.isSynced,
);
}
}