Fix chat bugs (#102)

This commit is contained in:
Phuoc Anh Kha Le 2024-01-03 02:07:17 -06:00 committed by GitHub
parent eb07dd8fa7
commit 88b07644ee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 6 deletions

View file

@ -227,9 +227,15 @@
.active-span { .active-span {
display: none; display: none;
} }
#chat-area { {% if not room %}
display: none; #chat-area {
} display: none;
}
{% else %}
.chat-left-panel {
display: none;
}
{% endif %}
.back-button { .back-button {
margin-right: 1em; margin-right: 1em;
font-size: 1.5em; font-size: 1.5em;

View file

@ -3,6 +3,7 @@
function load_next_page(last_id, refresh_html=false) { function load_next_page(last_id, refresh_html=false) {
if (refresh_html) { if (refresh_html) {
window.lock = true;
$('#chat-log').html(''); $('#chat-log').html('');
$('#loader').show(); $('#loader').show();
} }
@ -13,11 +14,11 @@
$.get("{{ url('chat', '') }}" + window.room_id, param) $.get("{{ url('chat', '') }}" + window.room_id, param)
.fail(function() { .fail(function() {
console.log("Fail to load page, last_id = " + last_id); console.log("Fail to load page, last_id = " + last_id);
window.lock = false;
}) })
.done(function(data) { .done(function(data) {
if (refresh_html) { if (refresh_html) {
$('#chat-box').scrollTop($('#chat-box')[0].scrollHeight); $('#chat-box').scrollTop($('#chat-box')[0].scrollHeight);
window.lock = true;
} }
var time = refresh_html ? 0 : 200; var time = refresh_html ? 0 : 200;
@ -67,7 +68,7 @@
} }
})} })}
function refresh_status() { function refresh_status(refresh_chat_info=false) {
$.get("{{url('online_status_ajax')}}") $.get("{{url('online_status_ajax')}}")
.fail(function() { .fail(function() {
console.log("Fail to get online status"); console.log("Fail to get online status");
@ -90,6 +91,10 @@
'user': window.other_user_id, 'user': window.other_user_id,
}; };
if (refresh_chat_info) {
$('#chat-info').html('');
}
$.get("{{url('user_online_status_ajax')}}", data) $.get("{{url('user_online_status_ajax')}}", data)
.fail(function() { .fail(function() {
console.log("Fail to get user online status"); console.log("Fail to get user online status");
@ -299,7 +304,7 @@
history.replaceState(null, '', "{{url('chat', '')}}" + window.room_id); history.replaceState(null, '', "{{url('chat', '')}}" + window.room_id);
load_next_page(null, true); load_next_page(null, true);
update_last_seen(); update_last_seen();
refresh_status(); refresh_status(true);
$('#chat-input').focus(); $('#chat-input').focus();
show_right_panel(); show_right_panel();
} }