펄스나인님 실시간 대화쪽지, 중복으로 나오는것 처리하신분 계신가요?
본문
펄스나인님의 실시간 대화쪽지를 사용하고 있는데요
계속 그러지는 않는데, 문득 문득 보낸대화가 2개로 표시가됩니다.
새로고침 하면 정상적으로 1개로 보이구요
글을 입력할떄와 자동으로 chat_refresh 되는 부분이 겹쳐서 그런것같은데
계쏙 만져봐도 안되네요.. 혹시 해결하신분이나 도움주실분 계신가요..
아래는 스크립트소스입니다
<script>
var pos_id = "<?php echo $pos_id;?>";
var chkDate = "<?php echo $chkDate;?>";
var send_mb_id = "<?php echo $member['mb_id'];?>";
var recv_mb_id = "<?php echo $recv_mb['mb_id'];?>";
var max_id = "<?php echo $max['max'];?>";
//var limit_record = "<?php echo $total - $limit;;?>";
var limit_record = "<?php echo $limit;?>";
var from_record = "<?php echo $from_record;?>";
var p_icon = '<?php echo $p_icon;?>';
var p_nick = "<?php echo $recv_mb['mb_nick'];?>";
function chat_refresh() {
$.ajax({
type: "POST",
data: {act:'refresh',send_mb_id:send_mb_id,recv_mb_id:recv_mb_id,max_id:max_id},
url: '<?php echo G5_BBS_URL; ?>/ajax.memo.php',
success: function(data) {
var html = '';
$.each(data.data, function(i, $i) {
var html = '';
if ($i.me_send_mb_id == send_mb_id) {
var cls = "recv";
var cls_box = "bubble_recv";
} else {
var cls = "send";
var cls_box = "bubble_send";
}
html +='<li id="chat_list_'+$i.me_id+'" class="'+cls+'" style=list-style:none;padding-left:10px;>';
if($i.me_send_mb_id != send_mb_id) {
html += '<span class="p_icon">'+p_icon+'</span>';
html += '<span class="p_nick">'+p_nick+'</span>';
}
html += '<div class="'+cls_box+'">';
html += $i.me_memo; //작성한 메세지 출력
html += '</div>';
html += '<div class="chat_time2_'+cls+'">';
if ($i.me_send_mb_id == send_mb_id) {
if($i.me_read_datetime.substr(0,1) == 0) {
//if($i.me_send_datetime.substr(0,1) == 0) {
html += "<span id='bm"+$i.me_id+"' style='color:#FF0000; font-weight:bold;'>1</span>";
} else {
//html += '';
}
}
html += $i.me_send_datetime.substr(10,6);
html += '</div>';
if($i.me_send_mb_id == send_mb_id) {
html += '<div class="del_div"><a href="<?php echo G5_BBS_URL ?>/ajax.memo_del.php?me_id='+$i.me_id+'&del_id=<?php echo $recv_mb['mb_id'] ?>" class="chatroom-cnt2 badge3"><svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" class="feather feather-trash w-4 h-4 mr-2"><polyline points="3 6 5 6 21 6"></polyline><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path></svg></a><div>';
}
html += '</li>';
$('#chat-list').append(html);
//보낸사람 숫자1 없애기
check_Read();
//ajax read체크
//$("#am"+$i.me_id).html("");
max_id = data.max.max;
if ($i.me_id) {
move_page();
}
});
}
});
return false;
}
$("#chat-history").click(function() {
$.ajax({
type: "POST",
data: {act:'history',send_mb_id:send_mb_id,recv_mb_id:recv_mb_id,from_record:from_record,limit_record:limit_record},
url: '<?php echo G5_BBS_URL; ?>/ajax.memo.php',
success: function(data) {
var html = '';
$.each(data.data, function(i, $i) {
pos_id = $i.me_id;
newDate = $i.me_send_datetime.substr(0,10);
if ($i.me_send_mb_id == send_mb_id) {
var cls = "recv";
var cls_box = "bubble_recv";
} else {
var cls = "send";
var cls_box = "bubble_send";
}
if (newDate != chkDate) {
if($('#'+newDate).length > 0) {
$('#'+newDate).remove();
}
html +='<li id="'+newDate+'" class="chkdate" style=list-style:none;>'+newDate+'</li>';
} else {
if($('#'+newDate).length > 0) {
$('#'+newDate).remove();
html +='<li id="'+newDate+'" class="chkdate" style=list-style:none;>'+newDate+'</li>';
}
}
html +='<li id="chat_list_'+$i.me_id+'" class="'+cls+'" style=list-style:none;>';
if($i.me_send_mb_id != send_mb_id) {
html += '<span class="p_icon">'+p_icon+'</span>';
html += '<span class="p_nick">'+p_nick+'</span>';
}
html += '<div class="'+cls_box+'">';
html += $i.me_memo;
html += '</div>';
html += '<div class="chat_time2_'+cls+'">'+$i.me_send_datetime.substr(10,6)+'</div>';
if($i.me_send_mb_id == send_mb_id) {
html += '<div class="del_div"><a href="<?php echo G5_BBS_URL; ?>/ajax.memo_del.php?me_id='+$i.me_id+'&del_id=<?php echo $recv_mb['mb_id'] ?>" class="chatroom-cnt2 badge3"><svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" class="feather feather-trash w-4 h-4 mr-2"><polyline points="3 6 5 6 21 6"></polyline><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path></svg></a><div>';
}
html += '</li>';
chkDate = newDate;
});
$('#chat-list').prepend(html);
from_record = data.from_record;
if (from_record == 0) {
//$('#chat-history').hide();
$('#chat_history_div_wrap').hide();
}
movePos();
}
});
return false;
});
$("#btn-chat").click(function() {
$("#chat-message").focus();
var message = $("#chat-message").val();
if (message == "")
{
alert('메세지를 입력하세요');
return false;
}
$("#chat-message").val('');
clearInterval(setInterval); //새로고침중지
send_message(message);
});
$("#btn-ref").click(function() {
window.location.reload();
});
/* 이것이 기본 */
function send_message(msg) {
$.ajax({
type: "POST",
data: {act:'update',send_mb_id:send_mb_id,recv_mb_id:recv_mb_id,me_memo:msg,recv_mb_level:<?php echo $recv_mb['mb_level'];?>},
url: '<?php echo G5_BBS_URL; ?>/ajax.memo.php',
success: function(data) {
if(data['error_msg'].length > 0) {
var html = '';
html +='<li class="">이용하실 수 없습니다.('+data['error_msg']+')</li>';
$('#chat-list').append(html);
return false;
}
chat_refresh();
}
});
}
/*
$(function() { //키보드 엔터시 메세지 전송
$('#chat-message').on('keydown', function(event) {
if (event.keyCode == 13)
if (!event.shiftKey){
event.preventDefault();
$('#btn-chat').trigger('click');
}
});
});
*/
/*
$('#chat-body').scroll(function() {
if($('#chat-body').scrollTop() == 0) {
$('#chat-history').trigger('click');
}
});
function movePos(){
var pos = pos_id;
document.getElementById('chat_list_'+pos).scrollIntoView();
}
*/
function move_page() {
$('#chat-body').animate({scrollTop:$('#chat-body')[0].scrollHeight}, 0);
}
window.onload = function () {
move_page();
};
function check_Read()
{
//전체데이터 가져와서 처리
$.post("<?php echo G5_BBS_URL; ?>/ajax.memo_read.php", {sender: "<?php echo $recv_mb['mb_id'];?>",receiver: "<?php echo $member['mb_id'];?>",from_record:"<?php echo $from_record;?>"}, function(result){
var dd=result.split("--");
for (i = 0; i < dd.length; i++) {
console.log( dd[i] );
var rd=dd[i].split("|");
//읽음
if( rd[1]=="Y"){
$("#am"+rd[0]).html("");
$("#bm"+rd[0]).html("");
}
}
//location.reload();
});
}
setInterval( function() {
chat_refresh();
check_Read();
}, 10000 ); //10초에 갱신
</script>