snarfed / bridgy-fed

🌉 A bridge between decentralized social network protocols
https://fed.brid.gy
Creative Commons Zero v1.0 Universal
549 stars 29 forks source link

AP => ATProto: trim mentions at the beginning of replies #1207

Open mackuba opened 1 month ago

mackuba commented 1 month ago

On the Fedi, replies usually start with mentions of the user(s) from the parent comments. This isn't needed on the ATProto side, because users are automatically notified of replies, and it's often taking valuable space, since Bluesky posts have a smaller character length limit. If we trim all the leading mentions, for longer posts it would mean that a bit more of the content would be visible inline, and possibly in some cases the [...] wouldn't even be needed. (The mentions should be left if they're in the middle of text.)

mackuba commented 1 month ago

I looked if I could maybe get this started, that would be I think in Granary somewhere here: https://github.com/snarfed/granary/blob/main/granary/bluesky.py#L760, but I realized it's not as easy as I thought - because I thought it would be just a matter of trimming a substring one or more times, but I think if we delete some text at the beginning, it would invalidate the positions of tags from the AS1 object that are parsed later (tag['startIndex']), so it'd need to calculate the offset and then adjust every single place later that uses the old positions by this offset?

snarfed commented 1 month ago

Sigh, yes. Good example of why facet/index-based rich text is more difficult to work with than markup-based rich text, and why much of the standards community, eg W3C, has moved away from it and mildly discourages it now.

snarfed commented 1 month ago

An alternative would be to do it earlier, with either the initial HTML or the Markdown links after we convert from HTML to Markdown:

https://github.com/snarfed/granary/blob/751991857a23e01c31cc7b78f4df0688d09c981a/granary/bluesky.py#L686

If you want to be extra careful, you could match them with tags.

Still, regardless of how you do it, you're right, it'll be a bit tricky, not that easy.

snarfed commented 1 month ago

(Awesome that you're looking at contributing btw! Happy to help and answer any questions if you do try.)