mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-05-07 12:55:44 +02: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-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",
|
||||||
|
|||||||
@@ -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)",
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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,29 +112,33 @@ controller.list = async function (req, res) {
|
|||||||
data.showSelect = true;
|
data.showSelect = true;
|
||||||
|
|
||||||
// Tracked/watched categories
|
// Tracked/watched categories
|
||||||
let cids = await user.getCategoriesByStates(req.uid, [
|
if (req.uid) {
|
||||||
categories.watchStates.tracking, categories.watchStates.watching,
|
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([
|
cids = cids.filter(cid => !utils.isNumber(cid));
|
||||||
categories.getCategories(cids),
|
const [categoryData, watchState] = await Promise.all([
|
||||||
categories.getWatchState(cids, req.uid),
|
categories.getCategories(cids),
|
||||||
]);
|
categories.getWatchState(cids, req.uid),
|
||||||
data.categories = categories.getTree(categoryData, 0);
|
]);
|
||||||
await Promise.all([
|
data.categories = categories.getTree(categoryData, 0);
|
||||||
categories.getRecentTopicReplies(categoryData, req.uid, req.query),
|
await Promise.all([
|
||||||
categories.setUnread(data.categories, cids, req.uid),
|
categories.getRecentTopicReplies(categoryData, req.uid, req.query),
|
||||||
]);
|
categories.setUnread(data.categories, cids, req.uid),
|
||||||
data.categories.forEach((category, idx) => {
|
]);
|
||||||
if (category) {
|
data.categories.forEach((category, idx) => {
|
||||||
helpers.trimChildren(category);
|
if (category) {
|
||||||
helpers.setCategoryTeaser(category);
|
helpers.trimChildren(category);
|
||||||
category.isWatched = watchState[idx] === categories.watchStates.watching;
|
helpers.setCategoryTeaser(category);
|
||||||
category.isTracked = watchState[idx] === categories.watchStates.tracking;
|
category.isWatched = watchState[idx] === categories.watchStates.watching;
|
||||||
category.isNotWatched = watchState[idx] === categories.watchStates.notwatching;
|
category.isTracked = watchState[idx] === categories.watchStates.tracking;
|
||||||
category.isIgnored = watchState[idx] === categories.watchStates.ignoring;
|
category.isNotWatched = watchState[idx] === categories.watchStates.notwatching;
|
||||||
}
|
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([]);
|
||||||
|
|||||||
Reference in New Issue
Block a user