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:06 +01:00
parent 8b9bff4d2e
commit d143abf392

View File

@@ -250,9 +250,12 @@ export function jf2ToAS2Activity(properties, actorUrl, publicationUrl, options =
if (postType === "like") {
const likeOf = properties["like-of"];
if (!likeOf) return null;
const followersUrl = `${actorUrl.replace(/\/$/, "")}/followers`;
return new Like({
actor: actorUri,
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") {
const repostOf = properties["repost-of"];
if (!repostOf) return null;
const followersUrl = `${actorUrl.replace(/\/$/, "")}/followers`;
return new Announce({
actor: actorUri,
object: new URL(repostOf),
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)) {
tags.push({
type: "Hashtag",
name: `#${cat.replace(/\s+/g, "")}`,
name: `#${cat.split("/").at(-1).replace(/\s+/g, "")}`,
href: `${publicationUrl}categories/${encodeURIComponent(cat)}`,
});
}
@@ -576,7 +581,7 @@ function buildFedifyTags(properties, publicationUrl, postType) {
for (const cat of asArray(properties.category)) {
tags.push(
new Hashtag({
name: `#${cat.replace(/\s+/g, "")}`,
name: `#${cat.split("/").at(-1).replace(/\s+/g, "")}`,
href: new URL(
`${publicationUrl}categories/${encodeURIComponent(cat)}`,
),