From: eal Date: Sun, 19 Nov 2017 23:21:53 +0000 (+0200) Subject: Don't let the user unfollow their own account. X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=4db5954786b60df84b833feb360fd8c81be956d9;p=akkoma Don't let the user unfollow their own account. --- 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)]})