mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-16 21:40:23 +01:00
Compare commits
18 Commits
normalize-
...
v1.16.2-be
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a60ea2ec7a | ||
|
|
4066d994ff | ||
|
|
de9bec2bb1 | ||
|
|
3aecd20096 | ||
|
|
54804d4789 | ||
|
|
55cefcba35 | ||
|
|
3da8b93578 | ||
|
|
b265e6f68b | ||
|
|
a6a02fb773 | ||
|
|
49583fe48b | ||
|
|
14e211fb68 | ||
|
|
7b98fab95c | ||
|
|
a373731570 | ||
|
|
a76b5d15e0 | ||
|
|
a06b84d258 | ||
|
|
ecf212d307 | ||
|
|
dc6fc65322 | ||
|
|
27b481765b |
@@ -2,7 +2,7 @@
|
||||
"name": "nodebb",
|
||||
"license": "GPL-3.0",
|
||||
"description": "NodeBB Forum",
|
||||
"version": "1.16.2-beta.0",
|
||||
"version": "1.16.2-beta.2",
|
||||
"homepage": "http://www.nodebb.org",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -190,4 +190,4 @@
|
||||
"url": "https://github.com/barisusakli"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,9 +109,9 @@ define('admin/manage/categories', [
|
||||
name: '[[admin/manage/categories:parent-category-none]]',
|
||||
icon: 'fa-none',
|
||||
});
|
||||
Benchpress.render('admin/partials/categories/create', {
|
||||
app.parseAndTranslate('admin/partials/categories/create', {
|
||||
categories: categories,
|
||||
}).then(function (html) {
|
||||
}, function (html) {
|
||||
var modal = bootbox.dialog({
|
||||
title: '[[admin/manage/categories:alert.create]]',
|
||||
message: html,
|
||||
|
||||
@@ -119,9 +119,9 @@ define('admin/manage/category', [
|
||||
return app.alertError(err.message);
|
||||
}
|
||||
|
||||
Benchpress.render('admin/partials/categories/copy-settings', {
|
||||
app.parseAndTranslate('admin/partials/categories/copy-settings', {
|
||||
categories: allCategories,
|
||||
}).then(function (html) {
|
||||
}, function (html) {
|
||||
var selectedCid;
|
||||
var modal = bootbox.dialog({
|
||||
title: '[[modules:composer.select_category]]',
|
||||
|
||||
@@ -2,7 +2,19 @@
|
||||
|
||||
(function (factory) {
|
||||
function loadClient(language, namespace) {
|
||||
return Promise.resolve(jQuery.getJSON([config.assetBaseUrl, 'language', language, namespace].join('/') + '.json?' + config['cache-buster']));
|
||||
return new Promise(function (resolve, reject) {
|
||||
jQuery.getJSON([config.assetBaseUrl, 'language', language, namespace].join('/') + '.json?' + config['cache-buster'], function (data) {
|
||||
const payload = {
|
||||
language: language,
|
||||
namespace: namespace,
|
||||
data: data,
|
||||
};
|
||||
$(window).trigger('action:translator.loadClient', payload);
|
||||
resolve(payload.promise ? Promise.resolve(payload.promise) : data);
|
||||
}).fail(function (jqxhr, textStatus, error) {
|
||||
reject(new Error(textStatus + ', ' + error));
|
||||
});
|
||||
});
|
||||
}
|
||||
var warn = function () { console.warn.apply(console, arguments); };
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
@@ -545,6 +557,18 @@
|
||||
});
|
||||
},
|
||||
|
||||
flushNamespace: function (namespace) {
|
||||
Object.keys(Translator.cache).forEach(function (code) {
|
||||
if (Translator.cache[code] &&
|
||||
Translator.cache[code].translations &&
|
||||
Translator.cache[code].translations[namespace]
|
||||
) {
|
||||
Translator.cache[code].translations[namespace] = null;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Legacy translator function for backwards compatibility
|
||||
*/
|
||||
|
||||
@@ -150,6 +150,11 @@ module.exports = function (Categories) {
|
||||
if (copyParent) {
|
||||
destination.parentCid = source.parentCid || 0;
|
||||
}
|
||||
await plugins.hooks.fire('filter:categories.copySettingsFrom', {
|
||||
source: source,
|
||||
destination: destination,
|
||||
copyParent: copyParent,
|
||||
});
|
||||
|
||||
await db.setObject('category:' + toCid, destination);
|
||||
|
||||
|
||||
@@ -57,9 +57,11 @@ Categories.getCategoryById = async function (data) {
|
||||
category.isIgnored = watchState[0] === Categories.watchStates.ignoring;
|
||||
category.parent = parent;
|
||||
|
||||
|
||||
calculateTopicPostCount(category);
|
||||
const result = await plugins.hooks.fire('filter:category.get', { category: category, uid: data.uid });
|
||||
const result = await plugins.hooks.fire('filter:category.get', {
|
||||
category: category,
|
||||
...data,
|
||||
});
|
||||
return result.category;
|
||||
};
|
||||
|
||||
|
||||
@@ -51,11 +51,12 @@ notificationsController.get = async function (req, res, next) {
|
||||
if (!selectedFilter) {
|
||||
return next();
|
||||
}
|
||||
let nids = await user.notifications.getAll(req.uid, selectedFilter.filter);
|
||||
const pageCount = Math.max(1, Math.ceil(nids.length / itemsPerPage));
|
||||
nids = nids.slice(start, stop + 1);
|
||||
|
||||
const notifications = await user.notifications.getNotifications(nids, req.uid);
|
||||
const nids = await user.notifications.getAll(req.uid, selectedFilter.filter);
|
||||
let notifications = await user.notifications.getNotifications(nids, req.uid);
|
||||
|
||||
const pageCount = Math.max(1, Math.ceil(notifications.length / itemsPerPage));
|
||||
notifications = notifications.slice(start, stop + 1);
|
||||
|
||||
res.render('notifications', {
|
||||
notifications: notifications,
|
||||
|
||||
@@ -8,6 +8,8 @@ const categories = require('../../categories');
|
||||
const pagination = require('../../pagination');
|
||||
const helpers = require('../helpers');
|
||||
const accountHelpers = require('./helpers');
|
||||
const plugins = require('../../plugins');
|
||||
const utils = require('../../utils');
|
||||
|
||||
const postsController = module.exports;
|
||||
|
||||
@@ -107,38 +109,38 @@ const templateToData = {
|
||||
};
|
||||
|
||||
postsController.getBookmarks = async function (req, res, next) {
|
||||
await getFromUserSet('account/bookmarks', req, res, next);
|
||||
await getPostsFromUserSet('account/bookmarks', req, res, next);
|
||||
};
|
||||
|
||||
postsController.getPosts = async function (req, res, next) {
|
||||
await getFromUserSet('account/posts', req, res, next);
|
||||
await getPostsFromUserSet('account/posts', req, res, next);
|
||||
};
|
||||
|
||||
postsController.getUpVotedPosts = async function (req, res, next) {
|
||||
await getFromUserSet('account/upvoted', req, res, next);
|
||||
await getPostsFromUserSet('account/upvoted', req, res, next);
|
||||
};
|
||||
|
||||
postsController.getDownVotedPosts = async function (req, res, next) {
|
||||
await getFromUserSet('account/downvoted', req, res, next);
|
||||
await getPostsFromUserSet('account/downvoted', req, res, next);
|
||||
};
|
||||
|
||||
postsController.getBestPosts = async function (req, res, next) {
|
||||
await getFromUserSet('account/best', req, res, next);
|
||||
await getPostsFromUserSet('account/best', req, res, next);
|
||||
};
|
||||
|
||||
postsController.getWatchedTopics = async function (req, res, next) {
|
||||
await getFromUserSet('account/watched', req, res, next);
|
||||
await getPostsFromUserSet('account/watched', req, res, next);
|
||||
};
|
||||
|
||||
postsController.getIgnoredTopics = async function (req, res, next) {
|
||||
await getFromUserSet('account/ignored', req, res, next);
|
||||
await getPostsFromUserSet('account/ignored', req, res, next);
|
||||
};
|
||||
|
||||
postsController.getTopics = async function (req, res, next) {
|
||||
await getFromUserSet('account/topics', req, res, next);
|
||||
await getPostsFromUserSet('account/topics', req, res, next);
|
||||
};
|
||||
|
||||
async function getFromUserSet(template, req, res, callback) {
|
||||
async function getPostsFromUserSet(template, req, res, callback) {
|
||||
const data = templateToData[template];
|
||||
const page = Math.max(1, parseInt(req.query.page, 10) || 1);
|
||||
|
||||
@@ -154,12 +156,26 @@ async function getFromUserSet(template, req, res, callback) {
|
||||
const start = (page - 1) * itemsPerPage;
|
||||
const stop = start + itemsPerPage - 1;
|
||||
const sets = await data.getSets(req.uid, userData);
|
||||
|
||||
const [itemCount, itemData] = await Promise.all([
|
||||
settings.usePagination ? db.sortedSetsCardSum(sets) : 0,
|
||||
getItemData(sets, data, req, start, stop),
|
||||
]);
|
||||
|
||||
let result;
|
||||
if (plugins.hooks.hasListeners('filter:account.getPostsFromUserSet')) {
|
||||
result = await plugins.hooks.fire('filter:account.getPostsFromUserSet', {
|
||||
req: req,
|
||||
template: template,
|
||||
userData: userData,
|
||||
settings: settings,
|
||||
data: data,
|
||||
start: start,
|
||||
stop: stop,
|
||||
itemCount: 0,
|
||||
itemData: [],
|
||||
});
|
||||
} else {
|
||||
result = await utils.promiseParallel({
|
||||
itemCount: settings.usePagination ? db.sortedSetsCardSum(sets) : 0,
|
||||
itemData: getItemData(sets, data, req, start, stop),
|
||||
});
|
||||
}
|
||||
const { itemCount, itemData } = result;
|
||||
userData[data.type] = itemData[data.type];
|
||||
userData.nextStart = itemData.nextStart;
|
||||
|
||||
|
||||
@@ -49,8 +49,8 @@ categoryController.get = async function (req, res, next) {
|
||||
return helpers.notAllowed(req, res);
|
||||
}
|
||||
|
||||
if (!res.locals.isAPI && (!req.params.slug || categoryFields.slug !== cid + '/' + req.params.slug) && (categoryFields.slug && categoryFields.slug !== cid + '/')) {
|
||||
return helpers.redirect(res, '/category/' + categoryFields.slug, true);
|
||||
if (!res.locals.isAPI && !req.params.slug && (categoryFields.slug && categoryFields.slug !== `${cid}/`)) {
|
||||
return helpers.redirect(res, `/category/${categoryFields.slug}`, true);
|
||||
}
|
||||
|
||||
if (categoryFields.link) {
|
||||
|
||||
@@ -118,7 +118,7 @@ function calculateStartStop(page, postIndex, settings) {
|
||||
let startSkip = 0;
|
||||
|
||||
if (!settings.usePagination) {
|
||||
if (postIndex !== 0) {
|
||||
if (postIndex > 1) {
|
||||
page = 1;
|
||||
}
|
||||
startSkip = Math.max(0, postIndex - Math.ceil(settings.postsPerPage / 2));
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const utils = require('./utils');
|
||||
const paths = require('./constants').paths;
|
||||
const { paths } = require('./constants');
|
||||
const plugins = require('./plugins');
|
||||
|
||||
const Languages = module.exports;
|
||||
const languagesPath = path.join(__dirname, '../build/public/language');
|
||||
@@ -12,8 +13,14 @@ const files = fs.readdirSync(path.join(paths.nodeModules, '/timeago/locales'));
|
||||
Languages.timeagoCodes = files.filter(f => f.startsWith('jquery.timeago')).map(f => f.split('.')[2]);
|
||||
|
||||
Languages.get = async function (language, namespace) {
|
||||
const data = await fs.promises.readFile(path.join(languagesPath, language, namespace + '.json'), 'utf8');
|
||||
return JSON.parse(data) || {};
|
||||
const data = await fs.promises.readFile(path.join(languagesPath, language, `${namespace}.json`), 'utf8');
|
||||
const parsed = JSON.parse(data) || {};
|
||||
const result = await plugins.hooks.fire('filter:languages.get', {
|
||||
language,
|
||||
namespace,
|
||||
data: parsed,
|
||||
});
|
||||
return result.data;
|
||||
};
|
||||
|
||||
let codeCache = null;
|
||||
|
||||
@@ -7,6 +7,7 @@ const _ = require('lodash');
|
||||
const meta = require('../meta');
|
||||
const languages = require('../languages');
|
||||
const helpers = require('./helpers');
|
||||
const plugins = require('../plugins');
|
||||
|
||||
module.exports = function (middleware) {
|
||||
middleware.addHeaders = helpers.try(function addHeaders(req, res, next) {
|
||||
@@ -75,10 +76,13 @@ module.exports = function (middleware) {
|
||||
next();
|
||||
});
|
||||
|
||||
middleware.autoLocale = helpers.try(async function autoLocale(req, res, next) {
|
||||
let langs;
|
||||
middleware.autoLocale = helpers.try(async (req, res, next) => {
|
||||
await plugins.hooks.fire('filter:middleware.autoLocale', {
|
||||
req: req,
|
||||
res: res,
|
||||
});
|
||||
if (req.query.lang) {
|
||||
langs = await listCodes();
|
||||
const langs = await listCodes();
|
||||
if (!langs.includes(req.query.lang)) {
|
||||
req.query.lang = meta.config.defaultLang;
|
||||
}
|
||||
@@ -87,7 +91,7 @@ module.exports = function (middleware) {
|
||||
if (parseInt(req.uid, 10) > 0 || !meta.config.autoDetectLang) {
|
||||
return next();
|
||||
}
|
||||
langs = await listCodes();
|
||||
const langs = await listCodes();
|
||||
const lang = req.acceptsLanguages(langs);
|
||||
if (!lang) {
|
||||
return next();
|
||||
|
||||
@@ -33,10 +33,16 @@ module.exports = function (middleware) {
|
||||
options.url = (req.baseUrl + req.path.replace(/^\/api/, ''));
|
||||
options.bodyClass = buildBodyClass(req, res, options);
|
||||
|
||||
const buildResult = await plugins.hooks.fire('filter:' + template + '.build', { req: req, res: res, templateData: options });
|
||||
const buildResult = await plugins.hooks.fire(`filter:${template}.build`, { req: req, res: res, templateData: options });
|
||||
if (res.headersSent) {
|
||||
return;
|
||||
}
|
||||
const templateToRender = buildResult.templateData.templateToRender || template;
|
||||
|
||||
const renderResult = await plugins.hooks.fire('filter:middleware.render', { req: req, res: res, templateData: buildResult.templateData });
|
||||
if (res.headersSent) {
|
||||
return;
|
||||
}
|
||||
options = renderResult.templateData;
|
||||
options._header = {
|
||||
tags: await meta.tags.parse(req, renderResult, res.locals.metaTags, res.locals.linkTags),
|
||||
|
||||
@@ -185,9 +185,8 @@ module.exports = function (middleware) {
|
||||
if (!userslug) {
|
||||
return next();
|
||||
}
|
||||
const path = req.path.replace(/^\/api/, '')
|
||||
.replace('uid', 'user')
|
||||
.replace(uid, function () { return userslug; });
|
||||
const path = req.url.replace(/^\/api/, '')
|
||||
.replace(`/uid/${uid}`, () => `/user/${userslug}`);
|
||||
controllers.helpers.redirect(res, path);
|
||||
});
|
||||
|
||||
|
||||
@@ -48,6 +48,10 @@ module.exports = function (Topics) {
|
||||
tids = await db.getSortedSetRevRange('uid:' + params.uid + ':followed_tids', 0, -1);
|
||||
} else if (params.cids) {
|
||||
tids = await getCidTids(params);
|
||||
} else if (params.tags.length) {
|
||||
tids = await getTagTids(params);
|
||||
} else if (params.sort === 'old') {
|
||||
tids = await db.getSortedSetRange(`topics:recent`, 0, meta.config.recentMaxTopics - 1);
|
||||
} else {
|
||||
tids = await db.getSortedSetRevRange('topics:' + params.sort, 0, meta.config.recentMaxTopics - 1);
|
||||
}
|
||||
@@ -55,12 +59,30 @@ module.exports = function (Topics) {
|
||||
return tids;
|
||||
}
|
||||
|
||||
async function getTagTids(params) {
|
||||
const sets = [
|
||||
params.sort === 'old' ?
|
||||
'topics:recent' :
|
||||
`topics:${params.sort}`,
|
||||
...params.tags.map(tag => `tag:${tag}:topics`),
|
||||
];
|
||||
const method = params.sort === 'old' ?
|
||||
'getSortedSetIntersect' :
|
||||
'getSortedSetRevIntersect';
|
||||
return await db[method]({
|
||||
sets: sets,
|
||||
start: 0,
|
||||
stop: meta.config.recentMaxTopics - 1,
|
||||
weights: sets.map((s, index) => (index ? 0 : 1)),
|
||||
});
|
||||
}
|
||||
|
||||
async function getCidTids(params) {
|
||||
const sets = [];
|
||||
const pinnedSets = [];
|
||||
params.cids.forEach(function (cid) {
|
||||
if (params.sort === 'recent') {
|
||||
sets.push('cid:' + cid + ':tids');
|
||||
params.cids.forEach((cid) => {
|
||||
if (params.sort === 'recent' || params.sort === 'old') {
|
||||
sets.push(`cid:${cid}:tids`);
|
||||
} else {
|
||||
sets.push('cid:' + cid + ':tids' + (params.sort ? ':' + params.sort : ''));
|
||||
}
|
||||
@@ -68,7 +90,10 @@ module.exports = function (Topics) {
|
||||
});
|
||||
let pinnedTids = await db.getSortedSetRevRange(pinnedSets, 0, -1);
|
||||
pinnedTids = await Topics.tools.checkPinExpiry(pinnedTids);
|
||||
const tids = await db.getSortedSetRevRange(sets, 0, meta.config.recentMaxTopics - 1);
|
||||
const method = params.sort === 'old' ?
|
||||
'getSortedSetRange' :
|
||||
'getSortedSetRevRange';
|
||||
const tids = await db[method](sets, 0, meta.config.recentMaxTopics - 1);
|
||||
return pinnedTids.concat(tids);
|
||||
}
|
||||
|
||||
@@ -77,12 +102,13 @@ module.exports = function (Topics) {
|
||||
return tids;
|
||||
}
|
||||
const topicData = await Topics.getTopicsFields(tids, ['tid', 'lastposttime', 'upvotes', 'downvotes', 'postcount', 'pinned']);
|
||||
let sortFn = sortRecent;
|
||||
if (params.sort === 'posts') {
|
||||
sortFn = sortPopular;
|
||||
} else if (params.sort === 'votes') {
|
||||
sortFn = sortVotes;
|
||||
}
|
||||
const sortMap = {
|
||||
recent: sortRecent,
|
||||
old: sortOld,
|
||||
posts: sortPopular,
|
||||
votes: sortVotes,
|
||||
};
|
||||
const sortFn = sortMap[params.sort] || sortRecent;
|
||||
|
||||
if (params.floatPinned) {
|
||||
floatPinned(topicData, sortFn);
|
||||
@@ -106,6 +132,10 @@ module.exports = function (Topics) {
|
||||
return b.lastposttime - a.lastposttime;
|
||||
}
|
||||
|
||||
function sortOld(a, b) {
|
||||
return a.lastposttime - b.lastposttime;
|
||||
}
|
||||
|
||||
function sortVotes(a, b) {
|
||||
if (a.votes !== b.votes) {
|
||||
return b.votes - a.votes;
|
||||
|
||||
@@ -1050,8 +1050,18 @@ describe('Controllers', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('should 404 if user does not exist', function (done) {
|
||||
request(nconf.get('url') + '/api/uid/123123', { json: true }, function (err, res) {
|
||||
it('should redirect to userslug and keep query params', (done) => {
|
||||
request(`${nconf.get('url')}/api/uid/${fooUid}/topics?foo=bar`, { json: true }, (err, res, body) => {
|
||||
assert.ifError(err);
|
||||
assert.equal(res.statusCode, 200);
|
||||
assert.equal(res.headers['x-redirect'], '/user/foo/topics?foo=bar');
|
||||
assert.equal(body, '/user/foo/topics?foo=bar');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should 404 if user does not exist', (done) => {
|
||||
request(`${nconf.get('url')}/api/uid/123123`, { json: true }, (err, res) => {
|
||||
assert.ifError(err);
|
||||
assert.equal(res.statusCode, 404);
|
||||
done();
|
||||
|
||||
@@ -2518,12 +2518,21 @@ describe('Topic\'s', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('sorted topics', function () {
|
||||
it('should get sorted topics in category', function (done) {
|
||||
var filters = ['', 'watched', 'unreplied', 'new'];
|
||||
async.map(filters, function (filter, next) {
|
||||
describe('sorted topics', () => {
|
||||
let category;
|
||||
before(async () => {
|
||||
category = await categories.create({ name: 'sorted' });
|
||||
const topic1Result = await topics.post({ uid: topic.userId, cid: category.cid, title: 'old replied', content: 'topic 1 OP' });
|
||||
const topic2Result = await topics.post({ uid: topic.userId, cid: category.cid, title: 'most recent replied', content: 'topic 2 OP' });
|
||||
await topics.reply({ uid: topic.userId, content: 'topic 1 reply', tid: topic1Result.topicData.tid });
|
||||
await topics.reply({ uid: topic.userId, content: 'topic 2 reply', tid: topic2Result.topicData.tid });
|
||||
});
|
||||
|
||||
it('should get sorted topics in category', (done) => {
|
||||
const filters = ['', 'watched', 'unreplied', 'new'];
|
||||
async.map(filters, (filter, next) => {
|
||||
topics.getSortedTopics({
|
||||
cids: [topic.categoryId],
|
||||
cids: [category.cid],
|
||||
uid: topic.userId,
|
||||
start: 0,
|
||||
stop: -1,
|
||||
@@ -2539,5 +2548,28 @@ describe('Topic\'s', function () {
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('should get topics recent replied first', async () => {
|
||||
const data = await topics.getSortedTopics({
|
||||
cids: [category.cid],
|
||||
uid: topic.userId,
|
||||
start: 0,
|
||||
stop: -1,
|
||||
sort: 'recent',
|
||||
});
|
||||
assert.strictEqual(data.topics[0].title, 'most recent replied');
|
||||
assert.strictEqual(data.topics[1].title, 'old replied');
|
||||
});
|
||||
|
||||
it('should get topics recent replied last', async () => {
|
||||
const data = await topics.getSortedTopics({
|
||||
cids: [category.cid],
|
||||
uid: topic.userId,
|
||||
start: 0,
|
||||
stop: -1,
|
||||
sort: 'old',
|
||||
});
|
||||
assert.strictEqual(data.topics[0].title, 'old replied');
|
||||
assert.strictEqual(data.topics[1].title, 'most recent replied');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user