Skip to content

Commit 92dcc67

Browse files
committed
Ensure that online profile is assigned to pushed chats
1 parent acf77ed commit 92dcc67

3 files changed

Lines changed: 27 additions & 8 deletions

File tree

lhc_web/design/defaulttheme/tpl/lhwebhooks/pushchat.tpl.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<?php include(erLhcoreClassDesign::designtpl('lhkernel/alert_success.tpl.php'));?>
99
<?php endif; ?>
1010

11-
<?php if (isset($chat)) : ?>
11+
<?php if (isset($chat) && $chat->id > 0) : ?>
1212
<a href="#/chat-id-<?php echo $chat->id?>" class="action-image" data-title="<?php echo erLhcoreClassDesign::shrt($chat->nick,10,'...',30,ENT_QUOTES);?>" onclick="lhinst.startChatNewWindow(<?php echo $chat->id?>,$(this).attr('data-title'))" title="<?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('webhook/push','Open chat')?>"><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('webhook/push','Open chat')?></a>
1313
<?php endif; ?>
1414

lhc_web/lib/core/lhchat/lhchatwebhookincomming.php

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2672,7 +2672,7 @@ public static function parseFilesDecode($params, $chat) {
26722672
return null;
26732673
}
26742674

2675-
public static function sendMessage($incomingWebhook, $item) {
2675+
public static function sendMessage($incomingWebhook, $item, $userData) {
26762676

26772677
$db = ezcDbInstance::get();
26782678

@@ -2692,7 +2692,17 @@ public static function sendMessage($incomingWebhook, $item) {
26922692
$incomingChat->incoming_id = $incomingWebhook->id;
26932693
}
26942694

2695-
$chat = new erLhcoreClassModelChat();
2695+
$vid = md5($incomingWebhook->id . '_' . $incomingChat->chat_external_id);
2696+
2697+
if (($onlineUser = erLhcoreClassModelChatOnlineUser::fetchByVid($vid)) !== false) {
2698+
if (erLhcoreClassModelChatBlockedUser::isBlocked(['online_user_id' => $onlineUser->id])) {
2699+
throw new Exception('Blocked by online visitor profile!');
2700+
}
2701+
}
2702+
2703+
if (($chat = $incomingChat->chat) === false || $chat->status === erLhcoreClassModelChat::STATUS_CLOSED_CHAT) {
2704+
$chat = new erLhcoreClassModelChat();
2705+
}
26962706

26972707
if ($item->dep_id > 0) {
26982708
$chat->dep_id = $item->dep_id;
@@ -2737,16 +2747,14 @@ public static function sendMessage($incomingWebhook, $item) {
27372747
$msg->time = time();
27382748
$msg->saveThis();
27392749

2740-
if ($item->close_chat == 1) {
2741-
$chat->status = erLhcoreClassModelChat::STATUS_CLOSED_CHAT;
2742-
}
2743-
27442750
/**
27452751
* Set appropriate chat attributes
27462752
*/
27472753
$chat->last_msg_id = $msg->id;
27482754
$chat->last_user_msg_time = $msg->time;
27492755
$chat->saveThis();
2756+
2757+
self::assignOnlineVisitor($chat, $incomingChat);
27502758
}
27512759

27522760
$incomingChat->chat_id = $chat->id;
@@ -2766,6 +2774,13 @@ public static function sendMessage($incomingWebhook, $item) {
27662774
'chat' => & $chat,
27672775
'msg' => $msg
27682776
));
2777+
2778+
if ($item->close_chat == 1) {
2779+
erLhcoreClassChatHelper::closeChat(array(
2780+
'user' => $userData,
2781+
'chat' => $chat,
2782+
));
2783+
}
27692784
}
27702785

27712786
} catch (Exception $e) {

lhc_web/modules/lhwebhooks/pushchat.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,11 @@
9797
$item->user_id = $userData->id;
9898
$item->name_support = (string)$userData->name_support;
9999

100-
$chat = erLhcoreClassChatWebhookIncoming::sendMessage(erLhcoreClassModelChatIncomingWebhook::fetch($item->incoming_api_id), $item);
100+
$chat = erLhcoreClassChatWebhookIncoming::sendMessage(
101+
erLhcoreClassModelChatIncomingWebhook::fetch($item->incoming_api_id),
102+
$item,
103+
$userData
104+
);
101105

102106
$tpl->set('updated', true);
103107
$tpl->set('chat', $chat);

0 commit comments

Comments
 (0)