1
0
mirror of https://github.com/danbee/chess synced 2025-03-04 08:39:06 +00:00

Some tidy up

This commit is contained in:
Daniel Barber 2018-09-09 19:28:31 -04:00
parent ae3ecefcf7
commit c059d4c13d
Signed by: danbarber
GPG Key ID: 931D8112E0103DD8
2 changed files with 15 additions and 9 deletions

View File

@ -24,7 +24,8 @@ class Channel {
} }
join() { join() {
this.channel.join() this.channel
.join()
.receive("error", resp => { .receive("error", resp => {
console.log("Unable to join", resp); console.log("Unable to join", resp);
}); });
@ -57,20 +58,24 @@ class Channel {
} }
setOpponentStatus() { setOpponentStatus() {
this.store.dispatch(setOpponentStatus( this.store.dispatch(
this.presences.opponentOnline(this.opponentId) ? "viewing" : "offline" setOpponentStatus(
)); this.presences.opponentOnline(this.opponentId) ? "viewing" : "offline"
)
);
} }
getAvailableMoves(square) { getAvailableMoves(square) {
this.channel.push("game:get_available_moves", { square }) this.channel
.receive("ok", (data) => { .push("game:get_available_moves", { square })
.receive("ok", data => {
this.store.dispatch(setAvailableMoves(data.moves)); this.store.dispatch(setAvailableMoves(data.moves));
}); });
} }
sendMove(move) { sendMove(move) {
this.channel.push("game:move", move) this.channel
.push("game:move", move)
.receive("error", resp => { .receive("error", resp => {
alert(resp.message); alert(resp.message);
}); });

View File

@ -90,13 +90,14 @@ defmodule ChessWeb.GameChannel do
opponent(game, socket.assigns.user_id).id opponent(game, socket.assigns.user_id).id
|> Integer.to_string |> Integer.to_string
send_update(socket)
"game:#{game.id}" "game:#{game.id}"
|> Presence.list |> Presence.list
|> case do |> case do
%{^opponent_id => _} -> %{^opponent_id => _} ->
send_update(socket) nil
_ -> _ ->
send_update(socket)
socket socket
|> Emails.opponent_moved_email(game) |> Emails.opponent_moved_email(game)
|> Mailer.deliver_later |> Mailer.deliver_later