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

Link previews from Mastodon should show more info with Apple link view #20569

Closed
jaanus opened this issue Nov 13, 2022 · 20 comments
Closed

Link previews from Mastodon should show more info with Apple link view #20569

jaanus opened this issue Nov 13, 2022 · 20 comments
Labels
bug Something isn't working

Comments

@jaanus
Copy link

jaanus commented Nov 13, 2022

Steps to reproduce the problem

  1. Share a link to a post on Mastodon in some system which uses Apple’s LPLinkView to render link previews
  2. Observe the preview that gets rendered

Expected behaviour

The link preview should have the post content

Actual behaviour

Link preview only shows avatar of author

Detailed description

(This issue may well affect also other systems that render previews of web links. I limit my discussion only to Apple LPLinkView because that’s what I’m familiar with.)

Link previews of Mastodon posts aren’t useful. They only show a large avatar of the author, and nothing about the post itself. Here is an example.

Link preview for https://mastodon.social/@Gargron/109300299959535882 rendered with LPLinkView looks like this:

mastodon post preview

As comparison, link preview for a tweet like https://twitter.com/joinmastodon/status/1591089671794462720 looks like this, which is much more useful:

twitter preview

Apple does not disclose how exactly they generate the previews. They definitely crawl the URL, and the preview is probably some combination of OpenGraph content, HTML metadata, and content parsing.

Link previews are powered by the LPLinkMetadata. I give a URL to LPMetadataProvider which fetches the link for me and generates the metadata object.

I can inspect the metadata objects in debugger. Here is what the data looks like for the Mastodon post:

mastodon in debugger

And here is the same for the Twitter post:

twitter in debugger

You see that the link metadata for the Mastodon post actually contains the Mastodon post content, but for whatever reason, the Apple LPLinkView decides not to render it, and only shows me the author’s avatar.

I am not sure how other link preview renderers behave with Mastodon posts. Maybe it’s only an Apple quirk. Nevertheless, there are quite a few Apple users out there, and many apps use the system-provided link previews. It would be nice to provide more informative previews for Mastodon posts.

Specifications

Mastodon server version on mastodon.social that was used to fetch the post: v4.0.0rc3

@jaanus jaanus added the bug Something isn't working label Nov 13, 2022
@connorshea
Copy link
Contributor

It's unfortunate that they don't just use normal opengraph things, since Discord is able to embed toots just fine:

Screen Shot 2022-11-13 at 11 11 57 AM

@connorshea
Copy link
Contributor

Also, for devs: the best way to reproduce this is via Apple's Messages app, if you have an iPhone/macOS device.

@connorshea
Copy link
Contributor

Here's Twitter's HTML <head> vs Mastodon's, with the stuff that seemed irrelevant stripped out (link tags, script and style tags, android-specific things, fb/google things, etc)

Mastodon:

<meta content="#191b22" name="theme-color">
<meta content="yes" name="apple-mobile-web-app-capable">
<title>Eugen 💀: "I've changed quite a few parts…" - Mastodon</title>
<meta content="Mastodon" property="og:site_name">
<meta content="article" property="og:type">
<meta content="Eugen 💀 (@Gargron@mastodon.social)" property="og:title">
<meta content="https://mastodon.social/@Gargron/109300299959535882" property="og:url">
<meta content="2022-11-07T03:03:41Z" property="og:published_time">
<meta content="I've changed quite a few parts on joinmastodon.org/servers today in response to the feedback from the past week. In detail:

You can now filter by region, type of legal entity, and sign-up speed. Added note about why the topics filter exists. Changed tagline.

&quot;Get on waitlist&quot; has become &quot;Apply for an account&quot; for servers that manually review new sign-ups. Removed total user count from cards." name="description">
<meta content="I've changed quite a few parts on joinmastodon.org/servers today in response to the feedback from the past week. In detail:

You can now filter by region, type of legal entity, and sign-up speed. Added note about why the topics filter exists. Changed tagline.

&quot;Get on waitlist&quot; has become &quot;Apply for an account&quot; for servers that manually review new sign-ups. Removed total user count from cards." property="og:description">

<meta content="https://files.mastodon.social/accounts/avatars/000/000/001/original/dc4286ceb8fab734.jpg" property="og:image">
<meta content="400" property="og:image:width">
<meta content="400" property="og:image:height">
<meta content="summary" property="twitter:card">

