mirror of
https://github.com/mastodon/mastodon.git
synced 2024-11-20 03:25:17 +01:00
parent
74ead7d106
commit
45d3b32488
@ -10,8 +10,9 @@ class Settings::FeaturedTagsController < Settings::BaseController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
if !featured_tag_exists?
|
@featured_tag = CreateFeaturedTagService.new.call(current_account, featured_tag_params[:name], force: false)
|
||||||
CreateFeaturedTagService.new.call(current_account, featured_tag_params[:name])
|
|
||||||
|
if @featured_tag.valid?
|
||||||
redirect_to settings_featured_tags_path
|
redirect_to settings_featured_tags_path
|
||||||
else
|
else
|
||||||
set_featured_tags
|
set_featured_tags
|
||||||
@ -28,10 +29,6 @@ class Settings::FeaturedTagsController < Settings::BaseController
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def featured_tag_exists?
|
|
||||||
current_account.featured_tags.by_name(featured_tag_params[:name]).exists?
|
|
||||||
end
|
|
||||||
|
|
||||||
def set_featured_tag
|
def set_featured_tag
|
||||||
@featured_tag = current_account.featured_tags.find(params[:id])
|
@featured_tag = current_account.featured_tags.find(params[:id])
|
||||||
end
|
end
|
||||||
|
@ -3,14 +3,18 @@
|
|||||||
class CreateFeaturedTagService < BaseService
|
class CreateFeaturedTagService < BaseService
|
||||||
include Payloadable
|
include Payloadable
|
||||||
|
|
||||||
def call(account, name)
|
def call(account, name, force: true)
|
||||||
@account = account
|
@account = account
|
||||||
|
|
||||||
FeaturedTag.create!(account: account, name: name).tap do |featured_tag|
|
FeaturedTag.create!(account: account, name: name).tap do |featured_tag|
|
||||||
ActivityPub::AccountRawDistributionWorker.perform_async(build_json(featured_tag), account.id) if @account.local?
|
ActivityPub::AccountRawDistributionWorker.perform_async(build_json(featured_tag), account.id) if @account.local?
|
||||||
end
|
end
|
||||||
rescue ActiveRecord::RecordNotUnique
|
rescue ActiveRecord::RecordNotUnique, ActiveRecord::RecordInvalid => e
|
||||||
FeaturedTag.by_name(name).find_by!(account: account)
|
if force && e.is_a(ActiveRecord::RecordNotUnique)
|
||||||
|
FeaturedTag.by_name(name).find_by!(account: account)
|
||||||
|
else
|
||||||
|
account.featured_tags.new(name: name)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
Loading…
Reference in New Issue
Block a user