fix(chat): Correction race condition + Implémentation TODOs
## Corrections Critiques ### Race Condition - Statuts de Messages - Fix : Les icônes de statut (✓, ✓✓, ✓✓ bleu) ne s'affichaient pas - Cause : WebSocket delivery confirmations arrivaient avant messages locaux - Solution : Pattern Optimistic UI dans chat_bloc.dart - Création message temporaire immédiate - Ajout à la liste AVANT requête HTTP - Remplacement par message serveur à la réponse - Fichier : lib/presentation/state_management/chat_bloc.dart ## Implémentation TODOs (13/21) ### Social (social_header_widget.dart) - ✅ Copier lien du post dans presse-papiers - ✅ Partage natif via Share.share() - ✅ Dialogue de signalement avec 5 raisons ### Partage (share_post_dialog.dart) - ✅ Interface sélection d'amis avec checkboxes - ✅ Partage externe via Share API ### Média (media_upload_service.dart) - ✅ Parsing JSON réponse backend - ✅ Méthode deleteMedia() pour suppression - ✅ Génération miniature vidéo ### Posts (create_post_dialog.dart, edit_post_dialog.dart) - ✅ Extraction URL depuis uploads - ✅ Documentation chargement médias ### Chat (conversations_screen.dart) - ✅ Navigation vers notifications - ✅ ConversationSearchDelegate pour recherche ## Nouveaux Fichiers ### Configuration - build-prod.ps1 : Script build production avec dart-define - lib/core/constants/env_config.dart : Gestion environnements ### Documentation - TODOS_IMPLEMENTED.md : Documentation complète TODOs ## Améliorations ### Architecture - Refactoring injection de dépendances - Amélioration routing et navigation - Optimisation providers (UserProvider, FriendsProvider) ### UI/UX - Amélioration thème et couleurs - Optimisation animations - Meilleure gestion erreurs ### Services - Configuration API avec env_config - Amélioration datasources (events, users) - Optimisation modèles de données
This commit is contained in:
136
lib/data/models/chat_message_model.dart
Normal file
136
lib/data/models/chat_message_model.dart
Normal file
@@ -0,0 +1,136 @@
|
||||
import '../../domain/entities/chat_message.dart';
|
||||
|
||||
/// Modèle de données pour les messages de chat (Data Transfer Object).
|
||||
class ChatMessageModel {
|
||||
ChatMessageModel({
|
||||
required this.id,
|
||||
required this.conversationId,
|
||||
required this.senderId,
|
||||
required this.senderFirstName,
|
||||
required this.senderLastName,
|
||||
this.senderProfileImageUrl,
|
||||
required this.content,
|
||||
required this.timestamp,
|
||||
required this.isRead,
|
||||
this.isDelivered = false,
|
||||
this.attachmentUrl,
|
||||
this.attachmentType,
|
||||
});
|
||||
|
||||
/// Factory pour créer un [ChatMessageModel] à partir d'un JSON.
|
||||
factory ChatMessageModel.fromJson(Map<String, dynamic> json) {
|
||||
return ChatMessageModel(
|
||||
id: _parseId(json, 'id', ''),
|
||||
conversationId: _parseString(json, 'conversationId', ''),
|
||||
senderId: _parseId(json, 'senderId', ''),
|
||||
senderFirstName: _parseString(json, 'senderFirstName', ''),
|
||||
senderLastName: _parseString(json, 'senderLastName', ''),
|
||||
senderProfileImageUrl: json['senderProfileImageUrl'] as String?,
|
||||
content: _parseString(json, 'content', ''),
|
||||
timestamp: DateTime.parse(json['timestamp'] as String),
|
||||
isRead: json['isRead'] as bool? ?? false,
|
||||
isDelivered: json['isDelivered'] as bool? ?? false,
|
||||
attachmentUrl: json['attachmentUrl'] as String?,
|
||||
attachmentType: _parseAttachmentType(json['attachmentType'] as String?),
|
||||
);
|
||||
}
|
||||
|
||||
/// Factory pour créer un [ChatMessageModel] à partir d'une entité.
|
||||
factory ChatMessageModel.fromEntity(ChatMessage message) {
|
||||
return ChatMessageModel(
|
||||
id: message.id,
|
||||
conversationId: message.conversationId,
|
||||
senderId: message.senderId,
|
||||
senderFirstName: message.senderFirstName,
|
||||
senderLastName: message.senderLastName,
|
||||
senderProfileImageUrl: message.senderProfileImageUrl,
|
||||
content: message.content,
|
||||
timestamp: message.timestamp,
|
||||
isRead: message.isRead,
|
||||
isDelivered: message.isDelivered,
|
||||
attachmentUrl: message.attachmentUrl,
|
||||
attachmentType: message.attachmentType,
|
||||
);
|
||||
}
|
||||
|
||||
final String id;
|
||||
final String conversationId;
|
||||
final String senderId;
|
||||
final String senderFirstName;
|
||||
final String senderLastName;
|
||||
final String? senderProfileImageUrl;
|
||||
final String content;
|
||||
final DateTime timestamp;
|
||||
final bool isRead;
|
||||
final bool isDelivered;
|
||||
final String? attachmentUrl;
|
||||
final AttachmentType? attachmentType;
|
||||
|
||||
/// Convertit ce modèle en JSON pour l'envoi vers l'API.
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'id': id,
|
||||
'conversationId': conversationId,
|
||||
'senderId': senderId,
|
||||
'senderFirstName': senderFirstName,
|
||||
'senderLastName': senderLastName,
|
||||
if (senderProfileImageUrl != null) 'senderProfileImageUrl': senderProfileImageUrl,
|
||||
'content': content,
|
||||
'timestamp': timestamp.toIso8601String(),
|
||||
'isRead': isRead,
|
||||
'isDelivered': isDelivered,
|
||||
if (attachmentUrl != null) 'attachmentUrl': attachmentUrl,
|
||||
if (attachmentType != null) 'attachmentType': _attachmentTypeToString(attachmentType!),
|
||||
};
|
||||
}
|
||||
|
||||
/// Convertit ce modèle vers une entité de domaine [ChatMessage].
|
||||
ChatMessage toEntity() {
|
||||
return ChatMessage(
|
||||
id: id,
|
||||
conversationId: conversationId,
|
||||
senderId: senderId,
|
||||
senderFirstName: senderFirstName,
|
||||
senderLastName: senderLastName,
|
||||
senderProfileImageUrl: senderProfileImageUrl,
|
||||
content: content,
|
||||
timestamp: timestamp,
|
||||
isRead: isRead,
|
||||
isDelivered: isDelivered,
|
||||
attachmentUrl: attachmentUrl,
|
||||
attachmentType: attachmentType,
|
||||
);
|
||||
}
|
||||
|
||||
// Méthodes de parsing
|
||||
static String _parseString(Map<String, dynamic> json, String key, String defaultValue) {
|
||||
return json[key] as String? ?? defaultValue;
|
||||
}
|
||||
|
||||
static String _parseId(Map<String, dynamic> json, String key, String defaultValue) {
|
||||
final value = json[key];
|
||||
if (value == null) return defaultValue;
|
||||
return value.toString();
|
||||
}
|
||||
|
||||
static AttachmentType? _parseAttachmentType(String? type) {
|
||||
if (type == null) return null;
|
||||
|
||||
switch (type.toLowerCase()) {
|
||||
case 'image':
|
||||
return AttachmentType.image;
|
||||
case 'video':
|
||||
return AttachmentType.video;
|
||||
case 'audio':
|
||||
return AttachmentType.audio;
|
||||
case 'file':
|
||||
return AttachmentType.file;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
static String _attachmentTypeToString(AttachmentType type) {
|
||||
return type.toString().split('.').last;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user