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

Go to move which sender was looking at when message was sent in broadcasts #15570

Closed

Conversation

Carbrex
Copy link
Member

@Carbrex Carbrex commented Jun 20, 2024

#15029
I am not sure if this is the right way to call these functions using site.analysis.study... as I don't see it any other place in the ui code.
Screencast from 20-06-24 07:35:58 PM IST.webm

Include only chapterid and ply in chat messages

Fix move not shown in title of chat msg

Remove comments

pnpm format
if (text == 'You too!' && !this.data.lines.some(l => l.u != this.data.userId)) return false;
if (text.length > 140) {
alert('Max length: 140 chars. ' + text.length + ' chars used.');
return false;
}

if (site.analysis?.study?.relay && !site.analysis.study.relay.tourShow()) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

What you have is fine.

I (personally) would not use site.analysis from chat module. Instead, I'd add a generic interface to chat/src/interfaces.ts (i.e. CustomChatHandler but with a better name), or just change ChatPlugin's existing members to optional and add two or three new bits. example:

interface ChatPlugin {
  ...
  prepareMsg?: (msg: string) => string; // embeds whatever special shit the
  // handler wants to embed right before sending a chat
  cleanMsg?: (msg: string) => string; // strips any special embedded shit
  // shit from a chat, used when rendering
  click?: (msg: string) => void; // chat module calls this with the whole
  // chat message, handler parses and navigates to chapter/ply if it can
}

Then all of this code you have here can go in relay module, except for the bits that call opts.plugin?.prepareMsg (prior to sending a chat), cleanMsg (when creating the snab vnode to render one), and click (in a click handler).

There should be a bit in relayTourView where you can create the object that implements these CustomChatHandler/ChatPlugin functions. You would pass this object to the chat module initializer via opts by way of makeChat.

But if this doesn't make sense to you, or you'd rather not do it - feel free to ignore as you've already got it working.

* remove site.analysis and move the msg logic to analyse module

* Remove comments and logs
@Carbrex Carbrex force-pushed the broadcast-chat-game-navigate-15029 branch from 9fc0e71 to f7155e1 Compare July 6, 2024 17:58
@Carbrex
Copy link
Member Author

Carbrex commented Jul 6, 2024

15570.webm

I have removed site.analysis and moved the code to analysis module. Is this correct?

if (segs.length == 3) {
const [_, chapterId, ply] = segs;
ctrl.study.setChapter(chapterId);
setTimeout(() => ctrl.jumpToMain(parseInt(ply)), 100);
Copy link
Member Author

Choose a reason for hiding this comment

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

It doesn't take to the correct move for some reason without the setTimeout.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Probably because there's network in between. The 100ms hack will not always work depending on who uses it and where from.

@Carbrex Carbrex marked this pull request as ready for review July 6, 2024 20:41
@Carbrex
Copy link
Member Author

Carbrex commented Jul 7, 2024

It doesn't work if the message is close to the maxLength(140) chars

@ornicar
Copy link
Collaborator

ornicar commented Jul 7, 2024

It also doesn't work if the ID has enough uppercase letter to trigger the shouting detection

@ornicar
Copy link
Collaborator

ornicar commented Jul 7, 2024

The new metadata (separators+ids) will also end up in the moderator tools, where they're not handled.

@Carbrex Carbrex marked this pull request as draft July 7, 2024 12:31
@Carbrex
Copy link
Member Author

Carbrex commented Jul 7, 2024

Is it ok now?

@Carbrex Carbrex marked this pull request as ready for review July 7, 2024 19:37
}
};

waitForLoadingAndJump();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry but I think this is terrible.

Instead, study.setChapter should return a promise that the caller can use.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh yes, that makes much more sense.

Comment on lines 367 to 373
if (this.vm.nextPly) {
this.ctrl.jumpToMain(this.vm.nextPly);
this.vm.nextPly = undefined;
} else {
// path could be gone (because of subtree deletion), go as far as possible
this.ctrl.userJump(this.ctrl.tree.longestValidPath(nextPath));
}
Copy link
Member Author

Choose a reason for hiding this comment

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

