diff --git a/src/messenger/webim/libs/chat.php b/src/messenger/webim/libs/chat.php
index 7deb64f7..0fa2444d 100644
--- a/src/messenger/webim/libs/chat.php
+++ b/src/messenger/webim/libs/chat.php
@@ -552,6 +552,21 @@ function close_thread($thread, $isuser)
mysql_close($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;
@@ -611,13 +626,18 @@ function do_take_thread($threadid, $operatorId, $operatorName)
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;
@@ -737,4 +757,4 @@ function get_remote_host()
return isset($_SERVER['REMOTE_HOST']) ? $_SERVER['REMOTE_HOST'] : $extAddr;
}
-?>
\ No newline at end of file
+?>
diff --git a/src/messenger/webim/libs/common.php b/src/messenger/webim/libs/common.php
index 75a52e69..33070f91 100644
--- a/src/messenger/webim/libs/common.php
+++ b/src/messenger/webim/libs/common.php
@@ -615,6 +615,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' => 600,
'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 cf876ca2..168ce502 100644
--- a/src/messenger/webim/locales/en/properties
+++ b/src/messenger/webim/locales/en/properties
@@ -468,12 +468,15 @@ settings.survey.askmail=Ask for visitor's email
settings.survey.askmessage.description=Show/hide initial question field in the survey
settings.survey.askmessage=Show initial question field
settings.title=Messenger settings
+settings.threadlifetime.description=Specify the lifetime of the thread after closing the dialog box in seconds. Default is 600 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}
settings.usernamepattern=Visitor's identifier
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 677c4d6e..e4578748 100644
--- a/src/messenger/webim/locales/ru/properties
+++ b/src/messenger/webim/locales/ru/properties
@@ -458,12 +458,15 @@ settings.survey.askmail=
settings.survey.askmessage.description=Показать/спрятать поле ввода первого вопроса
settings.survey.askmessage=Предлагать сразу же задать вопрос
settings.title=Настройки мессенджера
+settings.threadlifetime.description=Укажите время жизни диалога после закрытия диалогового окна в секундах. По умолчанию, 600 секунд. Укажите 0 для снятия ограничения.
+settings.threadlifetime=Время жизни диалога
settings.usercanchangename.description=Возможность убрать поле смены имени из чат окна
settings.usercanchangename=Разрешать посетителям менять имена
settings.usernamepattern.description=Укажите как отобразить имя посетителя операторам. Можно использовать {name}, {id} и {addr}. По умолчанию: {name}
settings.usernamepattern=Отображаемое имя посетителя
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 31d52bba..ad8908d2 100644
--- a/src/messenger/webim/operator/performance.php
+++ b/src/messenger/webim/operator/performance.php
@@ -30,7 +30,7 @@ $errors = array();
$options = array(
'online_timeout', 'updatefrequency_operator', 'updatefrequency_chat',
- 'updatefrequency_oldchat', 'max_connections_from_one_host');
+ 'updatefrequency_oldchat', 'max_connections_from_one_host', 'thread_lifetime');
loadsettings();
$params = array();
@@ -64,6 +64,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 (count($errors) == 0) {
foreach ($options as $opt) {
$settings[$opt] = $params[$opt];
@@ -78,6 +83,7 @@ $page['formonlinetimeout'] = $params['online_timeout'];
$page['formfrequencyoperator'] = $params['updatefrequency_operator'];
$page['formfrequencychat'] = $params['updatefrequency_chat'];
$page['formfrequencyoldchat'] = $params['updatefrequency_oldchat'];
+$page['formthreadlifetime'] = $params['thread_lifetime'];
$page['formonehostconnections'] = $params['max_connections_from_one_host'];
$page['stored'] = isset($_GET['stored']);
diff --git a/src/messenger/webim/operator/update.php b/src/messenger/webim/operator/update.php
index e6a9a3bc..eef45ed5 100644
--- a/src/messenger/webim/operator/update.php
+++ b/src/messenger/webim/operator/update.php
@@ -177,6 +177,7 @@ loadsettings_($link);
if (!isset($_SESSION["${mysqlprefix}operatorgroups"])) {
$_SESSION["${mysqlprefix}operatorgroups"] = get_operator_groupslist($operator['operatorid'], $link);
}
+close_old_threads($link);
mysql_close($link);
$groupids = $_SESSION["${mysqlprefix}operatorgroups"];
diff --git a/src/messenger/webim/view/performance.php b/src/messenger/webim/view/performance.php
index 51f2a32e..fa9513bc 100644
--- a/src/messenger/webim/view/performance.php
+++ b/src/messenger/webim/view/performance.php
@@ -90,6 +90,15 @@ require_once('inc_errors.php');
+