Skip to content

Commit 04af708

Browse files
browsquare-tombstudio
authored
fix(mobile): offer role controls for agents (#9475)
Mobile hides every role control for a channel member whose role is `bot`. On relays running [#8494 bot role from owner](#8494), any agent with a recorded owner is reported as `bot` whenever it holds an ordinary role. So if an admin demotes an owned agent from admin to member, the refreshed roster says `bot` and mobile no longer offers "Make channel admin": the demotion can't be undone from mobile. This change gives agents the same role controls as people, matching desktop: - The member profile actions offer "Make channel admin" for `bot` members. "Change to member" still appears only for admins and guests, so an agent that is already ordinary isn't offered it. - The members sheet shows the Role selector for agents, with Member selected for `bot` (the two are permission-equivalent). The row label still reads "Agent". **Rollout:** ship this in a mobile release before relays with #8494 deploy. Review discussion: [buzz-mobile-tomb-review-work thread](buzz://message?channel=95213a25-483a-458b-9bc3-71891fa5aef6&id=4714950ee67bf04464a59c1deb3470972c0809c7be780183da6b4a2e77243714). ### Regressions None expected. The relay already accepts admin, member and guest for agents (owned agents can hold admin today), so the newly shown actions submit role changes it accepts. On current relays an agent added as `bot` now also shows these controls; tapping Member on its selector is a no-op because Member is already selected. ### Validation Changed tests: the profile-actions role table now expects "Make channel admin" for `bot`; the promote, demote journey continues with the refreshed role coming back as `bot` and expects promotion to be offered again; the members-sheet agent row expects the Role selector with Member selected. Full mobile suite: 4,828 passed, 70 skipped, 1 failed. The failure, `video_controls_test.dart` "iOS timeline requests native Liquid Glass and fades with the toolbar", is unrelated media-viewer code; it passed when rerun on its own, and the pre-push hook's full mobile run passed. Simulator check against a live relay: an agent added with the `bot` role, viewed by the channel owner in its member profile. | Before | After | | --- | --- | | <img alt="before" src="https://github.com/user-attachments/assets/2503ae98-b198-46c3-85c9-0b85dae2c4ae" width="300"> | <img alt="after" src="https://github.com/user-attachments/assets/82abf55a-de56-45aa-86c5-7917877e388e" width="300"> | Signed-off-by: Tom Brow <[email protected]> Co-authored-by: Tom Brow <[email protected]> Co-authored-by: studio <dc2fc481343672df31a689840c09299972e704dac592e0da6f18486646a7ee3e@buzz.block.builderlab.xyz>
1 parent b6db61f commit 04af708

4 files changed

Lines changed: 44 additions & 36 deletions

File tree

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

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -130,22 +130,20 @@ class ChannelMemberProfileActions extends HookConsumerWidget {
130130
AppListCard(
131131
horizontalPadding: 0,
132132
children: [
133-
if (!member.isBot) ...[
134-
if (member.role != 'admin')
135-
AppListRow(
136-
icon: BuzzIcons.shieldCheck,
137-
title: 'Make channel admin',
138-
onTap: busy.value ? null : () => perform(role: 'admin'),
139-
),
140-
if (member.role == 'admin' || member.role == 'guest')
141-
AppListRow(
142-
icon: BuzzIcons.user,
143-
title: member.role == 'guest'
144-
? 'Make member'
145-
: 'Change to member',
146-
onTap: busy.value ? null : () => perform(role: 'member'),
147-
),
148-
],
133+
if (member.role != 'admin')
134+
AppListRow(
135+
icon: BuzzIcons.shieldCheck,
136+
title: 'Make channel admin',
137+
onTap: busy.value ? null : () => perform(role: 'admin'),
138+
),
139+
if (member.role == 'admin' || member.role == 'guest')
140+
AppListRow(
141+
icon: BuzzIcons.user,
142+
title: member.role == 'guest'
143+
? 'Make member'
144+
: 'Change to member',
145+
onTap: busy.value ? null : () => perform(role: 'member'),
146+
),
149147
AppListRow(
150148
icon: BuzzIcons.userMinus,
151149
title: 'Remove from channel',

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

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,6 @@ class _MemberTile extends ConsumerWidget {
313313
: ref
314314
.read(channelIdentityNamesProvider(channelId))
315315
.labelFor(member.pubkey);
316-
final canChangeRole = showManagementActions && !member.isBot;
317316
showBuzzModalBottomSheet<void>(
318317
context: context,
319318
title: label,
@@ -344,23 +343,21 @@ class _MemberTile extends ConsumerWidget {
344343
],
345344
),
346345
if (showManagementActions) ...[
347-
if (canChangeRole) ...[
348-
const SizedBox(height: Grid.xxs),
349-
_RoleSelector(
350-
selectedRole: member.role,
351-
onChanged: (role) async {
352-
Navigator.of(sheetContext).pop();
353-
await ref
354-
.read(channelActionsProvider)
355-
.changeMemberRole(
356-
channelId: channelId,
357-
pubkey: member.pubkey,
358-
role: role,
359-
);
360-
},
361-
),
362-
const SizedBox(height: Grid.xs),
363-
],
346+
const SizedBox(height: Grid.xxs),
347+
_RoleSelector(
348+
selectedRole: member.isBot ? 'member' : member.role,
349+
onChanged: (role) async {
350+
Navigator.of(sheetContext).pop();
351+
await ref
352+
.read(channelActionsProvider)
353+
.changeMemberRole(
354+
channelId: channelId,
355+
pubkey: member.pubkey,
356+
role: role,
357+
);
358+
},
359+
),
360+
const SizedBox(height: Grid.xs),
364361
SheetActionSection(
365362
horizontalPadding: Grid.gutter,
366363
children: [

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,13 +246,20 @@ void main() {
246246
await tester.tap(find.text('Change to member'));
247247
await tester.pumpAndSettle();
248248
expect(actions.calls, ['test:alice:admin', 'test:alice:member']);
249+
250+
// An owned agent demoted to ordinary membership is now reported as bot.
251+
// That label must not remove the owner's ability to promote it again.
252+
role = 'bot';
253+
container.invalidate(channelMembersProvider('test'));
254+
await tester.pumpAndSettle();
255+
expect(find.text('Make channel admin'), findsOneWidget);
249256
});
250257
for (final role in ['member', 'admin', 'guest', 'bot']) {
251258
testWidgets('management rows for $role', (tester) async {
252259
await _pump(tester, targetRole: role);
253260
expect(
254261
find.text('Make channel admin'),
255-
role == 'member' || role == 'guest' ? findsOneWidget : findsNothing,
262+
role == 'admin' ? findsNothing : findsOneWidget,
256263
);
257264
expect(
258265
find.text('Change to member'),

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,13 @@ void main() {
259259
);
260260
await tester.pumpAndSettle();
261261
expect(find.text('View activity'), findsOneWidget);
262-
expect(find.text('Role'), findsNothing);
262+
expect(find.text('Role'), findsOneWidget);
263+
expect(
264+
tester
265+
.widget<SegmentedButton<String>>(find.byType(SegmentedButton<String>))
266+
.selected,
267+
{'member'},
268+
);
263269
expect(tester.takeException(), isNull);
264270
});
265271

0 commit comments

Comments
 (0)