Skip to content

Commit 3b37215

Browse files
committed
fix #2434
1 parent 0682ffe commit 3b37215

1 file changed

Lines changed: 23 additions & 12 deletions

File tree

‎lhc_web/lib/core/lhchat/lhchatworkflow.php‎

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -856,19 +856,24 @@ public static function autoAssignMail(& $chat, $department, $params = array())
856856
if ($user_id > 0) {
857857

858858
$previousMessage = '';
859+
$previousUserId = $chat->user_id;
859860

860-
// Update previously assigned operator statistic
861-
if ($chat->user_id > 0) {
862-
erLhcoreClassChat::updateActiveChats($chat->user_id);
863-
864-
$userOld = erLhcoreClassModelUser::fetch($chat->user_id);
865-
$previousMessage = '[' . $chat->user_id . '] ' . $userOld->name_support . ' '. erTranslationClassLhTranslation::getInstance()->getTranslation('chat/adminchat','did not accepted mail in time.') . ' ';
861+
// Prepare previous operator message. Statistics are updated only after the
862+
// owner is changed, otherwise the recount still counts this mail for him
863+
if ($previousUserId > 0) {
864+
$userOld = erLhcoreClassModelUser::fetch($previousUserId);
865+
$previousMessage = '[' . $previousUserId . '] ' . $userOld->name_support . ' '. erTranslationClassLhTranslation::getInstance()->getTranslation('chat/adminchat','did not accepted mail in time.') . ' ';
866866
}
867867

868868
$chat->tslasign = $timestamp;
869869
$chat->user_id = $user_id;
870870
$chat->updateThis(array('update' => array('tslasign','user_id')));
871871

872+
// Update previously assigned operator statistic now, when mail no longer belongs to him
873+
if ($previousUserId > 0 && $previousUserId != $chat->user_id) {
874+
erLhcoreClassChat::updateActiveChats($previousUserId);
875+
}
876+
872877
erLhcoreClassUserDep::updateLastAcceptedByUser($user_id, $timestamp, '_mail');
873878

874879
// Update fresh user statistic
@@ -1179,15 +1184,16 @@ public static function autoAssign(& $chat, $department, $params = array()) {
11791184
$msg->user_id = -1;
11801185
$msg->time = $timestamp;
11811186

1182-
// Update previously assigned operator statistic
1183-
if ($chat->user_id > 0) {
1184-
$userOld = erLhcoreClassModelUser::fetch($chat->user_id);
1187+
$previousUserId = $chat->user_id;
1188+
1189+
// Prepare previous operator message. Statistics are updated after the owner change
1190+
if ($previousUserId > 0) {
1191+
$userOld = erLhcoreClassModelUser::fetch($previousUserId);
11851192
$msg->name_support = $userOld->name_support;
11861193

1187-
erLhcoreClassChatEventDispatcher::getInstance()->dispatch('chat.before_msg_user_saved', array('msg' => & $msg, 'chat' => & $chat, 'user_id' => $chat->user_id));
1194+
erLhcoreClassChatEventDispatcher::getInstance()->dispatch('chat.before_msg_user_saved', array('msg' => & $msg, 'chat' => & $chat, 'user_id' => $previousUserId));
11881195

1189-
$previousMessage = '[' . $chat->user_id . '] ' . $msg->name_support . ' '. erTranslationClassLhTranslation::getInstance()->getTranslation('chat/adminchat','did not accepted chat in time.') . ' ';
1190-
erLhcoreClassChat::updateActiveChats($chat->user_id);
1196+
$previousMessage = '[' . $previousUserId . '] ' . $msg->name_support . ' '. erTranslationClassLhTranslation::getInstance()->getTranslation('chat/adminchat','did not accepted chat in time.') . ' ';
11911197
}
11921198

11931199
$userNew = erLhcoreClassModelUser::fetch($user_id);
@@ -1205,6 +1211,11 @@ public static function autoAssign(& $chat, $department, $params = array()) {
12051211
$chat->last_msg_id = $msg->id;
12061212
$chat->updateThis(array('update' => array('last_msg_id','tslasign','user_id')));
12071213

1214+
// Update previously assigned operator statistic now, when chat no longer belongs to him
1215+
if ($previousUserId > 0 && $previousUserId != $chat->user_id) {
1216+
erLhcoreClassChat::updateActiveChats($previousUserId);
1217+
}
1218+
12081219
$successLastAccepted = erLhcoreClassUserDep::updateLastAcceptedByUser($user_id, $timestamp);
12091220

12101221
// Update fresh user statistic

0 commit comments

Comments
 (0)