5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-26 10:36:21 +00:00

feat: moderar en la social inbox

This commit is contained in:
f 2024-02-28 17:58:00 -03:00
parent 6eaf00c7ad
commit 6d9a64f728
No known key found for this signature in database
2 changed files with 46 additions and 2 deletions

View file

@ -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

View file

@ -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