stormy gray clouds

Adding comments to this blog

5 February 2024 - by @mozzius.dev

/Blog/Adding comments to this blog

This blog now has comments!

That might not sound particularly impressive, since I think most people would consider "comments on blogs" to be a Solved Problem. But I decided to go about it in a bit of a different way - all the comments are fetched directly from Bluesky. And I think the ease with which I did that goes a long way to demonstrating the power of Bluesky's Open Network, and is possibly worth talking about a little bit.

Bluesky is completely open

When I say "Bluesky is completely open", I really mean it. You don't even need an API key to query the AppView. Combined with the excellent tooling that Bluesky provides meant that implementating this feature took about hour, from scratch. Granted, I've been working with the API for a while now, but I think that's still pretty impressive.

Here's the code I used to fetch the comments (slightly simplified for clarity):

1// pass it the URI of the post you want to fetch replies for
2export const CommentSection = async ({ uri }: { uri: string }) => {
3 if (!uri) return <p className="text-center">No comments</p>;
4
5 const agent = new BskyAgent({ service: "https://public.api.bsky.app" });
6 const response = agent.getPostThread({ uri });
7
8 const thread = response.data.thread;
9
10 if (!AppBskyFeedDefs.isThreadViewPost(data.thread)) {
11 return <p className="text-center">Could not find thread</p>;
12 }
13
14 if (!thread.replies || thread.replies.length === 0) {
15 return <p className="text-center">No comments yet</p>;
16 }
17
18 return (
19 <div className="space-y-8">
20 {thread.replies.map((reply) => {
21 // if the reply is blocked/deleted, skip it
22 if (!AppBskyFeedDefs.isThreadViewPost(reply)) return null;
23 return <Comment key={reply.post.uri} comment={reply} />;
24 })}
25 </div>
26 );
27};

In the actual implementation, I don't use BskyAgent in favour of using fetch directly, due to Next.js overriding the fetch function, but this version is a bit more readable and typesafe. And it's basically the same under the hood.

Simply make a <Comment /> component that renders a Bluesky post, and you're done! It's really that simple.

See my other blog post for a step-by-step guide on how to render a Bluesky post. My blog comments take it one step futher by rendering the replies recursively, to make a threaded comment section.

What this means

"The organization is a future adversary"
- Paul Frazee

Bluesky talks a lot about being "Billionaire-proof", and I think the open API is a critical part of that. Due to it's decentralised nature, it's not just open, it's "locked open" - Bluesky (the company) couldn't start locking off access even if they wanted to. This is in harsh contrast to X (formerly Twitter) turning off the free API, and making the paid API much more expensive, and Reddit suddenly charging 3rd party apps like Apollo $20 million a year for it's previously free API (instantly killing the 3rd party ecosystem).

This is critical to building trust in the platform among the developer community that Bluesky is trying to foster, and I think it's a big part of why Bluesky has seen an explosion of community projects. It's also a big part of why I'm so excited to be building on it. I don't have to worry that Bluesky will get bought out and "pull a Reddit" on me, because they literally can't. This matters, whether you want to add a little comment section to your blog, all the way up to building a full-fledged client.

I think this is also great for non-developers too. I completely stopped using Reddit when they killed Apollo, because the official app is garbage. That's not something you have to worry about with Bluesky, and it goes so much deeper than just the app. Every part of the platform can be swapped out, and that's a really powerful thing. We've watched platform after platform succumb to enshittification, and even if Bluesky (the company) follows suit, Bluesky (the community) doesn't have to.

This little comments section project - sure, it's pretty frivolous, but I love that Bluesky doesn't shy away from creativity. They want you to build cool things with what they've built. I think that's great.

Overall, I'm really optimistic about the future of Bluesky, and I'm excited to see what else is possible.

Let me know what you think in the all-new comments!

- Samuel (@mozzius.dev)


63 likes - 14 reposts

Comments

Comments are fetched directly from this post - reply there to add your own comment.