displayname fix

main
jerl 2024-05-27 22:03:45 -05:00
parent 7deeb82a08
commit 5798d9030c
2 changed files with 32 additions and 37 deletions

View File

@ -23,7 +23,7 @@ window.socket.on('new_message', message => {
messages.appendChild(html.node`
<div class='message'>
<strong>${message.name}: </strong>
${message.message}
${message.content}
</div>`);
if (scroll)
messages.scroll(0, messages.scrollHeight - messages.clientHeight);
@ -54,36 +54,32 @@ function loadMessages(firstRender, callback) {
else
document.getElementById('msginput').classList.add('hidden');
}
window.emit(
'get_history',
{
before: earliestMessage,
thread: window.currentThread.id
},
msg => {
if (!msg.success) {
console.log('get_history failed: ' + msg.message);
return;
}
callback && callback(msg.messages);
if (firstRender && messages.hasChildNodes())
return;
if (msg.messages.length > 0) {
earliestMessage = msg.messages[msg.messages.length - 1].id;
for (let message of msg.messages)
messages.prepend(html.node`
<div class='message'>
<strong>${message.displayname}: </strong>
${message.message}
</div>`);
}
if (msg.more)
document.getElementById('loadmore').classList.remove('hidden');
else
document.getElementById('loadmore').classList.add('hidden');
messages.scroll(0, messages.scrollHeight - messages.clientHeight);
window.emit('get_history', {
before: earliestMessage,
thread: window.currentThread.id
}, msg => {
if (!msg.success) {
console.log('get_history failed: ' + msg.message);
return;
}
);
callback && callback(msg.messages);
if (firstRender && messages.hasChildNodes())
return;
if (msg.messages.length > 0) {
earliestMessage = msg.messages[msg.messages.length - 1].id;
for (let message of msg.messages)
messages.prepend(html.node`
<div class='message'>
<strong>${message.name}: </strong>
${message.content}
</div>`);
}
if (msg.more)
document.getElementById('loadmore').classList.remove('hidden');
else
document.getElementById('loadmore').classList.add('hidden');
messages.scroll(0, messages.scrollHeight - messages.clientHeight);
});
}
export default loadMessages;

View File

@ -37,8 +37,8 @@ async function send_message(msg, respond) {
s.emit('new_message', {
id: id.rows[0].id,
username: msg.auth_user.name,
displayname: msg.auth_user.displayname,
message: msg.message,
name: msg.auth_user.displayname,
content: msg.message,
thread: msg.thread
});
}
@ -70,9 +70,10 @@ async function get_history(msg, respond) {
});
}
const messages = await db.query(
`select user.name, post.id, content from post
`select coalesce(displayname, name) as name, post.id, content
from post
join user on post.user = user.id
${msg.before ? 'where post.id < ? and' : 'where'}
where ${msg.before ? 'post.id < ? and' : ''}
thread = ?
order by post.created desc
limit 101`,
@ -80,9 +81,7 @@ async function get_history(msg, respond) {
);
return respond({
success: true,
messages: messages.rows
.slice(0, 100)
.map((i) => ({ id: i.id, name: i.name, message: i.content })),
messages: messages.rows.slice(0, 100),
more: messages.rows.length > 100
});
}