feat: synchronisation mode deconnecte fin chat et stats
This commit is contained in:
@@ -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,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -25,13 +25,16 @@ class MessageAdapter extends TypeAdapter<Message> {
|
||||
sentAt: fields[5] as DateTime,
|
||||
isMe: fields[6] as bool,
|
||||
isRead: fields[7] as bool,
|
||||
senderFirstName: fields[8] as String?,
|
||||
readCount: fields[9] as int?,
|
||||
isSynced: fields[10] as bool,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void write(BinaryWriter writer, Message obj) {
|
||||
writer
|
||||
..writeByte(8)
|
||||
..writeByte(11)
|
||||
..writeByte(0)
|
||||
..write(obj.id)
|
||||
..writeByte(1)
|
||||
@@ -47,7 +50,13 @@ class MessageAdapter extends TypeAdapter<Message> {
|
||||
..writeByte(6)
|
||||
..write(obj.isMe)
|
||||
..writeByte(7)
|
||||
..write(obj.isRead);
|
||||
..write(obj.isRead)
|
||||
..writeByte(8)
|
||||
..write(obj.senderFirstName)
|
||||
..writeByte(9)
|
||||
..write(obj.readCount)
|
||||
..writeByte(10)
|
||||
..write(obj.isSynced);
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -26,6 +26,18 @@ class Room extends HiveObject {
|
||||
@HiveField(6)
|
||||
final int unreadCount;
|
||||
|
||||
@HiveField(7)
|
||||
final List<Map<String, dynamic>>? recentMessages;
|
||||
|
||||
@HiveField(8)
|
||||
final DateTime? updatedAt;
|
||||
|
||||
@HiveField(9)
|
||||
final int? createdBy;
|
||||
|
||||
@HiveField(10)
|
||||
final bool isSynced;
|
||||
|
||||
Room({
|
||||
required this.id,
|
||||
required this.title,
|
||||
@@ -34,6 +46,10 @@ class Room extends HiveObject {
|
||||
this.lastMessage,
|
||||
this.lastMessageAt,
|
||||
this.unreadCount = 0,
|
||||
this.recentMessages,
|
||||
this.updatedAt,
|
||||
this.createdBy,
|
||||
this.isSynced = true,
|
||||
});
|
||||
|
||||
// Simple factory depuis JSON
|
||||
@@ -42,12 +58,20 @@ class Room extends HiveObject {
|
||||
id: json['id'],
|
||||
title: json['title'] ?? 'Sans titre',
|
||||
type: json['type'] ?? 'private',
|
||||
createdAt: DateTime.parse(json['date_creation']),
|
||||
createdAt: DateTime.parse(json['created_at'] ?? json['date_creation']),
|
||||
lastMessage: json['last_message'],
|
||||
lastMessageAt: json['last_message_at'] != null
|
||||
? DateTime.parse(json['last_message_at'])
|
||||
: null,
|
||||
unreadCount: json['unread_count'] ?? 0,
|
||||
recentMessages: json['recent_messages'] != null
|
||||
? List<Map<String, dynamic>>.from(json['recent_messages'])
|
||||
: null,
|
||||
updatedAt: json['updated_at'] != null
|
||||
? DateTime.parse(json['updated_at'])
|
||||
: null,
|
||||
createdBy: json['created_by'],
|
||||
isSynced: json['is_synced'] ?? true,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -58,4 +82,33 @@ class Room extends HiveObject {
|
||||
'type': type,
|
||||
'date_creation': createdAt.toIso8601String(),
|
||||
};
|
||||
|
||||
// Méthode copyWith pour faciliter les mises à jour
|
||||
Room copyWith({
|
||||
String? id,
|
||||
String? title,
|
||||
String? type,
|
||||
DateTime? createdAt,
|
||||
String? lastMessage,
|
||||
DateTime? lastMessageAt,
|
||||
int? unreadCount,
|
||||
List<Map<String, dynamic>>? recentMessages,
|
||||
DateTime? updatedAt,
|
||||
int? createdBy,
|
||||
bool? isSynced,
|
||||
}) {
|
||||
return Room(
|
||||
id: id ?? this.id,
|
||||
title: title ?? this.title,
|
||||
type: type ?? this.type,
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
lastMessage: lastMessage ?? this.lastMessage,
|
||||
lastMessageAt: lastMessageAt ?? this.lastMessageAt,
|
||||
unreadCount: unreadCount ?? this.unreadCount,
|
||||
recentMessages: recentMessages ?? this.recentMessages,
|
||||
updatedAt: updatedAt ?? this.updatedAt,
|
||||
createdBy: createdBy ?? this.createdBy,
|
||||
isSynced: isSynced ?? this.isSynced,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -24,13 +24,19 @@ class RoomAdapter extends TypeAdapter<Room> {
|
||||
lastMessage: fields[4] as String?,
|
||||
lastMessageAt: fields[5] as DateTime?,
|
||||
unreadCount: fields[6] as int,
|
||||
recentMessages: (fields[7] as List?)
|
||||
?.map((dynamic e) => (e as Map).cast<String, dynamic>())
|
||||
?.toList(),
|
||||
updatedAt: fields[8] as DateTime?,
|
||||
createdBy: fields[9] as int?,
|
||||
isSynced: fields[10] as bool,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void write(BinaryWriter writer, Room obj) {
|
||||
writer
|
||||
..writeByte(7)
|
||||
..writeByte(11)
|
||||
..writeByte(0)
|
||||
..write(obj.id)
|
||||
..writeByte(1)
|
||||
@@ -44,7 +50,15 @@ class RoomAdapter extends TypeAdapter<Room> {
|
||||
..writeByte(5)
|
||||
..write(obj.lastMessageAt)
|
||||
..writeByte(6)
|
||||
..write(obj.unreadCount);
|
||||
..write(obj.unreadCount)
|
||||
..writeByte(7)
|
||||
..write(obj.recentMessages)
|
||||
..writeByte(8)
|
||||
..write(obj.updatedAt)
|
||||
..writeByte(9)
|
||||
..write(obj.createdBy)
|
||||
..writeByte(10)
|
||||
..write(obj.isSynced);
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
Reference in New Issue
Block a user