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

91 lines
3.0 KiB

  1. # frozen_string_literal: true
  2. class AboutController < ApplicationController
  3. layout 'public'
  4. # before_action :require_open_federation!, only: [:show, :more]
  5. before_action :set_body_classes, only: :show
  6. before_action :set_instance_presenter
  7. before_action :set_expires_in, only: [:show, :more, :terms]
  8. before_action :authenticate_user!, only: [:jump, :my_data]
  9. skip_before_action :require_functional!, only: [:more, :terms]
  10. def show; end
  11. def more
  12. flash.now[:notice] = I18n.t('about.instance_actor_flash') if params[:instance_actor]
  13. toc_generator = TOCGenerator.new(@instance_presenter.site_extended_description)
  14. @contents = toc_generator.html
  15. @table_of_contents = toc_generator.toc
  16. @blocks = DomainBlock.with_user_facing_limitations.by_severity if display_blocks?
  17. end
  18. def terms; end
  19. def jump
  20. @jump_url = "https://#{request.fullpath[6..-1]}"
  21. end
  22. def my_data
  23. @account = current_account
  24. year = params[:year].to_i
  25. year = nil unless year > 2000
  26. @year_text = year or ''
  27. y = year ? "statuses.created_at >= '#{year}-1-1' and statuses.created_at < '#{year+1}-1-1'" : nil
  28. y2 = year ? "s2.created_at >= '#{year}-1-1' and s2.created_at < '#{year+1}-1-1'" : nil
  29. def raw_to_list(r)
  30. r.map{|k,v| {:account => Account.find(k), :num => v.to_s}}
  31. end
  32. @total = @account.statuses.where(y).count
  33. @most_times = @account.statuses.where(y).group('cast (created_at as date)').reorder('count_id desc').limit(1).count(:id).map{ |k,v| {:date => k.to_s, :num => v.to_s}}
  34. @most_fav = @account.statuses.where(y).joins(:status_stat).reorder('status_stats.favourites_count desc').first
  35. @like_me_most = raw_to_list(@account.statuses.where(y).joins(:favourites).group('favourites.account_id').reorder('count_id desc').limit(5).count(:id))
  36. @i_like_most = raw_to_list(@account.favourites.where(y).joins(:status).group('statuses.account_id').reorder('count_id desc').limit(5).count(:id))
  37. @communi_most = raw_to_list(@account.statuses.where(y).where(y2).joins('join statuses as s2 on statuses.account_id != s2.account_id and (statuses.in_reply_to_id = s2.id or s2.in_reply_to_id = statuses.id)').group('s2.account_id').reorder('count_id desc').limit(3).count(:id))
  38. end
  39. helper_method :display_blocks?
  40. helper_method :display_blocks_rationale?
  41. helper_method :public_fetch_mode?
  42. helper_method :new_user
  43. private
  44. def require_open_federation!
  45. not_found if whitelist_mode?
  46. end
  47. def display_blocks?
  48. Setting.show_domain_blocks == 'all' || (Setting.show_domain_blocks == 'users' && user_signed_in?)
  49. end
  50. def display_blocks_rationale?
  51. Setting.show_domain_blocks_rationale == 'all' || (Setting.show_domain_blocks_rationale == 'users' && user_signed_in?)
  52. end
  53. def new_user
  54. User.new.tap do |user|
  55. user.build_account
  56. user.build_invite_request
  57. end
  58. end
  59. def set_instance_presenter
  60. @instance_presenter = InstancePresenter.new
  61. end
  62. def set_body_classes
  63. @hide_navbar = true
  64. end
  65. def set_expires_in
  66. expires_in 0, public: true
  67. end
  68. end