Fix credo warnings
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
37c1790273
commit
c0ab3d9905
|
@ -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 """
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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:
|
||||||
%{
|
text(activity.subject, %{
|
||||||
body:
|
profile: profile(activity),
|
||||||
dgettext("activity", "%{member} requested to join the group.", %{
|
member: title(activity)
|
||||||
profile: profile(activity),
|
}),
|
||||||
member: title(activity)
|
url: member_url(activity)
|
||||||
}),
|
}
|
||||||
url: member_url(activity)
|
end
|
||||||
}
|
|
||||||
|
|
||||||
:member_invited ->
|
defp text(:member_request, args) do
|
||||||
%{
|
dgettext("activity", "%{member} requested to join the group.", args)
|
||||||
body:
|
end
|
||||||
dgettext("activity", "%{member} was invited by %{profile}.", %{
|
|
||||||
profile: profile(activity),
|
|
||||||
member: title(activity)
|
|
||||||
}),
|
|
||||||
url: member_url(activity)
|
|
||||||
}
|
|
||||||
|
|
||||||
:member_accepted_invitation ->
|
defp text(:member_invited, args) do
|
||||||
%{
|
dgettext("activity", "%{member} was invited by %{profile}.", args)
|
||||||
body:
|
end
|
||||||
dgettext("activity", "%{member} accepted the invitation to join the group.", %{
|
|
||||||
profile: profile(activity),
|
|
||||||
member: title(activity)
|
|
||||||
}),
|
|
||||||
url: member_url(activity)
|
|
||||||
}
|
|
||||||
|
|
||||||
:member_rejected_invitation ->
|
defp text(:member_accepted_invitation, args) do
|
||||||
%{
|
dgettext("activity", "%{member} accepted the invitation to join the group.", args)
|
||||||
body:
|
end
|
||||||
dgettext("activity", "%{member} rejected the invitation to join the group.", %{
|
|
||||||
profile: profile(activity),
|
|
||||||
member: title(activity)
|
|
||||||
}),
|
|
||||||
url: member_url(activity)
|
|
||||||
}
|
|
||||||
|
|
||||||
:member_joined ->
|
defp text(:member_rejected_invitation, args) do
|
||||||
%{
|
dgettext("activity", "%{member} rejected the invitation to join the group.", args)
|
||||||
body:
|
end
|
||||||
dgettext("activity", "%{member} joined the group.", %{
|
|
||||||
member: title(activity)
|
|
||||||
}),
|
|
||||||
url: member_url(activity)
|
|
||||||
}
|
|
||||||
|
|
||||||
:member_added ->
|
defp text(:member_joined, args) do
|
||||||
%{
|
dgettext("activity", "%{member} joined the group.", args)
|
||||||
body:
|
end
|
||||||
dgettext("activity", "%{profile} added the member %{member}.", %{
|
|
||||||
profile: profile(activity),
|
|
||||||
member: title(activity)
|
|
||||||
}),
|
|
||||||
url: member_url(activity)
|
|
||||||
}
|
|
||||||
|
|
||||||
:member_updated ->
|
defp text(:member_added, args) do
|
||||||
%{
|
dgettext("activity", "%{profile} added the member %{member}.", args)
|
||||||
body:
|
end
|
||||||
dgettext("activity", "%{profile} updated the member %{member}.", %{
|
|
||||||
profile: profile(activity),
|
|
||||||
member: title(activity)
|
|
||||||
}),
|
|
||||||
url: member_url(activity)
|
|
||||||
}
|
|
||||||
|
|
||||||
:member_removed ->
|
defp text(:member_updated, args) do
|
||||||
%{
|
dgettext("activity", "%{profile} updated the member %{member}.", args)
|
||||||
body:
|
end
|
||||||
dgettext("activity", "%{profile} excluded member %{member}.", %{
|
|
||||||
profile: profile(activity),
|
|
||||||
member: title(activity)
|
|
||||||
}),
|
|
||||||
url: member_url(activity)
|
|
||||||
}
|
|
||||||
|
|
||||||
:member_quit ->
|
defp text(:member_removed, args) do
|
||||||
%{
|
dgettext("activity", "%{profile} excluded member %{member}.", args)
|
||||||
body:
|
end
|
||||||
dgettext("activity", "%{profile} quit the group.", %{
|
|
||||||
profile: profile(activity),
|
defp text(:member_quit, args) do
|
||||||
member: title(activity)
|
dgettext("activity", "%{profile} quit the group.", args)
|
||||||
}),
|
|
||||||
url: member_url(activity)
|
|
||||||
}
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
defp member_url(activity) do
|
defp member_url(activity) do
|
||||||
|
|
|
@ -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,
|
||||||
|
|
|
@ -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 ::
|
||||||
|
|
|
@ -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()
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue