Class: CustomFeedsStatusRelationshipsPresenter
- Inherits:
-
Object
- Object
- CustomFeedsStatusRelationshipsPresenter
- Defined in:
- app/presenters/custom_feeds_status_relationships_presenter.rb
Instance Attribute Summary collapse
-
#attributes_map ⇒ Object
readonly
Returns the value of attribute attributes_map.
-
#bookmarks_map ⇒ Object
readonly
Returns the value of attribute bookmarks_map.
-
#favourites_map ⇒ Object
readonly
Returns the value of attribute favourites_map.
-
#filters_map ⇒ Object
readonly
Returns the value of attribute filters_map.
-
#mutes_map ⇒ Object
readonly
Returns the value of attribute mutes_map.
-
#pins_map ⇒ Object
readonly
Returns the value of attribute pins_map.
-
#reblogs_map ⇒ Object
readonly
Returns the value of attribute reblogs_map.
Instance Method Summary collapse
- #boosted?(status) ⇒ Boolean
- #filter_boosted_statuses_inline(statuses) ⇒ Object
- #filtered ⇒ Object
- #get_original_status(boosted_status) ⇒ Object
-
#initialize(statuses, account_id = nil, **options) ⇒ CustomFeedsStatusRelationshipsPresenter
constructor
A new instance of CustomFeedsStatusRelationshipsPresenter.
- #relationship_data_for(status_id) ⇒ Object
- #relationships ⇒ Object
Constructor Details
#initialize(statuses, account_id = nil, **options) ⇒ CustomFeedsStatusRelationshipsPresenter
Returns a new instance of CustomFeedsStatusRelationshipsPresenter.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/presenters/custom_feeds_status_relationships_presenter.rb', line 10 def initialize(statuses, account_id = nil, **) @original_statuses = statuses @original_account_id = account_id filtered_statuses = filter_boosted_statuses_inline(statuses) if account_id.nil? @preloaded_account_relations = {} @filters_map = {} @reblogs_map = {} @favourites_map = {} @bookmarks_map = {} @mutes_map = {} @pins_map = {} @attributes_map = {} else @preloaded_account_relations = nil statuses = filtered_statuses.compact status_ids = statuses.flat_map { |s| [s.id, s.reblog_of_id, s.proper.quote&.quoted_status_id] }.uniq.compact conversation_ids = statuses.flat_map { |s| [s.proper.conversation_id, s.proper.quote&.quoted_status&.conversation_id] }.uniq.compact pinnable_status_ids = statuses.flat_map { |s| [s.proper, s.proper.quote&.quoted_status] }.compact.map { |s| s.id if s.account_id == account_id && %w(public unlisted private).include?(s.visibility) }.compact @filters_map = build_filters_map(statuses.flat_map { |s| [s, s.proper.quote&.quoted_status] }.compact.uniq, account_id).merge([:filters_map] || {}) if defined?(Status) @reblogs_map = Status.reblogs_map(status_ids, account_id).merge([:reblogs_map] || {}) @favourites_map = Status.favourites_map(status_ids, account_id).merge([:favourites_map] || {}) @bookmarks_map = Status.bookmarks_map(status_ids, account_id).merge([:bookmarks_map] || {}) @mutes_map = Status.mutes_map(conversation_ids, account_id).merge([:mutes_map] || {}) @pins_map = Status.pins_map(pinnable_status_ids, account_id).merge([:pins_map] || {}) else @reblogs_map = [:reblogs_map] || {} @favourites_map = [:favourites_map] || {} @bookmarks_map = [:bookmarks_map] || {} @mutes_map = [:mutes_map] || {} @pins_map = [:pins_map] || {} end @attributes_map = [:attributes_map] || {} end end |
Instance Attribute Details
#attributes_map ⇒ Object (readonly)
Returns the value of attribute attributes_map.
7 8 9 |
# File 'app/presenters/custom_feeds_status_relationships_presenter.rb', line 7 def attributes_map @attributes_map end |
#bookmarks_map ⇒ Object (readonly)
Returns the value of attribute bookmarks_map.
7 8 9 |
# File 'app/presenters/custom_feeds_status_relationships_presenter.rb', line 7 def bookmarks_map @bookmarks_map end |
#favourites_map ⇒ Object (readonly)
Returns the value of attribute favourites_map.
7 8 9 |
# File 'app/presenters/custom_feeds_status_relationships_presenter.rb', line 7 def favourites_map @favourites_map end |
#filters_map ⇒ Object (readonly)
Returns the value of attribute filters_map.
7 8 9 |
# File 'app/presenters/custom_feeds_status_relationships_presenter.rb', line 7 def filters_map @filters_map end |
#mutes_map ⇒ Object (readonly)
Returns the value of attribute mutes_map.
7 8 9 |
# File 'app/presenters/custom_feeds_status_relationships_presenter.rb', line 7 def mutes_map @mutes_map end |
#pins_map ⇒ Object (readonly)
Returns the value of attribute pins_map.
7 8 9 |
# File 'app/presenters/custom_feeds_status_relationships_presenter.rb', line 7 def pins_map @pins_map end |
#reblogs_map ⇒ Object (readonly)
Returns the value of attribute reblogs_map.
7 8 9 |
# File 'app/presenters/custom_feeds_status_relationships_presenter.rb', line 7 def reblogs_map @reblogs_map end |
Instance Method Details
#boosted?(status) ⇒ Boolean
64 65 66 |
# File 'app/presenters/custom_feeds_status_relationships_presenter.rb', line 64 def boosted?(status) status.respond_to?(:reblog_id) && !status.reblog_id.nil? end |
#filter_boosted_statuses_inline(statuses) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'app/presenters/custom_feeds_status_relationships_presenter.rb', line 76 def filter_boosted_statuses_inline(statuses) filtered = [] seen_original_ids = Set.new statuses.each do |status| if boosted?(status) original_status = get_original_status(status) if original_status && !seen_original_ids.include?(original_status.id) filtered << original_status seen_original_ids.add(original_status.id) end else filtered << status end end filtered end |
#filtered ⇒ Object
60 61 62 |
# File 'app/presenters/custom_feeds_status_relationships_presenter.rb', line 60 def filtered self end |
#get_original_status(boosted_status) ⇒ Object
68 69 70 71 72 73 74 |
# File 'app/presenters/custom_feeds_status_relationships_presenter.rb', line 68 def get_original_status(boosted_status) if boosted_status.respond_to?(:reblog) && boosted_status.reblog boosted_status.reblog elsif boosted_status.respond_to?(:reblog_id) && boosted_status.reblog_id nil end end |
#relationship_data_for(status_id) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'app/presenters/custom_feeds_status_relationships_presenter.rb', line 95 def relationship_data_for(status_id) return {} if @original_statuses.nil? || @original_statuses.empty? || @original_account_id.nil? filtered_statuses = filter_boosted_statuses_inline(@original_statuses) status = filtered_statuses.find { |s| s.id == status_id } return {} unless status { reblogged: reblogs_map[status.id] || false, favourited: favourites_map[status.id] || false, bookmarked: bookmarks_map[status.id] || false, muted: mutes_map[status.id] || false, pinned: pins_map[status.id] || false, } end |
#relationships ⇒ Object
56 57 58 |
# File 'app/presenters/custom_feeds_status_relationships_presenter.rb', line 56 def relationships self end |