snarfed / bridgy-fed

šŸŒ‰ A bridge between decentralized social network protocols
https://fed.brid.gy
Creative Commons Zero v1.0 Universal
565 stars 30 forks source link

ATProto => ActivityPub link previews #958

Closed snarfed closed 3 months ago

snarfed commented 5 months ago

They're partially making it over, but not all the way. Example Bluesky post and bridged fediverse post.

image

Bluesky record, pruned:

{
  "cid" : "bafyreicxnk4ipbjh5g3rikqa3hlmzee4dl3mdgahif7n3aezwdixggsaau",
  "uri" : "at://did:plc:3ljmtyyjqcjee2kpewgsifvb/app.bsky.feed.post/3kq6zy5it5k2i",
  "value" : {
    "$type" : "app.bsky.feed.post",
    "createdAt" : "2024-04-15T19:54:10.898Z",
    "embed" : {
      "$type" : "app.bsky.embed.external",
      "external" : {
        "description" : "",
        "thumb" : {
          "$type" : "blob",
          "mimeType" : "image/jpeg",
          "ref" : {"$link" : "bafkreiemenxtcacg5p4m4ck6iofqgcqyfulhbwq5lsatrwgd4kvvbtxjz4"},
          "size" : 377240
        },
        "title" : "Adeline Software International - Wikipedia",
        "uri" : "https://en.wikipedia.org/wiki/Adeline_Software_International"
      }
    },
    "text" : "and now with a link"
  }
}

AS1:

{
  "objectType": "note",
  "id": "at://did:plc:3ljmtyyjqcjee2kpewgsifvb/app.bsky.feed.post/3kq6zy5it5k2i",
  "url": "https://bsky.app/profile/did:plc:3ljmtyyjqcjee2kpewgsifvb/post/3kq6zy5it5k2i",
  "content": "and now with a link",
  "attachments": [{
      "objectType": "link",
      "url": "https://en.wikipedia.org/wiki/Adeline_Software_International",
      "displayName": "Adeline Software International - Wikipedia",
      "image": "https://morel.us-east.host.bsky.network/xrpc/com.atproto.sync.getBlob?did=did:plc:3ljmtyyjqcjee2kpewgsifvb&cid=bafkreiemenxtcacg5p4m4ck6iofqgcqyfulhbwq5lsatrwgd4kvvbtxjz4"
    }]
}

AS2:

{
  "type": "Note",
  "id": "https://atproto.brid.gy/convert/ap/at://did:plc:3ljmtyyjqcjee2kpewgsifvb/app.bsky.feed.post/3kq6zy5it5k2i",
  "url": "https://fed.brid.gy/r/https://bsky.app/profile/did:plc:3ljmtyyjqcjee2kpewgsifvb/post/3kq6zy5it5k2i",
  "content": "and now with a link",
  "attachment": [{
      "url": "https://en.wikipedia.org/wiki/Adeline_Software_International",
      "image": "https://morel.us-east.host.bsky.network/xrpc/com.atproto.sync.getBlob?did=did:plc:3ljmtyyjqcjee2kpewgsifvb&cid=bafkreiemenxtcacg5p4m4ck6iofqgcqyfulhbwq5lsatrwgd4kvvbtxjz4",
      "name": "Adeline Software International - Wikipedia"
    }],
  },
}
qazmlp commented 5 months ago

For Mastodon, you'll want to put the image URL in the attachment's icon or icon.url property, according to this code.

qazmlp commented 5 months ago

Pixelfed will drop any posts with link attachments that aren't replies, as it's strict about supported attachment types. Edit: Fixed URL.

I think that, generally speaking, you definitely should add a "type" property to the attachment to signal intent. Judging by the commented-out code in Pixelfed (second link), PeerTube uses/used "type": "Link" for this purpose.

It seems that PeerTube (now?) sends Video Objects instead of Notes, though, and creates attachments with "type": "Video". It ignores the "attachment" property on Notes, as far as I can tell, so if someone would comment on a video with an attachment-only link on Bsky, that link would be lost there.

