forked from YokaiRick/akkoma
[Credo] make all variables use snake_case
This commit is contained in:
parent
fb82f6fc7c
commit
c3d41b2b6e
5 changed files with 33 additions and 32 deletions
|
@ -650,10 +650,10 @@ def get_obj_helper(id) do
|
||||||
if object = Object.normalize(id), do: {:ok, object}, else: nil
|
if object = Object.normalize(id), do: {:ok, object}, else: nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_reply_to_uri(%{"inReplyTo" => inReplyTo} = object) when is_binary(inReplyTo) do
|
def set_reply_to_uri(%{"inReplyTo" => in_reply_to} = object) when is_binary(in_reply_to) do
|
||||||
with false <- String.starts_with?(inReplyTo, "http"),
|
with false <- String.starts_with?(in_reply_to, "http"),
|
||||||
{:ok, %{data: replied_to_object}} <- get_obj_helper(inReplyTo) do
|
{:ok, %{data: replied_to_object}} <- get_obj_helper(in_reply_to) do
|
||||||
Map.put(object, "inReplyTo", replied_to_object["external_url"] || inReplyTo)
|
Map.put(object, "inReplyTo", replied_to_object["external_url"] || in_reply_to)
|
||||||
else
|
else
|
||||||
_e -> object
|
_e -> object
|
||||||
end
|
end
|
||||||
|
@ -830,10 +830,10 @@ def set_sensitive(object) do
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_attributed_to(object) do
|
def add_attributed_to(object) do
|
||||||
attributedTo = object["attributedTo"] || object["actor"]
|
attributed_to = object["attributedTo"] || object["actor"]
|
||||||
|
|
||||||
object
|
object
|
||||||
|> Map.put("attributedTo", attributedTo)
|
|> Map.put("attributedTo", attributed_to)
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_likes(%{"id" => id, "like_count" => likes} = object) do
|
def add_likes(%{"id" => id, "like_count" => likes} = object) do
|
||||||
|
|
|
@ -88,8 +88,8 @@ def get_visibility(%{"in_reply_to_status_id" => status_id}) when not is_nil(stat
|
||||||
nil ->
|
nil ->
|
||||||
"public"
|
"public"
|
||||||
|
|
||||||
inReplyTo ->
|
in_reply_to ->
|
||||||
Pleroma.Web.MastodonAPI.StatusView.get_visibility(inReplyTo.data["object"])
|
Pleroma.Web.MastodonAPI.StatusView.get_visibility(in_reply_to.data["object"])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -101,15 +101,15 @@ def post(user, %{"status" => status} = data) do
|
||||||
|
|
||||||
with status <- String.trim(status),
|
with status <- String.trim(status),
|
||||||
attachments <- attachments_from_ids(data),
|
attachments <- attachments_from_ids(data),
|
||||||
inReplyTo <- get_replied_to_activity(data["in_reply_to_status_id"]),
|
in_reply_to <- get_replied_to_activity(data["in_reply_to_status_id"]),
|
||||||
{content_html, mentions, tags} <-
|
{content_html, mentions, tags} <-
|
||||||
make_content_html(
|
make_content_html(
|
||||||
status,
|
status,
|
||||||
attachments,
|
attachments,
|
||||||
data
|
data
|
||||||
),
|
),
|
||||||
{to, cc} <- to_for_user_and_mentions(user, mentions, inReplyTo, visibility),
|
{to, cc} <- to_for_user_and_mentions(user, mentions, in_reply_to, visibility),
|
||||||
context <- make_context(inReplyTo),
|
context <- make_context(in_reply_to),
|
||||||
cw <- data["spoiler_text"],
|
cw <- data["spoiler_text"],
|
||||||
full_payload <- String.trim(status <> (data["spoiler_text"] || "")),
|
full_payload <- String.trim(status <> (data["spoiler_text"] || "")),
|
||||||
length when length in 1..limit <- String.length(full_payload),
|
length when length in 1..limit <- String.length(full_payload),
|
||||||
|
@ -120,7 +120,7 @@ def post(user, %{"status" => status} = data) do
|
||||||
context,
|
context,
|
||||||
content_html,
|
content_html,
|
||||||
attachments,
|
attachments,
|
||||||
inReplyTo,
|
in_reply_to,
|
||||||
tags,
|
tags,
|
||||||
cw,
|
cw,
|
||||||
cc
|
cc
|
||||||
|
|
|
@ -19,13 +19,13 @@ defmodule Pleroma.Web.OStatus.NoteHandler do
|
||||||
2. The conversation reference in the ostatus xml
|
2. The conversation reference in the ostatus xml
|
||||||
3. A newly generated context id.
|
3. A newly generated context id.
|
||||||
"""
|
"""
|
||||||
def get_context(entry, inReplyTo) do
|
def get_context(entry, in_reply_to) do
|
||||||
context =
|
context =
|
||||||
(XML.string_from_xpath("//ostatus:conversation[1]", entry) ||
|
(XML.string_from_xpath("//ostatus:conversation[1]", entry) ||
|
||||||
XML.string_from_xpath("//ostatus:conversation[1]/@ref", entry) || "")
|
XML.string_from_xpath("//ostatus:conversation[1]/@ref", entry) || "")
|
||||||
|> String.trim()
|
|> String.trim()
|
||||||
|
|
||||||
with %{data: %{"context" => context}} <- Object.get_cached_by_ap_id(inReplyTo) do
|
with %{data: %{"context" => context}} <- Object.get_cached_by_ap_id(in_reply_to) do
|
||||||
context
|
context
|
||||||
else
|
else
|
||||||
_e ->
|
_e ->
|
||||||
|
@ -88,14 +88,14 @@ def add_external_url(note, entry) do
|
||||||
Map.put(note, "external_url", url)
|
Map.put(note, "external_url", url)
|
||||||
end
|
end
|
||||||
|
|
||||||
def fetch_replied_to_activity(entry, inReplyTo) do
|
def fetch_replied_to_activity(entry, in_reply_to) do
|
||||||
with %Activity{} = activity <- Activity.get_create_by_object_ap_id(inReplyTo) do
|
with %Activity{} = activity <- Activity.get_create_by_object_ap_id(in_reply_to) do
|
||||||
activity
|
activity
|
||||||
else
|
else
|
||||||
_e ->
|
_e ->
|
||||||
with inReplyToHref when not is_nil(inReplyToHref) <-
|
with in_reply_to_href when not is_nil(in_reply_to_href) <-
|
||||||
XML.string_from_xpath("//thr:in-reply-to[1]/@href", entry),
|
XML.string_from_xpath("//thr:in-reply-to[1]/@href", entry),
|
||||||
{:ok, [activity | _]} <- OStatus.fetch_activity_from_url(inReplyToHref) do
|
{:ok, [activity | _]} <- OStatus.fetch_activity_from_url(in_reply_to_href) do
|
||||||
activity
|
activity
|
||||||
else
|
else
|
||||||
_e -> nil
|
_e -> nil
|
||||||
|
@ -111,11 +111,12 @@ def handle_note(entry, doc \\ nil) do
|
||||||
{:ok, actor} <- OStatus.find_make_or_update_user(author),
|
{:ok, actor} <- OStatus.find_make_or_update_user(author),
|
||||||
content_html <- OStatus.get_content(entry),
|
content_html <- OStatus.get_content(entry),
|
||||||
cw <- OStatus.get_cw(entry),
|
cw <- OStatus.get_cw(entry),
|
||||||
inReplyTo <- XML.string_from_xpath("//thr:in-reply-to[1]/@ref", entry),
|
in_reply_to <- XML.string_from_xpath("//thr:in-reply-to[1]/@ref", entry),
|
||||||
inReplyToActivity <- fetch_replied_to_activity(entry, inReplyTo),
|
in_reply_to_activity <- fetch_replied_to_activity(entry, in_reply_to),
|
||||||
inReplyTo <- (inReplyToActivity && inReplyToActivity.data["object"]["id"]) || inReplyTo,
|
in_reply_to <-
|
||||||
|
(in_reply_to_activity && in_reply_to_activity.data["object"]["id"]) || in_reply_to,
|
||||||
attachments <- OStatus.get_attachments(entry),
|
attachments <- OStatus.get_attachments(entry),
|
||||||
context <- get_context(entry, inReplyTo),
|
context <- get_context(entry, in_reply_to),
|
||||||
tags <- OStatus.get_tags(entry),
|
tags <- OStatus.get_tags(entry),
|
||||||
mentions <- get_mentions(entry),
|
mentions <- get_mentions(entry),
|
||||||
to <- make_to_list(actor, mentions),
|
to <- make_to_list(actor, mentions),
|
||||||
|
@ -129,7 +130,7 @@ def handle_note(entry, doc \\ nil) do
|
||||||
context,
|
context,
|
||||||
content_html,
|
content_html,
|
||||||
attachments,
|
attachments,
|
||||||
inReplyToActivity,
|
in_reply_to_activity,
|
||||||
[],
|
[],
|
||||||
cw
|
cw
|
||||||
),
|
),
|
||||||
|
@ -141,8 +142,8 @@ def handle_note(entry, doc \\ nil) do
|
||||||
# TODO: Handle this case in make_note_data
|
# TODO: Handle this case in make_note_data
|
||||||
note <-
|
note <-
|
||||||
if(
|
if(
|
||||||
inReplyTo && !inReplyToActivity,
|
in_reply_to && !in_reply_to_activity,
|
||||||
do: note |> Map.put("inReplyTo", inReplyTo),
|
do: note |> Map.put("inReplyTo", in_reply_to),
|
||||||
else: note
|
else: note
|
||||||
) do
|
) do
|
||||||
ActivityPub.create(%{
|
ActivityPub.create(%{
|
||||||
|
|
|
@ -133,7 +133,7 @@ def upload(%Plug.Upload{} = file, %User{} = user, format \\ "xml") do
|
||||||
end
|
end
|
||||||
|
|
||||||
def register_user(params) do
|
def register_user(params) do
|
||||||
tokenString = params["token"]
|
token_string = params["token"]
|
||||||
|
|
||||||
params = %{
|
params = %{
|
||||||
nickname: params["nickname"],
|
nickname: params["nickname"],
|
||||||
|
@ -170,8 +170,8 @@ def register_user(params) do
|
||||||
|
|
||||||
# no need to query DB if registration is open
|
# no need to query DB if registration is open
|
||||||
token =
|
token =
|
||||||
unless registrations_open || is_nil(tokenString) do
|
unless registrations_open || is_nil(token_string) do
|
||||||
Repo.get_by(UserInviteToken, %{token: tokenString})
|
Repo.get_by(UserInviteToken, %{token: token_string})
|
||||||
end
|
end
|
||||||
|
|
||||||
cond do
|
cond do
|
||||||
|
|
|
@ -200,8 +200,8 @@ def gather_feed_data(topic, getter \\ &@httpoison.get/1) do
|
||||||
uri when not is_nil(uri) <- XML.string_from_xpath("/feed/author[1]/uri", doc),
|
uri when not is_nil(uri) <- XML.string_from_xpath("/feed/author[1]/uri", doc),
|
||||||
hub when not is_nil(hub) <- XML.string_from_xpath(~S{/feed/link[@rel="hub"]/@href}, doc) do
|
hub when not is_nil(hub) <- XML.string_from_xpath(~S{/feed/link[@rel="hub"]/@href}, doc) do
|
||||||
name = XML.string_from_xpath("/feed/author[1]/name", doc)
|
name = XML.string_from_xpath("/feed/author[1]/name", doc)
|
||||||
preferredUsername = XML.string_from_xpath("/feed/author[1]/poco:preferredUsername", doc)
|
preferred_username = XML.string_from_xpath("/feed/author[1]/poco:preferredUsername", doc)
|
||||||
displayName = XML.string_from_xpath("/feed/author[1]/poco:displayName", doc)
|
display_name = XML.string_from_xpath("/feed/author[1]/poco:displayName", doc)
|
||||||
avatar = OStatus.make_avatar_object(doc)
|
avatar = OStatus.make_avatar_object(doc)
|
||||||
bio = XML.string_from_xpath("/feed/author[1]/summary", doc)
|
bio = XML.string_from_xpath("/feed/author[1]/summary", doc)
|
||||||
|
|
||||||
|
@ -209,8 +209,8 @@ def gather_feed_data(topic, getter \\ &@httpoison.get/1) do
|
||||||
%{
|
%{
|
||||||
"uri" => uri,
|
"uri" => uri,
|
||||||
"hub" => hub,
|
"hub" => hub,
|
||||||
"nickname" => preferredUsername || name,
|
"nickname" => preferred_username || name,
|
||||||
"name" => displayName || name,
|
"name" => display_name || name,
|
||||||
"host" => URI.parse(uri).host,
|
"host" => URI.parse(uri).host,
|
||||||
"avatar" => avatar,
|
"avatar" => avatar,
|
||||||
"bio" => bio
|
"bio" => bio
|
||||||
|
|
Loading…
Reference in a new issue