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

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