From 94e980d6b4ab91ee37c30b266eb91e748e23861c Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Wed, 24 May 2017 13:53:31 +0200 Subject: Output proper published data in ostatus. --- lib/pleroma/web/ostatus/activity_representer.ex | 30 +++++++++---------------- 1 file changed, 10 insertions(+), 20 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/ostatus/activity_representer.ex b/lib/pleroma/web/ostatus/activity_representer.ex index ccf71218c..aa13cd62b 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"]) -- cgit v1.2.3 From bdcf42180fa67e43f13584d5e19f26d751199d03 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Wed, 24 May 2017 17:34:38 +0200 Subject: Save remote user bio and update if we see new data. --- lib/pleroma/web/ostatus/ostatus.ex | 31 +++++++++++++++++++++++-------- lib/pleroma/web/websub/websub.ex | 4 +++- 2 files changed, 26 insertions(+), 9 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/ostatus/ostatus.ex b/lib/pleroma/web/ostatus/ostatus.ex index 02fc273cf..9300de16e 100644 --- a/lib/pleroma/web/ostatus/ostatus.ex +++ b/lib/pleroma/web/ostatus/ostatus.ex @@ -228,16 +228,30 @@ defmodule Pleroma.Web.OStatus do 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 @@ -261,7 +275,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} 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} -- cgit v1.2.3 From c6aa60c829abb7eeff3e0aec0b8b5eb33b8a4947 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Tue, 30 May 2017 14:26:31 +0200 Subject: Shorten names in links. --- lib/pleroma/web/twitter_api/utils.ex | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/twitter_api/utils.ex b/lib/pleroma/web/twitter_api/utils.ex index 82e3620f2..91dfa191f 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, "#{match}") + short_match = String.split(match, "@") |> tl() |> hd() + String.replace(text, uuid, "@#{short_match}") end) end -- cgit v1.2.3 From 80705c7a204be461a5c7a4abb8c675f4482a9cd2 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Wed, 31 May 2017 17:48:22 +0200 Subject: Redirect to frontend on html notice path. --- lib/pleroma/web/ostatus/ostatus_controller.ex | 10 ++++++++-- lib/pleroma/web/router.ex | 3 +-- 2 files changed, 9 insertions(+), 4 deletions(-) (limited to 'lib') 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 -- cgit v1.2.3 From 4cfe1e0c9becebbc5665eb28b187451f96c73555 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Wed, 31 May 2017 18:24:50 +0200 Subject: Make timeouts longer, some servers are very slow. --- lib/pleroma/web/ostatus/ostatus.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/ostatus/ostatus.ex b/lib/pleroma/web/ostatus/ostatus.ex index 9300de16e..29291b7a5 100644 --- a/lib/pleroma/web/ostatus/ostatus.ex +++ b/lib/pleroma/web/ostatus/ostatus.ex @@ -341,9 +341,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)}") -- cgit v1.2.3