Fix undo activity.
This commit is contained in:
parent
e343c0c9c4
commit
7e9647b146
2 changed files with 31 additions and 0 deletions
|
@ -72,6 +72,26 @@ def to_map(%Activity{data: %{"type" => "Follow", "published" => created_at, "obj
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# TODO:
|
||||||
|
# Make this more proper. Just a placeholder to not break the frontend.
|
||||||
|
def to_map(%Activity{data: %{"type" => "Undo", "published" => created_at, "object" => undid_activity }} = activity, %{user: user} = opts) do
|
||||||
|
created_at = created_at |> Utils.date_to_asctime
|
||||||
|
|
||||||
|
text = "#{user.nickname} undid the action at #{undid_activity}"
|
||||||
|
%{
|
||||||
|
"id" => activity.id,
|
||||||
|
"user" => UserView.render("show.json", %{user: user, for: opts[:for]}),
|
||||||
|
"attentions" => [],
|
||||||
|
"statusnet_html" => text,
|
||||||
|
"text" => text,
|
||||||
|
"is_local" => activity.local,
|
||||||
|
"is_post_verb" => false,
|
||||||
|
"created_at" => created_at,
|
||||||
|
"in_reply_to_status_id" => nil,
|
||||||
|
"external_url" => activity.data["id"]
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
def to_map(%Activity{data: %{"object" => %{"content" => content} = object}} = activity, %{user: user} = opts) do
|
def to_map(%Activity{data: %{"object" => %{"content" => content} = object}} = activity, %{user: user} = opts) do
|
||||||
created_at = object["published"] |> Utils.date_to_asctime
|
created_at = object["published"] |> Utils.date_to_asctime
|
||||||
like_count = object["like_count"] || 0
|
like_count = object["like_count"] || 0
|
||||||
|
|
|
@ -132,4 +132,15 @@ test "an activity" do
|
||||||
|
|
||||||
assert ActivityRepresenter.to_map(activity, %{user: user, for: follower, mentioned: [mentioned_user]}) == expected_status
|
assert ActivityRepresenter.to_map(activity, %{user: user, for: follower, mentioned: [mentioned_user]}) == expected_status
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "an undo for a follow" do
|
||||||
|
follower = insert(:user)
|
||||||
|
followed = insert(:user)
|
||||||
|
|
||||||
|
{:ok, follow} = ActivityPub.follow(follower, followed)
|
||||||
|
{:ok, unfollow} = ActivityPub.unfollow(follower, followed)
|
||||||
|
|
||||||
|
map = ActivityRepresenter.to_map(unfollow, %{user: follower})
|
||||||
|
assert map["is_post_verb"] == false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue