1 # frozen_string_literal: true
3 class Api
::V1::NotificationsController < Api
::BaseController
4 before_action
-> { doorkeeper_authorize!
:read }
5 before_action
:require_user!
6 after_action
:insert_pagination_headers, only
: :index
10 DEFAULT_NOTIFICATIONS_LIMIT
= 15
13 @notifications = load_notifications
14 set_maps_for_notification_target_statuses
18 @notification = current_account
.notifications
.find(params
[:id])
22 current_account
.notifications
.delete_all
27 current_account
.notifications
.find_by!
(id
: params
[:id]).destroy!
33 def load_notifications
34 cache_collection paginated_notifications
, Notification
37 def paginated_notifications
38 browserable_account_notifications
.paginate_by_max_id(
39 limit_param(DEFAULT_NOTIFICATIONS_LIMIT
),
45 def browserable_account_notifications
46 current_account
.notifications
.browserable(exclude_types
)
49 def set_maps_for_notification_target_statuses
50 set_maps target_statuses_from_notifications
53 def target_statuses_from_notifications
54 @notifications.select
{ |notification
| !notification
.target_status
.nil? }.map(&:target_status)
57 def insert_pagination_headers
58 set_pagination_headers(next_path
, prev_path
)
62 unless @notifications.empty
?
63 api_v1_notifications_url
pagination_params(max_id
: pagination_max_id
)
68 unless @notifications.empty
?
69 api_v1_notifications_url
pagination_params(since_id
: pagination_since_id
)
74 @notifications.last
.id
77 def pagination_since_id
78 @notifications.first
.id
82 val
= params
.permit(exclude_types
: [])[:exclude_types] || []
83 val
= [val
] unless val
.is_a
?(Enumerable
)
87 def pagination_params(core_params
)
88 params
.permit(:limit, exclude_types
: []).merge(core_params
)