--- title: "FediLeventy Part 2 – comments and follower lists" date: 2022-11-09T00:00:00 slug: fedileventy-part-2-comments-and-follower-lists --- Yes, I'm calling it FediLeventy and there's nothing any of you can do to stop me. Yesterday, after publishing my [post on implementing some features of ActivityPub](https://lewisdale.dev/post/you-can-be-friends-with-my-blog), I received a comment from [i@social.bennypowers.dev](https://social.bennypowers.dev/@i):  The short answer: No. The long answer: Not yet. ## Yet is now Given I already had most of the framework in place for handling comments, it was actually really straightforward. A comment is a `Create` activity, and looks something like this (from [the W3C document outlining the spec](https://www.w3.org/TR/activitypub/#object-without-create)): ```json { "@context": "https://www.w3.org/ns/activitystreams", "type": "Create", "id": "https://example.net/~mallory/87374", "actor": "https://example.net/~mallory", "object": { "id": "https://example.com/~mallory/note/72", "type": "Note", "attributedTo": "https://example.net/~mallory", "content": "This is a note", "published": "2015-02-10T15:04:55Z", "to": ["https://example.org/~john/"], "cc": ["https://example.com/~erik/followers", "https://www.w3.org/ns/activitystreams#Public"] }, "published": "2015-02-10T15:04:55Z", "to": ["https://example.org/~john/"], "cc": ["https://example.com/~erik/followers", "https://www.w3.org/ns/activitystreams#Public"] } ``` It's fairly simple to convert this into a format that I could then display as a comment: I just store the display name for the Actor (i.e. username@domain), a flag to say it's a Mastodon comment, a link to the commenter, and the original reply. With that, I just added some extra fields for things like linking to the original status, and the user that posted the comment. ### Comment content One minor point I had to deal with is that the content field can contain HTML - in fact all Mastodon replies seem to. I handle this by first adding in line break characters where the `
` tags close, and then replacing all other HTML tags: ```javascript { comment: body.object.content .replaceAll('
', '\n') .replace(/<[^>]+>/g, '') } ``` and then when rendering, I just replace my line break characters with `