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

Conversation

panevka
Copy link

@panevka panevka commented Dec 13, 2024

Fixes the issue #14602

video.mp4

@fitztrev
Copy link
Member

Hi, thanks for the PR. This change was suggested in #14635 but see the comment for why it was declined at the time.

@panevka
Copy link
Author

panevka commented Dec 14, 2024

Hi, thanks for the PR. This change was suggested in #14635 but see the comment for why it was declined at the time.

Hello, thank you for your feedback. The difference between my PR and #14635 is that solution given there would remove chat.input from session storage when the game ends (which wouldn't be okay in a situation where player and their opponent would want to chat after the game finishes), while my fix clears chat.input on new chatbox initalization instead, which I thought should be alright.

@ornicar
Copy link
Collaborator

ornicar commented Dec 14, 2024

If you delete the chat input storage on every page load, then what use is left for that storage? It seems to defeat the entire point, or I missed something.
What's the difference between this PR, and completely removing the chat.input storage?

@panevka
Copy link
Author

panevka commented Dec 14, 2024

If you delete the chat input storage on every page load, then what use is left for that storage? It seems to defeat the entire point, or I missed something.
What's the difference between this PR, and completely removing the chat.input storage?

You're right - that would achieve the same result.

I can try to fix the PR, but I'd like to understand - what's the exact purpose of chat.input in session storage? How should the end-result of using it look like?

I can guess that it should save and load chat.input between games against same users (any games or possibly rematches-only), but I'm not sure. I'd like to also know what's the expected behaviour while:

  • spectating a game
  • watching a broadcast
  • playing arena/swiss tournament
  • using a team page.

Thanks in advance.

@ornicar
Copy link
Collaborator

ornicar commented Dec 14, 2024

I don't quite remember why it was added. But I can guess it helps when you play a tournament. The page can redirect to your new game, while you're typing in the chat. With the storage, your text isn't lost, and can even post it on the game page, since it shares the tournament chat.

@panevka
Copy link
Author

panevka commented Dec 17, 2024

I fixed the PR, now it should work with desired effect.

I added 2 keys to session storage, one tracking latest competition (arena/swiss) user took part in. The other one tracks the user's game that was just initiated.


Rematch case

RematchMessageSave.mp4

Arena tournament case

ArenaMessageSave.mp4

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants