logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

accounts_controller.rb (3280B)


  1. # frozen_string_literal: true
  2. class AccountsController < ApplicationController
  3. PAGE_SIZE = 20
  4. include AccountControllerConcern
  5. before_action :set_cache_headers
  6. def show
  7. respond_to do |format|
  8. format.html do
  9. @pinned_statuses = []
  10. if current_account && @account.blocking?(current_account)
  11. @statuses = []
  12. return
  13. end
  14. @pinned_statuses = cache_collection(@account.pinned_statuses, Status) if show_pinned_statuses?
  15. @statuses = filtered_status_page(params)
  16. @statuses = cache_collection(@statuses, Status)
  17. unless @statuses.empty?
  18. @older_url = older_url if @statuses.last.id > filtered_statuses.last.id
  19. @newer_url = newer_url if @statuses.first.id < filtered_statuses.first.id
  20. end
  21. end
  22. format.atom do
  23. @entries = @account.stream_entries.where(hidden: false).with_includes.paginate_by_max_id(PAGE_SIZE, params[:max_id], params[:since_id])
  24. render xml: OStatus::AtomSerializer.render(OStatus::AtomSerializer.new.feed(@account, @entries.reject { |entry| entry.status.nil? }))
  25. end
  26. format.json do
  27. skip_session!
  28. render_cached_json(['activitypub', 'actor', @account.cache_key], content_type: 'application/activity+json') do
  29. ActiveModelSerializers::SerializableResource.new(@account, serializer: ActivityPub::ActorSerializer, adapter: ActivityPub::Adapter)
  30. end
  31. end
  32. end
  33. end
  34. private
  35. def show_pinned_statuses?
  36. [replies_requested?, media_requested?, params[:max_id].present?, params[:since_id].present?].none?
  37. end
  38. def filtered_statuses
  39. default_statuses.tap do |statuses|
  40. statuses.merge!(only_media_scope) if media_requested?
  41. statuses.merge!(no_replies_scope) unless replies_requested?
  42. end
  43. end
  44. def default_statuses
  45. @account.statuses.where(visibility: [:public, :unlisted])
  46. end
  47. def only_media_scope
  48. Status.where(id: account_media_status_ids)
  49. end
  50. def account_media_status_ids
  51. @account.media_attachments.attached.reorder(nil).select(:status_id).distinct
  52. end
  53. def no_replies_scope
  54. Status.without_replies
  55. end
  56. def set_account
  57. @account = Account.find_local!(params[:username])
  58. end
  59. def older_url
  60. ::Rails.logger.info("older: max_id #{@statuses.last.id}, url #{pagination_url(max_id: @statuses.last.id)}")
  61. pagination_url(max_id: @statuses.last.id)
  62. end
  63. def newer_url
  64. pagination_url(min_id: @statuses.first.id)
  65. end
  66. def pagination_url(max_id: nil, min_id: nil)
  67. if media_requested?
  68. short_account_media_url(@account, max_id: max_id, min_id: min_id)
  69. elsif replies_requested?
  70. short_account_with_replies_url(@account, max_id: max_id, min_id: min_id)
  71. else
  72. short_account_url(@account, max_id: max_id, min_id: min_id)
  73. end
  74. end
  75. def media_requested?
  76. request.path.ends_with?('/media')
  77. end
  78. def replies_requested?
  79. request.path.ends_with?('/with_replies')
  80. end
  81. def filtered_status_page(params)
  82. if params[:min_id].present?
  83. filtered_statuses.paginate_by_min_id(PAGE_SIZE, params[:min_id]).reverse
  84. else
  85. filtered_statuses.paginate_by_max_id(PAGE_SIZE, params[:max_id], params[:since_id]).to_a
  86. end
  87. end
  88. end