From d70ed401cb85d10d32c6a4214fad13a27098de87 Mon Sep 17 00:00:00 2001 From: Dmitriy Simushev Date: Fri, 24 May 2013 12:44:24 +0000 Subject: [PATCH] Send messages about close invitation by timeout --- src/messenger/webim/libs/invitation.php | 26 +++++++++++++++++++++++ src/messenger/webim/locales/en/properties | 1 + src/messenger/webim/locales/ru/properties | 1 + 3 files changed, 28 insertions(+) diff --git a/src/messenger/webim/libs/invitation.php b/src/messenger/webim/libs/invitation.php index 0e4f0d04..447e7270 100644 --- a/src/messenger/webim/libs/invitation.php +++ b/src/messenger/webim/libs/invitation.php @@ -215,6 +215,21 @@ function invitation_reject($visitor_id) { function invitation_close_old() { $db = Database::getInstance(); + // Get all threads to close + $threads = $db->query( + "SELECT * FROM {chatthread} " . + "WHERE istate = :state_invited " . + "AND invitationstate = :invitation_wait " . + "AND (:now - dtmcreated) > :lifetime", + array( + ':invitation_wait' => Thread::INVITATION_WAIT, + ':state_invited' => Thread::STATE_INVITED, + ':lifetime' => Settings::get('invitation_lifetime'), + ':now' => time() + ), + array('return_rows' => Database::RETURN_ALL_ROWS) + ); + // Remove old invitations $db->query( "UPDATE {chatsitevisitor} v, {chatthread} t SET " . @@ -233,6 +248,17 @@ function invitation_close_old() { ':now' => time() ) ); + + // Iterate over all threads and send messages to operator about close by + // timeout + foreach($threads as $thread_info) { + $thread = Thread::createFromDbInfo($thread_info); + $thread->postMessage( + Thread::KIND_FOR_AGENT, + getstring_('chat.visitor.invitation.ignored', $thread->locale) + ); + unset($thread); + } } /** diff --git a/src/messenger/webim/locales/en/properties b/src/messenger/webim/locales/en/properties index dd6cbe62..f085fce6 100644 --- a/src/messenger/webim/locales/en/properties +++ b/src/messenger/webim/locales/en/properties @@ -82,6 +82,7 @@ chat.visitor.email=E-Mail: {0} chat.visitor.info=Info: {0} chat.visitor.invitation.accepted=Visitor accepted invitation from operator {0} chat.visitor.invitation.canceled=Operator canceled invitation +chat.visitor.invitation.ignored=Visitor ignored invitation and it was closed automatically chat.visitor.invitation.rejected=Visitor rejected invitation chat.visitor.invitation.sent=Operator {0} invites visitor at {1} page chat.wait=Thank you for contacting us. An operator will be with you shortly. diff --git a/src/messenger/webim/locales/ru/properties b/src/messenger/webim/locales/ru/properties index 6ab15560..35e740ca 100644 --- a/src/messenger/webim/locales/ru/properties +++ b/src/messenger/webim/locales/ru/properties @@ -82,6 +82,7 @@ chat.visitor.email=E-Mail: {0} chat.visitor.info=О Посетителе: {0} chat.visitor.invitation.accepted=Посетитель принял приглашение от оператора {0} chat.visitor.invitation.canceled=Оператор отменил приглашение +chat.visitor.invitation.ignored=Посетитель проигнорировал приглашение и оно было закрыто автоматически chat.visitor.invitation.rejected=Посетитель отклонил приглашение chat.visitor.invitation.sent=Оператор {0} пригласил посетителя на странице {1} chat.wait=Пожалуйста, подождите немного, к Вам присоединится оператор..