mastodon/app/models/concerns/status/fasp_concern.rb
David Roetzel 1dda12201d
Only share public statuses.
Only actually public, i.e. not "unlisted". One exception: Share
an update if the update changed the visibility from "public" to
something else. The fasp can act on this information then.
2025-03-06 14:08:38 +01:00

50 lines
1.5 KiB
Ruby

# frozen_string_literal: true
module Status::FaspConcern
extend ActiveSupport::Concern
included do
after_commit :announce_new_content_to_subscribed_fasp, on: :create
after_commit :announce_updated_content_to_subscribed_fasp, on: :update
after_commit :announce_deleted_content_to_subscribed_fasp, on: :destroy
after_commit :announce_trends_to_subscribed_fasp, on: :create
end
private
def announce_new_content_to_subscribed_fasp
return unless account_indexable? && public_visibility?
store_uri unless uri # TODO: solve this more elegantly
Fasp::AnnounceContentLifecycleEventWorker.perform_async(uri, 'new')
end
def announce_updated_content_to_subscribed_fasp
return unless account_indexable? && public_visibility_or_just_changed?
Fasp::AnnounceContentLifecycleEventWorker.perform_async(uri, 'update')
end
def announce_deleted_content_to_subscribed_fasp
return unless account_indexable? && public_visibility?
Fasp::AnnounceContentLifecycleEventWorker.perform_async(uri, 'delete')
end
def announce_trends_to_subscribed_fasp
return unless account_indexable?
candidate_id, trend_source =
if reblog_of_id
[reblog_of_id, 'reblog']
elsif in_reply_to_id
[in_reply_to_id, 'reply']
end
Fasp::AnnounceTrendWorker.perform_async(candidate_id, trend_source) if candidate_id
end
def public_visibility_or_just_changed?
public_visibility? || visibility_previously_was == 'public'
end
end