OStatus announce representer.
This commit is contained in:
parent
df71c142cf
commit
138641589d
|
@ -1,5 +1,5 @@
|
||||||
defmodule Pleroma.Web.OStatus.ActivityRepresenter do
|
defmodule Pleroma.Web.OStatus.ActivityRepresenter do
|
||||||
alias Pleroma.Activity
|
alias Pleroma.{Activity, User}
|
||||||
alias Pleroma.Web.OStatus.UserRepresenter
|
alias Pleroma.Web.OStatus.UserRepresenter
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
|
@ -84,6 +84,37 @@ def to_simple_form(%{data: %{"type" => "Like"}} = activity, user, with_author) d
|
||||||
] ++ author ++ mentions
|
] ++ author ++ mentions
|
||||||
end
|
end
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
in_reply_to = get_in_reply_to(activity.data)
|
||||||
|
author = if with_author, do: [{:author, UserRepresenter.to_simple_form(user)}], else: []
|
||||||
|
|
||||||
|
retweeted_activity = Activity.get_create_activity_by_object_ap_id(activity.data["object"])
|
||||||
|
retweeted_user = User.get_cached_by_ap_id(retweeted_activity.data["actor"])
|
||||||
|
|
||||||
|
retweeted_xml = to_simple_form(retweeted_activity, retweeted_user)
|
||||||
|
|
||||||
|
mentions = activity.data["to"] |> get_mentions
|
||||||
|
[
|
||||||
|
{:"activity:verb", ['http://activitystrea.ms/schema/1.0/share']},
|
||||||
|
{:id, h.(activity.data["id"])},
|
||||||
|
{:title, ['#{user.nickname} repeated a notice']},
|
||||||
|
{:content, [type: 'html'], ['RT #{retweeted_activity.data["object"]["content"]}']},
|
||||||
|
{:published, h.(inserted_at)},
|
||||||
|
{:updated, h.(updated_at)},
|
||||||
|
{:"ostatus:conversation", [], h.(activity.data["context"])},
|
||||||
|
{:link, [href: h.(activity.data["context"]), rel: 'ostatus:conversation'], []},
|
||||||
|
{:"thr:in-reply-to", [ref: to_charlist(activity.data["object"])], []},
|
||||||
|
{:"activity:object", retweeted_xml}
|
||||||
|
] ++ mentions ++ author
|
||||||
|
end
|
||||||
|
|
||||||
def wrap_with_entry(simple_form) do
|
def wrap_with_entry(simple_form) do
|
||||||
[{
|
[{
|
||||||
:entry, [
|
:entry, [
|
||||||
|
|
|
@ -2,7 +2,7 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenterTest do
|
||||||
use Pleroma.DataCase
|
use Pleroma.DataCase
|
||||||
|
|
||||||
alias Pleroma.Web.OStatus.ActivityRepresenter
|
alias Pleroma.Web.OStatus.ActivityRepresenter
|
||||||
alias Pleroma.{User, Activity}
|
alias Pleroma.{User, Activity, Object}
|
||||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||||
|
|
||||||
import Pleroma.Factory
|
import Pleroma.Factory
|
||||||
|
@ -73,6 +73,49 @@ test "a reply note" do
|
||||||
assert clean(res) == clean(expected)
|
assert clean(res) == clean(expected)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "an announce activity" do
|
||||||
|
note = insert(:note_activity)
|
||||||
|
user = insert(:user)
|
||||||
|
object = Object.get_cached_by_ap_id(note.data["object"]["id"])
|
||||||
|
|
||||||
|
{:ok, announce, object} = ActivityPub.announce(user, object)
|
||||||
|
|
||||||
|
announce = Repo.get(Activity, announce.id)
|
||||||
|
|
||||||
|
note_user = User.get_cached_by_ap_id(note.data["actor"])
|
||||||
|
note = Repo.get(Activity, note.id)
|
||||||
|
note_xml = ActivityRepresenter.to_simple_form(note, note_user)
|
||||||
|
|> :xmerl.export_simple_content(:xmerl_xml)
|
||||||
|
|> IO.iodata_to_binary
|
||||||
|
|
||||||
|
updated_at = announce.updated_at
|
||||||
|
|> NaiveDateTime.to_iso8601
|
||||||
|
inserted_at = announce.inserted_at
|
||||||
|
|> NaiveDateTime.to_iso8601
|
||||||
|
|
||||||
|
expected = """
|
||||||
|
<activity:verb>http://activitystrea.ms/schema/1.0/share</activity:verb>
|
||||||
|
<id>#{announce.data["id"]}</id>
|
||||||
|
<title>#{user.nickname} repeated a notice</title>
|
||||||
|
<content type="html">RT #{note.data["object"]["content"]}</content>
|
||||||
|
<published>#{inserted_at}</published>
|
||||||
|
<updated>#{updated_at}</updated>
|
||||||
|
<ostatus:conversation>#{announce.data["context"]}</ostatus:conversation>
|
||||||
|
<link href="#{announce.data["context"]}" rel="ostatus:conversation" />
|
||||||
|
<thr:in-reply-to ref="#{note.data["object"]["id"]}" />
|
||||||
|
<activity:object>
|
||||||
|
#{note_xml}
|
||||||
|
</activity:object>
|
||||||
|
<link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/person" href="#{note.data["actor"]}"/>
|
||||||
|
"""
|
||||||
|
|
||||||
|
announce_xml = ActivityRepresenter.to_simple_form(announce, user)
|
||||||
|
|> :xmerl.export_simple_content(:xmerl_xml)
|
||||||
|
|> IO.iodata_to_binary
|
||||||
|
|
||||||
|
assert clean(expected) == clean(announce_xml)
|
||||||
|
end
|
||||||
|
|
||||||
test "a like activity" do
|
test "a like activity" do
|
||||||
note = insert(:note)
|
note = insert(:note)
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
|
|
Loading…
Reference in a new issue