-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Go to move which sender was looking at when message was sent in broadcasts #15570
Closed
Carbrex
wants to merge
19
commits into
lichess-org:master
from
Carbrex:broadcast-chat-game-navigate-15029
Closed
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
221cda1
Update chatCtrl to include round and game information in chat messages
Carbrex 3547b56
Merge branch 'lichess-org:master' into broadcast-chat-game-navigate-1…
Carbrex 70c82d3
remove site.analysis and move code to analyse module (#2)
Carbrex 2caefd0
remove comments
Carbrex f7155e1
Fix lint errors
Carbrex 233373e
Change function names and fix ui when report button is also visible
Carbrex 3d356b6
Merge branch 'master' into broadcast-chat-game-navigate-15029
Carbrex 4bf6e75
Fix jump not taking to correct move if move is of different chapter
Carbrex 13636b7
Merge branch 'master' into broadcast-chat-game-navigate-15029
ornicar 3e43346
move relay chat code to the relay dir
ornicar 0031e1d
fix repeatedly hardcoded relay chat separator
ornicar 4c8aced
ui/chat cannot know about relay and hardcode its separator
ornicar 02ed544
move more relay code to the relay dir
ornicar accf84c
Jump to correct move only if chapter has loaded
Carbrex 9ff3d6e
Don't add metadata if text length exceeds 140 after encoding and don'…
Carbrex d124f2b
Use studyvm to go to a given move after chapter is fetched
Carbrex cdadf9a
Merge branch 'master' into broadcast-chat-game-navigate-15029
ornicar eda345a
ui/common throttlePromise now returns a Promise for chaining
ornicar 1a77d80
pnpm lint fixes
ornicar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { BroadcastChatHandler, Line } from 'chat/src/interfaces'; | ||
import AnalyseCtrl from '../../ctrl'; | ||
import { VNode, h } from 'snabbdom'; | ||
import { bind } from 'common/snabbdom'; | ||
|
||
export function broadcastChatHandler(ctrl: AnalyseCtrl): BroadcastChatHandler { | ||
// '\ue666' was arbitrarily chosen from the unicode private use area to separate the text from the chapterId and ply | ||
const separator = '\ue666'; | ||
|
||
const encodeMsg = (text: string): string => { | ||
text = cleanMsg(text); | ||
if (ctrl.study?.relay && !ctrl.study.relay.tourShow()) { | ||
const chapterId = ctrl.study.currentChapter().id; | ||
const ply = ctrl.study.currentNode().ply; | ||
const newText = text + separator + chapterId + separator + ply; | ||
if (newText.length <= 140) { | ||
text = newText; | ||
} | ||
} | ||
return text; | ||
}; | ||
|
||
const cleanMsg = (msg: string): string => { | ||
if (msg.includes(separator) && ctrl.study?.relay) { | ||
return msg.split(separator)[0]; | ||
} | ||
return msg; | ||
}; | ||
|
||
const jumpToMove = async (msg: string) => { | ||
if (msg.includes(separator) && ctrl.study?.relay) { | ||
const segs = msg.split(separator); | ||
if (segs.length == 3) { | ||
const [, chapterId, ply] = segs; | ||
await ctrl.study.setChapter(chapterId); | ||
ctrl.jumpToMain(parseInt(ply)); | ||
} | ||
} | ||
}; | ||
|
||
const canJumpToMove = (msg: string): string | null => { | ||
if (msg.includes(separator) && ctrl.study?.relay) { | ||
const segs = msg.split(separator); | ||
if (segs.length == 3) { | ||
const [, chapterId, ply] = segs; | ||
return `${chapterId}#${ply}`; | ||
} | ||
} | ||
return null; | ||
}; | ||
|
||
const jumpButton = (line: Line): VNode | null => { | ||
const msgPly = canJumpToMove(line.t); | ||
return msgPly | ||
? h( | ||
'button.jump', | ||
{ | ||
hook: bind('click', () => jumpToMove(line.t)), | ||
attrs: { | ||
title: `Jump to move ${msgPly}`, | ||
}, | ||
}, | ||
'#', | ||
) | ||
: null; | ||
}; | ||
|
||
return { | ||
encodeMsg, | ||
cleanMsg, | ||
jumpToMove, | ||
jumpButton, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. The broadcast encoding logic must not spill over unrelated section of the code, such as this one.
isShouting
must not even assume it's working on a chat message.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is your suggested way? Do I add 128 to ascii value of each character of chapterId in
encodeMsg
and then get back the chapterId by subtracting 128? So the chapterId doesn't affect the shouting mechanism.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something like this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isShouting
should only be applied to the text that was actually typed by the user.