Twitter:

<meta property="og:site_name" content="Twitter">
<link rel="mask-icon" sizes="any" href="https://abs.twimg.com/responsive-web/client-web/icon-svg.168b89d9.svg" color="#1D9BF0">
<meta name="theme-color" content="#FFFFFF">
<title>Marphy Black on Twitter: "I always felt the most curious alteration made to Gordon's model in Half-Life's Dreamcast port is blahblahblah</title>
<meta content="article" property="og:type" data-rh="true">
<meta description="" name="description" data-rh="true">
<meta content="https://twitter.com/SlappyCromwell/status/1591457037761671168" property="og:url" data-rh="true">
<meta content="Marphy Black on Twitter" property="og:title" data-rh="true">
<meta content="“I always felt the most curious alteration made to Gordon's model in Half-Life's Dreamcast port is blahblahblah”" property="og:description" data-rh="true">
<meta content="https://pbs.twimg.com/media/FhXKLxtXwAM2Do5.jpg:large" property="og:image" data-rh="true">
<meta content="twitter://status?id=1591457037761671168" property="al:ios:url" data-rh="true">
<meta content="333903271" property="al:ios:app_store_id" data-rh="true">
<meta content="Twitter" property="al:ios:app_name" data-rh="true">

Interestingly, the primary difference appears to be that Twitter does not use og:image unless it's an image embedded into the tweet. So for text-only tweets, it doesn't include an image property. Mastodon uses og:image for toots to represent the user's profile picture.

@connorshea
Copy link
Contributor

connorshea commented Nov 13, 2022

Okay, so after playing around with this for the last while, I'm pretty sure this can't be fixed by Mastodon (unless you do some very cursed things). It's hardcoded so it only works for twitter.

This HTML:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=0,viewport-fit=cover">
    <meta property="og:site_name" content="Mastodon">
    <link rel="mask-icon" sizes="any" href="https://abs.twimg.com/responsive-web/client-web/icon-svg.168b89d9.svg" color="#1D9BF0">
    <link rel="shortcut icon" href="//abs.twimg.com/favicons/twitter.2.ico">
    <link rel="apple-touch-icon" sizes="192x192" href="https://abs.twimg.com/responsive-web/client-web/icon-ios.b1fc7279.png">
    <meta name="theme-color" content="#191b22">
    <title>Eugen 💀: "I've changed quite a few parts…" - Mastodon</title>
    <meta content="article" property="og:type">
    <meta description="" name="description">
    <meta content="https://mastodon.social/@Gargron/109300299959535882" property="og:url">
    <meta content="Eugen 💀 (@Gargron@mastodon.social)" property="og:title">
    <meta
      content="“I've changed quite a few parts on joinmastodon.org/servers today in response to the feedback from the past week. In detail:”"
      property="og:description">
  </head>

  <body>
    Foo
  </body>

</html>

Gets us this in LinkPreview:

Screen Shot 2022-11-13 at 12 31 09 PM

This HTML:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=0,viewport-fit=cover">
    <meta property="og:site_name" content="Mastodon">
    <link rel="mask-icon" sizes="any" href="https://abs.twimg.com/responsive-web/client-web/icon-svg.168b89d9.svg" color="#1D9BF0">
    <link rel="shortcut icon" href="//abs.twimg.com/favicons/twitter.2.ico">
    <link rel="apple-touch-icon" sizes="192x192" href="https://abs.twimg.com/responsive-web/client-web/icon-ios.b1fc7279.png">
    <meta name="theme-color" content="#191b22">
    <title>Eugen 💀: "I've changed quite a few parts…" - Mastodon</title>
    <meta content="article" property="og:type">
    <meta description="" name="description">
    <meta content="https://twitter.com/Redistrict/status/1591657489933938689" property="og:url">
    <meta content="Eugen 💀 (@Gargron@mastodon.social)" property="og:title">
    <meta
      content="“I've changed quite a few parts on joinmastodon.org/servers today in response to the feedback from the past week. In detail:”"
      property="og:description">
  </head>

  <body>
    Foo
  </body>

</html>

Gets us this in LinkPreview:

