mirror of
https://github.com/mastodon/mastodon.git
synced 2025-05-28 20:47:10 +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,10 +29,14 @@ class Api::V1::Trends::LinksController < Api::BaseController
|
||||||
end
|
end
|
||||||
|
|
||||||
def links_from_trends
|
def links_from_trends
|
||||||
|
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 = Trends.links.query.allowed.in_locale(content_locale)
|
||||||
scope = scope.filtered_for(current_account) if user_signed_in?
|
scope = scope.filtered_for(current_account) if user_signed_in?
|
||||||
scope
|
scope
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def next_path
|
def next_path
|
||||||
api_v1_trends_links_url pagination_params(offset: offset_param + limit_param(DEFAULT_LINKS_LIMIT)) if records_continue?
|
api_v1_trends_links_url pagination_params(offset: offset_param + limit_param(DEFAULT_LINKS_LIMIT)) if records_continue?
|
||||||
|
|
|
@ -27,10 +27,17 @@ class Api::V1::Trends::StatusesController < Api::BaseController
|
||||||
end
|
end
|
||||||
|
|
||||||
def statuses_from_trends
|
def statuses_from_trends
|
||||||
|
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 = Trends.statuses.query.allowed.in_locale(content_locale)
|
||||||
scope = scope.filtered_for(current_account) if user_signed_in?
|
scope = scope.filtered_for(current_account) if user_signed_in?
|
||||||
scope
|
scope
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def next_path
|
def next_path
|
||||||
api_v1_trends_statuses_url pagination_params(offset: offset_param + limit_param(DEFAULT_STATUSES_LIMIT)) if records_continue?
|
api_v1_trends_statuses_url pagination_params(offset: offset_param + limit_param(DEFAULT_STATUSES_LIMIT)) if records_continue?
|
||||||
|
|
|
@ -27,10 +27,14 @@ class Api::V1::Trends::TagsController < Api::BaseController
|
||||||
end
|
end
|
||||||
|
|
||||||
def tags_from_trends
|
def tags_from_trends
|
||||||
|
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 = Trends.tags.query.allowed.in_locale(content_locale)
|
||||||
scope = scope.filtered_for(current_account) if user_signed_in?
|
scope = scope.filtered_for(current_account) if user_signed_in?
|
||||||
scope
|
scope
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def next_path
|
def next_path
|
||||||
api_v1_trends_tags_url pagination_params(offset: offset_param + limit_param(DEFAULT_TAGS_LIMIT)) if records_continue?
|
api_v1_trends_tags_url pagination_params(offset: offset_param + limit_param(DEFAULT_TAGS_LIMIT)) if records_continue?
|
||||||
|
|
|
@ -6,4 +6,9 @@ module Fasp
|
||||||
def self.table_name_prefix
|
def self.table_name_prefix
|
||||||
'fasp_'
|
'fasp_'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.capability_enabled?(capability_name)
|
||||||
|
Mastodon::Feature.fasp_enabled? &&
|
||||||
|
Provider.with_capability(capability_name).any?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,4 +16,16 @@
|
||||||
class Fasp::PreviewCardTrend < ApplicationRecord
|
class Fasp::PreviewCardTrend < ApplicationRecord
|
||||||
belongs_to :preview_card
|
belongs_to :preview_card
|
||||||
belongs_to :fasp_provider, class_name: 'Fasp::Provider'
|
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
|
end
|
||||||
|
|
|
@ -16,4 +16,17 @@
|
||||||
class Fasp::StatusTrend < ApplicationRecord
|
class Fasp::StatusTrend < ApplicationRecord
|
||||||
belongs_to :status
|
belongs_to :status
|
||||||
belongs_to :fasp_provider, class_name: 'Fasp::Provider'
|
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
|
end
|
||||||
|
|
|
@ -16,4 +16,16 @@
|
||||||
class Fasp::TagTrend < ApplicationRecord
|
class Fasp::TagTrend < ApplicationRecord
|
||||||
belongs_to :tag
|
belongs_to :tag
|
||||||
belongs_to :fasp_provider, class_name: 'Fasp::Provider'
|
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
|
end
|
||||||
|
|
|
@ -58,6 +58,7 @@ class PreviewCard < ApplicationRecord
|
||||||
|
|
||||||
has_many :preview_cards_statuses, dependent: :delete_all, inverse_of: :preview_card
|
has_many :preview_cards_statuses, dependent: :delete_all, inverse_of: :preview_card
|
||||||
has_many :statuses, through: :preview_cards_statuses
|
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
|
has_one :trend, class_name: 'PreviewCardTrend', inverse_of: :preview_card, dependent: :destroy
|
||||||
belongs_to :author_account, class_name: 'Account', optional: true
|
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 :mentions, dependent: :destroy, inverse_of: :status
|
||||||
has_many :mentioned_accounts, through: :mentions, source: :account, class_name: 'Account'
|
has_many :mentioned_accounts, through: :mentions, source: :account, class_name: 'Account'
|
||||||
has_many :media_attachments, dependent: :nullify
|
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
|
# 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
|
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 :passive_relationships, class_name: 'TagFollow', inverse_of: :tag, dependent: :destroy
|
||||||
has_many :featured_tags, dependent: :destroy, inverse_of: :tag
|
has_many :featured_tags, dependent: :destroy, inverse_of: :tag
|
||||||
has_many :followers, through: :passive_relationships, source: :account
|
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
|
has_one :trend, class_name: 'TagTrend', inverse_of: :tag, dependent: :destroy
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user