I tried to return promise from setChapter but that was too tough for me. What about this?

case LOWERCASE_LETTER => i - 1
case _ => i
} > 0
if text.contains('\ue666') then
Copy link
Collaborator

@ornicar ornicar Jul 10, 2024

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.

Copy link
Member Author

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

let encodedChapterId = '';
for (let i = 0; i < chapterId.length; i++) {
  encodedChapterId += String.fromCharCode(chapterId.charCodeAt(i) + 128);
}
chapterId = encodedChapterId;

Something like this?

Copy link
Collaborator

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.

@ornicar
Copy link
Collaborator

ornicar commented Jul 10, 2024

Let's face it, the whole thing is a hack, as we're stuffing metadata into a string that is supposed to contain user-typed text.
As a result every part of the code that treats the string as what it's supposed to be (user text) will be broken, and require more hacks to work around the embedded metadata.

isShouting is just the beginning, there are more, such as spam detection, garbage detection and various moderation tools, and others I don't have in mind yet.

@Carbrex
Copy link
Member Author

Carbrex commented Jul 10, 2024

Yes, I agree. Should I try to send chapterId and ply along with the user msg in site.pubsub.emit('socket.send', 'talk', text); this part and save it in the db and not encode in the actual user text?

@ornicar
Copy link
Collaborator

ornicar commented Jul 11, 2024

That will add non-trivial code to lila-ws and lila, and require a new storage format for these messages.

At the moment I don't see a simple and clean implementation for that feature. I like to keep things as simple and clean as possible, and I don't think the use case is important enough to justify the extra complexity.

It's never fun to turn down new features, and I understand that's it's frustrating to throw away work that's already done. I've done it myself many times when realizing that there are no simple solutions to the problem I'm trying to solve.

@Carbrex
Copy link
Member Author

Carbrex commented Jul 11, 2024

Ok, thanks for taking the time to review the pr and making necessary changes! It's a shame we couldn't work out a solution. But I am happy that I started understanding more ui code in the process.
Thanks again, ornicar and schlawg for your help.

@Carbrex Carbrex closed this Jul 11, 2024
@schlawg
Copy link
Collaborator

schlawg commented Jul 12, 2024

Your work is not wasted, and we can work out a solution.

Thibault is right that this deserves to be separate from the chat text, but I disagree that use cases don't support the work required to add chat metadata. The idea was we start with broadcasts and then make it work with studies more generally.

Linking study chat to board states is arguably a friendlier annotation mechanism than provided by the analysis UI itself. For example, a teacher creates a series of informative chat messages linked to various board states. Linking chat is not just about revealing what JoeBob97 was freaking out about when looking at yesterday's broadcast chat.

I'm sorry that I missed this exchange, and I'm sad to see this PR closed. I should not have recommended we fly under the radar and embed directly into the text. I hope db.msg_msg gets a general meta sub-document or something to support the linking I've described later this year. If you'd prefer not to take that on, I do expect the work you've done in this PR will be useful at that point.

@ornicar
Copy link
Collaborator

ornicar commented Jul 12, 2024

For example, a teacher creates a series of informative chat messages linked to various board states

This use case is covered by the ability to add comments to study positions, I think.

A chat line meta object is tempting, and would simplify (while adding its own complexity) existing hacks to sneak the title and status of the user into its message.

The reason things are the way they currently are, is that we have about a billion of chat messages stored in the database. It uses 53GB on each database replica. And that's with storing each line as a single string:

UserName Hello world!

with some hacks for metadata:

  private val UserLineRegex =
    """(?s)([\w-~]{2,}+)([ """ + s"$trollChar$deletedChar$patronChar$flairChar$patronFlairChar" + """])(.++)""".r

Storing lines as an object instead of a string would more than double the storage size.
Unless we keep both formats and only use objects when necessary...

@schlawg
Copy link
Collaborator

schlawg commented Jul 12, 2024

This use case is covered by the ability to add comments to study positions, I think.

It is for contributors, but comments have different discoverability being tucked away in the variations/chapters. Allowing chat as an additional navigation layer could be useful. Maybe very useful.

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.

None yet

3 participants