|
|
|
@ -92,27 +92,11 @@ async function getUsers(req, res) {
|
|
|
|
|
return uids;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function getUsersWithFields(set) {
|
|
|
|
|
const uids = await getUids(set);
|
|
|
|
|
const [isAdmin, userData, lastonline] = await Promise.all([
|
|
|
|
|
user.isAdministrator(uids),
|
|
|
|
|
user.getUsersWithFields(uids, userFields, req.uid),
|
|
|
|
|
db.sortedSetScores('users:online', uids),
|
|
|
|
|
]);
|
|
|
|
|
userData.forEach((user, index) => {
|
|
|
|
|
if (user) {
|
|
|
|
|
user.administrator = isAdmin[index];
|
|
|
|
|
const timestamp = lastonline[index] || user.joindate;
|
|
|
|
|
user.lastonline = timestamp;
|
|
|
|
|
user.lastonlineISO = utils.toISOString(timestamp);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return userData;
|
|
|
|
|
}
|
|
|
|
|
const set = buildSet();
|
|
|
|
|
const uids = await getUids(set);
|
|
|
|
|
const [count, users] = await Promise.all([
|
|
|
|
|
getCount(set),
|
|
|
|
|
getUsersWithFields(set),
|
|
|
|
|
loadUserInfo(req.uid, uids),
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
await render(req, res, {
|
|
|
|
@ -162,16 +146,8 @@ usersController.search = async function (req, res) {
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const uids = searchData.users.map(user => user && user.uid);
|
|
|
|
|
const userInfo = await user.getUsersFields(uids, ['email', 'flags', 'lastonline', 'joindate']);
|
|
|
|
|
searchData.users = await loadUserInfo(req.uid, uids);
|
|
|
|
|
|
|
|
|
|
searchData.users.forEach((user, index) => {
|
|
|
|
|
if (user && userInfo[index]) {
|
|
|
|
|
user.email = userInfo[index].email;
|
|
|
|
|
user.flags = userInfo[index].flags || 0;
|
|
|
|
|
user.lastonlineISO = userInfo[index].lastonlineISO;
|
|
|
|
|
user.joindateISO = userInfo[index].joindateISO;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
searchData.query = validator.escape(String(req.query.query || ''));
|
|
|
|
|
searchData.resultsPerPage = resultsPerPage;
|
|
|
|
|
searchData.sortBy = req.query.sortBy;
|
|
|
|
@ -179,6 +155,24 @@ usersController.search = async function (req, res) {
|
|
|
|
|
await render(req, res, searchData);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
async function loadUserInfo(callerUid, uids) {
|
|
|
|
|
const [isAdmin, userData, lastonline] = await Promise.all([
|
|
|
|
|
user.isAdministrator(uids),
|
|
|
|
|
user.getUsersWithFields(uids, userFields, callerUid),
|
|
|
|
|
db.sortedSetScores('users:online', uids),
|
|
|
|
|
]);
|
|
|
|
|
userData.forEach((user, index) => {
|
|
|
|
|
if (user) {
|
|
|
|
|
user.administrator = isAdmin[index];
|
|
|
|
|
user.flags = userData[index].flags || 0;
|
|
|
|
|
const timestamp = lastonline[index] || user.joindate;
|
|
|
|
|
user.lastonline = timestamp;
|
|
|
|
|
user.lastonlineISO = utils.toISOString(timestamp);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return userData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
usersController.registrationQueue = async function (req, res) {
|
|
|
|
|
const page = parseInt(req.query.page, 10) || 1;
|
|
|
|
|
const itemsPerPage = 20;
|
|
|
|
|