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.

53 lines
1.0 KiB

  1. # frozen_string_literal: true
  2. class DirectoriesController < ApplicationController
  3. layout 'public'
  4. before_action :check_enabled
  5. before_action :set_instance_presenter
  6. before_action :set_tag, only: :show
  7. before_action :set_tags
  8. before_action :set_accounts
  9. def index
  10. render :index
  11. end
  12. def show
  13. render :index
  14. end
  15. private
  16. def check_enabled
  17. return not_found unless Setting.profile_directory
  18. end
  19. def set_tag
  20. @tag = Tag.discoverable.find_by!(name: params[:id].downcase)
  21. end
  22. def set_tags
  23. @tags = Tag.discoverable.limit(30)
  24. end
  25. def set_accounts
  26. @accounts = Account.searchable.discoverable.page(params[:page]).per(50).tap do |query|
  27. query.merge!(Account.tagged_with(@tag.id)) if @tag
  28. if popular_requested?
  29. query.merge!(Account.popular)
  30. else
  31. query.merge!(Account.by_recent_status)
  32. end
  33. end
  34. end
  35. def set_instance_presenter
  36. @instance_presenter = InstancePresenter.new
  37. end
  38. def popular_requested?
  39. request.path.ends_with?('/popular')
  40. end
  41. end