The code powering m.abunchtell.com https://m.abunchtell.com
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 

79 rader
1.8 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 'Accept'
  8. undo_accept
  9. when 'Follow'
  10. undo_follow
  11. when 'Like'
  12. undo_like
  13. when 'Block'
  14. undo_block
  15. end
  16. end
  17. private
  18. def undo_announce
  19. status = Status.find_by(uri: object_uri, account: @account)
  20. status ||= Status.find_by(uri: @object['atomUri'], account: @account) if @object.is_a?(Hash) && @object['atomUri'].present?
  21. if status.nil?
  22. delete_later!(object_uri)
  23. else
  24. RemoveStatusService.new.call(status)
  25. end
  26. end
  27. def undo_accept
  28. ::Follow.find_by(target_account: @account, uri: target_uri)&.revoke_request!
  29. end
  30. def undo_follow
  31. target_account = account_from_uri(target_uri)
  32. return if target_account.nil? || !target_account.local?
  33. if @account.following?(target_account)
  34. @account.unfollow!(target_account)
  35. elsif @account.requested?(target_account)
  36. FollowRequest.find_by(account: @account, target_account: target_account)&.destroy
  37. else
  38. delete_later!(object_uri)
  39. end
  40. end
  41. def undo_like
  42. status = status_from_uri(target_uri)
  43. return if status.nil? || !status.account.local?
  44. if @account.favourited?(status)
  45. favourite = status.favourites.where(account: @account).first
  46. favourite&.destroy
  47. else
  48. delete_later!(object_uri)
  49. end
  50. end
  51. def undo_block
  52. target_account = account_from_uri(target_uri)
  53. return if target_account.nil? || !target_account.local?
  54. if @account.blocking?(target_account)
  55. UnblockService.new.call(@account, target_account)
  56. else
  57. delete_later!(object_uri)
  58. end
  59. end
  60. def target_uri
  61. @target_uri ||= value_or_id(@object['object'])
  62. end
  63. end