Skip to content

Commit

Permalink
Check for next player before sending notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
Thrillberg committed Mar 28, 2024
1 parent f54feae commit d2a3bc0
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions app/channels/game_channel.rb
Expand Up @@ -70,16 +70,20 @@ def receive(data)
next_player_name = data["data"]["nextPlayerName"]
next_player = game.users.find_by(name: next_player_name)

if !game.winner && !game.last_move&.player_notified_at && !game.cloned_from_game
if next_player &&
!game.winner &&
!game.last_move&.player_notified_at &&
!game.cloned_from_game

# Send email notification
should_send_turn_notification = next_player&.turn_notifications_enabled
should_send_turn_notification = next_player.turn_notifications_enabled
if should_send_turn_notification
TurnNotificationJob.set(wait: 1.hour)
.perform_later(next_player.id, game.id)
end
# Send Discord notification
current_player_identifier = next_player_name
current_player_discord_id = next_player&.discord_id
current_player_discord_id = next_player.discord_id
if current_player_discord_id
current_player_identifier = "<@#{current_player_discord_id}>"
end
Expand Down

0 comments on commit d2a3bc0

Please sign in to comment.