Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AP: try marking up @-mentions in content with semantic HTML #887

Open
snarfed opened this issue Feb 18, 2024 · 8 comments
Open

AP: try marking up @-mentions in content with semantic HTML #887

snarfed opened this issue Feb 18, 2024 · 8 comments
Labels
compat Protocol differences that need special handling.

Comments

@snarfed
Copy link
Owner

snarfed commented Feb 18, 2024

Mastodon understands which links in a given post are @-mentions and rewrites them to point to the local instance. Example: https://ohai.social/@lutoma/111947244364291173 . The first reply there from me is via Bridgy Fed, which has @-mention links that don't get that rewriting.

The only differences I see between the two posts' AS2 is that Mastodon's tag.names are fuly qualified, eg @mmu_man@m.g3l.org, while BF's are only @mmu_man, and that Mastodon's a tags in content have class="u-url mention". Not sure which matters, or both, or something else:

Mastodon AS2 object:

{
  "type": "Note",
  "id": "https://ohai.social/users/lutoma/statuses/111947244364291173",
  "url": "https://ohai.social/@lutoma/111947244364291173",
  "inReplyTo": "https://m.g3l.org/users/mmu_man/statuses/111947239114557378",
  "published": "2024-02-17T14:16:27Z",
  "attributedTo": "https://ohai.social/users/lutoma",
  "to": ["https://www.w3.org/ns/activitystreams#Public"]
  "cc": [
    "https://ohai.social/users/lutoma/followers",
    "https://m.g3l.org/users/mmu_man",
    "https://abyssdomain.expert/users/filippo"
  ],
  "content": "<p><span class=\"h-card\" translate=\"no\"><a href=\"https://m.g3l.org/@mmu_man\" class=\"u-url mention\">@<span>mmu_man</span></a></span> <span class=\"h-card\" translate=\"no\"><a href=\"https://abyssdomain.expert/@filippo\" class=\"u-url mention\">@<span>filippo</span></a></span> social.vivaldi.net is run by a for-profit entity. There&#39;s probably a few other ones as well.</p>",
  "tag": [{
      "type": "Mention",
      "href": "https://m.g3l.org/users/mmu_man",
      "name": "@mmu_man@m.g3l.org"
    }, {
      "type": "Mention",
      "href": "https://abyssdomain.expert/users/filippo",
      "name": "@filippo@abyssdomain.expert"
    }],
  "..."
}

BF AS2 object:

{
   "@context" : "https://www.w3.org/ns/activitystreams",
   "type" : "Note",
   "id" : "https://fed.brid.gy/r/https://snarfed.org/2024-02-18_lutoma-ohai-mmu_man-filippo-social-vival-ohai-social",
   "url" : "https://fed.brid.gy/r/https://snarfed.org/2024-02-18_lutoma-ohai-mmu_man-filippo-social-vival-ohai-social"
   "attributedTo" : "https://fed.brid.gy/snarfed.org",
   "to" : ["https://www.w3.org/ns/activitystreams#Public"],
   "cc" : [
      "https://abyssdomain.expert/@filippo",
      "https://m.g3l.org/@mmu_man"
   ],
   "content" : "<a class=\"u-in-reply-to\" href=\"https://ohai.social/@lutoma/111947244364291173\"></a>\n<div class=\"e-content\">\n<a href=\"https://abyssdomain.expert/@filippo\">@filippo</a> <a href=\"https://m.g3l.org/@mmu_man\">@mmu_man</a>\n<p>Yup, many. <a href=\"https://me.dm/\">me.dm</a>, <a href=\"https://flipboard.social/\">flipboard.social</a> and soon <a href=\"https://flipboard.com/\">flipboard.com</a>, <a href=\"https://1password.social/\">1password.social</a>, <a href=\"https://dnsimple.social\">dnsimple.social</a>, among others.</p>\n</div>",
   "inReplyTo" : "https://ohai.social/@lutoma/111947244364291173",
   "published" : "2024-02-18T10:05:50-08:00",
   "tag" : [{
         "href" : "https://abyssdomain.expert/@filippo",
         "name" : "@filippo",
         "type" : "Mention"
      }, {
         "href" : "https://m.g3l.org/@mmu_man",
         "name" : "@mmu_man",
         "type" : "Mention"
      }],
}
@snarfed
Copy link
Owner Author

