You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
1.4 KiB

  1. # frozen_string_literal: true
  2. class ActivityPub::Activity::Undo < ActivityPub::Activity
  3. def perform
  4. case @object['type']
  5. when 'Announce'
  6. undo_announce
  7. when 'Follow'
  8. undo_follow
  9. when 'Like'
  10. undo_like
  11. when 'Block'
  12. undo_block
  13. end
  14. end
  15. private
  16. def undo_announce
  17. status = Status.find_by(uri: object_uri, account: @account)
  18. if status.nil?
  19. delete_later!(object_uri)
  20. else
  21. RemoveStatusService.new.call(status)
  22. end
  23. end
  24. def undo_follow
  25. target_account = account_from_uri(target_uri)
  26. return if target_account.nil? || !target_account.local?
  27. if @account.following?(target_account)
  28. @account.unfollow!(target_account)
  29. else
  30. delete_later!(object_uri)
  31. end
  32. end
  33. def undo_like
  34. status = status_from_uri(target_uri)
  35. return if status.nil? || !status.account.local?
  36. if @account.favourited?(status)
  37. favourite = status.favourites.where(account: @account).first
  38. favourite&.destroy
  39. else
  40. delete_later!(object_uri)
  41. end
  42. end
  43. def undo_block
  44. target_account = account_from_uri(target_uri)
  45. return if target_account.nil? || !target_account.local?
  46. if @account.blocking?(target_account)
  47. UnblockService.new.call(@account, target_account)
  48. else
  49. delete_later!(object_uri)
  50. end
  51. end
  52. def target_uri
  53. @target_uri ||= @object['object'].is_a?(String) ? @object['object'] : @object['object']['id']
  54. end
  55. end