diff options
author | Takeshi Umeda <noel.yoshiba@gmail.com> | 2022-10-23 01:30:55 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-22 18:30:55 +0200 |
commit | 74ead7d10698c7f18ca22c07d2f04ff81f419097 (patch) | |
tree | 3bc7504ab88d44bbc28c0bb1dfa40a85963d65dd /app/services | |
parent | 73a48318a19a207c63f6d03ecea8ce35b7e2364a (diff) |
Change featured tag updates to add/remove activity (#19409)
* Change featured tag updates to add/remove activity * Fix to check for the existence of feature tag * Rename service and worker * Merge AddHashtagSerializer with AddSerializer * Undo removal of sidekiq_options
Diffstat (limited to 'app/services')
-rw-r--r-- | app/services/create_featured_tag_service.rb | 21 | ||||
-rw-r--r-- | app/services/remove_featured_tag_service.rb | 18 |
2 files changed, 39 insertions, 0 deletions
diff --git a/app/services/create_featured_tag_service.rb b/app/services/create_featured_tag_service.rb new file mode 100644 index 000000000..c99d16113 --- /dev/null +++ b/app/services/create_featured_tag_service.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +class CreateFeaturedTagService < BaseService + include Payloadable + + def call(account, name) + @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) + end + + private + + def build_json(featured_tag) + Oj.dump(serialize_payload(featured_tag, ActivityPub::AddSerializer, signer: @account)) + end +end diff --git a/app/services/remove_featured_tag_service.rb b/app/services/remove_featured_tag_service.rb new file mode 100644 index 000000000..2aa70e8fc --- /dev/null +++ b/app/services/remove_featured_tag_service.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class RemoveFeaturedTagService < BaseService + include Payloadable + + def call(account, featured_tag) + @account = account + + featured_tag.destroy! + ActivityPub::AccountRawDistributionWorker.perform_async(build_json(featured_tag), account.id) if @account.local? + end + + private + + def build_json(featured_tag) + Oj.dump(serialize_payload(featured_tag, ActivityPub::RemoveSerializer, signer: @account)) + end +end |