feat: store outbound DMs in ap_notifications for threading; redirect to ?tab=mention

This commit is contained in:
svemagie
2026-03-13 07:26:25 +01:00
parent 8d2dc3a05a
commit ba144da14c
+28 -1
View File
@@ -5,6 +5,7 @@
import { Create, Note, Mention } from "@fedify/fedify/vocab"; import { Create, Note, Mention } from "@fedify/fedify/vocab";
import { getToken, validateToken } from "../csrf.js"; import { getToken, validateToken } from "../csrf.js";
import { sanitizeContent } from "../timeline-store.js"; import { sanitizeContent } from "../timeline-store.js";
import { addNotification } from "../storage/notifications.js";
function createPublicationAwareDocumentLoader(documentLoader, publicationUrl) { function createPublicationAwareDocumentLoader(documentLoader, publicationUrl) {
if (typeof documentLoader !== "function") { if (typeof documentLoader !== "function") {
@@ -286,7 +287,33 @@ export function submitComposeController(mountPath, plugin) {
}); });
console.info(`[ActivityPub] Sent direct AP reply to ${senderActorUrl}`); console.info(`[ActivityPub] Sent direct AP reply to ${senderActorUrl}`);
return response.redirect(`${mountPath}/admin/reader/notifications`); // Store outbound DM so it appears in the thread view
try {
const ap_notifications = application?.collections?.get("ap_notifications");
if (ap_notifications) {
const hostname = new URL(plugin._publicationUrl).hostname;
await addNotification({ ap_notifications }, {
uid: noteId.href,
url: noteId.href,
type: "mention",
isDirect: true,
direction: "outbound",
senderActorUrl,
actorUrl: actorUri.href,
actorName: plugin.options?.actor?.name || handle,
actorPhoto: plugin.options?.actor?.icon || "",
actorHandle: `@${handle}@${hostname}`,
inReplyTo: inReplyTo || null,
content: { text: content.trim(), html: content.trim() },
published: new Date().toISOString(),
createdAt: new Date().toISOString(),
});
}
} catch (storeError) {
console.warn("[ActivityPub] Failed to store outbound DM:", storeError.message);
}
return response.redirect(`${mountPath}/admin/reader/notifications?tab=mention`);
} catch (error) { } catch (error) {
console.error("[ActivityPub] Native AP DM reply failed:", error.message); console.error("[ActivityPub] Native AP DM reply failed:", error.message);
return response.status(500).render("error", { return response.status(500).render("error", {