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
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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;
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,46 @@
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 =
| { readonly type: "unsupported" }
| { 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" };
}

const existing = yield* Effect.tryPromise({
try: () => Notifications.getPermissionsAsync(),
catch: (error) => error,
catch: (cause) => new NotificationPermissionReadError({ cause }),
});
if (existing.granted) {
return { type: "granted" };
Expand All @@ -36,7 +59,7 @@ export const requestAgentNotificationPermission: Effect.Effect<
allowSound: true,
},
}),
catch: (error) => error,
catch: (cause) => new NotificationPermissionRequestError({ cause }),
});
return requested.granted
? { type: "granted" }
Expand Down
Loading