Merge branch 'develop' of ssh.gitgud.io:lambadalambda/pleroma into develop

This commit is contained in:
Roger Braun 2017-06-01 11:24:03 +02:00
commit c7fdd1b7ff
14 changed files with 87 additions and 87 deletions

View file

@ -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"])

View file

@ -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)}")

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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}