From caa90f9f9c64dc1c07c1ebf63d767ddc84f85cf6 Mon Sep 17 00:00:00 2001 From: Dmitriy Simushev Date: Fri, 12 Jul 2013 14:46:31 +0000 Subject: [PATCH] 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. --- src/messenger/webim/client.php | 1 + src/messenger/webim/libs/chat.php | 5 +++++ src/messenger/webim/libs/track.php | 20 ++++++++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/src/messenger/webim/client.php b/src/messenger/webim/client.php index 8ec20acf..6ec8e397 100644 --- a/src/messenger/webim/client.php +++ b/src/messenger/webim/client.php @@ -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") { diff --git a/src/messenger/webim/libs/chat.php b/src/messenger/webim/libs/chat.php index 095df339..9895a3b8 100644 --- a/src/messenger/webim/libs/chat.php +++ b/src/messenger/webim/libs/chat.php @@ -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); diff --git a/src/messenger/webim/libs/track.php b/src/messenger/webim/libs/track.php index ef25cdde..27065add 100644 --- a/src/messenger/webim/libs/track.php +++ b/src/messenger/webim/libs/track.php @@ -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 + ) + ); +} + ?> \ No newline at end of file