Fix credo warnings

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2021-06-03 15:00:49 +02:00
parent 37c1790273
commit c0ab3d9905
No known key found for this signature in database
GPG Key ID: A061B9DDE0CA0773
7 changed files with 85 additions and 123 deletions

View File

@ -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 """

View File

@ -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

View File

@ -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

View File

@ -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,

View File

@ -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 ::

View File

@ -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()

View File

@ -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