Add stl antenna mode

This commit is contained in:
KMY 2023-05-10 09:42:29 +09:00
parent 551a676161
commit 7d237611d9
8 changed files with 38 additions and 4 deletions

View file

@ -4,7 +4,7 @@ import { makeGetAccount } from '../../../selectors';
import ImmutablePureComponent from 'react-immutable-pure-component';
import ImmutablePropTypes from 'react-immutable-proptypes';
import { Avatar } from '../../../components/avatar';
import DisplayName from '../../../components/display_name';
import { DisplayName } from '../../../components/display_name';
import { injectIntl } from 'react-intl';
const makeMapStateToProps = () => {

View file

@ -22,6 +22,7 @@
# exclude_domains :jsonb
# exclude_accounts :jsonb
# exclude_tags :jsonb
# stl :boolean default(FALSE), not null
#
class Antenna < ApplicationRecord
include Expireable
@ -33,6 +34,7 @@ class Antenna < ApplicationRecord
belongs_to :account
belongs_to :list, optional: true
scope :stls, -> { where(stl: true) }
scope :all_keywords, -> { where(any_keywords: true) }
scope :all_domains, -> { where(any_domains: true) }
scope :all_accounts, -> { where(any_accounts: true) }
@ -41,6 +43,8 @@ class Antenna < ApplicationRecord
validate :list_owner
before_save :check_stl_mode
def list_owner
raise Mastodon::ValidationError, I18n.t('antennas.errors.invalid_list_owner') if !list_id.zero? && list.present? && list.account != account
end
@ -208,4 +212,16 @@ class Antenna < ApplicationRecord
end
self[:exclude_accounts] = accounts
end
private
def check_stl_mode
self[:stl] = stl_mode?
end
def stl_mode?
list_id.zero? && !any_domains && any_accounts && any_keywords && any_tags &&
exclude_accounts.blank? && exclude_domains.blank? && exclude_keywords.blank? && exclude_tags.blank? &&
antenna_domains.count == 1 && antenna_domains.first.name == Rails.configuration.x.local_domain
end
end

View file

@ -49,7 +49,7 @@ class FanOutOnWriteService < BaseService
when :public, :unlisted, :public_unlisted, :private
deliver_to_all_followers!
deliver_to_lists!
deliver_to_antennas! if [:public, :public_unlisted].include?(@status.visibility.to_sym) && !@status.account.dissubscribable
deliver_to_antennas! if [:public, :public_unlisted].include?(@status.visibility.to_sym)
when :limited
deliver_to_mentioned_followers!
else
@ -125,6 +125,7 @@ class FanOutOnWriteService < BaseService
antennas = Antenna.availables
antennas = antennas.left_joins(:antenna_domains).where(any_domains: true).or(Antenna.left_joins(:antenna_domains).where(antenna_domains: { name: domain }))
antennas = antennas.where(with_media_only: false) unless @status.with_media?
antennas = antennas.where(stl: true) if @account.dissubscribable
antennas = antennas.where.not(account: @account.blocking)
antennas = Antenna.where(id: antennas.select(:id))

View file

@ -65,7 +65,10 @@
.announcements-list__item__action-bar
.announcements-list__item__meta
- if antenna.enabled_config_raws?
= t('antennas.index.contexts', contexts: antenna.context.map { |context| I18n.t("antennas.contexts.#{context}") }.join(', '))
- if antenna.stl
= t('antennas.index.stl')
- else
= t('antennas.index.contexts', contexts: antenna.context.map { |context| I18n.t("antennas.contexts.#{context}") }.join(', '))
- else
= t('antennas.errors.empty_contexts')