displayname fix
parent
7deeb82a08
commit
5798d9030c
|
@ -23,7 +23,7 @@ window.socket.on('new_message', message => {
|
||||||
messages.appendChild(html.node`
|
messages.appendChild(html.node`
|
||||||
<div class='message'>
|
<div class='message'>
|
||||||
<strong>${message.name}: </strong>
|
<strong>${message.name}: </strong>
|
||||||
${message.message}
|
${message.content}
|
||||||
</div>`);
|
</div>`);
|
||||||
if (scroll)
|
if (scroll)
|
||||||
messages.scroll(0, messages.scrollHeight - messages.clientHeight);
|
messages.scroll(0, messages.scrollHeight - messages.clientHeight);
|
||||||
|
@ -54,13 +54,10 @@ function loadMessages(firstRender, callback) {
|
||||||
else
|
else
|
||||||
document.getElementById('msginput').classList.add('hidden');
|
document.getElementById('msginput').classList.add('hidden');
|
||||||
}
|
}
|
||||||
window.emit(
|
window.emit('get_history', {
|
||||||
'get_history',
|
|
||||||
{
|
|
||||||
before: earliestMessage,
|
before: earliestMessage,
|
||||||
thread: window.currentThread.id
|
thread: window.currentThread.id
|
||||||
},
|
}, msg => {
|
||||||
msg => {
|
|
||||||
if (!msg.success) {
|
if (!msg.success) {
|
||||||
console.log('get_history failed: ' + msg.message);
|
console.log('get_history failed: ' + msg.message);
|
||||||
return;
|
return;
|
||||||
|
@ -73,8 +70,8 @@ function loadMessages(firstRender, callback) {
|
||||||
for (let message of msg.messages)
|
for (let message of msg.messages)
|
||||||
messages.prepend(html.node`
|
messages.prepend(html.node`
|
||||||
<div class='message'>
|
<div class='message'>
|
||||||
<strong>${message.displayname}: </strong>
|
<strong>${message.name}: </strong>
|
||||||
${message.message}
|
${message.content}
|
||||||
</div>`);
|
</div>`);
|
||||||
}
|
}
|
||||||
if (msg.more)
|
if (msg.more)
|
||||||
|
@ -82,8 +79,7 @@ function loadMessages(firstRender, callback) {
|
||||||
else
|
else
|
||||||
document.getElementById('loadmore').classList.add('hidden');
|
document.getElementById('loadmore').classList.add('hidden');
|
||||||
messages.scroll(0, messages.scrollHeight - messages.clientHeight);
|
messages.scroll(0, messages.scrollHeight - messages.clientHeight);
|
||||||
}
|
});
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default loadMessages;
|
export default loadMessages;
|
||||||
|
|
|
@ -37,8 +37,8 @@ async function send_message(msg, respond) {
|
||||||
s.emit('new_message', {
|
s.emit('new_message', {
|
||||||
id: id.rows[0].id,
|
id: id.rows[0].id,
|
||||||
username: msg.auth_user.name,
|
username: msg.auth_user.name,
|
||||||
displayname: msg.auth_user.displayname,
|
name: msg.auth_user.displayname,
|
||||||
message: msg.message,
|
content: msg.message,
|
||||||
thread: msg.thread
|
thread: msg.thread
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -70,9 +70,10 @@ async function get_history(msg, respond) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
const messages = await db.query(
|
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
|
join user on post.user = user.id
|
||||||
${msg.before ? 'where post.id < ? and' : 'where'}
|
where ${msg.before ? 'post.id < ? and' : ''}
|
||||||
thread = ?
|
thread = ?
|
||||||
order by post.created desc
|
order by post.created desc
|
||||||
limit 101`,
|
limit 101`,
|
||||||
|
@ -80,9 +81,7 @@ async function get_history(msg, respond) {
|
||||||
);
|
);
|
||||||
return respond({
|
return respond({
|
||||||
success: true,
|
success: true,
|
||||||
messages: messages.rows
|
messages: messages.rows.slice(0, 100),
|
||||||
.slice(0, 100)
|
|
||||||
.map((i) => ({ id: i.id, name: i.name, message: i.content })),
|
|
||||||
more: messages.rows.length > 100
|
more: messages.rows.length > 100
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue