(drunk) not even done yet
This commit is contained in:
barisusakli
2014-08-16 21:33:42 -04:00
parent 3011491863
commit ca90afd544
14 changed files with 178 additions and 108 deletions

View File

@@ -70,10 +70,6 @@ SocketTopics.postcount = function(socket, tid, callback) {
topics.getTopicField(tid, 'postcount', callback);
};
SocketTopics.lastPostIndex = function(socket, tid, callback) {
db.sortedSetCard('tid:' + tid + ':posts', callback);
};
SocketTopics.increaseViewCount = function(socket, tid) {
topics.increaseViewCount(tid);
};
@@ -421,6 +417,9 @@ SocketTopics.loadMore = function(socket, data, callback) {
},
privileges: function(next) {
privileges.topics.get(data.tid, socket.uid, next);
},
postCount: function(next) {
topics.getPostCount(data.tid, next);
}
}, function(err, results) {
if (err) {
@@ -431,19 +430,23 @@ SocketTopics.loadMore = function(socket, data, callback) {
return callback(new Error('[[error:no-privileges]]'));
}
var start = Math.max(parseInt(data.after, 10) - 1, 0),
end = start + results.settings.postsPerPage - 1;
var set = 'tid:' + data.tid + ':posts',
reverse = false;
reverse = false,
start = Math.max(parseInt(data.after, 10) - 1, 0);
if (results.settings.topicPostSort === 'newest_to_oldest') {
reverse = true;
data.after = results.postCount - data.after;
start = Math.max(parseInt(data.after, 10), 0);
} else if (results.settings.topicPostSort === 'most_votes') {
reverse = true;
data.after = results.postCount - data.after;
start = Math.max(parseInt(data.after, 10), 0);
set = 'tid:' + data.tid + ':posts:votes';
}
var end = start + results.settings.postsPerPage - 1;
async.parallel({
posts: function(next) {
topics.getTopicPosts(data.tid, set, start, end, socket.uid, reverse, next);