Added timestamps to messages

This commit is contained in:
jsrobson10 2019-04-17 16:40:22 +10:00
parent c63a625a0a
commit 39d8540498
3 changed files with 24 additions and 9 deletions

View File

@ -400,12 +400,13 @@ function connect(profile, connection_id)
if(data.mode == "new_message") if(data.mode == "new_message")
{ {
console.log("Recieved new message from "+data.from console.log("Recieved new message from "+data.from
+" in channel "+data.channel.toString()); +" in channel "+data.channel.toString(), data.date);
// Push the new messages to the chat // Push the new messages to the chat
g.chats[data.channel].messages.push({ g.chats[data.channel].messages.push({
message: data.message, message: data.message,
from: data.from from: data.from,
date: data.date
}); });
// Is the chat and server active // Is the chat and server active

View File

@ -205,8 +205,6 @@ function text_to_html(text)
if(strikethrough_check) out += "</del>"; if(strikethrough_check) out += "</del>";
if(code_check) out += "</code>"; if(code_check) out += "</code>";
console.log(out)
// Send out back // Send out back
return out; return out;
} }

View File

@ -160,6 +160,7 @@ function chat_switch_to(id)
// Setup some memory varibles // Setup some memory varibles
var last_chat_user = ""; var last_chat_user = "";
var last_chat_date = "";
// Loop over the messages // Loop over the messages
for(var i=0;i<connections[active_profile].chats[id].messages.length;i++) for(var i=0;i<connections[active_profile].chats[id].messages.length;i++)
@ -179,16 +180,23 @@ function chat_switch_to(id)
// Setup the message header varible // Setup the message header varible
var message_header = ""; var message_header = "";
// Get the date
var date = new Date(connections[active_profile].chats[id].messages[i].date);
date = date.toString();
// Should the chat header be included // Should the chat header be included
if(last_chat_user != connections[active_profile].chats[id].messages[i].from) if(
{ last_chat_user != connections[active_profile].chats[id].messages[i].from ||
// Set the last user last_chat_date != date
){
// Set the memory varibles
last_chat_user = connections[active_profile].chats[id].messages[i].from; last_chat_user = connections[active_profile].chats[id].messages[i].from;
last_chat_date = date;
// Include the message header // Include the message header
message_header = "<p class='message-header'><b>"+ message_header = "<p class='message-header'><b>"+
connections[active_profile].chats[id].messages[i].from+ connections[active_profile].chats[id].messages[i].from+
"</b></p>"; "</b> "+date+"</p>";
} }
// Add some html data to the chat // Add some html data to the chat
@ -249,6 +257,13 @@ function chat_send()
// Get the message // Get the message
var message = document.getElementById("chat-content-send-textarea").value; var message = document.getElementById("chat-content-send-textarea").value;
// Get the date
var date = new Date();
// Remove some data from the date
date.setMilliseconds(0);
date.setSeconds(0);
// Is the message not empty and isnt a newline // Is the message not empty and isnt a newline
if(message.length > 0 && message != "\n") if(message.length > 0 && message != "\n")
{ {
@ -259,7 +274,8 @@ function chat_send()
{ {
mode: "send_message", mode: "send_message",
channel: active_chat, channel: active_chat,
message: message message: message,
date: Date.parse(date)
} }
); );
} }