Skip to content
Snippets Groups Projects
Commit f4eea084 authored by lain's avatar lain
Browse files

Add unfavoriting to TwAPI.

parent a926038c
No related branches found
No related tags found
No related merge requests found
......@@ -137,6 +137,19 @@ def favorite(%User{} = user, %Activity{data: %{"object" => object}} = activity)
{:ok, status}
end
def unfavorite(%User{} = user, %Activity{data: %{"object" => object}} = activity) do
object = Object.get_by_ap_id(object["id"])
{:ok, object} = ActivityPub.unlike(user, object)
new_data = activity.data
|> Map.put("object", object.data)
status = %{activity | data: new_data}
|> activity_to_status(%{for: user})
{:ok, status}
end
def upload(%Plug.Upload{} = file, format \\ "xml") do
{:ok, object} = ActivityPub.upload(file)
......
......@@ -4,6 +4,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
alias Pleroma.Web.TwitterAPI.TwitterAPI
alias Pleroma.{Activity, User, Object, Repo}
alias Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter
alias Pleroma.Web.ActivityPub.ActivityPub
import Pleroma.Factory
......@@ -191,6 +192,22 @@ test "it favorites a status, returns the updated status" do
assert status == ActivityRepresenter.to_map(updated_activity, %{user: activity_user, for: user})
end
test "it unfavorites a status, returns the updated status" do
user = insert(:user)
note_activity = insert(:note_activity)
activity_user = Repo.get_by!(User, ap_id: note_activity.data["actor"])
object = Object.get_by_ap_id(note_activity.data["object"]["id"])
{:ok, like_activity, object } = ActivityPub.like(user, object)
updated_activity = Activity.get_by_ap_id(note_activity.data["id"])
assert ActivityRepresenter.to_map(updated_activity, %{user: activity_user, for: user})["fave_num"] == 1
{:ok, status} = TwitterAPI.unfavorite(user, note_activity)
updated_activity = Activity.get_by_ap_id(note_activity.data["id"])
assert status["fave_num"] == 0
end
setup do
Supervisor.terminate_child(Pleroma.Supervisor, ConCache)
Supervisor.restart_child(Pleroma.Supervisor, ConCache)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment