mirror of
https://github.com/KevinMidboe/zoff.git
synced 2025-10-29 18:00:23 +00:00
10 minutes chat history, limit of 20 messages
This commit is contained in:
@@ -1,3 +1,28 @@
|
||||
function get_history(channel, all, socket) {
|
||||
var query = {};
|
||||
if(all) {
|
||||
query = {
|
||||
all: true,
|
||||
};
|
||||
} else {
|
||||
query = {
|
||||
all: false,
|
||||
channel: channel,
|
||||
};
|
||||
}
|
||||
db.collection("chat_logs").find(query, {
|
||||
from: 1,
|
||||
createdAt: 1,
|
||||
all: 1,
|
||||
channel: 1,
|
||||
msg: 1,
|
||||
icon: 1,
|
||||
_id: 0
|
||||
}).sort({createdAt: 1}).limit(20, function(err, docs) {
|
||||
socket.emit("chat_history", {all: all, data: docs});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function chat(msg, guid, offline, socket) {
|
||||
if(typeof(msg) !== 'object' && !msg.hasOwnProperty('data') && !msg.hasOwnProperty('channel') && !msg.hasOwnProperty('pass')) {
|
||||
@@ -18,6 +43,7 @@ function chat(msg, guid, offline, socket) {
|
||||
if(n.length > 0 && n[0].icon) {
|
||||
icon = n[0].icon;
|
||||
}
|
||||
db.collection("chat_logs").insert({ "createdAt": new Date(), all: false, channel: coll, from: docs[0].name, msg: ": " + data, icon: icon });
|
||||
io.to(coll).emit('chat', {from: docs[0].name, msg: ": " + data, icon: icon});
|
||||
});
|
||||
} else if(docs.length == 0){
|
||||
@@ -49,6 +75,7 @@ function all_chat(msg, guid, offline, socket) {
|
||||
if(n.length > 0 && n[0].icon) {
|
||||
icon = n[0].icon;
|
||||
}
|
||||
db.collection("chat_logs").insert({ "createdAt": new Date(), all: true, channel: coll, from: docs[0].name, msg: ": " + data, icon: icon }, function(err, docs) {});
|
||||
io.sockets.emit('chat.all', {from: docs[0].name, msg: ": " + data, channel: coll, icon: icon});
|
||||
});
|
||||
} else if(docs.length == 0) {
|
||||
@@ -163,6 +190,7 @@ function get_name(guid, announce_payload) {
|
||||
})
|
||||
}
|
||||
|
||||
module.exports.get_history = get_history;
|
||||
module.exports.chat = chat;
|
||||
module.exports.all_chat = all_chat;
|
||||
module.exports.namechange = namechange;
|
||||
|
||||
@@ -2,6 +2,8 @@ var mongo_db_cred = {config: 'mydb'};
|
||||
var mongojs = require('mongojs');
|
||||
var db = mongojs(mongo_db_cred.config);
|
||||
|
||||
db.collection("chat_logs").createIndex({ "createdAt": 1 }, { expireAfterSeconds: 600 });
|
||||
|
||||
db.on('connected', function(err) {
|
||||
console.log("connected");
|
||||
})
|
||||
|
||||
@@ -131,6 +131,10 @@ module.exports = function() {
|
||||
}
|
||||
});
|
||||
|
||||
socket.on('get_history', function(msg) {
|
||||
Chat.get_history(msg.channel, msg.all, socket);
|
||||
});
|
||||
|
||||
socket.on('chat', function (msg) {
|
||||
Chat.chat(msg, guid, offline, socket);
|
||||
});
|
||||
|
||||
2
server/public/assets/dist/embed.min.js
vendored
2
server/public/assets/dist/embed.min.js
vendored
File diff suppressed because one or more lines are too long
2
server/public/assets/dist/main.min.js
vendored
2
server/public/assets/dist/main.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -89,8 +89,8 @@ var Chat = {
|
||||
return;
|
||||
},
|
||||
|
||||
allchat: function(inp) {
|
||||
if(inp.msg.substring(0,1) == ":" && !chat_active) {
|
||||
allchat: function(inp, time_sent, disable_blink) {
|
||||
if(inp.msg.substring(0,1) == ":" && !chat_active && !disable_blink) {
|
||||
Chat.all_received += 1;
|
||||
$("#favicon").attr("href", "/assets/images/highlogo.png");
|
||||
unseen = true;
|
||||
@@ -123,6 +123,9 @@ var Chat = {
|
||||
color = Helper.hexToRgb(color.substring(0,6));
|
||||
var color_temp = Helper.rgbToHsl([color.r, color.g, color.b], false);
|
||||
var _time = new Date();
|
||||
if(time_sent) {
|
||||
_time = new Date(time_sent);
|
||||
}
|
||||
var time = Helper.pad(_time.getHours()) + ":" + Helper.pad(_time.getMinutes());
|
||||
$("#chatall").append("<li title='"+inp.channel+"'><span class='time_color'>" + time + "</span> " + icon_add + "<span style='color:"+color_temp+";'>"+inp.from+"</span><span class='channel-info-all-chat'> " + inp.channel + " </span></li>");
|
||||
var in_text = document.createTextNode(inp.msg);
|
||||
@@ -130,8 +133,8 @@ var Chat = {
|
||||
document.getElementById("chatall").scrollTop = document.getElementById("chatall").scrollHeight;
|
||||
},
|
||||
|
||||
channelchat: function(data) {
|
||||
if(data.msg.substring(0,1) == ":" && !chat_active) {
|
||||
channelchat: function(data, time_sent, disable_blink) {
|
||||
if(data.msg.substring(0,1) == ":" && !chat_active && !disable_blink) {
|
||||
$("#favicon").attr("href", "/assets/images/highlogo.png");
|
||||
unseen = true;
|
||||
chat_unseen = true;
|
||||
@@ -162,6 +165,9 @@ var Chat = {
|
||||
color = Helper.hexToRgb(color.substring(0,6));
|
||||
var color_temp = Helper.rgbToHsl([color.r, color.g, color.b], false);
|
||||
var _time = new Date();
|
||||
if(time_sent) {
|
||||
_time = new Date(time_sent);
|
||||
}
|
||||
var time = Helper.pad(_time.getHours()) + ":" + Helper.pad(_time.getMinutes());
|
||||
$("#chatchannel").append("<li><span class='time_color'>" + time + "</span> " + icon_add + "<span style='color:"+color_temp+";'>"+data.from+"</span></li>");
|
||||
var in_text = document.createTextNode(data.msg);
|
||||
|
||||
@@ -310,6 +310,7 @@ function init(){
|
||||
if(private_channel) add = Crypt.getCookie("_uI") + "_";
|
||||
socket.emit("list", {version: parseInt(localStorage.getItem("VERSION")), channel: add + chan.toLowerCase(), pass: embed ? '' : Crypt.crypt_pass(Crypt.get_userpass(chan.toLowerCase()))});
|
||||
}
|
||||
|
||||
if(!Helper.mobilecheck()) {
|
||||
$("#viewers").tooltip({
|
||||
delay: 5,
|
||||
@@ -368,6 +369,9 @@ function init(){
|
||||
setup_list_listener();
|
||||
setup_chat_listener();
|
||||
|
||||
socket.emit("get_history", {channel: chan.toLowerCase(), all: false});
|
||||
socket.emit("get_history", {channel: chan.toLowerCase(), all: true});
|
||||
|
||||
if(!Helper.mobilecheck() && $("#alreadychannel").length === 0) setup_host_initialization();
|
||||
|
||||
if(!Helper.msieversion() && !Helper.mobilecheck()) Notification.requestPermission();
|
||||
@@ -748,6 +752,16 @@ function setup_admin_listener(){
|
||||
}
|
||||
|
||||
function setup_chat_listener(){
|
||||
socket.on("chat_history", function(msg) {
|
||||
var data = msg.data;
|
||||
for(var i = 0; i < data.length; i++) {
|
||||
if(msg.all) {
|
||||
Chat.allchat(data[i], data[i].createdAt, true);
|
||||
} else {
|
||||
Chat.channelchat(data[i], data[i].createdAt, true);
|
||||
}
|
||||
}
|
||||
});
|
||||
socket.on("chat.all", Chat.allchat);
|
||||
socket.on("chat", Chat.channelchat);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user