Add unfavoriting to TwAPI.
This commit is contained in:
parent
a926038cd0
commit
f4eea0847b
2 changed files with 30 additions and 0 deletions
|
@ -137,6 +137,19 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do
|
||||||
{:ok, status}
|
{:ok, status}
|
||||||
end
|
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
|
def upload(%Plug.Upload{} = file, format \\ "xml") do
|
||||||
{:ok, object} = ActivityPub.upload(file)
|
{:ok, object} = ActivityPub.upload(file)
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
||||||
alias Pleroma.Web.TwitterAPI.TwitterAPI
|
alias Pleroma.Web.TwitterAPI.TwitterAPI
|
||||||
alias Pleroma.{Activity, User, Object, Repo}
|
alias Pleroma.{Activity, User, Object, Repo}
|
||||||
alias Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter
|
alias Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter
|
||||||
|
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||||
|
|
||||||
import Pleroma.Factory
|
import Pleroma.Factory
|
||||||
|
|
||||||
|
@ -191,6 +192,22 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
||||||
assert status == ActivityRepresenter.to_map(updated_activity, %{user: activity_user, for: user})
|
assert status == ActivityRepresenter.to_map(updated_activity, %{user: activity_user, for: user})
|
||||||
end
|
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
|
setup do
|
||||||
Supervisor.terminate_child(Pleroma.Supervisor, ConCache)
|
Supervisor.terminate_child(Pleroma.Supervisor, ConCache)
|
||||||
Supervisor.restart_child(Pleroma.Supervisor, ConCache)
|
Supervisor.restart_child(Pleroma.Supervisor, ConCache)
|
||||||
|
|
Loading…
Reference in a new issue