about summary refs log tree commit diff
path: root/app/services
diff options
context:
space:
mode:
Diffstat (limited to 'app/services')
-rw-r--r--app/services/create_featured_tag_service.rb10
1 files changed, 7 insertions, 3 deletions
diff --git a/app/services/create_featured_tag_service.rb b/app/services/create_featured_tag_service.rb
index c99d16113..3cc59156d 100644
--- a/app/services/create_featured_tag_service.rb
+++ b/app/services/create_featured_tag_service.rb
@@ -3,14 +3,18 @@
 class CreateFeaturedTagService < BaseService
   include Payloadable
 
-  def call(account, name)
+  def call(account, name, force: true)
     @account = account
 
     FeaturedTag.create!(account: account, name: name).tap do |featured_tag|
       ActivityPub::AccountRawDistributionWorker.perform_async(build_json(featured_tag), account.id) if @account.local?
     end
-  rescue ActiveRecord::RecordNotUnique
-    FeaturedTag.by_name(name).find_by!(account: account)
+  rescue ActiveRecord::RecordNotUnique, ActiveRecord::RecordInvalid => e
+    if force && e.is_a(ActiveRecord::RecordNotUnique)
+      FeaturedTag.by_name(name).find_by!(account: account)
+    else
+      account.featured_tags.new(name: name)
+    end
   end
 
   private