Salmon: generate private key with native crypto if available.
[akkoma] / lib / pleroma / user.ex
index 56502e8973210d3d23f358e43bcdf491655e4251..68ffe184b7b36fa031ecdbca12259fd88ec5609e 100644 (file)
@@ -5,7 +5,6 @@ defmodule Pleroma.User do
   alias Pleroma.{Repo, User, Object, Web, Activity, Notification}
   alias Comeonin.Pbkdf2
   alias Pleroma.Web.{OStatus, Websub}
-  alias Pleroma.Web.ActivityPub.ActivityPub
   alias Pleroma.Web.ActivityPub.Utils
 
   schema "users" do
@@ -62,8 +61,9 @@ defmodule Pleroma.User do
   end
 
   def user_info(%User{} = user) do
+    oneself = if user.local, do: 1, else: 0
     %{
-      following_count: length(user.following),
+      following_count: length(user.following) - oneself,
       note_count: user.info["note_count"] || 0,
       follower_count: user.info["follower_count"] || 0
     }
@@ -89,7 +89,7 @@ defmodule Pleroma.User do
   end
 
   def update_changeset(struct, params \\ %{}) do
-    changeset = struct
+    struct
     |> cast(params, [:bio, :name])
     |> unique_constraint(:nickname)
     |> validate_format(:nickname, ~r/^[a-zA-Z\d]+$/)
@@ -159,7 +159,7 @@ defmodule Pleroma.User do
       |> follow_changeset(%{following: following})
       |> Repo.update
 
-      {:ok, followed} = update_follower_count(followed)
+      {:ok, _} = update_follower_count(followed)
 
       follower
     end
@@ -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)
 
@@ -214,7 +214,7 @@ defmodule Pleroma.User do
     with %User{} = user <- get_by_nickname(nickname)  do
       user
     else _e ->
-      with [nick, domain] <- String.split(nickname, "@"),
+      with [_nick, _domain] <- String.split(nickname, "@"),
            {:ok, user} <- OStatus.make_user(nickname) do
         user
       else _e -> nil
@@ -265,6 +265,7 @@ defmodule Pleroma.User do
   def update_follower_count(%User{} = user) do
     follower_count_query = from u in User,
       where: fragment("? @> ?", u.following, ^user.follower_address),
+      where: u.id != ^user.id,
       select: count(u.id)
 
     follower_count = Repo.one(follower_count_query)
@@ -276,7 +277,7 @@ defmodule Pleroma.User do
     Repo.update(cs)
   end
 
-  def get_notified_from_activity(%Activity{data: %{"to" => to}} = activity) do
+  def get_notified_from_activity(%Activity{data: %{"to" => to}}) do
     query = from u in User,
       where: u.ap_id in ^to,
       where: u.local == true
@@ -284,14 +285,14 @@ defmodule Pleroma.User do
     Repo.all(query)
   end
 
-  def get_recipients_from_activity(%Activity{data: %{"to" => to}} = activity) do
+  def get_recipients_from_activity(%Activity{data: %{"to" => to}}) do
     query = from u in User,
-      where: u.local == true
-
-    query = from u in query,
       where: u.ap_id in ^to,
       or_where: fragment("? \\\?| ?", u.following, ^to)
 
+    query = from u in query,
+      where: u.local == true
+
     Repo.all(query)
   end