import { ok } from "@atcute/client"; import { mainSchema as putRecordSchema } from "@atcute/atproto/types/repo/putRecord"; import { mainSchema as deleteRecordSchema } from "@atcute/atproto/types/repo/deleteRecord"; import type { Nsid, RecordKey } from "@atcute/lexicons/syntax"; import type { OAuthUserAgent } from "@atcute/oauth-browser-client"; import { createClient } from "$lib/auth/agent"; import type { BobbinContext, XrpcRequestInit } from "./client"; import { jsonGet } from "./_request"; import type { RecordView } from "./records"; import type * as ShTangledFeedReaction from "./lexicons/types/sh/tangled/feed/reaction"; export type ReactionRecord = ShTangledFeedReaction.Main; const REACTION_COLLECTION = "sh.tangled.feed.reaction" as Nsid; export const putReaction = async ( agent: OAuthUserAgent, rkey: string, record: ReactionRecord ): Promise> => { const rpc = createClient(agent); const { uri, cid } = await ok( rpc.call(putRecordSchema, { input: { repo: agent.sub, collection: REACTION_COLLECTION, rkey: rkey as RecordKey, record } }) ); return { uri, cid, value: record }; }; export const deleteReaction = async (agent: OAuthUserAgent, rkey: string): Promise => { const rpc = createClient(agent); await ok( rpc.call(deleteRecordSchema, { input: { repo: agent.sub, collection: REACTION_COLLECTION, rkey: rkey as RecordKey } }) ); }; export interface ReactionListPage { cursor?: string | null; items: RecordView[]; } export const listReactions = ( ctx: BobbinContext, subject: string, filter: { limit?: number; cursor?: string; order?: "asc" | "desc" } = {}, init?: XrpcRequestInit ) => jsonGet(ctx, "sh.tangled.feed.listReactions", { subject, ...filter }, init);