Skip to content

Commit c4f1875

Browse files
committed
feat: Add PendingSessionsScreen and integrate pending session handling in ConversationsScreen
1 parent 94a7f59 commit c4f1875

7 files changed

Lines changed: 330 additions & 21 deletions

File tree

.fvmrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"flutter": "3.35.7"
3+
}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,6 @@ app.*.map.json
4343
/android/app/debug
4444
/android/app/profile
4545
/android/app/release
46+
47+
# FVM Version Cache
48+
.fvm/

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"dart.flutterSdkPath": ".fvm\\versions\\3.35.7"
3+
}

lib/models/pending_sessions.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'package:hushnet_frontend/models/users.dart';
2+
13
class PendingSession {
24
final String id;
35
final String senderDeviceId;
@@ -6,14 +8,16 @@ class PendingSession {
68
final String ciphertext; // base64
79
final String? senderPrekeyPub; // base64 (nécessaire pour DH1)
810
final String createdAt;
9-
11+
User? senderUser;
12+
1013
PendingSession({
1114
required this.id,
1215
required this.senderDeviceId,
1316
required this.recipientDeviceId,
1417
required this.ephemeralPubkey,
1518
required this.ciphertext,
1619
required this.createdAt,
20+
this.senderUser,
1721
this.senderPrekeyPub,
1822
});
1923

lib/screens/conversations_screen.dart

Lines changed: 82 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
22
import 'package:hushnet_frontend/data/node/sessions/create_session.dart';
33
import 'package:hushnet_frontend/models/chat_view.dart';
44
import 'package:hushnet_frontend/screens/chat_view_screen.dart';
5+
import 'package:hushnet_frontend/screens/pending_sessions_screen.dart';
56
import 'package:hushnet_frontend/screens/user_list_screen.dart';
67
import 'package:hushnet_frontend/services/chat_service.dart';
78
import '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

Comments
 (0)