about summary refs log tree commit diff
path: root/app/controllers
diff options
context:
space:
mode:
authormultiple creatures <dev@multiple-creature.party>2019-08-10 03:21:04 -0500
committermultiple creatures <dev@multiple-creature.party>2019-08-10 03:21:04 -0500
commit8a7605e5027d55925c4e0497e8a25e52e2ed87d3 (patch)
tree7b4741d4f9292bf65c71fcf6528108d8f0643c08 /app/controllers
parent2a41140dc73b8c527c5fde138d23a45da8b8e264 (diff)
fix interaction buttons on public pages
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/remote_follow_controller.rb14
-rw-r--r--app/controllers/remote_interaction_controller.rb38
2 files changed, 25 insertions, 27 deletions
diff --git a/app/controllers/remote_follow_controller.rb b/app/controllers/remote_follow_controller.rb
index 17bc1940a..dc15e63bf 100644
--- a/app/controllers/remote_follow_controller.rb
+++ b/app/controllers/remote_follow_controller.rb
@@ -9,18 +9,10 @@ class RemoteFollowController < ApplicationController
   before_action :set_body_classes
 
   def new
-    @remote_follow = RemoteFollow.new(session_params)
-  end
-
-  def create
-    @remote_follow = RemoteFollow.new(resource_params)
+    raise Mastodon::NotPermittedError unless user_signed_in?
 
-    if @remote_follow.valid?
-      session[:remote_follow] = @remote_follow.acct
-      redirect_to @remote_follow.subscribe_address_for(@account)
-    else
-      render :new
-    end
+    FollowService.new.call(current_account, @account)
+    redirect_to TagManager.instance.url_for(@account)
   end
 
   private
diff --git a/app/controllers/remote_interaction_controller.rb b/app/controllers/remote_interaction_controller.rb
index d7197d434..b1b304055 100644
--- a/app/controllers/remote_interaction_controller.rb
+++ b/app/controllers/remote_interaction_controller.rb
@@ -5,24 +5,34 @@ class RemoteInteractionController < ApplicationController
 
   layout 'modal'
 
-  before_action :set_interaction_type
-  before_action :set_status
   before_action :set_body_classes
   before_action :set_pack
+  before_action :set_status
 
   def new
-    @remote_follow = RemoteFollow.new(session_params)
-  end
-
-  def create
-    @remote_follow = RemoteFollow.new(resource_params)
+    raise Mastodon::NotPermittedError unless user_signed_in?
 
-    if @remote_follow.valid?
-      session[:remote_follow] = @remote_follow.acct
-      redirect_to @remote_follow.interact_address_for(@status)
-    else
-      render :new
+    case params[:type]
+    when 'reblog'
+      if current_account.statuses.where(reblog: @status).exists?
+        status = current_account.statuses.find_by(reblog: @status)
+        RemoveStatusService.new.call(status)
+      else
+        ReblogService.new.call(current_account, @status)
+      end
+    when 'favourite'
+      if Favourite.where(account: current_account, status: @status).exists?
+        UnfavouriteService.new.call(current_account, @status)
+      else
+        FavouriteService.new.call(current_account, @status)
+      end
+    when 'follow'
+      FollowService.new.call(current_account, @status.account)
+    when 'unfollow'
+      UnfollowService.new.call(current_account, @status.account)
     end
+
+    redirect_to TagManager.instance.url_for(@status)
   end
 
   private
@@ -51,8 +61,4 @@ class RemoteInteractionController < ApplicationController
   def set_pack
     use_pack 'modal'
   end
-
-  def set_interaction_type
-    @interaction_type = %w(reply reblog favourite).include?(params[:type]) ? params[:type] : 'reply'
-  end
 end