diff --git a/src/webim/install/dbinfo.php b/src/webim/install/dbinfo.php index 49135b9c..e89a3eaf 100644 --- a/src/webim/install/dbinfo.php +++ b/src/webim/install/dbinfo.php @@ -28,6 +28,8 @@ $dbtables = array( "locale" => "varchar(8)", "lastpinguser" => "datetime DEFAULT 0", "lastpingagent" => "datetime DEFAULT 0", + "userTyping" => "int DEFAULT 0", + "agentTyping" => "int DEFAULT 0", ), "chatmessage" => array( @@ -57,7 +59,7 @@ $dbtables = array( $memtables = array(); $dbtables_can_update = array( - "chatthread" => array("agentId"), + "chatthread" => array("agentId", "userTyping", "agentTyping"), "chatmessage" => array("agentId"), ); diff --git a/src/webim/install/dbperform.php b/src/webim/install/dbperform.php index adabbac0..c41c510a 100644 --- a/src/webim/install/dbperform.php +++ b/src/webim/install/dbperform.php @@ -72,6 +72,14 @@ if($act == "createdb") { runsql("update chatthread,chatoperator set agentId = operatorid where agentId = 0 AND (vclocalename = agentName OR vccommonname = agentName)", $link); } + if( in_array("chatthread.agentTyping", $absent) ) { + runsql("ALTER TABLE chatthread ADD agentTyping int DEFAULT 0", $link); + } + + if( in_array("chatthread.userTyping", $absent) ) { + runsql("ALTER TABLE chatthread ADD userTyping int DEFAULT 0", $link); + } + } } diff --git a/src/webim/libs/chat.php b/src/webim/libs/chat.php index b4ef7339..ccc706b6 100644 --- a/src/webim/libs/chat.php +++ b/src/webim/libs/chat.php @@ -128,14 +128,15 @@ function get_messages($threadid,$meth,$isuser,&$lastid) { return $messages; } -function print_thread_messages($threadid, $token, $lastid, $isuser,$format) { - global $webim_encoding, $webimroot; +function print_thread_messages($thread, $token, $lastid, $isuser,$format) { + global $webim_encoding, $webimroot; + $threadid = $thread['threadid']; if( $format == "xml" ) { $output = get_messages($threadid,"xml",$isuser,$lastid); start_xml_output(); - print(""); + print(""); foreach( $output as $msg ) { print $msg; } @@ -270,30 +271,24 @@ function update_thread_access($threadid, $params, $link) { "where threadid = ".$threadid,$link); } -function get_access_time($threadid, $isuser, $link) { - return select_one_row(sprintf( - "select unix_timestamp(%s) as lastping, ". - "unix_timestamp(CURRENT_TIMESTAMP) as current ". - "from chatthread where threadid = %s", - $isuser ? "lastpinguser" : "lastpingagent", - $threadid), $link); -} - function ping_thread($thread, $isuser,$istyping) { global $kind_for_agent, $state_chatting, $state_waiting, $kind_conn, $connection_timeout; $link = connect(); - $params = array(($isuser ? "lastpinguser" : "lastpingagent") => "CURRENT_TIMESTAMP" ); - - $access = get_access_time($thread['threadid'], !$isuser, $link); - if( $access['lastping'] > 0 && abs($access['current']-$access['lastping']) > $connection_timeout ) { + $params = array(($isuser ? "lastpinguser" : "lastpingagent") => "CURRENT_TIMESTAMP", + ($isuser ? "userTyping" : "agentTyping") => ($istyping? "1" : "0") ); + + $lastping = $thread[$isuser ? "lpagent" : "lpuser"]; + $current = $thread['current']; + + if( $lastping > 0 && abs($current-$lastping) > $connection_timeout ) { $params[$isuser ? "lastpingagent" : "lastpinguser"] = "0"; if( !$isuser ) { $message_to_post = getstring_("chat.status.user.dead", $thread['locale']); - post_message_($thread['threadid'],$kind_for_agent,$message_to_post,$link,null,$access['lastping']+$connection_timeout); + post_message_($thread['threadid'],$kind_for_agent,$message_to_post,$link,null,$lastping+$connection_timeout); } else if( $thread['istate'] == $state_chatting ) { $message_to_post = getstring_("chat.status.operator.dead", $thread['locale']); - post_message_($thread['threadid'],$kind_conn,$message_to_post,$link,null,$access['lastping']+$connection_timeout); + post_message_($thread['threadid'],$kind_conn,$message_to_post,$link,null,$lastping+$connection_timeout); $params['istate'] = $state_waiting; commit_thread($thread['threadid'], $params, $link); mysql_close($link); @@ -343,6 +338,19 @@ function close_thread($thread,$isuser) { post_message($thread['threadid'], $kind_events, $message); } +function thread_by_id_($id,$link) { + return select_one_row("select threadid,userName,agentName,agentId,lrevision,istate,ltoken,userTyping,agentTyping". + ",remote,referer,locale,unix_timestamp(lastpinguser) as lpuser,unix_timestamp(lastpingagent) as lpagent, unix_timestamp(CURRENT_TIMESTAMP) as current". + " from chatthread where threadid = ". $id, $link ); +} + +function thread_by_id($id) { + $link = connect(); + $thread = thread_by_id_($id,$link); + mysql_close($link); + return $thread; +} + function create_thread($username,$remoteHost,$referer,$lang) { $link = connect(); @@ -359,7 +367,7 @@ function create_thread($username,$remoteHost,$referer,$lang) { perform_query($query,$link); $id = mysql_insert_id($link); - $newthread = select_one_row("select * from chatthread where threadid = ". $id, $link ); + $newthread = thread_by_id_($id,$link); mysql_close($link); return $newthread; } @@ -438,13 +446,6 @@ function check_for_reassign($thread,$operator) { } } -function thread_by_id($id) { - $link = connect(); - $thread = select_one_row("select * from chatthread where threadid = ". $id, $link ); - mysql_close($link); - return $thread; -} - function visitor_from_request() { global $namecookie; $userName = isset($_COOKIE[$namecookie]) ? $_COOKIE[$namecookie] : getstring("chat.default.username"); diff --git a/src/webim/operator/update.php b/src/webim/operator/update.php index be3333ac..b39107e7 100644 --- a/src/webim/operator/update.php +++ b/src/webim/operator/update.php @@ -49,7 +49,7 @@ function thread_to_xml($thread) { $result .= " canopen=\"true\""; - $result .= " state=\"$state\">"; + $result .= " state=\"$state\" typing=\"".$thread['userTyping']."\">"; $result .= "".htmlspecialchars(htmlspecialchars(get_user_name($thread['userName']))).""; $result .= "".htmlspecialchars(htmlspecialchars($thread['remote'])).""; $result .= "".htmlspecialchars(htmlspecialchars($threadoperator)).""; @@ -66,7 +66,7 @@ function print_pending_threads($since) { $revision = $since; $output = array(); - $query = "select threadid, userName, agentName, unix_timestamp(dtmcreated), ". + $query = "select threadid, userName, agentName, unix_timestamp(dtmcreated), userTyping, ". "unix_timestamp(dtmmodified), lrevision, istate, remote ". "from chatthread where lrevision > $since ORDER BY threadid"; $result = mysql_query($query,$link) or die(' Query failed: ' .mysql_error().": ".$query); diff --git a/src/webim/thread.php b/src/webim/thread.php index a0b2ac53..eb70aa99 100644 --- a/src/webim/thread.php +++ b/src/webim/thread.php @@ -40,7 +40,7 @@ if( !$isuser && $act != "rename" ) { if( $act == "refresh" ) { $lastid = verifyparam( "lastid", "/^\d{1,9}$/", -1); - print_thread_messages($threadid, $token, $lastid, $isuser,$outformat); + print_thread_messages($thread, $token, $lastid, $isuser,$outformat); exit; } else if( $act == "post" ) { @@ -51,7 +51,7 @@ if( $act == "refresh" ) { $from = $isuser ? $thread['userName'] : $thread['agentName']; post_message($threadid,$kind,$message,$from, $isuser ? null : $operator['operatorid'] ); - print_thread_messages($threadid, $token, $lastid, $isuser, $outformat); + print_thread_messages($thread, $token, $lastid, $isuser, $outformat); exit; } else if( $act == "rename" ) {