@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
22import 'package:hushnet_frontend/data/node/sessions/create_session.dart' ;
33import 'package:hushnet_frontend/models/chat_view.dart' ;
44import 'package:hushnet_frontend/screens/chat_view_screen.dart' ;
5+ import 'package:hushnet_frontend/screens/pending_sessions_screen.dart' ;
56import 'package:hushnet_frontend/screens/user_list_screen.dart' ;
67import 'package:hushnet_frontend/services/chat_service.dart' ;
78import 'package:hushnet_frontend/services/node_service.dart' ;
@@ -25,9 +26,9 @@ class _ConversationsScreenState extends State<ConversationsScreen> {
2526 nodeService.connectWebSocket ().then ((_) {
2627 nodeService.stream.listen ((event) {
2728 if (! mounted) return ;
28- if (event['event_type' ] == 'session' ) {
29- setState (( ) {
30- });
29+ if (event['event_type' ] == 'session' ||
30+ event[ 'event_type' ] == 'pending_session' ) {
31+ setState (() { });
3132 }
3233 });
3334 });
@@ -52,14 +53,22 @@ class _ConversationsScreenState extends State<ConversationsScreen> {
5253 children: [
5354 _buildHeader (),
5455 Expanded (
55- child: FutureBuilder <List <ChatView >>(
56- future: chatService.getChats (),
56+ child: FutureBuilder (
57+ future: Future .wait ([
58+ chatService.getChats (),
59+ SessionService ()
60+ .getPendingSessionsCount (), // 🧠 nouvelle méthode simple
61+ ]),
5762 builder: (context, snapshot) {
58- if (snapshot.connectionState == ConnectionState .waiting) {
63+ if (snapshot.connectionState ==
64+ ConnectionState .waiting) {
5965 return const Center (
60- child: CircularProgressIndicator (color: Colors .greenAccent),
66+ child: CircularProgressIndicator (
67+ color: Colors .greenAccent,
68+ ),
6169 );
6270 }
71+
6372 if (snapshot.hasError) {
6473 return Center (
6574 child: Text (
@@ -68,13 +77,37 @@ class _ConversationsScreenState extends State<ConversationsScreen> {
6877 ),
6978 );
7079 }
71- _chats = snapshot.data ?? [];
72- if (_chats.isEmpty) {
80+
81+ List <ChatView > chats =
82+ snapshot.data? [0 ] as List <ChatView >? ?? [];
83+ _chats = List .from (chats);
84+ int pendingCount = snapshot.data? [1 ] as int ? ?? 0 ;
85+
86+ if (chats.isEmpty && pendingCount == 0 ) {
7387 return const Center (
74- child: Text ("No conversations yet" , style: TextStyle (color: Colors .grey)),
88+ child: Text (
89+ "No conversations yet" ,
90+ style: TextStyle (color: Colors .grey),
91+ ),
7592 );
7693 }
77- return _buildConversationList (_chats);
94+
95+ return Column (
96+ children: [
97+ if (pendingCount > 0 )
98+ Padding (
99+ padding: const EdgeInsets .symmetric (
100+ horizontal: 12 ,
101+ vertical: 6 ,
102+ ),
103+ child: _buildPendingButton (
104+ context,
105+ pendingCount,
106+ ),
107+ ),
108+ Expanded (child: _buildConversationList (chats)),
109+ ],
110+ );
78111 },
79112 ),
80113 ),
@@ -123,16 +156,14 @@ class _ConversationsScreenState extends State<ConversationsScreen> {
123156 const Spacer (),
124157 IconButton (
125158 onPressed: () {
126- Navigator .of (context). push ( MaterialPageRoute (
127- builder : (_) => const UserListScreen () ,
128- ));
159+ Navigator .of (
160+ context ,
161+ ). push ( MaterialPageRoute (builder : (_) => const UserListScreen ()) );
129162 },
130163 icon: const Icon (Icons .add, color: Colors .white),
131164 ),
132165 IconButton (
133- onPressed: () {
134- SessionService ().processPendingSessions ();
135- },
166+ onPressed: () {},
136167 icon: const Icon (Icons .settings, color: Colors .white),
137168 ),
138169 IconButton (
@@ -151,6 +182,38 @@ class _ConversationsScreenState extends State<ConversationsScreen> {
151182 );
152183 }
153184
185+ Widget _buildPendingButton (BuildContext context, int count) {
186+ return GestureDetector (
187+ onTap: () {
188+ Navigator .of (context).push (
189+ MaterialPageRoute (builder: (_) => const PendingSessionsScreen ()),
190+ );
191+ },
192+ child: Container (
193+ padding: const EdgeInsets .symmetric (vertical: 10 , horizontal: 14 ),
194+ decoration: BoxDecoration (
195+ color: const Color (0xFF222222 ),
196+ borderRadius: BorderRadius .circular (10 ),
197+ border: Border .all (color: Colors .greenAccent.withOpacity (0.3 )),
198+ ),
199+ child: Row (
200+ mainAxisAlignment: MainAxisAlignment .center,
201+ children: [
202+ const Icon (Icons .key, color: Colors .greenAccent, size: 20 ),
203+ const SizedBox (width: 8 ),
204+ Text (
205+ "Pending sessions ($count )" ,
206+ style: const TextStyle (
207+ color: Colors .white,
208+ fontWeight: FontWeight .w500,
209+ ),
210+ ),
211+ ],
212+ ),
213+ ),
214+ );
215+ }
216+
154217 Widget _buildConversationList (List <ChatView > chats) {
155218 return ListView .builder (
156219 itemCount: chats.length,
@@ -197,10 +260,13 @@ class _ConversationsScreenState extends State<ConversationsScreen> {
197260 child: Column (
198261 crossAxisAlignment: CrossAxisAlignment .start,
199262 children: [
200- Text (chat.displayName,
201- style: const TextStyle (
202- color: Colors .white,
203- fontWeight: FontWeight .w600)),
263+ Text (
264+ chat.displayName,
265+ style: const TextStyle (
266+ color: Colors .white,
267+ fontWeight: FontWeight .w600,
268+ ),
269+ ),
204270 const SizedBox (height: 4 ),
205271 Text (
206272 chat.previewText,
0 commit comments