闭社主体 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.

36 lines
1.2 KiB

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