From 94f588b72ff25c41716c84c5f54c70d813247011 Mon Sep 17 00:00:00 2001 From: panevka <97028404+panevka@users.noreply.github.com> Date: Fri, 13 Dec 2024 19:05:09 +0000 Subject: [PATCH 1/3] Remove chat input from session storage to prevent game chatbox from saving it between games. --- ui/chat/src/ctrl.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ui/chat/src/ctrl.ts b/ui/chat/src/ctrl.ts index 0e568909968c9..f4ca007cc543b 100644 --- a/ui/chat/src/ctrl.ts +++ b/ui/chat/src/ctrl.ts @@ -15,7 +15,7 @@ import { type PresetCtrl, presetCtrl } from './preset'; import { noteCtrl } from './note'; import { moderationCtrl } from './moderation'; import { prop } from 'common'; -import { storage, type LichessStorage } from 'common/storage'; +import { storage, tempStorage, type LichessStorage } from 'common/storage'; import { pubsub, type PubsubEvent, type PubsubCallback } from 'common/pubsub'; import { alert } from 'common/dialog'; @@ -38,6 +38,7 @@ export default class ChatCtrl { readonly opts: ChatOpts, readonly redraw: Redraw, ) { + tempStorage.make('chat.input').remove(); this.data = opts.data; if (opts.noteId) this.allTabs.push('note'); if (opts.plugin) this.allTabs.push(opts.plugin.tab.key); From fb97a25228af395145c81c7a5f2684cd6dc2e775 Mon Sep 17 00:00:00 2001 From: panevka <97028404+panevka@users.noreply.github.com.> Date: Mon, 16 Dec 2024 23:32:43 +0000 Subject: [PATCH 2/3] fix: persist chat input only where appropriate; prevent message loss in tournaments and resolve unexpected input persistence in unrelated games --- ui/chat/src/ctrl.ts | 10 +++++++++- ui/round/src/ctrl.ts | 3 ++- ui/swiss/src/ctrl.ts | 4 +++- ui/tournament/src/ctrl.ts | 4 +++- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/ui/chat/src/ctrl.ts b/ui/chat/src/ctrl.ts index f4ca007cc543b..0643abd9b8f4c 100644 --- a/ui/chat/src/ctrl.ts +++ b/ui/chat/src/ctrl.ts @@ -38,7 +38,15 @@ export default class ChatCtrl { readonly opts: ChatOpts, readonly redraw: Redraw, ) { - tempStorage.make('chat.input').remove(); + const competitionRegex = new RegExp( + `^https:\\/\\/lichess\\.org\\/((tournament)|(swiss)|(simul))\\/${tempStorage.get('competition.id')}\\/?$`, + ); + const newGameRegex = new RegExp(`^https:\\/\\/lichess\\.org\\/(${tempStorage.get('newGame.id')})\\/?$`); + + if (!competitionRegex.test(location.href) && !newGameRegex.test(location.href)) { + tempStorage.make('chat.input').remove(); + } + this.data = opts.data; if (opts.noteId) this.allTabs.push('note'); if (opts.plugin) this.allTabs.push(opts.plugin.tab.key); diff --git a/ui/round/src/ctrl.ts b/ui/round/src/ctrl.ts index da498a0f2fe92..291ee20fdf6d6 100644 --- a/ui/round/src/ctrl.ts +++ b/ui/round/src/ctrl.ts @@ -46,7 +46,7 @@ import type { RoundTour, } from './interfaces'; import { defined, type Toggle, toggle, requestIdleCallback } from 'common'; -import { storage, once, type LichessBooleanStorage } from 'common/storage'; +import { storage, once, type LichessBooleanStorage, tempStorage } from 'common/storage'; import { pubsub } from 'common/pubsub'; import { readFen, almostSanOf, speakable } from 'chess/sanWriter'; import { plyToTurn } from 'chess'; @@ -704,6 +704,7 @@ export default class RoundController implements MoveRootCtrl { }; setLoading = (v: boolean, duration = 1500): void => { + if (this.data.game.rematch) tempStorage.make('newGame.id').set(this.data.game.rematch); clearTimeout(this.loadingTimeout); if (v) { this.loading = true; diff --git a/ui/swiss/src/ctrl.ts b/ui/swiss/src/ctrl.ts index f37c651334465..83373084707a5 100644 --- a/ui/swiss/src/ctrl.ts +++ b/ui/swiss/src/ctrl.ts @@ -3,7 +3,7 @@ import xhr from './xhr'; import { throttlePromiseDelay } from 'common/timing'; import { maxPerPage, myPage, players } from './pagination'; import type { SwissData, SwissOpts, Pages, Standing, Player } from './interfaces'; -import { storage } from 'common/storage'; +import { storage, tempStorage } from 'common/storage'; export default class SwissCtrl { data: SwissData; @@ -64,6 +64,8 @@ export default class SwissCtrl { redirectFirst = (gameId: string, rightNow?: boolean) => { const delay = rightNow || document.hasFocus() ? 10 : 1000 + Math.random() * 500; setTimeout(() => { + tempStorage.make('newGame.id').set(gameId); + tempStorage.make('competition.id').set(this.data.id); if (this.lastStorage.get() !== gameId) { this.lastStorage.set(gameId); site.redirect('/' + gameId, true); diff --git a/ui/tournament/src/ctrl.ts b/ui/tournament/src/ctrl.ts index 03e6ec7846a18..0501aac0b9111 100644 --- a/ui/tournament/src/ctrl.ts +++ b/ui/tournament/src/ctrl.ts @@ -11,7 +11,7 @@ import type { Standing, Player, } from './interfaces'; -import { storage } from 'common/storage'; +import { storage, tempStorage } from 'common/storage'; import { pubsub } from 'common/pubsub'; import { alerts, prompt } from 'common/dialog'; @@ -93,6 +93,8 @@ export default class TournamentController { const delay = rightNow || document.hasFocus() ? 10 : 1000 + Math.random() * 500; setTimeout(() => { if (this.lastStorage.get() !== gameId) { + tempStorage.make('newGame.id').set(gameId); + tempStorage.make('competition.id').set(this.data.id); this.lastStorage.set(gameId); site.redirect('/' + gameId, true); } From 4f3c26f81f95ace9500f3018513d37fed0c24fa3 Mon Sep 17 00:00:00 2001 From: panevka <97028404+panevka@users.noreply.github.com> Date: Tue, 17 Dec 2024 12:01:02 +0100 Subject: [PATCH 3/3] Remove simul from competition regex --- ui/chat/src/ctrl.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/chat/src/ctrl.ts b/ui/chat/src/ctrl.ts index 0643abd9b8f4c..aae5cc2ead9a8 100644 --- a/ui/chat/src/ctrl.ts +++ b/ui/chat/src/ctrl.ts @@ -39,7 +39,7 @@ export default class ChatCtrl { readonly redraw: Redraw, ) { const competitionRegex = new RegExp( - `^https:\\/\\/lichess\\.org\\/((tournament)|(swiss)|(simul))\\/${tempStorage.get('competition.id')}\\/?$`, + `^https:\\/\\/lichess\\.org\\/((tournament)|(swiss))\\/${tempStorage.get('competition.id')}\\/?$`, ); const newGameRegex = new RegExp(`^https:\\/\\/lichess\\.org\\/(${tempStorage.get('newGame.id')})\\/?$`);