mirror of
https://github.com/Mibew/design.git
synced 2025-01-23 02:20:34 +03:00
propagate typing notifications on server
git-svn-id: https://webim.svn.sourceforge.net/svnroot/webim/trunk@69 c66351dc-e62f-0410-b875-e3a5c0b9693f
This commit is contained in:
parent
5e242414e6
commit
4493a47848
@ -28,6 +28,8 @@ $dbtables = array(
|
|||||||
"locale" => "varchar(8)",
|
"locale" => "varchar(8)",
|
||||||
"lastpinguser" => "datetime DEFAULT 0",
|
"lastpinguser" => "datetime DEFAULT 0",
|
||||||
"lastpingagent" => "datetime DEFAULT 0",
|
"lastpingagent" => "datetime DEFAULT 0",
|
||||||
|
"userTyping" => "int DEFAULT 0",
|
||||||
|
"agentTyping" => "int DEFAULT 0",
|
||||||
),
|
),
|
||||||
|
|
||||||
"chatmessage" => array(
|
"chatmessage" => array(
|
||||||
@ -57,7 +59,7 @@ $dbtables = array(
|
|||||||
$memtables = array();
|
$memtables = array();
|
||||||
|
|
||||||
$dbtables_can_update = array(
|
$dbtables_can_update = array(
|
||||||
"chatthread" => array("agentId"),
|
"chatthread" => array("agentId", "userTyping", "agentTyping"),
|
||||||
"chatmessage" => array("agentId"),
|
"chatmessage" => array("agentId"),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -72,6 +72,14 @@ if($act == "createdb") {
|
|||||||
runsql("update chatthread,chatoperator set agentId = operatorid where agentId = 0 AND (vclocalename = agentName OR vccommonname = agentName)", $link);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,14 +128,15 @@ function get_messages($threadid,$meth,$isuser,&$lastid) {
|
|||||||
return $messages;
|
return $messages;
|
||||||
}
|
}
|
||||||
|
|
||||||
function print_thread_messages($threadid, $token, $lastid, $isuser,$format) {
|
function print_thread_messages($thread, $token, $lastid, $isuser,$format) {
|
||||||
global $webim_encoding, $webimroot;
|
global $webim_encoding, $webimroot;
|
||||||
|
$threadid = $thread['threadid'];
|
||||||
|
|
||||||
if( $format == "xml" ) {
|
if( $format == "xml" ) {
|
||||||
$output = get_messages($threadid,"xml",$isuser,$lastid);
|
$output = get_messages($threadid,"xml",$isuser,$lastid);
|
||||||
|
|
||||||
start_xml_output();
|
start_xml_output();
|
||||||
print("<thread lastid=\"$lastid\">");
|
print("<thread lastid=\"$lastid\" typing=\"".$thread[$isuser?"agentTyping":"userTyping"]."\">");
|
||||||
foreach( $output as $msg ) {
|
foreach( $output as $msg ) {
|
||||||
print $msg;
|
print $msg;
|
||||||
}
|
}
|
||||||
@ -270,30 +271,24 @@ function update_thread_access($threadid, $params, $link) {
|
|||||||
"where threadid = ".$threadid,$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) {
|
function ping_thread($thread, $isuser,$istyping) {
|
||||||
global $kind_for_agent, $state_chatting, $state_waiting, $kind_conn, $connection_timeout;
|
global $kind_for_agent, $state_chatting, $state_waiting, $kind_conn, $connection_timeout;
|
||||||
$link = connect();
|
$link = connect();
|
||||||
$params = array(($isuser ? "lastpinguser" : "lastpingagent") => "CURRENT_TIMESTAMP" );
|
$params = array(($isuser ? "lastpinguser" : "lastpingagent") => "CURRENT_TIMESTAMP",
|
||||||
|
($isuser ? "userTyping" : "agentTyping") => ($istyping? "1" : "0") );
|
||||||
|
|
||||||
$access = get_access_time($thread['threadid'], !$isuser, $link);
|
$lastping = $thread[$isuser ? "lpagent" : "lpuser"];
|
||||||
if( $access['lastping'] > 0 && abs($access['current']-$access['lastping']) > $connection_timeout ) {
|
$current = $thread['current'];
|
||||||
|
|
||||||
|
if( $lastping > 0 && abs($current-$lastping) > $connection_timeout ) {
|
||||||
$params[$isuser ? "lastpingagent" : "lastpinguser"] = "0";
|
$params[$isuser ? "lastpingagent" : "lastpinguser"] = "0";
|
||||||
if( !$isuser ) {
|
if( !$isuser ) {
|
||||||
$message_to_post = getstring_("chat.status.user.dead", $thread['locale']);
|
$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 ) {
|
} else if( $thread['istate'] == $state_chatting ) {
|
||||||
|
|
||||||
$message_to_post = getstring_("chat.status.operator.dead", $thread['locale']);
|
$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;
|
$params['istate'] = $state_waiting;
|
||||||
commit_thread($thread['threadid'], $params, $link);
|
commit_thread($thread['threadid'], $params, $link);
|
||||||
mysql_close($link);
|
mysql_close($link);
|
||||||
@ -343,6 +338,19 @@ function close_thread($thread,$isuser) {
|
|||||||
post_message($thread['threadid'], $kind_events, $message);
|
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) {
|
function create_thread($username,$remoteHost,$referer,$lang) {
|
||||||
$link = connect();
|
$link = connect();
|
||||||
|
|
||||||
@ -359,7 +367,7 @@ function create_thread($username,$remoteHost,$referer,$lang) {
|
|||||||
perform_query($query,$link);
|
perform_query($query,$link);
|
||||||
$id = mysql_insert_id($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);
|
mysql_close($link);
|
||||||
return $newthread;
|
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() {
|
function visitor_from_request() {
|
||||||
global $namecookie;
|
global $namecookie;
|
||||||
$userName = isset($_COOKIE[$namecookie]) ? $_COOKIE[$namecookie] : getstring("chat.default.username");
|
$userName = isset($_COOKIE[$namecookie]) ? $_COOKIE[$namecookie] : getstring("chat.default.username");
|
||||||
|
@ -49,7 +49,7 @@ function thread_to_xml($thread) {
|
|||||||
|
|
||||||
$result .= " canopen=\"true\"";
|
$result .= " canopen=\"true\"";
|
||||||
|
|
||||||
$result .= " state=\"$state\">";
|
$result .= " state=\"$state\" typing=\"".$thread['userTyping']."\">";
|
||||||
$result .= "<name>".htmlspecialchars(htmlspecialchars(get_user_name($thread['userName'])))."</name>";
|
$result .= "<name>".htmlspecialchars(htmlspecialchars(get_user_name($thread['userName'])))."</name>";
|
||||||
$result .= "<addr>".htmlspecialchars(htmlspecialchars($thread['remote']))."</addr>";
|
$result .= "<addr>".htmlspecialchars(htmlspecialchars($thread['remote']))."</addr>";
|
||||||
$result .= "<agent>".htmlspecialchars(htmlspecialchars($threadoperator))."</agent>";
|
$result .= "<agent>".htmlspecialchars(htmlspecialchars($threadoperator))."</agent>";
|
||||||
@ -66,7 +66,7 @@ function print_pending_threads($since) {
|
|||||||
|
|
||||||
$revision = $since;
|
$revision = $since;
|
||||||
$output = array();
|
$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 ".
|
"unix_timestamp(dtmmodified), lrevision, istate, remote ".
|
||||||
"from chatthread where lrevision > $since ORDER BY threadid";
|
"from chatthread where lrevision > $since ORDER BY threadid";
|
||||||
$result = mysql_query($query,$link) or die(' Query failed: ' .mysql_error().": ".$query);
|
$result = mysql_query($query,$link) or die(' Query failed: ' .mysql_error().": ".$query);
|
||||||
|
@ -40,7 +40,7 @@ if( !$isuser && $act != "rename" ) {
|
|||||||
|
|
||||||
if( $act == "refresh" ) {
|
if( $act == "refresh" ) {
|
||||||
$lastid = verifyparam( "lastid", "/^\d{1,9}$/", -1);
|
$lastid = verifyparam( "lastid", "/^\d{1,9}$/", -1);
|
||||||
print_thread_messages($threadid, $token, $lastid, $isuser,$outformat);
|
print_thread_messages($thread, $token, $lastid, $isuser,$outformat);
|
||||||
exit;
|
exit;
|
||||||
|
|
||||||
} else if( $act == "post" ) {
|
} else if( $act == "post" ) {
|
||||||
@ -51,7 +51,7 @@ if( $act == "refresh" ) {
|
|||||||
$from = $isuser ? $thread['userName'] : $thread['agentName'];
|
$from = $isuser ? $thread['userName'] : $thread['agentName'];
|
||||||
|
|
||||||
post_message($threadid,$kind,$message,$from, $isuser ? null : $operator['operatorid'] );
|
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;
|
exit;
|
||||||
|
|
||||||
} else if( $act == "rename" ) {
|
} else if( $act == "rename" ) {
|
||||||
|
Loading…
Reference in New Issue
Block a user