From 2b664b048eac5f37421ab958e26efed9c158c8d0 Mon Sep 17 00:00:00 2001 From: lain Date: Mon, 3 Jun 2019 18:16:11 +0200 Subject: [PATCH] User: Add function to get AP ids from nicknames. --- lib/pleroma/user.ex | 8 ++++++++ test/user_test.exs | 12 ++++++++++++ 2 files changed, 20 insertions(+) diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 474cd8c1a..dc534b05c 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -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 diff --git a/test/user_test.exs b/test/user_test.exs index 019f2b56d..d7473ef43 100644 --- a/test/user_test.exs +++ b/test/user_test.exs @@ -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 -- 2.45.2