diff --git a/src/messenger/webim/libs/chat.php b/src/messenger/webim/libs/chat.php
index 1588a611..4c3680f4 100644
--- a/src/messenger/webim/libs/chat.php
+++ b/src/messenger/webim/libs/chat.php
@@ -561,6 +561,21 @@ function close_thread($thread, $isuser)
close_connection($link);
}
+function close_old_threads($link)
+{
+ global $state_closed, $state_left, $state_chatting, $mysqlprefix, $settings;
+ if ($settings['thread_lifetime'] == 0) {
+ return;
+ }
+ $next_revision = next_revision($link);
+ $query = "update ${mysqlprefix}chatthread set lrevision = $next_revision, dtmmodified = CURRENT_TIMESTAMP, istate = $state_closed " .
+ "where istate <> $state_closed and istate <> $state_left and " .
+ "(ABS(UNIX_TIMESTAMP(CURRENT_TIMESTAMP) - UNIX_TIMESTAMP(lastpinguser)) > " . $settings['thread_lifetime'] . " and " .
+ "ABS(UNIX_TIMESTAMP(CURRENT_TIMESTAMP) - UNIX_TIMESTAMP(lastpingagent)) > " . $settings['thread_lifetime'] . ")";
+
+ perform_query($query, $link);
+}
+
function thread_by_id_($id, $link)
{
global $mysqlprefix;
@@ -623,13 +638,18 @@ function do_take_thread($threadid, $operatorId, $operatorName, $chatstart = fals
function reopen_thread($threadid)
{
- global $state_queue, $state_loading, $state_waiting, $state_chatting, $state_closed, $state_left, $kind_events;
+ global $state_queue, $state_loading, $state_waiting, $state_chatting, $state_closed, $state_left, $kind_events, $settings;
$link = connect();
+
$thread = thread_by_id_($threadid, $link);
if (!$thread)
return FALSE;
+ if ($settings['thread_lifetime'] != 0 && abs($thread['lpuser'] - time()) > $settings['thread_lifetime'] && abs($thread['lpagent'] - time()) > $settings['thread_lifetime']) {
+ return FALSE;
+ }
+
if ($thread['istate'] == $state_closed || $thread['istate'] == $state_left)
return FALSE;
diff --git a/src/messenger/webim/libs/common.php b/src/messenger/webim/libs/common.php
index c5e3bcf6..b29dcb93 100644
--- a/src/messenger/webim/libs/common.php
+++ b/src/messenger/webim/libs/common.php
@@ -664,6 +664,7 @@ $settings = array(
'geolinkparams' => 'width=440,height=100,toolbar=0,scrollbars=0,location=0,status=1,menubar=0,resizable=1',
'max_uploaded_file_size' => 100000,
'max_connections_from_one_host' => 10,
+ 'thread_lifetime' => 60,
'email' => '', /* inbox for left messages */
'left_messages_locale' => $home_locale,
diff --git a/src/messenger/webim/locales/en/properties b/src/messenger/webim/locales/en/properties
index 19704490..9018f58a 100644
--- a/src/messenger/webim/locales/en/properties
+++ b/src/messenger/webim/locales/en/properties
@@ -491,6 +491,8 @@ settings.survey.askmessage=Show initial question field
settings.title=Messenger settings
settings.trackinglifetime.description=Specify the lifetime of old visitor's tracks in seconds. Default is 600 seconds.
settings.trackinglifetime=Track lifetime
+settings.threadlifetime.description=Specify the lifetime of the thread after closing the dialog box in seconds. Default is 60 seconds. Set 0 for unlimited thread lifetime.
+settings.threadlifetime=Thread lifetime
settings.usercanchangename.description=Turn off to hide edit box from chat window
settings.usercanchangename=Allows users to change their names
settings.usernamepattern.description=How to build visitor's identifying string from {name}, {id} or {addr}. Default: {name}
@@ -499,6 +501,7 @@ settings.visitorslimit.description=Specify the number of items to display in tra
settings.visitorslimit=Limit for tracked visitors list
settings.wrong.email=Enter a valid email address
settings.wrong.onehostconnections="Max number of threads" field should be a number
+settings.wrong.threadlifetime="Thread lifetime" field should be a number
site.title=mibew.org
site.url=http://mibew.org
statistics.dates=Select dates
diff --git a/src/messenger/webim/locales/ru/properties b/src/messenger/webim/locales/ru/properties
index 2d2207d8..e901b141 100644
--- a/src/messenger/webim/locales/ru/properties
+++ b/src/messenger/webim/locales/ru/properties
@@ -481,6 +481,8 @@ settings.survey.askmessage=
settings.title=Настройки мессенджера
settings.trackinglifetime.description=Укажите срок хранения старых отслеженных путей в секундах. По умолчанию, 600 секунд.
settings.trackinglifetime=Срок хранения отслеженных путей
+settings.threadlifetime.description=Укажите время жизни диалога после закрытия диалогового окна в секундах. По умолчанию, 60 секунд. Укажите 0 для снятия ограничения.
+settings.threadlifetime=Время жизни диалога
settings.usercanchangename.description=Возможность убрать поле смены имени из чат окна
settings.usercanchangename=Разрешать посетителям менять имена
settings.usernamepattern.description=Укажите как отобразить имя посетителя операторам. Можно использовать {name}, {id} и {addr}. По умолчанию: {name}
@@ -489,6 +491,7 @@ settings.visitorslimit.description=
settings.visitorslimit=Ограничение на число выводимых в списке отслеживаемых посетителей
settings.wrong.email=Введите правильный адрес электронной почты
settings.wrong.onehostconnections=Поле "Максимальное количество диалогов" должно быть числом
+settings.wrong.threadlifetime=Поле "Время жизни диалога" должно быть числом
site.title=mibew.org
site.url=http://mibew.org
statistics.dates=Выберите даты
diff --git a/src/messenger/webim/operator/performance.php b/src/messenger/webim/operator/performance.php
index be9ffb29..23aac261 100644
--- a/src/messenger/webim/operator/performance.php
+++ b/src/messenger/webim/operator/performance.php
@@ -32,7 +32,7 @@ $options = array(
'online_timeout', 'updatefrequency_operator', 'updatefrequency_chat',
'updatefrequency_oldchat', 'max_connections_from_one_host',
'updatefrequency_tracking', 'visitors_limit', 'invitation_lifetime',
- 'tracking_lifetime' );
+ 'tracking_lifetime', 'thread_lifetime' );
loadsettings();
$params = array();
@@ -66,6 +66,11 @@ if (isset($_POST['onlinetimeout'])) {
$errors[] = getlocal("settings.wrong.onehostconnections");
}
+ $params['thread_lifetime'] = getparam('threadlifetime');
+ if (!is_numeric($params['thread_lifetime'])) {
+ $errors[] = getlocal("settings.wrong.threadlifetime");
+ }
+
if ($settings['enabletracking']) {
$params['updatefrequency_tracking'] = getparam('frequencytracking');
@@ -105,6 +110,7 @@ $page['formfrequencyoperator'] = $params['updatefrequency_operator'];
$page['formfrequencychat'] = $params['updatefrequency_chat'];
$page['formfrequencyoldchat'] = $params['updatefrequency_oldchat'];
$page['formonehostconnections'] = $params['max_connections_from_one_host'];
+$page['formthreadlifetime'] = $params['thread_lifetime'];
if ($settings['enabletracking']) {
diff --git a/src/messenger/webim/operator/update.php b/src/messenger/webim/operator/update.php
index c8694af8..3175dabc 100644
--- a/src/messenger/webim/operator/update.php
+++ b/src/messenger/webim/operator/update.php
@@ -266,6 +266,7 @@ loadsettings_($link);
if (!isset($_SESSION["${mysqlprefix}operatorgroups"])) {
$_SESSION["${mysqlprefix}operatorgroups"] = get_operator_groupslist($operator['operatorid'], $link);
}
+close_old_threads($link);
close_connection($link);
$groupids = $_SESSION["${mysqlprefix}operatorgroups"];
diff --git a/src/messenger/webim/view/performance.php b/src/messenger/webim/view/performance.php
index 937a2224..2da1937c 100644
--- a/src/messenger/webim/view/performance.php
+++ b/src/messenger/webim/view/performance.php
@@ -90,6 +90,15 @@ require_once('inc_errors.php');
+