Skip to content

Commit

Permalink
Same thing but with library
Browse files Browse the repository at this point in the history
  • Loading branch information
nanaya committed Oct 31, 2024
1 parent 74b1fd3 commit 019fdc3
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 21 deletions.
32 changes: 13 additions & 19 deletions app/Libraries/NotificationsBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,33 +76,27 @@ private function fillStacks(string $objectType, int $objectId, string $category)
return;
}

$notificationModel = new Notification();
$userNotificationModel = new UserNotification();
$query = $this
->user
->userNotifications()
->select($userNotificationModel->qualifyColumn('*'))
->hasPushDelivery()
->join(
$notificationModel->getTable(),
$notificationModel->qualifyColumn('id'),
'=',
$userNotificationModel->qualifyColumn('notification_id')
)
->where($notificationModel->qualifyColumn('notifiable_type'), $objectType)
->where($notificationModel->qualifyColumn('notifiable_id'), $objectId)
->whereIn($notificationModel->qualifyColumn('name'), Notification::namesInCategory($category))
->orderByDesc($notificationModel->qualifyColumn('created_at'))
->orderByDesc($notificationModel->qualifyColumn('id'))
->joinRelation('notification', function ($q) use ($category, $objectId, $objectType) {
$q
->where($q->qualifyColumn('notifiable_type'), $objectType)
->where($q->qualifyColumn('notifiable_id'), $objectId)
->whereIn($q->qualifyColumn('name'), Notification::namesInCategory($category))
->orderByDesc($q->qualifyColumn('created_at'))
->orderByDesc($q->qualifyColumn('id'));
if ($this->cursorId !== null) {
$q->where($q->qualifyColumn('id'), '<', $this->cursorId);
}
})
->limit(static::PER_STACK_LIMIT);

if ($this->unreadOnly) {
$query->where('is_read', false);
}

if ($this->cursorId !== null) {
$query->where($notificationModel->qualifyColumn('id'), '<', $this->cursorId);
$query->where($query->qualifyColumn('is_read'), false);
}
$query->select($query->qualifyColumn('*'));

$stack = $query->get();

Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"maennchen/zipstream-php": "^2.1",
"mariuzzo/laravel-js-localization": "*",
"paypal/paypal-checkout-sdk": "*",
"reedware/laravel-relation-joins": "^6.0",
"romanzipp/laravel-turnstile": "^1.3",
"sentry/sentry-laravel": "*",
"shopify/shopify-api": "^5.6",
Expand Down
70 changes: 68 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 019fdc3

Please sign in to comment.