Files
buzz/mobile/lib/features/activity/reminders_provider.dart
Tom Brow f6f6d9a673 chore(mobile): delete dead code with no remaining UI path (#8880)
## 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>
2026-11-01 14:09:50 -08:00

218 lines
6.0 KiB
Dart

import 'dart:convert';
import 'package:flutter/foundation.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:nostr/nostr.dart' as nostr;
import '../../shared/crypto/nip44.dart';
import '../../shared/relay/relay.dart';
/// NIP-ER event reminder kind — matches desktop's `KIND_EVENT_REMINDER`.
const kindEventReminder = 30300;
/// Message a reminder points at. Mirrors desktop's `ReminderTarget`.
@immutable
class ReminderTarget {
final String eventId;
final String channelId;
final String preview;
final String authorPubkey;
const ReminderTarget({
required this.eventId,
required this.channelId,
required this.preview,
required this.authorPubkey,
});
}
/// A decrypted NIP-ER reminder. Mirrors desktop's `Reminder`.
@immutable
class Reminder {
/// The `d`-tag (unique reminder identity).
final String id;
/// Unix seconds when due; null for done/cancelled reminders.
final int? notBefore;
final String status; // "pending" | "done" | "cancelled"
final ReminderTarget? target;
final String? note;
final int createdAt;
final String eventId;
const Reminder({
required this.id,
required this.notBefore,
required this.status,
required this.target,
required this.note,
required this.createdAt,
required this.eventId,
});
bool isDue(int nowUnixSeconds) =>
status == 'pending' && notBefore != null && notBefore! <= nowUnixSeconds;
}
/// Parse NIP-ER `not_before`: ASCII digits, no leading zero except "0".
/// Mirrors desktop's `parseNotBefore` strictness.
int? parseNotBefore(String raw) {
if (!RegExp(r'^(0|[1-9][0-9]*)$').hasMatch(raw)) return null;
return int.tryParse(raw);
}
/// Validate decrypted reminder plaintext — desktop's `parseReminderContent`.
/// Off-shape content fails closed (returns null).
({String status, ReminderTarget? target, String? note})? parseReminderContent(
String plaintext,
) {
final Object? parsed;
try {
parsed = jsonDecode(plaintext);
} catch (_) {
return null;
}
if (parsed is! Map<String, dynamic>) return null;
final status = parsed['status'];
if (status != 'pending' && status != 'done' && status != 'cancelled') {
return null;
}
final note = parsed['note'];
if (note != null && note is! String) return null;
ReminderTarget? target;
final rawTarget = parsed['target'];
if (rawTarget != null) {
if (rawTarget is! Map<String, dynamic>) return null;
final eventId = rawTarget['eventId'];
final channelId = rawTarget['channelId'];
final preview = rawTarget['preview'];
final authorPubkey = rawTarget['authorPubkey'];
if (eventId is! String ||
channelId is! String ||
preview is! String ||
authorPubkey is! String) {
return null;
}
target = ReminderTarget(
eventId: eventId,
channelId: channelId,
preview: preview,
authorPubkey: authorPubkey,
);
}
final noteText = note as String?;
if (target == null && (noteText == null || noteText.isEmpty)) return null;
return (status: status as String, target: target, note: noteText);
}
/// Decode one kind:30300 event into a [Reminder], or null when malformed.
Reminder? decodeReminderEvent(
NostrEvent event, {
required String Function(String ciphertext) decrypt,
}) {
String? dTag;
int? notBefore;
for (final tag in event.tags) {
if (tag.length >= 2 && tag[0] == 'd') dTag ??= tag[1];
if (tag.length >= 2 && tag[0] == 'not_before') {
notBefore ??= parseNotBefore(tag[1]);
}
}
if (dTag == null) return null;
final String plaintext;
try {
plaintext = decrypt(event.content);
} catch (_) {
return null;
}
final content = parseReminderContent(plaintext);
if (content == null) return null;
return Reminder(
id: dTag,
notBefore: notBefore,
status: content.status,
target: content.target,
note: content.note,
createdAt: event.createdAt,
eventId: event.id,
);
}
/// Fetches the user's NIP-ER reminders (kind 30300, self-encrypted). These
/// are the same relay events Buzz Desktop reads and writes, so reminders
/// created on Desktop appear here and vice versa.
class RemindersNotifier extends AsyncNotifier<List<Reminder>> {
@override
Future<List<Reminder>> build() {
ref.watch(relayConfigProvider);
ref.watch(relaySessionProvider);
return _fetch();
}
Future<List<Reminder>> _fetch() async {
final config = ref.read(relayConfigProvider);
final myPk = ref.read(myPubkeyProvider);
final nsec = config.nsec?.trim();
if (myPk == null || nsec == null || nsec.isEmpty) return const [];
final String privkeyHex;
try {
privkeyHex = nostr.Nip19.decode(payload: nsec).data;
} catch (_) {
return const [];
}
if (privkeyHex.isEmpty) return const [];
final conversationKey = getConversationKey(privkeyHex, myPk);
final session = ref.read(relaySessionProvider.notifier);
final events = await session.fetchHistory(
NostrFilter(
kinds: const [kindEventReminder],
authors: [myPk],
limit: 200,
),
);
// Parameterized-replaceable: keep only the newest event per d-tag.
final newestByDTag = <String, NostrEvent>{};
for (final event in events) {
final dTag = event.getTagValue('d');
if (dTag == null) continue;
final existing = newestByDTag[dTag];
if (existing == null || event.createdAt > existing.createdAt) {
newestByDTag[dTag] = event;
}
}
final reminders = <Reminder>[];
for (final event in newestByDTag.values) {
final reminder = decodeReminderEvent(
event,
decrypt: (ciphertext) => nip44Decrypt(conversationKey, ciphertext),
);
if (reminder != null) reminders.add(reminder);
}
reminders.sort(
(a, b) =>
(a.notBefore ?? a.createdAt).compareTo(b.notBefore ?? b.createdAt),
);
return reminders;
}
Future<void> refresh() async {
state = await AsyncValue.guard(_fetch);
}
}
final remindersProvider =
AsyncNotifierProvider<RemindersNotifier, List<Reminder>>(
RemindersNotifier.new,
);