Don't let the user unfollow their own account.
authoreal <eal@waifu.club>
Sun, 19 Nov 2017 23:21:53 +0000 (01:21 +0200)
committereal <eal@waifu.club>
Mon, 20 Nov 2017 05:50:56 +0000 (07:50 +0200)
lib/pleroma/user.ex
test/user_test.exs

index dde51bd3050deb440c40defbfec1c8ba41d43885..59d4fb839f4254eba5c039187871555b547e5d12 100644 (file)
@@ -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)
 
index 430f56846c920b8de84f7c37a185cebc60ee4c60..e9f7a866684b4a6d3e82b58d74db5822eff7ba5c 100644 (file)
@@ -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)]})