Add support for FASP data sharing (#34415)
This commit is contained in:
parent
3ea1f074ab
commit
a5a2c6dc7e
38 changed files with 1140 additions and 1 deletions
37
app/models/concerns/account/fasp_concern.rb
Normal file
37
app/models/concerns/account/fasp_concern.rb
Normal file
|
@ -0,0 +1,37 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Account::FaspConcern
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
after_commit :announce_new_account_to_subscribed_fasp, on: :create
|
||||
after_commit :announce_updated_account_to_subscribed_fasp, on: :update
|
||||
after_commit :announce_deleted_account_to_subscribed_fasp, on: :destroy
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def announce_new_account_to_subscribed_fasp
|
||||
return unless Mastodon::Feature.fasp_enabled?
|
||||
return unless discoverable?
|
||||
|
||||
uri = ActivityPub::TagManager.instance.uri_for(self)
|
||||
Fasp::AnnounceAccountLifecycleEventWorker.perform_async(uri, 'new')
|
||||
end
|
||||
|
||||
def announce_updated_account_to_subscribed_fasp
|
||||
return unless Mastodon::Feature.fasp_enabled?
|
||||
return unless discoverable? || saved_change_to_discoverable?
|
||||
|
||||
uri = ActivityPub::TagManager.instance.uri_for(self)
|
||||
Fasp::AnnounceAccountLifecycleEventWorker.perform_async(uri, 'update')
|
||||
end
|
||||
|
||||
def announce_deleted_account_to_subscribed_fasp
|
||||
return unless Mastodon::Feature.fasp_enabled?
|
||||
return unless discoverable?
|
||||
|
||||
uri = ActivityPub::TagManager.instance.uri_for(self)
|
||||
Fasp::AnnounceAccountLifecycleEventWorker.perform_async(uri, 'delete')
|
||||
end
|
||||
end
|
17
app/models/concerns/favourite/fasp_concern.rb
Normal file
17
app/models/concerns/favourite/fasp_concern.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Favourite::FaspConcern
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
after_commit :announce_trends_to_subscribed_fasp, on: :create
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def announce_trends_to_subscribed_fasp
|
||||
return unless Mastodon::Feature.fasp_enabled?
|
||||
|
||||
Fasp::AnnounceTrendWorker.perform_async(status_id, 'favourite')
|
||||
end
|
||||
end
|
53
app/models/concerns/status/fasp_concern.rb
Normal file
53
app/models/concerns/status/fasp_concern.rb
Normal file
|
@ -0,0 +1,53 @@
|
|||
# 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 Mastodon::Feature.fasp_enabled?
|
||||
return unless account_indexable? && public_visibility?
|
||||
|
||||
# We need the uri here, but it is set in another `after_commit`
|
||||
# callback. Hooks included from modules are run before the ones
|
||||
# in the class itself and can neither be reordered nor is there
|
||||
# a way to declare dependencies.
|
||||
store_uri if uri.nil?
|
||||
Fasp::AnnounceContentLifecycleEventWorker.perform_async(uri, 'new')
|
||||
end
|
||||
|
||||
def announce_updated_content_to_subscribed_fasp
|
||||
return unless Mastodon::Feature.fasp_enabled?
|
||||
return unless account_indexable? && public_visibility?
|
||||
|
||||
Fasp::AnnounceContentLifecycleEventWorker.perform_async(uri, 'update')
|
||||
end
|
||||
|
||||
def announce_deleted_content_to_subscribed_fasp
|
||||
return unless Mastodon::Feature.fasp_enabled?
|
||||
return unless account_indexable? && public_visibility?
|
||||
|
||||
Fasp::AnnounceContentLifecycleEventWorker.perform_async(uri, 'delete')
|
||||
end
|
||||
|
||||
def announce_trends_to_subscribed_fasp
|
||||
return unless Mastodon::Feature.fasp_enabled?
|
||||
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
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue