bugfix: leaving room needs to clear votes

This commit is contained in:
efim
2023-04-28 11:43:59 +04:00
parent 867b2f0f20
commit 3158a75f5d
2 changed files with 15 additions and 6 deletions

View File

@@ -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