Add User.get_domain/1

This commit is contained in:
Alex Gleason 2020-07-27 17:49:33 -05:00
parent 93bbbba883
commit 7c0c499c2e
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
2 changed files with 9 additions and 0 deletions

View File

@ -2293,4 +2293,8 @@ defmodule Pleroma.User do
|> Map.put(:bio, HTML.filter_tags(user.bio, filter))
|> Map.put(:fields, fields)
end
def get_domain(%User{ap_id: ap_id} = user) do
URI.parse(ap_id).host
end
end

View File

@ -1885,4 +1885,9 @@ defmodule Pleroma.UserTest do
assert User.avatar_url(user, no_default: true) == nil
end
test "get_domain/1" do
user = insert(:user, ap_id: "https://lain.com/users/lain", nickname: "lain")
assert User.get_domain(user) == "lain.com"
end
end