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

ATProto => ActivityPub @-mentions #959

Closed
snarfed opened this issue Apr 15, 2024 · 17 comments
Closed

ATProto => ActivityPub @-mentions #959

snarfed opened this issue Apr 15, 2024 · 17 comments

Comments

@snarfed
Copy link
Owner

snarfed commented Apr 15, 2024

Not working yet. Example Bluesky post and bridged fediverse post. Guess I'll go back and refresh my memory on #493.

image

Bluesky, at://did:plc:3ljmtyyjqcjee2kpewgsifvb/app.bsky.feed.post/3kq6zmsmpc52z:

{
  "$type" : "app.bsky.feed.post",
  "createdAt" : "2024-04-15T19:47:50.404Z",
  "text" : "eh indeed, cc @snarfed.indieweb.social.ap.brid.gy eh"
  "facets" : [{
      "$type" : "app.bsky.richtext.facet",
      "features" : [{
          "$type" : "app.bsky.richtext.facet#mention",
          "did" : "did:plc:bg5udl25mvzg3rt7l5n2hzet"
        }],
      "index" : {
        "byteEnd" : 49,
        "byteStart" : 14
      }
    }
  ],
}

AS1:

{
  "objectType": "comment",
  "id": "at://did:plc:3ljmtyyjqcjee2kpewgsifvb/app.bsky.feed.post/3kq6zmsmpc52z",
  "url": "https://bsky.app/profile/did:plc:3ljmtyyjqcjee2kpewgsifvb/post/3kq6zmsmpc52z",
  "content": "eh indeed, cc @snarfed.indieweb.social.ap.brid.gy eh",
  "tags": [{
      "objectType": "mention",
      "url": "https://bsky.app/profile/did:plc:bg5udl25mvzg3rt7l5n2hzet",
      "startIndex": 14,
      "displayName": "@snarfed.indieweb.social.ap.brid.gy",
      "length": 35
    }],
}

AS2:

{
    "type": "Note",
    "id": "https://atproto.brid.gy/convert/ap/at://did:plc:3ljmtyyjqcjee2kpewgsifvb/app.bsky.feed.post/3kq6zmsmpc52z",
    "url": "https://fed.brid.gy/r/https://bsky.app/profile/did:plc:3ljmtyyjqcjee2kpewgsifvb/post/3kq6zmsmpc52z",
    "content": "eh indeed, cc @snarfed.indieweb.social.ap.brid.gy eh",
    "tag": [{
        "startIndex": 14,
        "length": 35,
        "type": "Mention",
        "name": "@snarfed.indieweb.social.ap.brid.gy",
        "href": "https://atproto.brid.gy/ap/https://bsky.app/profile/did:plc:bg5udl25mvzg3rt7l5n2hzet"
      },{
        "type": "Mention",
        "href": "https://indieweb.social/users/snarfed"
      }],
}
@qazmlp
Copy link

qazmlp commented Apr 16, 2024

I did a bit of sleuthing about how Mastodon parses mentions in "content". In short:

So in short:

I think you can keep the mention format in the text, but you'll have to turn it into an HTML link so that it renders properly towards Mastodon clients and the web interface.

I think the mentions in the "tag" property are most likely fine already, as they are turned into account references for any further processing purely by resolving the href, so that Mastodon should prefill them in @user@domain-format when replying to this status.
"startIndex" is completely ignored by Mastodon (0 results), but other software could pick that up, so I'd keep it. I wonder if you'd have to adjust the range to account for inserted HTML-tags, though.

@snarfed
Copy link
Owner Author

snarfed commented Apr 16, 2024

Thanks!

When we tested and got these working from web a while back in #493 (comment), the HTML link in content evidently wasn't necessary, but tag definitely was.

Also, the goal here is more than just a clickable link; it's to make Mastodon actually handle it as a mention, so that when you click on it, it loads the mentioned user in the local instance's UI, instead of navigating your browser to the remote instance.

(startIndex and length are BF-specific warts from the AS1 => AS2 conversion, they exist in AS1 but not AS2. OK technically startIndex exists for collection pages, but not objects like this. We should be able to ignore them here.)

@qazmlp
Copy link

qazmlp commented Apr 16, 2024

Right, tag will give you the semantic mention (notifications, reply autofill I think), unless that isn't reliably working either.

I understood this issue here to be specifically about the inline presentation, which is largely handled separately, and for which I'm pretty certain either the link is necessary or maybe @user@domain formatting of the handle in the text could also work.

@qazmlp
Copy link

qazmlp commented Apr 16, 2024

Also, the goal here is more than just a clickable link; it's to make Mastodon actually handle it as a mention, so that when you click on it, it loads the mentioned user in the local instance's UI, instead of navigating your browser to the remote instance.

I finally found the place this is done, by searching for the status-link class those links have in the web UI. It's matched client-side to the href in tag:

https://github.com/mastodon/mastodon/blob/caad1e2628c78d2dfcd86e3a79b0849dc89baf16/app/javascript/mastodon/components/status_content.jsx#L104-L130

