Merge branch 'master' of github.com:designcreateplay/NodeBB

v1.18.x
Julian Lam 11 years ago
commit 4429014d2f

@ -62,5 +62,7 @@
"away": "Away",
"dnd": "Do not Disturb",
"invisible": "Invisible",
"offline": "Offline"
"offline": "Offline",
"privacy": "Privacy"
}

@ -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"
}

@ -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) {

@ -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) {

@ -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, '<span class="label label-success">' + searchQuery + '</span>');
$(this).html(text);

@ -6,18 +6,34 @@
<div class="row">
<div class="col-md-6">
<h4>privacy</h4>
<div class="panel panel-default">
<div class="panel-body">
<div class="checkbox">
<label>
<input id="showemailCheckBox" type="checkbox" {showemail}> [[user:show_email]]
<input id="usePaginationCheckBox" type="checkbox" <!-- IF settings.usePagination -->checked<!-- ENDIF settings.usePagination -->> <strong>[[user:paginate_description]]</strong>
</label>
</div>
<strong>[[user:topics_per_page]]</strong><br /> <input id="topicsPerPage" type="text" class="form-control" value="{settings.topicsPerPage}"><br />
<strong>[[user:posts_per_page]]</strong><br /> <input id="postsPerPage" type="text" class="form-control" value="{settings.postsPerPage}"><br />
</div>
</div>
</div>
<div class="col-md-6">
<div class="panel panel-default">
<div class="panel-body">
<h4>[[global:privacy]]</h4>
<div class="checkbox">
<label>
<input id="showemailCheckBox" type="checkbox" <!-- IF settings.showemail -->checked<!-- ENDIF settings.showemail --> > [[user:show_email]]
</label>
</div>
</div>
</div>
</div>
</div>
<div class="form-actions">
<a id="submitBtn" href="#" class="btn btn-primary">[[global:save_changes]]</a>
</div>

@ -41,9 +41,7 @@
</li>
<!-- END users -->
<li class="users-box {show_anon} anon-user">
<a href="#">
<img src="https://secure.gravatar.com/avatar/" class="img-thumbnail"/>
</a>
<br/>
<div class="user-info">
<span id="online_anon_count">{anonymousUserCount}</span>

@ -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));
});
});
};

@ -52,8 +52,23 @@ var path = require('path'),
config.defaultLang = meta.config.defaultLang || 'en_GB';
config.environment = process.env.NODE_ENV;
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) {
var uid = (req.user) ? req.user.uid : 0;
@ -189,9 +204,13 @@ 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);
}
var start = (page - 1) * settings.postsPerPage;
var end = start + settings.postsPerPage - 1;
ThreadTools.privileges(req.params.id, uid, function(err, privileges) {
if (privileges.read) {
@ -218,6 +237,7 @@ var path = require('path'),
}
});
});
});
app.get('/category/:id/:slug?', function (req, res, next) {
var uid = (req.user) ? req.user.uid : 0;
@ -230,11 +250,14 @@ 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);
}
var start = (page - 1) * settings.topicsPerPage;
var end = start + settings.topicsPerPage - 1;
// 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) {
@ -256,6 +279,7 @@ var path = require('path'),
}
});
});
});
app.get('/recent/:term?', function (req, res, next) {
var uid = (req.user) ? req.user.uid : 0;

@ -60,7 +60,7 @@
Auth.createRoutes = function(app) {
app.namespace(nconf.get('relative_path'), function () {
app.post('/logout', function(req, res) {
if (req.user && req.user.uid > 0) {
if (req.user && parseInt(req.user.uid, 10) > 0) {
winston.info('[Auth] Session ' + req.sessionID + ' logout (uid: ' + req.user.uid + ')');
var ws = require('../socket.io');

@ -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,7 +332,12 @@ var fs = require('fs'),
return next(err);
}
if (userData) {
if (!userData) {
return res.json(404, {
error: 'User not found!'
});
}
posts.getFavourites(uid, 0, 9, function (err, favourites) {
if (err) {
return next(err);
@ -344,11 +350,6 @@ var fs = require('fs'),
res.json(userData);
});
} else {
res.json(404, {
error: 'User not found!'
});
}
});
});
});
@ -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,7 +369,12 @@ var fs = require('fs'),
return next(err);
}
if (userData) {
if (!userData) {
return res.json(404, {
error: 'User not found!'
});
}
posts.getPostsByUid(callerUID, uid, 0, 19, function (err, userPosts) {
if (err) {
return next(err);
@ -382,11 +387,6 @@ var fs = require('fs'),
res.json(userData);
});
} else {
res.json(404, {
error: 'User not found!'
});
}
});
});
});

@ -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;
end = start + settings.topicsPerPage - 1;
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;

@ -1,6 +1,7 @@
var topics = require('../topics'),
threadTools = require('../threadTools'),
index = require('./index'),
user = require('../user'),
async = require('async'),
@ -233,11 +234,10 @@ 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;
end = start + settings.postsPerPage - 1;
async.parallel({
posts: function(next) {
@ -249,6 +249,7 @@ SocketTopics.loadMore = function(socket, data, callback) {
}, function(err, results) {
callback(err, results);
});
});
};
SocketTopics.loadMoreRecentTopics = function(socket, data, callback) {
@ -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;

@ -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);
}
};

@ -392,16 +392,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));
});
});
}
@ -809,7 +812,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) {

@ -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'];

Loading…
Cancel
Save