removed dupe code

v1.18.x
barisusakli 10 years ago
parent c974256600
commit 7f5984d1fd

@ -91,7 +91,7 @@ define('forum/account/profile', ['forum/account/header', 'forum/infinitescroll']
$('.loading-indicator').removeClass('hidden');
infinitescroll.loadMore('user.loadMoreRecentPosts', {
infinitescroll.loadMore('posts.loadMoreUserPosts', {
after: $('.user-recent-posts').attr('data-nextstart'),
uid: theirid
}, function(data, done) {

@ -148,7 +148,7 @@ accountsController.getAccount = function(req, res, next) {
user.isFollowing(callerUID, userData.theirid, next);
},
posts: function(next) {
posts.getPostsByUid(callerUID, userData.theirid, 0, 9, next);
posts.getPostsFromSet('uid:' + userData.theirid + ':posts', callerUID, 0, 9, next);
},
signature: function(next) {
postTools.parseSignature(userData, callerUID, next);
@ -230,7 +230,7 @@ accountsController.getFavourites = function(req, res, next) {
return helpers.notAllowed(req, res);
}
posts.getFavourites(userData.uid, 0, 9, function (err, favourites) {
posts.getPostsFromSet('uid:' + userData.uid + ':favourites', callerUID, 0, 9, function(err, favourites) {
if (err) {
return next(err);
}
@ -254,8 +254,7 @@ accountsController.getPosts = function(req, res, next) {
if (!userData) {
return helpers.notFound(res);
}
posts.getPostsByUid(callerUID, userData.uid, 0, 19, function (err, userPosts) {
posts.getPostsFromSet('uid:' + userData.uid + ':posts', callerUID, 0, 19, function(err, userPosts) {
if (err) {
return next(err);
}

@ -106,35 +106,20 @@ module.exports = function(Posts) {
});
};
Posts.getPostsByUid = function(callerUid, uid, start, end, callback) {
Posts.getPostsFromSet = function(set, uid, start, end, callback) {
async.waterfall([
function(next) {
user.getPostIds(uid, start, end, next);
db.getSortedSetRevRange(set, start, end, next);
},
function(pids, next) {
privileges.posts.filter('read', pids, callerUid, next);
},
function(pids, next) {
Posts.getPostSummaryByPids(pids, callerUid, {stripTags: false}, next);
},
function(posts, next) {
next(null, {posts: posts, nextStart: end + 1});
}
], callback);
};
Posts.getFavourites = function(uid, start, end, callback) {
async.waterfall([
function(next) {
db.getSortedSetRevRange('uid:' + uid + ':favourites', start, end, next);
privileges.posts.filter('read', pids, uid, next);
},
function(pids, next) {
Posts.getPostSummaryByPids(pids, uid, {stripTags: false}, next);
},
function(posts, next) {
callback(null, {posts: posts, nextStart: end + 1});
next(null, {posts: posts, nextStart: end + 1});
}
], callback);
};
};

@ -15,6 +15,7 @@ var async = require('async'),
groups = require('../groups'),
user = require('../user'),
websockets = require('./index'),
utils = require('../../public/src/utils'),
SocketPosts = {};
@ -375,18 +376,18 @@ SocketPosts.loadMoreFavourites = function(socket, data, callback) {
var start = parseInt(data.after, 10),
end = start + 9;
posts.getFavourites(socket.uid, start, end, callback);
posts.getPostsFromSet('uid:' + socket.uid + ':posts', socket.uid, start, end, callback);
};
SocketPosts.loadMoreUserPosts = function(socket, data, callback) {
if(!data || !data.after || !data.uid) {
if(!data || !data.uid || !utils.isNumber(data.after)) {
return callback(new Error('[[error:invalid-data]]'));
}
var start = parseInt(data.after, 10),
var start = Math.max(0, parseInt(data.after, 10)),
end = start + 9;
posts.getPostsByUid(socket.uid, data.uid, start, end, callback);
posts.getPostsFromSet('uid:' + data.uid + ':posts', socket.uid, start, end, callback);
};

@ -365,17 +365,6 @@ SocketUser.loadMore = function(socket, data, callback) {
});
};
SocketUser.loadMoreRecentPosts = function(socket, data, callback) {
if(!data || !data.uid || !utils.isNumber(data.after)) {
return callback(new Error('[[error:invalid-data]]'));
}
var start = Math.max(0, parseInt(data.after, 10)),
end = start + 9;
posts.getPostsByUid(socket.uid, data.uid, start, end, callback);
};
SocketUser.setStatus = function(socket, status, callback) {
if (!socket.uid) {
return callback(new Error('[[invalid-uid]]'));

Loading…
Cancel
Save