Something went wrong. Try again.
Monorepo for Tangled tangled.org
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455import { 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 ShTangledFeedComment from "./lexicons/types/sh/tangled/feed/comment";
export type CommentRecord = ShTangledFeedComment.Main;
const COMMENT_COLLECTION = "sh.tangled.feed.comment" as Nsid;
export const putComment = async ( agent: OAuthUserAgent, rkey: string, record: CommentRecord): Promise<RecordView<CommentRecord>> => { const rpc = createClient(agent); const { uri, cid } = await ok( rpc.call(putRecordSchema, { input: { repo: agent.sub, collection: COMMENT_COLLECTION, rkey: rkey as RecordKey, record } }) ); return { uri, cid, value: record };};
export const deleteComment = async (agent: OAuthUserAgent, rkey: string): Promise<void> => { const rpc = createClient(agent); await ok( rpc.call(deleteRecordSchema, { input: { repo: agent.sub, collection: COMMENT_COLLECTION, rkey: rkey as RecordKey } }) );};
export interface CommentListPage { cursor?: string | null; items: RecordView<CommentRecord>[];}
export const listComments = ( ctx: BobbinContext, subject: string, filter: { limit?: number; cursor?: string; order?: "asc" | "desc" } = {}, init?: XrpcRequestInit) => jsonGet<CommentListPage>(ctx, "sh.tangled.feed.listComments", { subject, ...filter }, init);