mirror of
https://github.com/block/buzz.git
synced 2026-11-06 17:31:19 +00:00
## Summary Deletes mobile code that no longer has a user-reachable path and has no counterpart in buzz-app, so it is unlikely to come back for parity. Net: 104 files, about 5,500 lines removed. No intended behavior change. - **iOS native message menu and action surface:** `NativeMessageMenu.swift` and `NativeMessageActionSurface.swift`, the `message`/`supportsMessage` coordinator branches, and the Dart selection hook. Dart stopped creating this view in [#8280](https://github.com/block/buzz/pull/8280). The native reactions sheet in the same coordinator is kept. - **Old home quick-actions launcher and `ComposeMorphIcon`:** only instantiated in tests since the nav-bar creation actions replaced them. - **Retired local theme stack:** `ThemeNotifier`, `AccentNotifier`, `SchemeNotifier`, `adaptive_theme.dart`, `AccentPickerPage`, the appearance-mode sheet and their helpers. These predate per-community theme sync. The legacy prefs migration in `community_theme_preference.dart` is kept. - **Unused widgets:** `ProfileAvatar` and `MaskedAvatarBadge`. - **Push permission-status plumbing:** the iOS `notificationAuthorizationStatus`/`openNotificationSettings` handlers, plus the uncalled strict age-gate snapshot registration and its Swift `syncAgeGatePushSnapshot` path. - **Orphaned files** with no importer: `profile_text_edit_sheet`, `editor_option_button`, `retained_page_transition`, `tappable_flapping_bee`, `agent_model_info`, `community_bot_profiles`, `sheet_divider`, `success_haptic`. - **Uncalled helpers:** the `pickAndUpload*`/camera helpers in `media_upload.dart`, unused `NostrFilters` builders, `mediaGetHeadersFor*`, and about 20 other uncalled functions, providers and styles. - **Removed-UI leftovers:** the never-wired invite directory providers, `AuthNotifier.signOut` and `removeActiveCommunityForSignOut` (the Sign out row is gone), `renameCommunity`, `HomePage.profilePageBuilder`/`SettingsPage.embedded`, and the create-forum branches of the create-channel sheet. Forum viewing is unchanged. Tests that only covered deleted code are removed. Tests of surviving code that used deleted helpers as drivers were repointed to the surviving API. An audit of `mobile/android` found no dead Kotlin, resources, manifest entries or Gradle dependencies, so Android code is unchanged. ## Validation - `flutter analyze`: no issues. - After rebasing onto main ([93b8b8f](https://github.com/block/buzz/commit/93b8b8febc)), `just mobile-check` is clean (format and analyze), and `just mobile-test` passes (4,070 passed, 35 skipped, 0 failed, plus the push-unconfigured and secp256k1 suites). - `dart format`: clean. - Android: `just mobile-build-android` builds the debug APK, and `./gradlew :app:testDebugUnitTest` passes. - iOS: `build-for-testing` succeeds and BuzzPushKit `swift test` passes (65 tests). In RunnerTests, 97 of 98 pass. `testNativeNavigationTitleExpandsAgainAtTop` fails, but it fails the same way on unmodified `main` (acf56fff6f) on the same machine (Xcode 27, iPhone 17 Pro simulator), so it is not caused by this change. - Agent review of the diff ran. Its one blocker (stale `project.pbxproj` entries for the deleted Swift files) is fixed. - In-app smoke run at [66141c1](66141c10b9): a debug build on a fresh iPhone 17 Pro simulator (iOS 27), signed in to the internal community. The following flows all worked with no errors: - Home: the New menu (channel, DM, workspace, chat) and the create-channel sheet, including its channel-type options. - A chat, with the message action sheet (reactions row, Reply, Copy link, Remind me, Mark unread, Copy text, Edit and Delete). - Appearance: the previews, and cycling the System and Light modes. - Settings: the profile header, the display name editor, and Edit photo (Image and Emoji tabs). - The Agents directory. - Search, including the Channels filter, plus opening a team channel from the results. - Tapping a reaction summary, which opens the native iOS Reactions sheet. - The recording isn't attached here because it shows internal channels and messages. 🤖 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>
165 lines
5.6 KiB
Dart
165 lines
5.6 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
import 'package:nostr/nostr.dart' as nostr;
|
|
|
|
import 'relay_provider.dart';
|
|
import 'package:buzz/shared/crypto/event_signing.dart';
|
|
|
|
const _mediaGetAuthKind = 24242;
|
|
const _mediaGetAuthLifetimeSeconds = 60;
|
|
|
|
/// Re-sign this long before the cached auth event expires, so an in-flight
|
|
/// request signed just before the boundary still lands well within validity.
|
|
/// With a 60-second lifetime, the margin equals the lifetime: each request
|
|
/// mints a fresh token (mint-per-request pattern for NIP-FI compliance).
|
|
const _mediaGetAuthRefreshMarginSeconds = 60;
|
|
|
|
/// Builds BUD-01 Blossom `t=get` auth headers for relay-host media URLs.
|
|
///
|
|
/// Returns an empty map for non-relay URLs or when no signing key is available,
|
|
/// so callers can safely use this on arbitrary profile/custom-emoji URLs without
|
|
/// leaking Buzz credentials to third-party hosts.
|
|
///
|
|
/// With a 60-second proof lifetime the refresh margin equals the lifetime, so
|
|
/// `_refreshAt == signedAt` and the cache never hits: every call mints a fresh
|
|
/// proof (mint-per-request pattern). This is intentional for NIP-FI compliance
|
|
/// — caching a 60-second token is staleness-prone and provides no meaningful
|
|
/// reduction in signing work. The service itself is rebuilt whenever the relay
|
|
/// config — base URL or signing identity — changes, via
|
|
/// [mediaGetAuthServiceProvider].
|
|
class MediaGetAuthService {
|
|
final String _baseUrl;
|
|
final String? _nsec;
|
|
final String? _pubkey;
|
|
final DateTime Function() _now;
|
|
|
|
Map<String, String>? _cachedHeaders;
|
|
DateTime? _refreshAt;
|
|
|
|
MediaGetAuthService({
|
|
required String baseUrl,
|
|
required String? nsec,
|
|
String? pubkey,
|
|
DateTime Function()? now,
|
|
}) : _baseUrl = baseUrl,
|
|
_nsec = nsec,
|
|
_pubkey = pubkey,
|
|
_now = now ?? DateTime.now;
|
|
|
|
bool isRelayMediaUrl(String url) {
|
|
final uri = Uri.tryParse(url);
|
|
final relayUri = Uri.tryParse(_baseUrl);
|
|
if (uri == null || relayUri == null) return false;
|
|
return _isRelayMediaUrl(uri, relayUri);
|
|
}
|
|
|
|
Map<String, String> headersFor(String url) {
|
|
final nsec = _nsec;
|
|
if (nsec == null || nsec.isEmpty) return const {};
|
|
if (!isRelayMediaUrl(url)) return const {};
|
|
|
|
final cached = _cachedHeaders;
|
|
final refreshAt = _refreshAt;
|
|
if (cached != null && refreshAt != null && _now().isBefore(refreshAt)) {
|
|
return cached;
|
|
}
|
|
|
|
try {
|
|
final signedAt = _now();
|
|
final authEvent = _buildGetAuthEvent(nsec);
|
|
final encoded = base64Url
|
|
.encode(utf8.encode(authEvent.toJson()))
|
|
.replaceAll('=', '');
|
|
final headers = Map<String, String>.unmodifiable({
|
|
'Authorization': 'Nostr $encoded',
|
|
});
|
|
_cachedHeaders = headers;
|
|
_refreshAt = signedAt.add(
|
|
const Duration(
|
|
seconds:
|
|
_mediaGetAuthLifetimeSeconds - _mediaGetAuthRefreshMarginSeconds,
|
|
),
|
|
);
|
|
return headers;
|
|
} catch (_) {
|
|
// Read auth is best-effort: while the relay rollout flag is off, an
|
|
// unsigned fetch still works. Once the flag is on, this request will 403
|
|
// instead of crashing the widget tree because local key material is bad.
|
|
return const {};
|
|
}
|
|
}
|
|
|
|
bool _isRelayMediaUrl(Uri uri, Uri relayUri) {
|
|
if (uri.scheme != 'http' && uri.scheme != 'https') return false;
|
|
if (uri.host.isEmpty || relayUri.host.isEmpty) return false;
|
|
// Extract the URL's origin and path. Query strings are ignored for media
|
|
// host/path detection, matching the fetch target shape used by descriptors.
|
|
final base = '${uri.scheme}://${uri.authority}';
|
|
final mediaAuthority = extractServerAuthority(base);
|
|
final relayAuthority = extractServerAuthority(_baseUrl);
|
|
if (mediaAuthority == null || relayAuthority == null) return false;
|
|
if (mediaAuthority.toLowerCase() != relayAuthority.toLowerCase()) {
|
|
return false;
|
|
}
|
|
return uri.path.startsWith('/media/');
|
|
}
|
|
|
|
nostr.Event _buildGetAuthEvent(String nsec) {
|
|
final privkeyHex = nostr.Nip19.decode(payload: nsec).data;
|
|
if (privkeyHex.isEmpty) {
|
|
throw Exception('Invalid nsec');
|
|
}
|
|
|
|
final expiration =
|
|
(_now().millisecondsSinceEpoch ~/ 1000) + _mediaGetAuthLifetimeSeconds;
|
|
final tags = <List<String>>[
|
|
['t', 'get'],
|
|
['expiration', '$expiration'],
|
|
if (extractServerAuthority(_baseUrl) case final authority?)
|
|
['server', authority],
|
|
];
|
|
|
|
return signNostrEvent(
|
|
kind: _mediaGetAuthKind,
|
|
content: 'Get buzz-media',
|
|
tags: tags,
|
|
secretKey: privkeyHex,
|
|
// Reuse the cached pubkey rather than deriving it per image.
|
|
pubkey: _pubkey,
|
|
);
|
|
}
|
|
}
|
|
|
|
final mediaGetAuthServiceProvider = Provider<MediaGetAuthService>((ref) {
|
|
final config = ref.watch(relayConfigProvider);
|
|
return MediaGetAuthService(
|
|
baseUrl: config.baseUrl,
|
|
nsec: config.nsec,
|
|
pubkey: ref.watch(myPubkeyProvider),
|
|
);
|
|
});
|
|
|
|
String? extractServerAuthority(String baseUrl) {
|
|
final uri = Uri.parse(baseUrl);
|
|
if (uri.host.isEmpty) return null;
|
|
final host = uri.host.contains(':') ? '[${uri.host}]' : uri.host;
|
|
final port = uri.hasPort ? uri.port : null;
|
|
final authority = port == null ? host : '$host:$port';
|
|
return _normalizeAuthority(authority);
|
|
}
|
|
|
|
String _normalizeAuthority(String authority) {
|
|
var normalized = authority.trim().toLowerCase();
|
|
if (normalized.endsWith('.')) {
|
|
normalized = normalized.substring(0, normalized.length - 1);
|
|
}
|
|
if (normalized.endsWith(':443')) {
|
|
return normalized.substring(0, normalized.length - ':443'.length);
|
|
}
|
|
if (normalized.endsWith(':80')) {
|
|
return normalized.substring(0, normalized.length - ':80'.length);
|
|
}
|
|
return normalized;
|
|
}
|