Make antenna able to insert home

This commit is contained in:
KMY 2023-05-09 15:07:29 +09:00
parent 7c118ed1d0
commit 9429f5b60c
7 changed files with 34 additions and 8 deletions

View file

@ -145,7 +145,7 @@ class StatusReachFinder
def banned_domains_for_misskey
return @banned_domains_for_misskey if @banned_domains_for_misskey
return @banned_domains_for_misskey = [] if (!@status.account.user&.reject_public_unlisted_subscription? && !@status.account.user&.reject_unlisted_subscription?) || (!@status.public_unlisted_visibility? && !@status.unlisted_visibility?)
return @banned_domains_for_misskey = [] if (!@status.account.user&.setting_reject_public_unlisted_subscription? && !@status.account.user&.reject_unlisted_subscription?) || (!@status.public_unlisted_visibility? && !@status.unlisted_visibility?)
domains = banned_domains_for_misskey_of_status(@status)
domains += banned_domains_for_misskey_of_status(@status.reblog) if @status.reblog? && @status.reblog.local?

View file

@ -31,7 +31,7 @@ class Antenna < ApplicationRecord
has_many :antenna_accounts, inverse_of: :antenna, dependent: :destroy
belongs_to :account
belongs_to :list
belongs_to :list, optional: true
scope :all_keywords, -> { where(any_keywords: true) }
scope :all_domains, -> { where(any_domains: true) }
@ -42,7 +42,7 @@ class Antenna < ApplicationRecord
validate :list_owner
def list_owner
raise Mastodon::ValidationError, I18n.t('antennas.errors.invalid_list_owner') if list.account != account
raise Mastodon::ValidationError, I18n.t('antennas.errors.invalid_list_owner') if list.present? && list.account != account
end
def enabled?

View file

@ -118,6 +118,7 @@ class FanOutOnWriteService < BaseService
def deliver_to_antennas!
lists = []
homes = []
tag_ids = @status.tags.pluck(:id)
domain = @account.domain || Rails.configuration.x.local_domain
@ -142,16 +143,27 @@ class FanOutOnWriteService < BaseService
next if antenna.exclude_domains&.include?(domain)
next if antenna.exclude_tags&.any? { |tag_id| tag_ids.include?(tag_id) }
lists << antenna.list_id
if antenna.list_id.zero?
homes << antenna.account_id
else
lists << antenna.list_id
end
end
end
lists = lists.uniq
homes = homes.uniq
if lists.any?
FeedInsertWorker.push_bulk(lists) do |list|
[@status.id, list, 'list', { 'update' => update? }]
end
end
if homes.any?
FeedInsertWorker.push_bulk(homes) do |home|
[@status.id, home, 'home', { 'update' => update? }]
end
end
end
def deliver_to_mentioned_followers!

View file

@ -13,7 +13,7 @@
= t('antennas.index.expires_in', distance: distance_of_time_in_words_to_now(antenna.expires_at))
.listname
= antenna.list.title
= antenna.list&.title || '[Insert to Home]'
.filters-list__item__permissions
%ul.permissions-list

View file

@ -9,7 +9,7 @@
.fields-row
.fields-group.fields-row__column.fields-row__column-6
= f.input :list, collection: lists, wrapper: :with_label, label_method: lambda { |list| list.title }, label: t('antennas.edit.list'), selected: f.object.list&.id, hint: false
= f.input :list, collection: lists, wrapper: :with_label, label_method: lambda { |list| list.title }, label: t('antennas.edit.list'), selected: f.object.list&.id, hint: false, include_blank: '[Insert to Home]'
.fields-group.fields-row__column.fields-row__column-6
= f.input :available, wrapper: :with_label, label: t('antennas.edit.available'), hint: false

View file

@ -0,0 +1,15 @@
# frozen_string_literal: true
class ChangeAntennasListToNullable < ActiveRecord::Migration[6.1]
def up
safety_assured do
remove_foreign_key :antennas, :lists
end
end
def down
safety_assured do
add_foreign_key :antennas, :lists
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_04_30_110057) do
ActiveRecord::Schema.define(version: 2023_05_09_045358) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -1285,7 +1285,6 @@ ActiveRecord::Schema.define(version: 2023_04_30_110057) do
add_foreign_key "antenna_tags", "antennas", on_delete: :cascade
add_foreign_key "antenna_tags", "tags", on_delete: :cascade
add_foreign_key "antennas", "accounts", on_delete: :cascade
add_foreign_key "antennas", "lists", on_delete: :cascade
add_foreign_key "appeals", "account_warnings", on_delete: :cascade
add_foreign_key "appeals", "accounts", column: "approved_by_account_id", on_delete: :nullify
add_foreign_key "appeals", "accounts", column: "rejected_by_account_id", on_delete: :nullify