mirror of
https://github.com/mastodon/mastodon.git
synced 2024-12-28 22:15:06 +01:00
Handle full content lifecycle for subscribed fasps
This commit is contained in:
parent
e234a89e06
commit
3f5c040d7c
@ -5,12 +5,22 @@ module Status::FaspConcern
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def announce_new_content_to_subscribed_fasp
|
||||
store_uri unless uri # TODO: solve this more elegantly
|
||||
Fasp::AnnounceNewContentWorker.perform_async(uri)
|
||||
Fasp::AnnounceContentLifecycleEventWorker.perform_async(uri, 'new')
|
||||
end
|
||||
|
||||
def announce_updated_content_to_subscribed_fasp
|
||||
Fasp::AnnounceContentLifecycleEventWorker.perform_async(uri, 'update')
|
||||
end
|
||||
|
||||
def announce_deleted_content_to_subscribed_fasp
|
||||
Fasp::AnnounceContentLifecycleEventWorker.perform_async(uri, 'delete')
|
||||
end
|
||||
end
|
||||
|
28
app/workers/fasp/announce_content_lifecycle_event_worker.rb
Normal file
28
app/workers/fasp/announce_content_lifecycle_event_worker.rb
Normal file
@ -0,0 +1,28 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Fasp::AnnounceContentLifecycleEventWorker
|
||||
include Sidekiq::Worker
|
||||
|
||||
sidekiq_options queue: 'fasp', retry: 5
|
||||
|
||||
def perform(uri, event_type)
|
||||
Fasp::Subscription.includes(:fasp_provider).content.lifecycle.each do |subscription|
|
||||
announce(subscription, uri, event_type)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def announce(subscription, uri, event_type)
|
||||
Fasp::Request.new(subscription.fasp_provider).post('/data_sharing/v0/announcements', body: {
|
||||
source: {
|
||||
subscription: {
|
||||
id: subscription.id.to_s,
|
||||
},
|
||||
},
|
||||
category: 'content',
|
||||
eventType: event_type,
|
||||
objectUris: [uri],
|
||||
})
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user