@@ -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 ) {
0 commit comments