Module: NewsmastMastodon::Overrides::NotificationExtendedController
- Defined in:
- app/lib/newsmast_mastodon/overrides/notification_extended_controller.rb
Instance Method Summary collapse
- #browserable_account_notifications ⇒ Object
- #browserable_params ⇒ Object
- #exclude_private_mentions? ⇒ Boolean
- #filter_private_mentions(notifications) ⇒ Object
- #load_grouped_notifications ⇒ Object
- #pagination_params(core_params) ⇒ Object
Instance Method Details
#browserable_account_notifications ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'app/lib/newsmast_mastodon/overrides/notification_extended_controller.rb', line 7 def browserable_account_notifications current_account.notifications.without_suspended.browserable( types: Array(browserable_params[:types]), exclude_types: Array(browserable_params[:exclude_types]), include_filtered: truthy_param?(:include_filtered), only_direct_mentions: truthy_param?(:only_direct_mentions) ) end |
#browserable_params ⇒ Object
49 50 51 |
# File 'app/lib/newsmast_mastodon/overrides/notification_extended_controller.rb', line 49 def browserable_params params.slice(:include_filtered, :types, :exclude_types, :grouped_types, :only_direct_mentions, :exclude_private_mentions).permit(:only_direct_mentions, :include_filtered, :exclude_private_mentions, types: [], exclude_types: [], grouped_types: []) end |
#exclude_private_mentions? ⇒ Boolean
45 46 47 |
# File 'app/lib/newsmast_mastodon/overrides/notification_extended_controller.rb', line 45 def exclude_private_mentions? truthy_param?(:exclude_private_mentions) end |
#filter_private_mentions(notifications) ⇒ Object
39 40 41 42 43 |
# File 'app/lib/newsmast_mastodon/overrides/notification_extended_controller.rb', line 39 def filter_private_mentions(notifications) notifications.reject do |notification| notification.target_status&.visibility == 'direct' end end |
#load_grouped_notifications ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/lib/newsmast_mastodon/overrides/notification_extended_controller.rb', line 16 def load_grouped_notifications return [] if @notifications.empty? MastodonOTELTracer.in_span('Api::V2::NotificationsController#load_grouped_notifications') do pagination_range = (@notifications.last.id)..@notifications.first.id # If the page is incomplete, we know we are on the last page if incomplete_page? if paginating_up? pagination_range = @notifications.last.id...(params[:max_id]&.to_i) else range_start = params[:since_id]&.to_i range_start += 1 unless range_start.nil? pagination_range = range_start..(@notifications.first.id) end end notifications = NotificationGroup.from_notifications(@notifications, pagination_range: pagination_range, grouped_types: params[:grouped_types]) notifications = filter_private_mentions(notifications) if exclude_private_mentions? notifications end end |
#pagination_params(core_params) ⇒ Object
53 54 55 |
# File 'app/lib/newsmast_mastodon/overrides/notification_extended_controller.rb', line 53 def pagination_params(core_params) params.slice(:limit, :include_filtered, :types, :exclude_types, :grouped_types, :only_direct_mentions, :exclude_private_mentions).permit(:limit, :only_direct_mentions, :include_filtered, :exclude_private_mentions, types: [], exclude_types: [], grouped_types: []).merge(core_params) end |