forked from AkkomaGang/akkoma
Add basic Ostatus user representer.
This commit is contained in:
parent
ce6cc84a4a
commit
36e883cd4b
4 changed files with 39 additions and 5 deletions
|
@ -18,6 +18,13 @@ defmodule Pleroma.User do
|
|||
timestamps()
|
||||
end
|
||||
|
||||
def avatar_url(user) do
|
||||
case user.avatar do
|
||||
%{"url" => [%{"href" => href} | _]} -> href
|
||||
_ -> "https://placehold.it/48x48"
|
||||
end
|
||||
end
|
||||
|
||||
def ap_id(%User{nickname: nickname}) do
|
||||
"#{Pleroma.Web.base_url}/users/#{nickname}"
|
||||
end
|
||||
|
|
14
lib/pleroma/web/ostatus/user_representer.ex
Normal file
14
lib/pleroma/web/ostatus/user_representer.ex
Normal file
|
@ -0,0 +1,14 @@
|
|||
defmodule Pleroma.Web.OStatus.UserRepresenter do
|
||||
alias Pleroma.User
|
||||
def to_tuple(user, wrapper \\ :author) do
|
||||
{
|
||||
wrapper, [
|
||||
{ :id, user.ap_id },
|
||||
{ :"activity:object", "http://activitystrea.ms/schema/1.0/person" },
|
||||
{ :uri, user.ap_id },
|
||||
{ :name, user.nickname },
|
||||
{ :link, %{rel: "avatar", href: User.avatar_url(user)}}
|
||||
]
|
||||
}
|
||||
end
|
||||
end
|
|
@ -4,11 +4,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.UserRepresenter do
|
|||
alias Pleroma.User
|
||||
|
||||
def to_map(user, opts) do
|
||||
image = case user.avatar do
|
||||
%{"url" => [%{"href" => href} | _]} -> href
|
||||
_ -> "https://placehold.it/48x48"
|
||||
end
|
||||
|
||||
image = User.avatar_url(user)
|
||||
following = if opts[:for] do
|
||||
User.following?(opts[:for], user)
|
||||
else
|
||||
|
|
17
test/web/ostatus/user_representer_test.exs
Normal file
17
test/web/ostatus/user_representer_test.exs
Normal file
|
@ -0,0 +1,17 @@
|
|||
defmodule Pleroma.Web.OStatus.UserRepresenterTest do
|
||||
use Pleroma.DataCase
|
||||
alias Pleroma.Web.OStatus.UserRepresenter
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
test "returns a user with id, uri, name and link" do
|
||||
user = build(:user)
|
||||
tuple = UserRepresenter.to_tuple(user)
|
||||
{:author, author} = tuple
|
||||
|
||||
[:id, :uri, :name, :link]
|
||||
|> Enum.each(fn (tag) ->
|
||||
assert Enum.find(author, fn(e) -> tag == elem(e, 0) end)
|
||||
end)
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue