mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-03-06 04:21:17 +01:00
Merge remote-tracking branch 'origin/0.5.1' into cluster
This commit is contained in:
@@ -36,7 +36,7 @@
|
||||
"nconf": "~0.6.7",
|
||||
"nodebb-plugin-dbsearch": "0.0.13",
|
||||
"nodebb-plugin-markdown": "~0.5.0",
|
||||
"nodebb-plugin-mentions": "~0.5.0",
|
||||
"nodebb-plugin-mentions": "~0.6.0",
|
||||
"nodebb-plugin-soundpack-default": "~0.1.1",
|
||||
"nodebb-theme-lavender": "~0.0.74",
|
||||
"nodebb-theme-vanilla": "~0.0.111",
|
||||
|
||||
@@ -98,6 +98,8 @@ Controllers.search = function(req, res, next) {
|
||||
return res.redirect('/404');
|
||||
}
|
||||
|
||||
req.params.term = req.params.term.replace(/"/g, '/"');
|
||||
|
||||
search.search(req.params.term, uid, function(err, results) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
|
||||
@@ -16,6 +16,7 @@ var topicsController = {},
|
||||
topicsController.get = function(req, res, next) {
|
||||
var tid = req.params.topic_id,
|
||||
page = req.query.page || 1,
|
||||
sort = req.query.sort,
|
||||
uid = req.user ? req.user.uid : 0,
|
||||
userPrivileges;
|
||||
|
||||
@@ -45,7 +46,15 @@ topicsController.get = function(req, res, next) {
|
||||
var set = 'tid:' + tid + ':posts',
|
||||
reverse = false;
|
||||
|
||||
if (settings.topicPostSort === 'newest_to_oldest') {
|
||||
// `sort` qs has priority over user setting
|
||||
if (sort === 'oldest_to_newest') {
|
||||
reverse = false;
|
||||
} else if (sort === 'newest_to_oldest') {
|
||||
reverse = true;
|
||||
} else if (sort === 'most_votes') {
|
||||
reverse = true;
|
||||
set = 'tid:' + tid + ':posts:votes';
|
||||
} else if (settings.topicPostSort === 'newest_to_oldest') {
|
||||
reverse = true;
|
||||
} else if (settings.topicPostSort === 'most_votes') {
|
||||
reverse = true;
|
||||
|
||||
77
src/posts.js
77
src/posts.js
@@ -25,6 +25,7 @@ var async = require('async'),
|
||||
websockets = require('./socket.io');
|
||||
|
||||
(function(Posts) {
|
||||
require('./posts/recent')(Posts);
|
||||
require('./posts/delete')(Posts);
|
||||
|
||||
Posts.create = function(data, callback) {
|
||||
@@ -160,68 +161,6 @@ var async = require('async'),
|
||||
});
|
||||
};
|
||||
|
||||
Posts.getRecentPosts = function(uid, start, stop, term, callback) {
|
||||
var terms = {
|
||||
day: 86400000,
|
||||
week: 604800000,
|
||||
month: 2592000000
|
||||
};
|
||||
|
||||
var since = terms.day;
|
||||
if (terms[term]) {
|
||||
since = terms[term];
|
||||
}
|
||||
|
||||
var count = parseInt(stop, 10) === -1 ? stop : stop - start + 1;
|
||||
|
||||
db.getSortedSetRevRangeByScore('posts:pid', start, count, Infinity, Date.now() - since, function(err, pids) {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if (!Array.isArray(pids) || !pids.length) {
|
||||
return callback(null, []);
|
||||
}
|
||||
|
||||
privileges.posts.filter('read', pids, uid, function(err, pids) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
Posts.getPostSummaryByPids(pids, uid, {stripTags: true}, callback);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
Posts.getRecentPosterUids = function(start, end, callback) {
|
||||
db.getSortedSetRevRange('posts:pid', start, end, function(err, pids) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if (!Array.isArray(pids) || !pids.length) {
|
||||
return callback(null, []);
|
||||
}
|
||||
|
||||
pids = pids.map(function(pid) {
|
||||
return 'post:' + pid;
|
||||
});
|
||||
|
||||
db.getObjectsFields(pids, ['uid'], function(err, postData) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
postData = postData.map(function(post) {
|
||||
return post && post.uid;
|
||||
}).filter(function(value, index, array) {
|
||||
return value && array.indexOf(value) === index;
|
||||
});
|
||||
|
||||
callback(null, postData);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
Posts.getUserInfoForPosts = function(uids, callback) {
|
||||
async.parallel({
|
||||
groups: function(next) {
|
||||
@@ -532,10 +471,20 @@ var async = require('async'),
|
||||
}
|
||||
|
||||
Posts.getPidIndex = function(pid, uid, callback) {
|
||||
callback = callback || function() {};
|
||||
// Making uid optional
|
||||
if ((!uid && !callback) || typeof uid === 'function') {
|
||||
callback = uid || function() {};
|
||||
uid = undefined;
|
||||
}
|
||||
|
||||
async.parallel({
|
||||
settings: function(next) {
|
||||
user.getSettings(uid, next);
|
||||
if (uid) {
|
||||
user.getSettings(uid, next);
|
||||
} else {
|
||||
// No uid specified, so return empty object so that the check below will assume regular topic post sorting
|
||||
next(null, {});
|
||||
}
|
||||
},
|
||||
tid: function(next) {
|
||||
Posts.getPostField(pid, 'tid', next);
|
||||
|
||||
70
src/posts/recent.js
Normal file
70
src/posts/recent.js
Normal file
@@ -0,0 +1,70 @@
|
||||
'use strict';
|
||||
|
||||
var db = require('../database'),
|
||||
privileges = require('../privileges');
|
||||
|
||||
|
||||
module.exports = function(Posts) {
|
||||
var terms = {
|
||||
day: 86400000,
|
||||
week: 604800000,
|
||||
month: 2592000000
|
||||
};
|
||||
|
||||
Posts.getRecentPosts = function(uid, start, stop, term, callback) {
|
||||
var since = terms.day;
|
||||
if (terms[term]) {
|
||||
since = terms[term];
|
||||
}
|
||||
|
||||
var count = parseInt(stop, 10) === -1 ? stop : stop - start + 1;
|
||||
|
||||
db.getSortedSetRevRangeByScore('posts:pid', start, count, Infinity, Date.now() - since, function(err, pids) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if (!Array.isArray(pids) || !pids.length) {
|
||||
return callback(null, []);
|
||||
}
|
||||
|
||||
privileges.posts.filter('read', pids, uid, function(err, pids) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
Posts.getPostSummaryByPids(pids, uid, {stripTags: true}, callback);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
Posts.getRecentPosterUids = function(start, end, callback) {
|
||||
db.getSortedSetRevRange('posts:pid', start, end, function(err, pids) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if (!Array.isArray(pids) || !pids.length) {
|
||||
return callback(null, []);
|
||||
}
|
||||
|
||||
pids = pids.map(function(pid) {
|
||||
return 'post:' + pid;
|
||||
});
|
||||
|
||||
db.getObjectsFields(pids, ['uid'], function(err, postData) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
postData = postData.map(function(post) {
|
||||
return post && post.uid;
|
||||
}).filter(function(value, index, array) {
|
||||
return value && array.indexOf(value) === index;
|
||||
});
|
||||
|
||||
callback(null, postData);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
};
|
||||
@@ -49,7 +49,7 @@ var path = require('path'),
|
||||
},
|
||||
function(next) {
|
||||
var topicUrls = [];
|
||||
topics.getTopicsFromSet(0, 'topics:recent', 0, -1, function(err, data) {
|
||||
topics.getTopicsFromSet(0, 'topics:recent', 0, 49, function(err, data) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
@@ -7,15 +7,15 @@ var async = require('async'),
|
||||
|
||||
|
||||
module.exports = function(Topics) {
|
||||
var terms = {
|
||||
daily: 'day',
|
||||
weekly: 'week',
|
||||
monthly: 'month',
|
||||
yearly: 'year'
|
||||
};
|
||||
|
||||
Topics.getPopular = function(term, uid, count, callback) {
|
||||
count = parseInt(count, 10) || 20;
|
||||
var terms = {
|
||||
daily: 'day',
|
||||
weekly: 'week',
|
||||
monthly: 'month',
|
||||
yearly: 'year'
|
||||
};
|
||||
|
||||
if (term === 'alltime') {
|
||||
return getAllTimePopular(uid, count, callback);
|
||||
|
||||
@@ -5,6 +5,12 @@
|
||||
var db = require('./../database');
|
||||
|
||||
module.exports = function(Topics) {
|
||||
var terms = {
|
||||
day: 86400000,
|
||||
week: 604800000,
|
||||
month: 2592000000,
|
||||
year: 31104000000
|
||||
};
|
||||
|
||||
Topics.getLatestTopics = function(uid, start, end, term, callback) {
|
||||
Topics.getLatestTids(start, end, term, function(err, tids) {
|
||||
@@ -17,15 +23,8 @@ module.exports = function(Topics) {
|
||||
};
|
||||
|
||||
Topics.getLatestTids = function(start, end, term, callback) {
|
||||
var terms = {
|
||||
day: 86400000,
|
||||
week: 604800000,
|
||||
month: 2592000000,
|
||||
year: 31104000000
|
||||
};
|
||||
|
||||
var since = terms.day;
|
||||
if(terms[term]) {
|
||||
if (terms[term]) {
|
||||
since = terms[term];
|
||||
}
|
||||
|
||||
|
||||
@@ -28,8 +28,8 @@ module.exports = function(User) {
|
||||
settings.openOutgoingLinksInNewTab = settings.openOutgoingLinksInNewTab ? parseInt(settings.openOutgoingLinksInNewTab, 10) !== 0 : false;
|
||||
settings.dailyDigestFreq = settings.dailyDigestFreq || 'off';
|
||||
settings.usePagination = settings.usePagination ? parseInt(settings.usePagination, 10) === 1 : parseInt(meta.config.usePagination, 10) === 1;
|
||||
settings.topicsPerPage = settings.topicsPerPage ? parseInt(settings.topicsPerPage, 10) : parseInt(meta.config.topicsPerPage, 10) || 20;
|
||||
settings.postsPerPage = settings.postsPerPage ? parseInt(settings.postsPerPage, 10) : parseInt(meta.config.postsPerPage, 10) || 10;
|
||||
settings.topicsPerPage = Math.min(settings.topicsPerPage ? parseInt(settings.topicsPerPage, 10) : parseInt(meta.config.topicsPerPage, 10) || 20, 20);
|
||||
settings.postsPerPage = Math.min(settings.postsPerPage ? parseInt(settings.postsPerPage, 10) : parseInt(meta.config.postsPerPage, 10) || 10, 20);
|
||||
settings.notificationSounds = settings.notificationSounds ? parseInt(settings.notificationSounds, 10) === 1 : true;
|
||||
settings.language = settings.language || meta.config.defaultLang || 'en_GB';
|
||||
settings.topicPostSort = settings.topicPostSort || meta.config.topicPostSort || 'oldest_to_newest';
|
||||
@@ -79,8 +79,8 @@ module.exports = function(User) {
|
||||
openOutgoingLinksInNewTab: data.openOutgoingLinksInNewTab,
|
||||
dailyDigestFreq: data.dailyDigestFreq || 'off',
|
||||
usePagination: data.usePagination,
|
||||
topicsPerPage: data.topicsPerPage,
|
||||
postsPerPage: data.postsPerPage,
|
||||
topicsPerPage: Math.min(data.topicsPerPage, 20),
|
||||
postsPerPage: Math.min(data.postsPerPage, 20),
|
||||
notificationSounds: data.notificationSounds,
|
||||
language: data.language || meta.config.defaultLang,
|
||||
followTopicsOnCreate: data.followTopicsOnCreate,
|
||||
|
||||
Reference in New Issue
Block a user