64
submitted 1 year ago by quest@lemmy.world to c/fediverse@lemmy.world

I'm trying to figure out how to get the comments of a post given a link to it using ActivityPub.

Based on reading the ActivityPub spec, I thought comments were federated via the replies key of the ActivityPub Object.

This works for Mastodon posts, but not for Lemmy (nor Pleroma). As an example

curl -H "Accept: application/activity+json" https://lemmy.my.id/post/79514 | jq

doesn't contain a replies key. Yet the comments are federated to Mastodon somehow.

What is going on? How can I get the comment?

top 9 comments
sorted by: hot top controversial new old

AFAIK, you can't load comments on posts manually. You only get comments that are pushed to your instance after someone has subscribed to the community containing the post.

[-] quest@lemmy.world 5 points 1 year ago* (last edited 1 year ago)

Unfortunately I think you’re right. I tested it by trying to load the Lemmy post up on a couple of single-user Mastodon instances, and they failed to load it.

It looks like only Mastodon and PeerTube and maybe a couple others list replies alongside the post. It would be nice if more did because I’m relying on the feature for this project of mine: https://github.com/BentonEdmondson/servitor

[-] r00ty@kbin.life 1 points 1 year ago

The public links with post and comment in are used specifically for federation and can only really be used to build a hierarchy upwards. The use case for this probably will make it make more sense.

Say I subscribe to a remote community from my instance. I won't get anything specifically until an activity happens. The first activity I get is a like for a comment. But I don't have the comment. But luckily the like message has a link to the comment URL. So now I can fetch that. But how can I just show a comment out of context? I cannot, but the comment json tells me what it is in reply to. Maybe a post, maybe another comment. I can just keep fetching up the tree until I get to the post. Once I have all that I have something that can be rendered, the whole hierarchy from the liked comment to the post.

That's why it works that way. It's probably just to save on DB queries, why query the DB for all the comments if in normal federation use case it already has the comment(s) it wants if it reached the post.

[-] quest@lemmy.world 1 points 1 year ago

But in the use case you give, how could you view the replies below the liked comment? If the replies key is absent you can’t. So you can only see those for Mastodon/PeerTube in that case, not Lemmy/Pleroma.

[-] r00ty@kbin.life 0 points 1 year ago

You can see the hierarchy above not below.

You might get a like. It looks like:

like: [
    "id" => "https://lemmy.one/activities/like/7d0ef24f-755f-48dd-9b37-ea42041cb34e",
    "actor" => "https://lemmy.one/u/Matt",
    "object" => "https://lemmy.procrastinati.org/comment/146844",
    "type" => "Like",
    "audience" => "https://lemdro.id/c/android"
]

In the object property you see the comment. If you visit that you'll get among the rest of the json for the comment

"inReplyTo": "https://lemmy.world/comment/1269475",

And again

"inReplyTo": "https://lemdro.id/post/77457",

Now you have the hierarchy from the like's comment to the post. Not the rest of the tree, enough to render the comment in context though.

[-] CommunityLinkFixer 1 points 1 year ago

Hi there! Looks like you linked to a Lemmy community using a URL instead of its name, which doesn't work well for people on different instances. Try fixing it like this: !android@lemdro.id

[-] quest@lemmy.world 1 points 1 year ago

I understand exactly what you're saying; you can get the parents but not the replies in that situation.

I'm just saying that in your situation (e.g. someone I follow on Mastodon likes a Lemmy post) it would be convenient for me as a user to be able to view the replies to that Lemmy post, but I cannot necessarily do that because Lemmy does not include replies.

[-] r00ty@kbin.life 0 points 1 year ago

I expect it does, from the lemmy API. But from the ActivityPub api, it doesn't make sense to.

[-] JakenVeina@lemm.ee 2 points 1 year ago

So, do lemmy instances communicate with each other over their own API, in addition to ActivityPub?

load more comments
view more: next ›
this post was submitted on 14 Jul 2023
64 points (98.5% liked)

Fediverse

28328 readers
290 users here now

A community to talk about the Fediverse and all it's related services using ActivityPub (Mastodon, Lemmy, KBin, etc).

If you wanted to get help with moderating your own community then head over to !moderators@lemmy.world!

Rules

Learn more at these websites: Join The Fediverse Wiki, Fediverse.info, Wikipedia Page, The Federation Info (Stats), FediDB (Stats), Sub Rehab (Reddit Migration), Search Lemmy

founded 1 year ago
MODERATORS