Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add possibility to hide user's and opponent's ratings ONLY when playing #16228

Merged
merged 57 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
370c5c4
Add game behavior preference to show or hide opponent rating
yahya-lafhal Oct 12, 2024
75e144a
Add basic translation for the show opponent rating pref
yahya-lafhal Oct 12, 2024
0631267
Handle hiding/showing opponent rating in round's userHtml view
yahya-lafhal Oct 13, 2024
64ce5d9
Change the way I handled the new showRating pref to be more like keyb…
yahya-lafhal Oct 13, 2024
615a41f
Remove unnecessary occurence of showRating and enfore defaut value to…
yahya-lafhal Oct 13, 2024
7a04f3c
Add the showRating pref to the JsonView
yahya-lafhal Oct 14, 2024
1c8e040
Hide ratings in side and user mini while in game based on the new pref
yahya-lafhal Oct 14, 2024
fd3af47
Hide the user's rating too when showRating pref is set to NO
yahya-lafhal Oct 15, 2024
e9387fa
Handle showRating pref in the mini game ui
yahya-lafhal Oct 15, 2024
b94f204
Reshow the hidden ratings after game ends
yahya-lafhal Oct 15, 2024
390d559
Make ratings reapper in mini user popups after game ends
yahya-lafhal Oct 15, 2024
92da481
Rename pref and variables around it for clarity
yahya-lafhal Oct 15, 2024
d8fdb72
Format code
yahya-lafhal Oct 15, 2024
26c8be4
Merge branch 'master' into show-opponent-rating-pref
yahya-lafhal Oct 16, 2024
1d42d8d
Merge branch 'master' into show-opponent-rating-pref
yahya-lafhal Oct 16, 2024
09f1d2b
Merge branch 'master' into show-opponent-rating-pref
yahya-lafhal Oct 17, 2024
d1cc05b
Add in-game only option in existing ratings pref instead of a new pref
yahya-lafhal Oct 20, 2024
ca3a631
Fix logic to work with the changed rating pref
yahya-lafhal Oct 20, 2024
77e79c8
Remove placeholder space from user popup without rating
yahya-lafhal Oct 22, 2024
bf0175c
Remove comment
yahya-lafhal Oct 22, 2024
0763f13
Fix formatting
yahya-lafhal Oct 22, 2024
4affd61
Merge branch 'show-opponent-rating-pref' of https://github.com/yahya-…
yahya-lafhal Oct 22, 2024
511994e
Remove unnecessary translation
yahya-lafhal Oct 22, 2024
aa3c4f9
Merge branch 'master' into show-opponent-rating-pref
yahya-lafhal Oct 22, 2024
80239e8
Fix server formatting
yahya-lafhal Oct 22, 2024
7f195d1
Merge branch 'master' into show-opponent-rating-pref
yahya-lafhal Oct 22, 2024
e5e3258
retrigger checks
yahya-lafhal Oct 22, 2024
e1d86e1
Change UI text for the new show ratings option
yahya-lafhal Oct 23, 2024
8de680b
Renaming so it makes sense
yahya-lafhal Oct 23, 2024
e67f1b6
Simplify if statements with boolean logic
yahya-lafhal Oct 23, 2024
bbe24f1
Use game.playable instead of game.finishedOrAborted
yahya-lafhal Oct 23, 2024
688c7b4
Format code
yahya-lafhal Oct 23, 2024
bf2c25d
Merge branch 'master' into show-opponent-rating-pref
yahya-lafhal Oct 23, 2024
324e5c2
Merge branch 'master' into show-opponent-rating-pref
ornicar Oct 24, 2024
4030f2c
codegolf
ornicar Oct 24, 2024
8426a85
rename isUserPlaying that is not about the user being shown, but the …
ornicar Oct 24, 2024
f9bb60c
fix code duplication with Pref.showRatingsIn
ornicar Oct 24, 2024
182a277
move logic out of view into controller
ornicar Oct 24, 2024
64a6f85
remove superfluous parens
ornicar Oct 24, 2024
55f143b
remove duplicated showRatings check
ornicar Oct 24, 2024
4b1fd37
Merge branch 'master' of https://github.com/yahya-lafhal/lila into sh…
yahya-lafhal Oct 24, 2024
0088a22
Merge branch 'show-opponent-rating-pref' of https://github.com/yahya-…
yahya-lafhal Oct 24, 2024
8729296
Hide ratings in round crosstable minis
yahya-lafhal Nov 5, 2024
b1506dd
Format code
yahya-lafhal Nov 5, 2024
5087199
Merge branch 'master' into show-opponent-rating-pref
yahya-lafhal Nov 5, 2024
71b6294
Merge branch 'master' into show-opponent-rating-pref
ornicar Nov 6, 2024
e89ae12
Merge branch 'master' into show-opponent-rating-pref
yahya-lafhal Dec 15, 2024
460a0a1
Use scss logic to handle rating hiding
yahya-lafhal Dec 15, 2024
3387b14
Remove unnecessary showRating argument form GameUI mini
yahya-lafhal Dec 15, 2024
178eee1
Fix formatting
yahya-lafhal Dec 15, 2024
e41563b
Use scss for hiding the side UI rating in game
yahya-lafhal Dec 15, 2024
2e57652
Merge branch 'master' into show-opponent-rating-pref
yahya-lafhal Dec 15, 2024
d114289
Merge branch 'master' into show-opponent-rating-pref
yahya-lafhal Dec 16, 2024
6570347
Merge branch 'master' into show-opponent-rating-pref
yahya-lafhal Dec 17, 2024
6036e3c
Merge branch 'master' into show-opponent-rating-pref
yahya-lafhal Dec 17, 2024
3ae2128
Merge branch 'master' into show-opponent-rating-pref
yahya-lafhal Dec 17, 2024
5640e11
Merge branch 'master' into show-opponent-rating-pref
ornicar Dec 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions app/controllers/User.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,9 @@ final class User(
env.game.cached
.lastPlayedPlayingId(username.id)
.orElse(env.game.gameRepo.quickLastPlayedId(username.id))
.flatMap {
.flatMap:
case None => NotFound("No ongoing game")
case Some(gameId) => gameC.exportGame(gameId)
}

private def apiGames(u: UserModel, filter: String, page: Int)(using BodyContext[?]) =
userGames(u, filter, page).flatMap(env.game.userGameApi.jsPaginator).map { res =>
Expand Down Expand Up @@ -177,11 +176,12 @@ final class User(
ctx.userId.soFu(env.game.crosstableApi(user.id, _)),
ctx.isAuth.so(env.pref.api.followable(user.id))
).flatMapN: (blocked, crosstable, followable) =>
val ping = env.socket.isOnline.exec(user.id).so(env.socket.getLagRating(user.id))
negotiate(
html = (ctx.isnt(user)).so(currentlyPlaying(user.user)).flatMap { pov =>
Ok.snip(views.user.mini(user, pov, blocked, followable, relation, ping, crosstable))
.map(_.withHeaders(CACHE_CONTROL -> "max-age=5"))
html = ctx.isnt(user).so(currentlyPlaying(user.user)).flatMap { pov =>
val ping = env.socket.isOnline.exec(user.id).so(env.socket.getLagRating(user.id))
Ok.snip(
views.user.mini(user, pov, blocked, followable, relation, ping, crosstable)
).map(_.withHeaders(CACHE_CONTROL -> "max-age=5"))
},
json =
import lila.game.JsonView.given
Expand Down
2 changes: 1 addition & 1 deletion app/views/base/page.scala
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ object page:
"kid" -> ctx.kid.yes,
"mobile" -> lila.common.HTTPRequest.isMobileBrowser(ctx.req),
"playing fixed-scroll" -> p.playing,
"no-rating" -> !pref.showRatings,
"no-rating" -> (!pref.showRatings || (p.playing && pref.hideRatingsInGame)),
"no-flair" -> !pref.flairs,
"zen" -> (pref.isZen || (p.playing && pref.isZenAuto)),
"zenable" -> p.zenable,
Expand Down
7 changes: 6 additions & 1 deletion app/views/game/side.scala
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,12 @@ object side:
game.players.mapList: p =>
frag(
div(cls := s"player color-icon is ${p.color.name} text")(
playerLink(p, withOnline = false, withDiff = true, withBerserk = true)
playerLink(
p,
withOnline = false,
withDiff = true,
withBerserk = true
)
),
tour.flatMap(_.teamVs).map(_.teams(p.color)).map {
teamLink(_, withIcon = false)(cls := "team")
Expand Down
1 change: 0 additions & 1 deletion modules/api/src/main/Context.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ final class LoginContext(
val oauth: Option[TokenScopes]
):
export me.{ isDefined as isAuth, isEmpty as isAnon }
def myId: Option[MyId] = me.map(_.myId)
def user: Option[User] = Me.raw(me)
def userId: Option[UserId] = user.map(_.id)
def username: Option[UserName] = user.map(_.username)
Expand Down
4 changes: 3 additions & 1 deletion modules/core/src/main/pref.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package lila.core
package pref

import lila.core.user.User
import lila.core.userId.UserId
import lila.core.userId.{ MyId, UserId }
import lila.core.game.Game

trait Pref:
val id: UserId
Expand All @@ -22,6 +23,7 @@ trait Pref:

def hasKeyboardMove: Boolean
def hasVoice: Boolean
def hideRatingsInGame: Boolean
def showRatings: Boolean
def animationMillis: Int
def animationMillisForSpeedPuzzles: Int
Expand Down
1 change: 1 addition & 0 deletions modules/coreI18n/src/main/key.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1088,6 +1088,7 @@ object I18nKey:
val `displayBoardResizeHandle`: I18nKey = "preferences:displayBoardResizeHandle"
val `onlyOnInitialPosition`: I18nKey = "preferences:onlyOnInitialPosition"
val `inGameOnly`: I18nKey = "preferences:inGameOnly"
val `exceptInGame`: I18nKey = "preferences:exceptInGame"
val `chessClock`: I18nKey = "preferences:chessClock"
val `tenthsOfSeconds`: I18nKey = "preferences:tenthsOfSeconds"
val `whenTimeRemainingLessThanTenSeconds`: I18nKey = "preferences:whenTimeRemainingLessThanTenSeconds"
Expand Down
7 changes: 6 additions & 1 deletion modules/game/src/main/ui/GameUi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ final class GameUi(helpers: Helpers):
private val dataTimeControl = attr("data-tc")
val cgWrap = span(cls := "cg-wrap")(cgWrapContent)

def apply(pov: Pov, ownerLink: Boolean = false, tv: Boolean = false, withLink: Boolean = true)(using
def apply(
pov: Pov,
ownerLink: Boolean = false,
tv: Boolean = false,
withLink: Boolean = true
)(using
ctx: Context
): Tag =
renderMini(
Expand Down
14 changes: 12 additions & 2 deletions modules/pref/src/main/Pref.scala
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ case class Pref(
def isZen = zen == Zen.YES
def isZenAuto = zen == Zen.GAME_AUTO

val showRatings = ratings == Ratings.YES
def showRatings = ratings != Ratings.NO
def hideRatingsInGame = ratings == Ratings.EXCEPT_GAME

def is2d = !is3d

Expand Down Expand Up @@ -427,7 +428,16 @@ object Pref:
GAME_AUTO -> "In-game only"
)

object Ratings extends BooleanPref
object Ratings:
val NO = 0
val YES = 1
val EXCEPT_GAME = 2

val choices = Seq(
NO -> "No",
YES -> "Yes",
EXCEPT_GAME -> "Except in-game"
)

val darkByDefaultSince = instantOf(2021, 11, 7, 8, 0)
val systemByDefaultSince = instantOf(2022, 12, 23, 8, 0)
Expand Down
2 changes: 1 addition & 1 deletion modules/pref/src/main/PrefForm.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ object PrefForm:
val moretime = "moretime" -> checkedNumber(Pref.Moretime.choices)
val clockSound = "clockSound" -> booleanNumber
val pieceNotation = "pieceNotation" -> booleanNumber
val ratings = "ratings" -> booleanNumber
val ratings = "ratings" -> checkedNumber(Pref.Ratings.choices)
val flairs = "flairs" -> boolean
val follow = "follow" -> booleanNumber
val challenge = "challenge" -> checkedNumber(Pref.Challenge.choices)
Expand Down
2 changes: 1 addition & 1 deletion modules/pref/src/main/ui/AccountPref.scala
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ final class AccountPref(helpers: Helpers, helper: PrefHelper, bits: AccountUi):
setting(
trp.showPlayerRatings(),
frag(
radios(form("ratings"), booleanChoices),
radios(form("ratings"), translatedRatingsChoices),
div(cls := "help text shy", dataIcon := Icon.InfoCircle)(trp.explainShowPlayerRatings())
),
"showRatings"
Expand Down
7 changes: 7 additions & 0 deletions modules/pref/src/main/ui/PrefHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ trait PrefHelper:
(Pref.Zen.GAME_AUTO, trans.preferences.inGameOnly.txt())
)

def translatedRatingsChoices(using Translate) =
List(
(Pref.Ratings.NO, trans.site.no.txt()),
(Pref.Ratings.YES, trans.site.yes.txt()),
(Pref.Ratings.EXCEPT_GAME, trans.preferences.exceptInGame.txt())
)

def translatedBoardCoordinateChoices(using Translate) =
List(
(Pref.Coords.NONE, trans.site.no.txt()),
Expand Down
1 change: 1 addition & 0 deletions modules/ui/src/main/Context.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ trait Context:

def is[U: UserIdOf](u: U): Boolean = me.exists(_.is(u))
def isnt[U: UserIdOf](u: U): Boolean = !is(u)
def myId: Option[MyId] = me.map(_.myId)
def noBlind = !blind
def flash(name: String): Option[String] = req.flash.get(name)
inline def noBot = !isBot
Expand Down
2 changes: 1 addition & 1 deletion modules/ui/src/main/helper/GameHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ trait GameHelper:
user.name,
user.flair.map(userFlair),
withRating.option(
frag(
span(cls := "rating")(
" (",
player.rating.fold(frag("?")): rating =>
if player.provisional.yes then
Expand Down
1 change: 1 addition & 0 deletions translation/source/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<string name="displayBoardResizeHandle">Show board resize handle</string>
<string name="onlyOnInitialPosition">Only on initial position</string>
<string name="inGameOnly">In-game only</string>
<string name="exceptInGame">Except in-game</string>
<string name="chessClock">Chess clock</string>
<string name="tenthsOfSeconds">Tenths of seconds</string>
<string name="whenTimeRemainingLessThanTenSeconds" comment="whenTimeRemainingLessThanTenSeconds&#10;&#10;The &amp;lt; symbol is not required (you can write it as a word), just do NOT use &lt; in its place.&#10;&#10;Technical information: &lt; is a reserved character in HTML, which is why it cannot be used.">When time remaining &lt; 10 seconds</string>
Expand Down
2 changes: 2 additions & 0 deletions ui/@types/lichess/i18n.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2103,6 +2103,8 @@ interface I18n {
displayBoardResizeHandle: string;
/** Drag a piece */
dragPiece: string;
/** Except in-game */
exceptInGame: string;
/** Can be disabled during a game with the board menu */
explainCanThenBeTemporarilyDisabled: string;
/** Hold the <ctrl> key while promoting to temporarily disable auto-promotion */
Expand Down
3 changes: 3 additions & 0 deletions ui/common/css/component/_mini-game.scss
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@

margin-inline-start: 1ch;
font-size: 0.9em;
body.no-rating & {
display: none;
}
}

&__clock {
Expand Down
3 changes: 3 additions & 0 deletions ui/common/css/component/_power-tip.scss
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@
padding: 2px 3px;
text-align: left;
}
body.no-rating & {
display: none;
}
}

&__warning {
Expand Down
5 changes: 5 additions & 0 deletions ui/common/css/component/_user-link.scss
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@
content: $licon-Agent;
}
}
.rating {
body.no-rating & {
display: none;
}
}
}

a.user-link:hover {
Expand Down
3 changes: 3 additions & 0 deletions ui/round/css/_user.scss
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
margin: 0 0.25em 0 0.3em;
color: $c-font-dim;
letter-spacing: -0.5px;
body.no-rating & {
display: none;
}
}

.line {
Expand Down
Loading