Changeset 7cea873 in Klonkt


Ignore:
Timestamp:
06/27/2026 11:56:24 AM (2 months ago)
Author:
Robin Genis <roboburr@…>
Branches:
main
Children:
bddbfe0
Parents:
6bc2ca7e
Message:

fix(fedi): link inline #hashtags in post bodies too (federate as Hashtag tags)

  • services/ActivityPubService.js — buildNote now links inline #hashtags in the post body (linkHashtags) and merges them with the post's tags field into one deduped Hashtag tag list (buildHashtagList), each with an href to our /tag page. Mirrors the reply fix; tags-field hashtags now carry hrefs too.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/services/ActivityPubService.js

    r6bc2ca7e r7cea873  
    228228  // shift+enter uses <br> and has no \n → this is a no-op there).
    229229  body = body.replace(/\r?\n/g, '<br>');
     230  body = linkHashtags(base, body); // link inline #hashtags in the post body too
    230231  const seen = new Set();
    231232  const attachment = urls.filter(Boolean)
     
    244245    to: post.fan_only ? [`${aId}/followers`] : [PUBLIC],
    245246    cc: post.fan_only ? [] : [`${aId}/followers`],
    246     tag: Array.isArray(post.tags) ? post.tags.map((t) => ({ type: 'Hashtag', name: '#' + String(t).replace(/\s+/g, '') })) : [],
     247    tag: buildHashtagList(base, post.tags, body),
    247248    replies: `${id}/replies`,
    248249    // NSFW → Mastodon-style content warning: sensitive (blurs media) + a summary/spoiler
     
    914915}
    915916
     917// Merge a post's tags field + the #hashtags linked inline in its body into one deduped
     918// Hashtag tag list (with hrefs to our /tag page).
     919function buildHashtagList(base, tagsField, content) {
     920  const out = [], seen = new Set();
     921  for (const t of (Array.isArray(tagsField) ? tagsField : [])) {
     922    const name = String(t).replace(/\s+/g, ''); if (!name) continue;
     923    const k = name.toLowerCase(); if (seen.has(k)) continue; seen.add(k);
     924    out.push({ type: 'Hashtag', href: `${base}/tag/${encodeURIComponent(k)}`, name: '#' + name });
     925  }
     926  for (const h of hashtagTags(base, content)) {
     927    const k = h.name.slice(1).toLowerCase(); if (seen.has(k)) continue; seen.add(k);
     928    out.push(h);
     929  }
     930  return out;
     931}
     932
    916933export function buildReplyNote(base, site, row) {
    917934  const me = actorId(base, site.slug);
Note: See TracChangeset for help on using the changeset viewer.