Skip to content

Commit

Permalink
unread messages count
Browse files Browse the repository at this point in the history
  • Loading branch information
aothyab committed Jun 24, 2024
1 parent 5c3c794 commit 50f70c5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
8 changes: 6 additions & 2 deletions src/Http/Controllers/API/DiscussionsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,14 @@ public function deleteConversation(Request $request, Discussion $discussion)
}
}

public function discussionsCountForUnReadMessages(Request $request)
/**
* @param Request $request
* @return mixed
*/
public function unreadMessagesCount(Request $request)
{
try {
return apiResponse($this->discussionService->discussionsCountForUnReadMessages());
return apiResponse($this->discussionService->unreadMessagesCount());
} catch (\Exception $e) {
return apiExceptionResponse($e);
}
Expand Down
5 changes: 2 additions & 3 deletions src/Services/DiscussionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,10 @@ public function deleteConversation(Discussion $discussion)
/**
* @return int
*/
public function discussionsCountForUnReadMessages()
public function unreadMessagesCount(): int
{
return Discussion::query()
->forUser(user())
->where('messaging_participations.unread_counts', '>', 0)
->count();
->sum('messaging_participations.unread_counts');
}
}
2 changes: 1 addition & 1 deletion src/routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
});

Route::post('discussions/{discussion}/mark-as-read', 'DiscussionsController@markAsRead');
Route::get('discussions/un-read-messages', 'DiscussionsController@discussionsCountForUnReadMessages');
Route::get('discussions/un-read-messages', 'DiscussionsController@unreadMessagesCount');

Route::post('discussions/{discussion}/delete-conversation', 'DiscussionsController@deleteConversation');

Expand Down

0 comments on commit 50f70c5

Please sign in to comment.