chore: Add count and current page in notification meta details (#1619)

This commit is contained in:
Muhsin Keloth
2021-01-13 03:34:27 -08:00
committed by GitHub
parent 8c66dbd342
commit 2d5aa9d3bd
3 changed files with 14 additions and 1 deletions

View File

@@ -3,10 +3,12 @@ class Api::V1::Accounts::NotificationsController < Api::V1::Accounts::BaseContro
before_action :fetch_notification, only: [:update]
before_action :set_primary_actor, only: [:read_all]
before_action :set_current_page, only: [:index]
def index
@unread_count = current_user.notifications.where(account_id: current_account.id, read_at: nil).count
@notifications = current_user.notifications.where(account_id: current_account.id).page params[:page]
@count = notifications.count
@notifications = notifications.page @current_page
end
def read_all
@@ -37,4 +39,12 @@ class Api::V1::Accounts::NotificationsController < Api::V1::Accounts::BaseContro
def fetch_notification
@notification = current_user.notifications.find(params[:id])
end
def set_current_page
@current_page = params[:page] || 1
end
def notifications
@notifications ||= current_user.notifications.where(account_id: current_account.id)
end
end