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.

87 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,
  24. serializer: ActivityPub::ActorSerializer,
  25. adapter: ActivityPub::Adapter,
  26. content_type: 'application/activity+json'
  27. end
  28. end
  29. end
  30. private
  31. def show_pinned_statuses?
  32. [replies_requested?, media_requested?, params[:max_id].present?, params[:since_id].present?].none?
  33. end
  34. def filtered_statuses
  35. default_statuses.tap do |statuses|
  36. statuses.merge!(only_media_scope) if media_requested?
  37. statuses.merge!(no_replies_scope) unless replies_requested?
  38. end
  39. end
  40. def default_statuses
  41. @account.statuses.where(visibility: [:public, :unlisted])
  42. end
  43. def only_media_scope
  44. Status.where(id: account_media_status_ids)
  45. end
  46. def account_media_status_ids
  47. @account.media_attachments.attached.reorder(nil).select(:status_id).distinct
  48. end
  49. def no_replies_scope
  50. Status.without_replies
  51. end
  52. def set_account
  53. @account = Account.find_local!(params[:username])
  54. end
  55. def next_url
  56. if media_requested?
  57. short_account_media_url(@account, max_id: @statuses.last.id)
  58. elsif replies_requested?
  59. short_account_with_replies_url(@account, max_id: @statuses.last.id)
  60. else
  61. short_account_url(@account, max_id: @statuses.last.id)
  62. end
  63. end
  64. def media_requested?
  65. request.path.ends_with?('/media')
  66. end
  67. def replies_requested?
  68. request.path.ends_with?('/with_replies')
  69. end
  70. end