Answer the question
In order to leave comments, you need to log in
How to reply to the sender of a message that the user is offline?
I create a messenger ...
there is a code that sends a message to the user and fires when the user is online
by clicking on the book. send
$(document).on('click','#sendmsg',function(e){
if($('.textarea[data='+$(this).attr('data')+']').val() !== '') {
socket.emit('send', {usr:$(this).attr('data'), msg:$('.textarea[data='+$(this).attr('data')+']').val()});
$('.messageBlock[data="'+$(this).attr('data')+'"]').append('<p class="msgTo">'+$('.textarea[data="'+$(this).attr('data')+'"]').val()+'</p>');
$('.textarea[data="'+$(this).attr('data')+'"]').val('');
}
});
socket.on('send', function (data) {
if (io.sockets.connected[users_login_list[data.usr]]===undefined) {
//тут вопрос как сказать пользователю 1 что пользователь2 не в сети??
socket.emit('sendmsg', {msg:'User is offline'});
} else {
//тут все хорошо
io.sockets.connected[users_login_list[data.usr]].emit('sendmsg', {msg:data.msg, usr:socket.user_id});
}
});
socket.on('sendmsg', function (data) {
if($('.messageBlock[data='+data.usr+']').length !== 0) { // тут я проверяю если открыто диалоговое окно чтоб в него добавить сообщения
$('.messageBlock[data='+data.usr+']').append('<p class="msgFrom">'+data.msg+'</p>');
}
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question