Screen Shot 2022-11-13 at 12 33 09 PM

The ONLY difference is that the og:url meta tag was changed to point to a random tweet by Dave Wasserman. I'm fairly certain the special display for tweets only works for URLs hardcoded to twitter.com :|

Maybe we should open a Radar ticket to fix this, or something?

All tested on macOS Monterey 12.6 by just throwing stuff at the wall with basic HTML on a github pages site.

@ineffyble
Copy link
Member

I'm fairly certain the special display for tweets only works for URLs hardcoded to twitter.com

Wouldn't surprise me, a lot of platforms handle Twitter in a special way unfortunately.

@jaanus
Copy link
Author

jaanus commented Nov 14, 2022

Yes, there seems to be special treatment for Twitter in Apple LinkPreview (as in other platforms too). I’ve seen lots of LinkPreviews from different sites and now that I think of it, Twitter is the only one where the content is expanded. Influencing internal working and special rules inside Apple LinkPreview is beyond the scope of this bug and we can’t expect it to happen.

Nevertheless, even within these constraints, the previews for Mastodon posts could be much more useful, compared to the current one seen above. I made a few more examples.

https://github.com/mastodon/mastodon/issues/20583

Screenshot 2022-11-14 at 09 42 55

https://www.bbc.com/future/article/20221103-how-language-warps-the-way-you-perceive-time-and-space

Screenshot 2022-11-14 at 09 44 06

Github is especially interesting because they encode a lot of info into the image 🙃 here is the extracted image from that. (Original image URL: https://opengraph.githubassets.com/ba3a59c4a81dbae2bea65e42a904b82b02fa9320b2d12a3e04ca03d27d59a89d/mastodon/mastodon/issues/20583)

20583

Generating the image is cool, but unlikely to be worth the work for Mastodon currently.

What I think would make the most sense for Mastodon is to set up the metadata so that the author’s image does not end up being so big, and the title text is the beginning of the post content, instead of just referring to the author. You often won’t see the full content of the post, but just the beginning would be useful to get a flavor/taste of what the post is about, and deciding whether to tap on the preview to see the full thing.

@zwaldowski
Copy link

From disassembly, I can support the special tweet formatting comes from it detecting specifically Twitter or Sina Weibo URLs. (+[LPPresentationSpecializations isMicroblogPost:])

With that being acknowledged, what should it be doing instead? From the OpenGraph side, how is og:type = article alone going to tell you something is a microblog post or a long read? I can imagine that not a lot of implementations are going to do anything with og:description because it's so rarely useful. (Outside of microblogs, it's often a marketing description of the entire site, even for a post on the site.)

Maybe it would be additional to throw up some non-standard attributes and build support around that, rather than encouraging one-off exceptions.

As others have pointed out, there are likely improvements to be made to the tags as we provide them now.

@connorshea
Copy link
Contributor

I've submitted a Radar for Apple to hopefully improve the way LPLinkView works, ID FB11832545 in case any Apple employees happen to see this :)

@czyz
Copy link

czyz commented Jan 3, 2023

Based on examination of the html of a twitter post and a mastodon post, I guessed in my closed-as-a-dupe issue #22382 that I suspected Messages is using the og:title and og:image tag information (as well as possibly some other meta tags) and discarding og:description. I wonder if it's possible for Mastodon server to detect the user-agent used by Messages and serve it a special version of the post in which the contents that would go into og:description is stuffed into og:title and og:image is omitted if there's no image in the post? I don't like the idea of serving things wrong as a special case, but I think this is an important case and I don't know how quickly or whether Apple will fix their implementation. A comment on the closed issue suggests that Messages isn't the only app that this might fix.

I don't have a dev build of Mastodon up and running to try a test, I suppose maybe I could just put some static HTML versions of twitter and Mastodon posts on my web server and see what tweaks to the opengraph tags (and possibly the <meta name="Author" content="Publication Name" /> tag) do to links pasted into Apple Messages.

@ineffyble
Copy link
Member

the contents that would go into og:description is stuffed into og:title

I can't imagine that would look very nice.

@czyz
Copy link

czyz commented Jan 4, 2023

It's what twitter does. If you open up this link in a browser and then examine the resulting source (getting the contentss of the tweet to display requires javascript), you'll find there's a tag that looks like this:

