chore: improve typing and documentation

Changed files
+26 -10
app
components
util
+13 -9
app/components/BskyComments.vue
···
<script setup lang="ts">
-
import { getBskyReplies, type ReplyThread } from "~/util/atproto";
+
import type { AppBskyFeedDefs } from "@atcute/bluesky";
+
import { getBskyReplies } from "~/util/atproto";
const props = defineProps({
cid: {
···
const data = ref(await getBskyReplies(cid.value));
const err = ref("");
-
const post = ref();
+
const post = ref<AppBskyFeedDefs.ThreadViewPost>();
if (data.value.$type === "app.bsky.feed.defs#blockedPost") {
err.value = "Post is blocked";
···
if (data.value.$type === "app.bsky.feed.defs#threadViewPost") {
console.log(data.value);
-
post.value = data.value;
+
post.value = data.value as AppBskyFeedDefs.ThreadViewPost;
}
</script>
···
<div class="md:w-[80%] mx-auto mt-16">
<div class="flex items-baseline flex-col md:flex-row md:gap-4 mb-2 md:mb-0">
<h3 class="font-bold text-xl">Join the conversation!</h3>
-
<div class="flex items-center gap-2">
+
<div v-if="post" class="flex items-center gap-6">
<p class="text-gray-500 text-sm" title="Replies">
<Icon name="ri:reply-line" class="-mb-[2px] mr-1" />
{{post.post.replyCount}}
···
</div>
</div>
-
<p class="text-gray-600 text-md mb-6">
+
<div v-if="err">
+
<p class="mt-2 text-gray-700 dark:text-gray-500">
+
{{ err }}
+
</p>
+
</div>
+
+
<p v-if="post" class="text-gray-600 dark:text-gray-500 text-md mb-6">
<a class="underline" :href="`https://bsky.app/profile/${post.post.author.handle}/post/${cid}`">Reply on Bluesky</a> to take part in the discussion.
</p>
-
<div v-if="err">
-
<div>{{ err }}</div>
-
</div>
<div v-if="post">
<div v-if="post.post.replyCount === 0">
···
<BskyPost
v-else
-
v-for="reply in post.replies"
+
v-for="reply in post.replies?.filter(reply => reply.$type === 'app.bsky.feed.defs#threadViewPost')"
:key="reply.post.cid"
:post="reply"
:depth="0"
+13 -1
app/util/atproto.ts
···
import config from "@/../blog.config";
const handler = simpleFetchHandler({
+
// Simply hit up the Bluesky API
service: "https://public.api.bsky.app"
});
const rpc = new Client({ handler });
···
| AppBskyFeedDefs.BlockedPost
| AppBskyFeedDefs.NotFoundPost;
+
/**
+
* Fetch the first 10 replies to a post
+
* @param cid
+
* @returns
+
*/
export async function getBskyReplies(cid: string) {
// uri should be in format: at://did:plc:xxx/app.bsky.feed.post/xxxxx
const uri: ResourceUri = `at://${config.authorDid}/app.bsky.feed.post/${cid}`;
···
const { ok, data } = await rpc.get("app.bsky.feed.getPostThread", {
params: {
uri,
-
depth: 10
+
depth: 6 // default
}
});
if (!ok) {
+
// Handle fetch errors as 'not found'. Could be cleaner, but works just fine.
console.error("Error fetching thread:", data.error);
return { $type: "app.bsky.feed.defs#notFoundPost" };
}
···
return { $type: "app.bsky.feed.defs#notFoundPost" };
}
+
/**
+
* Extract post id from an atproto uri
+
* @param uri The atproto uri, such as at://did:plc:user/app.bsky.feed.post/xxxxx`
+
* @returns The post id
+
*/
export function extractPostId(uri: ResourceUri) {
if (uri.includes("app.bsky.feed.post")) {
const parts = uri.split("/");