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

84 lines
2.4 KiB

  1. # frozen_string_literal: true
  2. class AccountsController < ApplicationController
  3. include AccountControllerConcern
  4. include SignatureVerification
  5. def show
  6. respond_to do |format|
  7. format.html do
  8. @pinned_statuses = []
  9. if current_account && @account.blocking?(current_account)
  10. @statuses = []
  11. return
  12. end
  13. @pinned_statuses = cache_collection(@account.pinned_statuses, Status) if show_pinned_statuses?
  14. @statuses = filtered_statuses.paginate_by_max_id(20, params[:max_id], params[:since_id])
  15. @statuses = cache_collection(@statuses, Status)
  16. @next_url = next_url unless @statuses.empty?
  17. end
  18. format.atom do
  19. @entries = @account.stream_entries.where(hidden: false).with_includes.paginate_by_max_id(20, params[:max_id], params[:since_id])
  20. render xml: OStatus::AtomSerializer.render(OStatus::AtomSerializer.new.feed(@account, @entries.reject { |entry| entry.status.nil? }))
  21. end
  22. format.json do
  23. render json: @account, serializer: ActivityPub::ActorSerializer, adapter: ActivityPub::Adapter, content_type: 'application/activity+json'
  24. end
  25. end
  26. end
  27. private
  28. def show_pinned_statuses?
  29. [replies_requested?, media_requested?, params[:max_id].present?, params[:since_id].present?].none?
  30. end
  31. def filtered_statuses
  32. default_statuses.tap do |statuses|
  33. statuses.merge!(only_media_scope) if media_requested?
  34. statuses.merge!(no_replies_scope) unless replies_requested?
  35. end
  36. end
  37. def default_statuses
  38. @account.statuses.where(visibility: [:public, :unlisted])
  39. end
  40. def only_media_scope
  41. Status.where(id: account_media_status_ids)
  42. end
  43. def account_media_status_ids
  44. @account.media_attachments.attached.reorder(nil).select(:status_id).distinct
  45. end
  46. def no_replies_scope
  47. Status.without_replies
  48. end
  49. def set_account
  50. @account = Account.find_local!(params[:username])
  51. end
  52. def next_url
  53. if media_requested?
  54. short_account_media_url(@account, max_id: @statuses.last.id)
  55. elsif replies_requested?
  56. short_account_with_replies_url(@account, max_id: @statuses.last.id)
  57. else
  58. short_account_url(@account, max_id: @statuses.last.id)
  59. end
  60. end
  61. def media_requested?
  62. request.path.ends_with?('/media')
  63. end
  64. def replies_requested?
  65. request.path.ends_with?('/with_replies')
  66. end
  67. end