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,143 +1,141 @@
|
||||
/// Page liste des conversations
|
||||
/// Page liste des conversations v4
|
||||
library conversations_page;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import '../../../../core/di/injection_container.dart';
|
||||
|
||||
import '../../../../shared/design_system/unionflow_design_system.dart';
|
||||
import '../../../../shared/utils/snackbar_helper.dart';
|
||||
import '../../domain/entities/conversation.dart';
|
||||
import '../bloc/messaging_bloc.dart';
|
||||
import '../bloc/messaging_event.dart';
|
||||
import '../bloc/messaging_state.dart';
|
||||
import '../widgets/conversation_tile.dart';
|
||||
import 'conversation_detail_page.dart';
|
||||
|
||||
class ConversationsPage extends StatelessWidget {
|
||||
final String? organizationId;
|
||||
|
||||
const ConversationsPage({
|
||||
super.key,
|
||||
this.organizationId,
|
||||
});
|
||||
const ConversationsPage({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider(
|
||||
create: (_) => sl<MessagingBloc>()
|
||||
..add(LoadConversations(organizationId: organizationId)),
|
||||
child: Scaffold(
|
||||
backgroundColor: ColorTokens.background,
|
||||
appBar: const UFAppBar(
|
||||
title: 'MESSAGES',
|
||||
automaticallyImplyLeading: true,
|
||||
),
|
||||
body: BlocBuilder<MessagingBloc, MessagingState>(
|
||||
builder: (context, state) {
|
||||
if (state is MessagingLoading) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
|
||||
if (state is MessagingError) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Icon(
|
||||
Icons.error_outline,
|
||||
size: 64,
|
||||
color: AppColors.error,
|
||||
),
|
||||
const SizedBox(height: SpacingTokens.md),
|
||||
Text(
|
||||
'Erreur',
|
||||
style: AppTypography.headerSmall,
|
||||
),
|
||||
const SizedBox(height: SpacingTokens.sm),
|
||||
Text(
|
||||
state.message,
|
||||
style: AppTypography.bodyTextSmall,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: SpacingTokens.lg),
|
||||
UFPrimaryButton(
|
||||
label: 'Réessayer',
|
||||
onPressed: () {
|
||||
context.read<MessagingBloc>().add(
|
||||
LoadConversations(organizationId: organizationId),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
return Scaffold(
|
||||
backgroundColor: scheme.surface,
|
||||
appBar: UFAppBar(
|
||||
title: 'Messages',
|
||||
moduleGradient: ModuleColors.communicationGradient,
|
||||
automaticallyImplyLeading: true,
|
||||
),
|
||||
body: BlocConsumer<MessagingBloc, MessagingState>(
|
||||
listener: (context, state) {
|
||||
if (state is MessagingError) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(state.message),
|
||||
backgroundColor: ColorTokens.error,
|
||||
),
|
||||
);
|
||||
}
|
||||
if (state is ConversationCreee) {
|
||||
_openDetail(context, state.conversation.id);
|
||||
}
|
||||
},
|
||||
builder: (context, state) {
|
||||
if (state is MessagingLoading) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
|
||||
if (state is MesConversationsLoaded) {
|
||||
return _buildList(context, state.conversations);
|
||||
}
|
||||
|
||||
// État initial ou erreur non fatale — afficher liste vide
|
||||
return _buildEmpty(context);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildList(BuildContext context, List<ConversationSummary> conversations) {
|
||||
if (conversations.isEmpty) {
|
||||
return _buildEmpty(context);
|
||||
}
|
||||
|
||||
// Tri : non lus d'abord, puis par date de dernier message
|
||||
final sorted = List.of(conversations)
|
||||
..sort((a, b) {
|
||||
if (a.hasUnread && !b.hasUnread) return -1;
|
||||
if (!a.hasUnread && b.hasUnread) return 1;
|
||||
final aDate = a.dernierMessageAt;
|
||||
final bDate = b.dernierMessageAt;
|
||||
if (aDate == null && bDate == null) return 0;
|
||||
if (aDate == null) return 1;
|
||||
if (bDate == null) return -1;
|
||||
return bDate.compareTo(aDate);
|
||||
});
|
||||
|
||||
return RefreshIndicator(
|
||||
color: ModuleColors.communication,
|
||||
onRefresh: () async {
|
||||
context.read<MessagingBloc>().add(const LoadMesConversations());
|
||||
},
|
||||
child: ListView.separated(
|
||||
padding: const EdgeInsets.all(SpacingTokens.md),
|
||||
itemCount: sorted.length,
|
||||
separatorBuilder: (_, __) => const SizedBox(height: SpacingTokens.sm),
|
||||
itemBuilder: (context, index) {
|
||||
final conv = sorted[index];
|
||||
return ConversationTile(
|
||||
conversation: conv,
|
||||
onTap: () => _openDetail(context, conv.id),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildEmpty(BuildContext context) {
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
return RefreshIndicator(
|
||||
color: ModuleColors.communication,
|
||||
onRefresh: () async {
|
||||
context.read<MessagingBloc>().add(const LoadMesConversations());
|
||||
},
|
||||
child: SingleChildScrollView(
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
child: SizedBox(
|
||||
height: MediaQuery.of(context).size.height * 0.6,
|
||||
child: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.chat_bubble_outline,
|
||||
size: 64,
|
||||
color: scheme.onSurfaceVariant.withOpacity(0.4),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (state is ConversationsLoaded) {
|
||||
final conversations = state.conversations;
|
||||
|
||||
if (conversations.isEmpty) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Icon(
|
||||
Icons.chat_bubble_outline,
|
||||
size: 64,
|
||||
color: AppColors.textSecondaryLight,
|
||||
),
|
||||
const SizedBox(height: SpacingTokens.md),
|
||||
Text(
|
||||
'Aucune conversation',
|
||||
style: AppTypography.headerSmall.copyWith(
|
||||
color: AppColors.textSecondaryLight,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: SpacingTokens.sm),
|
||||
Text(
|
||||
'Commencez une nouvelle conversation',
|
||||
style: AppTypography.bodyTextSmall.copyWith(
|
||||
color: AppColors.textSecondaryLight,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return RefreshIndicator(
|
||||
onRefresh: () async {
|
||||
context.read<MessagingBloc>().add(
|
||||
LoadConversations(organizationId: organizationId),
|
||||
);
|
||||
},
|
||||
child: ListView.separated(
|
||||
padding: const EdgeInsets.all(SpacingTokens.md),
|
||||
itemCount: conversations.length,
|
||||
separatorBuilder: (_, __) => const SizedBox(height: SpacingTokens.sm),
|
||||
itemBuilder: (context, index) {
|
||||
final conversation = conversations[index];
|
||||
return ConversationTile(
|
||||
conversation: conversation,
|
||||
onTap: () {
|
||||
SnackbarHelper.showNotImplemented(
|
||||
context,
|
||||
'Affichage des messages',
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
const SizedBox(height: SpacingTokens.md),
|
||||
Text('Aucune conversation', style: AppTypography.headerSmall),
|
||||
const SizedBox(height: SpacingTokens.sm),
|
||||
Text(
|
||||
'Contactez un membre ou le bureau\nde votre organisation',
|
||||
style: AppTypography.bodyTextSmall,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return const SizedBox.shrink();
|
||||
},
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
backgroundColor: AppColors.primaryGreen,
|
||||
onPressed: () {
|
||||
SnackbarHelper.showNotImplemented(context, 'Nouvelle conversation');
|
||||
},
|
||||
child: const Icon(Icons.add, color: Colors.white),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _openDetail(BuildContext context, String conversationId) {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (_) => BlocProvider.value(
|
||||
value: context.read<MessagingBloc>(),
|
||||
child: ConversationDetailPage(conversationId: conversationId),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user