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
2 changes: 1 addition & 1 deletion desktop/ox-mobile/PushBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void ox_ios_push_bridge_authorization(uint64_t sequence,
int64_t error_code);
void ox_ios_push_bridge_registration_token(const uint8_t *bytes, uintptr_t length);
void ox_ios_push_bridge_registration_failed(int64_t error_code);
void ox_ios_push_bridge_tap(const uint8_t *bytes, uintptr_t length,
void ox_ios_push_bridge_tap(int32_t session, const uint8_t *bytes, uintptr_t length,
int32_t has_hint, const uint8_t *_Nullable hint_bytes,
uintptr_t hint_length);
void ox_ios_push_bridge_activated(void);
Expand Down
26 changes: 19 additions & 7 deletions desktop/ox-mobile/PushBridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

static NSString *const OXApprovalContainerKey = @"ox";
static NSString *const OXApprovalRefKey = @"approval_ref";
static NSString *const OXSessionRefKey = @"session_ref";
static NSString *const OXAlertKindKey = @"kind";
static NSString *const OXPairingHintKey = @"pairing_hint";
static const NSUInteger OXMaxSeenResponses = 16;

Expand Down Expand Up @@ -89,8 +91,7 @@ - (BOOL)rememberResponse:(NSString *)identifier {
}

- (void)captureResponse:(UNNotificationResponse *)response {
// Only a tap that opens the app. Custom actions and a dismissal are not
// approval taps, and this bridge registers no custom actions.
// Only a tap that opens the app. This bridge registers no custom actions.
if (![response.actionIdentifier isEqualToString:UNNotificationDefaultActionIdentifier]) {
return;
}
Expand All @@ -106,21 +107,32 @@ - (void)captureResponse:(UNNotificationResponse *)response {
if (![container isKindOfClass:NSDictionary.class]) {
return;
}
id value = ((NSDictionary *)container)[OXApprovalRefKey];
NSDictionary *alert = (NSDictionary *)container;
id approval = alert[OXApprovalRefKey];
id session = alert[OXSessionRefKey];
if (approval != nil && session != nil) {
return;
}
if (session != nil) {
id kind = alert[OXAlertKindKey];
if (![kind isEqual:@"finished"] && ![kind isEqual:@"failed"] && ![kind isEqual:@"goal_reached"]) {
return;
}
}
id value = session ?: approval;
if (![value isKindOfClass:NSString.class]) {
return;
}

// Read only the approval reference and the optional routing hint. Rust
// distinguishes an absent hint from a field with a malformed value.
// Rust distinguishes absent and malformed hints for legacy approval alerts.
NSData *bytes = [(NSString *)value dataUsingEncoding:NSUTF8StringEncoding];
if (bytes.length == 0 || bytes.length > 4096) {
return;
}
id hint = ((NSDictionary *)container)[OXPairingHintKey];
id hint = alert[OXPairingHintKey];
NSData *hintBytes = [hint isKindOfClass:NSString.class] && [(NSString *)hint length] == 43
? [(NSString *)hint dataUsingEncoding:NSUTF8StringEncoding] : nil;
ox_ios_push_bridge_tap((const uint8_t *)bytes.bytes, (uintptr_t)bytes.length,
ox_ios_push_bridge_tap(session != nil, (const uint8_t *)bytes.bytes, (uintptr_t)bytes.length,
hint != nil, (const uint8_t *)hintBytes.bytes,
(uintptr_t)hintBytes.length);
}
Expand Down
Loading
Loading