Repository navigation
Restore mobile push and fix cold-start dismissals #20068
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
d35c06d
Restore mobile push for delivery validation
Jinwoo-H 5c75198
fix(mobile): register push task before headless startup
Jinwoo-H d333130
Add authenticated mobile push test and fix iOS release entitlements
Jinwoo-H 98df0e2
Mock push-test transport in notification consent tests
Jinwoo-H d837b3e
Fix slept workspace test for structured remount result
Jinwoo-H 7dcb481
Fix mobile notification review findings
Jinwoo-H 0dfd3e3
Pad Android notification icon to prevent square cropping
Jinwoo-H 5773b03
fix(mobile): present visible Android data pushes in foreground
Jinwoo-H 8fe17a3
test: use deterministic clock for teardown deadline
Jinwoo-H 8f4a811
fix(mobile): present foreground pushes through Expo public APIs
Jinwoo-H de91281
fix(mobile): check push eligibility before foreground scheduling
Jinwoo-H c7b0e0b
fix(mobile): register push from shared host connection lifecycle
Jinwoo-H File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| // Why this file exists: a bare "expo-notifications" plugin entry writes | ||
| // `aps-environment: development` into the iOS entitlements, while push-token.ts | ||
| // reports `production` for every non-__DEV__ build. A TestFlight or App Store build | ||
| // would then register a production APNs token against a sandbox entitlement, and the | ||
| // gateway's pushes would be accepted by Apple and delivered nowhere. Deriving the | ||
| // mode from an env var the release workflow sets makes the two agree by construction | ||
| // instead of relying on the export step to rewrite the entitlement. | ||
| // | ||
| // app.json stays the source for everything else: Expo reads it first and hands it to | ||
| // this function, so the fastlane version/buildNumber rewrite still flows through. | ||
| const APS_ENVIRONMENT = | ||
| process.env.ORCA_IOS_APS_ENVIRONMENT === 'production' ? 'production' : 'development' | ||
|
|
||
| module.exports = ({ config }) => ({ | ||
| ...config, | ||
| ios: { | ||
| ...config.ios, | ||
| entitlements: { ...config.ios?.entitlements, 'aps-environment': APS_ENVIRONMENT } | ||
| }, | ||
| plugins: (config.plugins ?? []).map((plugin) => | ||
| plugin === 'expo-notifications' | ||
| ? [ | ||
| 'expo-notifications', | ||
| { | ||
| enableBackgroundRemoteNotifications: true, | ||
| mode: APS_ENVIRONMENT, | ||
| icon: './assets/notification-icon.png' | ||
| } | ||
| ] | ||
| : plugin | ||
| ) | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| { | ||
| "project_info": { | ||
| "project_number": "120364513935", | ||
| "project_id": "onorca-cloud", | ||
| "storage_bucket": "onorca-cloud.firebasestorage.app" | ||
| }, | ||
| "client": [ | ||
| { | ||
| "client_info": { | ||
| "mobilesdk_app_id": "1:120364513935:android:1d951dc430aeb9bc664efa", | ||
| "android_client_info": { | ||
| "package_name": "com.stably.orca.mobile" | ||
| } | ||
| }, | ||
| "oauth_client": [ | ||
| { | ||
| "client_id": "120364513935-evfa8502bp5r9hn7afhd9i03oibs8223.apps.googleusercontent.com", | ||
| "client_type": 3 | ||
| } | ||
| ], | ||
| "api_key": [ | ||
| { | ||
| "current_key": "AIzaSyBmT_w0OUQSiVfxblx-F0qlRvGkBBkTNQU" | ||
| } | ||
| ], | ||
| "services": { | ||
| "appinvite_service": { | ||
| "other_platform_oauth_client": [ | ||
| { | ||
| "client_id": "120364513935-evfa8502bp5r9hn7afhd9i03oibs8223.apps.googleusercontent.com", | ||
| "client_type": 3 | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| } | ||
| ], | ||
| "configuration_version": "1" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| // Headless notification launches do not mount the router layout. | ||
| import './src/notifications/push-background-dismissal' | ||
| import 'expo-router/entry' |
7 changes: 7 additions & 0 deletions
7
mobile/modules/orca-notification-dismissal/expo-module.config.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "platforms": ["apple"], | ||
| "apple": { | ||
| "modules": ["OrcaNotificationDismissalModule"], | ||
| "appDelegateSubscribers": ["OrcaNotificationDismissalSubscriber"] | ||
| } | ||
| } |
15 changes: 15 additions & 0 deletions
15
mobile/modules/orca-notification-dismissal/ios/OrcaNotificationDismissal.podspec
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| Pod::Spec.new do |s| | ||
| s.name = 'OrcaNotificationDismissal' | ||
| s.version = '0.0.1' | ||
| s.summary = 'Native notification dismissal and sequence fencing' | ||
| s.description = s.summary | ||
| s.license = { :type => 'MIT' } | ||
| s.author = 'Orca' | ||
| s.homepage = 'https://onorca.dev' | ||
| s.source = { :git => 'https://github.com/stablyai/orca.git' } | ||
| s.platforms = { :ios => '15.1' } | ||
| s.swift_version = '5.9' | ||
| s.static_framework = true | ||
| s.dependency 'ExpoModulesCore' | ||
| s.source_files = '**/*.swift' | ||
| end |
14 changes: 14 additions & 0 deletions
14
mobile/modules/orca-notification-dismissal/ios/OrcaNotificationDismissalModule.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import ExpoModulesCore | ||
|
|
||
| public class OrcaNotificationDismissalModule: Module { | ||
| public func definition() -> ModuleDefinition { | ||
| Name("OrcaNotificationDismissal") | ||
| AsyncFunction("remember") { (payload: [String: Any]) in | ||
| if let identity = PushDismissalIdentity(payload) { PushDismissalLedger.shared.remember(identity) } | ||
| } | ||
| AsyncFunction("wasDismissed") { (payload: [String: Any]) -> Bool in | ||
| guard let identity = PushDismissalIdentity(payload) else { return false } | ||
| return PushDismissalLedger.shared.contains(identity) | ||
| } | ||
| } | ||
| } |
26 changes: 26 additions & 0 deletions
26
mobile/modules/orca-notification-dismissal/ios/OrcaNotificationDismissalSubscriber.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import ExpoModulesCore | ||
| import UserNotifications | ||
|
|
||
| public class OrcaNotificationDismissalSubscriber: ExpoAppDelegateSubscriber { | ||
| public func application( | ||
| _ application: UIApplication, | ||
| didReceiveRemoteNotification userInfo: [AnyHashable: Any], | ||
| fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void | ||
| ) { | ||
| guard let payload = userInfo["orca"] as? [String: Any], | ||
| payload["kind"] as? String == "dismiss", let fence = PushDismissalIdentity(payload) | ||
| else { completionHandler(.noData); return } | ||
| PushDismissalLedger.shared.remember(fence) | ||
| let center = UNUserNotificationCenter.current() | ||
| center.getDeliveredNotifications { notifications in | ||
| let ids = notifications.compactMap { notification -> String? in | ||
| guard let data = notification.request.content.userInfo["orca"] as? [String: Any], | ||
| data["hostFingerprint"] as? String == fence.hostFingerprint, | ||
| PushDismissalLedger.shared.containsNotification(data) else { return nil } | ||
| return notification.request.identifier | ||
| } | ||
| center.removeDeliveredNotifications(withIdentifiers: ids) | ||
| completionHandler(ids.isEmpty ? .noData : .newData) | ||
| } | ||
| } | ||
| } |
67 changes: 67 additions & 0 deletions
67
mobile/modules/orca-notification-dismissal/ios/PushDismissalLedger.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| import Foundation | ||
| import CoreFoundation | ||
|
|
||
| struct PushDismissalIdentity: Codable { | ||
| let hostFingerprint: String | ||
| let notificationId: String | ||
| let notificationEpoch: String | ||
| let notificationSeq: Int64 | ||
|
|
||
| init?(_ value: [String: Any]) { | ||
| guard let host = value["hostFingerprint"] as? String, !host.isEmpty, host.count <= 512, | ||
| let id = value["notificationId"] as? String, !id.isEmpty, id.count <= 2048, | ||
| let epoch = value["notificationEpoch"] as? String, !epoch.isEmpty, epoch.count <= 128, | ||
| let seq = value["notificationSeq"] as? NSNumber, | ||
| CFGetTypeID(seq) != CFBooleanGetTypeID(), seq.doubleValue.isFinite, | ||
| seq.doubleValue >= 0, seq.doubleValue <= 9_007_199_254_740_991, | ||
| seq.doubleValue.rounded(.down) == seq.doubleValue else { return nil } | ||
| hostFingerprint = host; notificationId = id; notificationEpoch = epoch | ||
| notificationSeq = seq.int64Value | ||
| } | ||
|
|
||
| func matches(_ other: PushDismissalIdentity) -> Bool { | ||
| hostFingerprint == other.hostFingerprint && notificationId == other.notificationId && | ||
| notificationEpoch == other.notificationEpoch | ||
| } | ||
| } | ||
|
|
||
| final class PushDismissalLedger { | ||
| static let shared = PushDismissalLedger() | ||
| private struct Entry: Codable { let identity: PushDismissalIdentity; let expiresAt: TimeInterval } | ||
| private let defaults: UserDefaults | ||
| private let lock = NSLock() | ||
| private let storageKey = "orca.pushDismissals.v1" | ||
| init(defaults: UserDefaults = .standard) { self.defaults = defaults } | ||
|
|
||
| private func read(now: TimeInterval) -> [Entry] { | ||
| guard let data = defaults.data(forKey: storageKey), | ||
| let entries = try? JSONDecoder().decode([Entry].self, from: data) else { return [] } | ||
| return entries.filter { $0.expiresAt > now } | ||
| } | ||
|
|
||
| func remember(_ identity: PushDismissalIdentity, now: TimeInterval = Date().timeIntervalSince1970) { | ||
| lock.lock(); defer { lock.unlock() } | ||
| let entries = read(now: now) | ||
| let previous = entries.first { $0.identity.matches(identity) } | ||
| let newest = (previous?.identity.notificationSeq ?? -1) > identity.notificationSeq | ||
| ? previous!.identity : identity | ||
| // Keep every live fence: count-based eviction lets delayed alerts reappear. | ||
| let next = entries.filter { !$0.identity.matches(identity) } + | ||
| [Entry(identity: newest, expiresAt: now + 86400)] | ||
| if let data = try? JSONEncoder().encode(next) { | ||
| defaults.set(data, forKey: storageKey) | ||
| } | ||
| } | ||
|
|
||
| func contains(_ identity: PushDismissalIdentity, now: TimeInterval = Date().timeIntervalSince1970) -> Bool { | ||
| lock.lock(); defer { lock.unlock() } | ||
| return read(now: now).contains { | ||
| $0.identity.matches(identity) && $0.identity.notificationSeq >= identity.notificationSeq | ||
| } | ||
| } | ||
|
|
||
| func containsNotification(_ payload: [String: Any], now: TimeInterval = Date().timeIntervalSince1970) -> Bool { | ||
| guard let identity = PushDismissalIdentity(payload) else { return false } | ||
| return contains(identity, now: now) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "name": "orca-notification-dismissal", | ||
| "version": "0.0.1", | ||
| "private": true | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.