User: Add function to get AP ids from nicknames.
authorlain <lain@soykaf.club>
Mon, 3 Jun 2019 16:16:11 +0000 (18:16 +0200)
committerlain <lain@soykaf.club>
Mon, 3 Jun 2019 16:16:11 +0000 (18:16 +0200)
lib/pleroma/user.ex
test/user_test.exs

index 474cd8c1a1b668026271290b253713b321bdaf6b..dc534b05c1e42aa9da56abba0dcf01cdafbf1461 100644 (file)
@@ -1441,4 +1441,12 @@ defmodule Pleroma.User do
       update_and_set_cache(cng)
     end
   end
+
+  def get_ap_ids_by_nicknames(nicknames) do
+    from(u in User,
+      where: u.nickname in ^nicknames,
+      select: u.ap_id
+    )
+    |> Repo.all()
+  end
 end
index 019f2b56d1fb648aff531e5a4916211be5cdf3a1..d7473ef4323413ca223c8848735ea8dce9f69dca 100644 (file)
@@ -1266,4 +1266,16 @@ defmodule Pleroma.UserTest do
       assert user.info.keys == "xxx"
     end
   end
+
+  describe "get_ap_ids_by_nicknames" do
+    test "it returns a list of AP ids for a given set of nicknames" do
+      user = insert(:user)
+      user_two = insert(:user)
+
+      ap_ids = User.get_ap_ids_by_nicknames([user.nickname, user_two.nickname, "nonexistent"])
+      assert length(ap_ids) == 2
+      assert user.ap_id in ap_ids
+      assert user_two.ap_id in ap_ids
+    end
+  end
 end