Handle black name fields on incoming users.
[akkoma] / lib / pleroma / user.ex
index ddf66cee95ee4840d9823851921f362ed881e252..ab29fe6f452f352a3a83d6a325cb4cf724d9aaff 100644 (file)
@@ -150,11 +150,12 @@ defmodule Pleroma.User do
 
   def follow(%User{} = follower, %User{info: info} = followed) do
     ap_followers = followed.follower_address
+
     if following?(follower, followed) or info["deactivated"] do
       {:error,
        "Could not follow user: #{followed.nickname} is already on your list."}
     else
-      if !followed.local && follower.local do
+      if !followed.local && follower.local && !ap_enabled?(followed) do
         Websub.subscribe(follower, followed)
       end
 
@@ -416,8 +417,15 @@ defmodule Pleroma.User do
     end
   end
 
+  defp blank?(""), do: nil
+  defp blank?(n), do: n
+
   def insert_or_update_user(data) do
+    data = data
+    |> Map.put(:name, blank?(data[:name]) || data[:nickname])
     cs = User.remote_user_creation(data)
     Repo.insert(cs, on_conflict: :replace_all, conflict_target: :nickname)
   end
+
+  def ap_enabled?(%User{info: %{"ap_enabled" => ap}}), do: ap
 end