Fix user duplication in visitors and threads lists

User can be either in threads list or in visitors list
but not in both at the same time.
This commit is contained in:
Dmitriy Simushev 2013-07-12 14:46:31 +00:00
parent 862e23e79c
commit caa90f9f9c
3 changed files with 26 additions and 0 deletions

View File

@ -22,6 +22,7 @@ require_once('libs/groups.php');
require_once('libs/expand.php');
require_once('libs/captcha.php');
require_once('libs/invitation.php');
require_once('libs/track.php');
require_once('libs/classes/thread.php');
if(Settings::get('enablessl') == "1" && Settings::get('forcessl') == "1") {

View File

@ -689,6 +689,11 @@ function chat_start_for_user($group_id, $requested_operator, $visitor_id, $visit
$_SESSION['threadid'] = $thread->id;
// Bind thread to the visitor
if (Settings::get('enabletracking')) {
track_visitor_bind_thread($visitor_id, $thread);
}
// Send several messages
if ($is_invited) {
$operator = operator_by_id($thread->agentId);

View File

@ -221,4 +221,24 @@ function track_get_user_id($visitorid) {
return $visitor['userid'];
}
/**
* Bind chat thread with visitor
*
* @param string $user_id User ID ({chatsitevisitor}.userid field) of the
* visitor.
* @param Thread $thread Chat thread object
*/
function track_visitor_bind_thread($user_id, $thread) {
$db = Database::getInstance();
$db->query(
'UPDATE {chatsitevisitor} ' .
'SET threadid = :thread_id ' .
'WHERE userid = :user_id',
array(
':thread_id' => $thread->id,
':user_id' => $user_id
)
);
}
?>