Skip to content

Commit

Permalink
Added closing threads by timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
JustBlackBird authored and inspirer committed Mar 14, 2012
1 parent 36a2d97 commit 323a7f2
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 3 deletions.
24 changes: 22 additions & 2 deletions src/messenger/webim/libs/chat.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -737,4 +757,4 @@ function get_remote_host()
return isset($_SERVER['REMOTE_HOST']) ? $_SERVER['REMOTE_HOST'] : $extAddr;
}

?>
?>
1 change: 1 addition & 0 deletions src/messenger/webim/libs/common.php
Expand Up @@ -615,6 +615,7 @@ function date_to_text($unixtime)
'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,
Expand Down
3 changes: 3 additions & 0 deletions src/messenger/webim/locales/en/properties
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/messenger/webim/locales/ru/properties
Expand Up @@ -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=�������� ����
Expand Down
8 changes: 7 additions & 1 deletion src/messenger/webim/operator/performance.php
Expand Up @@ -30,7 +30,7 @@

$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();
Expand Down Expand Up @@ -64,6 +64,11 @@
$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];
Expand All @@ -78,6 +83,7 @@
$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']);

Expand Down
1 change: 1 addition & 0 deletions src/messenger/webim/operator/update.php
Expand Up @@ -177,6 +177,7 @@ function print_operators()
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"];

Expand Down
9 changes: 9 additions & 0 deletions src/messenger/webim/view/performance.php
Expand Up @@ -90,6 +90,15 @@ function tpl_content() { global $page, $webimroot, $errors;
<br clear="all"/>
</div>

<div class="field">
<div class="flabel"><?php echo getlocal('settings.threadlifetime') ?></div>
<div class="fvalue">
<input type="text" name="threadlifetime" size="40" value="<?php echo form_value('threadlifetime') ?>" class="formauth"/>
</div>
<div class="fdescr"> &mdash; <?php echo getlocal('settings.threadlifetime.description') ?></div>
<br clear="all"/>
</div>

<div class="fbutton">
<input type="image" name="save" value="" src='<?php echo $webimroot.getlocal("image.button.save") ?>' alt='<?php echo getlocal("button.save") ?>'/>
</div>
Expand Down

0 comments on commit 323a7f2

Please sign in to comment.