aboutsummaryrefslogtreecommitdiff
path: root/lib/pleroma/web
diff options
context:
space:
mode:
Diffstat (limited to 'lib/pleroma/web')
-rw-r--r--lib/pleroma/web/activity_pub/activity_pub.ex2
-rw-r--r--lib/pleroma/web/router.ex1
-rw-r--r--lib/pleroma/web/twitter_api/representers/user_representer.ex6
-rw-r--r--lib/pleroma/web/twitter_api/twitter_api_controller.ex13
4 files changed, 19 insertions, 3 deletions
diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex
index 0d3360ee1..125473b96 100644
--- a/lib/pleroma/web/activity_pub/activity_pub.ex
+++ b/lib/pleroma/web/activity_pub/activity_pub.ex
@@ -167,7 +167,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
Repo.all(query)
end
- def upload(%Plug.Upload{} = file) do
+ def upload(file) do
data = Upload.store(file)
Repo.insert(%Object{data: data})
end
diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex
index 30e8e12cb..0446f622b 100644
--- a/lib/pleroma/web/router.ex
+++ b/lib/pleroma/web/router.ex
@@ -47,5 +47,6 @@ defmodule Pleroma.Web.Router do
post "/favorites/create", TwitterAPI.Controller, :favorite
post "/favorites/destroy/:id", TwitterAPI.Controller, :unfavorite
post "/statuses/retweet/:id", TwitterAPI.Controller, :retweet
+ post "/qvitter/update_avatar", TwitterAPI.Controller, :update_avatar
end
end
diff --git a/lib/pleroma/web/twitter_api/representers/user_representer.ex b/lib/pleroma/web/twitter_api/representers/user_representer.ex
index d8f98488e..2ee4ee254 100644
--- a/lib/pleroma/web/twitter_api/representers/user_representer.ex
+++ b/lib/pleroma/web/twitter_api/representers/user_representer.ex
@@ -4,8 +4,10 @@ defmodule Pleroma.Web.TwitterAPI.Representers.UserRepresenter do
alias Pleroma.User
def to_map(user, opts) do
-
- image = "https://placehold.it/48x48"
+ image = case user.avatar do
+ %{"url" => [%{"href" => href} | _]} -> href
+ _ -> "https://placehold.it/48x48"
+ end
following = if opts[:for] do
User.following?(opts[:for], user)
diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex
index f2ca83915..6014aedc4 100644
--- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex
+++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex
@@ -3,6 +3,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
alias Pleroma.Web.TwitterAPI.TwitterAPI
alias Pleroma.Web.TwitterAPI.Representers.{UserRepresenter, ActivityRepresenter}
alias Pleroma.{Repo, Activity}
+ alias Pleroma.Web.ActivityPub.ActivityPub
def verify_credentials(%{assigns: %{user: user}} = conn, _params) do
response = user |> UserRepresenter.to_json(%{for: user})
@@ -146,6 +147,18 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
end
end
+ def update_avatar(%{assigns: %{user: user}} = conn, params) do
+ {:ok, object} = ActivityPub.upload(params)
+ change = Ecto.Changeset.change(user, %{avatar: object.data})
+ {:ok, user} = Repo.update(change)
+
+ response = UserRepresenter.to_map(user, %{for: user})
+ |> Poison.encode!
+
+ conn
+ |> json_reply(200, response)
+ end
+
defp json_reply(conn, status, json) do
conn
|> put_resp_content_type("application/json")