Module: NewsmastMastodon::Concerns::FeedConcern
- Extended by:
- ActiveSupport::Concern
- Includes:
- Redisable
- Defined in:
- app/models/newsmast_mastodon/concerns/feed_concern.rb
Instance Method Summary collapse
- #fetch_grouped_admin_account_ids ⇒ Object
-
#filter_and_cache_statuses(unhydrated) ⇒ Object
Keep content_filters semantics: apply ban-list filtering from FeedService.
- #from_redis(limit, max_id, since_id, min_id, exclude_direct_statuses = nil, exclude_followed_tags = nil, exclude_replies = nil, grouped_admin_statuses = nil) ⇒ Object
- #get(limit, max_id = nil, since_id = nil, min_id = nil, account = nil, exclude_direct_statuses = false, exclude_followed_tags = false, exclude_replies = false, grouped_admin_statuses = false) ⇒ Object
Instance Method Details
#fetch_grouped_admin_account_ids ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'app/models/newsmast_mastodon/concerns/feed_concern.rb', line 84 def fetch_grouped_admin_account_ids Rails.cache.fetch('grouped_admin_account_ids', expires_in: 1.hour) do NewsmastMastodon::CommunityAdmin .includes(:community) .where( is_boost_bot: true, account_status: NewsmastMastodon::CommunityAdmin.account_statuses[:active], community: { channel_type: NewsmastMastodon::Community.channel_types[:channel_feed] } ) .pluck(:account_id) .uniq end end |
#filter_and_cache_statuses(unhydrated) ⇒ Object
Keep content_filters semantics: apply ban-list filtering from FeedService.
76 77 78 79 80 81 82 |
# File 'app/models/newsmast_mastodon/concerns/feed_concern.rb', line 76 def filter_and_cache_statuses(unhydrated) filter_service = NewsmastMastodon::FeedService.new banned_ids = filter_service.excluded_status_ids @statuses = Status.where(id: unhydrated) @statuses = @statuses.where.not(id: banned_ids) if banned_ids.any? @statuses end |
#from_redis(limit, max_id, since_id, min_id, exclude_direct_statuses = nil, exclude_followed_tags = nil, exclude_replies = nil, grouped_admin_statuses = nil) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'app/models/newsmast_mastodon/concerns/feed_concern.rb', line 34 def from_redis(limit, max_id, since_id, min_id, exclude_direct_statuses = nil, = nil, exclude_replies = nil, grouped_admin_statuses = nil) max_id = '+inf' if max_id.blank? unhydrated = if min_id.blank? since_id = '-inf' if since_id.blank? redis.zrevrangebyscore(key, "(#{max_id}", "(#{since_id}", limit: [0, limit], with_scores: true).map { |id| id.first.to_i } else redis.zrangebyscore(key, "(#{min_id}", "(#{max_id}", limit: [0, limit], with_scores: true).map { |id| id.first.to_i } end filter_and_cache_statuses(unhydrated) # Use where.not(visibility: direct) per plan — preserves `private` visibility (the # content_filters variant used `where(visibility: %i(public unlisted))` which dropped private posts). @statuses = @statuses.where.not(visibility: %i(direct)) if exclude_direct_statuses if followed_tag_ids = @account..pluck(:id) @statuses = @statuses.tagged_without(followed_tag_ids) end @statuses = @statuses.where(reply: false) if exclude_replies if grouped_admin_statuses return @statuses unless Status.column_names.include?('local_only') grouped_admin_account_ids = fetch_grouped_admin_account_ids if grouped_admin_account_ids.any? @statuses = @statuses.where.not(account_id: grouped_admin_account_ids, local_only: true, local: true) # Also exclude reblogs of grouped admin accounts' local_only statuses. grouped_admin_reblogged_ids = Status.where(account_id: grouped_admin_account_ids, local_only: true, local: true).pluck(:reblog_of_id).compact @statuses = @statuses.where.not(id: grouped_admin_reblogged_ids) if grouped_admin_reblogged_ids.any? end end @statuses end |
#get(limit, max_id = nil, since_id = nil, min_id = nil, account = nil, exclude_direct_statuses = false, exclude_followed_tags = false, exclude_replies = false, grouped_admin_statuses = false) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/models/newsmast_mastodon/concerns/feed_concern.rb', line 18 def get(limit, max_id = nil, since_id = nil, min_id = nil, account = nil, exclude_direct_statuses = false, = false, exclude_replies = false, grouped_admin_statuses = false) @account = account if account.present? && limit = limit.to_i max_id = max_id.to_i if max_id.present? since_id = since_id.to_i if since_id.present? min_id = min_id.to_i if min_id.present? from_redis( limit, max_id, since_id, min_id, exclude_direct_statuses, , exclude_replies, grouped_admin_statuses ) end |