Skip to content

Commit 3a65cac

Browse files
committed
feat: Enhance ConversationsScreen and UserListScreen with pending session handling and user exclusion
1 parent c4f1875 commit 3a65cac

2 files changed

Lines changed: 60 additions & 40 deletions

File tree

lib/screens/conversations_screen.dart

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ class _ConversationsScreenState extends State<ConversationsScreen> {
2626
nodeService.connectWebSocket().then((_) {
2727
nodeService.stream.listen((event) {
2828
if (!mounted) return;
29-
if (event['event_type'] == 'session') {
29+
if (event['event_type'] == 'session' ||
30+
event['event_type'] == 'pending_session') {
3031
setState(() {});
3132
}
3233
});
@@ -77,7 +78,9 @@ class _ConversationsScreenState extends State<ConversationsScreen> {
7778
);
7879
}
7980

80-
List<ChatView> chats = snapshot.data?[0] as List<ChatView>? ?? [];
81+
List<ChatView> chats =
82+
snapshot.data?[0] as List<ChatView>? ?? [];
83+
_chats = List.from(chats);
8184
int pendingCount = snapshot.data?[1] as int? ?? 0;
8285

8386
if (chats.isEmpty && pendingCount == 0) {
@@ -160,8 +163,7 @@ class _ConversationsScreenState extends State<ConversationsScreen> {
160163
icon: const Icon(Icons.add, color: Colors.white),
161164
),
162165
IconButton(
163-
onPressed: () {
164-
},
166+
onPressed: () {},
165167
icon: const Icon(Icons.settings, color: Colors.white),
166168
),
167169
IconButton(

lib/screens/user_list_screen.dart

Lines changed: 54 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ class _UserListScreenState extends State<UserListScreen> {
3030
try {
3131
final nodeUrl = await _nodeService.getCurrentNodeUrl();
3232
final users = await fetchUsers(nodeUrl!);
33+
// Exclude self from user list
34+
final userId = await _nodeService.getCurrentUserId();
35+
users.removeWhere((user) => user.id == userId);
3336
setState(() {
3437
_allUsers = users;
3538
_filteredUsers = users;
@@ -70,8 +73,10 @@ class _UserListScreenState extends State<UserListScreen> {
7073
actions: [
7174
TextButton(
7275
onPressed: () => Navigator.pop(context, false),
73-
child: Text("Cancel",
74-
style: GoogleFonts.inter(color: Colors.grey[400])),
76+
child: Text(
77+
"Cancel",
78+
style: GoogleFonts.inter(color: Colors.grey[400]),
79+
),
7580
),
7681
ElevatedButton(
7782
onPressed: () => Navigator.pop(context, true),
@@ -93,8 +98,7 @@ class _UserListScreenState extends State<UserListScreen> {
9398
if (!mounted) return;
9499
ScaffoldMessenger.of(context).showSnackBar(
95100
SnackBar(
96-
backgroundColor:
97-
success ? const Color(0xFF3A8DFF) : Colors.redAccent,
101+
backgroundColor: success ? const Color(0xFF3A8DFF) : Colors.redAccent,
98102
content: Text(
99103
success
100104
? "Session started with ${user.username}"
@@ -115,9 +119,13 @@ class _UserListScreenState extends State<UserListScreen> {
115119
backgroundColor: const Color(0xFF0D0D0D),
116120
appBar: AppBar(
117121
backgroundColor: const Color(0xFF0D0D0D),
118-
title: Text("Users",
119-
style: GoogleFonts.inter(
120-
color: Colors.white, fontWeight: FontWeight.w600)),
122+
title: Text(
123+
"Users",
124+
style: GoogleFonts.inter(
125+
color: Colors.white,
126+
fontWeight: FontWeight.w600,
127+
),
128+
),
121129
centerTitle: true,
122130
),
123131
body: SafeArea(
@@ -144,37 +152,47 @@ class _UserListScreenState extends State<UserListScreen> {
144152
),
145153
)
146154
: _filteredUsers.isEmpty
147-
? Center(
148-
child: Text("No users found",
155+
? Center(
156+
child: Text(
157+
"No users found",
158+
style: GoogleFonts.inter(
159+
color: Colors.white70,
160+
fontSize: 16,
161+
),
162+
),
163+
)
164+
: ListView.builder(
165+
itemCount: _filteredUsers.length,
166+
itemBuilder: (_, i) {
167+
final user = _filteredUsers[i];
168+
return Card(
169+
color: const Color(0xFF1E1E1E),
170+
margin: const EdgeInsets.symmetric(vertical: 6),
171+
shape: RoundedRectangleBorder(
172+
borderRadius: BorderRadius.circular(10),
173+
),
174+
child: ListTile(
175+
onTap: () => _onUserTap(user),
176+
title: Text(
177+
user.username,
149178
style: GoogleFonts.inter(
150-
color: Colors.white70, fontSize: 16)),
151-
)
152-
: ListView.builder(
153-
itemCount: _filteredUsers.length,
154-
itemBuilder: (_, i) {
155-
final user = _filteredUsers[i];
156-
return Card(
157-
color: const Color(0xFF1E1E1E),
158-
margin:
159-
const EdgeInsets.symmetric(vertical: 6),
160-
shape: RoundedRectangleBorder(
161-
borderRadius: BorderRadius.circular(10),
162-
),
163-
child: ListTile(
164-
onTap: () => _onUserTap(user),
165-
title: Text(
166-
user.username,
167-
style: GoogleFonts.inter(
168-
color: Colors.white, fontSize: 16),
169-
),
170-
leading: const Icon(Icons.person,
171-
color: Color(0xFF3A8DFF)),
172-
trailing: const Icon(Icons.arrow_forward_ios,
173-
color: Colors.white24, size: 16),
179+
color: Colors.white,
180+
fontSize: 16,
174181
),
175-
);
176-
},
177-
),
182+
),
183+
leading: const Icon(
184+
Icons.person,
185+
color: Color(0xFF3A8DFF),
186+
),
187+
trailing: const Icon(
188+
Icons.arrow_forward_ios,
189+
color: Colors.white24,
190+
size: 16,
191+
),
192+
),
193+
);
194+
},
195+
),
178196
),
179197
],
180198
),

0 commit comments

Comments
 (0)