| @@ -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 | |
| @@ -80,11 +80,27 @@ | ||
| 80 | 80 | |
| 81 | 81 | if ($search->hasContext()) { |
| 82 | 82 | // filter by context |
| 83 | 83 | $query->where($this->db->qn('m.context') . ' = ' . $this->db->q($search->getContext()->getAlias())); |
| 84 | - $query->where($this->db->qn('m.id_context') . ' = ' . (int) $search->getContext()->getID()); | |
| 84 | + | |
| 85 | + // filter by context ID only if provided | |
| 86 | + if ($search->getContext()->getID() > 0) { | |
| 87 | + $query->where($this->db->qn('m.id_context') . ' = ' . (int) $search->getContext()->getID()); | |
| 88 | + } | |
| 85 | 89 | } |
| 86 | 90 | |
| 91 | + if ($search->hasCategories()) { | |
| 92 | + // filter by supported contexts | |
| 93 | + $query->where($this->db->qn('m.context') . ' IN (' . implode(',', array_map([$this->db, 'q'], $search->getCategories())) . ')'); | |
| 94 | + } | |
| 95 | + | |
| 96 | + if ($search->hasRefId()) { | |
| 97 | + $refId = $search->getRefId(); | |
| 98 | + | |
| 99 | + // filter by reference ID | |
| 100 | + $query->where($this->db->qn('m.ref_id') . ' = ' . $this->db->q($refId)); | |
| 101 | + } | |
| 102 | + | |
| 87 | 103 | if ($search->hasAggregate()) { |
| 88 | 104 | $inner = $this->db->getQuery(true); |
| 89 | 105 | |
| 90 | 106 | // create inner query to fetch the latest message for each "thread" |
| @@ -178,8 +194,13 @@ | ||
| 178 | 194 | // do not notify myself |
| 179 | 195 | continue; |
| 180 | 196 | } |
| 181 | 197 | |
| 198 | + if ($recipient->getID() == -2) { | |
| 199 | + // skip also in case the recipient is the AI | |
| 200 | + continue; | |
| 201 | + } | |
| 202 | + | |
| 182 | 203 | // register unread notification |
| 183 | 204 | $unreadMessage = new stdClass; |
| 184 | 205 | $unreadMessage->id_message = $message->getID(); |
| 185 | 206 | $unreadMessage->id_sender = (int) $recipient->getID(); |
| @@ -185,8 +206,30 @@ | ||
| 185 | 206 | $unreadMessage->id_sender = (int) $recipient->getID(); |
| 186 | 207 | $this->db->insertObject('#__vikbooking_chat_messages_unread', $unreadMessage, 'id'); |
| 187 | 208 | } |
| 188 | 209 | } |
| 210 | + } | |
| 211 | + | |
| 212 | + /** | |
| 213 | + * @inheritDoc | |
| 214 | + */ | |
| 215 | + public function deleteMessage(VBOChatMessage $message) | |
| 216 | + { | |
| 217 | + // delete message record from the database | |
| 218 | + $query = $this->db->getQuery(true) | |
| 219 | + ->delete($this->db->qn('#__vikbooking_chat_messages')) | |
| 220 | + ->where($this->db->qn('id') . ' = ' . (int) $message->getID()); | |
| 221 | + | |
| 222 | + $this->db->setQuery($query); | |
| 223 | + $this->db->execute(); | |
| 224 | + | |
| 225 | + // delete notification record from the database | |
| 226 | + $query = $this->db->getQuery(true) | |
| 227 | + ->delete($this->db->qn('#__vikbooking_chat_messages_unread')) | |
| 228 | + ->where($this->db->qn('id_message') . ' = ' . (int) $message->getID()); | |
| 229 | + | |
| 230 | + $this->db->setQuery($query); | |
| 231 | + $this->db->execute(); | |
| 189 | 232 | } |
| 190 | 233 | |
| 191 | 234 | /** |
| 192 | 235 | * @inheritDoc |