mirror of
https://github.com/block/buzz.git
synced 2026-11-28 04:01:45 +00:00
## Summary Mobile part of growable DMs. A DM's details page now has an **Add** action where channels show Edit. - Adding only agents joins them to this DM with its history. No question is asked, matching desktop. - Adding a person asks first. **Include history** adds them to this DM with its earlier messages. **Start a new DM** opens a DM of the people, without the agents or history, and the app moves to it. If that DM already exists, the relay returns it. - In a DM of just you and your agents, adding a person skips the question and opens a DM of you and that person. The relay enforces this too. - Both choices send kind 41011. Only Include history carries the `["history","include"]` tag, per the relay's opt-in rule in #9125. Without the tag, the relay forks. - iOS shows a native alert. Android uses the standard adaptive dialog. - The relay's moderation DM shows no Add, recognized by the relay's NIP-11 signer key. The relay refuses adds there anyway. - Leave stays as it is. #9125 lets the relay accept a member's own leave from a DM. The question is asked before the sheet shows its busy state, so "Adding…" only appears after a choice. ### Related issue Depends on #9125 (relay) and pairs with block/buzz-app#2670 (desktop). Spec: Growable DMs. ### Testing - New widget tests: agents join with history and no question; adding a person to a DM of two or more people asks; adding a person to an agent-only DM opens a new DM without asking; Include history keeps this DM; Start a new DM sends no tag and opens the new DM; Cancel adds no one and leaves Add enabled; a DM member sees Add (not Edit) on the details page and it opens the add sheet; the moderation DM shows no Add. - `flutter analyze` is clean. The DM sheet, details and confirmation dialog tests pass on90d9c56d8(rebased on main). The iOS alert merged with main's non-destructive confirm option. The90d9c56d8push skipped the pre-push hook because `flutter analyze` fails on main itself (`native_media_headers_test.dart` references an undefined `videoPreviewFrameLoaderProvider`, from #9144); the full channels suite passed on 9421a7976, and the push hook runs the mobile checks. - The screenshots below come from a temporary headless widget render with test data. It is not committed. The iOS native alert can't render headlessly, so the dialog shots show the Android dialog. | | Light | Dark | |---|---|---| | Details, narrow |  |  | | Details, wide |  |  | | Choice, narrow |  |  | | Choice, wide |  |  | Not yet done: a human test on a device against a relay running #9125. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Signed-off-by: morgmart <98432065+morgmart@users.noreply.github.com> Signed-off-by: Tom Brow <tomb@squareup.com> Signed-off-by: Tom Brow <tomb@block.xyz> Co-authored-by: Carl <c217fe6b9d958f41c3a5e030dccc7f626775a923089cb6491305eade75ea1f1b@buzz.block.builderlab.xyz> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Tom Brow <tomb@block.xyz> Co-authored-by: Tom Brow <tomb@squareup.com> Co-authored-by: studio <dc2fc481343672df31a689840c09299972e704dac592e0da6f18486646a7ee3e@buzz.block.builderlab.xyz>
223 lines
7.7 KiB
Dart
223 lines
7.7 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:buzz/features/channels/channel.dart';
|
|
import 'package:buzz/features/channels/channel_actions_sheet.dart';
|
|
import 'package:buzz/features/channels/channel_detail_page.dart';
|
|
import 'package:buzz/features/channels/channel_management_provider.dart';
|
|
import 'package:buzz/features/channels/compose_bar.dart';
|
|
import 'package:buzz/features/profile/user_profile_sheet.dart';
|
|
import 'package:buzz/shared/me/me_sync.dart';
|
|
import 'package:buzz/shared/mentions/agent_identity_provider.dart';
|
|
import 'package:buzz/shared/profile/user_cache_provider.dart';
|
|
import 'package:buzz/shared/profile/user_profile.dart';
|
|
import 'package:buzz/shared/theme/theme.dart';
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
void main() {
|
|
final peer = 'a' * 64;
|
|
|
|
for (final nativeSheet in [false, true]) {
|
|
testWidgets(
|
|
'Message opens the DM without waiting on Solo (native sheet: $nativeSheet)',
|
|
(tester) async {
|
|
final dm = Channel(
|
|
id: 'dm-peer',
|
|
name: 'Peer',
|
|
channelType: 'dm',
|
|
visibility: 'private',
|
|
description: '',
|
|
memberCount: 2,
|
|
createdBy: 'self',
|
|
createdAt: DateTime(2025),
|
|
isMember: true,
|
|
);
|
|
final solo = Channel(
|
|
id: 'solo-project',
|
|
name: 'Project',
|
|
channelType: 'group',
|
|
visibility: 'private',
|
|
description: '',
|
|
memberCount: 2,
|
|
createdBy: 'self',
|
|
createdAt: DateTime(2025),
|
|
isMember: true,
|
|
);
|
|
tester.view.physicalSize = const Size(390, 844);
|
|
tester.view.devicePixelRatio = 1;
|
|
addTearDown(tester.view.reset);
|
|
addTearDown(() => debugDefaultTargetPlatformOverride = null);
|
|
const bridge = MethodChannel('buzz/channel_actions_sheet');
|
|
Completer<String?>? nativeResult;
|
|
var presentations = 0;
|
|
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(bridge, (
|
|
call,
|
|
) async {
|
|
if (call.method == 'present') {
|
|
presentations++;
|
|
nativeResult = Completer<String?>();
|
|
return nativeResult!.future;
|
|
}
|
|
return null;
|
|
});
|
|
addTearDown(
|
|
() => tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
|
|
bridge,
|
|
null,
|
|
),
|
|
);
|
|
final opened = <List<String>>[];
|
|
final waits = <bool>[];
|
|
SharedPreferences.setMockInitialValues({});
|
|
final prefs = await SharedPreferences.getInstance();
|
|
await tester.pumpWidget(
|
|
ProviderScope(
|
|
overrides: [
|
|
currentPubkeyProvider.overrideWith((ref) => 'self'),
|
|
agentOwnersProvider.overrideWithValue(
|
|
const AsyncValue.data(<String, String>{}),
|
|
),
|
|
channelMembersProvider(solo.id).overrideWith(
|
|
(ref) async => [
|
|
ChannelMember(
|
|
pubkey: peer,
|
|
role: 'member',
|
|
joinedAt: DateTime(2025),
|
|
),
|
|
],
|
|
),
|
|
userCacheProvider.overrideWith(
|
|
() => _UserCache({
|
|
peer: UserProfile(pubkey: peer, displayName: 'Peer'),
|
|
}),
|
|
),
|
|
channelActionsProvider.overrideWith(
|
|
(ref) => _FakeDmActions(dm, opened, waits),
|
|
),
|
|
savedPrefsProvider.overrideWithValue(prefs),
|
|
// Solo organization is still loading.
|
|
meGroupsProvider.overrideWith((ref) => const Stream.empty()),
|
|
],
|
|
child: MaterialApp(
|
|
theme: AppTheme.light(),
|
|
home: Builder(
|
|
builder: (context) => Scaffold(
|
|
body: TextButton(
|
|
onPressed: () => nativeSheet
|
|
? showChannelDetailsSheet(
|
|
context: context,
|
|
channel: solo,
|
|
currentPubkey: 'self',
|
|
personalChat: true,
|
|
onMemberTap: (context, pubkey) =>
|
|
showUserProfileSheet(context, pubkey),
|
|
)
|
|
: showUserProfileSheet(context, peer),
|
|
child: const Text('Open profile'),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
Future<void> openProfile() async {
|
|
if (nativeSheet) {
|
|
tester.view.physicalSize = const Size(1200, 800);
|
|
tester.view.padding = const FakeViewPadding(right: 76);
|
|
tester.view.viewPadding = tester.view.padding;
|
|
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
|
|
await tester.pumpAndSettle();
|
|
}
|
|
await tester.tap(find.text('Open profile'));
|
|
await tester.pumpAndSettle();
|
|
if (nativeSheet) {
|
|
// UIKit selection is the OS boundary; follow-up profile/DM routes are real.
|
|
debugDefaultTargetPlatformOverride = null;
|
|
expect(nativeResult, isNotNull);
|
|
expect(
|
|
nativeResult!.isCompleted,
|
|
isFalse,
|
|
reason: 'The underlying list must accept another tap',
|
|
);
|
|
nativeResult!.complete('member:$peer');
|
|
await tester.pumpAndSettle();
|
|
}
|
|
expect(find.byType(UserProfileSheet), findsOneWidget);
|
|
}
|
|
|
|
await openProfile();
|
|
if (nativeSheet) {
|
|
Navigator.of(tester.element(find.byType(UserProfileSheet))).pop();
|
|
await tester.pumpAndSettle();
|
|
// A stranded transparent owner route prevents this real tap from opening again.
|
|
await openProfile();
|
|
expect(presentations, 2);
|
|
}
|
|
await tester.tap(find.text('Message'));
|
|
await tester.pump();
|
|
await tester.pump(const Duration(seconds: 1));
|
|
|
|
expect(opened, [
|
|
[peer],
|
|
]);
|
|
// The page opens at once instead of waiting on the full channel list.
|
|
expect(waits, [false]);
|
|
expect(
|
|
tester
|
|
.widget<ChannelDetailPage>(find.byType(ChannelDetailPage))
|
|
.channel,
|
|
dm,
|
|
);
|
|
// The DM is usable at once, not a placement spinner.
|
|
expect(find.byType(ComposeBar), findsOneWidget);
|
|
if (nativeSheet) {
|
|
Navigator.of(tester.element(find.byType(ChannelDetailPage))).pop();
|
|
await tester.pumpAndSettle();
|
|
await openProfile();
|
|
expect(presentations, 3);
|
|
Navigator.of(tester.element(find.byType(UserProfileSheet))).pop();
|
|
await tester.pumpAndSettle();
|
|
}
|
|
},
|
|
);
|
|
}
|
|
}
|
|
|
|
class _UserCache extends UserCacheNotifier {
|
|
_UserCache(this._initial);
|
|
|
|
final Map<String, UserProfile> _initial;
|
|
|
|
@override
|
|
Map<String, UserProfile> build() => _initial;
|
|
|
|
@override
|
|
Future<bool> preload(List<String> pubkeys) async => true;
|
|
}
|
|
|
|
class _FakeDmActions implements ChannelActions {
|
|
_FakeDmActions(this.dm, this.opened, this.waits);
|
|
|
|
final Channel dm;
|
|
final List<List<String>> opened;
|
|
final List<bool> waits;
|
|
|
|
@override
|
|
Future<Channel> openDm({
|
|
required List<String> pubkeys,
|
|
bool waitForChannelList = true,
|
|
bool includeHistory = false,
|
|
}) async {
|
|
opened.add(pubkeys);
|
|
waits.add(waitForChannelList);
|
|
return dm;
|
|
}
|
|
|
|
@override
|
|
dynamic noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
|
|
}
|