Add banner and background updating.
This commit is contained in:
parent
5142a8efbb
commit
6c3a0ffae4
3 changed files with 36 additions and 3 deletions
|
@ -70,6 +70,8 @@ def user_fetcher(username) do
|
|||
post "/account/verify_credentials", TwitterAPI.Controller, :verify_credentials
|
||||
|
||||
post "/account/update_profile", TwitterAPI.Controller, :update_profile
|
||||
post "/account/update_profile_banner", TwitterAPI.Controller, :update_banner
|
||||
post "/qvitter/update_background_image", TwitterAPI.Controller, :update_background
|
||||
|
||||
post "/account/most_recent_notification", TwitterAPI.Controller, :update_most_recent_notification
|
||||
|
||||
|
|
|
@ -190,6 +190,30 @@ def update_avatar(%{assigns: %{user: user}} = conn, params) do
|
|||
render(conn, UserView, "show.json", %{user: user, for: user})
|
||||
end
|
||||
|
||||
def update_banner(%{assigns: %{user: user}} = conn, params) do
|
||||
with {:ok, object} <- ActivityPub.upload(%{"img" => params["banner"]}),
|
||||
new_info <- Map.put(user.info, "banner", object.data),
|
||||
change <- User.info_changeset(user, %{info: new_info}),
|
||||
{:ok, user} <- Repo.update(change) do
|
||||
%{"url" => [ %{ "href" => href } | t ]} = object.data
|
||||
response = %{ url: href } |> Poison.encode!
|
||||
conn
|
||||
|> json_reply(200, response)
|
||||
end
|
||||
end
|
||||
|
||||
def update_background(%{assigns: %{user: user}} = conn, params) do
|
||||
with {:ok, object} <- ActivityPub.upload(params),
|
||||
new_info <- Map.put(user.info, "background", object.data),
|
||||
change <- User.info_changeset(user, %{info: new_info}),
|
||||
{:ok, user} <- Repo.update(change) do
|
||||
%{"url" => [ %{ "href" => href } | t ]} = object.data
|
||||
response = %{ url: href } |> Poison.encode!
|
||||
conn
|
||||
|> json_reply(200, response)
|
||||
end
|
||||
end
|
||||
|
||||
def external_profile(%{assigns: %{user: current_user}} = conn, %{"profileurl" => uri}) do
|
||||
with {:ok, user_map} <- TwitterAPI.get_external_profile(current_user, uri),
|
||||
response <- Poison.encode!(user_map) do
|
||||
|
@ -229,8 +253,10 @@ def friends(%{assigns: %{user: user}} = conn, _params) do
|
|||
end
|
||||
|
||||
def update_profile(%{assigns: %{user: user}} = conn, params) do
|
||||
if bio = params["description"] do
|
||||
params = Map.put(params, "bio", bio)
|
||||
params = if bio = params["description"] do
|
||||
Map.put(params, "bio", bio)
|
||||
else
|
||||
params
|
||||
end
|
||||
|
||||
with changeset <- User.update_changeset(user, params),
|
||||
|
|
|
@ -11,6 +11,9 @@ def render("index.json", %{users: users, for: user}) do
|
|||
render_many(users, Pleroma.Web.TwitterAPI.UserView, "user.json", for: user)
|
||||
end
|
||||
|
||||
defp image_url(%{"url" => [ %{ "href" => href } | t ]}), do: href
|
||||
defp image_url(_), do: nil
|
||||
|
||||
def render("user.json", %{user: user = %User{}} = assigns) do
|
||||
image = User.avatar_url(user)
|
||||
following = if assigns[:for] do
|
||||
|
@ -37,7 +40,9 @@ def render("user.json", %{user: user = %User{}} = assigns) do
|
|||
"rights" => %{},
|
||||
"screen_name" => user.nickname,
|
||||
"statuses_count" => user_info[:note_count],
|
||||
"statusnet_profile_url" => user.ap_id
|
||||
"statusnet_profile_url" => user.ap_id,
|
||||
"cover_photo" => image_url(user.info["banner"]),
|
||||
"background_image" => image_url(user.info["background"])
|
||||
}
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue