Add featured tag add/remove activity handler (#19408)

This commit is contained in:
Takeshi Umeda
2022-10-22 18:49:41 +09:00
committed by GitHub
parent 7c152acb2c
commit 1d34eff63f
3 changed files with 47 additions and 2 deletions

View File

@ -2,12 +2,32 @@
class ActivityPub::Activity::Add < ActivityPub::Activity
def perform
return unless @json['target'].present? && value_or_id(@json['target']) == @account.featured_collection_url
return if @json['target'].blank?
case value_or_id(@json['target'])
when @account.featured_collection_url
case @object['type']
when 'Hashtag'
add_featured_tags
else
add_featured
end
end
end
private
def add_featured
status = status_from_object
return unless !status.nil? && status.account_id == @account.id && !@account.pinned?(status)
StatusPin.create!(account: @account, status: status)
end
def add_featured_tags
name = @object['name']&.delete_prefix('#')
FeaturedTag.create!(account: @account, name: name) if name.present?
end
end