diff --git a/server/handlers/chat.js b/server/handlers/chat.js index 9197921c..b7176dbd 100644 --- a/server/handlers/chat.js +++ b/server/handlers/chat.js @@ -1,4 +1,4 @@ -function get_history(channel, all, socket) { +function get_history(channel, all, socket, pass) { var query = {}; if(all) { query = { @@ -10,6 +10,18 @@ function get_history(channel, all, socket) { channel: channel, }; } + if(!query.all) { + db.collection(channel + "_settings").find({id: "config"}, function(err, conf) { + if(conf.length > 0 && conf[0].userpass == "" || conf[0].userpass == Functions.decrypt_string(socket.zoff_id, pass)) { + getAndSendLogs(channel, all, socket, pass, query); + } + }); + } else { + getAndSendLogs(channel, all, socket, pass, query); + } +} + +function getAndSendLogs(channel, all, socket, pass, query) { db.collection("chat_logs").find(query, { from: 1, createdAt: 1, diff --git a/server/handlers/io.js b/server/handlers/io.js index 3866f8b9..260e9b69 100644 --- a/server/handlers/io.js +++ b/server/handlers/io.js @@ -179,6 +179,7 @@ module.exports = function() { socket.on('get_history', function(msg) { if(!msg.hasOwnProperty("channel") || !msg.hasOwnProperty("all") || + !msg.hasOwnProperty("pass") || typeof(msg.pass) != "string" || typeof(msg.channel) != "string" || typeof(msg.all) != "boolean") { var result = { all: { @@ -197,7 +198,7 @@ module.exports = function() { socket.emit('update_required', result); return; } - Chat.get_history(msg.channel, msg.all, socket); + Chat.get_history(msg.channel, msg.all, socket, msg.pass); }); socket.on('chat', function (msg) { diff --git a/server/public/assets/js/channel.js b/server/public/assets/js/channel.js index 5cb52cd3..ec61d39c 100644 --- a/server/public/assets/js/channel.js +++ b/server/public/assets/js/channel.js @@ -103,6 +103,7 @@ var Channel = { } Crypt.init(); + setup_auth_listener(); if(Crypt.get_offline()){ @@ -198,9 +199,7 @@ var Channel = { setup_admin_listener(); setup_list_listener(); setup_chat_listener(); - - socket.emit("get_history", {channel: chan.toLowerCase(), all: false}); - socket.emit("get_history", {channel: chan.toLowerCase(), all: true}); + get_history(); if(!Helper.msieversion() && !Helper.mobilecheck()) Notification.requestPermission(); @@ -618,3 +617,16 @@ var Channel = { } } } + +function get_history() { + if(socket.id) { + var p = Crypt.get_userpass(); + var c = Crypt.crypt_pass(p, true); + socket.emit("get_history", {channel: chan.toLowerCase(), all: false, pass: embed ? '' : c}); + socket.emit("get_history", {channel: chan.toLowerCase(), all: true, pass: ""}); + } else { + setTimeout(function() { + get_history(); + }, 50); + } +}