fix: filter Like and Announce to only log reactions to our content

After following remote actors, their servers deliver all activities
to our inbox — including likes/boosts of other people's posts. Only
log Likes and Announces where the objectUrl starts with our
publication URL, filtering out unrelated activity.
This commit is contained in:
Ricardo
2026-02-20 09:28:08 +01:00
parent 432bb7a64a
commit baac0a60bc
2 changed files with 13 additions and 3 deletions
+12 -2
View File
@@ -161,13 +161,18 @@ export function registerInboxListeners(inboxChain, options) {
} }
}) })
.on(Like, async (ctx, like) => { .on(Like, async (ctx, like) => {
const objectId = (await like.getObject())?.id?.href || "";
// Only log likes of our own content
const pubUrl = collections._publicationUrl;
if (!objectId || (pubUrl && !objectId.startsWith(pubUrl))) return;
const actorObj = await like.getActor(); const actorObj = await like.getActor();
const actorUrl = actorObj?.id?.href || ""; const actorUrl = actorObj?.id?.href || "";
const actorName = const actorName =
actorObj?.name?.toString() || actorObj?.name?.toString() ||
actorObj?.preferredUsername?.toString() || actorObj?.preferredUsername?.toString() ||
actorUrl; actorUrl;
const objectId = (await like.getObject())?.id?.href || "";
await logActivity(collections, storeRawActivities, { await logActivity(collections, storeRawActivities, {
direction: "inbound", direction: "inbound",
@@ -179,13 +184,18 @@ export function registerInboxListeners(inboxChain, options) {
}); });
}) })
.on(Announce, async (ctx, announce) => { .on(Announce, async (ctx, announce) => {
const objectId = (await announce.getObject())?.id?.href || "";
// Only log boosts of our own content
const pubUrl = collections._publicationUrl;
if (!objectId || (pubUrl && !objectId.startsWith(pubUrl))) return;
const actorObj = await announce.getActor(); const actorObj = await announce.getActor();
const actorUrl = actorObj?.id?.href || ""; const actorUrl = actorObj?.id?.href || "";
const actorName = const actorName =
actorObj?.name?.toString() || actorObj?.name?.toString() ||
actorObj?.preferredUsername?.toString() || actorObj?.preferredUsername?.toString() ||
actorUrl; actorUrl;
const objectId = (await announce.getObject())?.id?.href || "";
await logActivity(collections, storeRawActivities, { await logActivity(collections, storeRawActivities, {
direction: "inbound", direction: "inbound",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@rmdes/indiekit-endpoint-activitypub", "name": "@rmdes/indiekit-endpoint-activitypub",
"version": "1.0.13", "version": "1.0.14",
"description": "ActivityPub federation endpoint for Indiekit via Fedify. Adds full fediverse support: actor, inbox, outbox, followers, following, syndication, and Mastodon migration.", "description": "ActivityPub federation endpoint for Indiekit via Fedify. Adds full fediverse support: actor, inbox, outbox, followers, following, syndication, and Mastodon migration.",
"keywords": [ "keywords": [
"indiekit", "indiekit",