Node.js based forum software built for the modern web
feat: beginnings of the /world route
Julian Lam04423232c670
diff --git a/public/language/en-GB/admin/settings/activitypub.json b/public/language/en-GB/admin/settings/activitypub.jsonindex 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 <a href=\"https://activitypub.rocks/\">ActivityPub</a>. 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 <a href=\"https://activitypub.rocks/\">ActivityPub</a>. 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 filediff --git a/src/controllers/activitypub/topics.js b/src/controllers/activitypub/topics.jsindex 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.jsindex 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.jsindex 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.tplindex 8002a4c5d5..ce339d0572 100644--- a/src/views/admin/settings/activitypub.tpl+++ b/src/views/admin/settings/activitypub.tpl@@ -1,18 +1,18 @@<div class="acp-page-container"><!-- IMPORT admin/partials/settings/header.tpl -->- <p class="lead">[[admin/settings/activitypub:intro-lead]]</p>- <p>[[admin/settings/activitypub:intro-body]]</p>+ <p class="lead">[[admin/settings/activitypub:acp.intro-lead]]</p>+ <p>[[admin/settings/activitypub:acp.intro-body]]</p><hr /><div class="row settings m-0">- <div class="col-sm-2 col-12 settings-header">[[admin/settings/activitypub:general]]</div>+ <div class="col-sm-2 col-12 settings-header">[[admin/settings/activitypub:acp.general]]</div><div class="col-sm-10 col-12"><form><div class="form-check form-switch mb-3"><input class="form-check-input" type="checkbox" data-field="activitypubEnabled">- <label class="form-check-label">[[admin/settings/activitypub:enabled]]</label>+ <label class="form-check-label">[[admin/settings/activitypub:acp.enabled]]</label></div></form></div>