For a chat application within a Django project, I populate a sidebar with links for logged in users. The links open a pop-up for chat(similar to FB stlye).If I refresh the page any open pop-up is closed. I want to refresh only the sidebar to reflect if a user has logged out. This code refreshes the entire page and all open pop-up's close.
$(function(){
$('#sidebar-name').on('scroll', function(){
scrolling = true;
});
setTimeout(function() { location.reload() },3500);
});
I use the code below to get the messages and refresh the message box
function getMessages(){
if (!scrolling) {
$.get('/chatpop/messages/', function(messages){
console.log(messages);
$('#msg-list').html(messages);
var chatlist = document.getElementById('msg-list-div');
chatlist.scrollTop = chatlist.scrollHeight;
});
}
var scrolling = false;
}
$(function(){
$('#msg-list-div').on('scroll', function(){
scrolling = true;
});
refreshTimer = setInterval(getMessages, 10000);
});
I also tried the following but not working..
$(function(){
$('#sidebar-name').on('scroll', function(){
scrolling = true;
});
(function() { load(location.href +'#sidebar-name') },10000);
});
I need to refresh only the sidebar in a way that does not close the already opened chat pop-up's.
The HTML being used is..
<div class="chat-sidebar">
<div class="sidebar-name">
<!-- Pass username and display name to register popup -->
{% for user in request.online_now %}
{% if request.user != user %}
<a href="javascript:register_popup('{{ user }}', '{{ user }}');">
{% for img in users %}
{% if img == user %}
{% thumbnail img.profile.photo "30x30" crop="100%" as im %}
<img src="{{ im.url }}" class="user-detail">
{% endthumbnail %}{% endif %}{% endfor %}
<span>{{ user }}</span>
</a>{% endif %}{% endfor %}
have looked at some stackoverflow answers. But they all seem to handle reload on occurrence of an event. I simply want to refresh at a set time interval.Many thks..