mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-03-18 10:30:49 +01:00
feat: ability to show only local posts in /world
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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)",
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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([]);
|
||||
|
||||
Reference in New Issue
Block a user