diff --git a/public/language/en_GB/user.json b/public/language/en_GB/user.json
index f89081ba14..d7f2d83b2d 100644
--- a/public/language/en_GB/user.json
+++ b/public/language/en_GB/user.json
@@ -49,6 +49,7 @@
"has_no_follower": "This user doesn't have any followers :(",
"follows_no_one": "This user isn't following anyone :(",
"has_no_posts": "This user didn't post anything yet.",
+ "has_no_topics": "This user didn't post any topics yet.",
"email_hidden": "Email Hidden",
"hidden": "hidden",
diff --git a/public/src/forum/accountheader.js b/public/src/forum/accountheader.js
index 96f73c9fe0..5ef0233fbb 100644
--- a/public/src/forum/accountheader.js
+++ b/public/src/forum/accountheader.js
@@ -3,7 +3,6 @@ define(function() {
AccountHeader.init = function() {
-
AccountHeader.createMenu();
hideLinks();
@@ -18,6 +17,7 @@ define(function() {
[[user:settings]]\
[[user:favourites]]\
[[global:posts]]\
+ [[topic:topics]]\
[[user:followers]]\
[[user:following]]\
[[user:edit]]\
diff --git a/public/src/forum/accountposts.js b/public/src/forum/accountposts.js
index 1403b606fe..c1e304c3b7 100644
--- a/public/src/forum/accountposts.js
+++ b/public/src/forum/accountposts.js
@@ -1,6 +1,6 @@
'use strict';
-/* globals define, app, socket, ajaxify, templates, translator */
+/* globals define, app, socket, ajaxify, templates, translator, utils */
define(['forum/accountheader'], function(header) {
var AccountPosts = {},
@@ -29,7 +29,7 @@ define(['forum/accountheader'], function(header) {
}
if (data.posts && data.posts.length) {
- onTopicsLoaded(data.posts);
+ onPostsLoaded(data.posts);
$('.user-favourite-posts').attr('data-nextstart', data.nextStart);
}
@@ -37,17 +37,16 @@ define(['forum/accountheader'], function(header) {
});
}
- function onTopicsLoaded(posts) {
+ function onPostsLoaded(posts) {
ajaxify.loadTemplate('accountposts', function(accountposts) {
var html = templates.parse(templates.getBlock(accountposts, 'posts'), {posts: posts});
translator.translate(html, function(translatedHTML) {
- $('#category-no-topics').remove();
html = $(translatedHTML);
html.find('img').addClass('img-responsive');
$('.user-favourite-posts').append(html);
- $('span.timeago').timeago();
+ html.find('span.timeago').timeago();
app.createUserTooltips();
utils.makeNumbersHumanReadable(html.find('.human-readable-number'));
});
diff --git a/public/src/forum/accounttopics.js b/public/src/forum/accounttopics.js
new file mode 100644
index 0000000000..3b4aa99b01
--- /dev/null
+++ b/public/src/forum/accounttopics.js
@@ -0,0 +1,55 @@
+'use strict';
+
+/* globals define, app, socket, ajaxify, templates, translator, utils */
+
+define(['forum/accountheader'], function(header) {
+ var AccountTopics = {},
+ loadingMore = false;
+
+ AccountTopics.init = function() {
+ header.init();
+
+ app.enableInfiniteLoading(function() {
+ if(!loadingMore) {
+ loadMore();
+ }
+ });
+ };
+
+ function loadMore() {
+ loadingMore = true;
+ socket.emit('topics.loadMoreFromSet', {
+ set: 'uid:' + $('.account-username-box').attr('data-uid') + ':topics',
+ after: $('.user-topics').attr('data-nextstart')
+ }, function(err, data) {
+ if(err) {
+ return app.alertError(err.message);
+ }
+
+ if (data.topics && data.topics.length) {
+ onTopicsLoaded(data.topics);
+ $('.user-topics').attr('data-nextstart', data.nextStart);
+ }
+
+ loadingMore = false;
+ });
+ }
+
+ function onTopicsLoaded(topics) {
+ ajaxify.loadTemplate('accounttopics', function(accounttopics) {
+ var html = templates.parse(templates.getBlock(accounttopics, 'topics'), {topics: topics});
+
+ translator.translate(html, function(translatedHTML) {
+ $('#category-no-topics').remove();
+
+ html = $(translatedHTML);
+ $('#topics-container').append(html);
+ html.find('span.timeago').timeago();
+ app.createUserTooltips();
+ utils.makeNumbersHumanReadable(html.find('.human-readable-number'));
+ });
+ });
+ }
+
+ return AccountTopics;
+});
\ No newline at end of file
diff --git a/src/controllers/accounts.js b/src/controllers/accounts.js
index 396d4ee86d..369449e9aa 100644
--- a/src/controllers/accounts.js
+++ b/src/controllers/accounts.js
@@ -10,6 +10,7 @@ var fs = require('fs'),
user = require('./../user'),
posts = require('./../posts'),
+ topics = require('./../topics'),
postTools = require('../postTools'),
utils = require('./../../public/src/utils'),
meta = require('./../meta'),
@@ -235,36 +236,68 @@ accountsController.getFavourites = function(req, res, next) {
accountsController.getPosts = function(req, res, next) {
var callerUID = req.user ? parseInt(req.user.uid, 10) : 0;
- user.getUidByUserslug(req.params.userslug, function (err, uid) {
- if (!uid) {
+ getBaseUser(req.params.userslug, function(err, userData) {
+ if (err) {
+ return next(err);
+ }
+
+ if (!userData) {
return userNotFound();
}
- user.getUserFields(uid, ['username', 'userslug'], function (err, userData) {
+ posts.getPostsByUid(callerUID, userData.uid, 0, 19, function (err, userPosts) {
if (err) {
return next(err);
}
- if (!userData) {
- return userNotFound();
+ userData.theirid = userData.uid;
+ userData.yourid = callerUID;
+ userData.posts = userPosts.posts;
+ userData.nextStart = userPosts.nextStart;
+
+ res.render('accountposts', userData);
+ });
+ });
+};
+
+accountsController.getTopics = function(req, res, next) {
+ var callerUID = req.user ? parseInt(req.user.uid, 10) : 0;
+
+ getBaseUser(req.params.userslug, function(err, userData) {
+ if (err) {
+ return next(err);
+ }
+
+ if (!userData) {
+ return userNotFound();
+ }
+
+ var set = 'uid:' + userData.uid + ':topics';
+ topics.getTopicsFromSet(callerUID, set, 0, 19, function(err, userTopics) {
+ if(err) {
+ return next(err);
}
- posts.getPostsByUid(callerUID, uid, 0, 19, function (err, userPosts) {
- if (err) {
- return next(err);
- }
- userData.uid = uid;
- userData.theirid = uid;
- userData.yourid = callerUID;
- userData.posts = userPosts.posts;
- userData.nextStart = userPosts.nextStart;
+ userData.theirid = userData.uid;
+ userData.yourid = callerUID;
+ userData.topics = userTopics.topics;
+ userData.nextStart = userTopics.nextStart;
- res.render('accountposts', userData);
- });
+ res.render('accounttopics', userData);
});
});
};
+function getBaseUser(userslug, callback) {
+ user.getUidByUserslug(userslug, function (err, uid) {
+ if (err || !uid) {
+ return callback(err);
+ }
+
+ user.getUserFields(uid, ['uid', 'username', 'userslug'], callback);
+ });
+}
+
accountsController.accountEdit = function(req, res, next) {
var callerUID = req.user ? parseInt(req.user.uid, 10) : 0;
diff --git a/src/routes/index.js b/src/routes/index.js
index bdb3c2323d..1f89c6d4a9 100644
--- a/src/routes/index.js
+++ b/src/routes/index.js
@@ -86,6 +86,9 @@ function accountRoutes(app, middleware, controllers) {
app.get('/user/:userslug/posts', middleware.buildHeader, middleware.checkGlobalPrivacySettings, controllers.accounts.getPosts);
app.get('/api/user/:userslug/posts', middleware.checkGlobalPrivacySettings, controllers.accounts.getPosts);
+ app.get('/user/:userslug/topics', middleware.buildHeader, middleware.checkGlobalPrivacySettings, controllers.accounts.getTopics);
+ app.get('/api/user/:userslug/topics', middleware.checkGlobalPrivacySettings, controllers.accounts.getTopics);
+
app.get('/user/:userslug/edit', middleware.buildHeader, middleware.checkGlobalPrivacySettings, middleware.checkAccountPermissions, controllers.accounts.accountEdit);
app.get('/api/user/:userslug/edit', middleware.checkGlobalPrivacySettings, middleware.checkAccountPermissions, controllers.accounts.accountEdit);