fix: add to/cc addressing to Like and Announce activities

Mastodon shared inboxes require cc:followers to route activities to
local followers. Like had no to/cc at all, Announce was missing cc.
Also normalize nested tags (on/art/music → music) in hashtag names.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
svemagie
2026-03-19 00:16:18 +01:00
co-authored by Claude Opus 4.6
parent 8b9bff4d2e
commit d143abf392
+7 -2
View File
@@ -250,9 +250,12 @@ export function jf2ToAS2Activity(properties, actorUrl, publicationUrl, options =
if (postType === "like") { if (postType === "like") {
const likeOf = properties["like-of"]; const likeOf = properties["like-of"];
if (!likeOf) return null; if (!likeOf) return null;
const followersUrl = `${actorUrl.replace(/\/$/, "")}/followers`;
return new Like({ return new Like({
actor: actorUri, actor: actorUri,
object: new URL(likeOf), object: new URL(likeOf),
to: new URL("https://www.w3.org/ns/activitystreams#Public"),
cc: new URL(followersUrl),
}); });
} }
@@ -260,10 +263,12 @@ export function jf2ToAS2Activity(properties, actorUrl, publicationUrl, options =
if (postType === "repost") { if (postType === "repost") {
const repostOf = properties["repost-of"]; const repostOf = properties["repost-of"];
if (!repostOf) return null; if (!repostOf) return null;
const followersUrl = `${actorUrl.replace(/\/$/, "")}/followers`;
return new Announce({ return new Announce({
actor: actorUri, actor: actorUri,
object: new URL(repostOf), object: new URL(repostOf),
to: new URL("https://www.w3.org/ns/activitystreams#Public"), to: new URL("https://www.w3.org/ns/activitystreams#Public"),
cc: new URL(followersUrl),
}); });
} }
@@ -554,7 +559,7 @@ function buildPlainTags(properties, publicationUrl, existing) {
for (const cat of asArray(properties.category)) { for (const cat of asArray(properties.category)) {
tags.push({ tags.push({
type: "Hashtag", type: "Hashtag",
name: `#${cat.replace(/\s+/g, "")}`, name: `#${cat.split("/").at(-1).replace(/\s+/g, "")}`,
href: `${publicationUrl}categories/${encodeURIComponent(cat)}`, href: `${publicationUrl}categories/${encodeURIComponent(cat)}`,
}); });
} }
@@ -576,7 +581,7 @@ function buildFedifyTags(properties, publicationUrl, postType) {
for (const cat of asArray(properties.category)) { for (const cat of asArray(properties.category)) {
tags.push( tags.push(
new Hashtag({ new Hashtag({
name: `#${cat.replace(/\s+/g, "")}`, name: `#${cat.split("/").at(-1).replace(/\s+/g, "")}`,
href: new URL( href: new URL(
`${publicationUrl}categories/${encodeURIComponent(cat)}`, `${publicationUrl}categories/${encodeURIComponent(cat)}`,
), ),