{: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)
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
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)