Node.js based forum software built for the modern web
removed dupe code
barisusakli7f5984d1fd60
diff --git a/public/src/client/account/profile.js b/public/src/client/account/profile.jsindex 2d273a33ca..2c3db09a07 100644--- a/public/src/client/account/profile.js+++ b/public/src/client/account/profile.js@@ -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) {diff --git a/src/controllers/accounts.js b/src/controllers/accounts.jsindex d79af62f7e..96d83a5a07 100644--- a/src/controllers/accounts.js+++ b/src/controllers/accounts.js@@ -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);}diff --git a/src/posts/user.js b/src/posts/user.jsindex 4fbaa96654..3b6f2e9e20 100644--- a/src/posts/user.js+++ b/src/posts/user.js@@ -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);};-};diff --git a/src/socket.io/posts.js b/src/socket.io/posts.jsindex a93b64e248..b84a45cd33 100644--- a/src/socket.io/posts.js+++ b/src/socket.io/posts.js@@ -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);};diff --git a/src/socket.io/user.js b/src/socket.io/user.jsindex c02d8ec8da..c4290d53f3 100644--- a/src/socket.io/user.js+++ b/src/socket.io/user.js@@ -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]]'));