chore: Use when clauses to aid the JIT in RenderUtils
All checks were successful
Build / build (push) Successful in 2m42s
All checks were successful
Build / build (push) Successful in 2m42s
This commit is contained in:
parent
d68b03d133
commit
e0107a3d81
1 changed files with 7 additions and 7 deletions
|
@ -1,13 +1,13 @@
|
||||||
defmodule BdfrBrowser.RenderUtils do
|
defmodule BdfrBrowser.RenderUtils do
|
||||||
def selftext(txt) do
|
def selftext(txt) when is_binary(txt) do
|
||||||
Earmark.as_html!(txt)
|
Earmark.as_html!(txt)
|
||||||
end
|
end
|
||||||
|
|
||||||
def comment(cmt) do
|
def comment(cmt) when is_binary(cmt) do
|
||||||
Earmark.as_html!(cmt)
|
Earmark.as_html!(cmt)
|
||||||
end
|
end
|
||||||
|
|
||||||
def message(msg) do
|
def message(msg) when is_binary(msg) do
|
||||||
img_replacement =
|
img_replacement =
|
||||||
"<p class=\"text-center\"><img src=\"/chat_media/\\1\" class=\"img-fluid\" loading=\"lazy\" /></p>"
|
"<p class=\"text-center\"><img src=\"/chat_media/\\1\" class=\"img-fluid\" loading=\"lazy\" /></p>"
|
||||||
|
|
||||||
|
@ -17,12 +17,12 @@ defmodule BdfrBrowser.RenderUtils do
|
||||||
|> Earmark.as_html!()
|
|> Earmark.as_html!()
|
||||||
end
|
end
|
||||||
|
|
||||||
def link_to_user(name) when name in ~w([deleted] DELETED), do: name
|
def link_to_user(name) when is_binary(name) and name in ~w([deleted] DELETED), do: name
|
||||||
def link_to_user(name), do: "<a href=\"/user/#{name}\">#{name}</a>"
|
def link_to_user(name) when is_binary(name), do: "<a href=\"/user/#{name}\">#{name}</a>"
|
||||||
|
|
||||||
# Helper
|
# Helper
|
||||||
|
|
||||||
defp maybe_insert_image(<<"mxc://reddit.com/", filename::binary>> = msg, replacement) do
|
defp maybe_insert_image(<<"mxc://reddit.com/", filename::binary>> = msg, replacement) when is_binary(msg) do
|
||||||
chat_directory = Application.fetch_env!(:bdfr_browser, :chat_directory)
|
chat_directory = Application.fetch_env!(:bdfr_browser, :chat_directory)
|
||||||
img_directory = Path.join([chat_directory, "images"])
|
img_directory = Path.join([chat_directory, "images"])
|
||||||
imgs = Path.wildcard("#{img_directory}/#{filename}.*")
|
imgs = Path.wildcard("#{img_directory}/#{filename}.*")
|
||||||
|
@ -35,5 +35,5 @@ defmodule BdfrBrowser.RenderUtils do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp maybe_insert_image(msg, _replacement), do: msg
|
defp maybe_insert_image(msg, _replacement) when is_binary(msg), do: msg
|
||||||
end
|
end
|
||||||
|
|
Reference in a new issue