Stefan Bohacek · @stefan
1254 followers · 2679 posts · Server stefanbohacek.online

I'm playing with Mastodon's Context API to fetch replies to posts I'm viewing, and while it's too early for me to add this to github.com/stefanbohacek/masto, the experience is so much better.

Has anyone done anything with this?

#mastodon #mastodonapi #contextapi

Last updated 2 years ago

robrich · @robrich
20 followers · 149 posts · Server hachyderm.io
Jonny · @jonny
443 followers · 728 posts · Server neuromatch.social

@jdp23 @liamsora @kichae @futurebird @stopthatgirl7
it certainly doesn't address the problem fully, but I'll be merging this into neuromatch.social to test soon enough: github.com/NeuromatchAcademy/m

It's relatively simple patch that's entirely frontend so hopefully easy to deploy on smaller instances.

Makes a button that lets you request the replies to a given post so you can see them even if no one on your instance follows the poster (ie. your instance wouldn't know about the post because of the pub/sub issues described above).

It works by using the search feature to fetch posts (as @liamsora also discovered):

  • Ask OP server for the context that it knows about, replies and ancestors
  • Submits the URLs for each of the replies to the search endpoint
  • Inserts posts as they are received into the redux store -> into the React component displaying the thread

It currently inserts them in a disordered way because the React component holding a thread is a single-layer component that holds expanded post & ancestors & replies. that's also related to why a thread is completely unreadable (imo) because it's rendered as a flat list rather than as a tree - which is what a thread is. Will be working on making a properly recursive component next.

Once that's done, then it should be possible to iteratively request replies in a smarter way, but that will also require another change in the way the /context endpoint works, which currently takes no arguments for subsetting and has no pagination - so therefore has relatively low hardcoded limits on the amount of replies you can request without being logged in. That will need to change to be able to request a certain depth (currently it gets the entire reply tree and then flattens it into an array) and paginate through results so that eg. you can get all the top-level replies to the request you have open, and then as you open deeper replies you get the replies to that reply, and so on....

(sorry for wall of text sort of got away from me.)

#fetchallreplies #nestedthreads #contextapi #mastodev

Last updated 3 years ago

Hackernoon · @hackernoon_bot
164 followers · 5635 posts · Server social.platypush.tech