scroll to posts

This commit is contained in:
Baris Usakli
2013-08-01 16:11:00 -04:00
parent dbfd3c19a1
commit 720dd9e960
7 changed files with 97 additions and 52 deletions

View File

@@ -24,9 +24,7 @@ var RDB = require('./redis.js'),
callback(posts);
});
} else {
callback({
error: 'no-posts'
});
callback([]);
}
});
}

View File

@@ -41,7 +41,9 @@ marked.setOptions({
Topics.getTopicPosts = function(tid, start, end, current_user, callback) {
posts.getPostsByTid(tid, start, end, function(postData) {
if(Array.isArray(postData) && !postData.length)
return callback([]);
function getFavouritesData(next) {
var pids = [];
for(var i=0; i<postData.length; ++i)
@@ -78,7 +80,7 @@ marked.setOptions({
postData[i].fav_star_class = fav_data[postData[i].pid] ? 'icon-star' : 'icon-star-empty';
postData[i]['display_moderator_tools'] = (postData[i].uid == current_user || privileges.editable) ? 'show' : 'none';
}
callback(postData);
});
});
@@ -279,8 +281,7 @@ marked.setOptions({
}
function getTopicPosts(next) {
Topics.getTopicPosts(tid, 0, -1, current_user, function(topicPosts, privileges) {
Topics.getTopicPosts(tid, 0, 10, current_user, function(topicPosts, privileges) {
next(null, topicPosts);
});
}

View File

@@ -556,14 +556,15 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
}
});
socket.on('api:topic.loadMore', function(data) {
socket.on('api:topic.loadMore', function(data, callback) {
var start = data.after,
end = start + 10;
topics.getTopicPosts(data.tid, start, end, uid, function(posts) {
io.sockets.in('topic_' + data.tid).emit('event:new_post', {
posts: posts
});
//io.sockets.in('topic_' + data.tid).emit('event:new_post', {
// posts: posts
//});
callback({posts:posts});
});
});