| @@ -31,9 +31,10 @@ | ||
| 31 | 31 | ->orderBy('updated_at', 'DESC') |
| 32 | 32 | ->paginate(); |
| 33 | 33 | |
| 34 | 34 | $data = [ |
| 35 | - 'notifications' => $notifications | |
| 35 | + 'notifications' => $notifications, | |
| 36 | + 'unread_count' => Notification::byStatus('unread', $user->ID)->count() | |
| 36 | 37 | ]; |
| 37 | 38 | return apply_filters('fluent_community/notifications_api_response', $data, $request->all()); |
| 38 | 39 | } |
| 39 | 40 | |
| @@ -53,8 +54,9 @@ | ||
| 53 | 54 | $data = [ |
| 54 | 55 | 'notifications' => $unreadNotifications, |
| 55 | 56 | 'unread_count' => Notification::byStatus('unread', get_current_user_id())->count() |
| 56 | 57 | ]; |
| 58 | + | |
| 57 | 59 | return apply_filters('fluent_community/unread_notifications_api_response', $data, $request->all()); |
| 58 | 60 | } |
| 59 | 61 | |
| 60 | 62 | public function markAllRead(Request $request) |
| @@ -72,10 +74,12 @@ | ||
| 72 | 74 | { |
| 73 | 75 | $notification = Notification::findOrFail($notification_id); |
| 74 | 76 | |
| 75 | 77 | NotificationSubscriber::whereHas('notification', function ($query) use ($notification) { |
| 76 | - return $query->where('id', $notification->id) | |
| 77 | - ->orWhere('feed_id', $notification->feed_id); | |
| 78 | + $query->where('id', $notification->id); | |
| 79 | + if ($notification->feed_id) { | |
| 80 | + $query->orWhere('feed_id', $notification->feed_id); | |
| 81 | + } | |
| 78 | 82 | }) |
| 79 | 83 | ->where('user_id', get_current_user_id()) |
| 80 | 84 | ->update(['is_read' => 1]); |
| 81 | 85 | |
| @@ -85,9 +89,9 @@ | ||
| 85 | 89 | } |
| 86 | 90 | |
| 87 | 91 | public function markAsReadByFeedId(Request $request, $feedId) |
| 88 | 92 | { |
| 89 | - $feed = Feed::findOrfail($feedId); | |
| 93 | + $feed = Feed::withoutGlobalScopes()->findOrFail($feedId); | |
| 90 | 94 | |
| 91 | 95 | NotificationSubscriber::whereHas('notification', function ($query) use ($feed) { |
| 92 | 96 | return $query->where('feed_id', $feed->id); |
| 93 | 97 | }) |