Skip to content

Commit 05d1714

Browse files
authored
fix(mobile): manage channel members from profile sheets (#8078)
Keep member administration reachable when small channels omit “See all.” Tapping a member now opens profile-sheet rows to make a channel admin, change an admin to member, or remove the person with confirmation, using the existing grouped list style. Actions follow the live roster, respect channel permissions, prevent duplicate submissions, and surface failures. Existing guests can become members or admins; owners, self, archived channels, and DMs do not expose these controls. Validation: mobile analysis, formatting, file-size checks, and the full mobile suite passed. Release iOS build installed and launched on a physical iPhone. Full repository `just ci` was previously stopped for low disk space during desktop compilation. --------- Signed-off-by: kenny lopez <[email protected]>
1 parent a14107a commit 05d1714

8 files changed

Lines changed: 533 additions & 4 deletions

File tree

‎mobile/lib/features/channels/channel_detail_page.dart‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import 'android_ime_lift.dart';
4242
import 'channel.dart';
4343
import 'channel_actions_sheet.dart';
4444
import 'channel_identity_names_provider.dart';
45+
import 'channel_member_profile_actions.dart';
4546
import 'channel_link_navigation.dart';
4647
import 'agent_activity/working_bots_provider.dart';
4748
import 'channel_management_provider.dart';
@@ -591,6 +592,10 @@ class ChannelDetailPage extends HookConsumerWidget {
591592
context,
592593
pubkey,
593594
names: channelIdentityNamesProvider(resolvedChannel.id),
595+
contextualActions: (_) => ChannelMemberProfileActions(
596+
channel: resolvedChannel,
597+
pubkey: pubkey,
598+
),
594599
),
595600
sectionId: ref
596601
.read(channelSectionsProvider)

‎mobile/lib/features/channels/channel_details_page.dart‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ class ChannelDetailsPage extends HookConsumerWidget {
207207
builder: (_) => MembersSheet(
208208
channel: resolvedChannel,
209209
currentPubkey: resolvedCurrentPubkey,
210+
onMemberTap: onMemberTap,
210211
),
211212
);
212213

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:flutter_hooks/flutter_hooks.dart';
3+
import 'package:hooks_riverpod/hooks_riverpod.dart';
4+
import 'package:lucide_icons_flutter/lucide_icons.dart';
5+
6+
import '../../shared/theme/theme.dart';
7+
import '../../shared/widgets/app_list.dart';
8+
import '../../shared/widgets/app_list_card.dart';
9+
import '../../shared/widgets/modal_presentation.dart';
10+
import 'channel.dart';
11+
import 'channel_identity_names_provider.dart';
12+
import 'channel_management_provider.dart';
13+
import 'channels_provider.dart';
14+
15+
/// Channel-scoped management rows embedded below a member's profile actions.
16+
class ChannelMemberProfileActions extends HookConsumerWidget {
17+
const ChannelMemberProfileActions({
18+
super.key,
19+
required this.channel,
20+
required this.pubkey,
21+
});
22+
23+
final Channel channel;
24+
final String pubkey;
25+
26+
@override
27+
Widget build(BuildContext context, WidgetRef ref) {
28+
final busy = useState(false);
29+
final error = useState<String?>(null);
30+
final actor = ref.watch(currentPubkeyProvider)?.toLowerCase();
31+
final roster = ref.watch(channelMembersProvider(channel.id));
32+
final channels = ref.watch(channelsProvider).asData?.value;
33+
final currentChannel =
34+
channels
35+
?.where((candidate) => candidate.id == channel.id)
36+
.firstOrNull ??
37+
channel;
38+
final target = pubkey.toLowerCase();
39+
40+
ChannelMember? manageableMember(
41+
AsyncValue<List<ChannelMember>> snapshot,
42+
String? currentActor,
43+
Channel current,
44+
) {
45+
if (current.isDm ||
46+
current.isArchived ||
47+
snapshot.isLoading ||
48+
snapshot.hasError ||
49+
currentActor == null ||
50+
target == currentActor) {
51+
return null;
52+
}
53+
final members = snapshot.asData?.value ?? const <ChannelMember>[];
54+
final viewer = members
55+
.where((m) => m.pubkey.toLowerCase() == currentActor)
56+
.firstOrNull;
57+
final member = members
58+
.where((m) => m.pubkey.toLowerCase() == target)
59+
.firstOrNull;
60+
if (viewer?.isElevated != true || member == null || member.isOwner) {
61+
return null;
62+
}
63+
return member;
64+
}
65+
66+
final member = manageableMember(roster, actor, currentChannel);
67+
if (member == null) return const SizedBox.shrink();
68+
69+
bool stillAllowed() {
70+
final latest =
71+
ref
72+
.read(channelsProvider)
73+
.asData
74+
?.value
75+
.where((candidate) => candidate.id == channel.id)
76+
.firstOrNull ??
77+
currentChannel;
78+
return ref.read(currentPubkeyProvider)?.toLowerCase() == actor &&
79+
manageableMember(
80+
ref.read(channelMembersProvider(channel.id)),
81+
actor,
82+
latest,
83+
)?.role ==
84+
member.role;
85+
}
86+
87+
Future<void> perform({String? role}) async {
88+
if (busy.value || !stillAllowed()) return;
89+
busy.value = true;
90+
error.value = null;
91+
try {
92+
if (role == null) {
93+
final label = ref
94+
.read(channelIdentityNamesProvider(channel.id))
95+
.labelFor(target);
96+
final confirmed = await showBuzzDialog<bool>(
97+
context: context,
98+
builder: (dialogContext) => AlertDialog(
99+
title: const Text('Remove from channel?'),
100+
content: Text('Remove $label from ${currentChannel.name}?'),
101+
actions: [
102+
TextButton(
103+
onPressed: () => Navigator.of(dialogContext).pop(false),
104+
child: const Text('Cancel'),
105+
),
106+
TextButton(
107+
onPressed: () => Navigator.of(dialogContext).pop(true),
108+
child: const Text('Remove'),
109+
),
110+
],
111+
),
112+
);
113+
if (!context.mounted || confirmed != true || !stillAllowed()) return;
114+
await ref
115+
.read(channelActionsProvider)
116+
.removeMember(channelId: channel.id, pubkey: target);
117+
if (context.mounted) Navigator.of(context).pop();
118+
} else {
119+
await ref
120+
.read(channelActionsProvider)
121+
.changeMemberRole(
122+
channelId: channel.id,
123+
pubkey: target,
124+
role: role,
125+
);
126+
}
127+
} catch (_) {
128+
if (context.mounted) {
129+
error.value = role == null
130+
? 'Could not remove this person. Please try again.'
131+
: 'Could not change this role. Please try again.';
132+
}
133+
} finally {
134+
if (context.mounted) busy.value = false;
135+
}
136+
}
137+
138+
return Column(
139+
crossAxisAlignment: CrossAxisAlignment.stretch,
140+
children: [
141+
AppListCard(
142+
horizontalPadding: 0,
143+
children: [
144+
if (!member.isBot) ...[
145+
if (member.role != 'admin')
146+
AppListRow(
147+
icon: LucideIcons.shieldCheck,
148+
title: 'Make channel admin',
149+
onTap: busy.value ? null : () => perform(role: 'admin'),
150+
),
151+
if (member.role == 'admin' || member.role == 'guest')
152+
AppListRow(
153+
icon: LucideIcons.user,
154+
title: member.role == 'guest'
155+
? 'Make member'
156+
: 'Change to member',
157+
onTap: busy.value ? null : () => perform(role: 'member'),
158+
),
159+
],
160+
AppListRow(
161+
icon: LucideIcons.userMinus,
162+
title: 'Remove from channel',
163+
titleColor: context.colors.error,
164+
onTap: busy.value ? null : () => perform(),
165+
),
166+
],
167+
),
168+
if (busy.value)
169+
Semantics(
170+
liveRegion: true,
171+
label: 'Updating channel member',
172+
child: const ExcludeSemantics(
173+
child: Center(child: Text('Updating…')),
174+
),
175+
),
176+
if (error.value != null)
177+
Semantics(
178+
liveRegion: true,
179+
label: error.value!,
180+
child: ExcludeSemantics(
181+
child: Text(
182+
error.value!,
183+
style: context.textTheme.bodyMedium?.copyWith(
184+
color: context.colors.error,
185+
),
186+
),
187+
),
188+
),
189+
],
190+
);
191+
}
192+
}

‎mobile/lib/features/channels/members_sheet.dart‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ import 'channel_management_provider.dart';
2020
class MembersSheet extends HookConsumerWidget {
2121
final Channel channel;
2222
final String? currentPubkey;
23+
final void Function(BuildContext context, String pubkey)? onMemberTap;
2324

2425
const MembersSheet({
2526
super.key,
2627
required this.channel,
2728
required this.currentPubkey,
29+
this.onMemberTap,
2830
});
2931

3032
@override
@@ -108,6 +110,9 @@ class MembersSheet extends HookConsumerWidget {
108110
currentPubkey?.toLowerCase(),
109111
channelId: channel.id,
110112
userStatus: statusCache[member.pubkey.toLowerCase()],
113+
onActivityTap: onMemberTap == null
114+
? null
115+
: () => onMemberTap!(context, member.pubkey),
111116
),
112117
],
113118
if (bots.isNotEmpty) ...[

‎mobile/lib/features/profile/user_profile_sheet.dart‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,17 @@ void showUserProfileSheet(
3434
BuildContext context,
3535
String pubkey, {
3636
ProviderListenable<IdentityNames>? names,
37+
WidgetBuilder? contextualActions,
3738
}) {
3839
showBuzzModalBottomSheet<Channel>(
3940
context: context,
4041
isScrollControlled: true,
4142
showDragHandle: false,
42-
builder: (_) => UserProfileSheet(pubkey: pubkey, names: names),
43+
builder: (_) => UserProfileSheet(
44+
pubkey: pubkey,
45+
names: names,
46+
contextualActions: contextualActions,
47+
),
4348
).then((channel) {
4449
if (channel == null || !context.mounted) return;
4550
Navigator.of(context).push(
@@ -58,7 +63,15 @@ class UserProfileSheet extends HookConsumerWidget {
5863
/// owns the context, so this sheet depends on no other feature's state.
5964
final ProviderListenable<IdentityNames>? names;
6065

61-
const UserProfileSheet({super.key, required this.pubkey, this.names});
66+
/// Optional actions supplied by the opening surface, below the profile tiles.
67+
final WidgetBuilder? contextualActions;
68+
69+
const UserProfileSheet({
70+
super.key,
71+
required this.pubkey,
72+
this.names,
73+
this.contextualActions,
74+
});
6275

6376
@override
6477
Widget build(BuildContext context, WidgetRef ref) {
@@ -285,6 +298,8 @@ class UserProfileSheet extends HookConsumerWidget {
285298
],
286299
),
287300
const SizedBox(height: Grid.xs),
301+
if (contextualActions != null)
302+
Builder(builder: contextualActions!),
288303
],
289304
),
290305
),

‎mobile/lib/shared/widgets/app_list_card.dart‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class AppListCard extends StatelessWidget {
1212
this.label,
1313
this.dividerIndent,
1414
this.verticalPadding = Grid.xxs,
15+
this.horizontalPadding = Grid.gutter,
1516
required this.children,
1617
});
1718

@@ -29,6 +30,9 @@ class AppListCard extends StatelessWidget {
2930
/// passing [Grid.twelve] creates a 24dp rhythm between grouped surfaces.
3031
final double verticalPadding;
3132

33+
/// Outer horizontal inset; use zero inside an already padded sheet.
34+
final double horizontalPadding;
35+
3236
final List<Widget> children;
3337

3438
static const _inset = Grid.xs;
@@ -61,9 +65,9 @@ class AppListCard extends StatelessWidget {
6165

6266
return Padding(
6367
padding: EdgeInsets.fromLTRB(
64-
Grid.gutter,
68+
horizontalPadding,
6569
verticalPadding,
66-
Grid.gutter,
70+
horizontalPadding,
6771
verticalPadding,
6872
),
6973
child: Column(

‎mobile/test/features/channels/channel_detail_page_test.dart‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2449,6 +2449,15 @@ void main() {
24492449
expect(addRow, findsOneWidget);
24502450
expect(memberRow, findsOneWidget);
24512451
expect(seeAllRow, findsNothing);
2452+
await tester.tap(
2453+
find.byKey(const ValueKey('channel-details-member-alice')),
2454+
);
2455+
await tester.pumpAndSettle();
2456+
expect(find.byType(UserProfileSheet), findsOneWidget);
2457+
expect(find.text('Make channel admin'), findsOneWidget);
2458+
expect(find.text('Remove from channel'), findsOneWidget);
2459+
Navigator.of(tester.element(find.byType(UserProfileSheet))).pop();
2460+
await tester.pumpAndSettle();
24522461
expect(
24532462
tester.widget<Text>(find.text('Add members')).style,
24542463
Theme.of(tester.element(addRow)).textTheme.bodyLarge,

0 commit comments

Comments
 (0)