Skip to content

feat: ✨ ios notifications#554

Open
ethancha0 wants to merge 8 commits into
mainfrom
ewc-ios-notifications
Open

feat: ✨ ios notifications#554
ethancha0 wants to merge 8 commits into
mainfrom
ewc-ios-notifications

Conversation

@ethancha0
Copy link
Copy Markdown
Collaborator

@ethancha0 ethancha0 commented May 28, 2026

Description

Hook current notifications to push IOS mobile notifications

Test Plan

This feature is only testable through the mobile ios Testflight, meaning it's not possible to test before merging

Issues

  • Closes #

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 issues found across 8 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread src/lib/push/send-push.ts Outdated
Comment thread src/server/data/user/queries.ts Outdated
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 issues found across 4 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread src/components/push/web-push-permission-button.tsx Outdated
Comment thread public/sw.js Outdated
Comment thread public/sw-register.js Outdated
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

9 issues found across 17 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/db/migrations/0019_native_push_tokens.sql">

<violation number="1" location="src/db/migrations/0019_native_push_tokens.sql:1">
P3: This migration duplicates the same `native_push_tokens` DDL already present in `0020_nice_synch.sql`, which makes the migration history harder to reason about and easy to drift.</violation>
</file>

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread src/app/api/push-tokens/route.ts Outdated
Comment thread src/lib/push/web-push.ts Outdated
Comment thread src/app/api/push-subscriptions/route.ts Outdated
Comment thread src/app/api/push-subscriptions/route.ts Outdated
Comment thread src/app/api/push-tokens/route.ts Outdated
Comment thread src/components/push/native-ios-push-bridge.tsx Outdated
Comment thread src/components/push/web-push-permission-button.tsx Outdated
Comment thread src/components/push/web-push-permission-button.tsx Outdated
@@ -0,0 +1,18 @@
CREATE TABLE IF NOT EXISTS "native_push_tokens" (
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: This migration duplicates the same native_push_tokens DDL already present in 0020_nice_synch.sql, which makes the migration history harder to reason about and easy to drift.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/db/migrations/0019_native_push_tokens.sql, line 1:

<comment>This migration duplicates the same `native_push_tokens` DDL already present in `0020_nice_synch.sql`, which makes the migration history harder to reason about and easy to drift.</comment>

<file context>
@@ -0,0 +1,18 @@
+CREATE TABLE IF NOT EXISTS "native_push_tokens" (
+	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
+	"user_id" text NOT NULL,
</file context>

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 17 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/db/migrations/0019_native_push_tokens.sql">

<violation number="1" location="src/db/migrations/0019_native_push_tokens.sql:1">
P3: This migration duplicates the same `native_push_tokens` DDL already present in `0020_nice_synch.sql`, which makes the migration history harder to reason about and easy to drift.</violation>
</file>

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread src/components/push/native-ios-push-bridge.tsx Outdated
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4 issues found across 8 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/db/migrations/0019_native_push_tokens.sql">

<violation number="1" location="src/db/migrations/0019_native_push_tokens.sql:1">
P3: This migration duplicates the same `native_push_tokens` DDL already present in `0020_nice_synch.sql`, which makes the migration history harder to reason about and easy to drift.</violation>
</file>

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread src/components/push/native-ios-push-bridge.tsx Outdated
Comment thread src/app/api/push-tokens/route.ts Outdated
Comment thread ios/src/ZotMeet/PushNotifications.swift Outdated
Comment thread src/lib/push/redirect.ts Outdated
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5 issues found across 16 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/app/api/push-tokens/route.ts">

<violation number="1" location="src/app/api/push-tokens/route.ts:108">
P1: The DELETE route performs an external SNS endpoint deletion before verifying token ownership, allowing authenticated users to delete endpoints they do not own if they know an ARN.</violation>
</file>

<file name="sst.config.ts">

<violation number="1" location="sst.config.ts:39">
P1: Scope SNS IAM resources more narrowly than `*` to avoid granting account-wide publish/endpoint management permissions.</violation>
</file>

<file name="src/lib/push/sns-register.ts">

<violation number="1" location="src/lib/push/sns-register.ts:28">
P1: `CreatePlatformEndpoint` errors are treated as fatal, but SNS can throw `InvalidParameter` for an existing token with different attributes; handle that case by recovering the existing endpoint ARN instead of returning `null`.</violation>
</file>

<file name="src/lib/push/send-push.ts">

<violation number="1" location="src/lib/push/send-push.ts:65">
P1: `InvalidParameterException` is treated as a stale endpoint unconditionally, which can cause valid push endpoints to be deleted on transient/message-format errors.</violation>
</file>

<file name="ios/src/ZotMeet/AppDelegate.swift">

<violation number="1" location="ios/src/ZotMeet/AppDelegate.swift:39">
P3: Use the existing `apnsTokenHexString(from:)` helper instead of duplicating APNs token formatting logic.</violation>
</file>

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

return NextResponse.json({ error: "Invalid token" }, { status: 400 });
}

if (isSnsEndpointArn(token)) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: The DELETE route performs an external SNS endpoint deletion before verifying token ownership, allowing authenticated users to delete endpoints they do not own if they know an ARN.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/app/api/push-tokens/route.ts, line 108:

<comment>The DELETE route performs an external SNS endpoint deletion before verifying token ownership, allowing authenticated users to delete endpoints they do not own if they know an ARN.</comment>

<file context>
@@ -88,17 +100,21 @@ export async function DELETE(request: Request) {
+		return NextResponse.json({ error: "Invalid token" }, { status: 400 });
+	}
+
+	if (isSnsEndpointArn(token)) {
+		await deleteIosPushEndpoint(token);
 	}
</file context>

Comment thread sst.config.ts
"sns:GetEndpointAttributes",
"sns:DeleteEndpoint",
],
resources: ["*"],
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: Scope SNS IAM resources more narrowly than * to avoid granting account-wide publish/endpoint management permissions.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At sst.config.ts, line 39:

<comment>Scope SNS IAM resources more narrowly than `*` to avoid granting account-wide publish/endpoint management permissions.</comment>

<file context>
@@ -27,12 +27,28 @@ export default $config({
+						"sns:GetEndpointAttributes",
+						"sns:DeleteEndpoint",
+					],
+					resources: ["*"],
+				},
+			],
</file context>

);
warnedMissingPlatformArn = true;
}
return null;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: CreatePlatformEndpoint errors are treated as fatal, but SNS can throw InvalidParameter for an existing token with different attributes; handle that case by recovering the existing endpoint ARN instead of returning null.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/lib/push/sns-register.ts, line 28:

<comment>`CreatePlatformEndpoint` errors are treated as fatal, but SNS can throw `InvalidParameter` for an existing token with different attributes; handle that case by recovering the existing endpoint ARN instead of returning `null`.</comment>

<file context>
@@ -0,0 +1,82 @@
+			);
+			warnedMissingPlatformArn = true;
+		}
+		return null;
+	}
+
</file context>

Comment thread src/lib/push/send-push.ts
const message = "message" in error ? String(error.message) : "";
return (
name === "EndpointDisabledException" ||
name === "InvalidParameterException" ||
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: InvalidParameterException is treated as a stale endpoint unconditionally, which can cause valid push endpoints to be deleted on transient/message-format errors.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/lib/push/send-push.ts, line 65:

<comment>`InvalidParameterException` is treated as a stale endpoint unconditionally, which can cause valid push endpoints to be deleted on transient/message-format errors.</comment>

<file context>
@@ -88,18 +30,47 @@ function chunkArray<T>(items: T[], size: number) {
-		code === "messaging/invalid-registration-token" ||
-		code === "messaging/registration-token-not-registered"
+		name === "EndpointDisabledException" ||
+		name === "InvalidParameterException" ||
+		message.includes("Endpoint is disabled") ||
+		message.includes("Invalid parameter: TargetArn")
</file context>

// // Messaging.messaging().apnsToken = deviceToken
// }
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
let token = deviceToken.map { String(format: "%02.2hhx", $0) }.joined()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: Use the existing apnsTokenHexString(from:) helper instead of duplicating APNs token formatting logic.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At ios/src/ZotMeet/AppDelegate.swift, line 39:

<comment>Use the existing `apnsTokenHexString(from:)` helper instead of duplicating APNs token formatting logic.</comment>

<file context>
@@ -30,127 +18,45 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
-//        // Messaging.messaging().apnsToken = deviceToken
-//      }
+      func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
+        let token = deviceToken.map { String(format: "%02.2hhx", $0) }.joined()
+        setApnsDeviceTokenHex(token)
+        sendApnsTokenToWebView(token: token)
</file context>
Suggested change
let token = deviceToken.map { String(format: "%02.2hhx", $0) }.joined()
let token = apnsTokenHexString(from: deviceToken)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant