- def handle_note(entry, doc \\ nil) do
- content_html = get_content(entry)
-
- [author] = :xmerl_xpath.string('//author[1]', doc)
- {:ok, actor} = find_make_or_update_user(author)
- inReplyTo = string_from_xpath("//thr:in-reply-to[1]/@ref", entry)
-
- if inReplyTo && !Object.get_cached_by_ap_id(inReplyTo) do
- inReplyToHref = string_from_xpath("//thr:in-reply-to[1]/@href", entry)
- if inReplyToHref do
- fetch_activity_from_html_url(inReplyToHref)
- else
- Logger.debug("Couldn't find a href link to #{inReplyTo}")
- end
- end
-
- context = (string_from_xpath("//ostatus:conversation[1]", entry) || "") |> String.trim
-
- attachments = get_attachments(entry)
-
- context = with %{data: %{"context" => context}} <- Object.get_cached_by_ap_id(inReplyTo) do
- context
- else _e ->
- if String.length(context) > 0 do
- context
- else
- Utils.generate_context_id
- end
- end
-
- tags = get_tags(entry)
-
- to = [
- "https://www.w3.org/ns/activitystreams#Public",
- User.ap_followers(actor)
- ]
-
- mentions = :xmerl_xpath.string('//link[@rel="mentioned" and @ostatus:object-type="http://activitystrea.ms/schema/1.0/person"]', entry)
- |> Enum.map(fn(person) -> string_from_xpath("@href", person) end)
-
- to = to ++ mentions
-
- date = string_from_xpath("//published", entry)
- id = string_from_xpath("//id", entry)
-
- object = %{
- "id" => id,
- "type" => "Note",
- "to" => to,
- "content" => content_html,
- "published" => date,
- "context" => context,
- "actor" => actor.ap_id,
- "attachment" => attachments,
- "tag" => tags