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

Remove chat input from session storage to prevent passing it into messagebox in another game #16587

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 10 additions & 1 deletion ui/chat/src/ctrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -38,6 +38,15 @@ export default class ChatCtrl {
readonly opts: ChatOpts,
readonly redraw: Redraw,
) {
const competitionRegex = new RegExp(
`^https:\\/\\/lichess\\.org\\/((tournament)|(swiss))\\/${tempStorage.get('competition.id')}\\/?$`,
);
const newGameRegex = new RegExp(`^https:\\/\\/lichess\\.org\\/(${tempStorage.get('newGame.id')})\\/?$`);
Copy link
Collaborator

@ornicar ornicar Dec 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ui/chat should know about chatting. It should not know about:

  • lichess.org
  • https
  • tournaments and swiss
  • URL formats for competitions and games
  • location.href

And it should not assume that other parts of the site will write to competition.id and newGame.id.

If this change requires adding that kind of hacks, then I say it's not worth it.


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);
Expand Down
3 changes: 2 additions & 1 deletion ui/round/src/ctrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion ui/swiss/src/ctrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion ui/tournament/src/ctrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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);
}
Expand Down
Loading