| @@ -3,8 +3,9 @@ | ||
| 3 | 3 | namespace FluentBooking\App\Hooks\Handlers; |
| 4 | 4 | |
| 5 | 5 | use FluentBooking\App\Models\Booking; |
| 6 | 6 | use FluentBooking\App\Services\EmailNotificationService; |
| 7 | +use FluentBooking\App\Services\NotificationGate; | |
| 7 | 8 | use FluentBooking\Framework\Support\Arr; |
| 8 | 9 | |
| 9 | 10 | class NotificationHandler |
| 10 | 11 | { |
| @@ -35,8 +36,11 @@ | ||
| 35 | 36 | } |
| 36 | 37 | |
| 37 | 38 | private function pushRemindersToQueue($booking, $reminderTimes, $emailTo) |
| 38 | 39 | { |
| 40 | + // A booking can be scheduled again (e.g. no_show back to scheduled); replace, don't stack. | |
| 41 | + \as_unschedule_all_actions('fluent_booking/booking_schedule_reminder', [$booking->id, $emailTo], 'fluent-booking'); | |
| 42 | + | |
| 39 | 43 | $this->clearGroupRemindersForHost($booking, $emailTo); |
| 40 | 44 | |
| 41 | 45 | foreach ($reminderTimes as $time) { |
| 42 | 46 | $reminderTimestamp = $this->getReminderTime($time); |
| @@ -70,15 +74,8 @@ | ||
| 70 | 74 | public function pushBookingScheduledToQueue($booking, $bookingEvent) |
| 71 | 75 | { |
| 72 | 76 | $notifications = $bookingEvent->getNotifications(); |
| 73 | 77 | |
| 74 | - if (Arr::isTrue($notifications, 'booking_conf_attendee.enabled') || (Arr::isTrue($notifications, 'booking_conf_host.enabled'))) { | |
| 75 | - as_enqueue_async_action('fluent_booking/after_booking_scheduled_async', [ | |
| 76 | - $booking->id, | |
| 77 | - $bookingEvent->id | |
| 78 | - ], 'fluent-booking'); | |
| 79 | - } | |
| 80 | - | |
| 81 | 78 | if (Arr::isTrue($notifications, 'reminder_to_attendee.enabled')) { |
| 82 | 79 | $reminderTimes = Arr::get($notifications, 'reminder_to_attendee.email.times', []); |
| 83 | 80 | $this->pushRemindersToQueue($booking, $reminderTimes, 'guest'); |
| 84 | 81 | } |
| @@ -86,12 +83,31 @@ | ||
| 86 | 83 | if (Arr::isTrue($notifications, 'reminder_to_host.enabled')) { |
| 87 | 84 | $reminderTimes = Arr::get($notifications, 'reminder_to_host.email.times', []); |
| 88 | 85 | $this->pushRemindersToQueue($booking, $reminderTimes, 'host'); |
| 89 | 86 | } |
| 87 | + | |
| 88 | + if (!is_null($booking->parent_id) && $booking->isRecurringBooking()) { | |
| 89 | + return; | |
| 90 | + } | |
| 91 | + | |
| 92 | + if (NotificationGate::isSuppressed('booking_scheduled', $booking)) { | |
| 93 | + return; | |
| 94 | + } | |
| 95 | + | |
| 96 | + if (Arr::isTrue($notifications, 'booking_conf_attendee.enabled') || (Arr::isTrue($notifications, 'booking_conf_host.enabled'))) { | |
| 97 | + as_enqueue_async_action('fluent_booking/after_booking_scheduled_async', [ | |
| 98 | + $booking->id, | |
| 99 | + $bookingEvent->id | |
| 100 | + ], 'fluent-booking'); | |
| 101 | + } | |
| 90 | 102 | } |
| 91 | 103 | |
| 92 | 104 | public function pushBookingPendingToQueue($booking, $bookingEvent) |
| 93 | 105 | { |
| 106 | + if (NotificationGate::isSuppressed('booking_pending', $booking)) { | |
| 107 | + return; | |
| 108 | + } | |
| 109 | + | |
| 94 | 110 | if (!$bookingEvent->isConfirmationEnabled() || $bookingEvent->isMultiGuestEvent()) { |
| 95 | 111 | return; |
| 96 | 112 | } |
| 97 | 113 | |
| @@ -98,8 +114,12 @@ | ||
| 98 | 114 | if ($booking->payment_method && $booking->payment_status != 'paid') { |
| 99 | 115 | return; |
| 100 | 116 | } |
| 101 | 117 | |
| 118 | + if (!is_null($booking->parent_id) && $booking->isRecurringBooking()) { | |
| 119 | + return; | |
| 120 | + } | |
| 121 | + | |
| 102 | 122 | $notifications = $bookingEvent->getNotifications(); |
| 103 | 123 | |
| 104 | 124 | if (Arr::isTrue($notifications, 'booking_request_host.enabled') || (Arr::isTrue($notifications, 'booking_request_attendee.enabled'))) { |
| 105 | 125 | as_enqueue_async_action('fluent_booking/after_booking_pending_async', [ |
| @@ -110,8 +130,12 @@ | ||
| 110 | 130 | } |
| 111 | 131 | |
| 112 | 132 | public function emailToUpdatedEmail($booking, $calendarEvent) |
| 113 | 133 | { |
| 134 | + if (NotificationGate::isSuppressed('booking_email_changed', $booking)) { | |
| 135 | + return; | |
| 136 | + } | |
| 137 | + | |
| 114 | 138 | $notifications = $calendarEvent->getNotifications(); |
| 115 | 139 | |
| 116 | 140 | if (Arr::isTrue($notifications, 'booking_conf_attendee.enabled') || (Arr::isTrue($notifications, 'booking_conf_host.enabled'))) { |
| 117 | 141 | as_enqueue_async_action('fluent_booking/after_booking_scheduled_async', [ |
| @@ -220,9 +244,9 @@ | ||
| 220 | 244 | } |
| 221 | 245 | |
| 222 | 246 | public function emailOnBookingCancelled(Booking $booking, $calendarEvent) |
| 223 | 247 | { |
| 224 | - if (!$calendarEvent) { | |
| 248 | + if (!$calendarEvent || NotificationGate::isSuppressed('booking_cancelled', $booking)) { | |
| 225 | 249 | return; |
| 226 | 250 | } |
| 227 | 251 | |
| 228 | 252 | $notifications = $calendarEvent->getNotifications(); |
| @@ -275,8 +299,12 @@ | ||
| 275 | 299 | $reminderTimes = Arr::get($notifications, 'reminder_to_host.email.times', []); |
| 276 | 300 | $this->pushRemindersToQueue($booking, $reminderTimes, 'host'); |
| 277 | 301 | } |
| 278 | 302 | |
| 303 | + if (NotificationGate::isSuppressed('booking_rescheduled', $booking)) { | |
| 304 | + return; | |
| 305 | + } | |
| 306 | + | |
| 279 | 307 | $rescheduledBy = $booking->getMeta('rescheduled_by_type', 'host'); |
| 280 | 308 | |
| 281 | 309 | if ($rescheduledBy == 'host') { |
| 282 | 310 | if (Arr::isTrue($notifications, 'rescheduled_by_host.enabled')) { |
| @@ -298,9 +326,9 @@ | ||
| 298 | 326 | } |
| 299 | 327 | |
| 300 | 328 | public function emailOnBookingRejected(Booking $booking, $calendarEvent) |
| 301 | 329 | { |
| 302 | - if (!$calendarEvent) { | |
| 330 | + if (!$calendarEvent || NotificationGate::isSuppressed('booking_rejected', $booking)) { | |
| 303 | 331 | return; |
| 304 | 332 | } |
| 305 | 333 | |
| 306 | 334 | $notifications = $calendarEvent->getNotifications(); |