feat: #7743 account/posts controller

v1.18.x
Barış Soner Uşaklı 6 years ago
parent 9b3f4b98d1
commit e72f3e4ffe

@ -1,234 +1,191 @@
'use strict'; 'use strict';
const validator = require('validator');
var async = require('async'); const winston = require('winston');
var validator = require('validator'); const nconf = require('nconf');
var winston = require('winston');
var nconf = require('nconf'); const user = require('../../user');
const groups = require('../../groups');
var user = require('../../user'); const plugins = require('../../plugins');
var groups = require('../../groups'); const meta = require('../../meta');
var plugins = require('../../plugins'); const utils = require('../../utils');
var meta = require('../../meta'); const privileges = require('../../privileges');
var utils = require('../../utils');
var privileges = require('../../privileges');
const translator = require('../../translator'); const translator = require('../../translator');
var helpers = module.exports; const helpers = module.exports;
helpers.getUserDataByUserSlug = function (userslug, callerUID, callback) {
let results;
async.waterfall([
function (next) {
user.getUidByUserslug(userslug, next);
},
function (uid, next) {
if (!uid) {
return callback(null, null);
}
async.parallel({ helpers.getUserDataByUserSlug = async function (userslug, callerUID) {
userData: function (next) { const uid = await user.getUidByUserslug(userslug);
user.getUserData(uid, next); if (!uid) {
}, return null;
isTargetAdmin: function (next) { }
user.isAdministrator(uid, next);
},
userSettings: function (next) {
user.getSettings(uid, next);
},
isAdmin: function (next) {
user.isAdministrator(callerUID, next);
},
isGlobalModerator: function (next) {
user.isGlobalModerator(callerUID, next);
},
isModerator: function (next) {
user.isModeratorOfAnyCategory(callerUID, next);
},
isFollowing: function (next) {
user.isFollowing(callerUID, uid, next);
},
ips: function (next) {
user.getIPs(uid, 4, next);
},
profile_menu: function (next) {
const links = [{
id: 'info',
route: 'info',
name: '[[user:account_info]]',
visibility: {
self: false,
other: false,
moderator: true,
globalMod: true,
admin: true,
},
}, {
id: 'sessions',
route: 'sessions',
name: '[[pages:account/sessions]]',
visibility: {
self: true,
other: false,
moderator: false,
globalMod: false,
admin: false,
},
}];
if (meta.config.gdpr_enabled) { const results = await getAllData(uid, callerUID);
links.push({ if (!results.userData) {
id: 'consent', throw new Error('[[error:invalid-uid]]');
route: 'consent', }
name: '[[user:consent.title]]', await parseAboutMe(results.userData);
visibility: {
self: true,
other: false,
moderator: false,
globalMod: false,
admin: false,
},
});
}
plugins.fireHook('filter:user.profileMenu', { const userData = results.userData;
uid: uid, const userSettings = results.userSettings;
callerUID: callerUID, const isAdmin = results.isAdmin;
links: links, const isGlobalModerator = results.isGlobalModerator;
}, next); const isModerator = results.isModerator;
}, const isSelf = parseInt(callerUID, 10) === parseInt(userData.uid, 10);
groups: function (next) {
groups.getUserGroups([uid], next);
},
sso: function (next) {
plugins.fireHook('filter:auth.list', { uid: uid, associations: [] }, next);
},
canEdit: function (next) {
privileges.users.canEdit(callerUID, uid, next);
},
canBanUser: function (next) {
privileges.users.canBanUser(callerUID, uid, next);
},
isBlocked: function (next) {
user.blocks.is(uid, callerUID, next);
},
}, next);
},
function (_results, next) {
results = _results;
if (!results.userData) {
return callback(new Error('[[error:invalid-uid]]'));
}
parseAboutMe(results.userData, next);
},
function (next) {
var userData = results.userData;
var userSettings = results.userSettings;
var isAdmin = results.isAdmin;
var isGlobalModerator = results.isGlobalModerator;
var isModerator = results.isModerator;
var isSelf = parseInt(callerUID, 10) === parseInt(userData.uid, 10);
userData.joindateISO = utils.toISOString(userData.joindate); userData.age = Math.max(0, userData.birthday ? Math.floor((new Date().getTime() - new Date(userData.birthday).getTime()) / 31536000000) : 0);
userData.lastonlineISO = utils.toISOString(userData.lastonline || userData.joindate);
userData.age = Math.max(0, userData.birthday ? Math.floor((new Date().getTime() - new Date(userData.birthday).getTime()) / 31536000000) : 0);
userData.emailClass = 'hide'; userData.emailClass = 'hide';
if (!isAdmin && !isGlobalModerator && !isSelf && (!userSettings.showemail || meta.config.hideEmail)) { if (!isAdmin && !isGlobalModerator && !isSelf && (!userSettings.showemail || meta.config.hideEmail)) {
userData.email = ''; userData.email = '';
} else if (!userSettings.showemail) { } else if (!userSettings.showemail) {
userData.emailClass = ''; userData.emailClass = '';
} }
if (!isAdmin && !isGlobalModerator && !isSelf && (!userSettings.showfullname || meta.config.hideFullname)) { if (!isAdmin && !isGlobalModerator && !isSelf && (!userSettings.showfullname || meta.config.hideFullname)) {
userData.fullname = ''; userData.fullname = '';
} }
if (isAdmin || isSelf || ((isGlobalModerator || isModerator) && !results.isTargetAdmin)) { if (isAdmin || isSelf || ((isGlobalModerator || isModerator) && !results.isTargetAdmin)) {
userData.ips = results.ips; userData.ips = results.ips;
} }
if (!isAdmin && !isGlobalModerator && !isModerator) { if (!isAdmin && !isGlobalModerator && !isModerator) {
userData.moderationNote = undefined; userData.moderationNote = undefined;
} }
userData.isBlocked = results.isBlocked; userData.isBlocked = results.isBlocked;
if (isAdmin || isSelf) { if (isAdmin || isSelf) {
userData.blocksCount = parseInt(userData.blocksCount, 10) || 0; userData.blocksCount = parseInt(userData.blocksCount, 10) || 0;
} }
userData.yourid = callerUID; userData.yourid = callerUID;
userData.theirid = userData.uid; userData.theirid = userData.uid;
userData.isTargetAdmin = results.isTargetAdmin; userData.isTargetAdmin = results.isTargetAdmin;
userData.isAdmin = isAdmin; userData.isAdmin = isAdmin;
userData.isGlobalModerator = isGlobalModerator; userData.isGlobalModerator = isGlobalModerator;
userData.isModerator = isModerator; userData.isModerator = isModerator;
userData.isAdminOrGlobalModerator = isAdmin || isGlobalModerator; userData.isAdminOrGlobalModerator = isAdmin || isGlobalModerator;
userData.isAdminOrGlobalModeratorOrModerator = isAdmin || isGlobalModerator || isModerator; userData.isAdminOrGlobalModeratorOrModerator = isAdmin || isGlobalModerator || isModerator;
userData.isSelfOrAdminOrGlobalModerator = isSelf || isAdmin || isGlobalModerator; userData.isSelfOrAdminOrGlobalModerator = isSelf || isAdmin || isGlobalModerator;
userData.canEdit = results.canEdit; userData.canEdit = results.canEdit;
userData.canBan = results.canBanUser; userData.canBan = results.canBanUser;
userData.canChangePassword = isAdmin || (isSelf && !meta.config['password:disableEdit']); userData.canChangePassword = isAdmin || (isSelf && !meta.config['password:disableEdit']);
userData.isSelf = isSelf; userData.isSelf = isSelf;
userData.isFollowing = results.isFollowing; userData.isFollowing = results.isFollowing;
userData.showHidden = isSelf || isAdmin || (isGlobalModerator && !results.isTargetAdmin); userData.showHidden = isSelf || isAdmin || (isGlobalModerator && !results.isTargetAdmin);
userData.groups = Array.isArray(results.groups) && results.groups.length ? results.groups[0] : []; userData.groups = Array.isArray(results.groups) && results.groups.length ? results.groups[0] : [];
userData.disableSignatures = meta.config.disableSignatures === 1; userData.disableSignatures = meta.config.disableSignatures === 1;
userData['reputation:disabled'] = meta.config['reputation:disabled'] === 1; userData['reputation:disabled'] = meta.config['reputation:disabled'] === 1;
userData['downvote:disabled'] = meta.config['downvote:disabled'] === 1; userData['downvote:disabled'] = meta.config['downvote:disabled'] === 1;
userData['email:confirmed'] = !!userData['email:confirmed']; userData['email:confirmed'] = !!userData['email:confirmed'];
userData.profile_links = filterLinks(results.profile_menu.links, { userData.profile_links = filterLinks(results.profile_menu.links, {
self: isSelf, self: isSelf,
other: !isSelf, other: !isSelf,
moderator: isModerator, moderator: isModerator,
globalMod: isGlobalModerator, globalMod: isGlobalModerator,
admin: isAdmin, admin: isAdmin,
}); });
userData.sso = results.sso.associations; userData.sso = results.sso.associations;
userData.status = user.getStatus(userData); userData.banned = userData.banned === 1;
userData.banned = userData.banned === 1; userData.website = validator.escape(String(userData.website || ''));
userData.website = validator.escape(String(userData.website || '')); userData.websiteLink = !userData.website.startsWith('http') ? 'http://' + userData.website : userData.website;
userData.websiteLink = !userData.website.startsWith('http') ? 'http://' + userData.website : userData.website; userData.websiteName = userData.website.replace(validator.escape('http://'), '').replace(validator.escape('https://'), '');
userData.websiteName = userData.website.replace(validator.escape('http://'), '').replace(validator.escape('https://'), '');
userData.fullname = validator.escape(String(userData.fullname || ''));
userData.location = validator.escape(String(userData.location || ''));
userData.signature = validator.escape(String(userData.signature || ''));
userData.birthday = validator.escape(String(userData.birthday || ''));
userData.moderationNote = validator.escape(String(userData.moderationNote || ''));
if (userData['cover:url']) {
userData['cover:url'] = userData['cover:url'].startsWith('http') ? userData['cover:url'] : (nconf.get('relative_path') + userData['cover:url']);
} else {
userData['cover:url'] = require('../../coverPhoto').getDefaultProfileCover(userData.uid);
}
userData.fullname = validator.escape(String(userData.fullname || '')); userData['cover:position'] = validator.escape(String(userData['cover:position'] || '50% 50%'));
userData.location = validator.escape(String(userData.location || '')); userData['username:disableEdit'] = !userData.isAdmin && meta.config['username:disableEdit'];
userData.signature = validator.escape(String(userData.signature || '')); userData['email:disableEdit'] = !userData.isAdmin && meta.config['email:disableEdit'];
userData.birthday = validator.escape(String(userData.birthday || ''));
userData.moderationNote = validator.escape(String(userData.moderationNote || ''));
if (userData['cover:url']) { return userData;
userData['cover:url'] = userData['cover:url'].startsWith('http') ? userData['cover:url'] : (nconf.get('relative_path') + userData['cover:url']); };
} else {
userData['cover:url'] = require('../../coverPhoto').getDefaultProfileCover(userData.uid);
}
userData['cover:position'] = validator.escape(String(userData['cover:position'] || '50% 50%')); async function getAllData(uid, callerUID) {
userData['username:disableEdit'] = !userData.isAdmin && meta.config['username:disableEdit']; return await utils.promiseParallel({
userData['email:disableEdit'] = !userData.isAdmin && meta.config['email:disableEdit']; userData: user.getUserData(uid),
isTargetAdmin: user.isAdministrator(uid),
userSettings: user.getSettings(uid),
isAdmin: user.isAdministrator(callerUID),
isGlobalModerator: user.isGlobalModerator(callerUID),
isModerator: user.isModeratorOfAnyCategory(callerUID),
isFollowing: user.isFollowing(callerUID, uid),
ips: user.getIPs(uid, 4),
profile_menu: getProfileMenu(uid, callerUID),
groups: groups.getUserGroups([uid]),
sso: plugins.fireHook('filter:auth.list', { uid: uid, associations: [] }),
canEdit: privileges.users.canEdit(callerUID, uid),
canBanUser: privileges.users.canBanUser(callerUID, uid),
isBlocked: user.blocks.is(uid, callerUID),
});
}
next(null, userData); async function getProfileMenu(uid, callerUID) {
const links = [{
id: 'info',
route: 'info',
name: '[[user:account_info]]',
visibility: {
self: false,
other: false,
moderator: true,
globalMod: true,
admin: true,
}, },
], callback); }, {
}; id: 'sessions',
route: 'sessions',
name: '[[pages:account/sessions]]',
visibility: {
self: true,
other: false,
moderator: false,
globalMod: false,
admin: false,
},
}];
if (meta.config.gdpr_enabled) {
links.push({
id: 'consent',
route: 'consent',
name: '[[user:consent.title]]',
visibility: {
self: true,
other: false,
moderator: false,
globalMod: false,
admin: false,
},
});
}
return await plugins.fireHook('filter:user.profileMenu', {
uid: uid,
callerUID: callerUID,
links: links,
});
}
function parseAboutMe(userData, callback) { async function parseAboutMe(userData) {
if (!userData.aboutme) { if (!userData.aboutme) {
return callback(); return;
} }
userData.aboutme = validator.escape(String(userData.aboutme || '')); userData.aboutme = validator.escape(String(userData.aboutme || ''));
async.waterfall([ const parsed = await plugins.fireHook('filter:parse.aboutme', userData.aboutme);
function (next) { userData.aboutmeParsed = translator.escape(parsed);
plugins.fireHook('filter:parse.aboutme', userData.aboutme, next);
},
function (aboutme, next) {
userData.aboutmeParsed = translator.escape(aboutme);
next();
},
], callback);
} }
function filterLinks(links, states) { function filterLinks(links, states) {
@ -256,3 +213,5 @@ function filterLinks(links, states) {
return permit; return permit;
}); });
} }
require('../../promisify')(helpers);

