mirror of
https://github.com/mastodon/mastodon.git
synced 2025-05-07 12:16:14 +00:00
Display FASP trends when enabled
This is a temporary measure. The end goal is to interleave local and FASP trends for optimal UX.
This commit is contained in:
parent
a93b247c64
commit
8dc93f718d
|
@ -29,9 +29,13 @@ class Api::V1::Trends::LinksController < Api::BaseController
|
|||
end
|
||||
|
||||
def links_from_trends
|
||||
scope = Trends.links.query.allowed.in_locale(content_locale)
|
||||
scope = scope.filtered_for(current_account) if user_signed_in?
|
||||
scope
|
||||
if Fasp.capability_enabled?('trends')
|
||||
Fasp::PreviewCardTrend.preview_cards(language: user_signed_in? ? current_user.chosen_languages : content_locale)
|
||||
else
|
||||
scope = Trends.links.query.allowed.in_locale(content_locale)
|
||||
scope = scope.filtered_for(current_account) if user_signed_in?
|
||||
scope
|
||||
end
|
||||
end
|
||||
|
||||
def next_path
|
||||
|
|
|
@ -27,9 +27,16 @@ class Api::V1::Trends::StatusesController < Api::BaseController
|
|||
end
|
||||
|
||||
def statuses_from_trends
|
||||
scope = Trends.statuses.query.allowed.in_locale(content_locale)
|
||||
scope = scope.filtered_for(current_account) if user_signed_in?
|
||||
scope
|
||||
if Fasp.capability_enabled?('trends')
|
||||
Fasp::StatusTrend.statuses(
|
||||
language: user_signed_in? ? current_user.chosen_languages : content_locale,
|
||||
filtered_for: current_account
|
||||
)
|
||||
else
|
||||
scope = Trends.statuses.query.allowed.in_locale(content_locale)
|
||||
scope = scope.filtered_for(current_account) if user_signed_in?
|
||||
scope
|
||||
end
|
||||
end
|
||||
|
||||
def next_path
|
||||
|
|
|
@ -27,9 +27,13 @@ class Api::V1::Trends::TagsController < Api::BaseController
|
|||
end
|
||||
|
||||
def tags_from_trends
|
||||
scope = Trends.tags.query.allowed.in_locale(content_locale)
|
||||
scope = scope.filtered_for(current_account) if user_signed_in?
|
||||
scope
|
||||
if Fasp.capability_enabled?('trends')
|
||||
Fasp::TagTrend.tags(language: user_signed_in? ? current_user.chosen_languages : content_locale)
|
||||
else
|
||||
scope = Trends.tags.query.allowed.in_locale(content_locale)
|
||||
scope = scope.filtered_for(current_account) if user_signed_in?
|
||||
scope
|
||||
end
|
||||
end
|
||||
|
||||
def next_path
|
||||
|
|
|
@ -6,4 +6,9 @@ module Fasp
|
|||
def self.table_name_prefix
|
||||
'fasp_'
|
||||
end
|
||||
|
||||
def self.capability_enabled?(capability_name)
|
||||
Mastodon::Feature.fasp_enabled? &&
|
||||
Provider.with_capability(capability_name).any?
|
||||
end
|
||||
end
|
||||
|
|
|
@ -16,4 +16,16 @@
|
|||
class Fasp::PreviewCardTrend < ApplicationRecord
|
||||
belongs_to :preview_card
|
||||
belongs_to :fasp_provider, class_name: 'Fasp::Provider'
|
||||
|
||||
scope :allowed, -> { where(allowed: true) }
|
||||
scope :in_language, ->(language) { where(language:) }
|
||||
scope :ranked, -> { order(rank: :desc) }
|
||||
|
||||
def self.preview_cards(language:)
|
||||
scope = PreviewCard.joins(:fasp_preview_card_trends)
|
||||
.merge(allowed)
|
||||
.merge(ranked)
|
||||
scope = scope.merge(in_language(language)) if language
|
||||
scope
|
||||
end
|
||||
end
|
||||
|
|
|
@ -16,4 +16,17 @@
|
|||
class Fasp::StatusTrend < ApplicationRecord
|
||||
belongs_to :status
|
||||
belongs_to :fasp_provider, class_name: 'Fasp::Provider'
|
||||
|
||||
scope :allowed, -> { where(allowed: true) }
|
||||
scope :in_language, ->(language) { where(language:) }
|
||||
scope :ranked, -> { order(rank: :desc) }
|
||||
|
||||
def self.statuses(language:, filtered_for: nil)
|
||||
scope = Status.joins(:fasp_status_trends)
|
||||
.merge(allowed)
|
||||
.merge(ranked)
|
||||
scope = scope.not_excluded_by_account(filtered_for).not_domain_blocked_by_account(filtered_for) if filtered_for
|
||||
scope = scope.merge(in_language(language)) if language
|
||||
scope
|
||||
end
|
||||
end
|
||||
|
|
|
@ -16,4 +16,16 @@
|
|||
class Fasp::TagTrend < ApplicationRecord
|
||||
belongs_to :tag
|
||||
belongs_to :fasp_provider, class_name: 'Fasp::Provider'
|
||||
|
||||
scope :allowed, -> { where(allowed: true) }
|
||||
scope :in_language, ->(language) { where(language:) }
|
||||
scope :ranked, -> { order(rank: :desc) }
|
||||
|
||||
def self.tags(language:)
|
||||
scope = Tag.joins(:fasp_tag_trends)
|
||||
.merge(allowed)
|
||||
.merge(ranked)
|
||||
scope = scope.merge(in_language(language)) if language
|
||||
scope
|
||||
end
|
||||
end
|
||||
|
|
|
@ -58,6 +58,7 @@ class PreviewCard < ApplicationRecord
|
|||
|
||||
has_many :preview_cards_statuses, dependent: :delete_all, inverse_of: :preview_card
|
||||
has_many :statuses, through: :preview_cards_statuses
|
||||
has_many :fasp_preview_card_trends, class_name: 'Fasp::PreviewCardTrend', dependent: :delete_all
|
||||
|
||||
has_one :trend, class_name: 'PreviewCardTrend', inverse_of: :preview_card, dependent: :destroy
|
||||
belongs_to :author_account, class_name: 'Account', optional: true
|
||||
|
|
|
@ -74,6 +74,7 @@ class Status < ApplicationRecord
|
|||
has_many :mentions, dependent: :destroy, inverse_of: :status
|
||||
has_many :mentioned_accounts, through: :mentions, source: :account, class_name: 'Account'
|
||||
has_many :media_attachments, dependent: :nullify
|
||||
has_many :fasp_status_trends, class_name: 'Fasp::StatusTrend', dependent: :delete_all
|
||||
|
||||
# The `dependent` option is enabled by the initial `mentions` association declaration
|
||||
has_many :active_mentions, -> { active }, class_name: 'Mention', inverse_of: :status # rubocop:disable Rails/HasManyOrHasOneDependent
|
||||
|
|
|
@ -31,6 +31,7 @@ class Tag < ApplicationRecord
|
|||
has_many :passive_relationships, class_name: 'TagFollow', inverse_of: :tag, dependent: :destroy
|
||||
has_many :featured_tags, dependent: :destroy, inverse_of: :tag
|
||||
has_many :followers, through: :passive_relationships, source: :account
|
||||
has_many :fasp_tag_trends, class_name: 'Fasp::TagTrend', dependent: :delete_all
|
||||
|
||||
has_one :trend, class_name: 'TagTrend', inverse_of: :tag, dependent: :destroy
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user