diff options
author | Roger Braun <roger@rogerbraun.net> | 2017-06-01 11:24:03 +0200 |
---|---|---|
committer | Roger Braun <roger@rogerbraun.net> | 2017-06-01 11:24:03 +0200 |
commit | c7fdd1b7ff6e7a08389395d555862eaec9721b08 (patch) | |
tree | 2eacd5f670c35fa834399636a0cc5c8de53ba054 /lib | |
parent | 87c2c42badd7d8cd1f36e979eae923725f27bbe7 (diff) | |
parent | 4cfe1e0c9becebbc5665eb28b187451f96c73555 (diff) | |
download | pleroma-c7fdd1b7ff6e7a08389395d555862eaec9721b08.tar.gz |
Merge branch 'develop' of ssh.gitgud.io:lambadalambda/pleroma into develop
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pleroma/web/ostatus/activity_representer.ex | 30 | ||||
-rw-r--r-- | lib/pleroma/web/ostatus/ostatus.ex | 35 | ||||
-rw-r--r-- | lib/pleroma/web/ostatus/ostatus_controller.ex | 10 | ||||
-rw-r--r-- | lib/pleroma/web/router.ex | 3 | ||||
-rw-r--r-- | lib/pleroma/web/twitter_api/utils.ex | 3 | ||||
-rw-r--r-- | lib/pleroma/web/websub/websub.ex | 4 |
6 files changed, 49 insertions, 36 deletions
diff --git a/lib/pleroma/web/ostatus/activity_representer.ex b/lib/pleroma/web/ostatus/activity_representer.ex index 85140282c..e91ff0769 100644 --- a/lib/pleroma/web/ostatus/activity_representer.ex +++ b/lib/pleroma/web/ostatus/activity_representer.ex @@ -28,10 +28,8 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenter do def to_simple_form(%{data: %{"object" => %{"type" => "Note"}}} = activity, user, with_author) do h = fn(str) -> [to_charlist(str)] end - updated_at = activity.updated_at - |> NaiveDateTime.to_iso8601 - inserted_at = activity.inserted_at - |> NaiveDateTime.to_iso8601 + updated_at = activity.data["published"] + inserted_at = activity.data["published"] attachments = Enum.map(activity.data["object"]["attachment"] || [], fn(attachment) -> url = hd(attachment["url"]) @@ -62,10 +60,8 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenter do def to_simple_form(%{data: %{"type" => "Like"}} = activity, user, with_author) do h = fn(str) -> [to_charlist(str)] end - updated_at = activity.updated_at - |> NaiveDateTime.to_iso8601 - inserted_at = activity.inserted_at - |> NaiveDateTime.to_iso8601 + updated_at = activity.data["published"] + inserted_at = activity.data["published"] in_reply_to = get_in_reply_to(activity.data) author = if with_author, do: [{:author, UserRepresenter.to_simple_form(user)}], else: [] @@ -92,10 +88,8 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenter do def to_simple_form(%{data: %{"type" => "Announce"}} = activity, user, with_author) do h = fn(str) -> [to_charlist(str)] end - updated_at = activity.updated_at - |> NaiveDateTime.to_iso8601 - inserted_at = activity.inserted_at - |> NaiveDateTime.to_iso8601 + updated_at = activity.data["published"] + inserted_at = activity.data["published"] in_reply_to = get_in_reply_to(activity.data) author = if with_author, do: [{:author, UserRepresenter.to_simple_form(user)}], else: [] @@ -124,10 +118,8 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenter do def to_simple_form(%{data: %{"type" => "Follow"}} = activity, user, with_author) do h = fn(str) -> [to_charlist(str)] end - updated_at = activity.updated_at - |> NaiveDateTime.to_iso8601 - inserted_at = activity.inserted_at - |> NaiveDateTime.to_iso8601 + updated_at = activity.data["published"] + inserted_at = activity.data["published"] author = if with_author, do: [{:author, UserRepresenter.to_simple_form(user)}], else: [] @@ -153,10 +145,8 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenter do def to_simple_form(%{data: %{"type" => "Undo"}} = activity, user, with_author) do h = fn(str) -> [to_charlist(str)] end - updated_at = activity.updated_at - |> NaiveDateTime.to_iso8601 - inserted_at = activity.inserted_at - |> NaiveDateTime.to_iso8601 + updated_at = activity.data["published"] + inserted_at = activity.data["published"] author = if with_author, do: [{:author, UserRepresenter.to_simple_form(user)}], else: [] follow_activity = Activity.get_by_ap_id(activity.data["object"]) diff --git a/lib/pleroma/web/ostatus/ostatus.ex b/lib/pleroma/web/ostatus/ostatus.ex index f8bcf4718..df80d137a 100644 --- a/lib/pleroma/web/ostatus/ostatus.ex +++ b/lib/pleroma/web/ostatus/ostatus.ex @@ -152,16 +152,30 @@ defmodule Pleroma.Web.OStatus do |> Enum.map(fn (category) -> string_from_xpath("/category/@term", category) end) end + def maybe_update(doc, user) do + old_data = %{ + avatar: user.avatar, + bio: user.bio, + name: user.name + } + + with false <- user.local, + avatar <- make_avatar_object(doc), + bio when not is_nil(bio) <- string_from_xpath("//author[1]/summary", doc), + name when not is_nil(name) <- string_from_xpath("//author[1]/poco:displayName", doc), + new_data <- %{avatar: avatar, name: name, bio: bio}, + false <- new_data == old_data do + change = Ecto.Changeset.change(user, new_data) + Repo.update(change) + else e -> + {:ok, user} + end + end + def find_make_or_update_user(doc) do uri = string_from_xpath("//author/uri[1]", doc) with {:ok, user} <- find_or_make_user(uri) do - avatar = make_avatar_object(doc) - if !user.local && user.avatar != avatar do - change = Ecto.Changeset.change(user, %{avatar: avatar}) - Repo.update(change) - else - {:ok, user} - end + maybe_update(doc, user) end end @@ -185,7 +199,8 @@ defmodule Pleroma.Web.OStatus do nickname: info["nickname"] <> "@" <> info["host"], ap_id: info["uri"], info: info, - avatar: info["avatar"] + avatar: info["avatar"], + bio: info["bio"] } with %User{} = user <- User.get_by_ap_id(data.ap_id) do {:ok, user} @@ -250,9 +265,9 @@ defmodule Pleroma.Web.OStatus do def fetch_activity_from_html_url(url) do Logger.debug("Trying to fetch #{url}") - with {:ok, %{body: body}} <- @httpoison.get(url, [], follow_redirect: true), + with {:ok, %{body: body}} <- @httpoison.get(url, [], follow_redirect: true, timeout: 10000, recv_timeout: 20000), {:ok, atom_url} <- get_atom_url(body), - {:ok, %{status_code: code, body: body}} when code in 200..299 <- @httpoison.get(atom_url, [], follow_redirect: true) do + {:ok, %{status_code: code, body: body}} when code in 200..299 <- @httpoison.get(atom_url, [], follow_redirect: true, timeout: 10000, recv_timeout: 20000) do Logger.debug("Got document from #{url}, handling...") handle_incoming(body) else e -> Logger.debug("Couldn't get #{url}: #{inspect(e)}") diff --git a/lib/pleroma/web/ostatus/ostatus_controller.ex b/lib/pleroma/web/ostatus/ostatus_controller.ex index fd8dcdf52..948996d01 100644 --- a/lib/pleroma/web/ostatus/ostatus_controller.ex +++ b/lib/pleroma/web/ostatus/ostatus_controller.ex @@ -47,7 +47,10 @@ defmodule Pleroma.Web.OStatus.OStatusController do with id <- o_status_url(conn, :object, uuid), %Activity{} = activity <- Activity.get_create_activity_by_object_ap_id(id), %User{} = user <- User.get_cached_by_ap_id(activity.data["actor"]) do - represent_activity(conn, activity, user) + case get_format(conn) do + "html" -> redirect(conn, to: "/notice/#{activity.id}") + _ -> represent_activity(conn, activity, user) + end end end @@ -55,7 +58,10 @@ defmodule Pleroma.Web.OStatus.OStatusController do with id <- o_status_url(conn, :activity, uuid), %Activity{} = activity <- Activity.get_by_ap_id(id), %User{} = user <- User.get_cached_by_ap_id(activity.data["actor"]) do - represent_activity(conn, activity, user) + case get_format(conn) do + "html" -> redirect(conn, to: "/notice/#{activity.id}") + _ -> represent_activity(conn, activity, user) + end end end diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 12159cffc..07c1f8028 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -70,7 +70,7 @@ defmodule Pleroma.Web.Router do end pipeline :ostatus do - plug :accepts, ["xml", "atom"] + plug :accepts, ["xml", "atom", "html"] end scope "/", Pleroma.Web do @@ -97,7 +97,6 @@ defmodule Pleroma.Web.Router do scope "/", Fallback do get "/*path", RedirectController, :redirector end - end defmodule Fallback.RedirectController do diff --git a/lib/pleroma/web/twitter_api/utils.ex b/lib/pleroma/web/twitter_api/utils.ex index 32b9eab44..65d893869 100644 --- a/lib/pleroma/web/twitter_api/utils.ex +++ b/lib/pleroma/web/twitter_api/utils.ex @@ -38,7 +38,8 @@ defmodule Pleroma.Web.TwitterAPI.Utils do end) Enum.reduce(mentions, step_one, fn ({match, %User{ap_id: ap_id}, uuid}, text) -> - String.replace(text, uuid, "<a href='#{ap_id}'>#{match}</a>") + short_match = String.split(match, "@") |> tl() |> hd() + String.replace(text, uuid, "<a href='#{ap_id}'>@#{short_match}</a>") end) end diff --git a/lib/pleroma/web/websub/websub.ex b/lib/pleroma/web/websub/websub.ex index e46e0a2ce..a683f6da4 100644 --- a/lib/pleroma/web/websub/websub.ex +++ b/lib/pleroma/web/websub/websub.ex @@ -156,6 +156,7 @@ defmodule Pleroma.Web.Websub do preferredUsername = XML.string_from_xpath("/feed/author[1]/poco:preferredUsername", doc) displayName = XML.string_from_xpath("/feed/author[1]/poco:displayName", doc) avatar = OStatus.make_avatar_object(doc) + bio = XML.string_from_xpath("/feed/author[1]/summary", doc) {:ok, %{ "uri" => uri, @@ -163,7 +164,8 @@ defmodule Pleroma.Web.Websub do "nickname" => preferredUsername || name, "name" => displayName || name, "host" => URI.parse(uri).host, - "avatar" => avatar + "avatar" => avatar, + "bio" => bio }} else e -> {:error, e} |