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

Display message header when time delta is larger than a minute.

This commit is contained in:
Juliusz Chroboczek 2020-12-01 02:51:15 +01:00
parent e8df60cbbe
commit f4c5d6a6ef

View file

@ -1502,6 +1502,7 @@ function formatTime(time) {
* @property {string} [nick] * @property {string} [nick]
* @property {string} [peerId] * @property {string} [peerId]
* @property {string} [dest] * @property {string} [dest]
* @property {number} [time]
*/ */
/** @type {lastMessage} */ /** @type {lastMessage} */
@ -1532,16 +1533,29 @@ function addToChatbox(peerId, dest, nick, time, priviledged, kind, message) {
if(kind !== 'me') { if(kind !== 'me') {
let p = formatLines(message.split('\n')); let p = formatLines(message.split('\n'));
if(lastMessage.nick !== (nick || null) || let doHeader = true;
if(!peerId && !dest && !nick) {
doHeader = false;
} else if(lastMessage.nick !== (nick || null) ||
lastMessage.peerId !== peerId || lastMessage.peerId !== peerId ||
lastMessage.dest !== (dest || null)) { lastMessage.dest !== (dest || null) ||
!time || !lastMessage.time) {
doHeader = true;
} else {
let delta = time - lastMessage.time;
doHeader = delta < 0 || delta > 60000;
}
if(doHeader) {
let header = document.createElement('p'); let header = document.createElement('p');
if(peerId || nick || dest) {
let user = document.createElement('span'); let user = document.createElement('span');
user.textContent = dest ? user.textContent = dest ?
`${nick||'(anon)'} \u2192 ${users[dest]||'(anon)'}` : `${nick||'(anon)'} \u2192 ${users[dest]||'(anon)'}` :
(nick || '(anon)'); (nick || '(anon)');
user.classList.add('message-user'); user.classList.add('message-user');
header.appendChild(user); header.appendChild(user);
}
header.classList.add('message-header'); header.classList.add('message-header');
container.appendChild(header); container.appendChild(header);
if(time) { if(time) {
@ -1551,11 +1565,13 @@ function addToChatbox(peerId, dest, nick, time, priviledged, kind, message) {
header.appendChild(tm); header.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);
lastMessage.time = (time || null);
container.appendChild(footer); container.appendChild(footer);
} else { } else {
let asterisk = document.createElement('span'); let asterisk = document.createElement('span');