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')

View file

@ -1031,6 +1031,7 @@ en:
empty: You have no antennas.
expires_in: Expires in %{distance}
expires_on: Expires on %{date}
stl: This antenna is in STL mode, ignoring reject-subscription settings.
title: Antennas
new:
save: Save new antenna

View file

@ -1028,6 +1028,7 @@ ja:
expires_on: 有効期限 %{date}
keywords:
other: "%{count}件のキーワード"
stl: STLモードが適用されます。購読拒否設定は無視されます。
tags:
other: "%{count}件のタグ"
title: アンテナ

View file

@ -0,0 +1,10 @@
# frozen_string_literal: true
class AddStlToAntennas < ActiveRecord::Migration[6.1]
def change
safety_assured do
add_column :antennas, :stl, :boolean, null: false, default: false
add_index :antennas, :stl
end
end
end

View file

@ -12,7 +12,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2023_05_09_045358) do
ActiveRecord::Schema.define(version: 2023_05_10_000439) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -308,6 +308,7 @@ ActiveRecord::Schema.define(version: 2023_05_09_045358) do
t.jsonb "exclude_domains"
t.jsonb "exclude_accounts"
t.jsonb "exclude_tags"
t.boolean "stl", default: false, null: false
t.index ["account_id"], name: "index_antennas_on_account_id"
t.index ["any_accounts"], name: "index_antennas_on_any_accounts"
t.index ["any_domains"], name: "index_antennas_on_any_domains"
@ -315,6 +316,7 @@ ActiveRecord::Schema.define(version: 2023_05_09_045358) do
t.index ["any_tags"], name: "index_antennas_on_any_tags"
t.index ["available"], name: "index_antennas_on_available"
t.index ["list_id"], name: "index_antennas_on_list_id"
t.index ["stl"], name: "index_antennas_on_stl"
end
create_table "appeals", force: :cascade do |t|