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.

29 lines
1.0 KiB

  1. class PostStatusService < BaseService
  2. # Post a text status update, fetch and notify remote users mentioned
  3. # @param [Account] account Account from which to post
  4. # @param [String] text Message
  5. # @param [Status] in_reply_to Optional status to reply to
  6. # @param [Enumerable] media_ids Optional array of media IDs to attach
  7. # @return [Status]
  8. def call(account, text, in_reply_to = nil, media_ids = nil)
  9. status = account.statuses.create!(text: text, thread: in_reply_to)
  10. attach_media(status, media_ids)
  11. process_mentions_service.(status)
  12. DistributionWorker.perform_async(status.id)
  13. account.ping!(account_url(account, format: 'atom'), [Rails.configuration.x.hub_url])
  14. status
  15. end
  16. private
  17. def attach_media(status, media_ids)
  18. return if media_ids.nil? || !media_ids.is_a?(Enumerable)
  19. media = MediaAttachment.where(status_id: nil).where(id: media_ids.take(4).map { |id| id.to_i })
  20. media.update(status_id: status.id)
  21. end
  22. def process_mentions_service
  23. @process_mentions_service ||= ProcessMentionsService.new
  24. end
  25. end