diff --git a/public/src/forum/account/profile.js b/public/src/forum/account/profile.js index a7a522f220..2d273a33ca 100644 --- a/public/src/forum/account/profile.js +++ b/public/src/forum/account/profile.js @@ -2,7 +2,7 @@ /* globals define, ajaxify, app, utils, socket, translator*/ -define('forum/account/profile', ['forum/account/header'], function(header) { +define('forum/account/profile', ['forum/account/header', 'forum/infinitescroll'], function(header, infinitescroll) { var Account = {}, yourid, theirid, @@ -39,6 +39,8 @@ define('forum/account/profile', ['forum/account/header'], function(header) { if (yourid !== theirid) { socket.emit('user.increaseViewCount', theirid); } + + infinitescroll.init(loadMoreTopics); }; function processPage() { @@ -82,5 +84,44 @@ define('forum/account/profile', ['forum/account/header'], function(header) { } + function loadMoreTopics(direction) { + if(direction < 0 || !$('.user-recent-posts').length) { + return; + } + + $('.loading-indicator').removeClass('hidden'); + + infinitescroll.loadMore('user.loadMoreRecentPosts', { + after: $('.user-recent-posts').attr('data-nextstart'), + uid: theirid + }, function(data, done) { + if (data.posts && data.posts.length) { + onPostsLoaded(data.posts, done); + $('.user-recent-posts').attr('data-nextstart', data.nextStart); + } else { + done(); + } + $('.loading-indicator').addClass('hidden'); + }); + } + + function onPostsLoaded(posts, callback) { + posts = posts.filter(function(post) { + return !$('.user-recent-posts div[data-pid=' + post.pid + ']').length; + }); + + if (!posts.length) { + return callback(); + } + + infinitescroll.parseAndTranslate('account/profile', 'posts', {posts: posts}, function(html) { + + $('.user-recent-posts .loading-indicator').before(html); + html.find('span.timeago').timeago(); + + callback(); + }); + } + return Account; }); diff --git a/public/src/forum/recent.js b/public/src/forum/recent.js index f3e51686aa..78cbff6c14 100644 --- a/public/src/forum/recent.js +++ b/public/src/forum/recent.js @@ -122,7 +122,7 @@ define('forum/recent', ['forum/infinitescroll'], function(infinitescroll) { }); if (!topics.length) { - callback(); + return callback(); } infinitescroll.parseAndTranslate(templateName, 'topics', {topics: topics, showSelect: showSelect}, function(html) { diff --git a/src/controllers/accounts.js b/src/controllers/accounts.js index 616cfc50d3..fe40a3ea9a 100644 --- a/src/controllers/accounts.js +++ b/src/controllers/accounts.js @@ -166,6 +166,7 @@ accountsController.getAccount = function(req, res, next) { return p && parseInt(p.deleted, 10) !== 1; }); + userData.nextStart = results.posts.nextStart; userData.isFollowing = results.isFollowing; if (!userData.profileviews) { diff --git a/src/socket.io/user.js b/src/socket.io/user.js index 44d6f4b41c..81667079b9 100644 --- a/src/socket.io/user.js +++ b/src/socket.io/user.js @@ -5,6 +5,7 @@ var async = require('async'), user = require('../user'), groups = require('../groups'), topics = require('../topics'), + posts = require('../posts'), notifications = require('../notifications'), messaging = require('../messaging'), plugins = require('../plugins'), @@ -329,6 +330,16 @@ 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) {