{:ok, unannounce_activity} <- insert(unannounce_data, local),
{:ok, _activity} <- Repo.delete(activity),
{:ok, object} <- remove_announce_from_object(activity, object) do
- {:ok, unannounce_activity, object}
+ {:ok, unannounce_activity, activity, object}
else
_e -> {:ok, object}
end
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, _, _, %{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
CommonAPI.post(user, data)
end
+ def delete(%User{} = user, id) do
+ # TwitterAPI does not have an "unretweet" endpoint; instead this is done
+ # via the "destroy" endpoint. Therefore, there is a 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
+ end
+ end
+
def follow(%User{} = follower, params) do
with {:ok, %User{} = followed} <- get_user(params),
{:ok, follower} <- User.follow(follower, followed),
end
end
+ defp unrepeat(%User{} = user, ap_id_or_id) do
+ with {:ok, _unannounce, activity, _object} <- CommonAPI.unrepeat(ap_id_or_id, user) do
+ {:ok, activity}
+ end
+ end
+
def fav(%User{} = user, ap_id_or_id) do
with {:ok, _announce, %{data: %{"id" => id}}} = CommonAPI.favorite(ap_id_or_id, user),
%Activity{} = activity <- Activity.get_create_activity_by_object_ap_id(id) do
end
def delete_post(%{assigns: %{user: user}} = conn, %{"id" => id}) do
- with {:ok, delete} <- CommonAPI.delete(id, user) do
- render(conn, ActivityView, "activity.json", %{activity: delete, for: user})
+ with {:ok, activity} <- TwitterAPI.delete(id, user) do
+ render(conn, ActivityView, "activity.json", %{activity: activity, for: user})
end
end
end
end
- def unretweet(%{assigns: %{user: user}} = conn, %{"id" => id}) do
- with {: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})
{:ok, announce_activity, object} = ActivityPub.announce(user, object)
assert object.data["announcement_count"] == 1
- {:ok, unannounce_activity, object} = ActivityPub.unannounce(user, object)
+ {:ok, unannounce_activity, activity, object} = ActivityPub.unannounce(user, object)
assert object.data["announcement_count"] == 0
+ assert activity == announce_activity
+
assert unannounce_activity.data["to"] == [
User.ap_followers(user),
note_activity.data["actor"]