mirror of
https://github.com/block/buzz.git
synced 2026-10-27 04:30:52 +00:00
🤖 ## Summary In a channel conversation, two identities with the same display name looked identical. In the example below, the channel shows "Bad Janet" twice, for two different identities. A reader cannot tell which one was added and then removed. This PR uses the contextual names from the previous PR everywhere a conversation names someone: - Message authors, threads, forum posts and replies - Reactions, the typing indicator, and system rows (joined, added, removed) - Inline mentions and the agent activity sheet - The profile sheet title, which now matches the row that opened it Names are compared against the channel's members, so a label only gets longer when a real collision exists in that channel. The mention picker labels each choice against every candidate, so two "Honey" choices look different. When you pick one, it still inserts the identity's own name ("@Honey"), so the message text does not change. Part 2 of 3: #7894 (resolver) → #7895 (conversations) → #7896 (lists, Search, Pulse). ### Related issue Related to #2910. ### Testing - A widget test checks that the profile sheet names an author the same way the channel does. - A unit test checks that two same-name mention choices get different labels but insert the same wire name. - `flutter analyze` is clean, and the full `flutter test` suite passes. - Checked on an Android emulator against the live relay, in an archived channel with two identities named "Bad Janet". | Before | After | | --- | --- | | <img width="300" alt="Before: the channel shows two different identities both as Bad Janet" src="https://github.com/user-attachments/assets/c7f6c345-12d8-4e11-9434-bbd2c63722db" /> | <img width="300" alt="After: the second identity shows as Bad Janet · sqxl" src="https://github.com/user-attachments/assets/51c6b9fc-8900-4200-8ce0-ad1887f41dba" /> | --------- Signed-off-by: Logan Johnson <loganj@squareup.com> Co-authored-by: Larry <627498bd4bd1f281a16431e3c6cce3b5c25b6692798c78672298aefbf2f8f8b5@buzz.block.builderlab.xyz>
84 lines
2.9 KiB
Dart
84 lines
2.9 KiB
Dart
import 'dart:collection';
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
|
|
import '../../shared/identity_names/identity_names.dart';
|
|
import '../../shared/identity_names/identity_names_provider.dart';
|
|
import '../../shared/mentions/agent_identity_provider.dart';
|
|
import 'channel_management_provider.dart';
|
|
import 'channels_provider.dart';
|
|
|
|
/// Contextual identity labels for one channel, thread, or DM.
|
|
///
|
|
/// The comparison context is the channel's members; a referenced non-member
|
|
/// (historical author, outside mention) is compared against the members plus
|
|
/// itself. Watch one label with
|
|
/// `ref.watch(channelIdentityNamesProvider(id).select((n) => n.labelFor(pk)))`.
|
|
final channelIdentityNamesProvider = Provider.autoDispose
|
|
.family<IdentityNames, String>((ref, channelId) {
|
|
final sources = ref.watch(identityNameSourcesProvider);
|
|
final members =
|
|
watchLatestChannelMembers(ref, channelId) ??
|
|
(ref.watch(channelsProvider).asData == null
|
|
? const <ChannelMember>[]
|
|
: ref
|
|
.read(channelsProvider.notifier)
|
|
.cachedMembersForChannel(channelId));
|
|
final names = sources.scope(
|
|
[for (final member in members) member.pubkey],
|
|
// The roster's own bot roles stay available offline, when the
|
|
// relay-backed bot lookup and agent directory are empty.
|
|
agentPubkeys: {
|
|
...ref.watch(agentMentionPubkeysProvider(channelId)),
|
|
for (final member in members)
|
|
if (member.isBot) member.pubkey,
|
|
},
|
|
fallbackNames: {
|
|
for (final member in members) member.pubkey: ?member.displayName,
|
|
},
|
|
);
|
|
loadIdentityNameOwners(ref, names);
|
|
return names;
|
|
});
|
|
|
|
/// Watches one identity's contextual label in [channelId].
|
|
String watchChannelIdentityLabel(
|
|
WidgetRef ref,
|
|
String channelId,
|
|
String pubkey,
|
|
) => ref.watch(
|
|
channelIdentityNamesProvider(
|
|
channelId,
|
|
).select((names) => names.labelFor(pubkey)),
|
|
);
|
|
|
|
/// Watches contextual labels for [pubkeys] in [channelId], keyed by
|
|
/// lowercase pubkey. Rebuilds only when one of these labels changes.
|
|
Map<String, String> watchChannelIdentityLabels(
|
|
WidgetRef ref,
|
|
String channelId,
|
|
Iterable<String> pubkeys,
|
|
) {
|
|
final keys = {for (final pubkey in pubkeys) pubkey.toLowerCase()};
|
|
if (keys.isEmpty) return const {};
|
|
return ref.watch(
|
|
channelIdentityNamesProvider(channelId).select(
|
|
(names) => _LabelMap({for (final key in keys) key: names.labelFor(key)}),
|
|
),
|
|
);
|
|
}
|
|
|
|
class _LabelMap extends UnmodifiableMapView<String, String> {
|
|
_LabelMap(super.labels);
|
|
|
|
@override
|
|
bool operator ==(Object other) =>
|
|
other is Map<String, String> && mapEquals(this, other);
|
|
|
|
@override
|
|
int get hashCode => Object.hashAllUnordered(
|
|
entries.map((entry) => Object.hash(entry.key, entry.value)),
|
|
);
|
|
}
|