Merge branch 'master' of github.com:designcreateplay/NodeBB

v1.18.x
Julian Lam 11 years ago
commit 25b48c43eb

@ -1,9 +1,51 @@
define(['forum/accountheader'], function(header) {
var AccountHeader = {};
var Favourites = {},
loadingMore = false;
AccountHeader.init = function() {
Favourites.init = function() {
header.init();
app.enableInfiniteLoading(function() {
if(!loadingMore) {
loadMore();
}
});
};
return AccountHeader;
function loadMore() {
loadingMore = true;
socket.emit('posts.loadMoreFavourites', {
after: $('.user-favourite-posts').attr('data-nextstart')
}, function(err, data) {
if(err) {
return app.alertError(err.message);
}
if (data.posts && data.posts.length) {
onTopicsLoaded(data.posts);
$('.user-favourite-posts').attr('data-nextstart', data.nextStart);
}
loadingMore = false;
});
}
function onTopicsLoaded(posts) {
var html = templates.prepare(templates['favourites'].blocks['posts']).parse({
posts: posts
});
translator.translate(html, function(translatedHTML) {
$('#category-no-topics').remove();
html = $(translatedHTML);
$('.user-favourite-posts').append(html);
$('span.timeago').timeago();
app.createUserTooltips();
app.makeNumbersHumanReadable(html.find('.human-readable-number'));
});
}
return Favourites;
});

@ -6,12 +6,12 @@
</span>
</div>
<!-- IF show_nofavourites -->
<!-- IF !posts.length -->
<div id="no-favourites-notice" class="alert alert-warning">[[topic:favourites.has_no_favourites]]</div>
<!-- ENDIF show_nofavourites -->
<!-- ENDIF !posts.length -->
<div class="row">
<div class="col-md-12 user-favourite-posts">
<div class="col-md-12 user-favourite-posts" data-nextstart="{nextStart}">
<!-- BEGIN posts -->
<div class="topic-row panel panel-default clearfix">
<div class="panel-body">

@ -232,12 +232,15 @@ var db = require('./database'),
Posts.getPostSummaryByPids = function(pids, stripTags, callback) {
var posts = [];
function getPostSummary(pid, callback) {
async.waterfall([
function(next) {
Posts.getPostFields(pid, ['pid', 'tid', 'content', 'uid', 'timestamp', 'deleted'], function(err, postData) {
if(err) {
return next(err);
}
if (parseInt(postData.deleted, 10) === 1) {
return callback(null);
} else {
@ -287,20 +290,19 @@ var db = require('./database'),
next(null, postData);
}
}
], function(err, postData) {
if (!err) {
posts.push(postData);
}
callback(err);
});
], callback);
}
async.eachSeries(pids, getPostSummary, function(err) {
if (!err) {
callback(null, posts);
} else {
callback(err, null);
async.map(pids, getPostSummary, function(err, posts) {
if(err) {
return callback(err);
}
posts = posts.filter(function(p) {
return p;
});
callback(null, posts);
});
};
@ -458,13 +460,33 @@ var db = require('./database'),
async.each(pids, reIndex, callback);
}
Posts.getFavourites = function(uid, callback) {
db.getSortedSetRevRange('uid:' + uid + ':favourites', 0, -1, function(err, pids) {
Posts.getFavourites = function(uid, start, end, callback) {
db.getSortedSetRevRange('uid:' + uid + ':favourites', start, end, function(err, pids) {
if (err) {
return callback(err, null);
return callback(err);
}
Posts.getPostSummaryByPids(pids, false, callback);
Posts.getPostSummaryByPids(pids, false, function(err, posts) {
if(err) {
return callback(err);
}
if(!posts || !posts.length) {
return callback(null, { posts: [], nextStart: 0});
}
db.sortedSetRevRank('uid:' + uid + ':favourites', posts[posts.length - 1].pid, function(err, rank) {
if(err) {
return calllback(err);
}
var favourites = {
posts: posts,
nextStart: parseInt(rank, 10) + 1
};
callback(null, favourites);
});
});
});
}

@ -344,12 +344,14 @@ var fs = require('fs'),
}
if (userData) {
posts.getFavourites(uid, function (err, posts) {
posts.getFavourites(uid, 0, 9, function (err, favourites) {
if (err) {
return next(err);
}
userData.posts = posts;
userData.show_nofavourites = posts.length === 0;
userData.posts = favourites.posts;
userData.nextStart = favourites.nextStart;
res.json(userData);
});
} else {

@ -247,4 +247,15 @@ SocketPosts.flag = function(socket, pid, callback) {
], callback);
}
SocketPosts.loadMoreFavourites = function(socket, data, callback) {
if(!data || !data.after) {
return callback(new Error('invalid data'));
}
var start = parseInt(data.after, 10),
end = start + 9;
posts.getFavourites(socket.uid, start, end, callback);
};
module.exports = SocketPosts;
Loading…
Cancel
Save