mirror of
https://github.com/glitch-soc/mastodon.git
synced 2025-12-13 15:58:50 +00:00
Add REST API for featuring and unfeaturing a hashtag (#34489)
Co-authored-by: Matt Jankowski <matt@jankowski.online> Co-authored-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
@@ -3,18 +3,24 @@
|
||||
class CreateFeaturedTagService < BaseService
|
||||
include Payloadable
|
||||
|
||||
def call(account, name, force: true)
|
||||
def call(account, name_or_tag, raise_error: true)
|
||||
raise ArgumentError unless account.local?
|
||||
|
||||
@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, 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)
|
||||
@featured_tag = begin
|
||||
if name_or_tag.is_a?(Tag)
|
||||
account.featured_tags.find_or_initialize_by(tag: name_or_tag)
|
||||
else
|
||||
account.featured_tags.find_or_initialize_by(name: name_or_tag)
|
||||
end
|
||||
end
|
||||
|
||||
create_method = raise_error ? :save! : :save
|
||||
|
||||
ActivityPub::AccountRawDistributionWorker.perform_async(build_json(@featured_tag), @account.id) if @featured_tag.new_record? && @featured_tag.public_send(create_method)
|
||||
|
||||
@featured_tag
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -3,11 +3,24 @@
|
||||
class RemoveFeaturedTagService < BaseService
|
||||
include Payloadable
|
||||
|
||||
def call(account, featured_tag)
|
||||
def call(account, featured_tag_or_tag)
|
||||
raise ArgumentError unless account.local?
|
||||
|
||||
@account = account
|
||||
|
||||
featured_tag.destroy!
|
||||
ActivityPub::AccountRawDistributionWorker.perform_async(build_json(featured_tag), account.id) if @account.local?
|
||||
@featured_tag = begin
|
||||
if featured_tag_or_tag.is_a?(FeaturedTag)
|
||||
featured_tag_or_tag
|
||||
elsif featured_tag_or_tag.is_a?(Tag)
|
||||
FeaturedTag.find_by(account: account, tag: featured_tag_or_tag)
|
||||
end
|
||||
end
|
||||
|
||||
return if @featured_tag.nil?
|
||||
|
||||
@featured_tag.destroy!
|
||||
|
||||
ActivityPub::AccountRawDistributionWorker.perform_async(build_json(@featured_tag), account.id) if @account.local?
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
Reference in New Issue
Block a user