From 83a201acce9459822cff1f4aaea4a0ccf7f01581 Mon Sep 17 00:00:00 2001 From: psychobunny Date: Mon, 10 Feb 2014 13:55:42 -0500 Subject: [PATCH 1/6] closes #918 --- public/src/forum/search.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/src/forum/search.js b/public/src/forum/search.js index 08bad46056..71ed19b69f 100644 --- a/public/src/forum/search.js +++ b/public/src/forum/search.js @@ -4,7 +4,7 @@ define(function() { Search.init = function() { var searchQuery = $('#topic-results').attr('data-search-query'); $('.search-result-text').children().each(function() { - var text = $(this).html(); + var text = $(this).text(); var regex = new RegExp(searchQuery, 'gi'); text = text.replace(regex, '' + searchQuery + ''); $(this).html(text); From 8c2611aeb5037535cc55a0ae884f2a8cfc0fbc4b Mon Sep 17 00:00:00 2001 From: psychobunny Date: Mon, 10 Feb 2014 14:05:09 -0500 Subject: [PATCH 2/6] potentially fixes #823 --- public/src/app.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/public/src/app.js b/public/src/app.js index 7f79031b20..dd738fe8eb 100644 --- a/public/src/app.js +++ b/public/src/app.js @@ -444,7 +444,11 @@ var socket, clearInterval(titleObj.interval); } titleObj.interval = setInterval(function() { - window.document.title = titleObj.titles[titleObj.titles.indexOf(window.document.title) ^ 1]; + var title = titleObj.titles[titleObj.titles.indexOf(window.document.title) ^ 1]; + + if (title) { + window.document.title = title; + } }, 2000); } else { if (titleObj.interval) { From 242927d702b5aa5c71bb72a2a37c02661e5b84d0 Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Mon, 10 Feb 2014 14:15:54 -0500 Subject: [PATCH 3/6] user selectable pagination --- public/src/forum/accountsettings.js | 5 +- public/templates/accountsettings.tpl | 27 +++++-- src/categories.js | 13 ++-- src/routes/api.js | 112 ++++++++++++++++----------- src/routes/user.js | 106 ++++++++++++------------- src/socket.io/categories.js | 14 ++-- src/socket.io/topics.js | 31 ++++---- src/socket.io/user.js | 4 +- src/topics.js | 13 ++-- src/user.js | 41 ++++++++++ 10 files changed, 228 insertions(+), 138 deletions(-) diff --git a/public/src/forum/accountsettings.js b/public/src/forum/accountsettings.js index db21bb4efa..ea906036af 100644 --- a/public/src/forum/accountsettings.js +++ b/public/src/forum/accountsettings.js @@ -7,7 +7,10 @@ define(['forum/accountheader'], function(header) { $('#submitBtn').on('click', function() { var settings = { - showemail: $('#showemailCheckBox').is(':checked') ? 1 : 0 + showemail: $('#showemailCheckBox').is(':checked') ? 1 : 0, + usePagination: $('#usePaginationCheckBox').is(':checked') ? 1 : 0, + topicsPerPage: $('#topicsPerPage').val(), + postsPerPage: $('#postsPerPage').val() }; socket.emit('user.saveSettings', settings, function(err) { diff --git a/public/templates/accountsettings.tpl b/public/templates/accountsettings.tpl index 3e8f592d5e..b6c3e62c96 100644 --- a/public/templates/accountsettings.tpl +++ b/public/templates/accountsettings.tpl @@ -6,16 +6,31 @@
-

privacy

-
- -
+
+
+

privacy

+
+ +
+
+
+
+
+
+ +
+ Topics per Page

+ Posts per Page

