Commit 5a526c24 authored by Alain Takoudjou's avatar Alain Takoudjou

sfu.js: fix display message time in chat box

parent 2388dfd3
...@@ -1380,8 +1380,9 @@ function formatLines(lines) { ...@@ -1380,8 +1380,9 @@ function formatLines(lines) {
function formatTime(time) { function formatTime(time) {
let delta = Date.now() - time; let delta = Date.now() - time;
let date = new Date(time); let date = new Date(time);
let m = date.getMinutes();
if(delta >= 0) if(delta >= 0)
return date.toTimeString().slice(null, 8); return date.getHours() + ':' + ((m < 10) ? '0' : '') + m;
return date.toLocaleString(); return date.toLocaleString();
} }
...@@ -1409,6 +1410,8 @@ function addToChatbox(peerId, dest, nick, time, kind, message) { ...@@ -1409,6 +1410,8 @@ function addToChatbox(peerId, dest, nick, time, kind, message) {
let container = document.createElement('div'); let container = document.createElement('div');
container.classList.add('message'); container.classList.add('message');
row.appendChild(container); row.appendChild(container);
let footer = document.createElement('p');
footer.classList.add('message-footer');
if(!peerId) if(!peerId)
container.classList.add('message-system'); container.classList.add('message-system');
if(userpass.username === nick) if(userpass.username === nick)
...@@ -1430,12 +1433,19 @@ function addToChatbox(peerId, dest, nick, time, kind, message) { ...@@ -1430,12 +1433,19 @@ function addToChatbox(peerId, dest, nick, time, kind, message) {
header.appendChild(user); header.appendChild(user);
header.classList.add('message-header'); header.classList.add('message-header');
container.appendChild(header); container.appendChild(header);
if(time) {
let tm = document.createElement('span');
tm.textContent = formatTime(time);
tm.classList.add('message-time');
footer.appendChild(tm);
}
} }
p.classList.add('message-content'); p.classList.add('message-content');
container.appendChild(p); container.appendChild(p);
lastMessage.nick = (nick || null); lastMessage.nick = (nick || null);
lastMessage.peerId = peerId; lastMessage.peerId = peerId;
lastMessage.dest = (dest || null); lastMessage.dest = (dest || null);
container.appendChild(footer);
} else { } else {
let asterisk = document.createElement('span'); let asterisk = document.createElement('span');
asterisk.textContent = '*'; asterisk.textContent = '*';
...@@ -1455,17 +1465,6 @@ function addToChatbox(peerId, dest, nick, time, kind, message) { ...@@ -1455,17 +1465,6 @@ function addToChatbox(peerId, dest, nick, time, kind, message) {
lastMessage = {}; lastMessage = {};
} }
if(time) {
let tm = document.createElement('span');
let datetime = new Date(time);
tm.textContent = datetime.getHours() + ':' + datetime.getMinutes();
tm.classList.add('message-time');
let footer = document.createElement('p');
footer.classList.add('message-footer');
footer.appendChild(tm);
container.appendChild(footer);
}
let box = document.getElementById('box'); let box = document.getElementById('box');
box.appendChild(row); box.appendChild(row);
if(box.scrollHeight > box.clientHeight) { if(box.scrollHeight > box.clientHeight) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment