Commit 36711e1c authored by sxsdv1's avatar sxsdv1
Browse files

Handle client submitted activitypub like activity

parent 1eb73188
...@@ -204,6 +204,15 @@ def handle_user_activity(user, %{"type" => "Delete"} = params) do ...@@ -204,6 +204,15 @@ def handle_user_activity(user, %{"type" => "Delete"} = params) do
end end
end end
def handle_user_activity(user, %{"type" => "Like"} = params) do
with %Object{} = object <- Object.normalize(params["object"]),
{:ok, activity, _object} <- ActivityPub.like(user, object) do
{:ok, activity}
else
_ -> {:error, "Can't like object"}
end
end
def handle_user_activity(_, _) do def handle_user_activity(_, _) do
{:error, "Unhandled activity type"} {:error, "Unhandled activity type"}
end end
......
...@@ -292,6 +292,31 @@ test "it rejects delete activity of object from other actor", %{conn: conn} do ...@@ -292,6 +292,31 @@ test "it rejects delete activity of object from other actor", %{conn: conn} do
assert json_response(conn, 400) assert json_response(conn, 400)
end end
test "it increases like count when receiving a like action", %{conn: conn} do
note_activity = insert(:note_activity)
user = User.get_cached_by_ap_id(note_activity.data["actor"])
data = %{
type: "Like",
object: %{
id: note_activity.data["object"]["id"]
}
}
conn =
conn
|> assign(:user, user)
|> put_req_header("content-type", "application/activity+json")
|> post("/users/#{user.nickname}/outbox", data)
result = json_response(conn, 201)
assert Activity.get_by_ap_id(result["id"])
object = Object.get_by_ap_id(note_activity.data["object"]["id"])
assert object
assert object.data["like_count"] == 1
end
end end
describe "/users/:nickname/followers" do describe "/users/:nickname/followers" do
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment