fixup! Add webpush front-end support
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
0853433dbd
commit
da4349e678
|
@ -25,7 +25,15 @@ defmodule Mobilizon.GraphQL.Resolvers.PushSubscription do
|
|||
def register_push_subscription(_parent, args, %{
|
||||
context: %{current_user: %User{id: user_id}}
|
||||
}) do
|
||||
Users.create_push_subscription(Map.put(args, :user_id, user_id))
|
||||
case Users.create_push_subscription(Map.put(args, :user_id, user_id)) do
|
||||
{:ok, %PushSubscription{}} ->
|
||||
{:ok, "OK"}
|
||||
|
||||
{:error, err} ->
|
||||
require Logger
|
||||
Logger.error(inspect(err))
|
||||
{:error, "Something went wrong"}
|
||||
end
|
||||
end
|
||||
|
||||
@spec unregister_push_subscription(map(), map(), map()) ::
|
||||
|
@ -36,14 +44,20 @@ defmodule Mobilizon.GraphQL.Resolvers.PushSubscription do
|
|||
with %PushSubscription{user: %User{id: push_subscription_user_id}} = push_subscription <-
|
||||
Users.get_push_subscription(push_subscription_id),
|
||||
{:user_owns_push_subscription, true} <-
|
||||
{:user_owns_push_subscription, push_subscription_user_id == user_id} do
|
||||
Users.delete_push_subscription(push_subscription)
|
||||
{:user_owns_push_subscription, push_subscription_user_id == user_id},
|
||||
{:ok, %PushSubscription{}} <- Users.delete_push_subscription(push_subscription) do
|
||||
{:ok, "OK"}
|
||||
else
|
||||
{:user_owns_push_subscription, false} ->
|
||||
{:error, :unauthorized}
|
||||
|
||||
nil ->
|
||||
{:error, :not_found}
|
||||
|
||||
{:error, err} ->
|
||||
require Logger
|
||||
Logger.error(inspect(err))
|
||||
{:error, "Something went wrong"}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -47,6 +47,7 @@ defmodule Mobilizon.GraphQL.Schema do
|
|||
import_types(Schema.ReportType)
|
||||
import_types(Schema.AdminType)
|
||||
import_types(Schema.StatisticsType)
|
||||
import_types(Schema.Users.PushSubscription)
|
||||
|
||||
@desc "A struct containing the id of the deleted object"
|
||||
object :deleted_object do
|
||||
|
@ -155,6 +156,7 @@ defmodule Mobilizon.GraphQL.Schema do
|
|||
import_fields(:resource_queries)
|
||||
import_fields(:post_queries)
|
||||
import_fields(:statistics_queries)
|
||||
# import_fields(:push_queries)
|
||||
end
|
||||
|
||||
@desc """
|
||||
|
@ -179,6 +181,7 @@ defmodule Mobilizon.GraphQL.Schema do
|
|||
import_fields(:post_mutations)
|
||||
import_fields(:actor_mutations)
|
||||
import_fields(:follower_mutations)
|
||||
import_fields(:push_mutations)
|
||||
end
|
||||
|
||||
@desc """
|
||||
|
|
|
@ -13,11 +13,21 @@ defmodule Mobilizon.GraphQL.Schema.Users.PushSubscription do
|
|||
field(:auth, non_null(:string))
|
||||
end
|
||||
|
||||
object :push_queries do
|
||||
field :list_push_subscriptions, :paginated_push_subscription_list do
|
||||
resolve(&PushSubscription.list_user_push_subscriptions/3)
|
||||
end
|
||||
end
|
||||
# object :push_subscription do
|
||||
# field(:id, :id)
|
||||
# end
|
||||
|
||||
# @desc "A paginated list of subscriptions"
|
||||
# object :paginated_push_subscription_list do
|
||||
# field(:elements, list_of(:push_subscription), description: "A list of push subscriptions")
|
||||
# field(:total, :integer, description: "The total number of push subscriptions in the list")
|
||||
# end
|
||||
|
||||
# object :push_queries do
|
||||
# field :list_push_subscriptions, :paginated_push_subscription_list do
|
||||
# resolve(&PushSubscription.list_user_push_subscriptions/3)
|
||||
# end
|
||||
# end
|
||||
|
||||
object :push_mutations do
|
||||
field :register_push, :string do
|
||||
|
|
Loading…
Reference in New Issue