[solved] What's the interoperable mention format?

Hi, Hypolite from Friendica here.

I’ve been asked today why the Mastodon mentions displayed in Friendica-originated posts link to the remote server profile instead of opening the local user profile.

See this thread lostinlight: "🐉 Important question Have you collected anything…" - Mastodon

Here’s the HTML code for a mention in Mastodon from Mastodon:

<span class="h-card">
  <a href="https://friendica.mrpetovan.com/profile/hypolite" class="u-url mention">
    @<span>hypolite</span>
  </a>
</span>

And here’s the HTML code for a mention in Mastodon from Friendica:

@<span class="">
  <a href="https://mastodon.xyz/users/lightone" class="u-url mention" rel="nofollow noopener noreferrer" target="_blank">
    <span class="mention">lightone</span>
  </a>
</span>

As you can see, the h-card class is missing from the latter, and the link is treated like an external link with the rel="nofollow noopener noreferrer" target="_blank" attributes.

Additionally, the @ sign is located outside of the link but I’m not sure if it’s important.

I couldn’t find any spot in Friendica where we would be generating this code so I assume that there’s a convention in Mastodon messages to format mentions a certain way which gets displayed this way, while Friendica almost-but-not-quite-the-same format doesn’t pass muster.

So what’s the correct mention format for them to behave the same whether they come from Friendica or from Mastodon?

Thank you in advance for our consideration.
Hypolite Petovan

1 Like

I just checked some HTML generated by mastodon.social:

<span class="h-card"><a href="https://mastodon.social/@saper" class="u-url mention status-link" title="saper" target="_blank" rel="noopener noreferrer">@<span>saper</span></a></span>

it looks pretty what you need - but the information gets transferred over to Friendica as ActivityPub JSON so I am not sure if HTML is really involved here.

Thank you for the reply, I’m currently knee-deep in Mastodon’s code, and it looks like the decision for each link to be “handled” or not as a mention of a local account is done in app/javascript/mastodon/components/status_content.js where a link is transformed into a local mention if its URL matches the list of mentions of the corresponding status. However, I don’t know where this list of mentions comes from exactly.

See mastodon/status_content.js at 1fb92037e432913902a5e5c8a5b673b036d84cb8 · tootsuite/mastodon · GitHub

      let mention = this.props.status.get('mentions').find(item => link.href === item.get('url'));

      if (mention) {
        link.addEventListener('click', this.onMentionClick.bind(this, mention), false);
        link.setAttribute('title', mention.get('acct'));
      } else if (link.textContent[0] === '#' || (link.previousSibling && link.previousSibling.textContent && link.previousSibling.textContent[link.previousSibling.textContent.length - 1] === '#')) {
        link.addEventListener('click', this.onHashtagClick.bind(this, link.text), false);
      } else {
        link.setAttribute('title', link.href);
        link.classList.add('unhandled-link');
      }

Yes, but that’s the user interface only. I think the problem is deeper in the ActivityPub messages exchanged between Mastodon and Friendica.

Never mind, I found the issue. Mastodon’s mentions array uses the https://domain.tld/@username profile URL format while Friendica uses the https://domain.tld/users/username profile URL format. Both work to access a profile page, but in this context, they don’t match the link URL and the it ends up “unhandled”.

It’s unfortunate because in the Friendica-originated AP message, these URLs match, but it is transformed by Mastodon before being displayed. This means we have to use the https://domain.tld/@username format in the link URLs of the message body.

Anyway, I have my answer, thank you for entertaining my request!

We’ve gone back and forth on this behavior, but I think the last time this came up, our stance on the matter is “For accounts which have a difference between their url and their id, their user-facing context should use the url. Therefore, we apply our UX optimizations to the url, but not the id—the assumption is that if the user ever does get linked to the actor’s id, and it’s different from the url, then that’s an intentional distinction that we should preserve”

Obviously, this justification is a little weird in this case because you’re just echoing the URL back at us, and Friendica doesn’t make the id/url distinction natively, but since the consequence is extremely minor (basically just a matter of the front-end behaving differently), it’s probably not a huge priority to change.

Hi, thanks for the elaboration, I don’t think Mastodon needs to be changed. It would be nice if it would use the same mention URL that was provided in the original message, but it’s probably more a matter for us at Friendica to switch from one format to another as the “primary” one. We don’t have this id/url distinction because our data model predates AP, instead we have url/alias which we could exchange for Mastodon contacts.

By this I assume that you mean the url in the mentions array? That will always be the id, not the url. (Since it’s a URI that’s uniquely identifying the actor in question)

Thank you for the clarification. Would mentions still work if Friendica sent the account url and not the id in the AP tag.href property?

Never mind again, it was a trivial change in Friendica to have the id in the tag list and the url in the message body.

2 Likes