diff --git a/backend/src/main/scala/industries/sunshine/planningpoker/RoomService.scala b/backend/src/main/scala/industries/sunshine/planningpoker/RoomService.scala index 5ce24dd..f3f7520 100644 --- a/backend/src/main/scala/industries/sunshine/planningpoker/RoomService.scala +++ b/backend/src/main/scala/industries/sunshine/planningpoker/RoomService.scala @@ -105,8 +105,8 @@ class InMemoryRoomService[F[_]: Concurrent](stateRef: Ref[F, Map[RoomID, (Room, roomID, room => room.round match { - case RoundState.Viewing(_) => room - case RoundState.Voting(votes) => room.copy(round = RoundState.Viewing(votes)) + case RoundState.Viewing(_) => room + case RoundState.Voting(votes) => room.copy(round = RoundState.Viewing(votes)) } ) override def startNewPoll(roomID: RoomID, playerID: PlayerID): F[Unit] = updateRoom( @@ -122,7 +122,11 @@ class InMemoryRoomService[F[_]: Concurrent](stateRef: Ref[F, Map[RoomID, (Room, */ override def leaveRoom(roomID: RoomID, playerID: PlayerID): F[Unit] = updateRoom( roomID, - room => room.copy(players = room.players.filterNot(_.id == playerID)) + room => + room.copy( + players = room.players.filterNot(_.id == playerID), + round = room.round.removePlayer(playerID) + ) ) override def deleteRoom(roomID: RoomID): F[Unit] = { @@ -159,7 +163,7 @@ class InMemoryRoomService[F[_]: Concurrent](stateRef: Ref[F, Map[RoomID, (Room, room.players.find(_.name == nickName) match { case Some(player) => player.id -> room case None => // player is not present, but potentially was previously - val addingPlayer = Player.create(nickPassword) + val addingPlayer = Player.create(nickName) val roomWithPlayer = room.copy(players = addingPlayer :: room.players) room.playersPasswords.get(nickName) match { case Some(_) => addingPlayer.id -> roomWithPlayer diff --git a/common/src/main/scala/industries/sunshine/planningpoker/Models.scala b/common/src/main/scala/industries/sunshine/planningpoker/Models.scala index 39dd083..3197318 100644 --- a/common/src/main/scala/industries/sunshine/planningpoker/Models.scala +++ b/common/src/main/scala/industries/sunshine/planningpoker/Models.scala @@ -83,18 +83,23 @@ object Models { // no need to send to the front end, no deed to derive codec, cool sealed trait RoundState { def toViewFor(player: PlayerID): RoundStateView + def removePlayer(id: PlayerID): RoundState } object RoundState { final case class Voting(votes: Map[PlayerID, String]) extends RoundState { - def toViewFor(playerId: PlayerID): RoundStateView.Voting = RoundStateView.Voting( + override def toViewFor(playerId: PlayerID): RoundStateView.Voting = RoundStateView.Voting( myCard = votes.get(playerId), alreadyVoted = votes.filterKeys(id => id != playerId).keys.toList ) + override def removePlayer(id: PlayerID): RoundState.Voting = + RoundState.Voting(votes.filterKeys(_ != id).toMap) } final case class Viewing(votes: Map[PlayerID, String]) extends RoundState { - def toViewFor(player: PlayerID): RoundStateView.Viewing = + override def toViewFor(player: PlayerID): RoundStateView.Viewing = RoundStateView.Viewing(votes.toList) + override def removePlayer(id: PlayerID): RoundState.Viewing = + RoundState.Viewing(votes.filterKeys(_ != id).toMap) } } }