Merge branch 'feature/twitterapi-unrepeat' into 'develop'
Add TwitterAPI unretweet endpoint and cleanup AP.unannounce See merge request pleroma/pleroma!218
This commit is contained in:
commit
8c7fdcb31b
9 changed files with 63 additions and 16 deletions
|
|
@ -199,7 +199,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||
:ok <- maybe_federate(unannounce_activity),
|
||||
{:ok, _activity} <- Repo.delete(announce_activity),
|
||||
{:ok, object} <- remove_announce_from_object(announce_activity, object) do
|
||||
{:ok, unannounce_activity, announce_activity, object}
|
||||
{:ok, unannounce_activity, object}
|
||||
else
|
||||
_e -> {:ok, object}
|
||||
end
|
||||
|
|
|
|||
|
|
@ -312,7 +312,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
|
|||
with %User{} = actor <- User.get_or_fetch_by_ap_id(actor),
|
||||
{:ok, object} <-
|
||||
get_obj_helper(object_id) || ActivityPub.fetch_object_from_id(object_id),
|
||||
{:ok, activity, _, _} <- ActivityPub.unannounce(actor, object, id, false) do
|
||||
{:ok, activity, _} <- ActivityPub.unannounce(actor, object, id, false) do
|
||||
{:ok, activity}
|
||||
else
|
||||
_e -> :error
|
||||
|
|
|
|||
|
|
@ -360,7 +360,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
|
|||
end
|
||||
|
||||
def unreblog_status(%{assigns: %{user: user}} = conn, %{"id" => ap_id_or_id}) do
|
||||
with {:ok, _, _, %{data: %{"id" => id}}} <- CommonAPI.unrepeat(ap_id_or_id, user),
|
||||
with {:ok, _unannounce, %{data: %{"id" => id}}} <- CommonAPI.unrepeat(ap_id_or_id, user),
|
||||
%Activity{} = activity <- Activity.get_create_activity_by_object_ap_id(id) do
|
||||
render(conn, StatusView, "status.json", %{activity: activity, for: user, as: :activity})
|
||||
end
|
||||
|
|
|
|||
|
|
@ -244,6 +244,7 @@ defmodule Pleroma.Web.Router do
|
|||
|
||||
post("/statuses/update", TwitterAPI.Controller, :status_update)
|
||||
post("/statuses/retweet/:id", TwitterAPI.Controller, :retweet)
|
||||
post("/statuses/unretweet/:id", TwitterAPI.Controller, :unretweet)
|
||||
post("/statuses/destroy/:id", TwitterAPI.Controller, :delete_post)
|
||||
|
||||
get("/pleroma/friend_requests", TwitterAPI.Controller, :friend_requests)
|
||||
|
|
|
|||
|
|
@ -12,14 +12,9 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do
|
|||
end
|
||||
|
||||
def delete(%User{} = user, id) do
|
||||
# TwitterAPI does not have an "unretweet" endpoint; instead this is done
|
||||
# via the "destroy" endpoint. Therefore, we need to handle
|
||||
# when the status to "delete" is actually an Announce (repeat) object.
|
||||
with %Activity{data: %{"type" => type}} <- Repo.get(Activity, id) do
|
||||
case type do
|
||||
"Announce" -> unrepeat(user, id)
|
||||
_ -> CommonAPI.delete(id, user)
|
||||
end
|
||||
with %Activity{data: %{"type" => type}} <- Repo.get(Activity, id),
|
||||
{:ok, activity} <- CommonAPI.delete(id, user) do
|
||||
{:ok, activity}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -70,8 +65,9 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do
|
|||
end
|
||||
end
|
||||
|
||||
defp unrepeat(%User{} = user, ap_id_or_id) do
|
||||
with {:ok, _unannounce, activity, _object} <- CommonAPI.unrepeat(ap_id_or_id, user) do
|
||||
def unrepeat(%User{} = user, ap_id_or_id) do
|
||||
with {:ok, _unannounce, %{data: %{"id" => id}}} <- CommonAPI.unrepeat(ap_id_or_id, user),
|
||||
%Activity{} = activity <- Activity.get_create_activity_by_object_ap_id(id) do
|
||||
{:ok, activity}
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -241,6 +241,13 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
|
|||
end
|
||||
end
|
||||
|
||||
def unretweet(%{assigns: %{user: user}} = conn, %{"id" => id}) do
|
||||
with {_, {:ok, id}} <- {:param_cast, Ecto.Type.cast(:integer, id)},
|
||||
{:ok, activity} <- TwitterAPI.unrepeat(user, id) do
|
||||
render(conn, ActivityView, "activity.json", %{activity: activity, for: user})
|
||||
end
|
||||
end
|
||||
|
||||
def register(conn, params) do
|
||||
with {:ok, user} <- TwitterAPI.register_user(params) do
|
||||
render(conn, UserView, "show.json", %{user: user})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue