feat(communication): module messagerie unifié + contact policies + blocages
Aligné avec le backend MessagingResource : - Nouveau module communication (conversations, messages, participants) - Respect des ContactPolicy (qui peut parler à qui par rôle) - Gestion MemberBlock (blocages individuels) - UI : conversations list, conversation detail, broadcast, tiles - BLoC : MessagingBloc avec events (envoyer, démarrer conversation rôle, etc.)
This commit is contained in:
@@ -1,70 +1,110 @@
|
||||
/// Model de données Conversation avec sérialisation JSON
|
||||
/// Modèles de données Conversation v4 avec désérialisation JSON
|
||||
library conversation_model;
|
||||
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import '../../domain/entities/conversation.dart';
|
||||
import '../../domain/entities/message.dart';
|
||||
import 'message_model.dart';
|
||||
|
||||
part 'conversation_model.g.dart';
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class ConversationModel extends Conversation {
|
||||
@JsonKey(
|
||||
fromJson: _messageFromJson,
|
||||
toJson: _messageToJson,
|
||||
)
|
||||
@override
|
||||
final Message? lastMessage;
|
||||
|
||||
const ConversationModel({
|
||||
/// Modèle de résumé de conversation (liste)
|
||||
class ConversationSummaryModel extends ConversationSummary {
|
||||
const ConversationSummaryModel({
|
||||
required super.id,
|
||||
required super.name,
|
||||
super.description,
|
||||
required super.type,
|
||||
required super.participantIds,
|
||||
super.organizationId,
|
||||
this.lastMessage,
|
||||
super.unreadCount,
|
||||
super.isMuted,
|
||||
super.isPinned,
|
||||
super.isArchived,
|
||||
required super.createdAt,
|
||||
super.updatedAt,
|
||||
super.avatarUrl,
|
||||
super.metadata,
|
||||
}) : super(lastMessage: lastMessage);
|
||||
required super.typeConversation,
|
||||
required super.titre,
|
||||
required super.statut,
|
||||
super.dernierMessageApercu,
|
||||
super.dernierMessageType,
|
||||
super.dernierMessageAt,
|
||||
super.nonLus,
|
||||
super.organisationId,
|
||||
});
|
||||
|
||||
static Message? _messageFromJson(Map<String, dynamic>? json) =>
|
||||
json == null ? null : MessageModel.fromJson(json);
|
||||
|
||||
static Map<String, dynamic>? _messageToJson(Message? message) =>
|
||||
message == null ? null : MessageModel.fromEntity(message).toJson();
|
||||
|
||||
factory ConversationModel.fromJson(Map<String, dynamic> json) =>
|
||||
_$ConversationModelFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$ConversationModelToJson(this);
|
||||
|
||||
factory ConversationModel.fromEntity(Conversation conversation) {
|
||||
return ConversationModel(
|
||||
id: conversation.id,
|
||||
name: conversation.name,
|
||||
description: conversation.description,
|
||||
type: conversation.type,
|
||||
participantIds: conversation.participantIds,
|
||||
organizationId: conversation.organizationId,
|
||||
lastMessage: conversation.lastMessage,
|
||||
unreadCount: conversation.unreadCount,
|
||||
isMuted: conversation.isMuted,
|
||||
isPinned: conversation.isPinned,
|
||||
isArchived: conversation.isArchived,
|
||||
createdAt: conversation.createdAt,
|
||||
updatedAt: conversation.updatedAt,
|
||||
avatarUrl: conversation.avatarUrl,
|
||||
metadata: conversation.metadata,
|
||||
factory ConversationSummaryModel.fromJson(Map<String, dynamic> json) {
|
||||
return ConversationSummaryModel(
|
||||
id: json['id']?.toString() ?? '',
|
||||
typeConversation: json['typeConversation']?.toString() ?? 'DIRECTE',
|
||||
titre: json['titre']?.toString() ?? '',
|
||||
statut: json['statut']?.toString() ?? 'ACTIVE',
|
||||
dernierMessageApercu: json['dernierMessageApercu']?.toString(),
|
||||
dernierMessageType: json['dernierMessageType']?.toString(),
|
||||
dernierMessageAt: json['dernierMessageAt'] != null
|
||||
? DateTime.tryParse(json['dernierMessageAt'].toString())
|
||||
: null,
|
||||
nonLus: _parseInt(json['nonLus']),
|
||||
organisationId: json['organisationId']?.toString(),
|
||||
);
|
||||
}
|
||||
|
||||
Conversation toEntity() => this;
|
||||
}
|
||||
|
||||
/// Modèle de participant
|
||||
class ConversationParticipantModel extends ConversationParticipant {
|
||||
const ConversationParticipantModel({
|
||||
required super.membreId,
|
||||
super.prenom,
|
||||
super.nom,
|
||||
super.roleDansConversation,
|
||||
super.luJusqua,
|
||||
});
|
||||
|
||||
factory ConversationParticipantModel.fromJson(Map<String, dynamic> json) {
|
||||
return ConversationParticipantModel(
|
||||
membreId: json['membreId']?.toString() ?? '',
|
||||
prenom: json['prenom']?.toString(),
|
||||
nom: json['nom']?.toString(),
|
||||
roleDansConversation: json['roleDansConversation']?.toString(),
|
||||
luJusqua: json['luJusqua'] != null
|
||||
? DateTime.tryParse(json['luJusqua'].toString())
|
||||
: null,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Modèle de conversation complète (détail)
|
||||
class ConversationModel extends Conversation {
|
||||
const ConversationModel({
|
||||
required super.id,
|
||||
required super.typeConversation,
|
||||
required super.titre,
|
||||
required super.statut,
|
||||
super.organisationId,
|
||||
super.organisationNom,
|
||||
super.dateCreation,
|
||||
super.nombreMessages,
|
||||
super.participants,
|
||||
super.messages,
|
||||
super.nonLus,
|
||||
super.roleCible,
|
||||
});
|
||||
|
||||
factory ConversationModel.fromJson(Map<String, dynamic> json) {
|
||||
final participantsJson = json['participants'] as List<dynamic>? ?? [];
|
||||
final messagesJson = json['messages'] as List<dynamic>? ?? [];
|
||||
|
||||
return ConversationModel(
|
||||
id: json['id']?.toString() ?? '',
|
||||
typeConversation: json['typeConversation']?.toString() ?? 'DIRECTE',
|
||||
titre: json['titre']?.toString() ?? '',
|
||||
statut: json['statut']?.toString() ?? 'ACTIVE',
|
||||
organisationId: json['organisationId']?.toString(),
|
||||
organisationNom: json['organisationNom']?.toString(),
|
||||
dateCreation: json['dateCreation'] != null
|
||||
? DateTime.tryParse(json['dateCreation'].toString())
|
||||
: null,
|
||||
nombreMessages: _parseInt(json['nombreMessages']),
|
||||
participants: participantsJson
|
||||
.map((p) => ConversationParticipantModel.fromJson(p as Map<String, dynamic>))
|
||||
.toList(),
|
||||
messages: messagesJson
|
||||
.map((m) => MessageModel.fromJson(m as Map<String, dynamic>))
|
||||
.toList(),
|
||||
nonLus: _parseInt(json['nonLus']),
|
||||
roleCible: json['roleCible']?.toString(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
int _parseInt(dynamic value) {
|
||||
if (value == null) return 0;
|
||||
if (value is int) return value;
|
||||
if (value is double) return value.toInt();
|
||||
return int.tryParse(value.toString()) ?? 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user