Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions desktop/ox-mobile/PushBridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
static NSString *const OXAlertKindKey = @"kind";
static NSString *const OXPairingHintKey = @"pairing_hint";

// Contract ids for lock-screen approval actions. They are fixed identifiers,
// never localized button titles, and this bridge registers no actions yet.
// Contract ids for lock-screen approval actions, separate from the button titles.
static NSString *const OXApprovalActionsCategory = @"OX_APPROVAL_ACTIONS";
static NSString *const OXAllowOnceActionIdentifier = @"AllowOnce";
static NSString *const OXDenyActionIdentifier = @"Deny";
Expand Down Expand Up @@ -99,8 +98,6 @@ - (BOOL)rememberResponse:(NSString *)identifier {

- (void)captureResponse:(UNNotificationResponse *)response {
// The two action ids are the only custom responses this bridge understands.
// It registers no actions, so they can only arrive from notification
// content that already names this category.
OXPushAlertIntent intent;
if ([response.actionIdentifier isEqualToString:UNNotificationDefaultActionIdentifier]) {
intent = OXPushAlertIntentDefault;
Expand Down Expand Up @@ -190,7 +187,25 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center
static dispatch_once_t once;
dispatch_once(&once, ^{
bridge = [[OXPushBridge alloc] init];
UNUserNotificationCenter.currentNotificationCenter.delegate = bridge;
UNUserNotificationCenter *center = UNUserNotificationCenter.currentNotificationCenter;
center.delegate = bridge;
// The app needs a foreground signed lookup and a live subscription to
// verify the exact request. iOS unlocks the device before handing it over.
UNNotificationActionOptions options =
UNNotificationActionOptionAuthenticationRequired | UNNotificationActionOptionForeground;
UNNotificationAction *allow =
[UNNotificationAction actionWithIdentifier:OXAllowOnceActionIdentifier
title:@"Allow once" options:options];
UNNotificationAction *deny =
[UNNotificationAction actionWithIdentifier:OXDenyActionIdentifier
title:@"Deny"
options:options | UNNotificationActionOptionDestructive];
UNNotificationCategory *category =
[UNNotificationCategory categoryWithIdentifier:OXApprovalActionsCategory
actions:@[allow, deny]
intentIdentifiers:@[]
options:0];
[center setNotificationCategories:[NSSet setWithObject:category]];
});
return bridge;
}
Expand Down
15 changes: 7 additions & 8 deletions desktop/ox-mobile/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,13 @@ started after it. The bridge adds no APNs entitlement, so the unsigned
simulator launch check runs without one.

The relay may mark an approval alert with the fixed `OX_APPROVAL_ACTIONS`
category. If such an alert returns the fixed `AllowOnce` or `Deny` action
identifiers, the bridge accepts them only as the exact approval envelope: an
approval reference with no session reference or `kind` field, a canonical
43-character reference and its canonical pairing hint. Those responses become
a typed `AlertIntent` on the buffered tap. This slice registers no
notification actions, so it cannot create the buttons, and it dispatches no
decision: the existing review path opens as it does for an ordinary tap.
Question and session alerts never produce an action intent.
category. iOS brings OX Mobile to the foreground for **Allow once** or **Deny**
and asks the user to unlock if needed. The app checks the canonical approval
reference and pairing hint, reads the same phone's signed opt-in from the
host, and verifies the exact request against the live conversation. It sends
the selected decision only when the host supplies the current allow-once and
deny indices for that request. Otherwise it opens the request for review when
available. Question and session alerts use the ordinary open action.

On iPhone, open **Host settings → Notifications** on a paired host. Until the
phone has said yes or no for a pairing, the home screen offers to turn alerts
Expand Down
79 changes: 66 additions & 13 deletions desktop/ox-mobile/src/mobile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ use crate::{
#[cfg(target_os = "ios")]
use crate::push;
#[cfg(any(target_os = "ios", all(target_os = "android", feature = "android-fcm")))]
use crate::push::AlertKind;
use crate::push::{AlertIntent, AlertKind};
#[cfg(any(target_os = "ios", all(target_os = "android", feature = "android-fcm")))]
use crate::tap::{self, Phase as TapPhase, Resolution as TapResolution, Taps};
mod attachment_picker;
Expand Down Expand Up @@ -3277,7 +3277,7 @@ impl Mobile {
return;
}
let confirmed = match &live {
Some(tap::Verified::Approval(_, ask)) => {
Some(tap::Verified::Approval(_, ask, _)) => {
app.tap.confirm(*generation, ask.reference().as_deref()) == Some(true)
}
Some(tap::Verified::Session(_)) => app.tap.confirm_session(*generation),
Expand Down Expand Up @@ -3478,8 +3478,8 @@ impl Mobile {
}
#[cfg(any(target_os = "ios", all(target_os = "android", feature = "android-fcm")))]
match exact {
Some(tap::Verified::Approval(thread, ask)) => {
app.show_tapped(thread, ask, window, cx);
Some(tap::Verified::Approval(thread, ask, intent)) => {
app.show_tapped(thread, ask, intent, window, cx);
}
Some(tap::Verified::Session(thread)) => app.open_thread(thread, window, cx),
None => {}
Expand Down Expand Up @@ -4602,10 +4602,11 @@ impl Mobile {
let Some(tap) = push::drain_taps().into_iter().last() else {
return;
};
self.follow_tap(
self.follow_notification(
tap.kind,
tap.reference.as_str(),
&tap.pairing_hint,
tap.intent,
window,
cx,
);
Expand Down Expand Up @@ -4649,16 +4650,34 @@ impl Mobile {
}
}

#[cfg(all(target_os = "android", feature = "android-fcm"))]
fn follow_tap(
&mut self,
kind: AlertKind,
reference: &str,
hint: &crate::approval_routing::TapHint,
window: &mut Window,
cx: &mut Context<Self>,
) {
self.follow_notification(kind, reference, hint, AlertIntent::Default, window, cx);
}

fn follow_notification(
&mut self,
kind: AlertKind,
reference: &str,
hint: &crate::approval_routing::TapHint,
intent: AlertIntent,
window: &mut Window,
cx: &mut Context<Self>,
) {
use crate::approval_routing::TapHint;

let intent = if kind == AlertKind::Approval && matches!(hint, TapHint::Routed(_)) {
intent
} else {
AlertIntent::Default
};
if self.screen == Screen::Pair && !self.recovering_tap_startup {
return;
}
Expand Down Expand Up @@ -4716,7 +4735,7 @@ impl Mobile {
Ok(true) if destination.still_eligible() => {
app.lookup_tap(
(client, Some(destination)),
(kind, reference),
(kind, reference, intent),
generation,
window,
cx,
Expand All @@ -4739,7 +4758,13 @@ impl Mobile {
}));
cx.notify();
} else {
self.lookup_tap((client, None), (kind, reference), generation, window, cx);
self.lookup_tap(
(client, None),
(kind, reference, intent),
generation,
window,
cx,
);
}
}

Expand All @@ -4754,7 +4779,7 @@ impl Mobile {
fn lookup_tap(
&mut self,
(client, destination): (PairedClient, Option<remote::ApprovalPairing>),
(kind, reference): (AlertKind, String),
(kind, reference, intent): (AlertKind, String, AlertIntent),
generation: u64,
window: &mut Window,
cx: &mut Context<Self>,
Expand All @@ -4765,7 +4790,18 @@ impl Mobile {
match kind {
AlertKind::Approval => Ok(match client.lookup_approval(&reference).await? {
ApprovalLookup::Available { scope, thread } => {
Some((scope, tap::Thread::Approval(thread)))
// The tap remains review-only unless the same signed
// pairing confirms the explicit notification opt-in.
let preference = if intent != AlertIntent::Default {
client
.settings(serde_json::json!({"action": "native_push_approval_actions"}))
.await
.ok()
} else {
None
};
let intent = tap::opted_in_intent(intent, preference.as_ref());
Some((scope, tap::Thread::Approval(thread, intent)))
}
ApprovalLookup::Unavailable => None,
}),
Expand Down Expand Up @@ -4927,15 +4963,15 @@ impl Mobile {
///
/// The thread's ask is checked before the selection or the composer moves,
/// so an expired tap leaves the current screen and draft exactly as they
/// were. No decision is sent and no field is filled.
/// were. A default tap opens the approval for review.
fn open_tapped(
&mut self,
generation: u64,
target: TappedAlert,
window: &mut Window,
cx: &mut Context<Self>,
) {
let tap::Thread::Approval(thread) = target.thread else {
let tap::Thread::Approval(thread, intent) = target.thread else {
return;
};
let Some(reference) = self.tap.reference(generation) else {
Expand All @@ -4950,7 +4986,7 @@ impl Mobile {
if let Some(destination) = &target.destination {
self.bind_tapped_alerts(&destination.identity);
}
self.show_tapped(thread, ask, window, cx);
self.show_tapped(thread, ask, intent, window, cx);
}
_ => cx.notify(),
}
Expand All @@ -4961,6 +4997,7 @@ impl Mobile {
&mut self,
thread: Option<String>,
ask: tap::OpenAsk,
intent: AlertIntent,
window: &mut Window,
cx: &mut Context<Self>,
) {
Expand All @@ -4982,8 +5019,24 @@ impl Mobile {
// owner, so no thread is selected.
self.creating = true;
}
self.opened_ask = Some(tap::OpenedAsk::Live(ask));
self.navigate(Screen::Conversation, window, cx);
// The rendered store must still hold the same live token and owner.
let decision = self
.store()
.filter(|store| store.state() == &Connection::Ready)
.and_then(|store| ask.decision(store, self.owner(), intent));
// Local dispatch can succeed before the host sees the decision. Keep
// the pinned request until the host removes it, so it can be retried.
self.opened_ask = Some(tap::OpenedAsk::Live(ask));
if let Some(decision) = decision
&& self.action(decision, window, cx)
{
self.notice = Some(match intent {
AlertIntent::AllowOnce => "Approval sent.".into(),
AlertIntent::Deny => "Denial sent.".into(),
AlertIntent::Default => unreachable!("a default tap cannot send a decision"),
});
}
self.refresh_conversation(window, cx);
cx.notify();
}
Expand Down
Loading
Loading