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

61 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(activity_type: 'Status').where(hidden: false).with_includes.paginate_by_max_id(20, params[:max_id], params[:since_id])
  16. end
  17. format.activitystreams2
  18. end
  19. end
  20. def follow
  21. FollowService.new.call(current_user.account, @account.acct)
  22. redirect_to account_path(@account)
  23. end
  24. def unfollow
  25. UnfollowService.new.call(current_user.account, @account)
  26. redirect_to account_path(@account)
  27. end
  28. def followers
  29. @followers = @account.followers.order('follows.created_at desc').paginate(page: params[:page], per_page: 12)
  30. end
  31. def following
  32. @following = @account.following.order('follows.created_at desc').paginate(page: params[:page], per_page: 12)
  33. end
  34. private
  35. def set_account
  36. @account = Account.find_local!(params[:username])
  37. end
  38. def set_link_headers
  39. 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)]]])
  40. end
  41. def webfinger_account_url
  42. webfinger_url(resource: "acct:#{@account.acct}@#{Rails.configuration.x.local_domain}")
  43. end
  44. def check_account_suspension
  45. head 410 if @account.suspended?
  46. end
  47. end