Module: NewsmastMastodon::Concerns::FeedManagerConcern
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/newsmast_mastodon/concerns/feed_manager_concern.rb
Instance Method Summary collapse
-
#filter_from_custom?(status, account, crutches = nil) ⇒ Boolean
Filter for custom timeline.
-
#merge_into_custom(from_account, into_account) ⇒ void
Merge an account’s statuses into custom timeline.
-
#populate_custom(account) ⇒ void
Populate custom timeline from scratch.
-
#push_to_custom(account, status, update: false) ⇒ Boolean
Push a status to custom timeline.
-
#unmerge_from_custom(from_account, into_account) ⇒ void
Remove an account’s statuses from custom timeline.
-
#unpush_from_custom(account, status, update: false) ⇒ Boolean
Remove a status from custom timeline.
Instance Method Details
#filter_from_custom?(status, account, crutches = nil) ⇒ Boolean
Filter for custom timeline.
126 127 128 129 130 131 132 133 |
# File 'app/models/newsmast_mastodon/concerns/feed_manager_concern.rb', line 126 def filter_from_custom?(status, account, crutches = nil) crutches ||= build_crutches(account.id, [status]) base_filter = filter_from_home(status, account.id, crutches, :custom) return true if base_filter == :filter false end |
#merge_into_custom(from_account, into_account) ⇒ void
This method returns an undefined value.
Merge an account’s statuses into custom timeline.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'app/models/newsmast_mastodon/concerns/feed_manager_concern.rb', line 79 def merge_into_custom(from_account, into_account) return unless into_account.user&.signed_in_recently? timeline_key = key(:custom, into_account.id) aggregate = into_account.user&.aggregates_reblogs? query = from_account.statuses.list_eligible_visibility .includes(:preloadable_poll, :media_attachments, reblog: :account) .limit(FeedManager::MAX_ITEMS / 4) if redis.zcard(timeline_key) >= FeedManager::MAX_ITEMS / 4 oldest_score = redis.zrange(timeline_key, 0, 0, with_scores: true).first.last.to_i query = query.where('id > ?', oldest_score) end statuses = query.to_a crutches = build_crutches(into_account.id, statuses) statuses.each do |status| next if filter_from_custom?(status, into_account, crutches) add_to_feed(:custom, into_account.id, status, aggregate_reblogs: aggregate) end trim(:custom, into_account.id) end |
#populate_custom(account) ⇒ void
This method returns an undefined value.
Populate custom timeline from scratch.
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_manager_concern.rb', line 52 def populate_custom(account) limit = FeedManager::MAX_ITEMS / 2 aggregate = account.user&.aggregates_reblogs? timeline_key = key(:custom, account.id) statuses = Status .where(account: custom_timeline_accounts_for(account)) .list_eligible_visibility .includes(:preloadable_poll, :media_attachments, :account, reblog: :account) .limit(limit) .order(id: :desc) crutches = build_crutches(account.id, statuses) statuses.each do |status| next if filter_from_custom?(status, account, crutches) add_to_feed(:custom, account.id, status, aggregate_reblogs: aggregate) end trim(:custom, account.id) end |
#push_to_custom(account, status, update: false) ⇒ Boolean
Push a status to custom timeline.
19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/models/newsmast_mastodon/concerns/feed_manager_concern.rb', line 19 def push_to_custom(account, status, update: false) return false unless account.user&.signed_in_recently? return false if filter_from_custom?(status, account) return false unless add_to_feed(:custom, account.id, status, aggregate_reblogs: account.user&.aggregates_reblogs?) trim(:custom, account.id) if push_update_required?("timeline:custom:#{account.id}") PushUpdateWorker.perform_async(account.id, status.id, "timeline:custom:#{account.id}", { 'update' => update }) end true end |
#unmerge_from_custom(from_account, into_account) ⇒ void
This method returns an undefined value.
Remove an account’s statuses from custom timeline.
109 110 111 112 113 114 115 116 117 118 119 |
# File 'app/models/newsmast_mastodon/concerns/feed_manager_concern.rb', line 109 def unmerge_from_custom(from_account, into_account) timeline_key = key(:custom, into_account.id) timeline_status_ids = redis.zrange(timeline_key, 0, -1) from_account.statuses.select(:id, :reblog_of_id) .where(id: timeline_status_ids) .reorder(nil) .find_each do |status| remove_from_feed(:custom, into_account.id, status, aggregate_reblogs: into_account.user&.aggregates_reblogs?) end end |
#unpush_from_custom(account, status, update: false) ⇒ Boolean
Remove a status from custom timeline.
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/models/newsmast_mastodon/concerns/feed_manager_concern.rb', line 36 def unpush_from_custom(account, status, update: false) return false unless NewsmastMastodon::CommunityAdmin.table_exists? return false unless NewsmastMastodon::CommunityAdmin.exists?( is_boost_bot: true, account_id: account.id, account_status: NewsmastMastodon::CommunityAdmin.account_statuses[:active] ) return false unless remove_from_feed(:custom, account.id, status, aggregate_reblogs: account.user&.aggregates_reblogs?) redis.publish("timeline:custom:#{account.id}", Oj.dump(event: :delete, payload: status.id.to_s)) unless update true end |