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.

34 lines
1.1 KiB

7 years ago
7 years ago
  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.call(status)
  12. process_hashtags_service.call(status)
  13. DistributionWorker.perform_async(status.id)
  14. HubPingWorker.perform_async(account.id)
  15. status
  16. end
  17. private
  18. def attach_media(status, media_ids)
  19. return if media_ids.nil? || !media_ids.is_a?(Enumerable)
  20. media = MediaAttachment.where(status_id: nil).where(id: media_ids.take(4).map(&:to_i))
  21. media.update(status_id: status.id)
  22. end
  23. def process_mentions_service
  24. @process_mentions_service ||= ProcessMentionsService.new
  25. end
  26. def process_hashtags_service
  27. @process_hashtags_service ||= ProcessHashtagsService.new
  28. end
  29. end