mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-16 21:40:23 +01:00
Compare commits
24 Commits
normalize-
...
v1.16.2-be
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a68fc1dc50 | ||
|
|
536b66dc89 | ||
|
|
75d60bfaf2 | ||
|
|
9f6ad7637e | ||
|
|
fdf7e65331 | ||
|
|
1cc32705fe | ||
|
|
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]]',
|
||||
|
||||
@@ -9,7 +9,7 @@ define('forum/account/best', ['forum/account/header', 'forum/account/posts'], fu
|
||||
|
||||
$('[component="post/content"] img:not(.not-responsive)').addClass('img-responsive');
|
||||
|
||||
posts.handleInfiniteScroll('posts.loadMoreBestPosts', 'account/best');
|
||||
posts.handleInfiniteScroll('account/best');
|
||||
};
|
||||
|
||||
return Best;
|
||||
|
||||
@@ -9,7 +9,7 @@ define('forum/account/bookmarks', ['forum/account/header', 'forum/account/posts'
|
||||
|
||||
$('[component="post/content"] img:not(.not-responsive)').addClass('img-responsive');
|
||||
|
||||
posts.handleInfiniteScroll('posts.loadMoreBookmarks', 'account/bookmarks');
|
||||
posts.handleInfiniteScroll('account/bookmarks');
|
||||
};
|
||||
|
||||
return Bookmarks;
|
||||
|
||||
@@ -9,7 +9,7 @@ define('forum/account/downvoted', ['forum/account/header', 'forum/account/posts'
|
||||
|
||||
$('[component="post/content"] img:not(.not-responsive)').addClass('img-responsive');
|
||||
|
||||
posts.handleInfiniteScroll('posts.loadMoreDownVotedPosts', 'account/downvoted');
|
||||
posts.handleInfiniteScroll('account/downvoted');
|
||||
};
|
||||
|
||||
return Downvoted;
|
||||
|
||||
13
public/src/client/account/ignored.js
Normal file
13
public/src/client/account/ignored.js
Normal file
@@ -0,0 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
define('forum/account/ignored', ['forum/account/header', 'forum/account/topics'], function (header, topics) {
|
||||
var AccountIgnored = {};
|
||||
|
||||
AccountIgnored.init = function () {
|
||||
header.init();
|
||||
|
||||
topics.handleInfiniteScroll('account/ignored');
|
||||
};
|
||||
|
||||
return AccountIgnored;
|
||||
});
|
||||
@@ -3,20 +3,21 @@
|
||||
|
||||
define('forum/account/posts', ['forum/account/header', 'forum/infinitescroll'], function (header, infinitescroll) {
|
||||
var AccountPosts = {};
|
||||
var method;
|
||||
|
||||
var template;
|
||||
var page = 1;
|
||||
|
||||
AccountPosts.init = function () {
|
||||
header.init();
|
||||
|
||||
$('[component="post/content"] img:not(.not-responsive)').addClass('img-responsive');
|
||||
|
||||
AccountPosts.handleInfiniteScroll('posts.loadMoreUserPosts', 'account/posts');
|
||||
AccountPosts.handleInfiniteScroll('account/posts');
|
||||
};
|
||||
|
||||
AccountPosts.handleInfiniteScroll = function (_method, _template) {
|
||||
method = _method;
|
||||
AccountPosts.handleInfiniteScroll = function (_template) {
|
||||
template = _template;
|
||||
page = ajaxify.data.pagination.currentPage;
|
||||
if (!config.usePagination) {
|
||||
infinitescroll.init(loadMore);
|
||||
}
|
||||
@@ -26,17 +27,16 @@ define('forum/account/posts', ['forum/account/header', 'forum/infinitescroll'],
|
||||
if (direction < 0) {
|
||||
return;
|
||||
}
|
||||
var params = utils.params();
|
||||
page += 1;
|
||||
params.page = page;
|
||||
|
||||
infinitescroll.loadMore(method, {
|
||||
uid: ajaxify.data.theirid,
|
||||
after: $('[component="posts"]').attr('data-nextstart'),
|
||||
}, function (data, done) {
|
||||
infinitescroll.loadMoreXhr(params, function (data, done) {
|
||||
if (data.posts && data.posts.length) {
|
||||
onPostsLoaded(data.posts, done);
|
||||
} else {
|
||||
done();
|
||||
}
|
||||
$('[component="posts"]').attr('data-nextstart', data.nextStart);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -3,21 +3,19 @@
|
||||
|
||||
define('forum/account/topics', ['forum/account/header', 'forum/infinitescroll'], function (header, infinitescroll) {
|
||||
var AccountTopics = {};
|
||||
var method;
|
||||
|
||||
var template;
|
||||
var set;
|
||||
var page = 1;
|
||||
|
||||
AccountTopics.init = function () {
|
||||
header.init();
|
||||
|
||||
AccountTopics.handleInfiniteScroll('topics.loadMoreUserTopics', 'account/topics');
|
||||
AccountTopics.handleInfiniteScroll('account/topics');
|
||||
};
|
||||
|
||||
AccountTopics.handleInfiniteScroll = function (_method, _template, _set) {
|
||||
method = _method;
|
||||
AccountTopics.handleInfiniteScroll = function (_template) {
|
||||
template = _template;
|
||||
set = _set;
|
||||
|
||||
page = ajaxify.data.pagination.currentPage;
|
||||
if (!config.usePagination) {
|
||||
infinitescroll.init(loadMore);
|
||||
}
|
||||
@@ -27,20 +25,16 @@ define('forum/account/topics', ['forum/account/header', 'forum/infinitescroll'],
|
||||
if (direction < 0) {
|
||||
return;
|
||||
}
|
||||
var params = utils.params();
|
||||
page += 1;
|
||||
params.page = page;
|
||||
|
||||
infinitescroll.loadMore(method, {
|
||||
set: set,
|
||||
uid: ajaxify.data.theirid,
|
||||
after: $('[component="category"]').attr('data-nextstart'),
|
||||
count: config.topicsPerPage,
|
||||
}, function (data, done) {
|
||||
infinitescroll.loadMoreXhr(params, function (data, done) {
|
||||
if (data.topics && data.topics.length) {
|
||||
onTopicsLoaded(data.topics, done);
|
||||
} else {
|
||||
done();
|
||||
}
|
||||
|
||||
$('[component="category"]').attr('data-nextstart', data.nextStart);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ define('forum/account/upvoted', ['forum/account/header', 'forum/account/posts'],
|
||||
|
||||
$('[component="post/content"] img:not(.not-responsive)').addClass('img-responsive');
|
||||
|
||||
posts.handleInfiniteScroll('posts.loadMoreUpVotedPosts', 'account/upvoted');
|
||||
posts.handleInfiniteScroll('account/upvoted');
|
||||
};
|
||||
|
||||
return Upvoted;
|
||||
|
||||
@@ -7,7 +7,7 @@ define('forum/account/watched', ['forum/account/header', 'forum/account/topics']
|
||||
AccountWatched.init = function () {
|
||||
header.init();
|
||||
|
||||
topics.handleInfiniteScroll('topics.loadMoreFromSet', 'account/watched', 'uid:' + ajaxify.data.theirid + ':followed_tids');
|
||||
topics.handleInfiniteScroll('account/watched');
|
||||
};
|
||||
|
||||
return AccountWatched;
|
||||
|
||||
@@ -78,6 +78,25 @@ define('forum/infinitescroll', function () {
|
||||
});
|
||||
};
|
||||
|
||||
scroll.loadMoreXhr = function (data, callback) {
|
||||
if (loadingMore) {
|
||||
return;
|
||||
}
|
||||
loadingMore = true;
|
||||
var url = config.relative_path + '/api' + location.pathname.replace(new RegExp('^' + config.relative_path), '');
|
||||
var hookData = { url: url, data: data };
|
||||
$(window).trigger('action:infinitescroll.loadmore.xhr', hookData);
|
||||
|
||||
$.get(url, data, function (data) {
|
||||
callback(data, function () {
|
||||
loadingMore = false;
|
||||
});
|
||||
}).fail(function (jqXHR) {
|
||||
loadingMore = false;
|
||||
app.alertError(String(jqXHR.responseJSON || jqXHR.statusText));
|
||||
});
|
||||
};
|
||||
|
||||
scroll.removeExtra = function (els, direction, count) {
|
||||
if (els.length <= count) {
|
||||
return;
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ blocksController.getBlocks = async function (req, res, next) {
|
||||
const start = Math.max(0, page - 1) * resultsPerPage;
|
||||
const stop = start + resultsPerPage - 1;
|
||||
|
||||
const userData = await accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid);
|
||||
const userData = await accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid, req.query);
|
||||
if (!userData) {
|
||||
return next();
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ const helpers = require('../helpers');
|
||||
const categoriesController = module.exports;
|
||||
|
||||
categoriesController.get = async function (req, res, next) {
|
||||
const userData = await accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid);
|
||||
const userData = await accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid, req.query);
|
||||
if (!userData) {
|
||||
return next();
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ consentController.get = async function (req, res, next) {
|
||||
return next();
|
||||
}
|
||||
|
||||
const userData = await accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid);
|
||||
const userData = await accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid, req.query);
|
||||
if (!userData) {
|
||||
return next();
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ const editController = module.exports;
|
||||
|
||||
editController.get = async function (req, res, next) {
|
||||
const [userData, canUseSignature] = await Promise.all([
|
||||
accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid),
|
||||
accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid, req.query),
|
||||
privileges.global.can('signature', req.uid),
|
||||
]);
|
||||
if (!userData) {
|
||||
@@ -114,7 +114,7 @@ async function renderRoute(name, req, res, next) {
|
||||
}
|
||||
|
||||
async function getUserData(req) {
|
||||
const userData = await accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid);
|
||||
const userData = await accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid, req.query);
|
||||
if (!userData) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ followController.getFollowers = async function (req, res, next) {
|
||||
};
|
||||
|
||||
async function getFollow(tpl, name, req, res, next) {
|
||||
const userData = await accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid);
|
||||
const userData = await accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid, req.query);
|
||||
if (!userData) {
|
||||
return next();
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ const accountHelpers = require('./helpers');
|
||||
const groupsController = module.exports;
|
||||
|
||||
groupsController.get = async function (req, res, next) {
|
||||
const userData = await accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid);
|
||||
const userData = await accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid, req.query);
|
||||
if (!userData) {
|
||||
return next();
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ const categories = require('../../categories');
|
||||
|
||||
const helpers = module.exports;
|
||||
|
||||
helpers.getUserDataByUserSlug = async function (userslug, callerUID) {
|
||||
helpers.getUserDataByUserSlug = async function (userslug, callerUID, query = {}) {
|
||||
const uid = await user.getUidByUserslug(userslug);
|
||||
if (!uid) {
|
||||
return null;
|
||||
@@ -114,7 +114,11 @@ helpers.getUserDataByUserSlug = async function (userslug, callerUID) {
|
||||
|
||||
await getCounts(userData, callerUID);
|
||||
|
||||
const hookData = await plugins.hooks.fire('filter:helpers.getUserDataByUserSlug', { userData: userData, callerUID: callerUID });
|
||||
const hookData = await plugins.hooks.fire('filter:helpers.getUserDataByUserSlug', {
|
||||
userData: userData,
|
||||
callerUID: callerUID,
|
||||
query: query,
|
||||
});
|
||||
return hookData.userData;
|
||||
};
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ const pagination = require('../../pagination');
|
||||
const infoController = module.exports;
|
||||
|
||||
infoController.get = async function (req, res, next) {
|
||||
const userData = await accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid);
|
||||
const userData = await accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid, req.query);
|
||||
if (!userData) {
|
||||
return next();
|
||||
}
|
||||
|
||||
@@ -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,43 +109,43 @@ 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);
|
||||
|
||||
const [userData, settings] = await Promise.all([
|
||||
accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid),
|
||||
accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid, req.query),
|
||||
user.getSettings(req.uid),
|
||||
]);
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ profileController.get = async function (req, res, next) {
|
||||
}
|
||||
}
|
||||
|
||||
const userData = await accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid);
|
||||
const userData = await accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid, req.query);
|
||||
if (!userData) {
|
||||
return next();
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ const accountHelpers = require('./helpers');
|
||||
const sessionController = module.exports;
|
||||
|
||||
sessionController.get = async function (req, res, next) {
|
||||
const userData = await accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid);
|
||||
const userData = await accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid, req.query);
|
||||
if (!userData) {
|
||||
return next();
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ const accountHelpers = require('./helpers');
|
||||
const settingsController = module.exports;
|
||||
|
||||
settingsController.get = async function (req, res, next) {
|
||||
const userData = await accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid);
|
||||
const userData = await accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid, req.query);
|
||||
if (!userData) {
|
||||
return next();
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ const accountHelpers = require('./helpers');
|
||||
const uploadsController = module.exports;
|
||||
|
||||
uploadsController.get = async function (req, res, next) {
|
||||
const userData = await accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid);
|
||||
const userData = await accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid, req.query);
|
||||
if (!userData) {
|
||||
return next();
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -106,6 +106,7 @@ modsController.flags.list = async function (req, res, next) {
|
||||
filters: filters,
|
||||
sort: sort,
|
||||
uid: req.uid,
|
||||
query: req.query,
|
||||
}),
|
||||
analytics.getDailyStatsForSet('analytics:flags', Date.now(), 30),
|
||||
categories.buildForSelect(req.uid, 'read'),
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -14,7 +14,7 @@ userController.getCurrentUser = async function (req, res) {
|
||||
return res.status(401).json('not-authorized');
|
||||
}
|
||||
const userslug = await user.getUserField(req.uid, 'userslug');
|
||||
const userData = await accountHelpers.getUserDataByUserSlug(userslug, req.uid);
|
||||
const userData = await accountHelpers.getUserDataByUserSlug(userslug, req.uid, req.query);
|
||||
res.json(userData);
|
||||
};
|
||||
|
||||
|
||||
15
src/flags.js
15
src/flags.js
@@ -121,13 +121,13 @@ Flags.get = async function (flagId) {
|
||||
return data.flag;
|
||||
};
|
||||
|
||||
Flags.getCount = async function ({ uid, filters }) {
|
||||
Flags.getCount = async function ({ uid, filters, query }) {
|
||||
filters = filters || {};
|
||||
const flagIds = await Flags.getFlagIdsWithFilters({ filters, uid });
|
||||
const flagIds = await Flags.getFlagIdsWithFilters({ filters, uid, query });
|
||||
return flagIds.length;
|
||||
};
|
||||
|
||||
Flags.getFlagIdsWithFilters = async function ({ filters, uid }) {
|
||||
Flags.getFlagIdsWithFilters = async function ({ filters, uid, query }) {
|
||||
let sets = [];
|
||||
const orSets = [];
|
||||
|
||||
@@ -164,7 +164,13 @@ Flags.getFlagIdsWithFilters = async function ({ filters, uid }) {
|
||||
}
|
||||
}
|
||||
|
||||
return flagIds;
|
||||
const result = await plugins.hooks.fire('filter:flags.getFlagIdsWithFilters', {
|
||||
filters,
|
||||
uid,
|
||||
query,
|
||||
flagIds,
|
||||
});
|
||||
return result.flagIds;
|
||||
};
|
||||
|
||||
Flags.list = async function (data) {
|
||||
@@ -172,6 +178,7 @@ Flags.list = async function (data) {
|
||||
let flagIds = await Flags.getFlagIdsWithFilters({
|
||||
filters,
|
||||
uid: data.uid,
|
||||
query: data.query,
|
||||
});
|
||||
flagIds = await Flags.sort(flagIds, data.sort);
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -109,6 +109,7 @@ middleware.renderHeader = async function renderHeader(req, res, data) {
|
||||
unreadCount: templateValues.unreadCount,
|
||||
} = await appendUnreadCounts({
|
||||
uid: req.uid,
|
||||
query: req.query,
|
||||
navigation: results.navigation,
|
||||
unreadData,
|
||||
}));
|
||||
@@ -152,7 +153,7 @@ middleware.renderHeader = async function renderHeader(req, res, data) {
|
||||
return await req.app.renderAsync('header', hookReturn.templateValues);
|
||||
};
|
||||
|
||||
async function appendUnreadCounts({ uid, navigation, unreadData }) {
|
||||
async function appendUnreadCounts({ uid, navigation, unreadData, query }) {
|
||||
const originalRoutes = navigation.map(nav => nav.originalRoute);
|
||||
const calls = {
|
||||
unreadData: topics.getUnreadData({ uid: uid }),
|
||||
@@ -162,6 +163,7 @@ async function appendUnreadCounts({ uid, navigation, unreadData }) {
|
||||
if (originalRoutes.includes('/flags') && await user.isPrivileged(uid)) {
|
||||
return flags.getCount({
|
||||
uid,
|
||||
query,
|
||||
filters: {
|
||||
quick: 'unresolved',
|
||||
cid: (await user.isAdminOrGlobalMod(uid)) ? [] : (await user.getModeratedCids(uid)),
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
|
||||
@@ -282,7 +282,7 @@ async function getWatchedCids(data) {
|
||||
if (!data.categories.includes('watched')) {
|
||||
return [];
|
||||
}
|
||||
return await user.getCategoriesByStates(data.uid, [categories.watchStates.watching]);
|
||||
return await user.getWatchedCategories(data.uid);
|
||||
}
|
||||
|
||||
async function getChildrenCids(data) {
|
||||
|
||||
@@ -6,7 +6,6 @@ const privileges = require('../privileges');
|
||||
const plugins = require('../plugins');
|
||||
const meta = require('../meta');
|
||||
const topics = require('../topics');
|
||||
const categories = require('../categories');
|
||||
const user = require('../user');
|
||||
const socketHelpers = require('./helpers');
|
||||
const utils = require('../utils');
|
||||
@@ -100,41 +99,6 @@ SocketPosts.getPost = async function (socket, pid) {
|
||||
return await api.posts.get(socket, { pid });
|
||||
};
|
||||
|
||||
SocketPosts.loadMoreBookmarks = async function (socket, data) {
|
||||
return await loadMorePosts('uid:' + data.uid + ':bookmarks', socket.uid, data);
|
||||
};
|
||||
|
||||
SocketPosts.loadMoreUserPosts = async function (socket, data) {
|
||||
const cids = await categories.getCidsByPrivilege('categories:cid', socket.uid, 'topics:read');
|
||||
const keys = cids.map(c => 'cid:' + c + ':uid:' + data.uid + ':pids');
|
||||
return await loadMorePosts(keys, socket.uid, data);
|
||||
};
|
||||
|
||||
SocketPosts.loadMoreBestPosts = async function (socket, data) {
|
||||
const cids = await categories.getCidsByPrivilege('categories:cid', socket.uid, 'topics:read');
|
||||
const keys = cids.map(c => 'cid:' + c + ':uid:' + data.uid + ':pids:votes');
|
||||
return await loadMorePosts(keys, socket.uid, data);
|
||||
};
|
||||
|
||||
SocketPosts.loadMoreUpVotedPosts = async function (socket, data) {
|
||||
return await loadMorePosts('uid:' + data.uid + ':upvote', socket.uid, data);
|
||||
};
|
||||
|
||||
SocketPosts.loadMoreDownVotedPosts = async function (socket, data) {
|
||||
return await loadMorePosts('uid:' + data.uid + ':downvote', socket.uid, data);
|
||||
};
|
||||
|
||||
async function loadMorePosts(set, uid, data) {
|
||||
if (!data || !utils.isNumber(data.uid) || !utils.isNumber(data.after)) {
|
||||
throw new Error('[[error:invalid-data]]');
|
||||
}
|
||||
|
||||
const start = Math.max(0, parseInt(data.after, 10));
|
||||
const stop = start + 9;
|
||||
|
||||
return await posts.getPostSummariesFromSet(set, uid, start, stop);
|
||||
}
|
||||
|
||||
SocketPosts.getCategory = async function (socket, pid) {
|
||||
return await posts.getCidByPid(pid);
|
||||
};
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const topics = require('../../topics');
|
||||
const categories = require('../../categories');
|
||||
const privileges = require('../../privileges');
|
||||
const meta = require('../../meta');
|
||||
const utils = require('../../utils');
|
||||
@@ -89,12 +88,6 @@ module.exports = function (SocketTopics) {
|
||||
return await topics.getTopicsFromSet(data.set, socket.uid, start, stop);
|
||||
};
|
||||
|
||||
SocketTopics.loadMoreUserTopics = async function (socket, data) {
|
||||
const cids = await categories.getCidsByPrivilege('categories:cid', socket.uid, 'topics:read');
|
||||
data.set = cids.map(c => 'cid:' + c + ':uid:' + data.uid + ':tids');
|
||||
return await SocketTopics.loadMoreFromSet(socket, data);
|
||||
};
|
||||
|
||||
function calculateStartStop(data) {
|
||||
const itemsPerPage = Math.min(meta.config.topicsPerPage || 20, parseInt(data.count, 10) || meta.config.topicsPerPage || 20);
|
||||
let start = Math.max(0, parseInt(data.after, 10));
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -4,6 +4,7 @@ const _ = require('lodash');
|
||||
|
||||
const db = require('../database');
|
||||
const categories = require('../categories');
|
||||
const plugins = require('../plugins');
|
||||
|
||||
module.exports = function (User) {
|
||||
User.setCategoryWatchState = async function (uid, cids, state) {
|
||||
@@ -36,14 +37,24 @@ module.exports = function (User) {
|
||||
if (!(parseInt(uid, 10) > 0)) {
|
||||
return [];
|
||||
}
|
||||
return await User.getCategoriesByStates(uid, [categories.watchStates.ignoring]);
|
||||
const cids = await User.getCategoriesByStates(uid, [categories.watchStates.ignoring]);
|
||||
const result = await plugins.hooks.fire('filter:user.getIgnoredCategories', {
|
||||
uid: uid,
|
||||
cids: cids,
|
||||
});
|
||||
return result.cids;
|
||||
};
|
||||
|
||||
User.getWatchedCategories = async function (uid) {
|
||||
if (!(parseInt(uid, 10) > 0)) {
|
||||
return [];
|
||||
}
|
||||
return await User.getCategoriesByStates(uid, [categories.watchStates.watching]);
|
||||
const cids = await User.getCategoriesByStates(uid, [categories.watchStates.watching]);
|
||||
const result = await plugins.hooks.fire('filter:user.getWatchedCategories', {
|
||||
uid: uid,
|
||||
cids: cids,
|
||||
});
|
||||
return result.cids;
|
||||
};
|
||||
|
||||
User.getCategoriesByStates = async function (uid, states) {
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -901,55 +901,8 @@ describe('Post\'s', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('shold error with invalid data', function (done) {
|
||||
socketPosts.loadMoreBookmarks({ uid: voterUid }, { uid: voterUid, after: null }, function (err) {
|
||||
assert.equal(err.message, '[[error:invalid-data]]');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should load more bookmarks', function (done) {
|
||||
socketPosts.loadMoreBookmarks({ uid: voterUid }, { uid: voterUid, after: 0 }, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert(data);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should load more user posts', function (done) {
|
||||
socketPosts.loadMoreUserPosts({ uid: voterUid }, { uid: voterUid, after: 0 }, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert(data);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should load more best posts', function (done) {
|
||||
socketPosts.loadMoreBestPosts({ uid: voterUid }, { uid: voterUid, after: 0 }, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert(data);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should load more up voted posts', function (done) {
|
||||
socketPosts.loadMoreUpVotedPosts({ uid: voterUid }, { uid: voterUid, after: 0 }, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert(data);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should load more down voted posts', function (done) {
|
||||
socketPosts.loadMoreDownVotedPosts({ uid: voterUid }, { uid: voterUid, after: 0 }, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert(data);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should get post category', function (done) {
|
||||
socketPosts.getCategory({ uid: voterUid }, pid, function (err, postCid) {
|
||||
it('should get post category', (done) => {
|
||||
socketPosts.getCategory({ uid: voterUid }, pid, (err, postCid) => {
|
||||
assert.ifError(err);
|
||||
assert.equal(cid, postCid);
|
||||
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