Skip to content

Commit 5535d18

Browse files
loganjLarry
andcommitted
fix(mobile): let callers own a profile sheet's naming context
The profile sheet imported the channels feature to resolve a channel's naming context. Features may import only from shared/, so that made the profile feature depend on channel state. Callers now pass a watchable naming context. Channel, thread and forum surfaces pass their channel's live names. Other surfaces can wrap a comparison context with liveIdentityNamesProvider, which resolves it against the current naming facts. The sheet watches the context, so its title still follows profile changes while it is open. Co-authored-by: Larry <627498bd4bd1f281a16431e3c6cce3b5c25b6692798c78672298aefbf2f8f8b5@buzz.block.builderlab.xyz> Signed-off-by: Logan Johnson <[email protected]>
1 parent 2f9668c commit 5535d18

9 files changed

Lines changed: 66 additions & 47 deletions

File tree

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,11 @@ class ChannelDetailPage extends HookConsumerWidget {
606606
context: context,
607607
channel: resolvedChannel,
608608
currentPubkey: currentPubkey,
609-
onMemberTap: showUserProfileSheet,
609+
onMemberTap: (context, pubkey) => showUserProfileSheet(
610+
context,
611+
pubkey,
612+
names: channelIdentityNamesProvider(resolvedChannel.id),
613+
),
610614
sectionId: ref
611615
.read(channelSectionsProvider)
612616
.store

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,9 @@ class _MessageBubble extends HookConsumerWidget {
169169
onTap: () => showUserProfileSheet(
170170
context,
171171
message.pubkey,
172-
channelId: currentChannelId,
172+
names: channelIdentityNamesProvider(
173+
currentChannelId,
174+
),
173175
),
174176
child: _UserAvatar(
175177
profile: profile,
@@ -211,7 +213,10 @@ class _MessageBubble extends HookConsumerWidget {
211213
showUserProfileSheet(
212214
context,
213215
message.pubkey,
214-
channelId: currentChannelId,
216+
names:
217+
channelIdentityNamesProvider(
218+
currentChannelId,
219+
),
215220
),
216221
displayNameKey: ValueKey(
217222
'message-author-${message.id}',
@@ -296,7 +301,9 @@ class _MessageBubble extends HookConsumerWidget {
296301
onMentionTap: (pubkey) => showUserProfileSheet(
297302
context,
298303
pubkey,
299-
channelId: currentChannelId,
304+
names: channelIdentityNamesProvider(
305+
currentChannelId,
306+
),
300307
),
301308
),
302309
],

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ class _MessageStyleSystemMessageContent extends StatelessWidget {
395395
onTap: () => showUserProfileSheet(
396396
context,
397397
displayPubkey,
398-
channelId: channelId,
398+
names: channelIdentityNamesProvider(channelId),
399399
),
400400
child: _UserAvatar(
401401
profile: userCache[displayPubkey.toLowerCase()],
@@ -517,7 +517,7 @@ Widget _systemEventAvatar(
517517
onTap: () => showUserProfileSheet(
518518
context,
519519
event.actorPubkey!,
520-
channelId: channelId,
520+
names: channelIdentityNamesProvider(channelId),
521521
),
522522
child: SmallAvatar(
523523
pubkey: event.actorPubkey!,
@@ -531,7 +531,7 @@ Widget _systemEventAvatar(
531531
onTap: () => showUserProfileSheet(
532532
context,
533533
event.targetPubkey!,
534-
channelId: channelId,
534+
names: channelIdentityNamesProvider(channelId),
535535
),
536536
child: SmallAvatar(
537537
pubkey: event.targetPubkey!,
@@ -550,7 +550,7 @@ Widget _systemEventAvatar(
550550
onTap: () => showUserProfileSheet(
551551
context,
552552
event.actorPubkey!,
553-
channelId: channelId,
553+
names: channelIdentityNamesProvider(channelId),
554554
),
555555
child: SmallAvatar(pubkey: event.actorPubkey!, userCache: userCache),
556556
);

‎mobile/lib/features/channels/thread_detail_page/thread_message.dart‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ class _ThreadMessage extends HookConsumerWidget {
164164
onTap: () => showUserProfileSheet(
165165
context,
166166
message.pubkey,
167-
channelId: channelId,
167+
names: channelIdentityNamesProvider(channelId),
168168
),
169169
child: _Avatar(
170170
profile: profile,
@@ -206,7 +206,10 @@ class _ThreadMessage extends HookConsumerWidget {
206206
showUserProfileSheet(
207207
context,
208208
message.pubkey,
209-
channelId: channelId,
209+
names:
210+
channelIdentityNamesProvider(
211+
channelId,
212+
),
210213
),
211214
displayNameKey: ValueKey(
212215
'thread-message-author-${message.id}',
@@ -292,7 +295,9 @@ class _ThreadMessage extends HookConsumerWidget {
292295
showUserProfileSheet(
293296
context,
294297
pubkey,
295-
channelId: channelId,
298+
names: channelIdentityNamesProvider(
299+
channelId,
300+
),
296301
),
297302
),
298303
],

‎mobile/lib/features/forum/forum_post_card.dart‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ class ForumPostCard extends HookConsumerWidget {
123123
onTap: () => showUserProfileSheet(
124124
context,
125125
post.pubkey,
126-
channelId: post.channelId,
126+
names: channelIdentityNamesProvider(post.channelId),
127127
),
128128
child: _PostAvatar(
129129
profile: profile,
@@ -138,7 +138,7 @@ class ForumPostCard extends HookConsumerWidget {
138138
onTap: () => showUserProfileSheet(
139139
context,
140140
post.pubkey,
141-
channelId: post.channelId,
141+
names: channelIdentityNamesProvider(post.channelId),
142142
),
143143
child: Text(
144144
displayName,

‎mobile/lib/features/forum/forum_thread_page.dart‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ class _OriginalPost extends ConsumerWidget {
366366
onTap: () => showUserProfileSheet(
367367
context,
368368
post.pubkey,
369-
channelId: post.channelId,
369+
names: channelIdentityNamesProvider(post.channelId),
370370
),
371371
child: _Avatar(
372372
key: ValueKey('forum-original-avatar-${post.eventId}'),
@@ -385,7 +385,7 @@ class _OriginalPost extends ConsumerWidget {
385385
onTap: () => showUserProfileSheet(
386386
context,
387387
post.pubkey,
388-
channelId: post.channelId,
388+
names: channelIdentityNamesProvider(post.channelId),
389389
),
390390
child: Text(
391391
displayName,
@@ -425,7 +425,7 @@ class _OriginalPost extends ConsumerWidget {
425425
onMentionTap: (pubkey) => showUserProfileSheet(
426426
context,
427427
pubkey,
428-
channelId: post.channelId,
428+
names: channelIdentityNamesProvider(post.channelId),
429429
),
430430
),
431431
],
@@ -489,7 +489,7 @@ class _ReplyRow extends ConsumerWidget {
489489
onTap: () => showUserProfileSheet(
490490
context,
491491
reply.pubkey,
492-
channelId: channelId,
492+
names: channelIdentityNamesProvider(channelId),
493493
),
494494
child: _Avatar(
495495
key: ValueKey('forum-reply-avatar-${reply.eventId}'),
@@ -508,7 +508,7 @@ class _ReplyRow extends ConsumerWidget {
508508
onTap: () => showUserProfileSheet(
509509
context,
510510
reply.pubkey,
511-
channelId: channelId,
511+
names: channelIdentityNamesProvider(channelId),
512512
),
513513
child: Text(
514514
displayName,
@@ -560,8 +560,11 @@ class _ReplyRow extends ConsumerWidget {
560560
baseStyle: messageBodyTextStyle.copyWith(
561561
color: context.colors.onSurface,
562562
),
563-
onMentionTap: (pubkey) =>
564-
showUserProfileSheet(context, pubkey, channelId: channelId),
563+
onMentionTap: (pubkey) => showUserProfileSheet(
564+
context,
565+
pubkey,
566+
names: channelIdentityNamesProvider(channelId),
567+
),
565568
),
566569
),
567570
],

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

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
44
import 'package:flutter/services.dart';
55
import 'package:flutter_hooks/flutter_hooks.dart';
66
import 'package:hooks_riverpod/hooks_riverpod.dart';
7+
import 'package:hooks_riverpod/misc.dart' show ProviderListenable;
78
import 'package:lucide_icons_flutter/lucide_icons.dart';
89

910
import '../../shared/animated_avatar.dart';
@@ -18,7 +19,6 @@ import '../../shared/widgets/modal_presentation.dart';
1819
import '../../shared/widgets/progressive_animated_avatar.dart';
1920
import '../channels/channel.dart';
2021
import '../channels/channel_detail_page.dart';
21-
import '../channels/channel_identity_names_provider.dart';
2222
import '../channels/channel_management_provider.dart';
2323
import '../channels/message_content.dart';
2424
import 'presence_cache_provider.dart';
@@ -27,21 +27,19 @@ import 'user_status_cache_provider.dart';
2727

2828
/// Show a user profile bottom sheet for the given [pubkey].
2929
///
30-
/// The sheet names [pubkey] as the opening surface did: within [channelId]
31-
/// when given, otherwise within [names] (for example a Pulse timeline's
32-
/// authors). With neither, the identity is compared only with itself.
30+
/// The sheet names [pubkey] as the opening surface did: within the live
31+
/// comparison context [names] (for example a channel's members or a Pulse
32+
/// timeline). Without it, the identity is compared only with itself.
3333
void showUserProfileSheet(
3434
BuildContext context,
3535
String pubkey, {
36-
String? channelId,
37-
IdentityNames? names,
36+
ProviderListenable<IdentityNames>? names,
3837
}) {
3938
showBuzzModalBottomSheet<Channel>(
4039
context: context,
4140
isScrollControlled: true,
4241
showDragHandle: false,
43-
builder: (_) =>
44-
UserProfileSheet(pubkey: pubkey, channelId: channelId, names: names),
42+
builder: (_) => UserProfileSheet(pubkey: pubkey, names: names),
4543
).then((channel) {
4644
if (channel == null || !context.mounted) return;
4745
Navigator.of(context).push(
@@ -55,19 +53,12 @@ void showUserProfileSheet(
5553
class UserProfileSheet extends HookConsumerWidget {
5654
final String pubkey;
5755

58-
/// The channel whose members form the naming context, if any.
59-
final String? channelId;
56+
/// The opening surface's comparison context. The sheet watches it, so its
57+
/// title follows profile and context changes while it is open. The caller
58+
/// owns the context, so this sheet depends on no other feature's state.
59+
final ProviderListenable<IdentityNames>? names;
6060

61-
/// The opening surface's comparison context, used when [channelId] is
62-
/// null. The sheet resolves it against live naming facts.
63-
final IdentityNames? names;
64-
65-
const UserProfileSheet({
66-
super.key,
67-
required this.pubkey,
68-
this.channelId,
69-
this.names,
70-
});
61+
const UserProfileSheet({super.key, required this.pubkey, this.names});
7162

7263
@override
7364
Widget build(BuildContext context, WidgetRef ref) {
@@ -115,12 +106,10 @@ class UserProfileSheet extends HookConsumerWidget {
115106

116107
// The contextual label from the opening surface, so the sheet names the
117108
// identity exactly as the row that was tapped.
118-
final contextChannelId = channelId;
119-
final displayName = contextChannelId != null
120-
? watchChannelIdentityLabel(ref, contextChannelId, pk)
121-
: (names?.withSources(ref.watch(identityNameSourcesProvider)) ??
122-
watchIdentityNames(ref, {pk}))
123-
.labelFor(pk);
109+
final opener = names;
110+
final displayName =
111+
(opener != null ? ref.watch(opener) : watchIdentityNames(ref, {pk}))
112+
.labelFor(pk);
124113
final avatarUrl = profile?.avatarUrl;
125114
final nip05 = profile?.nip05Handle;
126115
final initial =

‎mobile/lib/shared/identity_names/identity_names_provider.dart‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ final identityNameSourcesProvider = Provider<IdentityNameSources>((ref) {
1717
);
1818
});
1919

20+
/// [names]'s comparison context resolved against the live naming facts.
21+
/// Lets a surface hand its context to a sheet or route as a watchable
22+
/// value, so the destination follows later profile and owner changes.
23+
final liveIdentityNamesProvider = Provider.autoDispose
24+
.family<IdentityNames, IdentityNames>(
25+
(ref, names) => names.withSources(ref.watch(identityNameSourcesProvider)),
26+
);
27+
2028
/// Requests missing owner profiles for [names] after the current build.
2129
void loadIdentityNameOwners(Ref ref, IdentityNames names) {
2230
final missing = names.missingOwnerProfiles();

‎mobile/test/features/profile/user_profile_sheet_names_test.dart‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ void main() {
5151
other,
5252
]);
5353
return Scaffold(
54-
body: UserProfileSheet(pubkey: scout, names: opened),
54+
body: UserProfileSheet(
55+
pubkey: scout,
56+
names: liveIdentityNamesProvider(opened),
57+
),
5558
);
5659
},
5760
),

0 commit comments

Comments
 (0)