Merge branch 'hotfix_broken_likes' into 'develop'

hotfix for broken like completely breaking the notifications API

See merge request pleroma/pleroma!284
This commit is contained in:
kaniini 2018-09-02 12:37:00 +00:00
commit b7923aa304
2 changed files with 29 additions and 1 deletions

View File

@ -181,6 +181,7 @@ def render("activity.json", %{activity: %{data: %{"type" => "Announce"}} = activ
def render("activity.json", %{activity: %{data: %{"type" => "Like"}} = activity} = opts) do def render("activity.json", %{activity: %{data: %{"type" => "Like"}} = activity} = opts) do
user = get_user(activity.data["actor"], opts) user = get_user(activity.data["actor"], opts)
liked_activity = Activity.get_create_activity_by_object_ap_id(activity.data["object"]) liked_activity = Activity.get_create_activity_by_object_ap_id(activity.data["object"])
liked_activity_id = if liked_activity, do: liked_activity.id, else: nil
created_at = created_at =
activity.data["published"] activity.data["published"]
@ -197,7 +198,7 @@ def render("activity.json", %{activity: %{data: %{"type" => "Like"}} = activity}
"is_post_verb" => false, "is_post_verb" => false,
"uri" => "tag:#{activity.data["id"]}:objectType=Favourite", "uri" => "tag:#{activity.data["id"]}:objectType=Favourite",
"created_at" => created_at, "created_at" => created_at,
"in_reply_to_status_id" => liked_activity.id, "in_reply_to_status_id" => liked_activity_id,
"external_url" => activity.data["id"], "external_url" => activity.data["id"],
"activity_type" => "like" "activity_type" => "like"
} }

View File

@ -126,6 +126,33 @@ test "a like activity" do
assert result == expected assert result == expected
end end
test "a like activity for deleted post" 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)
CommonAPI.delete(activity.id, 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" => nil,
"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
test "an announce activity" do test "an announce activity" do
user = insert(:user) user = insert(:user)
other_user = insert(:user, %{nickname: "shp"}) other_user = insert(:user, %{nickname: "shp"})