diff --git a/src/activitypub/handler.ts b/src/activitypub/handler.ts index 04ef3b3931e79415b39000371403ffbc14c5d9a5..e9d1ffaa91b27383fdfb59214fa84ed8e28b76b7 100644 --- a/src/activitypub/handler.ts +++ b/src/activitypub/handler.ts @@ -2,6 +2,8 @@ import { Conf } from '@/config.ts'; import { Stickynotes } from '@/deps.ts'; import { activitiesCounter } from '@/metrics.ts'; +import { generateId } from '../utils/id.ts'; + import { cipher, followsDB } from '../db.ts'; import { fetchAndPublishActor, fetchAndPublishObject, publish, publishFollows } from '../nostr/publisher.ts'; import { toEvent0, toEvent1, toEvent10002, toEvent5, toEvent6, toEvent7 } from '../nostr/transmute.ts'; @@ -58,7 +60,10 @@ function handleFollow(activity: Follow) { } async function handleCreateNote({ object }: CreateNote) { - if (!isObjectPublic(object)) return; + if (!isObjectPublic(object)) { + handleMaybeDM(object); + return; + } if (object.quoteUrl) { await fetchAndPublishObject(object.quoteUrl); @@ -76,6 +81,48 @@ async function handleCreateNote({ object }: CreateNote) { } } +function handleMaybeDM(object: Note) { + federate( + autoReply( + 'The Nostr bridge does not support direct messages. The recipient will not see your message. This is an automated reply.', + object, + ), + ); +} + +function autoReply(message: string, object: Note): Activity { + return { + type: 'Create', + id: generateId('activities'), + actor: object.to[0], + object: { + type: 'Note', + id: generateId('objects'), + attributedTo: object.to[0], + to: [ + object.attributedTo, + ], + cc: [], + inReplyTo: object.id, + content: message, + tag: [ + { + type: 'Mention', + href: object.attributedTo, + }, + ], + sensitive: false, + summary: undefined, + published: new Date().toISOString(), + }, + to: [ + object.attributedTo, + ], + cc: [], + published: new Date().toISOString(), + }; +} + async function handleAnnounce(activity: Announce) { if (!isObjectPublic(activity)) return;