+
+
diff --git a/src/categories.js b/src/categories.js index 1714b6a9aa..b998701048 100644 --- a/src/categories.js +++ b/src/categories.js @@ -77,7 +77,7 @@ var db = require('./database'), } function getPageCount(next) { - Categories.getPageCount(category_id, next); + Categories.getPageCount(category_id, current_user, next); } async.parallel({ @@ -146,16 +146,19 @@ var db = require('./database'), db.getSortedSetRevRange('categories:' + cid + ':tid', start, stop, callback); }; - Categories.getPageCount = function(cid, callback) { + Categories.getPageCount = function(cid, uid, callback) { db.sortedSetCard('categories:' + cid + ':tid', function(err, topicCount) { if(err) { return callback(err); } - var topicsPerPage = parseInt(meta.config.topicsPerPage, 10); - topicsPerPage = topicsPerPage ? topicsPerPage : 20; + user.getSettings(uid, function(err, settings) { + if(err) { + return callback(err); + } - callback(null, Math.ceil(parseInt(topicCount, 10) / topicsPerPage)); + callback(null, Math.ceil(parseInt(topicCount, 10) / settings.topicsPerPage)); + }); }); }; diff --git a/src/routes/api.js b/src/routes/api.js index bb27b2c199..4b9c0d318f 100644 --- a/src/routes/api.js +++ b/src/routes/api.js @@ -52,7 +52,22 @@ var path = require('path'), config.defaultLang = meta.config.defaultLang || 'en_GB'; config.environment = process.env.NODE_ENV; - res.json(200, config); + if (!req.user) { + return res.json(200, config); + } + + if(req.user) { + user.getSettings(req.user.uid, function(err, settings) { + if(err) { + return next(err); + } + + config.usePagination = settings.usePagination; + config.topicsPerPage = settings.topicsPerPage; + config.postsPerPage = settings.postsPerPage; + res.json(200, config); + }); + } }); app.get('/home', function (req, res) { @@ -189,33 +204,38 @@ var path = require('path'), return res.send(404); } - var postsPerPage = parseInt(meta.config.postsPerPage ? meta.config.postsPerPage : 20, 10); - var start = (page - 1) * postsPerPage; - var end = start + postsPerPage - 1; + user.getSettings(uid, function(err, settings) { + if(err) { + return next(err); + } - ThreadTools.privileges(req.params.id, uid, function(err, privileges) { - if (privileges.read) { - topics.getTopicWithPosts(req.params.id, uid, start, end, false, function (err, data) { - if(err) { - return next(err); - } + var start = (page - 1) * settings.postsPerPage; + var end = start + settings.postsPerPage - 1; - if(page > data.pageCount) { - return res.send(404); - } + ThreadTools.privileges(req.params.id, uid, function(err, privileges) { + if (privileges.read) { + topics.getTopicWithPosts(req.params.id, uid, start, end, false, function (err, data) { + if(err) { + return next(err); + } - data.currentPage = page; - data.privileges = privileges; + if(page > data.pageCount) { + return res.send(404); + } - if (parseInt(data.deleted, 10) === 1 && parseInt(data.expose_tools, 10) === 0) { - return res.json(404, {}); - } + data.currentPage = page; + data.privileges = privileges; - res.json(data); - }); - } else { - res.send(403); - } + if (parseInt(data.deleted, 10) === 1 && parseInt(data.expose_tools, 10) === 0) { + return res.json(404, {}); + } + + res.json(data); + }); + } else { + res.send(403); + } + }); }); }); @@ -230,30 +250,34 @@ var path = require('path'), return res.send(404); } - var topicsPerPage = parseInt(meta.config.topicsPerPage ? meta.config.topicsPerPage : 20, 10); - var start = (page - 1) * topicsPerPage; - var end = start + topicsPerPage - 1; + user.getSettings(uid, function(err, settings) { + if(err) { + return next(err); + } - // Category Whitelisting - categoryTools.privileges(req.params.id, uid, function(err, privileges) { - if (!err && privileges.read) { - categories.getCategoryById(req.params.id, start, end, uid, function (err, data) { - if(err) { - return next(err); - } + var start = (page - 1) * settings.topicsPerPage; + var end = start + settings.topicsPerPage - 1; - data.currentPage = page; - data.privileges = privileges; + categoryTools.privileges(req.params.id, uid, function(err, privileges) { + if (!err && privileges.read) { + categories.getCategoryById(req.params.id, start, end, uid, function (err, data) { + if(err) { + return next(err); + } - if (data && parseInt(data.disabled, 10) === 0) { - res.json(data); - } else { - next(); - } - }, req.params.id, uid); - } else { - res.send(403); - } + data.currentPage = page; + data.privileges = privileges; + + if (data && parseInt(data.disabled, 10) === 0) { + res.json(data); + } else { + next(); + } + }, req.params.id, uid); + } else { + res.send(403); + } + }); }); }); diff --git a/src/routes/user.js b/src/routes/user.js index 61dc5a26af..07a6947e68 100644 --- a/src/routes/user.js +++ b/src/routes/user.js @@ -270,40 +270,43 @@ var fs = require('fs'), var callerUID = req.user ? req.user.uid : '0'; user.getUidByUserslug(req.params.userslug, function (err, uid) { + if (err) { + return next(err); + } + if (!uid) { - res.json(404, { + return res.json(404, { error: 'User not found!' }); - return; } if (uid != callerUID || callerUID == '0') { - res.json(403, { + return res.json(403, { error: 'Not allowed!' }); - return; } - - user.getUserFields(uid, ['username', 'userslug', 'showemail'], function (err, userData) { - if (err) + user.getUserFields(uid, ['username', 'userslug'], function (err, userData) { + if (err) { return next(err); + } - if (userData) { - if (userData.showemail && parseInt(userData.showemail, 10) === 1) { - userData.showemail = "checked"; - } else { - userData.showemail = ""; + if(!userData) { + return res.json(404, { + error: 'User not found!' + }); + } + + user.getSettings(uid, function(err, settings) { + if(err) { + return next(err); } userData.theirid = uid; userData.yourid = callerUID; + userData.settings = settings; res.json(userData); - } else { - res.json(404, { - error: 'User not found!' - }); - } + }); }); }); }); @@ -313,17 +316,15 @@ var fs = require('fs'), user.getUidByUserslug(req.params.userslug, function (err, uid) { if (!uid) { - res.json(404, { + return res.json(404, { error: 'User not found!' }); - return; } if (uid != callerUID || callerUID == '0') { - res.json(403, { + return res.json(403, { error: 'Not allowed!' }); - return; } user.getUserFields(uid, ['username', 'userslug'], function (err, userData) { @@ -331,24 +332,24 @@ var fs = require('fs'), return next(err); } - if (userData) { - posts.getFavourites(uid, 0, 9, function (err, favourites) { - if (err) { - return next(err); - } - - userData.theirid = uid; - userData.yourid = callerUID; - userData.posts = favourites.posts; - userData.nextStart = favourites.nextStart; - - res.json(userData); - }); - } else { - res.json(404, { + if (!userData) { + return res.json(404, { error: 'User not found!' }); } + + posts.getFavourites(uid, 0, 9, function (err, favourites) { + if (err) { + return next(err); + } + + userData.theirid = uid; + userData.yourid = callerUID; + userData.posts = favourites.posts; + userData.nextStart = favourites.nextStart; + + res.json(userData); + }); }); }); }); @@ -358,10 +359,9 @@ var fs = require('fs'), user.getUidByUserslug(req.params.userslug, function (err, uid) { if (!uid) { - res.json(404, { + return res.json(404, { error: 'User not found!' }); - return; } user.getUserFields(uid, ['username', 'userslug'], function (err, userData) { @@ -369,24 +369,24 @@ var fs = require('fs'), return next(err); } - if (userData) { - 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; - - res.json(userData); - }); - } else { - res.json(404, { + if (!userData) { + return res.json(404, { error: 'User not found!' }); } + + 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; + + res.json(userData); + }); }); }); }); diff --git a/src/socket.io/categories.js b/src/socket.io/categories.js index ddea33d2f3..2e08d5bb54 100644 --- a/src/socket.io/categories.js +++ b/src/socket.io/categories.js @@ -1,5 +1,6 @@ var categories = require('../categories'), meta = require('./../meta'), + user = require('./../user'), SocketCategories = {}; @@ -16,16 +17,17 @@ SocketCategories.loadMore = function(socket, data, callback) { return callback(new Error('invalid data')); } - var topicsPerPage = parseInt(meta.config.topicsPerPage, 10) || 20; + user.getSettings(socket.uid, function(err, settings) { - var start = parseInt(data.after, 10), - end = start + topicsPerPage - 1; + var start = parseInt(data.after, 10), + end = start + settings.topicsPerPage - 1; - categories.getCategoryTopics(data.cid, start, end, socket.uid, callback); + categories.getCategoryTopics(data.cid, start, end, socket.uid, callback); + }); }; SocketCategories.getPageCount = function(socket, cid, callback) { - categories.getPageCount(cid, callback); -} + categories.getPageCount(cid, socket.uid, callback); +}; module.exports = SocketCategories; \ No newline at end of file diff --git a/src/socket.io/topics.js b/src/socket.io/topics.js index 381cbc13ea..d78968c512 100644 --- a/src/socket.io/topics.js +++ b/src/socket.io/topics.js @@ -1,6 +1,7 @@ var topics = require('../topics'), threadTools = require('../threadTools'), index = require('./index'), + user = require('../user'), async = require('async'), @@ -233,21 +234,21 @@ SocketTopics.loadMore = function(socket, data, callback) { return callback(new Error('invalid data')); } - var postsPerPage = parseInt(meta.config.postsPerPage, 10); - postsPerPage = postsPerPage ? postsPerPage : 20; + user.getSettings(socket.uid, function(err, settings) { - var start = parseInt(data.after, 10), - end = start + postsPerPage - 1; - - async.parallel({ - posts: function(next) { - topics.getTopicPosts(data.tid, start, end, socket.uid, next); - }, - privileges: function(next) { - threadTools.privileges(data.tid, socket.uid, next); - } - }, function(err, results) { - callback(err, results); + var start = parseInt(data.after, 10), + end = start + settings.postsPerPage - 1; + + async.parallel({ + posts: function(next) { + topics.getTopicPosts(data.tid, start, end, socket.uid, next); + }, + privileges: function(next) { + threadTools.privileges(data.tid, socket.uid, next); + } + }, function(err, results) { + callback(err, results); + }); }); }; @@ -286,7 +287,7 @@ SocketTopics.loadMoreFromSet = function(socket, data, callback) { SocketTopics.getPageCount = function(socket, tid, callback) { - topics.getPageCount(tid, callback); + topics.getPageCount(tid, socket.uid, callback); }; module.exports = SocketTopics; \ No newline at end of file diff --git a/src/socket.io/user.js b/src/socket.io/user.js index f560151512..c9a9bed657 100644 --- a/src/socket.io/user.js +++ b/src/socket.io/user.js @@ -135,9 +135,7 @@ SocketUser.unfollow = function(socket, data, callback) { SocketUser.saveSettings = function(socket, data, callback) { if (socket.uid && data) { - user.setUserFields(socket.uid, { - showemail: data.showemail - }, callback); + user.saveSettings(socket.uid, data, callback); } }; diff --git a/src/topics.js b/src/topics.js index 79a2423252..9c4fb78010 100644 --- a/src/topics.js +++ b/src/topics.js @@ -391,16 +391,19 @@ var async = require('async'), }); } - Topics.getPageCount = function(tid, callback) { + Topics.getPageCount = function(tid, uid, callback) { db.sortedSetCard('tid:' + tid + ':posts', function(err, postCount) { if(err) { return callback(err); } - var postsPerPage = parseInt(meta.config.postsPerPage, 10); - postsPerPage = postsPerPage ? postsPerPage : 20; + user.getSettings(uid, function(err, settings) { + if(err) { + return callback(err); + } - callback(null, Math.ceil(parseInt(postCount, 10) / postsPerPage)); + callback(null, Math.ceil(parseInt(postCount, 10) / settings.postsPerPage)); + }); }); } @@ -808,7 +811,7 @@ var async = require('async'), } function getPageCount(next) { - Topics.getPageCount(tid, next); + Topics.getPageCount(tid, current_user, next); } async.parallel([getTopicData, getTopicPosts, getPrivileges, getCategoryData, getPageCount], function(err, results) { diff --git a/src/user.js b/src/user.js index 846f6f5486..26d0a19f98 100644 --- a/src/user.js +++ b/src/user.js @@ -184,6 +184,47 @@ var bcrypt = require('bcryptjs'), }); }; + User.getSettings = function(uid, callback) { + function sendDefaultSettings() { + callback(null, { + showemail: false, + usePagination: parseInt(meta.config.usePagination, 10) !== 0, + topicsPerPage: parseInt(meta.config.topicsPerPage, 10) || 20, + postsPerPage: parseInt(meta.config.postsPerPage, 10) || 10 + }); + } + + if(!parseInt(uid, 10)) { + return sendDefaultSettings(); + } + + db.getObject('user:' + uid + ':settings', function(err, settings) { + if(err) { + return callback(err); + } + + if(!settings) { + return sendDefaultSettings(); + } + + settings.showemail = parseInt(settings.showemail, 10) !== 0; + settings.usePagination = parseInt(settings.usePagination, 10) !== 0; + settings.topicsPerPage = parseInt(settings.topicsPerPage, 10); + settings.postsPerPage = parseInt(settings.postsPerPage, 10); + + callback(null, settings); + }); + } + + User.saveSettings = function(uid, data, callback) { + db.setObject('user:' + uid + ':settings', { + showemail: data.showemail || 0, + usePagination: data.usePagination || 0, + topicsPerPage: data.topicsPerPage || 20, + postsPerPage: data.postsPerPage || 10 + }, callback); + } + User.updateProfile = function(uid, data, callback) { var fields = ['username', 'email', 'fullname', 'website', 'location', 'birthday', 'signature']; From b75877d61f4028d75e1b4e1d3c4704be8419ddf6 Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Mon, 10 Feb 2014 14:21:45 -0500 Subject: [PATCH 4/6] some language strings --- public/language/en_GB/global.json | 4 +++- public/language/en_GB/user.json | 6 +++++- public/templates/accountsettings.tpl | 13 +++++++------ 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/public/language/en_GB/global.json b/public/language/en_GB/global.json index 910bde29f4..40e0f8ed98 100644 --- a/public/language/en_GB/global.json +++ b/public/language/en_GB/global.json @@ -62,5 +62,7 @@ "away": "Away", "dnd": "Do not Disturb", "invisible": "Invisible", - "offline": "Offline" + "offline": "Offline", + + "privacy": "Privacy" } diff --git a/public/language/en_GB/user.json b/public/language/en_GB/user.json index 1526809f45..210d9da4d9 100644 --- a/public/language/en_GB/user.json +++ b/public/language/en_GB/user.json @@ -40,5 +40,9 @@ "has_no_posts": "This user didn't post anything yet.", "email_hidden": "Email Hidden", - "hidden": "hidden" + "hidden": "hidden", + + "paginate_description" : "Paginate topics and posts instead of using infinite scroll.", + "topics_per_page": "Topics per Page", + "posts_per_page": "Posts per Page" } diff --git a/public/templates/accountsettings.tpl b/public/templates/accountsettings.tpl index b6c3e62c96..98d32c2054 100644 --- a/public/templates/accountsettings.tpl +++ b/public/templates/accountsettings.tpl @@ -8,12 +8,14 @@
-

privacy

+ + [[user:topics_per_page]]

+ [[user:posts_per_page]]

@@ -21,18 +23,17 @@
+

[[global:privacy]]

- - Topics per Page

- Posts per Page

+ From 34338c3265794041472936bc8c1b1635c24caa39 Mon Sep 17 00:00:00 2001 From: Maciej Benke Date: Mon, 10 Feb 2014 20:35:35 +0100 Subject: [PATCH 5/6] No point in having anonymous users as a link. --- public/templates/users.tpl | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/public/templates/users.tpl b/public/templates/users.tpl index b48c8ce3e0..5f02ada4cf 100644 --- a/public/templates/users.tpl +++ b/public/templates/users.tpl @@ -41,9 +41,7 @@
  • - - - +