@ -1,82 +1,67 @@
'use strict'; 'use strict';
const db = require('../../database');
var async = require('async'); const user = require('../../user');
const posts = require('../../posts');
var db = require('../../database'); const topics = require('../../topics');
var user = require('../../user'); const categories = require('../../categories');
var posts = require('../../posts'); const pagination = require('../../pagination');
var topics = require('../../topics'); const helpers = require('../helpers');
var categories = require('../../categories'); const accountHelpers = require('./helpers');
var pagination = require('../../pagination');
var helpers = require('../helpers'); const postsController = module.exports;
var accountHelpers = require('./helpers');
const templateToData = {
var postsController = module.exports;
var templateToData = {
'account/bookmarks': { 'account/bookmarks': {
type: 'posts', type: 'posts',
noItemsFoundKey: '[[topic:bookmarks.has_no_bookmarks]]', noItemsFoundKey: '[[topic:bookmarks.has_no_bookmarks]]',
crumb: '[[user:bookmarks]]', crumb: '[[user:bookmarks]]',
getSets: function (callerUid, userData, calback) { getSets: function (callerUid, userData) {
setImmediate(calback, null, 'uid:' + userData.uid + ':bookmarks'); return 'uid:' + userData.uid + ':bookmarks';
}, },
}, },
'account/posts': { 'account/posts': {
type: 'posts', type: 'posts',
noItemsFoundKey: '[[user:has_no_posts]]', noItemsFoundKey: '[[user:has_no_posts]]',
crumb: '[[global:posts]]', crumb: '[[global:posts]]',
getSets: function (callerUid, userData, callback) { getSets: async function (callerUid, userData) {
async.waterfall([ const cids = await categories.getCidsByPrivilege('categories:cid', callerUid, 'topics:read');
function (next) { return cids.map(c => 'cid:' + c + ':uid:' + userData.uid + ':pids');
categories.getCidsByPrivilege('categories:cid', callerUid, 'topics:read', next);
},
function (cids, next) {
next(null, cids.map(c => 'cid:' + c + ':uid:' + userData.uid + ':pids'));
},
], callback);
}, },
}, },
'account/upvoted': { 'account/upvoted': {
type: 'posts', type: 'posts',
noItemsFoundKey: '[[user:has_no_upvoted_posts]]', noItemsFoundKey: '[[user:has_no_upvoted_posts]]',
crumb: '[[global:upvoted]]', crumb: '[[global:upvoted]]',
getSets: function (callerUid, userData, calback) { getSets: function (callerUid, userData) {
setImmediate(calback, null, 'uid:' + userData.uid + ':upvote'); return 'uid:' + userData.uid + ':upvote';
}, },
}, },
'account/downvoted': { 'account/downvoted': {
type: 'posts', type: 'posts',
noItemsFoundKey: '[[user:has_no_downvoted_posts]]', noItemsFoundKey: '[[user:has_no_downvoted_posts]]',
crumb: '[[global:downvoted]]', crumb: '[[global:downvoted]]',
getSets: function (callerUid, userData, calback) { getSets: function (callerUid, userData) {
setImmediate(calback, null, 'uid:' + userData.uid + ':downvote'); return 'uid:' + userData.uid + ':downvote';
}, },
}, },
'account/best': { 'account/best': {
type: 'posts', type: 'posts',
noItemsFoundKey: '[[user:has_no_voted_posts]]', noItemsFoundKey: '[[user:has_no_voted_posts]]',
crumb: '[[global:best]]', crumb: '[[global:best]]',
getSets: function (callerUid, userData, callback) { getSets: async function (callerUid, userData) {
async.waterfall([ const cids = await categories.getCidsByPrivilege('categories:cid', callerUid, 'topics:read');
function (next) { return cids.map(c => 'cid:' + c + ':uid:' + userData.uid + ':pids:votes');
categories.getCidsByPrivilege('categories:cid', callerUid, 'topics:read', next);
},
function (cids, next) {
next(null, cids.map(c => 'cid:' + c + ':uid:' + userData.uid + ':pids:votes'));
},
], callback);
}, },
}, },
'account/watched': { 'account/watched': {
type: 'topics', type: 'topics',
noItemsFoundKey: '[[user:has_no_watched_topics]]', noItemsFoundKey: '[[user:has_no_watched_topics]]',
crumb: '[[user:watched]]', crumb: '[[user:watched]]',
getSets: function (callerUid, userData, calback) { getSets: function (callerUid, userData) {
setImmediate(calback, null, 'uid:' + userData.uid + ':followed_tids'); return 'uid:' + userData.uid + ':followed_tids';
}, },
getTopics: function (set, req, start, stop, callback) { getTopics: async function (set, req, start, stop) {
const sort = req.query.sort; const sort = req.query.sort;
const map = { const map = {
votes: 'topics:votes', votes: 'topics:votes',
@ -87,163 +72,123 @@ var templateToData = {
}; };
if (!sort || !map[sort]) { if (!sort || !map[sort]) {
return topics.getTopicsFromSet(set, req.uid, start, stop, callback); return await topics.getTopicsFromSet(set, req.uid, start, stop);
} }
const sortSet = map[sort]; const sortSet = map[sort];
let tids; let tids = await db.getSortedSetRevRange(set, 0, -1);
async.waterfall([ const scores = await db.sortedSetScores(sortSet, tids);
function (next) { tids = tids.map((tid, i) => ({ tid: tid, score: scores[i] }))
db.getSortedSetRevRange(set, 0, -1, next); .sort((a, b) => b.score - a.score)
}, .slice(start, stop + 1)
function (_tids, next) { .map(t => t.tid);
tids = _tids;
db.sortedSetScores(sortSet, tids, next); const topicsData = await topics.getTopics(tids, req.uid);
}, topics.calculateTopicIndices(topicsData, start);
function (scores, next) { return { topics: topicsData, nextStart: stop + 1 };
tids = tids.map((tid, i) => ({ tid: tid, score: scores[i] }))
.sort((a, b) => b.score - a.score)
.slice(start, stop + 1)
.map(t => t.tid);
topics.getTopics(tids, req.uid, next);
},
function (topicsData, next) {
topics.calculateTopicIndices(topicsData, start);
next(null, { topics: topicsData, nextStart: stop + 1 });
},
], callback);
}, },
}, },
'account/ignored': { 'account/ignored': {
type: 'topics', type: 'topics',
noItemsFoundKey: '[[user:has_no_ignored_topics]]', noItemsFoundKey: '[[user:has_no_ignored_topics]]',
crumb: '[[user:ignored]]', crumb: '[[user:ignored]]',
getSets: function (callerUid, userData, calback) { getSets: function (callerUid, userData) {
setImmediate(calback, null, 'uid:' + userData.uid + ':ignored_tids'); return 'uid:' + userData.uid + ':ignored_tids';
}, },
}, },
'account/topics': { 'account/topics': {
type: 'topics', type: 'topics',
noItemsFoundKey: '[[user:has_no_topics]]', noItemsFoundKey: '[[user:has_no_topics]]',
crumb: '[[global:topics]]', crumb: '[[global:topics]]',
getSets: function (callerUid, userData, callback) { getSets: async function (callerUid, userData) {
async.waterfall([ const cids = await categories.getCidsByPrivilege('categories:cid', callerUid, 'topics:read');
function (next) { return cids.map(c => 'cid:' + c + ':uid:' + userData.uid + ':tids');
categories.getCidsByPrivilege('categories:cid', callerUid, 'topics:read', next);
},
function (cids, next) {
next(null, cids.map(c => 'cid:' + c + ':uid:' + userData.uid + ':tids'));
},
], callback);
}, },
}, },
}; };
postsController.getBookmarks = function (req, res, next) { postsController.getBookmarks = async function (req, res, next) {
getFromUserSet('account/bookmarks', req, res, next); await getFromUserSet('account/bookmarks', req, res, next);
}; };
postsController.getPosts = function (req, res, next) { postsController.getPosts = async function (req, res, next) {
getFromUserSet('account/posts', req, res, next); await getFromUserSet('account/posts', req, res, next);
}; };
postsController.getUpVotedPosts = function (req, res, next) { postsController.getUpVotedPosts = async function (req, res, next) {
getFromUserSet('account/upvoted', req, res, next); await getFromUserSet('account/upvoted', req, res, next);
}; };
postsController.getDownVotedPosts = function (req, res, next) { postsController.getDownVotedPosts = async function (req, res, next) {
getFromUserSet('account/downvoted', req, res, next); await getFromUserSet('account/downvoted', req, res, next);
}; };
postsController.getBestPosts = function (req, res, next) { postsController.getBestPosts = async function (req, res, next) {
getFromUserSet('account/best', req, res, next); await getFromUserSet('account/best', req, res, next);
}; };
postsController.getWatchedTopics = function (req, res, next) { postsController.getWatchedTopics = async function (req, res, next) {
getFromUserSet('account/watched', req, res, next); await getFromUserSet('account/watched', req, res, next);
}; };
postsController.getIgnoredTopics = function (req, res, next) { postsController.getIgnoredTopics = async function (req, res, next) {
getFromUserSet('account/ignored', req, res, next); await getFromUserSet('account/ignored', req, res, next);
}; };
postsController.getTopics = function (req, res, next) { postsController.getTopics = async function (req, res, next) {
getFromUserSet('account/topics', req, res, next); await getFromUserSet('account/topics', req, res, next);
}; };
function getFromUserSet(template, req, res, callback) { async function getFromUserSet(template, req, res, callback) {
var data = templateToData[template]; const data = templateToData[template];
var userData; const page = Math.max(1, parseInt(req.query.page, 10) || 1);
var settings;
var itemsPerPage; const [userData, settings] = await Promise.all([
var page = Math.max(1, parseInt(req.query.page, 10) || 1); accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid),
user.getSettings(req.uid),
async.waterfall([ ]);
function (next) {
async.parallel({ if (!userData) {
settings: function (next) { return callback();
user.getSettings(req.uid, next); }
}, const itemsPerPage = data.type === 'topics' ? settings.topicsPerPage : settings.postsPerPage;
userData: function (next) { const start = (page - 1) * itemsPerPage;
accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid, next); const stop = start + itemsPerPage - 1;
}, const sets = await data.getSets(req.uid, userData);
}, next);
}, const [itemCount, itemData] = await Promise.all([
function (results, next) { settings.usePagination ? db.sortedSetsCardSum(sets) : 0,
if (!results.userData) { getItemData(sets, data, req, start, stop),
return callback(); ]);
}
userData[data.type] = itemData[data.type];
userData = results.userData; userData.nextStart = itemData.nextStart;
settings = results.settings;
itemsPerPage = data.type === 'topics' ? settings.topicsPerPage : settings.postsPerPage; const pageCount = Math.ceil(itemCount / itemsPerPage);
userData.pagination = pagination.create(page, pageCount, req.query);
userData.noItemsFoundKey = data.noItemsFoundKey;
userData.title = '[[pages:' + template + ', ' + userData.username + ']]';
userData.breadcrumbs = helpers.buildBreadcrumbs([{ text: userData.username, url: '/user/' + userData.userslug }, { text: data.crumb }]);
userData.showSort = template === 'account/watched';
const baseUrl = (req.baseUrl + req.path.replace(/^\/api/, ''));
userData.sortOptions = [
{ url: baseUrl + '?sort=votes', name: '[[global:votes]]' },
{ url: baseUrl + '?sort=posts', name: '[[global:posts]]' },
{ url: baseUrl + '?sort=views', name: '[[global:views]]' },
{ url: baseUrl + '?sort=lastpost', name: '[[global:lastpost]]' },
{ url: baseUrl + '?sort=firstpost', name: '[[global:firstpost]]' },
];
userData.sortOptions.forEach(function (option) {
option.selected = option.url.includes('sort=' + req.query.sort);
});
res.render(template, userData);
}
data.getSets(req.uid, userData, next); async function getItemData(sets, data, req, start, stop) {
}, if (data.getTopics) {
function (sets, next) { return await data.getTopics(sets, req, start, stop);
async.parallel({ }
itemCount: function (next) { const method = data.type === 'topics' ? topics.getTopicsFromSet : posts.getPostSummariesFromSet;
if (settings.usePagination) { return await method(sets, req.uid, start, stop);
db.sortedSetsCardSum(sets, next);
} else {
next(null, 0);
}
},
data: function (next) {
var start = (page - 1) * itemsPerPage;
var stop = start + itemsPerPage - 1;
const method = data.type === 'topics' ? topics.getTopicsFromSet : posts.getPostSummariesFromSet;
if (data.getTopics) {
return data.getTopics(sets, req, start, stop, next);
}
method(sets, req.uid, start, stop, next);
},
}, next);
},
function (results) {
userData[data.type] = results.data[data.type];
userData.nextStart = results.data.nextStart;
var pageCount = Math.ceil(results.itemCount / itemsPerPage);
userData.pagination = pagination.create(page, pageCount, req.query);
userData.noItemsFoundKey = data.noItemsFoundKey;
userData.title = '[[pages:' + template + ', ' + userData.username + ']]';
userData.breadcrumbs = helpers.buildBreadcrumbs([{ text: userData.username, url: '/user/' + userData.userslug }, { text: data.crumb }]);
userData.showSort = template === 'account/watched';
const baseUrl = (req.baseUrl + req.path.replace(/^\/api/, ''));
userData.sortOptions = [
{ url: baseUrl + '?sort=votes', name: '[[global:votes]]' },
{ url: baseUrl + '?sort=posts', name: '[[global:posts]]' },
{ url: baseUrl + '?sort=views', name: '[[global:views]]' },
{ url: baseUrl + '?sort=lastpost', name: '[[global:lastpost]]' },
{ url: baseUrl + '?sort=firstpost', name: '[[global:firstpost]]' },
];
userData.sortOptions.forEach(function (option) {
option.selected = option.url.includes('sort=' + req.query.sort);
});
res.render(template, userData);
},
], callback);
} }

Loading…
Cancel
Save