<meta content="“In scathing exit memo, Meta VR expert John Carmack derides the company's bureaucracy: 'I have never been able to kill stupid things before they cause damage.' https://t.co/YAuRQEDRYN”" property="og:description" data-rh="true">

And when I send that twitter URL to myself via Apple Messages, its preview renders like so, which seems to be using the full contents of that og:title:

image

The og:title tag of "Insider Business on Twitter" appears to be ignored by Messages. It does attribute the tweet in the preview to "Insider Business", so maybe it isn't ignoring og:title but is doing a special-case-for-twitter grep of og:title for (.+)(?: on Twitter).

@czyz
Copy link

czyz commented Jan 4, 2023

Whoa, so I'm totally wrong. There's the og:description right there, not og:title. I'm face-palming right now.

It remains a mystery to me why URLs to Mastodon posts don't end up with better previews in Messages.

@thillsman
Copy link

The ONLY difference is that the og:url meta tag was changed to point to a random tweet by Dave Wasserman. I'm fairly certain the special display for tweets only works for URLs hardcoded to twitter.com :|

I found the same thing. It seems to require a format of https://twitter.com/x/status/x. (I shared that here: https://mastodon.social/@thillsman/109739680807358262)

I did the very cursed thing (😂) as a hacky workaround for https://mstdn.link but I'd agree it's improper to update the actual project and the ball's fully in Apple's court for this, unfortunately.

@jaanus
Copy link
Author

jaanus commented Jan 27, 2023

I wonder if it's possible for Mastodon server to detect the user-agent used by Messages and serve it a special version of the post in which the contents that would go into og:description is stuffed into og:title and og:image is omitted if there's no image in the post?

This is not only about Messages. Many other apps use LPLinkView for web previews. Including Mastodon apps. I'm not sure if the user agent for LPLinkMetadata fetcher is always the same, or does it depend on the app.

@jaanus
Copy link
Author

jaanus commented Feb 7, 2023

One other tidbit. Link previews for Mastodon posts that contain images are actually really nice, and exactly as expected. The problem is only about the posts with text. Here is a nice LPLinkView of a Mastodon post with images.

You could argue that if the post has both images and text (like this one), it could show some text as well, but that doesn’t matter so much. The images already provide a lot of valuable preview smell.

Screenshot 2023-02-07 at 09 48 53

@kamcma
Copy link

kamcma commented Feb 7, 2023

I'd actually suggest Mastodon should remove the account profile photo header from the markup for links to individual posts, on the logic that the profile photo is per se associated with the account, and not individual posts from that account. Until such time as Apple's Link Preview framework supports text preview content generally and not as a special-casing of Twitter, when sent/sending a Mastodon post link with no attachments, I'd personally rather see a media-less Link Preview in my Messages, with just the user name and domain text. A giant profile photo (perhaps repeated over and over, if you send multiple links) isn't directly relevant and unnecessarily takes up huge vertical space in the message thread.

@davidmnelson
Copy link

I'd actually suggest Mastodon should remove the account profile photo header from the markup for links to individual posts, on the logic that the profile photo is per se associated with the account, and not individual posts from that account. Until such time as Apple's Link Preview framework supports text preview content generally and not as a special-casing of Twitter, when sent/sending a Mastodon post link with no attachments, I'd personally rather see a media-less Link Preview in my Messages, with just the user name and domain text. A giant profile photo (perhaps repeated over and over, if you send multiple links) isn't directly relevant and unnecessarily takes up huge vertical space in the message thread.

FWIW I like this suggestion because the giant profile photo can create a false impression that the profile photo is the content being shared. The recipient may not realize they are supposed to click on it to read a text-based message.

@Gargron
Copy link
Member

Gargron commented Feb 7, 2023

Already removed in main branch.

@kamcma
Copy link

kamcma commented Feb 16, 2023

iOS 16.4 beta 1 may have added Mastodon support to message previews.

@jaanus
Copy link
Author

jaanus commented Apr 2, 2023

I am closing this as the original reporter, because in iOS 16.4 Apple indeed greatly improved how LPLinkView renders Mastodon previews.

For reference, this is how the link from my original report is now presented.

image

@jaanus jaanus closed this as completed Apr 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

9 participants