Files
indiekit-endpoint-activitypub/lib/controllers/activities.js
Ricardo 25513c7ea5 feat: add breadcrumb navigation across all ActivityPub UI pages
Document.njk pages (followers, following, activities, featured, tags,
profile, migrate) get parent breadcrumbs via the upstream heading
component. Reader pages (explore, notifications, compose, moderation,
tag timeline, post detail, remote profile, my profile) get a new
breadcrumb nav bar in ap-reader.njk layout.
2026-02-27 12:10:31 +01:00

59 lines
1.7 KiB
JavaScript

/**
* Activity log controller — paginated list of inbound/outbound activities.
*/
const PAGE_SIZE = 20;
export function activitiesController(mountPath) {
return async (request, response, next) => {
try {
const { application } = request.app.locals;
const collection = application?.collections?.get("ap_activities");
if (!collection) {
return response.render("activitypub-activities", {
title: response.locals.__("activitypub.activities"),
parent: { href: mountPath, text: response.locals.__("activitypub.title") },
activities: [],
mountPath,
});
}
const page = Math.max(1, Number.parseInt(request.query.page, 10) || 1);
const totalCount = await collection.countDocuments();
const totalPages = Math.ceil(totalCount / PAGE_SIZE);
const activities = await collection
.find()
.sort({ receivedAt: -1 })
.skip((page - 1) * PAGE_SIZE)
.limit(PAGE_SIZE)
.toArray();
const cursor = buildCursor(page, totalPages, mountPath + "/admin/activities");
response.render("activitypub-activities", {
title: response.locals.__("activitypub.activities"),
parent: { href: mountPath, text: response.locals.__("activitypub.title") },
activities,
mountPath,
cursor,
});
} catch (error) {
next(error);
}
};
}
function buildCursor(page, totalPages, basePath) {
if (totalPages <= 1) return null;
return {
previous: page > 1
? { href: `${basePath}?page=${page - 1}` }
: undefined,
next: page < totalPages
? { href: `${basePath}?page=${page + 1}` }
: undefined,
};
}