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_optionslocal
parent
73a48318a1
commit
74ead7d106
10 changed files with 117 additions and 15 deletions
@ -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 |
@ -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 |
@ -0,0 +1,9 @@ |
||||
# frozen_string_literal: true |
||||
|
||||
class ActivityPub::AccountRawDistributionWorker < ActivityPub::RawDistributionWorker |
||||
protected |
||||
|
||||
def inboxes |
||||
@inboxes ||= AccountReachFinder.new(@account).inboxes |
||||
end |
||||
end |
@ -0,0 +1,11 @@ |
||||
# frozen_string_literal: true |
||||
|
||||
class RemoveFeaturedTagWorker |
||||
include Sidekiq::Worker |
||||
|
||||
def perform(account_id, featured_tag_id) |
||||
RemoveFeaturedTagService.new.call(Account.find(account_id), FeaturedTag.find(featured_tag_id)) |
||||
rescue ActiveRecord::RecordNotFound |
||||
true |
||||
end |
||||
end |
Loading…
Reference in new issue