Skip to content

Commit

Permalink
Merge branch 'master' into move-list-button
Browse files Browse the repository at this point in the history
  • Loading branch information
johndoknjas committed Nov 10, 2024
2 parents a4aae9a + 937a618 commit caf7566
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 28 deletions.
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: 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
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,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"
}
}
2 changes: 1 addition & 1 deletion project/Dependencies.scala
Original file line number Diff line number Diff line change
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
3 changes: 2 additions & 1 deletion ui/mod/css/_mod-timeline.scss
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
padding: 0.1em 1em;
}
.mod-timeline__event__from {
white-space: nowrap;
@extend %nowrap-ellipsis;
max-width: 25em;
}
.mod-timeline__event__flair {
@extend %flex-center;
Expand Down
5 changes: 3 additions & 2 deletions ui/puzzle/src/ctrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export default class PuzzleCtrl implements ParentCtrl {
voteDisabled?: boolean;
isDaily: boolean;
blindfolded = false;
private readonly report: Report;
private report: Report;

constructor(
readonly opts: PuzzleOpts,
Expand Down Expand Up @@ -140,7 +140,7 @@ export default class PuzzleCtrl implements ParentCtrl {

this.keyboardHelp = propWithEffect(location.hash === '#keyboard', this.redraw);
keyboard(this);
this.report = new Report(this.data.puzzle.id);
this.report = new Report();

// If the page loads while being hidden (like when changing settings),
// chessground is not displayed, and the first move is not fully applied.
Expand Down Expand Up @@ -230,6 +230,7 @@ export default class PuzzleCtrl implements ParentCtrl {
this.isDaily = location.href.endsWith('/daily');
this.hintHasBeenShown(false);
this.canViewSolution(false);
this.report = new Report();

this.setPath(site.blindMode ? initialPath : treePath.init(initialPath));
setTimeout(
Expand Down
12 changes: 6 additions & 6 deletions ui/puzzle/src/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ export default class Report {
tsHideReportDialog: StoredProp<number>;

// bump when logic is changed, to distinguish cached clients from new ones
private version = 1;
private version = 2;

constructor(readonly id: PuzzleId) {
constructor() {
this.tsHideReportDialog = storedIntProp('puzzle.report.hide.ts', 0);
}

Expand Down Expand Up @@ -53,13 +53,13 @@ export default class Report {
) {
// in all case, we do not want to show the dialog more than once
this.reported = true;
const reason = `v${this.version}: after move ${node.ply}. ${node.san}, at depth ${ev.depth}, multiple solutions, pvs ${ev.pvs.map(pv => `${pv.moves[0]}: ${pv.cp}`).join(', ')}`;
this.reportDialog(reason);
const reason = `(v${this.version}) after move ${node.ply}. ${node.san}, at depth ${ev.depth}, multiple solutions, pvs ${ev.pvs.map(pv => `${pv.moves[0]}: ${pv.cp}`).join(', ')}`;
this.reportDialog(ctrl.data.puzzle.id, reason);
}
}
}

private reportDialog = (reason: string) => {
private reportDialog = (puzzleId: PuzzleId, reason: string) => {
const switchButton =
`<div class="switch switch-report-puzzle" title="temporarily disable reporting puzzles">` +
`<input id="puzzle-toggle-report" class="cmn-toggle cmn-toggle--subtle" type="checkbox">` +
Expand Down Expand Up @@ -95,7 +95,7 @@ export default class Report {
dlg.close();
});
$('.apply', dlg.view).on('click', () => {
xhr.report(this.id, reason);
xhr.report(puzzleId, reason);
dlg.close();
});
dlg.showModal();
Expand Down
19 changes: 8 additions & 11 deletions ui/site/src/sound.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { storage } from 'common/storage';
import { isIOS } from 'common/device';
import { throttle } from 'common/timing';
import { charRole } from 'chess';
import { defined } from 'common';
import { charRole } from 'chess';

type Name = string;
type Path = string;
Expand Down Expand Up @@ -139,7 +139,7 @@ export default new (class implements SoundI {
say = (text: string, cut = false, force = false, translated = false) => {
if (typeof window.speechSynthesis === 'undefined') return false;
try {
if (cut) window.speechSynthesis.cancel();
if (cut) speechSynthesis.cancel();
if (!this.speech() && !force) return false;
const msg = new SpeechSynthesisUtterance(text);
msg.volume = this.getVolume();
Expand Down Expand Up @@ -224,13 +224,10 @@ export default new (class implements SoundI {
$('#warn-no-autoplay').addClass('shown');
resolve();
}, 400);
this.ctx
?.resume()
.then(() => {
clearTimeout(resumeTimer);
resolve();
})
.catch(resolve);
this.ctx?.resume().then(() => {
clearTimeout(resumeTimer);
resolve();
});
});
if (this.ctx?.state !== 'running') return false;
$('#warn-no-autoplay').removeClass('shown');
Expand Down Expand Up @@ -272,8 +269,8 @@ class Sound {

function makeAudioContext(): AudioContext | undefined {
return window.webkitAudioContext
? new window.webkitAudioContext()
? new window.webkitAudioContext({ latencyHint: 'interactive' })
: typeof AudioContext !== 'undefined'
? new AudioContext()
? new AudioContext({ latencyHint: 'interactive' })
: undefined;
}

0 comments on commit caf7566

Please sign in to comment.