[codex] Structure mobile notification setting failures (#3391)
Co-authored-by: codex <[email protected]>
This commit is contained in:
1 parent
7a8bab5d9d
commit
f7867addbe
2 files changed
+40
-4
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Schema from "effect/Schema";
|
||||
import { HttpClient } from "effect/unstable/http";
|
||||
import { ManagedRelay } from "@t3tools/client-runtime/relay";
|
||||
|
||||
@@ -7,6 +8,18 @@ import { savePreferencesPatch } from "../../lib/storage";
|
||||
import { linkEnvironmentToCloud } from "../cloud/linkEnvironment";
|
||||
import { refreshAgentAwarenessRegistration } from "./remoteRegistration";
|
||||
|
||||
export class LiveActivityPreferenceSaveError extends Schema.TaggedErrorClass<LiveActivityPreferenceSaveError>()(
|
||||
"LiveActivityPreferenceSaveError",
|
||||
{
|
||||
enabled: Schema.Boolean,
|
||||
cause: Schema.Defect(),
|
||||
},
|
||||
) {
|
||||
override get message(): string {
|
||||
return `Failed to save the Live Activity updates setting (enabled: ${this.enabled}).`;
|
||||
}
|
||||
}
|
||||
|
||||
export function setLiveActivityUpdatesEnabled(input: {
|
||||
readonly enabled: boolean;
|
||||
readonly clerkToken: string | null;
|
||||
@@ -15,7 +28,7 @@ export function setLiveActivityUpdatesEnabled(input: {
|
||||
return Effect.gen(function* () {
|
||||
yield* Effect.tryPromise({
|
||||
try: () => savePreferencesPatch({ liveActivitiesEnabled: input.enabled }),
|
||||
catch: (error) => error,
|
||||
catch: (cause) => new LiveActivityPreferenceSaveError({ enabled: input.enabled, cause }),
|
||||
});
|
||||
|
||||
yield* refreshAgentAwarenessRegistration();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import * as Notifications from "expo-notifications";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Schema from "effect/Schema";
|
||||
import { Platform } from "react-native";
|
||||
|
||||
export type NotificationPermissionResult =
|
||||
@@ -7,9 +8,31 @@ export type NotificationPermissionResult =
|
||||
| { readonly type: "granted" }
|
||||
| { readonly type: "denied"; readonly canAskAgain: boolean };
|
||||
|
||||
export class NotificationPermissionReadError extends Schema.TaggedErrorClass<NotificationPermissionReadError>()(
|
||||
"NotificationPermissionReadError",
|
||||
{
|
||||
cause: Schema.Defect(),
|
||||
},
|
||||
) {
|
||||
override get message(): string {
|
||||
return "Failed to read notification permissions on iOS.";
|
||||
}
|
||||
}
|
||||
|
||||
export class NotificationPermissionRequestError extends Schema.TaggedErrorClass<NotificationPermissionRequestError>()(
|
||||
"NotificationPermissionRequestError",
|
||||
{
|
||||
cause: Schema.Defect(),
|
||||
},
|
||||
) {
|
||||
override get message(): string {
|
||||
return "Failed to request notification permissions on iOS.";
|
||||
}
|
||||
}
|
||||
|
||||
export const requestAgentNotificationPermission: Effect.Effect<
|
||||
NotificationPermissionResult,
|
||||
unknown
|
||||
NotificationPermissionReadError | NotificationPermissionRequestError
|
||||
> = Effect.gen(function* () {
|
||||
if (Platform.OS !== "ios") {
|
||||
return { type: "unsupported" };
|
||||
@@ -17,7 +40,7 @@ export const requestAgentNotificationPermission: Effect.Effect<
|
||||
|
||||
const existing = yield* Effect.tryPromise({
|
||||
try: () => Notifications.getPermissionsAsync(),
|
||||
catch: (error) => error,
|
||||
catch: (cause) => new NotificationPermissionReadError({ cause }),
|
||||
});
|
||||
if (existing.granted) {
|
||||
return { type: "granted" };
|
||||
@@ -36,7 +59,7 @@ export const requestAgentNotificationPermission: Effect.Effect<
|
||||
allowSound: true,
|
||||
},
|
||||
}),
|
||||
catch: (error) => error,
|
||||
catch: (cause) => new NotificationPermissionRequestError({ cause }),
|
||||
});
|
||||
return requested.granted
|
||||
? { type: "granted" }
|
||||
|
||||
Reference in new issue
Block a user