Changeset 7e66e7e in Klonkt


Ignore:
Timestamp:
06/27/2026 12:04:44 AM (2 months ago)
Author:
Robin Genis <roboburr@…>
Branches:
main
Children:
ace5a9b
Parents:
0a75356
Message:

feat(fedi): hide the leading @mention in displayed comments

A federated reply carries a leading @user@domain mention (the person replied to).
Strip it for display (Mastodon does the same) so a comment reads 'dope tekening ouwe'
not '@jason@… dope …'. Applied to inbound + outbound reply nodes, the
My-replies list, and the notifications preview. stripLeadingMentions keeps the <p>
wrapper and handles both <a>mention</a> links and plain-text mentions.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/services/ActivityPubService.js

    r0a75356 r7e66e7e  
    414414}
    415415
     416// Drop the leading @mention(s) a federated reply carries (the person being replied to),
     417// so a comment reads "dope tekening ouwe" instead of "@jason@jasonhacky.nl dope …".
     418// Keeps a leading <p> wrapper; handles mention <a> links and plain-text @user@domain.
     419export function stripLeadingMentions(html) {
     420  if (!html) return html;
     421  let s = String(html);
     422  s = s.replace(/^(\s*<p[^>]*>)?\s*(?:<a\b[^>]*>\s*@[^<]+<\/a>[  ]*)+/i, (m, p) => p || '');
     423  s = s.replace(/^(\s*<p[^>]*>)?\s*(?:@[\w.-]+(?:@[\w.-]+)?[  ]+)+/i, (m, p) => p || '');
     424  return s;
     425}
     426
    416427// View-ready threaded view of a post's fediverse activity (inbound replies +
    417428// our outbound replies, nested), plus like/boost counts.
     
    434445      noteId: r.object_uri, parent: r.parent_uri || null, mine: false, id: r.id,
    435446      actor_name: r.actor_name, actor_handle: r.actor_handle, actor_url: r.actor_url,
    436       actor_icon: r.actor_icon, content: r.content, created_at: r.published || r.created_at,
     447      actor_icon: r.actor_icon, content: stripLeadingMentions(r.content), created_at: r.published || r.created_at,
    437448      acted_boost: !!r.acted_boost, acted_like: !!r.acted_like,
    438449      children: [],
     
    442453    nodes.push({
    443454      noteId: baseClean ? `${baseClean}/ap/notes/${o.id}` : o.id, parent: o.in_reply_to || null,
    444       mine: true, outboxId: o.id, content: o.content, created_at: o.created_at,
     455      mine: true, outboxId: o.id, content: stripLeadingMentions(o.content), created_at: o.created_at,
    445456      actor_name: siteName, actor_handle: siteHandle, actor_url: siteUrl, actor_icon: siteIcon,
    446457      children: [],
     
    9981009// List a site's own outbound fediverse replies (for the manage/delete view).
    9991010export function listOutbox(siteSlug) {
    1000   return db.prepare('SELECT id, content, to_handle, in_reply_to, created_at FROM ap_outbox WHERE site_slug = ? ORDER BY created_at DESC').all(siteSlug);
     1011  return db.prepare('SELECT id, content, to_handle, in_reply_to, created_at FROM ap_outbox WHERE site_slug = ? ORDER BY created_at DESC')
     1012    .all(siteSlug).map((r) => ({ ...r, content: stripLeadingMentions(r.content) }));
    10011013}
    10021014
     
    12911303    for (const r of rows) out.push({
    12921304      type: r.kind, name: r.actor_name, handle: r.actor_handle, url: r.actor_url,
    1293       content: r.content, post_slug: r.post_slug, post_title: r.post_title, created_at: r.created_at,
     1305      content: stripLeadingMentions(r.content), post_slug: r.post_slug, post_title: r.post_title, created_at: r.created_at,
    12941306    });
    12951307  } catch { /* ignore */ }
Note: See TracChangeset for help on using the changeset viewer.