diff --git a/static/js/check_new_messages.js b/static/js/check_new_messages.js index 1397e97..5c3d8e8 100644 --- a/static/js/check_new_messages.js +++ b/static/js/check_new_messages.js @@ -20,7 +20,9 @@ function check_new_messages_timeout(){ } check_msg = setInterval(function () { - + sessionStorage.setItem('online',user_online) + let new_message = getNewMessageSession() + let user_online = userOnline('set') window = document.querySelector(".container-messages") if (window === null){ // @@ -29,7 +31,7 @@ function check_new_messages_timeout(){ check_new_messages(window,it) } }, - 1000) + 60000) } @@ -58,6 +60,7 @@ function check_new_messages (window,it){ data_new_messages.last_message_modifiedDT = last_message_time.dataset['modifieddt'] } + $.ajax({ headers: { "X-CSRFToken": $('input[name=csrfmiddlewaretoken]').val() }, url: '/ru/messages/update_chat/', @@ -110,3 +113,16 @@ function success_check_new_messages (data) { } + +function userOnline (set=null,check=null) { + let user_online = null + if (set !== null){ + user_online = navigator.userActivation.isActive || navigator.userActivation.hasBeenActive === true; + sessionStorage.setItem('online',user_online) + + } else if (check !== null){ + user_online = navigator.userActivation.isActive || navigator.userActivation.hasBeenActive === true; + sessionStorage.getItem('online') + } + return user_online +} \ No newline at end of file diff --git a/static/js/global_js.js b/static/js/global_js.js new file mode 100644 index 0000000..abf8c58 --- /dev/null +++ b/static/js/global_js.js @@ -0,0 +1,11 @@ +$(document).ready(function (){ + getNewMessageSession() +}) + +function getNewMessageSession (){ + let new_message = JSON.parse( + sessionStorage.getItem('user_alerts') + ) + return new_message +} + diff --git a/templates/tb_base.html b/templates/tb_base.html index 1132407..8a6e258 100644 --- a/templates/tb_base.html +++ b/templates/tb_base.html @@ -13,6 +13,8 @@ + + {% block meta %}