闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
755 B

  1. # frozen_string_literal: true
  2. class PublishScheduledAnnouncementWorker
  3. include Sidekiq::Worker
  4. include Redisable
  5. def perform(announcement_id)
  6. @announcement = Announcement.find(announcement_id)
  7. refresh_status_ids!
  8. @announcement.publish! unless @announcement.published?
  9. payload = InlineRenderer.render(@announcement, nil, :announcement)
  10. payload = Oj.dump(event: :announcement, payload: payload)
  11. FeedManager.instance.with_active_accounts do |account|
  12. redis.publish("timeline:#{account.id}", payload) if redis.exists("subscribed:timeline:#{account.id}")
  13. end
  14. end
  15. private
  16. def refresh_status_ids!
  17. @announcement.status_ids = Status.from_text(@announcement.text).map(&:id)
  18. @announcement.save
  19. end
  20. end