about summary refs log tree commit diff
path: root/app/controllers/remote_unfollows.rb
diff options
context:
space:
mode:
authorThibG <thib@sitedethib.com>2018-04-08 13:40:22 +0200
committerEugen Rochko <eugen@zeonfederated.com>2018-04-08 13:40:22 +0200
commit1364e9e4ae1fb12a1c970795f1d0afd651c7cfe2 (patch)
tree0c835286de94b4a1dc8a5ba973c80922d226a9ee /app/controllers/remote_unfollows.rb
parent1ed1014546bcfef0d2441702673deab586f6bca0 (diff)
Fix follow/unfollow buttons on public profile (fixes #7036) (#7040)
* Fix follow/unfollow buttons on public profile

- Present non-logged users with web+mastodon:// URLs for remote accounts
- Present logged-in users with appropriate links (authorize_follows and
  remote_unfollows) for remote accounts

* Do not cache rendered cards if user is logged in
Diffstat (limited to 'app/controllers/remote_unfollows.rb')
-rw-r--r--app/controllers/remote_unfollows.rb39
1 files changed, 39 insertions, 0 deletions
diff --git a/app/controllers/remote_unfollows.rb b/app/controllers/remote_unfollows.rb
new file mode 100644
index 000000000..af5943363
--- /dev/null
+++ b/app/controllers/remote_unfollows.rb
@@ -0,0 +1,39 @@
+# frozen_string_literal: true
+
+class RemoteUnfollowsController < ApplicationController
+  layout 'modal'
+
+  before_action :authenticate_user!
+  before_action :set_body_classes
+
+  def create
+    @account = unfollow_attempt.try(:target_account)
+
+    if @account.nil?
+      render :error
+    else
+      render :success
+    end
+  rescue ActiveRecord::RecordNotFound, Mastodon::NotPermittedError
+    render :error
+  end
+
+  private
+
+  def unfollow_attempt
+    username, domain = acct_without_prefix.split('@')
+    UnfollowService.new.call(current_account, Account.find_remote!(username, domain))
+  end
+
+  def acct_without_prefix
+    acct_params.gsub(/\Aacct:/, '')
+  end
+
+  def acct_params
+    params.fetch(:acct, '')
+  end
+
+  def set_body_classes
+    @body_classes = 'modal-layout'
+  end
+end