mirror of
https://github.com/block/buzz.git
synced 2026-11-12 04:12:21 +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>
214 lines
7.1 KiB
Swift
214 lines
7.1 KiB
Swift
import BuzzPushKit
|
|
import Flutter
|
|
import Foundation
|
|
import Intents
|
|
import UserNotifications
|
|
|
|
final class BuzzPushSnapshotBridge {
|
|
private let containerURL: () -> URL?
|
|
private let endpointGrantStore: BuzzPushEndpointGrantKeychainStore
|
|
private let interactionDeletionDeadline: BuzzInteractionDeletionDeadline
|
|
private let keychainAccessGroup: String?
|
|
private let queue = DispatchQueue(
|
|
label: "xyz.block.buzz.push-snapshot",
|
|
qos: .utility
|
|
)
|
|
private lazy var store: BuzzPushPresentationCacheStore? = {
|
|
guard let container = containerURL() else { return nil }
|
|
return BuzzPushPresentationCacheStore(containerURL: container)
|
|
}()
|
|
private let ageRestrictionSession = BuzzAgeRestrictionSession()
|
|
|
|
init(
|
|
appGroupIdentifier: String?,
|
|
endpointGrantStore: BuzzPushEndpointGrantKeychainStore,
|
|
keychainAccessGroup: String?,
|
|
containerURL: (() -> URL?)? = nil,
|
|
interactionDeletionDeadline: BuzzInteractionDeletionDeadline =
|
|
BuzzInteractionDeletionDeadline(
|
|
timeout: 5,
|
|
deleteAllInteractions: { completion in
|
|
INInteraction.deleteAll(completion: completion)
|
|
},
|
|
scheduleTimeout: { delay, action in
|
|
DispatchQueue.global(qos: .utility).asyncAfter(
|
|
deadline: .now() + delay,
|
|
execute: action
|
|
)
|
|
}
|
|
)
|
|
) {
|
|
self.containerURL = containerURL ?? {
|
|
guard let appGroupIdentifier else { return nil }
|
|
return FileManager.default.containerURL(
|
|
forSecurityApplicationGroupIdentifier: appGroupIdentifier)
|
|
}
|
|
self.endpointGrantStore = endpointGrantStore
|
|
self.keychainAccessGroup = keychainAccessGroup
|
|
self.interactionDeletionDeadline = interactionDeletionDeadline
|
|
}
|
|
|
|
@discardableResult
|
|
func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) -> Bool {
|
|
if call.method == "restoreAgeRestrictedNotifications" {
|
|
queue.async { [self] in
|
|
ageRestrictionSession.release()
|
|
BuzzInteractionCleanupRetry(
|
|
containerURL: containerURL(), deletion: interactionDeletionDeadline
|
|
).retryPending { error in
|
|
Self.complete(result, value: error.map {
|
|
FlutterError(code: "interaction_cleanup_retry_failed",
|
|
message: "Unable to finish pending interaction cleanup.",
|
|
details: $0.localizedDescription)
|
|
})
|
|
}
|
|
}
|
|
return true
|
|
}
|
|
if call.method == "purgeAgeRestrictedNotifications" {
|
|
purgeAgeRestrictedNotifications(result: result)
|
|
return true
|
|
}
|
|
guard call.method == "syncPushSnapshot",
|
|
let arguments = call.arguments as? [String: Any],
|
|
let section = arguments["section"] as? String
|
|
else {
|
|
return false
|
|
}
|
|
switch section {
|
|
case "communities":
|
|
syncCommunities(arguments, result: result)
|
|
default: return false
|
|
}
|
|
return true
|
|
}
|
|
|
|
private func purgeAgeRestrictedNotifications(result: @escaping FlutterResult) {
|
|
queue.async { [weak self] in
|
|
do {
|
|
guard let self, let container = containerURL() else {
|
|
throw NSError(
|
|
domain: "BuzzPushSnapshotBridge",
|
|
code: 1,
|
|
userInfo: [
|
|
NSLocalizedDescriptionKey: "The age-restriction session container is unavailable."
|
|
]
|
|
)
|
|
}
|
|
try ageRestrictionSession.restrict(containerURL: container)
|
|
// Preserve snapshots and credentials. Restriction authority expires
|
|
// with this process even when cleanup or a later storage read fails.
|
|
let center = UNUserNotificationCenter.current()
|
|
center.removeAllDeliveredNotifications()
|
|
center.removeAllPendingNotificationRequests()
|
|
BuzzInteractionCleanupRetry(
|
|
containerURL: container, deletion: interactionDeletionDeadline
|
|
).request { error in
|
|
Self.complete(
|
|
result,
|
|
value: error.map {
|
|
FlutterError(
|
|
code: "age_restriction_purge_failed",
|
|
message: "Unable to suppress and purge restricted notifications.",
|
|
details: $0.localizedDescription
|
|
)
|
|
}
|
|
)
|
|
}
|
|
} catch {
|
|
Self.complete(
|
|
result,
|
|
value: FlutterError(
|
|
code: "age_restriction_purge_failed",
|
|
message: "Unable to suppress and purge restricted notifications.",
|
|
details: error.localizedDescription
|
|
)
|
|
)
|
|
}
|
|
}
|
|
}
|
|
|
|
private func syncCommunities(
|
|
_ arguments: [String: Any],
|
|
result: @escaping FlutterResult
|
|
) {
|
|
guard let communities = arguments["communities"] as? [[String: Any]],
|
|
let signingKeys = arguments["signingKeys"] as? [String: String],
|
|
communities.count <= BuzzPushPresentationCacheStore.maximumCommunities
|
|
else {
|
|
result(
|
|
FlutterError(
|
|
code: "invalid_arguments",
|
|
message: "Expected bounded communities and signing keys.",
|
|
details: nil
|
|
)
|
|
)
|
|
return
|
|
}
|
|
queue.async { [weak self] in
|
|
do {
|
|
guard let self else {
|
|
Self.complete(result, value: nil)
|
|
return
|
|
}
|
|
guard let store else {
|
|
Self.complete(result, value: nil)
|
|
return
|
|
}
|
|
// Relay-metadata enrichment is optional presentation state. A damaged
|
|
// grant cache must not block the core NSE snapshot and key update.
|
|
let grants = (try? endpointGrantStore.records()) ?? []
|
|
let enriched = communities.map { community -> [String: Any] in
|
|
var community = community
|
|
guard let relayURL = community["relayUrl"] as? String,
|
|
let relayMetadataPubkey = Self.relayMetadataPubkey(
|
|
relayURL: relayURL,
|
|
grants: grants
|
|
)
|
|
else { return community }
|
|
community["relayMetadataPubkey"] = relayMetadataPubkey
|
|
return community
|
|
}
|
|
let data = try JSONSerialization.data(withJSONObject: enriched, options: [.sortedKeys])
|
|
let decoded = try JSONDecoder().decode([PushLeaseCommunity].self, from: data)
|
|
// Ordinary snapshot maintenance never changes age access.
|
|
try store.replaceCommunities(decoded)
|
|
try BuzzPushKeychain.replace(
|
|
signingKeys: signingKeys,
|
|
accessGroup: self.keychainAccessGroup
|
|
)
|
|
Self.complete(result, value: nil)
|
|
} catch {
|
|
Self.complete(
|
|
result,
|
|
value: FlutterError(
|
|
code: "snapshot_sync_failed",
|
|
message: "Unable to sync push community state.",
|
|
details: error.localizedDescription
|
|
)
|
|
)
|
|
}
|
|
}
|
|
}
|
|
|
|
static func relayMetadataPubkey(
|
|
relayURL: String,
|
|
grants: [BuzzPushEndpointGrantRecord]
|
|
) -> String? {
|
|
guard let origin = BuzzPushPresentationCacheStore.canonicalRelayOrigin(relayURL) else {
|
|
return nil
|
|
}
|
|
return grants.filter {
|
|
BuzzPushPresentationCacheStore.canonicalRelayOrigin($0.relayOrigin) == origin
|
|
}.max {
|
|
$0.generation < $1.generation
|
|
}?.relayMetadataPubkey
|
|
}
|
|
|
|
private static func complete(_ result: @escaping FlutterResult, value: Any?) {
|
|
DispatchQueue.main.async {
|
|
result(value)
|
|
}
|
|
}
|
|
}
|