Skip to content

Commit cb8939f

Browse files
committed
use Context.pref to honor anon prefs in RoundApi - closes lichess-org#14686
1 parent c01be15 commit cb8939f

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

modules/api/src/main/RoundApi.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ final private[api] class RoundApi(
4646
for
4747
initialFen <- gameRepo.initialFen(pov.game)
4848
users <- users.orLoad(userApi.gamePlayers(pov.game.userIdPair, pov.game.perfType))
49-
prefs <- prefApi.get(users.map(_.map(_.user)))
49+
prefs <- prefApi.get(users.map(_.map(_.user)), pov.color, ctx.pref)
5050
given Lang = ctx.lang
5151
(((((json, simul), swiss), note), forecast), bookmarked) <-
5252
jsonView.playerJson(pov, prefs, users, initialFen, ctxFlags) zip

modules/pref/src/main/PrefApi.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import reactivemongo.api.bson.*
66
import lila.db.dsl.{ given, * }
77
import lila.memo.CacheApi.*
88
import lila.user.User
9-
import chess.ByColor
9+
import chess.{ Color, ByColor }
1010

1111
final class PrefApi(
1212
val coll: Coll,
@@ -58,8 +58,9 @@ final class PrefApi(
5858
def byId(both: ByColor[Option[UserId]]): Fu[ByColor[Pref]] =
5959
both.traverse(_.fold(fuccess(Pref.default))(byId))
6060

61-
def get(both: ByColor[Option[User]]): Fu[ByColor[Pref]] =
62-
both.traverse(_.fold(fuccess(Pref.default))(get))
61+
def get(both: ByColor[Option[User]], myPov: Color, myPref: Pref): Fu[ByColor[Pref]] =
62+
both(!myPov).so(get) map: opponent =>
63+
myPov.fold(ByColor(myPref, opponent), ByColor(opponent, myPref))
6364

6465
def followable(userId: UserId): Fu[Boolean] =
6566
coll.primitiveOne[Boolean]($id(userId), "follow").map(_ | Pref.default.follow)

0 commit comments

Comments
 (0)