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

59 lines
1.8 KiB

  1. # frozen_string_literal: true
  2. class AccountsController < ApplicationController
  3. layout 'public'
  4. before_action :set_account
  5. before_action :set_link_headers
  6. before_action :authenticate_user!, only: [:follow, :unfollow]
  7. before_action :check_account_suspension
  8. def show
  9. respond_to do |format|
  10. format.html do
  11. @statuses = @account.statuses.permitted_for(@account, current_account).order('id desc').paginate_by_max_id(20, params[:max_id], params[:since_id])
  12. @statuses = cache_collection(@statuses, Status)
  13. end
  14. format.atom do
  15. @entries = @account.stream_entries.order('id desc').where(hidden: false).with_includes.paginate_by_max_id(20, params[:max_id], params[:since_id])
  16. end
  17. end
  18. end
  19. def follow
  20. FollowService.new.call(current_user.account, @account.acct)
  21. redirect_to account_path(@account)
  22. end
  23. def unfollow
  24. UnfollowService.new.call(current_user.account, @account)
  25. redirect_to account_path(@account)
  26. end
  27. def followers
  28. @followers = @account.followers.order('follows.created_at desc').paginate(page: params[:page], per_page: 12)
  29. end
  30. def following
  31. @following = @account.following.order('follows.created_at desc').paginate(page: params[:page], per_page: 12)
  32. end
  33. private
  34. def set_account
  35. @account = Account.find_local!(params[:username])
  36. end
  37. def set_link_headers
  38. response.headers['Link'] = LinkHeader.new([[webfinger_account_url, [%w(rel lrdd), %w(type application/xrd+xml)]], [account_url(@account, format: 'atom'), [%w(rel alternate), %w(type application/atom+xml)]]])
  39. end
  40. def webfinger_account_url
  41. webfinger_url(resource: "acct:#{@account.acct}@#{Rails.configuration.x.local_domain}")
  42. end
  43. def check_account_suspension
  44. head 410 if @account.suspended?
  45. end
  46. end