@@ -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' ;
@@ -26,8 +27,7 @@ class _ConversationsScreenState extends State<ConversationsScreen> {
2627 nodeService.stream.listen ((event) {
2728 if (! mounted) return ;
2829 if (event['event_type' ] == 'session' ) {
29- setState (() {
30- });
30+ setState (() {});
3131 }
3232 });
3333 });
@@ -52,14 +52,22 @@ class _ConversationsScreenState extends State<ConversationsScreen> {
5252 children: [
5353 _buildHeader (),
5454 Expanded (
55- child: FutureBuilder <List <ChatView >>(
56- future: chatService.getChats (),
55+ child: FutureBuilder (
56+ future: Future .wait ([
57+ chatService.getChats (),
58+ SessionService ()
59+ .getPendingSessionsCount (), // 🧠 nouvelle méthode simple
60+ ]),
5761 builder: (context, snapshot) {
58- if (snapshot.connectionState == ConnectionState .waiting) {
62+ if (snapshot.connectionState ==
63+ ConnectionState .waiting) {
5964 return const Center (
60- child: CircularProgressIndicator (color: Colors .greenAccent),
65+ child: CircularProgressIndicator (
66+ color: Colors .greenAccent,
67+ ),
6168 );
6269 }
70+
6371 if (snapshot.hasError) {
6472 return Center (
6573 child: Text (
@@ -68,13 +76,35 @@ class _ConversationsScreenState extends State<ConversationsScreen> {
6876 ),
6977 );
7078 }
71- _chats = snapshot.data ?? [];
72- if (_chats.isEmpty) {
79+
80+ List <ChatView > chats = snapshot.data? [0 ] as List <ChatView >? ?? [];
81+ int pendingCount = snapshot.data? [1 ] as int ? ?? 0 ;
82+
83+ if (chats.isEmpty && pendingCount == 0 ) {
7384 return const Center (
74- child: Text ("No conversations yet" , style: TextStyle (color: Colors .grey)),
85+ child: Text (
86+ "No conversations yet" ,
87+ style: TextStyle (color: Colors .grey),
88+ ),
7589 );
7690 }
77- return _buildConversationList (_chats);
91+
92+ return Column (
93+ children: [
94+ if (pendingCount > 0 )
95+ Padding (
96+ padding: const EdgeInsets .symmetric (
97+ horizontal: 12 ,
98+ vertical: 6 ,
99+ ),
100+ child: _buildPendingButton (
101+ context,
102+ pendingCount,
103+ ),
104+ ),
105+ Expanded (child: _buildConversationList (chats)),
106+ ],
107+ );
78108 },
79109 ),
80110 ),
@@ -123,15 +153,14 @@ class _ConversationsScreenState extends State<ConversationsScreen> {
123153 const Spacer (),
124154 IconButton (
125155 onPressed: () {
126- Navigator .of (context). push ( MaterialPageRoute (
127- builder : (_) => const UserListScreen () ,
128- ));
156+ Navigator .of (
157+ context ,
158+ ). push ( MaterialPageRoute (builder : (_) => const UserListScreen ()) );
129159 },
130160 icon: const Icon (Icons .add, color: Colors .white),
131161 ),
132162 IconButton (
133163 onPressed: () {
134- SessionService ().processPendingSessions ();
135164 },
136165 icon: const Icon (Icons .settings, color: Colors .white),
137166 ),
@@ -151,6 +180,38 @@ class _ConversationsScreenState extends State<ConversationsScreen> {
151180 );
152181 }
153182
183+ Widget _buildPendingButton (BuildContext context, int count) {
184+ return GestureDetector (
185+ onTap: () {
186+ Navigator .of (context).push (
187+ MaterialPageRoute (builder: (_) => const PendingSessionsScreen ()),
188+ );
189+ },
190+ child: Container (
191+ padding: const EdgeInsets .symmetric (vertical: 10 , horizontal: 14 ),
192+ decoration: BoxDecoration (
193+ color: const Color (0xFF222222 ),
194+ borderRadius: BorderRadius .circular (10 ),
195+ border: Border .all (color: Colors .greenAccent.withOpacity (0.3 )),
196+ ),
197+ child: Row (
198+ mainAxisAlignment: MainAxisAlignment .center,
199+ children: [
200+ const Icon (Icons .key, color: Colors .greenAccent, size: 20 ),
201+ const SizedBox (width: 8 ),
202+ Text (
203+ "Pending sessions ($count )" ,
204+ style: const TextStyle (
205+ color: Colors .white,
206+ fontWeight: FontWeight .w500,
207+ ),
208+ ),
209+ ],
210+ ),
211+ ),
212+ );
213+ }
214+
154215 Widget _buildConversationList (List <ChatView > chats) {
155216 return ListView .builder (
156217 itemCount: chats.length,
@@ -197,10 +258,13 @@ class _ConversationsScreenState extends State<ConversationsScreen> {
197258 child: Column (
198259 crossAxisAlignment: CrossAxisAlignment .start,
199260 children: [
200- Text (chat.displayName,
201- style: const TextStyle (
202- color: Colors .white,
203- fontWeight: FontWeight .w600)),
261+ Text (
262+ chat.displayName,
263+ style: const TextStyle (
264+ color: Colors .white,
265+ fontWeight: FontWeight .w600,
266+ ),
267+ ),
204268 const SizedBox (height: 4 ),
205269 Text (
206270 chat.previewText,
0 commit comments