forked from AkkomaGang/akkoma
TwApi ActivityView: Add Like rendering.
This commit is contained in:
parent
361016349f
commit
1f1caab138
2 changed files with 66 additions and 2 deletions
|
@ -5,8 +5,32 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do
|
||||||
alias Pleroma.Web.TwitterAPI.UserView
|
alias Pleroma.Web.TwitterAPI.UserView
|
||||||
alias Pleroma.Web.TwitterAPI.TwitterAPI
|
alias Pleroma.Web.TwitterAPI.TwitterAPI
|
||||||
alias Pleroma.Web.TwitterAPI.Representers.ObjectRepresenter
|
alias Pleroma.Web.TwitterAPI.Representers.ObjectRepresenter
|
||||||
|
alias Pleroma.Activity
|
||||||
alias Pleroma.Formatter
|
alias Pleroma.Formatter
|
||||||
|
|
||||||
|
def render("activity.json", %{activity: %{data: %{"type" => "Like"}} = activity} = opts) do
|
||||||
|
user = User.get_cached_by_ap_id(activity.data["actor"])
|
||||||
|
liked_activity = Activity.get_create_activity_by_object_ap_id(activity.data["object"])
|
||||||
|
created_at = activity.data["published"]
|
||||||
|
|> Utils.date_to_asctime
|
||||||
|
|
||||||
|
text = "#{user.nickname} favorited a status."
|
||||||
|
|
||||||
|
%{
|
||||||
|
"id" => activity.id,
|
||||||
|
"user" => UserView.render("show.json", %{user: user, for: opts[:for]}),
|
||||||
|
"statusnet_html" => text,
|
||||||
|
"text" => text,
|
||||||
|
"is_local" => activity.local,
|
||||||
|
"is_post_verb" => false,
|
||||||
|
"uri" => "tag:#{activity.data["id"]}:objectType=Favourite",
|
||||||
|
"created_at" => created_at,
|
||||||
|
"in_reply_to_status_id" => liked_activity.id,
|
||||||
|
"external_url" => activity.data["id"],
|
||||||
|
"activity_type" => "like"
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
def render("activity.json", %{activity: %{data: %{"type" => "Create", "object" => object}} = activity} = opts) do
|
def render("activity.json", %{activity: %{data: %{"type" => "Create", "object" => object}} = activity} = opts) do
|
||||||
actor = get_in(activity.data, ["actor"])
|
actor = get_in(activity.data, ["actor"])
|
||||||
user = User.get_cached_by_ap_id(actor)
|
user = User.get_cached_by_ap_id(actor)
|
||||||
|
|
|
@ -24,7 +24,7 @@ test "a create activity with a note" do
|
||||||
"attentions" => [
|
"attentions" => [
|
||||||
UserView.render("show.json", %{user: other_user})
|
UserView.render("show.json", %{user: other_user})
|
||||||
],
|
],
|
||||||
"created_at" => activity.data["object"]["published"] |> Utils.date_to_asctime,
|
"created_at" => activity.data["object"]["published"] |> Utils.date_to_asctime(),
|
||||||
"external_url" => activity.data["object"]["id"],
|
"external_url" => activity.data["object"]["id"],
|
||||||
"fave_num" => 0,
|
"fave_num" => 0,
|
||||||
"favorited" => false,
|
"favorited" => false,
|
||||||
|
@ -37,7 +37,7 @@ test "a create activity with a note" do
|
||||||
"repeated" => false,
|
"repeated" => false,
|
||||||
"statusnet_conversation_id" => convo_id,
|
"statusnet_conversation_id" => convo_id,
|
||||||
"statusnet_html" =>
|
"statusnet_html" =>
|
||||||
"Hey <span><a href=\"http://localhost:4001/users/nick1\">@<span>shp</span></a></span>!",
|
"Hey <span><a href=\"#{other_user.ap_id}\">@<span>shp</span></a></span>!",
|
||||||
"tags" => [],
|
"tags" => [],
|
||||||
"text" => "Hey @shp!",
|
"text" => "Hey @shp!",
|
||||||
"uri" => activity.data["object"]["id"],
|
"uri" => activity.data["object"]["id"],
|
||||||
|
@ -46,4 +46,44 @@ test "a create activity with a note" do
|
||||||
|
|
||||||
assert result == expected
|
assert result == expected
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "an activity that is a reply" do
|
||||||
|
user = insert(:user)
|
||||||
|
other_user = insert(:user, %{nickname: "shp"})
|
||||||
|
|
||||||
|
{:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
|
||||||
|
|
||||||
|
{:ok, answer} =
|
||||||
|
CommonAPI.post(other_user, %{"status" => "Hi!", "in_reply_to_status_id" => activity.id})
|
||||||
|
|
||||||
|
result = ActivityView.render("activity.json", %{activity: answer})
|
||||||
|
|
||||||
|
assert result["in_reply_to_status_id"] == activity.id
|
||||||
|
end
|
||||||
|
|
||||||
|
test "a like activity" do
|
||||||
|
user = insert(:user)
|
||||||
|
other_user = insert(:user, %{nickname: "shp"})
|
||||||
|
|
||||||
|
{:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
|
||||||
|
{:ok, like, _object} = CommonAPI.favorite(activity.id, other_user)
|
||||||
|
|
||||||
|
result = ActivityView.render("activity.json", activity: like)
|
||||||
|
|
||||||
|
expected = %{
|
||||||
|
"activity_type" => "like",
|
||||||
|
"created_at" => like.data["published"] |> Utils.date_to_asctime(),
|
||||||
|
"external_url" => like.data["id"],
|
||||||
|
"id" => like.id,
|
||||||
|
"in_reply_to_status_id" => activity.id,
|
||||||
|
"is_local" => true,
|
||||||
|
"is_post_verb" => false,
|
||||||
|
"statusnet_html" => "shp favorited a status.",
|
||||||
|
"text" => "shp favorited a status.",
|
||||||
|
"uri" => "tag:#{like.data["id"]}:objectType=Favourite",
|
||||||
|
"user" => UserView.render("show.json", user: other_user)
|
||||||
|
}
|
||||||
|
|
||||||
|
assert result == expected
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue