Something went wrong. Try again.
softfork of @juliet.paris parfait forked from juliet.paris/parfait
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233import { ok } from "@atcute/client";import { createStore } from "solid-js/store";
import type { Acting } from "./api";
/** Posts deleted from here, by address: they leave every feed and thread showing them at once. */const [deleted, setDeleted] = createStore<Record<string, true>>({});
export const isDeleted = (uri: string) => !!deleted[uri];
type PostRef = { uri: string; author: { did: string } };
/** Whether a post is the account's own, so it can delete it. */const canDelete = (post: PostRef, as: Acting | undefined) => !!as && post.author.did === as.did;
/** Deletes one of the account's own posts from its repository. Throws if Bluesky refuses. */export const deletePost = async (post: PostRef, as: Acting) => { if (!canDelete(post, as)) throw new Error("Only your own posts can be deleted."); const remove = (collection: `${string}.${string}.${string}`) => as.pds.post("com.atproto.repo.deleteRecord", { input: { repo: as.did as `did:${string}:${string}`, collection, rkey: post.uri.slice(post.uri.lastIndexOf("/") + 1), }, }); await ok(remove("app.bsky.feed.post")); setDeleted(post.uri, true); // Its rules for replies and quotes, if it had any, go with it; most posts have none. await Promise.allSettled([remove("app.bsky.feed.threadgate"), remove("app.bsky.feed.postgate")]);};