Files
buzz/mobile/lib/features/channels/message_author_visibility.dart
Tom Brow c0e30110dd fix(mobile): restore header cues and per-channel identity check for #9369 (#9370)
Follow-up to #9369 (conversation header avatars). Fixes two regressions
found in its review. The intended behavior of #9369 stays the same.

1. **Message rows no longer each scan the roster.**
`showMessageAuthorName` ran at the top of every message and thread row,
in every channel. Each run watched a whole `Channel` object (which has
no value equality) and built sets from the full roster, plus two more
sets for the stale-DM check in DMs. A new
`confirmedConversationPairProvider` works out the two-person pair once
per channel, including the rule that a DM keeps attribution while its
metadata disagrees with the roster. It returns a record that compares by
value, so rows rebuild only when the pair itself changes. It reads
`watchLatestChannelMembers`, so a revisit uses the cached roster and
rows no longer re-wrap 48 dp wider once the roster fetch returns. The
visible rule is the same as before.
2. **Android private channels show the lock again.** Every Android
conversation header now uses the compact title pill, which had no lock.
The pill now shows the existing lock icon (and its "Private channel"
label) before the name.

### Validation

- Added tests, all extending existing journeys:
- The author-visibility journey checks that replacing the channel object
(as live activity does) doesn't notify rows when the pair is unchanged.
Its existing `stale-dm` case covers the metadata rule now inside the
provider.
  - The private-lock header test expects the lock again.
- Each new or restored Dart assertion fails with its fix reverted, and
so does the `stale-dm` case with the provider's metadata rule removed.
- Full mobile suite (`just mobile-test`) and `flutter analyze` pass.
- Not run: an automated full-app session on a simulator or device.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Signed-off-by: Tom Brow <tomb@squareup.com>
Co-authored-by: Tom Brow <tomb@squareup.com>
Co-authored-by: studio <dc2fc481343672df31a689840c09299972e704dac592e0da6f18486646a7ee3e@buzz.block.builderlab.xyz>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 06:21:39 -08:00

67 lines
2.3 KiB
Dart

import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'channel_management_provider.dart';
import 'channels_provider.dart';
Set<String> _normalizedKeys(Iterable<String> keys) => keys
.map((key) => key.trim().toLowerCase())
.where((key) => key.isNotEmpty)
.toSet();
/// The two lowercase pubkeys of a conversation whose membership confirms
/// exactly two people, or null otherwise.
///
/// Computed once per channel so message rows do not each scan the roster.
/// The record compares by value, so rows rebuild only when the pair changes,
/// not on every channel or roster emission.
final confirmedConversationPairProvider = Provider.autoDispose
.family<(String, String)?, String>((ref, channelId) {
final channel = ref.watch(
channelsProvider.select(
(value) => value.value
?.where((channel) => channel.id == channelId)
.firstOrNull,
),
);
if (channel == null) return null;
final members = watchLatestChannelMembers(ref, channelId);
final current = members == null
? null
: _normalizedKeys(members.map((member) => member.pubkey));
if (channel.isDm && current != null) {
// The DM header still uses metadata. Keep attribution while that
// snapshot disagrees with current membership, even if only one
// counterpart remains.
final metadata = _normalizedKeys(channel.participantPubkeys);
if (metadata.length != current.length ||
!metadata.containsAll(current)) {
return null;
}
}
final participants =
current ??
(channel.isDm
? _normalizedKeys(channel.participantPubkeys)
: const <String>{});
if (participants.length != 2) return null;
final sorted = participants.toList()..sort();
return (sorted[0], sorted[1]);
});
/// Keep names unless membership confirms a conversation with only two people.
bool showMessageAuthorName(
WidgetRef ref,
String channelId,
String authorPubkey,
String? viewerPubkey,
) {
final pair = ref.watch(confirmedConversationPairProvider(channelId));
if (pair == null) return true;
bool inPair(String? pubkey) {
final key = pubkey?.toLowerCase();
return key == pair.$1 || key == pair.$2;
}
return !inPair(viewerPubkey) || !inPair(authorPubkey);
}