feat: ability to show only local posts in /world

This commit is contained in:
Julian Lam
2026-03-16 13:34:04 -04:00
parent 6c01a5d84f
commit 44e65b8d73
4 changed files with 44 additions and 31 deletions

View File

@@ -108,10 +108,10 @@
"nodebb-plugin-spam-be-gone": "2.3.2", "nodebb-plugin-spam-be-gone": "2.3.2",
"nodebb-plugin-web-push": "0.7.7", "nodebb-plugin-web-push": "0.7.7",
"nodebb-rewards-essentials": "1.0.2", "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-lavender": "7.1.21",
"nodebb-theme-peace": "2.2.57", "nodebb-theme-peace": "2.2.57",
"nodebb-theme-persona": "14.2.29", "nodebb-theme-persona": "14.2.30",
"nodebb-widget-essentials": "7.0.43", "nodebb-widget-essentials": "7.0.43",
"nodemailer": "8.0.2", "nodemailer": "8.0.2",
"nprogress": "0.2.0", "nprogress": "0.2.0",

View File

@@ -1,6 +1,7 @@
{ {
"name": "World", "name": "World",
"latest": "Latest (Following)", "latest": "Latest",
"latest-local": "Latest (Local)",
"latest-all": "Latest (All)", "latest-all": "Latest (All)",
"popular-day": "Popular (Day)", "popular-day": "Popular (Day)",
"popular-week": "Popular (Week)", "popular-week": "Popular (Week)",

View File

@@ -45,7 +45,13 @@ define('forum/world', [
} }
default: { 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; sortLabelEl.innerText = translated;
}); });
break; break;

View File

@@ -16,8 +16,8 @@ const helpers = require('../helpers');
const controller = module.exports; const controller = module.exports;
controller.list = async function (req, res) { controller.list = async function (req, res) {
if (!req.uid && !req.query.sort && !req.query.all) { if (!req.uid && !req.query.sort && !req.query.local) {
return helpers.redirect(res, '/world?all=1', false); return helpers.redirect(res, '/world?local=1', false);
} }
const { topicsPerPage } = await user.getSettings(req.uid); const { topicsPerPage } = await user.getSettings(req.uid);
@@ -50,12 +50,14 @@ controller.list = async function (req, res) {
let tids; let tids;
let topicCount; let topicCount;
let { local } = req.query;
local = parseInt(local, 10) === 1;
if (req.query.sort === 'popular') { if (req.query.sort === 'popular') {
cidQuery = { cidQuery = {
...cidQuery, ...cidQuery,
sort: 'posts', sort: 'posts',
term: req.query.term || 'day', term: req.query.term || 'day',
includeRemote: true, includeRemote: !local,
followingOnly: !req.query.all || !parseInt(req.query.all, 10), followingOnly: !req.query.all || !parseInt(req.query.all, 10),
}; };
delete cidQuery.cid; delete cidQuery.cid;
@@ -65,7 +67,7 @@ controller.list = async function (req, res) {
cidQuery = { cidQuery = {
...cidQuery, ...cidQuery,
term: req.query.term, term: req.query.term,
includeRemote: true, includeRemote: !local,
followingOnly: !req.query.all || !parseInt(req.query.all, 10), followingOnly: !req.query.all || !parseInt(req.query.all, 10),
}; };
delete cidQuery.cid; delete cidQuery.cid;
@@ -110,6 +112,7 @@ controller.list = async function (req, res) {
data.showSelect = true; data.showSelect = true;
// Tracked/watched categories // Tracked/watched categories
if (req.uid) {
let cids = await user.getCategoriesByStates(req.uid, [ let cids = await user.getCategoriesByStates(req.uid, [
categories.watchStates.tracking, categories.watchStates.watching, categories.watchStates.tracking, categories.watchStates.watching,
]); ]);
@@ -133,6 +136,9 @@ controller.list = async function (req, res) {
category.isIgnored = watchState[idx] === categories.watchStates.ignoring; category.isIgnored = watchState[idx] === categories.watchStates.ignoring;
} }
}); });
} else {
data.categories = [];
}
data.title = translator.escape(data.name); data.title = translator.escape(data.name);
data.breadcrumbs = helpers.buildBreadcrumbs([]); data.breadcrumbs = helpers.buildBreadcrumbs([]);