Changeset 204bd74 in Klonkt


Ignore:
Timestamp:
06/27/2026 12:28:08 PM (2 months ago)
Author:
Robin Genis <roboburr@…>
Branches:
main
Children:
0a7ba90
Parents:
04c70fc
Message:

fix(fedi): mention link href = profile URL, actor URI in the Mention tag (data-actor)

  • services/ActivityPubService.js — mention links used the actor URI as href, so on Mastodon a click opened the remote AP endpoint instead of the profile. Now the link href is the human profile URL (actor.url) with the actor URI carried in data-actor; mentionTags reads data-actor for the Mention tag href. Applies to deliverReply, resolveMentionsInText and deliverOutboxUpdate.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/services/ActivityPubService.js

    r04c70fc r204bd74  
    934934function mentionTags(content) {
    935935  const tags = [], seen = new Set();
    936   const re = /<a href="([^"]+)" class="u-url mention">@([^<]+)<\/a>/gi;
     936  // The link href is the human profile URL; the actor URI (for the Mention tag) is in data-actor.
     937  const re = /<a href="[^"]*" class="u-url mention" data-actor="([^"]+)">@([^<]+)<\/a>/gi;
    937938  let m;
    938939  while ((m = re.exec(content || ''))) {
     
    959960    const inbox = actor && ((actor.endpoints && actor.endpoints.sharedInbox) || actor.inbox);
    960961    if (inbox) inboxes.push(inbox);
     962    const profileUrl = actorInfo(actor, actorUri).url || actorUri; // human profile page → the link href
    961963    const esc = h.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
    962964    out = out.replace(new RegExp('(^|[\\s>])@' + esc + '(?![A-Za-z0-9_.-])', 'g'),
    963       (full, pre) => `${pre}<a href="${actorUri}" class="u-url mention">@${h}</a>`);
     965      (full, pre) => `${pre}<a href="${profileUrl}" class="u-url mention" data-actor="${actorUri}">@${h}</a>`);
    964966  }
    965967  return { html: out, inboxes };
     
    10051007  const mres = await resolveMentionsInText(base, body); // link inline @mentions + collect their inboxes
    10061008  const mention = parent.actor_uri
    1007     ? `<a href="${escHtml(parent.actor_uri || parent.actor_url)}" class="u-url mention">${escHtml(dispHandle)}</a> ` : '';
     1009    ? `<a href="${escHtml(parent.actor_url || parent.actor_uri)}" class="u-url mention" data-actor="${escHtml(parent.actor_uri)}">${escHtml(dispHandle)}</a> ` : '';
    10081010  const content = `<p>${mention}${linkHashtags(base, mres.html)}</p>`;
    10091011  // Dedup: skip if the exact same reply was already sent (double-submit guard).
     
    11581160  if (!base) return false;
    11591161  const me = actorId(base, site.slug);
     1162  const toActor = row.to_actor ? await fetchActor(row.to_actor).catch(() => null) : null;
     1163  const toProfile = row.to_actor ? (actorInfo(toActor, row.to_actor).url || row.to_actor) : '';
     1164  const _h = row.to_handle || deriveHandle(row.to_actor);
     1165  const toHandle = _h && _h[0] === '@' ? _h : '@' + (_h || '');
    11601166  const mention = row.to_actor
    1161     ? `<a href="${escHtml(row.to_actor)}" class="u-url mention">${escHtml(row.to_handle || deriveHandle(row.to_actor))}</a> ` : '';
     1167    ? `<a href="${escHtml(toProfile)}" class="u-url mention" data-actor="${escHtml(row.to_actor)}">${escHtml(toHandle)}</a> ` : '';
    11621168  const mres = await resolveMentionsInText(base, escHtml(text).replace(/\r?\n/g, '<br>'));
    11631169  const content = `<p>${mention}${linkHashtags(base, mres.html)}</p>`;
     
    11721178  const keys = getOrCreateKeys(site.slug);
    11731179  const inboxes = new Set();
    1174   if (row.to_actor) { const a = await fetchActor(row.to_actor).catch(() => null); if (a) inboxes.add((a.endpoints && a.endpoints.sharedInbox) || a.inbox); }
     1180  if (toActor) inboxes.add((toActor.endpoints && toActor.endpoints.sharedInbox) || toActor.inbox);
    11751181  for (const f of fStmts().list.all(site.slug)) inboxes.add(f.shared_inbox || f.inbox);
     1182  mres.inboxes.forEach((i) => inboxes.add(i)); // people @mentioned inline in the edit
    11761183  inboxes.delete(`${me}/inbox`); inboxes.delete(`${base}/ap/inbox`);
    11771184  let delivered = 0;
Note: See TracChangeset for help on using the changeset viewer.