Skip to content

Commit

Permalink
Fix unfollowing remote actors
Browse files Browse the repository at this point in the history
resolves #3462
  • Loading branch information
Floppy committed Jan 22, 2025
1 parent ce05050 commit 528ad8e
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/components/follow_button_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def before_render
@method = :post
else
@path = @target.is_a?(Federails::Actor) ?
follow_remote_actor_path(@target) :
unfollow_remote_actor_path(@target) :
url_for(@target) + "/follows"
@method = @following ? :delete : :post
end
Expand Down
9 changes: 8 additions & 1 deletion app/controllers/follows_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class FollowsController < ApplicationController
before_action :get_target, except: [:index, :new, :remote_follow, :perform_remote_follow, :follow_remote_actor]
before_action :get_target, except: [:index, :new, :remote_follow, :perform_remote_follow, :follow_remote_actor, :unfollow_remote_actor]
skip_after_action :verify_policy_scoped, only: :index
skip_after_action :verify_authorized, only: [:new, :remote_follow, :perform_remote_follow]

Expand Down Expand Up @@ -49,6 +49,13 @@ def follow_remote_actor
redirect_to root_url, notice: t(".followed", actor: @actor.at_address)
end

def unfollow_remote_actor
authorize Federails::Following, :destroy?
@actor = Federails::Actor.find_param(params[:id])
current_user.unfollow(@actor)
redirect_to root_url, notice: t(".unfollowed", actor: @actor.at_address)
end

def create
authorize Federails::Following
current_user.follow @target
Expand Down
2 changes: 1 addition & 1 deletion app/models/concerns/follower.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def follow(target)
end

def unfollow(target)
f = federails_actor.follows?(target.federails_actor)
f = federails_actor.follows?(target.is_a?(Federails::Actor) ? target : target.federails_actor)
f&.destroy unless f == false
end

Expand Down
2 changes: 2 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,8 @@ en:
placeholder: Your Fediverse username, e.g. manyfold@3dp.chat
submit: Take me home
title: Follow %{name}
unfollow_remote_actor:
unfollowed: Unfollowed %{actor}
general:
delete: Delete
download: Download
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
post "/remote_follow" => "follows#remote_follow", :as => :remote_follow
post "/perform_remote_follow" => "follows#perform_remote_follow", :as => :perform_remote_follow
post "/follow_remote_actor/:id" => "follows#follow_remote_actor", :as => :follow_remote_actor
delete "/follow_remote_actor/:id" => "follows#unfollow_remote_actor", :as => :unfollow_remote_actor
end

if SiteSettings.federation_enabled? || Rails.env.test?
Expand Down

0 comments on commit 528ad8e

Please sign in to comment.