Skip to content

Commit 0ad1bd8

Browse files
authored
Merge pull request #3470 from manyfold3d/fix-unfollow-remote
Fix unfollowing remote actors
2 parents ce05050 + 528ad8e commit 0ad1bd8

File tree

5 files changed

+13
-3
lines changed

5 files changed

+13
-3
lines changed

app/components/follow_button_component.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def before_render
1818
@method = :post
1919
else
2020
@path = @target.is_a?(Federails::Actor) ?
21-
follow_remote_actor_path(@target) :
21+
unfollow_remote_actor_path(@target) :
2222
url_for(@target) + "/follows"
2323
@method = @following ? :delete : :post
2424
end

app/controllers/follows_controller.rb

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class FollowsController < ApplicationController
2-
before_action :get_target, except: [:index, :new, :remote_follow, :perform_remote_follow, :follow_remote_actor]
2+
before_action :get_target, except: [:index, :new, :remote_follow, :perform_remote_follow, :follow_remote_actor, :unfollow_remote_actor]
33
skip_after_action :verify_policy_scoped, only: :index
44
skip_after_action :verify_authorized, only: [:new, :remote_follow, :perform_remote_follow]
55

@@ -49,6 +49,13 @@ def follow_remote_actor
4949
redirect_to root_url, notice: t(".followed", actor: @actor.at_address)
5050
end
5151

52+
def unfollow_remote_actor
53+
authorize Federails::Following, :destroy?
54+
@actor = Federails::Actor.find_param(params[:id])
55+
current_user.unfollow(@actor)
56+
redirect_to root_url, notice: t(".unfollowed", actor: @actor.at_address)
57+
end
58+
5259
def create
5360
authorize Federails::Following
5461
current_user.follow @target

app/models/concerns/follower.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def follow(target)
1616
end
1717

1818
def unfollow(target)
19-
f = federails_actor.follows?(target.federails_actor)
19+
f = federails_actor.follows?(target.is_a?(Federails::Actor) ? target : target.federails_actor)
2020
f&.destroy unless f == false
2121
end
2222

config/locales/en.yml

+2
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,8 @@ en:
311311
placeholder: Your Fediverse username, e.g. [email protected]
312312
submit: Take me home
313313
title: Follow %{name}
314+
unfollow_remote_actor:
315+
unfollowed: Unfollowed %{actor}
314316
general:
315317
delete: Delete
316318
download: Download

config/routes.rb

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
post "/remote_follow" => "follows#remote_follow", :as => :remote_follow
4646
post "/perform_remote_follow" => "follows#perform_remote_follow", :as => :perform_remote_follow
4747
post "/follow_remote_actor/:id" => "follows#follow_remote_actor", :as => :follow_remote_actor
48+
delete "/follow_remote_actor/:id" => "follows#unfollow_remote_actor", :as => :unfollow_remote_actor
4849
end
4950

5051
if SiteSettings.federation_enabled? || Rails.env.test?

0 commit comments

Comments
 (0)