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

53 lines
1.5 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. def show
  7. respond_to do |format|
  8. format.html do
  9. @statuses = @account.statuses.order('id desc').paginate_by_max_id(20, params[:max_id], params[:since_id])
  10. @statuses = cache_collection(@statuses, Status)
  11. end
  12. format.atom do
  13. @entries = @account.stream_entries.order('id desc').with_includes.paginate_by_max_id(20, params[:max_id], params[:since_id])
  14. end
  15. end
  16. end
  17. def follow
  18. FollowService.new.call(current_user.account, @account.acct)
  19. redirect_to account_path(@account)
  20. end
  21. def unfollow
  22. UnfollowService.new.call(current_user.account, @account)
  23. redirect_to account_path(@account)
  24. end
  25. def followers
  26. @followers = @account.followers.order('follows.created_at desc').paginate(page: params[:page], per_page: 12)
  27. end
  28. def following
  29. @following = @account.following.order('follows.created_at desc').paginate(page: params[:page], per_page: 12)
  30. end
  31. private
  32. def set_account
  33. @account = Account.find_local!(params[:username])
  34. end
  35. def set_link_headers
  36. 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)]]])
  37. end
  38. def webfinger_account_url
  39. webfinger_url(resource: "acct:#{@account.acct}@#{Rails.configuration.x.local_domain}")
  40. end
  41. end