Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notifications #60

Merged
merged 14 commits into from
Mar 17, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore(Subscriptions): Minor changes on GraphQL API
  • Loading branch information
Betree committed Mar 16, 2019
commit bf456481c6e07222a747d572ee8ae877edf8d7ca
2 changes: 1 addition & 1 deletion apps/cf_graphql/lib/schema/schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ defmodule CF.Graphql.Schema do
end

@desc "Get logged in user"
field :loggedin_user, :user do
field :logged_in_user, :user do
middleware(Middleware.RequireAuthentication)
resolve(&Resolvers.Users.get_logged_in/3)
end
Expand Down
11 changes: 11 additions & 0 deletions apps/cf_graphql/lib/schema/types/subscription.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ defmodule CF.Graphql.Schema.Types.Subscription do
use Absinthe.Ecto, repo: DB.Repo

import CF.Graphql.Schema.Utils
alias DB.Type.VideoHashId

@desc "A user subscription to entities changes, used by notifications generator"
object :notifications_subscription do
Expand All @@ -27,6 +28,16 @@ defmodule CF.Graphql.Schema.Types.Subscription do
@desc "Associated video ID"
field(:video_id, :integer)

@desc "Associated video hash ID"
field(
:video_hash_id,
:string,
do:
resolve(fn a, _, _ ->
{:ok, a.video_id && VideoHashId.encode(a.video_id)}
end)
)

@desc "Associated statement ID"
field(:statement_id, :integer)

Expand Down
4 changes: 2 additions & 2 deletions apps/cf_rest_api/lib/channels/video_debate_channel.ex
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,11 @@ defmodule CF.RestApi.VideoDebateChannel do
{:reply, {:ok, %{speakers: Repo.all(speakers_query)}}, socket}
end

def handle_in_authenticated!("change_subscription", subscribe, socket) do
def handle_in_authenticated!("change_subscription", %{"subscribed" => subscribed}, socket) do
user = Guardian.Phoenix.Socket.current_resource(socket)
video = %Video{id: socket.assigns.video_id}

if subscribe do
if subscribed do
Subscriptions.subscribe(user, video)
else
Subscriptions.unsubscribe(user, video)
Expand Down