Skip to content

Commit

Permalink
Merge branch 'master' of github.com:lichess-org/lila
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Feb 13, 2025
2 parents 07050b4 + ab533e4 commit 11b4420
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 34 deletions.
5 changes: 2 additions & 3 deletions app/UiEnv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ object UiEnv
def setEnv(e: Env) = envVar = Some(e)
def env: Env = envVar.get

def netConfig = env.net
def contactEmailInClear = env.net.email.value
def picfitUrl = env.memo.picfitUrl
def netConfig = env.net
def picfitUrl = env.memo.picfitUrl

given lila.core.config.NetDomain = env.net.domain
given (using ctx: PageContext): Option[Nonce] = ctx.nonce
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ lazy val root = Project("lila", file("."))
.dependsOn(api)
.aggregate(api)
.settings(buildSettings)
.settings(scalacOptions ++= Seq("-unchecked", "-deprecation"))

organization := "org.lichess"
Compile / run / fork := true
javaOptions ++= Seq("-Xms64m", "-Xmx512m", "-Dlogger.file=conf/logger.dev.xml")
ThisBuild / scalacOptions ++= Seq("-unchecked", "-deprecation")
ThisBuild / usePipelining := false
// shorter prod classpath
scriptClasspath := Seq("*")
Expand Down
2 changes: 1 addition & 1 deletion modules/analyse/src/main/Analyser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ final class Analyser(
analysis.id match
case Analysis.Id.Game(id) =>
gameRepo.game(id).flatMapz { prev =>
val game = prev.focus(_.metadata.analysed).set(true)
val game = prev.focus(_.metadata.analysed).replace(true)
for
_ <- gameRepo.setAnalysed(game.id, true)
_ <- analysisRepo.save(analysis)
Expand Down
2 changes: 1 addition & 1 deletion modules/fide/src/main/FidePlayerSync.scala
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ final private class FidePlayerSync(repo: FideRepo, ws: StandaloneWSClient)(using
nbAll <- repo.player.countAll
yield
lila.mon.fideSync.updated.update(nbUpdated)
lila.mon.fideSync.players.update(nbAll)
lila.mon.fideSync.players.update(nbAll.toDouble)
logger.info(s"RelayFidePlayerApi.update upserted: $nbUpdated, total: $nbAll")
yield ()

Expand Down
2 changes: 1 addition & 1 deletion modules/fishnet/src/test/TreeBuilderTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ object TreeBuilderTest:
def cleanup: NewBranch =
node
.focus(_.metas.clock)
.set(none)
.replace(none)
.focus(_.metas.comments)
.modify(_.cleanup)

Expand Down
20 changes: 15 additions & 5 deletions modules/relay/src/main/HttpClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,21 @@ private final class HttpClient(
CanProxy
): Fu[(Option[Body], Option[Etag])] =
val req = etag.foldLeft(toRequest(url))((req, etag) => req.addHttpHeaders("If-None-Match" -> etag))
fetchResponse(req).map: res =>
val newEtag = extractEtagValue(res)
if res.status == 304
then none -> newEtag.orElse(etag)
else decodeResponseBody(res).some -> newEtag
fetchResponse(req)
.map: res =>
val newEtag = extractEtagValue(res)
if res.status == 304
then none -> newEtag.orElse(etag)
else decodeResponseBody(res).some -> newEtag
.recoverWith:
case Status(400, _) if etag.isDefined =>
val prevEtag = etag.get // terrible, I wish it could be extracted from the match above
fetchBodyAndEtag(url, none)
.addEffects: res =>
val success = if res.isSuccess then "succeeded" else "failed"
logger.info(s"Retrying $url without etag $prevEtag -> $success")
.map: (body, etag) =>
(body, etag.filter(_ != prevEtag))

// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/ETag#w
private def extractEtagValue(res: StandaloneWSResponse): Option[Etag] =
Expand Down
2 changes: 1 addition & 1 deletion modules/relay/src/main/ui/RelayTourUi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ final class RelayTourUi(helpers: Helpers, ui: RelayUi):
lila.ui.bits.mselect(
s"relay-calendar__month--$id",
span(showMonth(at.getMonth)),
java.time.Month.values.map: m =>
java.time.Month.values.toIndexedSeq.map: m =>
a(
cls := (m == at.getMonth).option("current"),
href := url(at.getYear, m)
Expand Down
2 changes: 1 addition & 1 deletion modules/study/src/test/Helpers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ object Helpers:
def cleanup: NewBranch =
node
.focus(_.metas.clock)
.set(none)
.replace(none)
.focus(_.metas.comments)
.modify(_.cleanup)

Expand Down
7 changes: 6 additions & 1 deletion ui/analyse/src/keyboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ export const bind = (ctrl: AnalyseCtrl) => {
let shiftAlone = 0;
document.addEventListener('keydown', e => e.key === 'Shift' && (shiftAlone = e.location));
document.addEventListener('keyup', e => {
if (e.key === 'Shift' && e.location === shiftAlone) {
if (
e.key === 'Shift' &&
e.location === shiftAlone &&
!document.activeElement?.classList.contains('mchat__say')
) {
// hilities confound ddugovic when he fails to capitalize a letter in chat
if (shiftAlone === 1 && ctrl.fork.prev()) ctrl.setAutoShapes();
else if (shiftAlone === 2 && ctrl.fork.next()) ctrl.setAutoShapes();
else if (shiftAlone === 0) return;
Expand Down
12 changes: 10 additions & 2 deletions ui/analyse/src/study/chapterNewForm.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { parseFen } from 'chessops/fen';
import { defined, prop, type Prop, toggle } from 'common';
import { snabDialog, alert } from 'common/dialog';
import { type Dialog, snabDialog, alert } from 'common/dialog';
import * as licon from 'common/licon';
import { bind, bindSubmit, onInsert, looseH as h, dataIcon, type VNode } from 'common/snabbdom';
import { storedProp } from 'common/storage';
Expand Down Expand Up @@ -29,7 +29,10 @@ export const fieldValue = (e: Event, id: string) =>
export class StudyChapterNewForm {
readonly multiPgnMax = 64;
variants: Variant[] = [];
isOpen = toggle(false);
dialog: Dialog | undefined;
isOpen = toggle(false, val => {
if (!val) this.dialog?.close();
});
initial = toggle(false);
tab = storedProp<ChapterTab>(
'analyse.study.form.tab',
Expand Down Expand Up @@ -142,11 +145,16 @@ export function view(ctrl: StudyChapterNewForm): VNode {
return snabDialog({
class: 'chapter-new',
onClose() {
ctrl.dialog = undefined;
ctrl.isOpen(false);
ctrl.redraw();
},
modal: true,
noClickAway: true,
onInsert: dlg => {
ctrl.dialog = dlg;
dlg.show();
},
vnodes: [
activeTab !== 'edit' &&
h('h2', [
Expand Down
38 changes: 22 additions & 16 deletions ui/common/src/dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,10 @@ class DialogWrapper implements Dialog {
view.parentElement?.style.setProperty('---viewport-height', `${window.innerHeight}px`);
this.dialogEvents.addListener(view, 'click', e => e.stopPropagation());

this.dialogEvents.addListener(dialog, 'cancel', () => !this.returnValue && (this.returnValue = 'cancel'));
this.dialogEvents.addListener(dialog, 'cancel', e => {
if (o.noClickAway && o.noCloseButton && o.class !== 'alert') return e.preventDefault();
if (!this.returnValue) this.returnValue = 'cancel';
});
this.dialogEvents.addListener(dialog, 'close', this.onRemove);
if (!o.noCloseButton)
this.dialogEvents.addListener(
Expand All @@ -276,7 +279,7 @@ class DialogWrapper implements Dialog {
else where.appendChild(app.node);
}
this.updateActions();
this.dialogEvents.addListener(this.dialog, 'keydown', onKeydown);
this.dialogEvents.addListener(this.dialog, 'keydown', this.onKeydown);
}

get open(): boolean {
Expand Down Expand Up @@ -322,6 +325,23 @@ class DialogWrapper implements Dialog {
}
};

private onKeydown = (e: KeyboardEvent) => {
if (e.key === 'Escape' && !(this.o.noCloseButton && this.o.noClickAway)) {
this.close('cancel');
e.preventDefault();
} else if (e.key === 'Tab') {
const $focii = $(focusQuery, e.currentTarget as Element),
first = $as<HTMLElement>($focii.first()),
last = $as<HTMLElement>($focii.last()),
focus = document.activeElement as HTMLElement;
if (focus === last && !e.shiftKey) first.focus();
else if (focus === first && e.shiftKey) last.focus();
else return;
e.preventDefault();
}
e.stopPropagation();
};

private autoFocus() {
const focus =
(this.o.focus ? this.view.querySelector(this.o.focus) : this.view.querySelector('input[autofocus]')) ??
Expand Down Expand Up @@ -365,20 +385,6 @@ function escapeHtmlAddBreaks(s: string) {
return escapeHtml(s).replace(/\n/g, '<br>');
}

function onKeydown(e: KeyboardEvent) {
if (e.key === 'Tab') {
const $focii = $(focusQuery, e.currentTarget as Element),
first = $as<HTMLElement>($focii.first()),
last = $as<HTMLElement>($focii.last()),
focus = document.activeElement as HTMLElement;
if (focus === last && !e.shiftKey) first.focus();
else if (focus === first && e.shiftKey) last.focus();
else return;
e.preventDefault();
}
e.stopPropagation();
}

function onResize() {
// ios safari vh behavior workaround
$('dialog > div.scrollable').css('---viewport-height', `${window.innerHeight}px`);
Expand Down
2 changes: 1 addition & 1 deletion ui/site/src/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const url = (path: string, opts: AssetUrlOpts = {}) => {

function asHashed(path: string, hash: string) {
const name = path.slice(path.lastIndexOf('/') + 1);
const extPos = name.indexOf('.');
const extPos = name.lastIndexOf('.');
return `hashed/${extPos < 0 ? `${name}.${hash}` : `${name.slice(0, extPos)}.${hash}${name.slice(extPos)}`}`;
}

Expand Down

0 comments on commit 11b4420

Please sign in to comment.