Skip to content

Commit

Permalink
Merge master and fix conflict.
Browse files Browse the repository at this point in the history
  • Loading branch information
johndoknjas committed Nov 11, 2024
2 parents ea7fd74 + 7a98452 commit ce313f1
Show file tree
Hide file tree
Showing 472 changed files with 2,027 additions and 2,025 deletions.
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
!/ui/**
dist/
readme
/ui/.build/pnpm-lock.yaml
pnpm-lock.yaml
/ui/voice/@build/crowdv/*.json
3 changes: 1 addition & 2 deletions app/controllers/ForumController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ private[controllers] trait ForumController:
if granted | isGranted(_.ModerateForum)
then a
else
getTopic.flatMap { topic =>
getTopic.flatMap: topic =>
if topic.exists(_.isUblogAuthor(me)) then a
else Forbidden("You cannot moderate this forum")
}
}
12 changes: 5 additions & 7 deletions app/http/KeyPages.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ final class KeyPages(val env: Env)(using Executor)
extends lila.web.ResponseWriter
with RequestContext
with CtrlPage
with lila.web.CtrlErrors
with ControllerHelpers:

def home(status: Results.Status)(using ctx: Context): Fu[Result] =
homeHtml
.map: html =>
env.security.lilaCookie.ensure(ctx.req)(status(html))
homeHtml.map: html =>
env.security.lilaCookie.ensure(ctx.req)(status(html))

def homeHtml(using ctx: Context): Fu[lila.ui.RenderedPage] =
env
Expand Down Expand Up @@ -45,8 +45,6 @@ final class KeyPages(val env: Env)(using Executor)
NotFound.snip(views.base.notFoundEmbed(msg))

def blacklisted(using ctx: Context): Result =
if lila.security.Mobile.Api.requested(ctx.req) then
Results.Unauthorized:
Json.obj:
"error" -> views.site.message.blacklistedMessage
if lila.security.Mobile.Api.requested(ctx.req)
then Unauthorized(jsonError(views.site.message.blacklistedMessage))
else Unauthorized(views.site.message.blacklistedSnippet)
8 changes: 4 additions & 4 deletions app/http/ResponseBuilder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ trait ResponseBuilder(using Executor)
then json.dmap(_.withHeaders(VARY -> "Accept").as(JSON))
else html.dmap(_.withHeaders(VARY -> "Accept"))

def negotiateJson(result: => Fu[Result])(using Context) =
def negotiateJson(result: => Fu[Result])(using Context): Fu[Result] =
negotiate(
notFound("This endpoint only returns JSON, add the header `Accept: application/json`".some),
result
Expand Down Expand Up @@ -120,17 +120,17 @@ trait ResponseBuilder(using Executor)
InternalServerError(jsonError(msg))
)

def notForBotAccounts(using Context) = negotiate(
def notForBotAccounts(using Context): Fu[Result] = negotiate(
Forbidden.page(views.site.message.noBot),
forbiddenJson("This API endpoint is not for Bot accounts.")
)

def notForLameAccounts(using Context, Me) = negotiate(
def notForLameAccounts(using Context, Me): Fu[Result] = negotiate(
Forbidden.page(views.site.message.noLame),
forbiddenJson("The access to this resource is restricted.")
)

def playbanJsonError(ban: lila.playban.TempBan) =
def playbanJsonError(ban: lila.playban.TempBan): Result =
Forbidden(
jsonError(
s"Banned from playing for ${ban.remainingMinutes} minutes. Reason: Too many aborts, unplayed games, or rage quits."
Expand Down
9 changes: 8 additions & 1 deletion modules/api/src/main/ui/ModTimelineUi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,14 @@ final class ModTimelineUi(helpers: Helpers)(
strong(
cls := "mod-timeline__event__from",
title := r.atoms.toList.map(_.by.id).map(usernameOrId).map(_.toString).mkString(", ")
)(fragList(reporters))
)(
if r.atoms.size > 3
then pluralize("player", r.atoms.size)
else
fragList:
r.atoms.toList.map: atom =>
userIdLink(atom.by.some, withOnline = false)
)
,
div(cls := "mod-timeline__event__action")(
" opened a ",
Expand Down
2 changes: 2 additions & 0 deletions modules/common/src/test/FormTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ class FormTest extends munit.FunSuite:
assertEquals(single("t" -> cleanTextWithSymbols).bind(Map("t" -> s" $invisibleStr ")), Right(""))
assert(single("t" -> cleanText(minLength = 1)).bind(Map("t" -> invisibleStr)).isLeft)
assert(single("t" -> cleanText(minLength = 1)).bind(Map("t" -> s" $invisibleStr ")).isLeft)
// braille space
assert(single("t" -> cleanText(minLength = 1)).bind(Map("t" -> "")).isLeft)
}
test("other garbage chars are also removed before validation, unless allowed") {
val garbageStr = "꧁ ۩۞"
Expand Down
2 changes: 1 addition & 1 deletion modules/core/src/main/user.scala
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ object user:
perf: PerfKey,
useCache: Boolean = true
): Fu[Option[ByColor[WithPerf]]]
def glicko(userId: UserId, perf: PerfKey): Fu[Glicko]
def glicko(userId: UserId, perf: PerfKey): Fu[Option[Glicko]]
def containsDisabled(userIds: Iterable[UserId]): Fu[Boolean]
def containsEngine(userIds: List[UserId]): Fu[Boolean]
def usingPerfOf[A, U: UserIdOf](u: U, perfKey: PerfKey)(f: Perf ?=> Fu[A]): Fu[A]
Expand Down
8 changes: 5 additions & 3 deletions modules/lobby/src/main/LobbySocket.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import lila.core.game.ChangeFeatured
import lila.core.pool.PoolConfigId
import lila.core.socket.{ protocol as P, * }
import lila.core.timeline.*
import lila.rating.RatingRange
import lila.rating.{ Glicko, RatingRange }

case class LobbyCounters(members: Int, rounds: Int)

Expand Down Expand Up @@ -193,12 +193,14 @@ final class LobbySocket(
yield
lobby ! CancelHook(member.sri) // in case there's one...
userApi.glicko(user.id, perfType).foreach { glicko =>
val pairingGlicko = glicko | Glicko.pairingDefault
poolApi.join(
PoolConfigId(id),
lila.core.pool.Joiner(
sri = member.sri,
rating = glicko.establishedIntRating | IntRating(
scalalib.Maths.boxedNormalDistribution(glicko.intRating.value, glicko.intDeviation, 0.3)
rating = pairingGlicko.establishedIntRating | IntRating(
scalalib.Maths
.boxedNormalDistribution(pairingGlicko.intRating.value, pairingGlicko.intDeviation, 0.3)
),
ratingRange = ratingRange,
lame = user.lame,
Expand Down
6 changes: 6 additions & 0 deletions modules/mod/src/main/ui/ModInquiryUi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ final class ModInquiryUi(helpers: Helpers):
),
div(cls := "submission")(
submitButton(cls := "button thin", name := "noteType", value := "mod")("SEND"),
button(
cls := "button thin",
name := "noteType",
value := "copy-url",
title := "copy current URL to note"
)("ADD URL"),
Granter
.opt(_.Admin)
.option(
Expand Down
2 changes: 1 addition & 1 deletion modules/msg/src/main/Msg.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ object Msg:
def unreadBy(userId: UserId) = !read && user != userId

def make(text: String, user: UserId, date: Instant): Option[Msg] =
val cleanText = lila.common.String.normalize(text.trim.take(8_000))
val cleanText = lila.common.String.softCleanUp(text.take(8_000))
cleanText.nonEmpty.option(
Msg(
text = cleanText,
Expand Down
8 changes: 6 additions & 2 deletions modules/playban/src/main/PlaybanApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import lila.core.game.Source
import lila.core.msg.MsgApi
import lila.core.playban.RageSit as RageSitCounter
import lila.db.dsl.{ *, given }
import scalalib.cache.OnceEvery

final class PlaybanApi(
coll: Coll,
Expand Down Expand Up @@ -116,7 +117,7 @@ final class PlaybanApi(
if game.casual && blameableSource(game) && isQuickResign(game, status)
then winner.map(game.opponent).flatMap(_.userId).so(handleQuickResign(game, _))
else
IfBlameable(game) {
IfBlameable(game):
~(for
w <- winner
loser = game.opponent(w)
Expand All @@ -142,12 +143,15 @@ final class PlaybanApi(
.getOrElse:
good(game, status, !w)
)
}

private val quickResignCasualOnce = OnceEvery[UserId](1.day)

private def isQuickResign(game: Game, status: Status) =
status.is(_.Resign) && game.hasFewerMovesThanExpected && {
val veryQuick = (game.clock.fold(600)(_.estimateTotalSeconds / 3)).atMost(60)
game.durationSeconds.exists(_ < veryQuick)
} && {
game.mode.rated || game.loserUserId.exists(loser => !quickResignCasualOnce(loser))
}

private def handleQuickResign(game: Game, userId: UserId): Funit =
Expand Down
4 changes: 4 additions & 0 deletions modules/rating/src/main/Glicko.scala
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ object Glicko:

val default = new Glicko(1500d, maxDeviation, defaultVolatility)

// Virtual rating for first pairing to make the expected score 50% without
// actually changing the default rating
val pairingDefault = new Glicko(1460d, maxDeviation, defaultVolatility)

// managed is for students invited to a class
val defaultManaged = new Glicko(800d, 400d, defaultVolatility)
val defaultManagedPuzzle = new Glicko(800d, 400d, defaultVolatility)
Expand Down
4 changes: 2 additions & 2 deletions modules/user/src/main/UserPerfsRepo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ final class UserPerfsRepo(c: Coll)(using Executor) extends lila.core.user.PerfsR
def setPerf(userId: UserId, pk: PerfKey, perf: Perf): Funit =
coll.update.one($id(userId), $set(pk.value -> perf), upsert = true).void

def glicko(userId: UserId, perf: PerfKey): Fu[Glicko] =
def glicko(userId: UserId, perf: PerfKey): Fu[Option[Glicko]] =
coll
.find($id(userId), $doc(s"$perf.gl" -> true).some)
.one[Bdoc]
.dmap:
_.flatMap(_.child(perf.value))
.flatMap(_.getAsOpt[Glicko]("gl")) | lila.rating.Glicko.default
.flatMap(_.getAsOpt[Glicko]("gl"))

def addPuzRun(field: String, userId: UserId, score: Int): Funit =
coll.update
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"@typescript-eslint/parser": "^8.13.0",
"ab": "github:lichess-org/ab-stub",
"chessground": "^9.1.1",
"chessops": "^0.14.2",
"eslint": "^9.14.0",
"lint-staged": "^15.2.10",
"onchange": "^7.1.0",
Expand All @@ -54,6 +55,7 @@
"serverlog": "pnpm journal & pnpm metals",
"piece-css": "pnpx tsx bin/gen/piece-css.ts",
"trans-dump": "pnpx tsx bin/trans-dump.ts",
"test": "cd ui/ && pnpm test",
"multilog": "pnpm serverlog & ui/build -w"
}
}
48 changes: 7 additions & 41 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ object Dependencies {
}

object scalalib {
val version = "11.3.1"
val version = "11.3.2"
val core = "org.lichess" %% "scalalib-core" % version
val model = "org.lichess" %% "scalalib-model" % version
val playJson = "org.lichess" %% "scalalib-play-json" % version
Expand Down Expand Up @@ -79,7 +79,7 @@ object Dependencies {
object reactivemongo {
val driver = "org.reactivemongo" %% "reactivemongo" % "1.1.0-RC13"
val stream = "org.reactivemongo" %% "reactivemongo-akkastream" % "1.1.0-RC14"
val shaded = "org.reactivemongo" % s"reactivemongo-shaded-native-$os-$dashArch" % "1.1.0-RC13"
val shaded = "org.reactivemongo" % s"reactivemongo-shaded-native-$os-$dashArch" % "1.1.0-RC14"
// val kamon = "org.reactivemongo" %% "reactivemongo-kamon" % "1.0.8"
def bundle = Seq(driver, stream)
}
Expand Down
Loading

0 comments on commit ce313f1

Please sign in to comment.