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. Handles the push subscriptions-related GraphQL calls.
""" """
alias Mobilizon.Users
alias Mobilizon.Storage.Page alias Mobilizon.Storage.Page
alias Mobilizon.Users
alias Mobilizon.Users.{PushSubscription, User} alias Mobilizon.Users.{PushSubscription, User}
@doc """ @doc """

View file

@ -1,4 +1,7 @@
defmodule Mobilizon.Users.PushSubscription do defmodule Mobilizon.Users.PushSubscription do
@moduledoc """
Represents informations about a push subscription for a specific user
"""
use Ecto.Schema use Ecto.Schema
alias Mobilizon.Users.User alias Mobilizon.Users.User
import Ecto.Changeset import Ecto.Changeset

View file

@ -16,96 +16,50 @@ defmodule Mobilizon.Service.Activity.Renderer.Member do
locale = Keyword.get(options, :locale, "en") locale = Keyword.get(options, :locale, "en")
Gettext.put_locale(locale) Gettext.put_locale(locale)
case activity.subject do
:member_request ->
%{ %{
body: body:
dgettext("activity", "%{member} requested to join the group.", %{ text(activity.subject, %{
profile: profile(activity),
member: title(activity)
}),
url: member_url(activity)
}
:member_invited ->
%{
body:
dgettext("activity", "%{member} was invited by %{profile}.", %{
profile: profile(activity),
member: title(activity)
}),
url: member_url(activity)
}
:member_accepted_invitation ->
%{
body:
dgettext("activity", "%{member} accepted the invitation to join the group.", %{
profile: profile(activity),
member: title(activity)
}),
url: member_url(activity)
}
:member_rejected_invitation ->
%{
body:
dgettext("activity", "%{member} rejected the invitation to join the group.", %{
profile: profile(activity),
member: title(activity)
}),
url: member_url(activity)
}
:member_joined ->
%{
body:
dgettext("activity", "%{member} joined the group.", %{
member: title(activity)
}),
url: member_url(activity)
}
:member_added ->
%{
body:
dgettext("activity", "%{profile} added the member %{member}.", %{
profile: profile(activity),
member: title(activity)
}),
url: member_url(activity)
}
:member_updated ->
%{
body:
dgettext("activity", "%{profile} updated the member %{member}.", %{
profile: profile(activity),
member: title(activity)
}),
url: member_url(activity)
}
:member_removed ->
%{
body:
dgettext("activity", "%{profile} excluded member %{member}.", %{
profile: profile(activity),
member: title(activity)
}),
url: member_url(activity)
}
:member_quit ->
%{
body:
dgettext("activity", "%{profile} quit the group.", %{
profile: profile(activity), profile: profile(activity),
member: title(activity) member: title(activity)
}), }),
url: member_url(activity) url: member_url(activity)
} }
end end
defp text(:member_request, args) do
dgettext("activity", "%{member} requested to join the group.", args)
end
defp text(:member_invited, args) do
dgettext("activity", "%{member} was invited by %{profile}.", args)
end
defp text(:member_accepted_invitation, args) do
dgettext("activity", "%{member} accepted the invitation to join the group.", args)
end
defp text(:member_rejected_invitation, args) do
dgettext("activity", "%{member} rejected the invitation to join the group.", args)
end
defp text(:member_joined, args) do
dgettext("activity", "%{member} joined the group.", args)
end
defp text(:member_added, args) do
dgettext("activity", "%{profile} added the member %{member}.", args)
end
defp text(:member_updated, args) do
dgettext("activity", "%{profile} updated the member %{member}.", args)
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 end
defp member_url(activity) do defp member_url(activity) do

View file

@ -3,8 +3,8 @@ defmodule Mobilizon.Service.Activity.Renderer do
Behavior for Activity renderers Behavior for Activity renderers
""" """
alias Mobilizon.Config
alias Mobilizon.Activities.Activity alias Mobilizon.Activities.Activity
alias Mobilizon.Config
alias Mobilizon.Service.Activity.Renderer.{ alias Mobilizon.Service.Activity.Renderer.{
Comment, Comment,

View file

@ -46,27 +46,28 @@ defmodule Mobilizon.Service.Notifier.Email do
Filter.can_send_activity?(activity, "email", user, &default_activity_behavior/1) Filter.can_send_activity?(activity, "email", user, &default_activity_behavior/1)
end 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() @spec default_activity_behavior(String.t()) :: boolean()
defp default_activity_behavior(activity_setting) do defp default_activity_behavior(activity_setting) do
case activity_setting do Map.get(@default_behavior, activity_setting, false)
"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
end end
@type notification_type :: @type notification_type ::

View file

@ -1,6 +1,9 @@
defmodule Mobilizon.Service.Notifier.Filter do 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.Activities.Activity
alias Mobilizon.Users
alias Mobilizon.Users.{ActivitySetting, User} alias Mobilizon.Users.{ActivitySetting, User}
@type method :: String.t() @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) Filter.can_send_activity?(activity, "push", user, &default_activity_behavior/1)
end 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() @spec default_activity_behavior(String.t()) :: boolean()
defp default_activity_behavior(activity_setting) do defp default_activity_behavior(activity_setting) do
case activity_setting do Map.get(@default_behavior, activity_setting, false)
"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
end end
defp send_subscription(activity, subscription, options) do defp send_subscription(activity, subscription, options) do