1
Fork 0
mirror of https://github.com/jech/galene.git synced 2024-11-23 00:55:58 +01:00

sfu.js: fix display message time in chat box

This commit is contained in:
Alain Takoudjou 2020-10-12 12:48:12 +02:00
parent 2388dfd351
commit 5a526c24f6

View file

@ -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) {
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) {
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) {
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) {