Detect when all messages are loaded with jquery
I need to detect in some way, from javascript, when the chat has finished loading, whether it is a new conversation or if I retrieve messages from a previous conversation.
I'm using directLine and I've created one using a CSS, a bubble to fold and unfold the chat. What I want to do is that when a new message arrives to the chat if it is hidden, deploy it.
For this the idea is to assign to the chat an event that if a new message arrives it is displayed. The problem I have is that I have to assign it once I have loaded all the messages from the previous conversation, or if it is a new conversation, when I have finished loading the chat completely, but I do not know how I can know the moment with javascript .
Is there any way to know when I upload the chat completely?
The code js is:
$('.wc-message-group-content').on("DOMNodeInserted", function(){
if (!$('#containerChat').hasClass('appear')){
//If a message is received with the chat closed, I display it
$("#messenger-button").click();
}
});
I would also like to know when a new message arrives to the chat from javascript. In this way, if that message arrives with the folded chat, I can display it.
Is there an event in javascript like bot.on () or something like that, to detect when new messages arrive?
Thanks
You can look at our backchannel sample and you can use the same technique to watch the observable when a new message/activity had arrived.