← All changes
|
app/Http/Controllers/NotificationsController.php
+14
-10
1.0.97
→
2.10.01
View file →
| @@ -14,9 +14,9 @@ | ||
| 14 | 14 | public function getNotifications(Request $request) |
| 15 | 15 | { |
| 16 | 16 | $user = $this->getUser(true); |
| 17 | 17 | |
| 18 | - $notifcations = Notification::whereHas('subscribers', function ($query) use ($user) { | |
| 18 | + $notifications = Notification::whereHas('subscribers', function ($query) use ($user) { | |
| 19 | 19 | return $query->where('user_id', $user->ID); |
| 20 | 20 | }) |
| 21 | 21 | ->with([ |
| 22 | 22 | 'xprofile' => function ($q) { |
| @@ -30,11 +30,13 @@ | ||
| 30 | 30 | ->byType($request->get('notification_type', 'all')) |
| 31 | 31 | ->orderBy('updated_at', 'DESC') |
| 32 | 32 | ->paginate(); |
| 33 | 33 | |
| 34 | - return [ | |
| 35 | - 'notifications' => $notifcations | |
| 34 | + $data = [ | |
| 35 | + 'notifications' => $notifications, | |
| 36 | + 'unread_count' => Notification::byStatus('unread', $user->ID)->count() | |
| 36 | 37 | ]; |
| 38 | + return apply_filters('fluent_community/notifications_api_response', $data, $request->all()); | |
| 37 | 39 | } |
| 38 | 40 | |
| 39 | 41 | public function getUnreadNotifications(Request $request) |
| 40 | 42 | { |
| @@ -48,12 +50,14 @@ | ||
| 48 | 50 | ->byType($request->get('notification_type', 'all')) |
| 49 | 51 | ->limit(50) |
| 50 | 52 | ->get(); |
| 51 | 53 | |
| 52 | - return [ | |
| 54 | + $data = [ | |
| 53 | 55 | 'notifications' => $unreadNotifications, |
| 54 | 56 | 'unread_count' => Notification::byStatus('unread', get_current_user_id())->count() |
| 55 | 57 | ]; |
| 58 | + | |
| 59 | + return apply_filters('fluent_community/unread_notifications_api_response', $data, $request->all()); | |
| 56 | 60 | } |
| 57 | 61 | |
| 58 | 62 | public function markAllRead(Request $request) |
| 59 | 63 | { |
| @@ -67,13 +71,15 @@ | ||
| 67 | 71 | } |
| 68 | 72 | |
| 69 | 73 | public function markAsRead(Request $request, $notification_id) |
| 70 | 74 | { |
| 71 | - $notification = Notification::find($notification_id); | |
| 75 | + $notification = Notification::findOrFail($notification_id); | |
| 72 | 76 | |
| 73 | 77 | NotificationSubscriber::whereHas('notification', function ($query) use ($notification) { |
| 74 | - return $query->where('id', $notification->id) | |
| 75 | - ->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 | + } | |
| 76 | 82 | }) |
| 77 | 83 | ->where('user_id', get_current_user_id()) |
| 78 | 84 | ->update(['is_read' => 1]); |
| 79 | 85 | |
| @@ -79,15 +85,13 @@ | ||
| 79 | 85 | |
| 80 | 86 | return [ |
| 81 | 87 | 'unread_count' => Notification::byStatus('unread', get_current_user_id())->count() |
| 82 | 88 | ]; |
| 83 | - | |
| 84 | - return $this->getUnreadNotifications($request); | |
| 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 | }) |