From 4db5954786b60df84b833feb360fd8c81be956d9 Mon Sep 17 00:00:00 2001 From: eal Date: Mon, 20 Nov 2017 01:21:53 +0200 Subject: [PATCH] Don't let the user unfollow their own account. --- lib/pleroma/user.ex | 2 +- test/user_test.exs | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index dde51bd30..59d4fb839 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -167,7 +167,7 @@ defmodule Pleroma.User do def unfollow(%User{} = follower, %User{} = followed) do ap_followers = followed.follower_address - if following?(follower, followed) do + if following?(follower, followed) and follower.ap_id != followed.ap_id do following = follower.following |> List.delete(ap_followers) diff --git a/test/user_test.exs b/test/user_test.exs index 430f56846..e9f7a8666 100644 --- a/test/user_test.exs +++ b/test/user_test.exs @@ -66,6 +66,15 @@ defmodule Pleroma.UserTest do assert user.following == [] end + test "unfollow doesn't unfollow yourself" do + user = insert(:user) + + {:error, _} = User.unfollow(user, user) + + assert user.following == [user.ap_id] + end + + test "test if a user is following another user" do followed = insert(:user) user = insert(:user, %{following: [User.ap_followers(followed)]}) -- 2.45.2