Skip to content

Commit 2450b7e

Browse files
committed
Merge branch 'main' of github.com:HushNet/HushNet-Frontend
2 parents 022cf0b + cb0f396 commit 2450b7e

19 files changed

Lines changed: 430 additions & 67 deletions

.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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,8 @@ app.*.map.json
4343
/android/app/debug
4444
/android/app/profile
4545
/android/app/release
46+
47+
# FVM Version Cache
48+
.fvm/
49+
50+
.vscode/

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
{
2+
"dart.flutterSdkPath": ".fvm\\versions\\3.35.7",
23
"C_Cpp_Runner.cCompilerPath": "gcc",
34
"C_Cpp_Runner.cppCompilerPath": "g++",
45
"C_Cpp_Runner.debuggerPath": "gdb",
56
"C_Cpp_Runner.cStandard": "",
67
"C_Cpp_Runner.cppStandard": "",
7-
"C_Cpp_Runner.msvcBatchPath": "C:/Program Files/Microsoft Visual Studio/VR_NR/Community/VC/Auxiliary/Build/vcvarsall.bat",
8+
"C_Cpp_Runner.msvcBatchPath": "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Auxiliary/Build/vcvarsall.bat",
89
"C_Cpp_Runner.useMsvc": false,
910
"C_Cpp_Runner.warnings": [
1011
"-Wall",

assets/icons/app.ico

14.7 KB
Binary file not shown.

devtools_options.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
description: This file stores settings for Dart & Flutter DevTools.
2+
documentation: https://docs.flutter.dev/tools/devtools/extensions#configure-extension-enablement-states
3+
extensions:

lib/main.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ class HushNetApp extends StatelessWidget {
1616
@override
1717
Widget build(BuildContext context) {
1818
return MaterialApp(
19-
title: 'Flutter Demo',
19+
title: 'HushNet',
2020
theme: hushNetTheme,
21-
home: const MyHomePage(title: 'Flutter Demo Home Page'),
21+
home: const MyHomePage(title: 'HushNet Home Page'),
2222
);
2323
}
2424
}

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: 87 additions & 21 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';
@@ -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

Comments
 (0)