- def get_replied_to_activity(id) when not is_nil(id) do
- Repo.get(Activity, id)
- end
-
- def get_replied_to_activity(_), do: nil
-
- def create_status(user = %User{}, data = %{"status" => status}) do
- attachments = attachments_from_ids(data["media_ids"])
- context = ActivityPub.generate_context_id
- mentions = parse_mentions(status)
- content_html = format_input(status, mentions)
- to = to_for_user_and_mentions(user, mentions)
- date = make_date()
-
- inReplyTo = get_replied_to_activity(data["in_reply_to_status_id"])
-
- # Wire up reply info.
- [to, context, object, additional] =
- if inReplyTo do
- context = inReplyTo.data["context"]
- to = to ++ [inReplyTo.data["actor"]]
-
- object = %{
- "type" => "Note",
- "to" => to,
- "content" => content_html,
- "published" => date,
- "context" => context,
- "attachment" => attachments,
- "actor" => user.ap_id,
- "inReplyTo" => inReplyTo.data["object"]["id"],
- "inReplyToStatusId" => inReplyTo.id,
- "statusnetConversationId" => inReplyTo.data["statusnetConversationId"]
- }
- additional = %{
- "statusnetConversationId" => inReplyTo.data["statusnetConversationId"]
- }
-
- [to, context, object, additional]
- else
- object = %{
- "type" => "Note",
- "to" => to,
- "content" => content_html,
- "published" => date,
- "context" => context,
- "attachment" => attachments,
- "actor" => user.ap_id
- }
- [to, context, object, %{}]
+ 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