| @@ -2,9 +2,9 @@ | ||
| 2 | 2 | /** |
| 3 | 3 | * @package VikBooking |
| 4 | 4 | * @subpackage core |
| 5 | 5 | * @author E4J s.r.l. |
| 6 | - * @copyright Copyright (C) 2021 E4J s.r.l. All Rights Reserved. | |
| 6 | + * @copyright Copyright (C) 2026 E4J s.r.l. All Rights Reserved. | |
| 7 | 7 | * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL |
| 8 | 8 | * @link https://vikwp.com |
| 9 | 9 | */ |
| 10 | 10 | |
| @@ -18,8 +18,9 @@ | ||
| 18 | 18 | */ |
| 19 | 19 | class VBOChatUserAdmin extends VBOChatUseraware implements VBOChatNotifiable |
| 20 | 20 | { |
| 21 | 21 | use VBOChatNotificationWebpush; |
| 22 | + use VBOChatNotificationApp; | |
| 22 | 23 | |
| 23 | 24 | /** @var JUser */ |
| 24 | 25 | protected $user; |
| 25 | 26 | |
| @@ -100,8 +101,29 @@ | ||
| 100 | 101 | * @see VBOChatNotifiable |
| 101 | 102 | */ |
| 102 | 103 | public function scheduleNotification(VBOChatMessage $message, VBOChatUser $user) |
| 103 | 104 | { |
| 105 | + /** @var VBOChatContext */ | |
| 106 | + $context = $message->getContext(); | |
| 107 | + | |
| 108 | + if ($context->getAlias() === 'session') { | |
| 109 | + /** @var array */ | |
| 110 | + $metadata = $context->getMetadata(); | |
| 111 | + | |
| 112 | + // proceed only in case the AI is actually supported and the current context | |
| 113 | + // still supports automatic AI replies | |
| 114 | + if (VBOChatUserAi::isSupported() && $metadata['use_ai']) { | |
| 115 | + // obtain the last 2 messages for this context | |
| 116 | + $lastMessages = VBOFactory::getChatMediator()->getMessages((new VBOChatSearch)->limit(2)->withContext($context)); | |
| 117 | + | |
| 118 | + // send a notification only when the session starts (first message sent) | |
| 119 | + if (count($lastMessages) > 1) { | |
| 120 | + // the thread owns 2+ messages, we don't need to send further notifications | |
| 121 | + return; | |
| 122 | + } | |
| 123 | + } | |
| 124 | + } | |
| 125 | + | |
| 104 | 126 | /** |
| 105 | 127 | * Enqueues a message for the admin within the notification center. |
| 106 | 128 | * |
| 107 | 129 | * @see VBOChatNotificationWebpush |
| @@ -106,6 +128,14 @@ | ||
| 106 | 128 | * |
| 107 | 129 | * @see VBOChatNotificationWebpush |
| 108 | 130 | */ |
| 109 | 131 | $this->sendWebPushNotification($message, $user); |
| 132 | + | |
| 133 | + /** | |
| 134 | + * Send notification to the mobile APP as well. | |
| 135 | + * | |
| 136 | + * @since 1.8.15 | |
| 137 | + * @see VBOChatNotificationApp | |
| 138 | + */ | |
| 139 | + $this->scheduleAppNotification($message, 'admin'); | |
| 110 | 140 | } |
| 111 | 141 | } |