snarfed commented Nov 1, 2024

Got nudged on this again recently: #1009 (comment)

@Tamschi
Copy link
Collaborator

Tamschi commented Nov 1, 2024

[I removed my earlier comment, that was mistaken.]

Ah, actually I think it finds them by CSS class, here: https://github.com/mastodon/mastodon/blob/b06fd54c305915527e3a6edc575dc23b623143ef/app/javascript/hooks/useLinks.ts#L8-L9C31.
The mention class is allow-listed in the HTML sanitiser here: https://github.com/mastodon/mastodon/blob/b06fd54c305915527e3a6edc575dc23b623143ef/lib/sanitize_ext/sanitize_config.rb#L32

So most likely, you just need to put class="mention" on that <a> tag.

@snarfed
Copy link
Owner Author

snarfed commented Nov 1, 2024

😂 😭

Thanks for the sleuthing!

@snarfed snarfed added the now label Nov 1, 2024
snarfed added a commit that referenced this issue Nov 6, 2024
@snarfed
Copy link
Owner Author

snarfed commented Nov 6, 2024

Sadly class="mention" didn't work. Example post:

curl -vL -H 'Accept: application/activity+json' https://bsky.brid.gy/r/https://bsky.app/profile/did:plc:3ljmtyyjqcjee2kpewgsifvb/post/3lacg74pbtb24

eg https://indieweb.social/@snarfed.bsky.social@bsky.brid.gy/113437538777283822 , or if you're not logged into indieweb.social, search for @snarfed.bsky.social@bsky.brid.gy, it's their first post:

image

@snarfed snarfed removed the now label Nov 6, 2024
@Tamschi
Copy link
Collaborator

Tamschi commented Nov 6, 2024

It's close though, it now fails this condition somehow: https://github.com/mastodon/mastodon/blob/d482211aa6293f78f161cbc7149e829966cd8e3a/app/javascript/mastodon/components/status_content.jsx#L108
(The unhandled-link class that gets added made this easy to search for.)

I had to look this up by searching for https://bsky.brid.gy/r/https://bsky.app/profile/did:plc:3ljmtyyjqcjee2kpewgsifvb/post/3lacg74pbtb24, since Mastodon doesn't backfill and other software can't backfill without the outbox. For reference, this is the JSON:

grafik
(I can't copy this as text properly.)

Ohhhhhhh.

It matches the link's href on the account's (web) url property, so it probably expects https://mastodon.social/@snarfed rather than the id https://mastodon.social/users/snarfed in the anchor tag!

That actually makes complete sense, since the post body link is user-facing and should point to an HTML page.

@Tamschi
Copy link
Collaborator

Tamschi commented Nov 6, 2024

Regarding my earlier comment #887 (comment): Turns out the function that detects class="mention" is used only in the account bio: https://github.com/mastodon/mastodon/blob/d482211aa6293f78f161cbc7149e829966cd8e3a/app/javascript/mastodon/components/account_bio.tsx#L7

I think this is different because the lookup is lazy there, because Mastodon doesn't want to eagerly fetch a potentially unbounded network of users that bio-mention each other. Accounts tag-Mentioned in Notes are resolved eagerly though, so there it has it on hand more directly.

@snarfed
Copy link
Owner Author

snarfed commented Nov 7, 2024

Phew. Fediverse hashtags and mentions, ugh, feels like they never end. OK! So the next thing to try here is:

It matches the link's href on the account's (web) url property, so it probably expects https://mastodon.social/@snarfed rather than the id https://mastodon.social/users/snarfed in the anchor tag!

Thanks @Tamschi! BF isn't set up to do this easily right now, not sure how I'd try. Maybe here, load all the mentioned actors, replace their ids in the tags with their urls, run link_tags, then swap the tags back to ids. Heavy, but doable.

as2.link_tags(obj_or_activity)

@Tamschi
Copy link
Collaborator

Tamschi commented Nov 8, 2024

I looked at Granary yesterday to see if I could contribute this directly, but yeah in Python this is beyond me unless the data is right there already.

Some ActivityPub software also accepts the web URL in the Mention's href (GoToSocial, but not Mastodon I think!).
It's definitely cleaner to put the URI there though. That's also what GoToSocial does for outgoing mentions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compat Protocol differences that need special handling.
Projects
None yet
Development

No branches or pull requests

2 participants