about summary refs log tree commit diff
path: root/app/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/account_follow_controller.rb12
-rw-r--r--app/controllers/account_unfollow_controller.rb12
-rw-r--r--app/controllers/accounts_controller.rb37
-rw-r--r--app/controllers/concerns/account_controller_concern.rb51
-rw-r--r--app/controllers/follower_accounts_controller.rb15
-rw-r--r--app/controllers/following_accounts_controller.rb15
6 files changed, 106 insertions, 36 deletions
diff --git a/app/controllers/account_follow_controller.rb b/app/controllers/account_follow_controller.rb
new file mode 100644
index 000000000..185a355f8
--- /dev/null
+++ b/app/controllers/account_follow_controller.rb
@@ -0,0 +1,12 @@
+# frozen_string_literal: true
+
+class AccountFollowController < ApplicationController
+  include AccountControllerConcern
+
+  before_action :authenticate_user!
+
+  def create
+    FollowService.new.call(current_user.account, @account.acct)
+    redirect_to account_path(@account)
+  end
+end
diff --git a/app/controllers/account_unfollow_controller.rb b/app/controllers/account_unfollow_controller.rb
new file mode 100644
index 000000000..378ec86dc
--- /dev/null
+++ b/app/controllers/account_unfollow_controller.rb
@@ -0,0 +1,12 @@
+# frozen_string_literal: true
+
+class AccountUnfollowController < ApplicationController
+  include AccountControllerConcern
+
+  before_action :authenticate_user!
+
+  def create
+    UnfollowService.new.call(current_user.account, @account)
+    redirect_to account_path(@account)
+  end
+end
diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb
index d4f157614..8eda96336 100644
--- a/app/controllers/accounts_controller.rb
+++ b/app/controllers/accounts_controller.rb
@@ -1,12 +1,7 @@
 # frozen_string_literal: true
 
 class AccountsController < ApplicationController
-  layout 'public'
-
-  before_action :set_account
-  before_action :set_link_headers
-  before_action :authenticate_user!, only: [:follow, :unfollow]
-  before_action :check_account_suspension
+  include AccountControllerConcern
 
   def show
     respond_to do |format|
@@ -24,39 +19,9 @@ class AccountsController < ApplicationController
     end
   end
 
-  def follow
-    FollowService.new.call(current_user.account, @account.acct)
-    redirect_to account_path(@account)
-  end
-
-  def unfollow
-    UnfollowService.new.call(current_user.account, @account)
-    redirect_to account_path(@account)
-  end
-
-  def followers
-    @followers = @account.followers.order('follows.created_at desc').page(params[:page]).per(12)
-  end
-
-  def following
-    @following = @account.following.order('follows.created_at desc').page(params[:page]).per(12)
-  end
-
   private
 
   def set_account
     @account = Account.find_local!(params[:username])
   end
-
-  def set_link_headers
-    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)]]])
-  end
-
-  def webfinger_account_url
-    webfinger_url(resource: @account.to_webfinger_s)
-  end
-
-  def check_account_suspension
-    gone if @account.suspended?
-  end
 end
diff --git a/app/controllers/concerns/account_controller_concern.rb b/app/controllers/concerns/account_controller_concern.rb
new file mode 100644
index 000000000..d36fc8c93
--- /dev/null
+++ b/app/controllers/concerns/account_controller_concern.rb
@@ -0,0 +1,51 @@
+# frozen_string_literal: true
+
+module AccountControllerConcern
+  extend ActiveSupport::Concern
+
+  FOLLOW_PER_PAGE = 12
+
+  included do
+    layout 'public'
+    before_action :set_account
+    before_action :set_link_headers
+    before_action :check_account_suspension
+  end
+
+  private
+
+  def set_account
+    @account = Account.find_local!(params[:account_username])
+  end
+
+  def set_link_headers
+    response.headers['Link'] = LinkHeader.new(
+      [
+        webfinger_account_link,
+        atom_account_url_link,
+      ]
+    )
+  end
+
+  def webfinger_account_link
+    [
+      webfinger_account_url,
+      [%w(rel lrdd), %w(type application/xrd+xml)],
+    ]
+  end
+
+  def atom_account_url_link
+    [
+      account_url(@account, format: 'atom'),
+      [%w(rel alternate), %w(type application/atom+xml)],
+    ]
+  end
+
+  def webfinger_account_url
+    webfinger_url(resource: @account.to_webfinger_s)
+  end
+
+  def check_account_suspension
+    gone if @account.suspended?
+  end
+end
diff --git a/app/controllers/follower_accounts_controller.rb b/app/controllers/follower_accounts_controller.rb
new file mode 100644
index 000000000..165cbf1b5
--- /dev/null
+++ b/app/controllers/follower_accounts_controller.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class FollowerAccountsController < ApplicationController
+  include AccountControllerConcern
+
+  def index
+    @accounts = ordered_accounts.page(params[:page]).per(FOLLOW_PER_PAGE)
+  end
+
+  private
+
+  def ordered_accounts
+    @account.followers.order('follows.created_at desc')
+  end
+end
diff --git a/app/controllers/following_accounts_controller.rb b/app/controllers/following_accounts_controller.rb
new file mode 100644
index 000000000..faeea144a
--- /dev/null
+++ b/app/controllers/following_accounts_controller.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class FollowingAccountsController < ApplicationController
+  include AccountControllerConcern
+
+  def index
+    @accounts = ordered_accounts.page(params[:page]).per(FOLLOW_PER_PAGE)
+  end
+
+  private
+
+  def ordered_accounts
+    @account.following.order('follows.created_at desc')
+  end
+end