Node.js based forum software built for the modern web
feat: ability to show only local posts in /world
Julian Lam44e65b8d73f0
diff --git a/install/package.json b/install/package.jsonindex 6631108574..17da5d468c 100644--- a/install/package.json+++ b/install/package.json@@ -108,10 +108,10 @@"nodebb-plugin-spam-be-gone": "2.3.2","nodebb-plugin-web-push": "0.7.7","nodebb-rewards-essentials": "1.0.2",- "nodebb-theme-harmony": "2.2.55",+ "nodebb-theme-harmony": "2.2.56","nodebb-theme-lavender": "7.1.21","nodebb-theme-peace": "2.2.57",- "nodebb-theme-persona": "14.2.29",+ "nodebb-theme-persona": "14.2.30","nodebb-widget-essentials": "7.0.43","nodemailer": "8.0.2","nprogress": "0.2.0",diff --git a/public/language/en-GB/world.json b/public/language/en-GB/world.jsonindex 58e6526fbb..af21f98948 100644--- a/public/language/en-GB/world.json+++ b/public/language/en-GB/world.json@@ -1,6 +1,7 @@{"name": "World",- "latest": "Latest (Following)",+ "latest": "Latest",+ "latest-local": "Latest (Local)","latest-all": "Latest (All)","popular-day": "Popular (Day)","popular-week": "Popular (Week)",diff --git a/public/src/client/world.js b/public/src/client/world.jsindex 6e63b85a23..61492a5d9f 100644--- a/public/src/client/world.js+++ b/public/src/client/world.js@@ -45,7 +45,13 @@ define('forum/world', [}default: {- translator.translate(`[[world:latest${params.get('all') === '1' ? '-all' : ''}]]`, function (translated) {+ let suffix = '';+ if (params.get('all') === '1') {+ suffix = '-all';+ } else if (params.get('local') === '1') {+ suffix = '-local';+ }+ translator.translate(`[[world:latest${suffix}]]`, function (translated) {sortLabelEl.innerText = translated;});break;diff --git a/src/controllers/activitypub/topics.js b/src/controllers/activitypub/topics.jsindex 8785fecc14..d45b187761 100644--- a/src/controllers/activitypub/topics.js+++ b/src/controllers/activitypub/topics.js@@ -16,8 +16,8 @@ const helpers = require('../helpers');const controller = module.exports;controller.list = async function (req, res) {- if (!req.uid && !req.query.sort && !req.query.all) {- return helpers.redirect(res, '/world?all=1', false);+ if (!req.uid && !req.query.sort && !req.query.local) {+ return helpers.redirect(res, '/world?local=1', false);}const { topicsPerPage } = await user.getSettings(req.uid);@@ -50,12 +50,14 @@ controller.list = async function (req, res) {let tids;let topicCount;+ let { local } = req.query;+ local = parseInt(local, 10) === 1;if (req.query.sort === 'popular') {cidQuery = {...cidQuery,sort: 'posts',term: req.query.term || 'day',- includeRemote: true,+ includeRemote: !local,followingOnly: !req.query.all || !parseInt(req.query.all, 10),};delete cidQuery.cid;@@ -65,7 +67,7 @@ controller.list = async function (req, res) {cidQuery = {...cidQuery,term: req.query.term,- includeRemote: true,+ includeRemote: !local,followingOnly: !req.query.all || !parseInt(req.query.all, 10),};delete cidQuery.cid;@@ -110,29 +112,33 @@ controller.list = async function (req, res) {data.showSelect = true;// Tracked/watched categories- let cids = await user.getCategoriesByStates(req.uid, [- categories.watchStates.tracking, categories.watchStates.watching,- ]);- cids = cids.filter(cid => !utils.isNumber(cid));- const [categoryData, watchState] = await Promise.all([- categories.getCategories(cids),- categories.getWatchState(cids, req.uid),- ]);- data.categories = categories.getTree(categoryData, 0);- await Promise.all([- categories.getRecentTopicReplies(categoryData, req.uid, req.query),- categories.setUnread(data.categories, cids, req.uid),- ]);- data.categories.forEach((category, idx) => {- if (category) {- helpers.trimChildren(category);- helpers.setCategoryTeaser(category);- category.isWatched = watchState[idx] === categories.watchStates.watching;- category.isTracked = watchState[idx] === categories.watchStates.tracking;- category.isNotWatched = watchState[idx] === categories.watchStates.notwatching;- category.isIgnored = watchState[idx] === categories.watchStates.ignoring;- }- });+ if (req.uid) {+ let cids = await user.getCategoriesByStates(req.uid, [+ categories.watchStates.tracking, categories.watchStates.watching,+ ]);+ cids = cids.filter(cid => !utils.isNumber(cid));+ const [categoryData, watchState] = await Promise.all([+ categories.getCategories(cids),+ categories.getWatchState(cids, req.uid),+ ]);+ data.categories = categories.getTree(categoryData, 0);+ await Promise.all([+ categories.getRecentTopicReplies(categoryData, req.uid, req.query),+ categories.setUnread(data.categories, cids, req.uid),+ ]);+ data.categories.forEach((category, idx) => {+ if (category) {+ helpers.trimChildren(category);+ helpers.setCategoryTeaser(category);+ category.isWatched = watchState[idx] === categories.watchStates.watching;+ category.isTracked = watchState[idx] === categories.watchStates.tracking;+ category.isNotWatched = watchState[idx] === categories.watchStates.notwatching;+ category.isIgnored = watchState[idx] === categories.watchStates.ignoring;+ }+ });+ } else {+ data.categories = [];+ }data.title = translator.escape(data.name);data.breadcrumbs = helpers.buildBreadcrumbs([]);