refactor(backend): change naming of function names to avoid the is_ prefix
Following Credo.Check.Readability.PredicateFunctionNames check Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -55,14 +55,14 @@ defmodule Mobilizon.Service.DateTime do
|
||||
)
|
||||
end
|
||||
|
||||
@spec is_first_day_of_week(Date.t(), String.t()) :: boolean()
|
||||
defp is_first_day_of_week(%Date{} = date, locale) do
|
||||
@spec first_day_of_week?(Date.t(), String.t()) :: boolean()
|
||||
defp first_day_of_week?(%Date{} = date, locale) do
|
||||
Date.day_of_week(date) == Cldr.Calendar.first_day_for_locale(locale)
|
||||
end
|
||||
|
||||
@spec calculate_first_day_of_week(Date.t(), String.t()) :: Date.t()
|
||||
def calculate_first_day_of_week(%Date{} = date, locale \\ "en") do
|
||||
if is_first_day_of_week(date, locale),
|
||||
if first_day_of_week?(date, locale),
|
||||
do: date,
|
||||
else: calculate_first_day_of_week(Date.add(date, -1), locale)
|
||||
end
|
||||
@@ -204,11 +204,11 @@ defmodule Mobilizon.Service.DateTime do
|
||||
compare_to_day = Keyword.get(options, :compare_to_day, Date.utc_today())
|
||||
locale = Keyword.get(options, :locale, "en")
|
||||
|
||||
is_first_day_of_week(compare_to_day, locale) && is_between_hours?(options)
|
||||
first_day_of_week?(compare_to_day, locale) && is_between_hours?(options)
|
||||
end
|
||||
|
||||
@spec is_delay_ok_since_last_notification_sent?(DateTime.t(), pos_integer()) :: boolean()
|
||||
def is_delay_ok_since_last_notification_sent?(
|
||||
@spec delay_ok_since_last_notification_sent?(DateTime.t(), pos_integer()) :: boolean()
|
||||
def delay_ok_since_last_notification_sent?(
|
||||
%DateTime{} = last_notification_sent,
|
||||
delay \\ 3_600
|
||||
) do
|
||||
@@ -216,8 +216,8 @@ defmodule Mobilizon.Service.DateTime do
|
||||
:lt
|
||||
end
|
||||
|
||||
@spec is_same_day?(DateTime.t(), DateTime.t()) :: boolean()
|
||||
def is_same_day?(%DateTime{} = one, %DateTime{} = two) do
|
||||
@spec same_day?(DateTime.t(), DateTime.t()) :: boolean()
|
||||
def same_day?(%DateTime{} = one, %DateTime{} = two) do
|
||||
DateTime.to_date(one) == DateTime.to_date(two)
|
||||
end
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ defmodule Mobilizon.Service.Export.Common do
|
||||
def fetch_actor_event_feed(name, limit) do
|
||||
case Actors.get_actor_by_name(name) do
|
||||
%Actor{} = actor ->
|
||||
if Actor.is_public_visibility?(actor) do
|
||||
if Actor.public_visibility?(actor) do
|
||||
%Page{elements: events} = Events.list_public_upcoming_events_for_actor(actor, 1, limit)
|
||||
%Page{elements: posts} = Posts.get_public_posts_for_group(actor, 1, limit)
|
||||
{:ok, actor, events, posts}
|
||||
|
||||
@@ -265,7 +265,7 @@ defmodule Mobilizon.Service.Export.Feed do
|
||||
end
|
||||
|
||||
defp clear_actor_feed(%Actor{preferred_username: preferred_username} = actor) do
|
||||
if Actor.is_public_visibility?(actor) do
|
||||
if Actor.public_visibility?(actor) do
|
||||
Cachex.del(:feed, "actor_#{preferred_username}")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -216,7 +216,7 @@ defmodule Mobilizon.Service.Export.ICalendar do
|
||||
end
|
||||
|
||||
defp clear_actor_feed(%Actor{preferred_username: preferred_username} = actor) do
|
||||
if Actor.is_public_visibility?(actor) do
|
||||
if Actor.public_visibility?(actor) do
|
||||
Cachex.del(:ics, "actor_#{preferred_username}")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -13,8 +13,8 @@ defmodule Mobilizon.Service.HTTP.Utils do
|
||||
end
|
||||
end
|
||||
|
||||
@spec is_content_type?(Enum.t(), String.t() | list(String.t())) :: boolean
|
||||
def is_content_type?(headers, content_type) do
|
||||
@spec content_type_matches?(Enum.t(), String.t() | list(String.t())) :: boolean
|
||||
def content_type_matches?(headers, content_type) do
|
||||
headers
|
||||
|> get_header("Content-Type")
|
||||
|> content_type_header_matches(content_type)
|
||||
|
||||
@@ -12,8 +12,8 @@ defmodule Mobilizon.Service.Notifier.Email do
|
||||
|
||||
import Mobilizon.Service.DateTime,
|
||||
only: [
|
||||
is_delay_ok_since_last_notification_sent?: 1,
|
||||
is_delay_ok_since_last_notification_sent?: 2
|
||||
delay_ok_since_last_notification_sent?: 1,
|
||||
delay_ok_since_last_notification_sent?: 2
|
||||
]
|
||||
|
||||
require Logger
|
||||
@@ -129,7 +129,7 @@ defmodule Mobilizon.Service.Notifier.Email do
|
||||
|
||||
# Delay ok since last notification
|
||||
defp match_group_notifications_setting(:one_hour, _, %DateTime{} = last_notification_sent, _) do
|
||||
is_delay_ok_since_last_notification_sent?(last_notification_sent)
|
||||
delay_ok_since_last_notification_sent?(last_notification_sent)
|
||||
end
|
||||
|
||||
# Delay ok since last notification
|
||||
@@ -139,7 +139,7 @@ defmodule Mobilizon.Service.Notifier.Email do
|
||||
%DateTime{} = last_notification_sent,
|
||||
options
|
||||
) do
|
||||
is_delay_ok_since_last_notification_sent?(last_notification_sent, 3_600 * 23) and
|
||||
delay_ok_since_last_notification_sent?(last_notification_sent, 3_600 * 23) and
|
||||
Keyword.get(options, :recap, false) != false
|
||||
end
|
||||
|
||||
@@ -149,7 +149,7 @@ defmodule Mobilizon.Service.Notifier.Email do
|
||||
%DateTime{} = last_notification_sent,
|
||||
options
|
||||
) do
|
||||
is_delay_ok_since_last_notification_sent?(last_notification_sent, 3_600 * 24 * 6) and
|
||||
delay_ok_since_last_notification_sent?(last_notification_sent, 3_600 * 24 * 6) and
|
||||
Keyword.get(options, :recap, false) != false
|
||||
end
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@ defmodule Mobilizon.Service.RichMedia.Parser do
|
||||
opts: @options
|
||||
)},
|
||||
{:is_html, _response_headers, true} <-
|
||||
{:is_html, response_headers, is_html?(response_headers)} do
|
||||
{:is_html, response_headers, html?(response_headers)} do
|
||||
body
|
||||
|> convert_utf8(response_headers)
|
||||
|> maybe_parse()
|
||||
@@ -106,21 +106,21 @@ defmodule Mobilizon.Service.RichMedia.Parser do
|
||||
defp get_data_for_media(response_headers, url) do
|
||||
data = %{title: get_filename_from_headers(response_headers) || get_filename_from_url(url)}
|
||||
|
||||
if is_image?(response_headers) do
|
||||
if image?(response_headers) do
|
||||
Map.put(data, :image_remote_url, url)
|
||||
else
|
||||
data
|
||||
end
|
||||
end
|
||||
|
||||
@spec is_html?(Enum.t()) :: boolean
|
||||
defp is_html?(headers) do
|
||||
is_content_type?(headers, ["text/html", "application/xhtml"])
|
||||
@spec html?(Enum.t()) :: boolean
|
||||
defp html?(headers) do
|
||||
content_type_matches?(headers, ["text/html", "application/xhtml"])
|
||||
end
|
||||
|
||||
@spec is_image?(Enum.t()) :: boolean
|
||||
defp is_image?(headers) do
|
||||
is_content_type?(headers, ["image/"])
|
||||
@spec image?(Enum.t()) :: boolean
|
||||
defp image?(headers) do
|
||||
content_type_matches?(headers, ["image/"])
|
||||
end
|
||||
|
||||
@spec get_filename_from_headers(Enum.t()) :: String.t() | nil
|
||||
|
||||
@@ -81,7 +81,7 @@ defmodule Mobilizon.Service.Workers.LegacyNotifierBuilder do
|
||||
options
|
||||
) do
|
||||
mentionned_actor_ids
|
||||
|> Enum.filter(&Actors.is_member?(&1, Keyword.fetch!(options, :group_id)))
|
||||
|> Enum.filter(&Actors.member?(&1, Keyword.fetch!(options, :group_id)))
|
||||
|> users_from_actor_ids(Keyword.fetch!(options, :author_id))
|
||||
end
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ defmodule Mobilizon.Service.Workers.SendActivityRecapWorker do
|
||||
only: [
|
||||
is_between_hours?: 1,
|
||||
is_between_hours_on_first_day?: 1,
|
||||
is_delay_ok_since_last_notification_sent?: 1
|
||||
delay_ok_since_last_notification_sent?: 1
|
||||
]
|
||||
|
||||
@impl Oban.Worker
|
||||
@@ -108,7 +108,7 @@ defmodule Mobilizon.Service.Workers.SendActivityRecapWorker do
|
||||
"Testing if it's less than an hour since the last time we sent an activity recap"
|
||||
)
|
||||
|
||||
is_delay_ok_since_last_notification_sent?(last_notification_sent)
|
||||
delay_ok_since_last_notification_sent?(last_notification_sent)
|
||||
end
|
||||
|
||||
# If we're between notification hours
|
||||
|
||||
Reference in New Issue
Block a user