weathermen/soundstorm

View on GitHub
app/jobs/broadcast_message_job.rb

Summary

Maintainability
A
0 mins
Test Coverage
# frozen_string_literal: true

# Deliver +ActivityPub+ notifications to all followers of a given user.
class BroadcastMessageJob < ApplicationJob
  queue_as :federation

  def perform(version)
    broadcasts = version.remote_followers.map do |follower|
      ActivityPub.deliver(version.message, to: follower.host)
    end

    raise 'Error: Broadcast Unsuccessful' if broadcasts.none?(&:success?)

    version.update!(broadcasted_at: Time.current)
  end
end