X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Fweb%2Fostatus%2Factivity_representer.ex;h=842e44ee4aa25dc909a5ca379dc4adaf753f35ca;hb=11714fbaa2b90e1fc577d2b9b3d4075a44181633;hp=aa13cd62bb5860e1f32754caae3cb83c6aa7c72d;hpb=94e980d6b4ab91ee37c30b266eb91e748e23861c;p=akkoma diff --git a/lib/pleroma/web/ostatus/activity_representer.ex b/lib/pleroma/web/ostatus/activity_representer.ex index aa13cd62b..842e44ee4 100644 --- a/lib/pleroma/web/ostatus/activity_representer.ex +++ b/lib/pleroma/web/ostatus/activity_representer.ex @@ -1,10 +1,18 @@ 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: [] @@ -24,12 +32,35 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenter 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 - updated_at = activity.data["published"] - inserted_at = activity.data["published"] + updated_at = activity.data["object"]["published"] + inserted_at = activity.data["object"]["published"] attachments = Enum.map(activity.data["object"]["attachment"] || [], fn(attachment) -> url = hd(attachment["url"]) @@ -48,13 +79,12 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenter do {:"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, [href: 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 + {:link, [ref: h.(activity.data["context"]), rel: 'ostatus:conversation'], []}, + ] ++ get_links(activity) ++ categories ++ attachments ++ in_reply_to ++ author ++ mentions end def to_simple_form(%{data: %{"type" => "Like"}} = activity, user, with_author) do @@ -79,7 +109,7 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenter do {:id, h.(activity.data["object"])}, # For notes, federate the object id. ]}, {:"ostatus:conversation", [], h.(activity.data["context"])}, - {:link, [href: h.(activity.data["context"]), rel: 'ostatus:conversation'], []}, + {:link, [ref: h.(activity.data["context"]), rel: 'ostatus:conversation'], []}, {:link, [rel: 'self', type: ['application/atom+xml'], href: h.(activity.data["id"])], []}, {:"thr:in-reply-to", [ref: to_charlist(activity.data["object"])], []} ] ++ author ++ mentions @@ -109,7 +139,7 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenter do {:published, h.(inserted_at)}, {:updated, h.(updated_at)}, {:"ostatus:conversation", [], h.(activity.data["context"])}, - {:link, [href: h.(activity.data["context"]), rel: 'ostatus:conversation'], []}, + {:link, [ref: h.(activity.data["context"]), rel: 'ostatus:conversation'], []}, {:link, [rel: 'self', type: ['application/atom+xml'], href: h.(activity.data["id"])], []}, {:"activity:object", retweeted_xml} ] ++ mentions ++ author