Automatically scroll to bottom
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
parent
d36e97fa2e
commit
b86dfe7351
|
@ -95,8 +95,18 @@ function setChannels(new_channels) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function receiveMessage(message) {
|
function receiveMessage(message) {
|
||||||
|
let scrollableContent = document.getElementById('chat-messages')
|
||||||
|
let isScrolledToBottom = scrollableContent.scrollHeight - scrollableContent.clientHeight <= scrollableContent.scrollTop + 1
|
||||||
|
|
||||||
messages[message['channel_id']].set(message['id'], message)
|
messages[message['channel_id']].set(message['id'], message)
|
||||||
redrawMessages()
|
redrawMessages()
|
||||||
|
|
||||||
|
// Scroll to bottom if the user was already at the bottom
|
||||||
|
if (isScrolledToBottom)
|
||||||
|
scrollableContent.scrollTop = scrollableContent.scrollHeight - scrollableContent.clientHeight
|
||||||
|
|
||||||
|
if (message['content'].includes("@everyone"))
|
||||||
|
showNotification(channels[message['channel_id']]['name'], `${message['author']} : ${message['content']}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
function fetchMessages(channel_id, offset = 0, limit = MAX_MESSAGES) {
|
function fetchMessages(channel_id, offset = 0, limit = MAX_MESSAGES) {
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
</button>
|
</button>
|
||||||
</h3>
|
</h3>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body overflow-y-scroll mw-100 h-100 flex-grow-0" id="chat-messages">
|
<div class="card-body d-flex flex-column-reverse flex-grow-0 overflow-y-scroll" id="chat-messages">
|
||||||
<div class="text-center d-none" id="fetch-previous-messages">
|
<div class="text-center d-none" id="fetch-previous-messages">
|
||||||
<a href="#" class="nav-link" onclick="event.preventDefault(); fetchPreviousMessages()">
|
<a href="#" class="nav-link" onclick="event.preventDefault(); fetchPreviousMessages()">
|
||||||
{% trans "Fetch previous messages…" %}
|
{% trans "Fetch previous messages…" %}
|
||||||
|
|
Loading…
Reference in New Issue