fixed notification system and added a new tenant notifications receipt table to track read status and filter messages by scope.
This commit is contained in:
@@ -2018,6 +2018,8 @@ class EventPublicController extends BaseController
|
||||
[$event] = $result;
|
||||
$guestIdentifier = $this->resolveNotificationIdentifier($request);
|
||||
$limit = max(1, min(50, (int) $request->integer('limit', 35)));
|
||||
$statusFilter = $request->string('status')->lower()->value();
|
||||
$scopeFilter = $request->string('scope')->lower()->value();
|
||||
|
||||
if (! Schema::hasTable('guest_notifications')) {
|
||||
return $this->emptyNotificationsResponse($request, $event->id, 'disabled');
|
||||
@@ -2029,6 +2031,31 @@ class EventPublicController extends BaseController
|
||||
->notExpired()
|
||||
->visibleToGuest($guestIdentifier);
|
||||
|
||||
if ($statusFilter === 'unread') {
|
||||
$baseQuery->where(function ($query) use ($guestIdentifier) {
|
||||
$query->whereDoesntHave('receipts', fn ($receipt) => $receipt->where('guest_identifier', $guestIdentifier))
|
||||
->orWhereHas('receipts', fn ($receipt) => $receipt
|
||||
->where('guest_identifier', $guestIdentifier)
|
||||
->where('status', GuestNotificationDeliveryStatus::NEW->value));
|
||||
});
|
||||
} elseif ($statusFilter === 'read') {
|
||||
$baseQuery->whereHas('receipts', fn ($receipt) => $receipt
|
||||
->where('guest_identifier', $guestIdentifier)
|
||||
->where('status', GuestNotificationDeliveryStatus::READ->value));
|
||||
} elseif ($statusFilter === 'dismissed') {
|
||||
$baseQuery->whereHas('receipts', fn ($receipt) => $receipt
|
||||
->where('guest_identifier', $guestIdentifier)
|
||||
->where('status', GuestNotificationDeliveryStatus::DISMISSED->value));
|
||||
}
|
||||
|
||||
if ($scopeFilter === 'uploads') {
|
||||
$baseQuery->whereIn('type', [GuestNotificationType::UPLOAD_ALERT->value, GuestNotificationType::PHOTO_ACTIVITY->value]);
|
||||
} elseif ($scopeFilter === 'tips') {
|
||||
$baseQuery->whereIn('type', [GuestNotificationType::SUPPORT_TIP->value, GuestNotificationType::ACHIEVEMENT_MAJOR->value]);
|
||||
} elseif ($scopeFilter === 'general') {
|
||||
$baseQuery->whereIn('type', [GuestNotificationType::BROADCAST->value, GuestNotificationType::FEEDBACK_REQUEST->value]);
|
||||
}
|
||||
|
||||
$notifications = (clone $baseQuery)
|
||||
->with(['receipts' => fn ($query) => $query->where('guest_identifier', $guestIdentifier)])
|
||||
->orderByDesc('priority')
|
||||
|
||||
Reference in New Issue
Block a user