Prevent empty messages from being posted (related to Issue #9)

This commit is contained in:
Fedor A. Fetisov 2013-11-14 15:09:52 +04:00
parent 6eef9e8762
commit 2ff3e8c4f0
3 changed files with 7 additions and 3 deletions

View File

@ -142,8 +142,10 @@ if( !isset($_GET['token']) || !isset($_GET['thread']) ) {
} }
if($firstmessage) { if($firstmessage) {
$postedid = post_message_($thread['threadid'],$kind_user,$firstmessage,$link,$visitor['name']); $postedid = post_message_($thread['threadid'],$kind_user,$firstmessage,$link,$visitor['name']);
if ($postedid) {
commit_thread( $thread['threadid'], array('shownmessageid' => intval($postedid)), $link); commit_thread( $thread['threadid'], array('shownmessageid' => intval($postedid)), $link);
} }
}
notify_operators($thread, $firstmessage, $link); notify_operators($thread, $firstmessage, $link);
mysql_close($link); mysql_close($link);
} }

View File

@ -61,6 +61,9 @@ function next_revision($link)
function post_message_($threadid, $kind, $message, $link, $from = null, $utime = null, $opid = null) function post_message_($threadid, $kind, $message, $link, $from = null, $utime = null, $opid = null)
{ {
global $mysqlprefix; global $mysqlprefix;
if (!isset($message) || preg_match('/^\s*$/', $message)) {
return 0;
}
$query = sprintf( $query = sprintf(
"insert into ${mysqlprefix}chatmessage (threadid,ikind,tmessage,tname,agentId,dtmcreated) values (%s,%s,'%s',%s,%s,%s)", "insert into ${mysqlprefix}chatmessage (threadid,ikind,tmessage,tname,agentId,dtmcreated) values (%s,%s,'%s',%s,%s,%s)",
intval($threadid), intval($threadid),
@ -69,7 +72,6 @@ function post_message_($threadid, $kind, $message, $link, $from = null, $utime =
$from ? "'" . mysql_real_escape_string($from, $link) . "'" : "null", $from ? "'" . mysql_real_escape_string($from, $link) . "'" : "null",
$opid ? intval($opid) : "0", $opid ? intval($opid) : "0",
$utime ? "FROM_UNIXTIME(" . intval($utime) . ")" : "CURRENT_TIMESTAMP"); $utime ? "FROM_UNIXTIME(" . intval($utime) . ")" : "CURRENT_TIMESTAMP");
perform_query($query, $link); perform_query($query, $link);
return mysql_insert_id($link); return mysql_insert_id($link);
} }

View File

@ -75,7 +75,7 @@ if( $act == "refresh" ) {
$link = connect(); $link = connect();
$postedid = post_message_($threadid,$kind,$message,$link,$from,null,$isuser ? null : $operator['operatorid'] ); $postedid = post_message_($threadid,$kind,$message,$link,$from,null,$isuser ? null : $operator['operatorid'] );
if($isuser && $thread["shownmessageid"] == 0) { if($isuser && $postedid && $thread["shownmessageid"] == 0) {
commit_thread( $thread['threadid'], array('shownmessageid' => intval($postedid)), $link); commit_thread( $thread['threadid'], array('shownmessageid' => intval($postedid)), $link);
} }
mysql_close($link); mysql_close($link);