Skip to content

Node.js based forum software built for the modern web

feat: followers and following endpoints

Julian Lam7e1dac39eaaa
diff --git a/src/controllers/activitypub.js b/src/controllers/activitypub.js
index 921e59cf2c..9e4527c7ac 100644
--- a/src/controllers/activitypub.js
+++ b/src/controllers/activitypub.js
@@ -40,6 +40,42 @@ Controller.getActor = async (req, res) => {
});
};
+Controller.getFollowing = async (req, res) => {
+ const { followingCount: totalItems } = await user.getUserFields(res.locals.uid, ['followingCount']);
+
+ const page = parseInt(req.query.page, 10) || 1;
+ const resultsPerPage = 50;
+ const start = Math.max(0, page - 1) * resultsPerPage;
+ const stop = start + resultsPerPage - 1;
+
+ let orderedItems = await user.getFollowing(res.locals.uid, start, stop);
+ orderedItems = orderedItems.map(({ userslug }) => `${nconf.get('url')}/user/${userslug}`);
+ res.status(200).json({
+ '@context': 'https://www.w3.org/ns/activitystreams',
+ type: 'OrderedCollection',
+ totalItems,
+ orderedItems,
+ });
+};
+
+Controller.getFollowers = async (req, res) => {
+ const { followerCount: totalItems } = await user.getUserFields(res.locals.uid, ['followerCount']);
+
+ const page = parseInt(req.query.page, 10) || 1;
+ const resultsPerPage = 50;
+ const start = Math.max(0, page - 1) * resultsPerPage;
+ const stop = start + resultsPerPage - 1;
+
+ let orderedItems = await user.getFollowers(res.locals.uid, start, stop);
+ orderedItems = orderedItems.map(({ userslug }) => `${nconf.get('url')}/user/${userslug}`);
+ res.status(200).json({
+ '@context': 'https://www.w3.org/ns/activitystreams',
+ type: 'OrderedCollection',
+ totalItems,
+ orderedItems,
+ });
+};
+
Controller.getOutbox = async (req, res) => {
// stub
res.status(200).json({
diff --git a/src/routes/activitypub.js b/src/routes/activitypub.js
index f96484a7b2..02fe9a2bf0 100644
--- a/src/routes/activitypub.js
+++ b/src/routes/activitypub.js
@@ -5,6 +5,9 @@ module.exports = function (app, middleware, controllers) {
app.get('/user/:userslug', middlewares, controllers.activitypub.getActor);
+ app.get('/user/:userslug/following', middlewares, controllers.activitypub.getFollowing);
+ app.get('/user/:userslug/followers', middlewares, controllers.activitypub.getFollowers);
+
app.get('/user/:userslug/outbox', middlewares, controllers.activitypub.getOutbox);
app.post('/user/:userslug/outbox', middlewares, controllers.activitypub.postOutbox);