## 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
129 lines
3.5 KiB
Dart
129 lines
3.5 KiB
Dart
import '../../domain/entities/comment.dart';
|
|
|
|
/// Modèle de données pour les commentaires (Data Transfer Object).
|
|
///
|
|
/// Cette classe est responsable de la sérialisation/désérialisation
|
|
/// avec l'API backend et convertit vers/depuis l'entité de domaine Comment.
|
|
class CommentModel {
|
|
CommentModel({
|
|
required this.id,
|
|
required this.postId,
|
|
required this.userId,
|
|
required this.userFirstName,
|
|
required this.userLastName,
|
|
required this.userProfileImageUrl,
|
|
required this.content,
|
|
required this.timestamp,
|
|
});
|
|
|
|
/// Factory pour créer un [CommentModel] à partir d'un JSON.
|
|
factory CommentModel.fromJson(Map<String, dynamic> json) {
|
|
return CommentModel(
|
|
id: _parseId(json, 'id', ''),
|
|
postId: _parseId(json, 'postId', ''),
|
|
userId: _parseId(json, 'userId', ''),
|
|
userFirstName: _parseString(json, 'userFirstName', ''),
|
|
userLastName: _parseString(json, 'userLastName', ''),
|
|
userProfileImageUrl: _parseString(json, 'userProfileImageUrl', ''),
|
|
content: _parseString(json, 'content', ''),
|
|
timestamp: _parseTimestamp(json['timestamp']),
|
|
);
|
|
}
|
|
|
|
/// Crée un [CommentModel] depuis une entité de domaine [Comment].
|
|
factory CommentModel.fromEntity(Comment comment) {
|
|
return CommentModel(
|
|
id: comment.id,
|
|
postId: comment.postId,
|
|
userId: comment.userId,
|
|
userFirstName: comment.userFirstName,
|
|
userLastName: comment.userLastName,
|
|
userProfileImageUrl: comment.userProfileImageUrl,
|
|
content: comment.content,
|
|
timestamp: comment.timestamp,
|
|
);
|
|
}
|
|
|
|
final String id;
|
|
final String postId;
|
|
final String userId;
|
|
final String userFirstName;
|
|
final String userLastName;
|
|
final String userProfileImageUrl;
|
|
final String content;
|
|
final DateTime timestamp;
|
|
|
|
/// Convertit ce modèle en JSON pour l'envoi vers l'API.
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
'id': id,
|
|
'postId': postId,
|
|
'userId': userId,
|
|
'userFirstName': userFirstName,
|
|
'userLastName': userLastName,
|
|
'userProfileImageUrl': userProfileImageUrl,
|
|
'content': content,
|
|
'timestamp': timestamp.toIso8601String(),
|
|
};
|
|
}
|
|
|
|
/// Convertit ce modèle vers une entité de domaine [Comment].
|
|
Comment toEntity() {
|
|
return Comment(
|
|
id: id,
|
|
postId: postId,
|
|
userId: userId,
|
|
userFirstName: userFirstName,
|
|
userLastName: userLastName,
|
|
userProfileImageUrl: userProfileImageUrl,
|
|
content: content,
|
|
timestamp: timestamp,
|
|
);
|
|
}
|
|
|
|
/// Parse une valeur string depuis le JSON avec valeur par défaut.
|
|
static String _parseString(
|
|
Map<String, dynamic> json,
|
|
String key,
|
|
String defaultValue,
|
|
) {
|
|
return json[key] as String? ?? defaultValue;
|
|
}
|
|
|
|
/// Parse un timestamp depuis le JSON.
|
|
static DateTime _parseTimestamp(dynamic timestamp) {
|
|
if (timestamp == null) return DateTime.now();
|
|
|
|
if (timestamp is String) {
|
|
try {
|
|
return DateTime.parse(timestamp);
|
|
} catch (e) {
|
|
return DateTime.now();
|
|
}
|
|
}
|
|
|
|
if (timestamp is int) {
|
|
return DateTime.fromMillisecondsSinceEpoch(timestamp);
|
|
}
|
|
|
|
return DateTime.now();
|
|
}
|
|
|
|
/// Parse un ID (UUID) depuis le JSON.
|
|
///
|
|
/// [json] Le JSON à parser
|
|
/// [key] La clé de l'ID
|
|
/// [defaultValue] La valeur par défaut si l'ID est null
|
|
///
|
|
/// Returns l'ID parsé ou la valeur par défaut
|
|
static String _parseId(
|
|
Map<String, dynamic> json,
|
|
String key,
|
|
String defaultValue,
|
|
) {
|
|
final value = json[key];
|
|
if (value == null) return defaultValue;
|
|
return value.toString();
|
|
}
|
|
}
|