diff --git a/public/src/app.js b/public/src/app.js index c04df7da9a..327b63b5d4 100644 --- a/public/src/app.js +++ b/public/src/app.js @@ -496,8 +496,10 @@ var socket, } else { if (allowGuestSearching) { $('#search-button').removeClass("hide").show(); + $('#mobile-search-button').removeClass("hide").show(); } else { $('#search-button').addClass("hide").hide(); + $('#mobile-search-button').addClass("hide").hide(); } $('.nodebb-loggedin').hide(); diff --git a/public/src/modules/chat.js b/public/src/modules/chat.js index 3a67ed1165..af5c4cc02c 100644 --- a/public/src/modules/chat.js +++ b/public/src/modules/chat.js @@ -7,6 +7,7 @@ define(['taskbar', 'string'], function(taskbar, S) { var chatsToggleEl = $('#chat_dropdown'), chatsListEl = $('#chat-list'), chatDropdownEl = chatsToggleEl.parent(); + chatsToggleEl.on('click', function() { if (chatDropdownEl.hasClass('open')) { return; @@ -43,27 +44,29 @@ define(['taskbar', 'string'], function(taskbar, S) { }); socket.on('event:chats.receive', function(data) { - require(['chat'], function(chat) { - if (chat.modalExists(data.fromuid)) { - var modal = chat.getModal(data.fromuid); - chat.appendChatMessage(modal, data.message, data.timestamp); - - if (modal.is(":visible")) { - chat.load(modal.attr('UUID')); - } else { - chat.toggleNew(modal.attr('UUID'), true); - } - if (!modal.is(":visible") || !app.isFocused) { - app.alternatingTitle(data.username + ' has messaged you'); - } + if (module.modalExists(data.fromuid)) { + var modal = module.getModal(data.fromuid); + module.appendChatMessage(modal, data.message, data.timestamp); + + if (modal.is(":visible")) { + module.bringModalToTop(modal); + checkOnlineStatus(modal); + taskbar.updateActive(modal.attr('UUID')); + scrollToBottom(modal.find('#chat-content')); } else { - chat.createModal(data.username, data.fromuid, function(modal) { - chat.toggleNew(modal.attr('UUID'), true); - app.alternatingTitle(data.username + ' has messaged you'); - }); + module.toggleNew(modal.attr('UUID'), true); } - }); + + if (!modal.is(":visible") || !app.isFocused) { + app.alternatingTitle(data.username + ' has messaged you'); + } + } else { + module.createModal(data.username, data.fromuid, function(modal) { + module.toggleNew(modal.attr('UUID'), true); + app.alternatingTitle(data.username + ' has messaged you'); + }); + } }); } diff --git a/public/templates/header.tpl b/public/templates/header.tpl index 72b0d3d28f..be0a49486d 100644 --- a/public/templates/header.tpl +++ b/public/templates/header.tpl @@ -54,23 +54,24 @@ + diff --git a/src/database/mongo.js b/src/database/mongo.js index 5f27c9da90..83e6eb8dec 100644 --- a/src/database/mongo.js +++ b/src/database/mongo.js @@ -741,17 +741,44 @@ module.getListRange = function(key, start, stop, callback) { - if(stop === -1) { - // mongo doesnt allow -1 as the count argument in slice - // pass in a large value to retrieve the whole array - stop = Math.pow(2, 31) - 2; + var skip = start, + limit = stop - start + 1, + splice = false; + + if((start < 0 && stop >= 0) || (start >= 0 && stop < 0)) { + skip = 0; + limit = Math.pow(2, 31) - 2; + splice = true; + } else if (start > stop) { + return callback(null, []); } - db.collection('objects').findOne({_key:key}, { array: { $slice: [start, stop - start + 1] }}, function(err, data) { + db.collection('objects').findOne({_key:key}, { array: { $slice: [skip, limit] }}, function(err, data) { if(err) { return callback(err); } + if(data && data.array) { + if(splice) { + + if(start < 0) { + start = data.array.length - Math.abs(start); + } + + if(stop < 0) { + stop = data.array.length - Math.abs(stop); + } + + if(start > stop) { + return callback(null, []); + } + + var howMany = stop - start + 1; + if(start !== 0 || howMany !== data.array.length) { + data.array = data.array.splice(start, howMany); + } + } + callback(null, data.array); } else { callback(null, []); diff --git a/src/database/redis.js b/src/database/redis.js index f6291f6fbd..7490f6c87c 100644 --- a/src/database/redis.js +++ b/src/database/redis.js @@ -160,26 +160,15 @@ return callback(err); } - data = data.split("\r\n"); + var lines = data.toString().split("\r\n").sort(); var redisData = {}; - - for (var i in data) { - - if (data[i].indexOf(':') == -1 || !data[i]) - continue; - - try { - data[i] = data[i].replace(/:/, "\":\""); - var json = "{\"" + data[i] + "\"}"; - - var jsonObject = JSON.parse(json); - for (var key in jsonObject) { - redisData[key] = jsonObject[key]; - } - } catch (err) { - winston.warn('can\'t parse redis status variable, ignoring', i, data[i], err); + lines.forEach(function (line) { + var parts = line.split(':'); + if (parts[1]) { + redisData[parts[0]] = parts[1]; } - } + }); + redisData.raw = JSON.stringify(redisData, null, 4); redisData.redis = true; diff --git a/src/events.js b/src/events.js index 8dfb922dfa..421b57321b 100644 --- a/src/events.js +++ b/src/events.js @@ -21,6 +21,10 @@ var fs = require('fs'), log(uid,'changed email from "' + oldEmail + '" to "' + newEmail +'"'); } + events.logUsernameChange = function(uid, oldUsername, newUsername) { + log(uid,'changed username from "' + oldUsername + '" to "' + newUsername +'"'); + } + events.logAdminLogin = function(uid) { log(uid, 'logged into admin panel'); } diff --git a/src/install.js b/src/install.js index 61e47bc93d..bb52441d40 100644 --- a/src/install.js +++ b/src/install.js @@ -5,7 +5,6 @@ var async = require('async'), path = require('path'), prompt = require('prompt'), winston = require('winston'), - reds = require('reds'), nconf = require('nconf'), install = { @@ -474,11 +473,6 @@ var async = require('async'), file: path.join(__dirname, '..', 'config.json') }); - /*var RDB = require('./redis'); - reds.createClient = function () { - return reds.client || (reds.client = RDB); - };*/ - callback(err); }); } diff --git a/src/meta.js b/src/meta.js index e755bf940f..dc3b8f56d1 100644 --- a/src/meta.js +++ b/src/meta.js @@ -62,6 +62,10 @@ var fs = require('fs'), }, setOnEmpty: function (field, value, callback) { Meta.configs.get(field, function (err, curValue) { + if(err) { + return callback(err); + } + if (!curValue) { Meta.configs.set(field, value, callback); } else { diff --git a/src/routes/api.js b/src/routes/api.js index 0f16d85bf6..2bfd66a8de 100644 --- a/src/routes/api.js +++ b/src/routes/api.js @@ -258,6 +258,10 @@ var path = require('path'), return callback(err, null); } + if(pids.length > 50) { + pids = pids.splice(0, 50); + } + posts.getPostSummaryByPids(pids, false, function (err, posts) { if (err){ return callback(err, null); @@ -273,6 +277,10 @@ var path = require('path'), return callback(err, null); } + if(tids.length > 50) { + tids = tids.splice(0, 50); + } + topics.getTopicsByTids(tids, 0, function (topics) { callback(null, topics); }, 0); diff --git a/src/routes/debug.js b/src/routes/debug.js index 147df9d13c..c31684a6dd 100644 --- a/src/routes/debug.js +++ b/src/routes/debug.js @@ -82,6 +82,7 @@ var DebugRoute = function(app) { app.get('/test', function(req, res) { res.send(); }); + }); }; diff --git a/src/routes/user.js b/src/routes/user.js index 35ecc00857..bbd8fca5bd 100644 --- a/src/routes/user.js +++ b/src/routes/user.js @@ -424,7 +424,7 @@ var fs = require('fs'), if (!userData.profileviews) { userData.profileviews = 1; } - if (callerUID !== userData.uid) { + if (parseInt(callerUID, 10) !== parseInt(userData.uid, 10)) { user.incrementUserFieldBy(userData.uid, 'profileviews', 1); } diff --git a/src/socket.io/topics.js b/src/socket.io/topics.js index 9b8f6be65c..c9eba84a5d 100644 --- a/src/socket.io/topics.js +++ b/src/socket.io/topics.js @@ -4,6 +4,8 @@ var topics = require('../topics'), SocketTopics = {}; SocketTopics.post = function(data, callback, sessionData) { + var socket = sessionData.socket; + if (sessionData.uid < 1 && parseInt(meta.config.allowGuestPosting, 10) === 0) { socket.emit('event:alert', { title: 'Post Unsuccessful', @@ -51,7 +53,7 @@ SocketTopics.post = function(data, callback, sessionData) { module.parent.exports.emitTopicPostStats(); - sessionData.socket.emit('event:alert', { + socket.emit('event:alert', { title: 'Thank you for posting', message: 'You have successfully posted. Click here to view your post.', type: 'success', diff --git a/src/threadTools.js b/src/threadTools.js index d0c0960bb1..c5c0f9e647 100644 --- a/src/threadTools.js +++ b/src/threadTools.js @@ -285,7 +285,7 @@ var winston = require('winston'), } ThreadTools.getLatestUndeletedPid = function(tid, callback) { - db.getSortedSetRange('tid:' + tid + ':posts', 0, -1, function(err, pids) { + db.getSortedSetRevRange('tid:' + tid + ':posts', 0, -1, function(err, pids) { if(err) { return callback(err); } @@ -293,14 +293,9 @@ var winston = require('winston'), return callback(new Error('no-undeleted-pids-found')); } - pids.reverse(); async.detectSeries(pids, function(pid, next) { posts.getPostField(pid, 'deleted', function(err, deleted) { - if (parseInt(deleted, 10) === 0) { - next(true); - } else { - next(false); - } + next(parseInt(deleted, 10) === 0); }); }, function(pid) { if (pid) { diff --git a/src/topics.js b/src/topics.js index 970a3c65aa..7f76f181ac 100644 --- a/src/topics.js +++ b/src/topics.js @@ -982,7 +982,7 @@ var async = require('async'), return callback(err, null); } - posts.getPostFields(pid, ['pid', 'content', 'uid', 'timestamp'], function(err, postData) { + posts.getPostFields(pid, ['pid', 'uid', 'timestamp'], function(err, postData) { if (err) { return callback(err, null); } else if(!postData) { @@ -994,26 +994,13 @@ var async = require('async'), return callback(err, null); } - var stripped = postData.content, - timestamp = postData.timestamp, - returnObj = { - "pid": postData.pid, - "username": userData.username || 'anonymous', - "userslug": userData.userslug, - "picture": userData.picture || gravatar.url('', {}, https = nconf.get('https')), - "timestamp": timestamp - }; - - if (postData.content) { - stripped = postData.content.replace(/>.+\n\n/, ''); - postTools.parse(stripped, function(err, stripped) { - returnObj.text = S(stripped).stripTags().s; - callback(null, returnObj); - }); - } else { - returnObj.text = ''; - callback(null, returnObj); - } + callback(null, { + pid: postData.pid, + username: userData.username || 'anonymous', + userslug: userData.userslug, + picture: userData.picture || gravatar.url('', {}, https = nconf.get('https')), + timestamp: postData.timestamp + }); }); }); }); diff --git a/src/user.js b/src/user.js index 46036d07cf..96e8244eb0 100644 --- a/src/user.js +++ b/src/user.js @@ -312,6 +312,7 @@ var bcrypt = require('bcrypt'), db.searchRemove('user', uid, function() { db.searchIndex('user', data.username, uid); }); + events.logUsernameChange(uid, userData.username, data.username); } if(userslug !== userData.userslug) {