From c059d4c13dc44075880bc46907d3750771cd2e0e Mon Sep 17 00:00:00 2001 From: Dan Barber Date: Sun, 9 Sep 2018 19:28:31 -0400 Subject: [PATCH] Some tidy up --- assets/js/services/channel.js | 19 ++++++++++++------- lib/chess_web/channels/game_channel.ex | 5 +++-- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/assets/js/services/channel.js b/assets/js/services/channel.js index f817db3..8119d62 100644 --- a/assets/js/services/channel.js +++ b/assets/js/services/channel.js @@ -24,7 +24,8 @@ class Channel { } join() { - this.channel.join() + this.channel + .join() .receive("error", resp => { console.log("Unable to join", resp); }); @@ -57,20 +58,24 @@ class Channel { } setOpponentStatus() { - this.store.dispatch(setOpponentStatus( - this.presences.opponentOnline(this.opponentId) ? "viewing" : "offline" - )); + this.store.dispatch( + setOpponentStatus( + this.presences.opponentOnline(this.opponentId) ? "viewing" : "offline" + ) + ); } getAvailableMoves(square) { - this.channel.push("game:get_available_moves", { square }) - .receive("ok", (data) => { + this.channel + .push("game:get_available_moves", { square }) + .receive("ok", data => { this.store.dispatch(setAvailableMoves(data.moves)); }); } sendMove(move) { - this.channel.push("game:move", move) + this.channel + .push("game:move", move) .receive("error", resp => { alert(resp.message); }); diff --git a/lib/chess_web/channels/game_channel.ex b/lib/chess_web/channels/game_channel.ex index 5eff7c2..1c5f431 100644 --- a/lib/chess_web/channels/game_channel.ex +++ b/lib/chess_web/channels/game_channel.ex @@ -90,13 +90,14 @@ defmodule ChessWeb.GameChannel do opponent(game, socket.assigns.user_id).id |> Integer.to_string + send_update(socket) + "game:#{game.id}" |> Presence.list |> case do %{^opponent_id => _} -> - send_update(socket) + nil _ -> - send_update(socket) socket |> Emails.opponent_moved_email(game) |> Mailer.deliver_later