From 04423232c67020abd813b1748a4423957d16d50e Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Wed, 17 Jan 2024 23:14:12 -0500 Subject: [PATCH] feat: beginnings of the /world route --- .../en-GB/admin/settings/activitypub.json | 9 +++++---- src/controllers/activitypub/topics.js | 18 ++++++++++++++++++ src/routes/activitypub.js | 10 +++++++--- src/topics/recent.js | 4 +++- src/views/admin/settings/activitypub.tpl | 8 ++++---- 5 files changed, 37 insertions(+), 12 deletions(-) diff --git a/public/language/en-GB/admin/settings/activitypub.json b/public/language/en-GB/admin/settings/activitypub.json index 989eeaf6f3..2874d82c8e 100644 --- a/public/language/en-GB/admin/settings/activitypub.json +++ b/public/language/en-GB/admin/settings/activitypub.json @@ -1,7 +1,8 @@ { - "intro-lead": "What is Federation?", - "intro-body": "NodeBB is able to communicate with other NodeBB instances that support it. This is achieved through a protocol called ActivityPub. If enabled, NodeBB will also be able to communicate with other apps and websites that use ActivityPub (e.g. Mastodon, Peertube, etc.)", + "no-topics": "This forum doesn't know of any other topics yet.", - "general": "General", - "enabled": "Enable Federation" + "acp.intro-lead": "What is Federation?", + "acp.intro-body": "NodeBB is able to communicate with other NodeBB instances that support it. This is achieved through a protocol called ActivityPub. If enabled, NodeBB will also be able to communicate with other apps and websites that use ActivityPub (e.g. Mastodon, Peertube, etc.)", + "acp.general": "General", + "acp.enabled": "Enable Federation" } \ No newline at end of file diff --git a/src/controllers/activitypub/topics.js b/src/controllers/activitypub/topics.js index aae87065e2..36a7659baa 100644 --- a/src/controllers/activitypub/topics.js +++ b/src/controllers/activitypub/topics.js @@ -14,7 +14,25 @@ const helpers = require('../helpers'); const controller = module.exports; +controller.list = async function (req, res, next) { + const { topicsPerPage } = await user.getSettings(req.uid); + const page = parseInt(req.query.page, 10) || 1; + const start = Math.max(0, (page - 1) * topicsPerPage); + const stop = start + topicsPerPage - 1; + + const tids = await db.getSortedSetRevRange('cid:-1:tids', start, stop); + const topicData = await topics.getTopicsByTids(tids, { uid: req.uid }); + topics.calculateTopicIndices(topicData, start); + res.render('world', { + topics: topicData, + }); +}; + controller.get = async function (req, res, next) { + /** + * Ideally we would use the existing topicsController.get... + * this controller may be a stopgap towards that end goal. + */ const pid = await notes.resolveId(req.uid, req.query.resource); if (pid !== req.query.resource) { return helpers.redirect(res, `/topic/remote?resource=${pid}`, true); diff --git a/src/routes/activitypub.js b/src/routes/activitypub.js index 1c0e0a672d..cb0aab8268 100644 --- a/src/routes/activitypub.js +++ b/src/routes/activitypub.js @@ -1,10 +1,14 @@ 'use strict'; -/** - * These controllers only respond if the sender is making an json+activitypub style call (i.e. S2S-only) - */ +const helpers = require('./helpers'); module.exports = function (app, middleware, controllers) { + helpers.setupPageRoute(app, '/world/:view?', controllers.activitypub.topics.list); + + /** + * These controllers only respond if the sender is making an json+activitypub style call (i.e. S2S-only) + */ + const middlewares = [middleware.proceedOnActivityPub, middleware.exposeUid]; app.get('/user/:userslug', middlewares, controllers.activitypub.getActor); diff --git a/src/topics/recent.js b/src/topics/recent.js index 06c0482c81..67c02d1975 100644 --- a/src/topics/recent.js +++ b/src/topics/recent.js @@ -4,6 +4,7 @@ const db = require('../database'); const plugins = require('../plugins'); const posts = require('../posts'); +const activitypub = require('../activitypub'); module.exports = function (Topics) { const terms = { @@ -73,7 +74,8 @@ module.exports = function (Topics) { data = await plugins.hooks.fire('filter:topics.updateRecent', { tid: tid, timestamp: timestamp }); } if (data && data.tid && data.timestamp) { - await db.sortedSetAdd('topics:recent', data.timestamp, data.tid); + const setPrefix = activitypub.helpers.isUri(data.tid) ? 'topicsRemote' : 'topics'; + await db.sortedSetAdd(`${setPrefix}:recent`, data.timestamp, data.tid); } }; }; diff --git a/src/views/admin/settings/activitypub.tpl b/src/views/admin/settings/activitypub.tpl index 8002a4c5d5..ce339d0572 100644 --- a/src/views/admin/settings/activitypub.tpl +++ b/src/views/admin/settings/activitypub.tpl @@ -1,18 +1,18 @@
-

[[admin/settings/activitypub:intro-lead]]

-

[[admin/settings/activitypub:intro-body]]

+

[[admin/settings/activitypub:acp.intro-lead]]

+

[[admin/settings/activitypub:acp.intro-body]]


-
[[admin/settings/activitypub:general]]
+
[[admin/settings/activitypub:acp.general]]
- +