This also confirms that the surrounding markup doesn't matter, you just need an <a> tag at least for Mastodon. The account @ that's inserted into the new local href is the one Mastodon resolved from the tag href too, if I didn't completely misread that earlier.


Edit: Pixelfed seems to be sensitive to the mention class on the link and the link text, but I don't know how much pre-processing that does serverside. It's prone to turn mentions of (that Pixelfed's) local users by Mastodon users into links that 404, though.

(It has multiple rewriteLinks implementations in its frontend and they don't quite seem to all do the same.)

@snarfed
Copy link
Owner Author

snarfed commented May 31, 2024

Looked at this a bit. We need to convert the mention href to the mentioned actor's AP id. Right now we have eg ATProto record at://did:plc:3ljmtyyjqcjee2kpewgsifvb/app.bsky.feed.post/3ksveg5r2qs24:a

{
    "$type": "app.bsky.feed.post",
    "text": "maybe if @snarfed.indieweb.social.ap.brid.gy and #alf meet up",
    "createdAt": "2024-05-20T03:49:56.091Z",
    "facets": [{
      "$type": "app.bsky.richtext.facet",
      "features": [{
          "$type": "app.bsky.richtext.facet#mention",
          "did": "did:plc:bg5udl25mvzg3rt7l5n2hzet"
        }],
      "index": {
        "byteEnd": 44,
        "byteStart": 9
      }
    }],
  }

...to AS2:

{
  "id": "https://bsky.brid.gy/convert/ap/at://did:plc:3ljmtyyjqcjee2kpewgsifvb/app.bsky.feed.post/3ksveg5r2qs24",
  "url": "https://fed.brid.gy/r/https://bsky.app/profile/did:plc:3ljmtyyjqcjee2kpewgsifvb/post/3ksveg5r2qs24",
  "content": "<p>maybe if <a href=\"https://bsky.brid.gy/ap/https://bsky.app/profile/did:plc:bg5udl25mvzg3rt7l5n2hzet\">@snarfed.indieweb.social.ap.brid.gy</a> and <a href=\"https://bsky.brid.gy/hashtag/alf\">#alf</a> meet up</p>",
  "published": "2024-05-20T03:49:56.091Z",
  "attributedTo": "https://bsky.brid.gy/ap/did:plc:3ljmtyyjqcjee2kpewgsifvb",
  "@context": "https://www.w3.org/ns/activitystreams",
  "type": "Note",
  "tag": [{
      "type": "Mention",
      "name": "@snarfed.indieweb.social.ap.brid.gy",
      "href": "https://bsky.brid.gy/ap/https://bsky.app/profile/did:plc:bg5udl25mvzg3rt7l5n2hzet"
    }],
}

@snarfed
Copy link
Owner Author

snarfed commented May 31, 2024

Current status: Object.get_by_id("at://did:plc:3ljmtyyjqcjee2kpewgsifvb/app.bsky.feed.post/3ksveg5r2qs24").as1 has the mention url as https://bsky.app/profile/did:plc:bg5udl25mvzg3rt7l5n2hzet. resolve_ids in Protocol.receive should detect that that's a copy id and convert to the original, https://indieweb.social/users/snarfed, but I expect it's getting tripped up by the bsky.app URL.

@mackuba
Copy link

mackuba commented May 31, 2024

So that should eventually show the mention as "@snarfed@indieweb.social" in the post text on the Mastodon side, right?

@snarfed
Copy link
Owner Author

snarfed commented May 31, 2024

Yes, or just @snarfed. More importantly, it should be a mention, ie link to that fediverse account inside the local instance wherever you're reading it, as usual.

snarfed added a commit that referenced this issue Jun 2, 2024
@snarfed
Copy link
Owner Author

snarfed commented Jun 2, 2024

^ Progress. We're now at least generating the right Mention tag to notify the mentioned user. Example: https://bsky.app/profile/snarfed.bsky.social/post/3ktxejevy3s2o => https://indieweb.social/@snarfed.bsky.social@bsky.brid.gy/112547944255049449

The link doesn't get rewritten to point to the mentioned user inside the local instance, though. It's a normal HTML link that goes to the user on their own instance. Example of how I'd ideally like it to work: https://indieweb.social/@tchambers/112542225021901875 . I've gotten this working before with Web => AP, not sure what needs to change. Does the mention link text need to be the AP handle? Something else? Back to #493, my old nemesis.

@snarfed snarfed removed the now label Jun 2, 2024
@qazmlp
Copy link

qazmlp commented Jun 3, 2024

I'm pretty sure this is because you're using "name":"@snarfed.indieweb.social.ap.brid.gy", instead of "name":"@snarfed@indieweb.social", for the "Mention"-"tag".

Remember that these get matched href=-to-"href": in Mastodon, not text-to-"name" as in the standard!

(I think this is another case of Mastodon overusing @@-handles again. Other apps may skip that indirection and use the href directly. I'm not sure there is actually any software that matches text-to-"name" though, but that probably should still match.)

@snarfed
Copy link
Owner Author

snarfed commented Jun 3, 2024

text-to-"name" as in the standard!

@qazmlp out of curiosity, are you talking about this section? https://www.w3.org/TR/activitystreams-vocabulary/#microsyntaxes

A typical social software implementation would typically render such a content such that "@sally" is replaced with a hyperlink to "@sally"'s social profile page and "#givingthanks" is replaced with a hyperlink to a listing of other notes that have been "tagged" with the same topic. Most implementations would also send a special notification to sally letting her know that a note mentioning her has been created.

Not normative, but still, useful if so, thanks for the nudge.

@qazmlp
Copy link

qazmlp commented Jun 3, 2024

I'm talking about "EXAMPLE 158" which appears to have the post content as plaintext in JSON:

{
  "@context": "https://www.w3.org/ns/activitystreams",
  "name": "A thank-you note",
  "type": "Note",
  "content": "Thank you @sally for all your hard work! #givingthanks",
  "tag": [
    {
      "type": "Mention",
      "href": "http://example.org/people/sally",
      "name": "@sally"
    },
    {
      "id": "http://example.org/tags/givingthanks",
      "name": "#givingthanks"
    }
  ]
}

I'm not sure if any behaviour is actually being prescribed there, though, and in my opinion automatic parsing of incoming plaintext without markup isn't usually a great idea, generally speaking.

@snarfed
Copy link
Owner Author

snarfed commented Jun 3, 2024

I'm not sure if any behaviour is actually being prescribed there, though, and in my opinion automatic parsing of incoming plaintext without markup isn't usually a great idea, generally speaking.

Right! That whole section is non-normative, so no, they're not prescribing behavior per se, and they agree with you on avoiding parsing text content. From the beginning of the section:

Many social software systems use special text-based microsyntaxes that allow users to define special addressing for notifications, linking, or categorization within objects. For example, including text such as "@username" within an object's content will often route the object to a special "mentions" or "inbox" stream for a particular user. Likewise, including text such as " #topic" within the object's content will often mark the object as being related to the topic "topic"...

While such microsyntaxes MAY be used within the values of the content, name, and summary properties on an Activity Streams Object, implementations SHOULD NOT be required to parse the values of those properties in order to determine the appropriate routing of notifications, categorization or linking between objects. Instead, publishers SHOULD make appropriate use of the vocabulary terms provided specifically for these purposes.

@snarfed snarfed added the now label Jun 3, 2024
@snarfed
Copy link
Owner Author

snarfed commented Jun 5, 2024

Looking at this again. Here's the (pruned) AS2 object for the example above with the mention that notified the Mastodon user but didn't get rewritten. The mention href is the mentioned user's AP id, and the href and name both match the link href and text, respectively, in the HTML content. 🤷

{
   "@context" : "https://www.w3.org/ns/activitystreams",
   "type" : "Note",
   "id" : "https://bsky.brid.gy/convert/ap/at://did:plc:3ljmtyyjqcjee2kpewgsifvb/app.bsky.feed.post/3ktxejevy3s2o",
   "url" : "https://fed.brid.gy/r/https://bsky.app/profile/did:plc:3ljmtyyjqcjee2kpewgsifvb/post/3ktxejevy3s2o"
   "attributedTo" : "https://bsky.brid.gy/ap/did:plc:3ljmtyyjqcjee2kpewgsifvb",
   "content" : "<p><a href=\"https://indieweb.social/users/snarfed\">@snarfed.indieweb.social.ap.brid.gy</a> and <a href=\"https://bsky.brid.gy/hashtag/alf\">#alf</a> should meet up again</p>",
   "tag" : [{
         "href" : "https://indieweb.social/users/snarfed",
         "name" : "@snarfed.indieweb.social.ap.brid.gy",
         "type" : "Mention"
      },{
         "href" : "https://bsky.brid.gy/hashtag/alf",
         "name" : "#alf",
         "type" : "Hashtag"
      }],
}

@snarfed
Copy link
Owner Author

snarfed commented Jun 5, 2024

From Mastodon's AP docs:

In the ActivityStreams Vocabulary, Mention is a subtype of Link that is intended to represent the microsyntax of @mentions. The tag property is intended to add references to other Objects or Links. For Link tags, the name of the Link should be a substring of the natural language properties (name, summary, content) on that object. Wherever such a substring is found, it can be transformed into a hyperlink reference to the href.

It's not clear whether that describes what Mastodon actually does, or just what's generally possible with AS2 Mentions.

@snarfed snarfed removed the now label Jun 5, 2024
@snarfed
Copy link
Owner Author

snarfed commented Jun 19, 2024

I think this is now the same as #887.

@snarfed
Copy link
Owner Author

snarfed commented Jun 25, 2024

Closing, will track the local rewriting in #887.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants