From c0ab3d99058235cf20fd0f2b90ab1fe02849fce6 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Thu, 3 Jun 2021 15:00:49 +0200 Subject: [PATCH] Fix credo warnings Signed-off-by: Thomas Citharel --- lib/graphql/resolvers/push_subscription.ex | 2 +- lib/mobilizon/users/push_subscription.ex | 3 + lib/service/activity/renderer/member.ex | 118 +++++++-------------- lib/service/activity/renderer/renderer.ex | 2 +- lib/service/notifier/email.ex | 39 +++---- lib/service/notifier/filter.ex | 5 +- lib/service/notifier/push.ex | 39 +++---- 7 files changed, 85 insertions(+), 123 deletions(-) diff --git a/lib/graphql/resolvers/push_subscription.ex b/lib/graphql/resolvers/push_subscription.ex index 30be6482..dd2018db 100644 --- a/lib/graphql/resolvers/push_subscription.ex +++ b/lib/graphql/resolvers/push_subscription.ex @@ -3,8 +3,8 @@ defmodule Mobilizon.GraphQL.Resolvers.PushSubscription do Handles the push subscriptions-related GraphQL calls. """ - alias Mobilizon.Users alias Mobilizon.Storage.Page + alias Mobilizon.Users alias Mobilizon.Users.{PushSubscription, User} @doc """ diff --git a/lib/mobilizon/users/push_subscription.ex b/lib/mobilizon/users/push_subscription.ex index 2dc8c24c..737139f2 100644 --- a/lib/mobilizon/users/push_subscription.ex +++ b/lib/mobilizon/users/push_subscription.ex @@ -1,4 +1,7 @@ defmodule Mobilizon.Users.PushSubscription do + @moduledoc """ + Represents informations about a push subscription for a specific user + """ use Ecto.Schema alias Mobilizon.Users.User import Ecto.Changeset diff --git a/lib/service/activity/renderer/member.ex b/lib/service/activity/renderer/member.ex index 4e804229..39d468fb 100644 --- a/lib/service/activity/renderer/member.ex +++ b/lib/service/activity/renderer/member.ex @@ -16,96 +16,50 @@ defmodule Mobilizon.Service.Activity.Renderer.Member do locale = Keyword.get(options, :locale, "en") Gettext.put_locale(locale) - case activity.subject do - :member_request -> - %{ - body: - dgettext("activity", "%{member} requested to join the group.", %{ - profile: profile(activity), - member: title(activity) - }), - url: member_url(activity) - } + %{ + body: + text(activity.subject, %{ + profile: profile(activity), + member: title(activity) + }), + url: member_url(activity) + } + end - :member_invited -> - %{ - body: - dgettext("activity", "%{member} was invited by %{profile}.", %{ - profile: profile(activity), - member: title(activity) - }), - url: member_url(activity) - } + defp text(:member_request, args) do + dgettext("activity", "%{member} requested to join the group.", args) + end - :member_accepted_invitation -> - %{ - body: - dgettext("activity", "%{member} accepted the invitation to join the group.", %{ - profile: profile(activity), - member: title(activity) - }), - url: member_url(activity) - } + defp text(:member_invited, args) do + dgettext("activity", "%{member} was invited by %{profile}.", args) + end - :member_rejected_invitation -> - %{ - body: - dgettext("activity", "%{member} rejected the invitation to join the group.", %{ - profile: profile(activity), - member: title(activity) - }), - url: member_url(activity) - } + defp text(:member_accepted_invitation, args) do + dgettext("activity", "%{member} accepted the invitation to join the group.", args) + end - :member_joined -> - %{ - body: - dgettext("activity", "%{member} joined the group.", %{ - member: title(activity) - }), - url: member_url(activity) - } + defp text(:member_rejected_invitation, args) do + dgettext("activity", "%{member} rejected the invitation to join the group.", args) + end - :member_added -> - %{ - body: - dgettext("activity", "%{profile} added the member %{member}.", %{ - profile: profile(activity), - member: title(activity) - }), - url: member_url(activity) - } + defp text(:member_joined, args) do + dgettext("activity", "%{member} joined the group.", args) + end - :member_updated -> - %{ - body: - dgettext("activity", "%{profile} updated the member %{member}.", %{ - profile: profile(activity), - member: title(activity) - }), - url: member_url(activity) - } + defp text(:member_added, args) do + dgettext("activity", "%{profile} added the member %{member}.", args) + end - :member_removed -> - %{ - body: - dgettext("activity", "%{profile} excluded member %{member}.", %{ - profile: profile(activity), - member: title(activity) - }), - url: member_url(activity) - } + defp text(:member_updated, args) do + dgettext("activity", "%{profile} updated the member %{member}.", args) + end - :member_quit -> - %{ - body: - dgettext("activity", "%{profile} quit the group.", %{ - profile: profile(activity), - member: title(activity) - }), - url: member_url(activity) - } - end + defp text(:member_removed, args) do + dgettext("activity", "%{profile} excluded member %{member}.", args) + end + + defp text(:member_quit, args) do + dgettext("activity", "%{profile} quit the group.", args) end defp member_url(activity) do diff --git a/lib/service/activity/renderer/renderer.ex b/lib/service/activity/renderer/renderer.ex index 475db67b..87e1d56d 100644 --- a/lib/service/activity/renderer/renderer.ex +++ b/lib/service/activity/renderer/renderer.ex @@ -3,8 +3,8 @@ defmodule Mobilizon.Service.Activity.Renderer do Behavior for Activity renderers """ - alias Mobilizon.Config alias Mobilizon.Activities.Activity + alias Mobilizon.Config alias Mobilizon.Service.Activity.Renderer.{ Comment, diff --git a/lib/service/notifier/email.ex b/lib/service/notifier/email.ex index f182e02e..eceaa49b 100644 --- a/lib/service/notifier/email.ex +++ b/lib/service/notifier/email.ex @@ -46,27 +46,28 @@ defmodule Mobilizon.Service.Notifier.Email do Filter.can_send_activity?(activity, "email", user, &default_activity_behavior/1) end + @default_behavior %{ + "participation_event_updated" => true, + "participation_event_comment" => true, + "event_new_pending_participation" => true, + "event_new_participation" => false, + "event_created" => false, + "event_updated" => false, + "discussion_updated" => false, + "post_published" => false, + "post_updated" => false, + "resource_updated" => false, + "member_request" => true, + "member_updated" => false, + "user_email_password_updated" => true, + "event_comment_mention" => true, + "discussion_mention" => true, + "event_new_comment" => true + } + @spec default_activity_behavior(String.t()) :: boolean() defp default_activity_behavior(activity_setting) do - case activity_setting do - "participation_event_updated" -> true - "participation_event_comment" -> true - "event_new_pending_participation" -> true - "event_new_participation" -> false - "event_created" -> false - "event_updated" -> false - "discussion_updated" -> false - "post_published" -> false - "post_updated" -> false - "resource_updated" -> false - "member_request" -> true - "member_updated" -> false - "user_email_password_updated" -> true - "event_comment_mention" -> true - "discussion_mention" -> true - "event_new_comment" -> true - _ -> false - end + Map.get(@default_behavior, activity_setting, false) end @type notification_type :: diff --git a/lib/service/notifier/filter.ex b/lib/service/notifier/filter.ex index c763c4d6..c3708a93 100644 --- a/lib/service/notifier/filter.ex +++ b/lib/service/notifier/filter.ex @@ -1,6 +1,9 @@ defmodule Mobilizon.Service.Notifier.Filter do - alias Mobilizon.Users + @moduledoc """ + Module to filter activities to notify according to user's activity settings + """ alias Mobilizon.Activities.Activity + alias Mobilizon.Users alias Mobilizon.Users.{ActivitySetting, User} @type method :: String.t() diff --git a/lib/service/notifier/push.ex b/lib/service/notifier/push.ex index e604fa01..6cec1d92 100644 --- a/lib/service/notifier/push.ex +++ b/lib/service/notifier/push.ex @@ -42,27 +42,28 @@ defmodule Mobilizon.Service.Notifier.Push do Filter.can_send_activity?(activity, "push", user, &default_activity_behavior/1) end + @default_behavior %{ + "participation_event_updated" => true, + "participation_event_comment" => true, + "event_new_pending_participation" => true, + "event_new_participation" => false, + "event_created" => false, + "event_updated" => false, + "discussion_updated" => false, + "post_published" => false, + "post_updated" => false, + "resource_updated" => false, + "member_request" => true, + "member_updated" => false, + "user_email_password_updated" => false, + "event_comment_mention" => true, + "discussion_mention" => false, + "event_new_comment" => false + } + @spec default_activity_behavior(String.t()) :: boolean() defp default_activity_behavior(activity_setting) do - case activity_setting do - "participation_event_updated" -> true - "participation_event_comment" -> true - "event_new_pending_participation" -> true - "event_new_participation" -> false - "event_created" -> false - "event_updated" -> false - "discussion_updated" -> false - "post_published" -> false - "post_updated" -> false - "resource_updated" -> false - "member_request" -> true - "member_updated" -> false - "user_email_password_updated" -> false - "event_comment_mention" -> true - "discussion_mention" -> false - "event_new_comment" -> false - _ -> false - end + Map.get(@default_behavior, activity_setting, false) end defp send_subscription(activity, subscription, options) do