defmodule Pleroma.Web.OStatus.ActivityRepresenter do
- alias Pleroma.{Activity, User}
+ alias Pleroma.{Activity, User, Object}
alias Pleroma.Web.OStatus.UserRepresenter
require Logger
+ defp get_href(id) do
+ with %Object{data: %{ "external_url" => external_url } }<- Object.get_cached_by_ap_id(id) do
+ external_url
+ else
+ _e -> id
+ end
+ end
+
defp get_in_reply_to(%{"object" => %{"inReplyTo" => in_reply_to}}) do
- [{:"thr:in-reply-to", [ref: to_charlist(in_reply_to)], []}]
+ [{:"thr:in-reply-to", [ref: to_charlist(in_reply_to), href: to_charlist(get_href(in_reply_to))], []}]
end
defp get_in_reply_to(_), do: []
end)
end
+ defp get_links(%{local: true, data: data}) do
+ h = fn(str) -> [to_charlist(str)] end
+ [
+ {:link, [type: ['application/atom+xml'], href: h.(data["object"]["id"]), rel: 'self'], []},
+ {:link, [type: ['text/html'], href: h.(data["object"]["id"]), rel: 'alternate'], []}
+ ]
+ end
+
+ defp get_links(%{local: false,
+ data: %{
+ "object" => %{
+ "external_url" => external_url
+ }
+ }}) do
+
+ h = fn(str) -> [to_charlist(str)] end
+ [
+ {:link, [type: ['text/html'], href: h.(external_url), rel: 'alternate'], []}
+ ]
+ end
+
+ defp get_links(_activity), do: []
+
def to_simple_form(activity, user, with_author \\ false)
def to_simple_form(%{data: %{"object" => %{"type" => "Note"}}} = activity, user, with_author) do
h = fn(str) -> [to_charlist(str)] end
{:"activity:verb", ['http://activitystrea.ms/schema/1.0/post']},
{:id, h.(activity.data["object"]["id"])}, # For notes, federate the object id.
{:title, ['New note by #{user.nickname}']},
- {:content, [type: 'html'], h.(activity.data["object"]["content"])},
+ {:content, [type: 'html'], h.(activity.data["object"]["content"] |> String.replace(~r/[\n\r]/, ""))},
{:published, h.(inserted_at)},
{:updated, h.(updated_at)},
{:"ostatus:conversation", [], h.(activity.data["context"])},
{:link, [ref: h.(activity.data["context"]), rel: 'ostatus:conversation'], []},
- {:link, [type: ['application/atom+xml'], href: h.(activity.data["object"]["id"]), rel: 'self'], []}
- ] ++ categories ++ attachments ++ in_reply_to ++ author ++ mentions
+ ] ++ get_links(activity) ++ categories ++ attachments ++ in_reply_to ++ author ++ mentions
end
def to_simple_form(%{data: %{"type" => "Like"}} = activity, user, with_author) do