add.rb 729 B

123456789101112131415161718192021222324252627282930313233
  1. # frozen_string_literal: true
  2. class ActivityPub::Activity::Add < ActivityPub::Activity
  3. def perform
  4. return if @json['target'].blank?
  5. case value_or_id(@json['target'])
  6. when @account.featured_collection_url
  7. case @object['type']
  8. when 'Hashtag'
  9. add_featured_tags
  10. else
  11. add_featured
  12. end
  13. end
  14. end
  15. private
  16. def add_featured
  17. status = status_from_object
  18. return unless !status.nil? && status.account_id == @account.id && !@account.pinned?(status)
  19. StatusPin.create!(account: @account, status: status)
  20. end
  21. def add_featured_tags
  22. name = @object['name']&.delete_prefix('#')
  23. FeaturedTag.create!(account: @account, name: name) if name.present?
  24. end
  25. end