35 lines
982 B
Elixir
35 lines
982 B
Elixir
# Pleroma: A lightweight social networking server
|
|
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
defmodule Pleroma.Web.StaticFE.UserRepresenter do
|
|
alias Pleroma.User
|
|
alias Pleroma.Web.ActivityPub.ActivityPub
|
|
alias Pleroma.Web.StaticFE.ActivityRepresenter
|
|
|
|
def prepare_user(%User{} = user) do
|
|
%{}
|
|
|> set_user(user)
|
|
|> set_timeline(user)
|
|
end
|
|
|
|
defp set_user(data, %User{} = user), do: Map.put(data, :user, user)
|
|
|
|
defp set_timeline(data, %User{} = user) do
|
|
activities =
|
|
ActivityPub.fetch_user_activities(user, nil, %{})
|
|
|> Enum.map(fn activity -> ActivityRepresenter.prepare_activity(user, activity) end)
|
|
|
|
Map.put(data, :timeline, activities)
|
|
end
|
|
|
|
def represent(username_or_id) do
|
|
with %User{} = user <- User.get_cached_by_nickname_or_id(username_or_id),
|
|
data <- prepare_user(user) do
|
|
{:ok, data}
|
|
else
|
|
e ->
|
|
{:error, e}
|
|
end
|
|
end
|
|
end
|