diff --git a/app/models/activity_pub/actor.rb b/app/models/activity_pub/actor.rb index 92750946..a5171815 100644 --- a/app/models/activity_pub/actor.rb +++ b/app/models/activity_pub/actor.rb @@ -13,5 +13,16 @@ class ActivityPub has_many :actor_moderation has_many :activity_pubs, as: :object has_many :activities + + # Obtiene el nombre de la Actor como menciĆ³n, solo si obtuvimos el + # contenido de antemano. + # + # @return [String, nil] + def mention + return if content['preferredUsername'].blank? + return if instance.blank? + + @mention ||= "@#{content['preferredUsername']}@#{instance.hostname}" + end end end diff --git a/app/models/actor_moderation.rb b/app/models/actor_moderation.rb index 69fbf3bd..efbde33b 100644 --- a/app/models/actor_moderation.rb +++ b/app/models/actor_moderation.rb @@ -15,18 +15,51 @@ class ActorModeration < ApplicationRecord event :pause do transitions from: %i[allowed blocked reported], to: :paused + + before do + pause_remotely! + end end - event :allowed do + event :allow do transitions from: %i[paused blocked reported], to: :allowed + + before do + allow_remotely! + end end - event :blocked do + event :block do transitions from: %i[paused allowed], to: :blocked + + before do + block_remotely! + end end event :reported do transitions from: %i[blocked], to: :reported end end + + def pause_remotely! + raise AASM::InvalidTransition unless + actor.mention && + site.social_inbox.allowlist.delete(list: [actor.mention]).ok? && + site.social_inbox.blocklist.delete(list: [actor.mention]).ok? + end + + def allow_remotely! + raise AASM::InvalidTransition unless + actor.mention && + site.social_inbox.allowlist.post(list: [actor.mention]).ok? && + site.social_inbox.blocklist.delete(list: [actor.mention]).ok? + end + + def block_remotely! + raise AASM::InvalidTransition unless + actor.mention && + site.social_inbox.allowlist.delete(list: [actor.mention]).ok? && + site.social_inbox.blocklist.post(list: [actor.mention]).ok? + end end