- content_html = add_user_links(content, mentions)
-
- date = make_date()
-
- activity = %{
- "type" => "Create",
- "to" => to,
- "actor" => user.ap_id,
- "object" => %{
- "type" => "Note",
- "to" => to,
- "content" => content_html,
- "published" => date,
- "context" => context,
- "attachment" => attachments,
- "actor" => user.ap_id
- },
- "published" => date,
- "context" => context
- }
-
- # Wire up reply info.
- activity = with inReplyToId when not is_nil(inReplyToId) <- data["in_reply_to_status_id"],
- inReplyTo <- Repo.get(Activity, inReplyToId),
- context <- inReplyTo.data["context"]
- do
-
- to = activity["to"] ++ [inReplyTo.data["actor"]]
-
- activity
- |> put_in(["to"], to)
- |> put_in(["context"], context)
- |> put_in(["object", "context"], context)
- |> put_in(["object", "inReplyTo"], inReplyTo.data["object"]["id"])
- |> put_in(["object", "inReplyToStatusId"], inReplyToId)
- |> put_in(["statusnetConversationId"], inReplyTo.data["statusnetConversationId"])
- |> put_in(["object", "statusnetConversationId"], inReplyTo.data["statusnetConversationId"])
- else _e ->
- activity
- end
-
- with {:ok, activity} <- ActivityPub.insert(activity) do
- {:ok, activity} = add_conversation_id(activity)
- Websub.publish(OStatus.feed_path(user), user, activity)
- {:ok, activity}
+ 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, %{"status" => status} = data) do
+ with attachments <- attachments_from_ids(data["media_ids"]),
+ mentions <- Formatter.parse_mentions(status),
+ inReplyTo <- get_replied_to_activity(data["in_reply_to_status_id"]),
+ to <- to_for_user_and_mentions(user, mentions, inReplyTo),
+ content_html <- make_content_html(status, mentions, attachments),
+ context <- make_context(inReplyTo),
+ tags <- Formatter.parse_tags(status),
+ object <- make_note_data(user.ap_id, to, context, content_html, attachments, inReplyTo, tags) do
+ res = ActivityPub.create(to, user, context, object)
+ User.update_note_count(user)
+ res