Files
indiekit-endpoint-activitypub/lib/activity-log.js
Ricardo e40ffbf61d feat: add outbound follow/unfollow, activity logging, and Microsub timeline integration
- Add followActor() and unfollowActor() methods for sending Follow/Undo(Follow) activities
- Add shared activity-log.js utility for logging to ap_activities collection
- Log all outbound activities (syndication, follow, unfollow) with success/failure details
- Update inbox Create listener to store timeline items from followed accounts
- Add Microsub collection accessors for cross-plugin timeline integration
- Refactor inbox-listeners to use shared activity logging utility
2026-02-19 18:11:28 +01:00

32 lines
1.1 KiB
JavaScript

/**
* Shared activity logging utility.
*
* Logs inbound and outbound ActivityPub activities to the ap_activities
* collection so they appear in the Activity Log admin UI.
*/
/**
* Log an activity to the ap_activities collection.
*
* @param {object} collection - The ap_activities MongoDB collection
* @param {object} record - Activity record
* @param {string} record.direction - "inbound" or "outbound"
* @param {string} record.type - Activity type (e.g. "Create", "Follow", "Undo(Follow)")
* @param {string} [record.actorUrl] - Actor URL
* @param {string} [record.actorName] - Actor display name
* @param {string} [record.objectUrl] - Object URL
* @param {string} [record.targetUrl] - Target URL (e.g. reply target)
* @param {string} [record.content] - Content excerpt
* @param {string} record.summary - Human-readable summary
*/
export async function logActivity(collection, record) {
try {
await collection.insertOne({
...record,
receivedAt: new Date().toISOString(),
});
} catch (error) {
console.warn("[ActivityPub] Failed to log activity:", error.message);
}
}