snarfed commented 5 months ago

I'm actually surprised that fediverse servers, or at least Mastodon, use anything in attachments for link previews at all, if it even does? Mastodon famously refetches links itself to generate previews instead of trusting the remote server that sent the activity: https://github.com/mastodon/mastodon/issues/4486 , https://github.com/mastodon/mastodon/issues/23662

qazmlp commented 5 months ago

It's an edge case of a fallback, yeah. Mastodon does not actually support link attachments outside the content at all, but if it receives an attachment that it doesn't support, it will reliably render that as some form of clickable placeholder. (The app is a little better about telling you what's behind there, in my experience.)

Thinking about it, the semantic intention of icon is most likely "file icon" or "favicon". (I don't know how it renders in practice. I think you can also colour in that rectangle with a Blurhash.)

I noticed that Akkoma can apparently show some kind of summary text when it can't show the attachment preview, but I can't read its source code well enough to know how to make use of that.

I think it's fair to say that "links as attachments" just isn't something that's widely supported by Fediverse apps, even if in my opinion it should be, and could be a way to not overwhelm the link destination.

qazmlp commented 5 months ago

It breaks very badly in some third-party clients, though:

Elk.zone - tall image ![image](https://github.com/snarfed/bridgy-fed/assets/17500283/d37192d2-65f7-4111-b4b4-721b787a7b03)

Similar issue in Phanpy: image

I can't even click through there (in either case), even though technically the information is provided by Mastodon: image

snarfed commented 5 months ago

It breaks very badly in some third-party clients, though:

Right, and it breaks in Mastodon itself too, eg the screenshot in the original description here.

The AS2 attachment here was converted automatically by granary from the embed facet in the Bluesky post. I wasn't intentionally trying to generate a link preview in the fediverse; I expected Mastodon and most others to fetch the link and generate the preview themselves, like they usually do.

Regardless, you're right, type: Link should hopefully fix this. šŸ¤ž

qazmlp commented 5 months ago

Regardless, you're right, type: Link should hopefully fix this. šŸ¤ž

Unfortunately not at first, since I don't think anything actually supports that kind of attachment. It would make it decently easy for Mastodon et al to add support for it, though, as then there'd be a clear intent.

The only way to make links work reliably and render correctly, currently, is to insert them into the post content for (almost all?) fediverse apps, unfortunately, since they follow Twitter's data model in that regard.

snarfed commented 5 months ago

Looking at this again, I'm inclined to just remove these attachments altogether and let fediverse servers generate their own link previews, since that's the happier and more common path in the fediverse.

snarfed commented 5 months ago

Reopening this, @bnewbold inspired me to try again to see if I can get fedi servers to render link previews that are separate from post text. I never actually tried with type: Link. I should!

bnewbold commented 5 months ago

to clarify, what i was reporting was that sometimes there is a bsky post with no URL in the text and only a card/embed. In those cases, it feels like the URL from the embed should be appended to the end of the post text (with a <br> or two?), so that the link preview will render. Otherwise there is just the post text commenting on the referenced content, but no URL or link preview at all on the AP side.

At least in the case of:

just remove these attachments altogether and let fediverse servers generate their own link previews, since that's the happier and more common path in the fediverse

snarfed commented 5 months ago

Right! I get it. I generally try pretty hard to not modify users' original post text at all, so I first plan to try to get the AS2 equivalent of a Link attachment without its URL in the post text working. If that doesn't work, I can consider appending the URL to the post text.

snarfed commented 3 months ago

Tried again just now with type: Link and icon, but no dice, Mastodon still renders it as "Preview not available." It is at least clickable and linked to the url, and shows the name on hover, but still.

image

snarfed commented 3 months ago

I went the HTML-link-in-content route. Example: https://indieweb.social/@snarfed.bsky.social@bsky.brid.gy/112645157258479340 . Should be deployed in ~10m.