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:
@@ -1,23 +1,153 @@
|
||||
class SocialPost {
|
||||
final String userName;
|
||||
final String userImage;
|
||||
final String postText;
|
||||
final String postImage;
|
||||
final int likes;
|
||||
final int comments;
|
||||
final int shares;
|
||||
final List<String> badges; // Gamification badges
|
||||
final List<String> tags; // Ajout de tags pour personnalisation des posts
|
||||
import '../../domain/entities/social_post.dart';
|
||||
|
||||
SocialPost({
|
||||
required this.userName,
|
||||
required this.userImage,
|
||||
required this.postText,
|
||||
required this.postImage,
|
||||
required this.likes,
|
||||
required this.comments,
|
||||
required this.shares,
|
||||
required this.badges,
|
||||
this.tags = const [],
|
||||
/// Modèle de données pour les posts sociaux (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 SocialPost.
|
||||
class SocialPostModel {
|
||||
SocialPostModel({
|
||||
required this.id,
|
||||
required this.content,
|
||||
required this.userId,
|
||||
required this.userFirstName,
|
||||
required this.userLastName,
|
||||
required this.userProfileImageUrl,
|
||||
required this.timestamp,
|
||||
this.imageUrl,
|
||||
this.likesCount = 0,
|
||||
this.commentsCount = 0,
|
||||
this.sharesCount = 0,
|
||||
this.isLikedByCurrentUser = false,
|
||||
});
|
||||
|
||||
/// Factory pour créer un [SocialPostModel] à partir d'un JSON.
|
||||
factory SocialPostModel.fromJson(Map<String, dynamic> json) {
|
||||
return SocialPostModel(
|
||||
id: _parseId(json, 'id', ''),
|
||||
content: _parseString(json, 'content', ''),
|
||||
userId: _parseId(json, 'userId', ''),
|
||||
userFirstName: _parseString(json, 'userFirstName', ''),
|
||||
userLastName: _parseString(json, 'userLastName', ''),
|
||||
userProfileImageUrl: _parseString(json, 'userProfileImageUrl', ''),
|
||||
timestamp: _parseTimestamp(json['timestamp']),
|
||||
imageUrl: json['imageUrl'] as String?,
|
||||
likesCount: _parseInt(json, 'likesCount'),
|
||||
commentsCount: _parseInt(json, 'commentsCount'),
|
||||
sharesCount: _parseInt(json, 'sharesCount'),
|
||||
isLikedByCurrentUser: json['isLikedByCurrentUser'] as bool? ?? false,
|
||||
);
|
||||
}
|
||||
|
||||
/// Crée un [SocialPostModel] depuis une entité de domaine [SocialPost].
|
||||
factory SocialPostModel.fromEntity(SocialPost post) {
|
||||
return SocialPostModel(
|
||||
id: post.id,
|
||||
content: post.content,
|
||||
userId: post.userId,
|
||||
userFirstName: post.userFirstName,
|
||||
userLastName: post.userLastName,
|
||||
userProfileImageUrl: post.userProfileImageUrl,
|
||||
timestamp: post.timestamp,
|
||||
imageUrl: post.imageUrl,
|
||||
likesCount: post.likesCount,
|
||||
commentsCount: post.commentsCount,
|
||||
sharesCount: post.sharesCount,
|
||||
isLikedByCurrentUser: post.isLikedByCurrentUser,
|
||||
);
|
||||
}
|
||||
|
||||
final String id;
|
||||
final String content;
|
||||
final String userId;
|
||||
final String userFirstName;
|
||||
final String userLastName;
|
||||
final String userProfileImageUrl;
|
||||
final DateTime timestamp;
|
||||
final String? imageUrl;
|
||||
final int likesCount;
|
||||
final int commentsCount;
|
||||
final int sharesCount;
|
||||
final bool isLikedByCurrentUser;
|
||||
|
||||
/// Convertit ce modèle en JSON pour l'envoi vers l'API.
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'id': id,
|
||||
'content': content,
|
||||
'userId': userId,
|
||||
'userFirstName': userFirstName,
|
||||
'userLastName': userLastName,
|
||||
'userProfileImageUrl': userProfileImageUrl,
|
||||
'timestamp': timestamp.toIso8601String(),
|
||||
if (imageUrl != null) 'imageUrl': imageUrl,
|
||||
'likesCount': likesCount,
|
||||
'commentsCount': commentsCount,
|
||||
'sharesCount': sharesCount,
|
||||
'isLikedByCurrentUser': isLikedByCurrentUser,
|
||||
};
|
||||
}
|
||||
|
||||
/// Convertit ce modèle vers une entité de domaine [SocialPost].
|
||||
SocialPost toEntity() {
|
||||
return SocialPost(
|
||||
id: id,
|
||||
content: content,
|
||||
userId: userId,
|
||||
userFirstName: userFirstName,
|
||||
userLastName: userLastName,
|
||||
userProfileImageUrl: userProfileImageUrl,
|
||||
timestamp: timestamp,
|
||||
imageUrl: imageUrl,
|
||||
likesCount: likesCount,
|
||||
commentsCount: commentsCount,
|
||||
sharesCount: sharesCount,
|
||||
isLikedByCurrentUser: isLikedByCurrentUser,
|
||||
);
|
||||
}
|
||||
|
||||
/// 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 une valeur int depuis le JSON avec valeur par défaut 0.
|
||||
static int _parseInt(Map<String, dynamic> json, String key) {
|
||||
return json[key] as int? ?? 0;
|
||||
}
|
||||
|
||||
/// 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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user