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

Add ListMessageSplitter and apply to rules command #376

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

ShadowJonathan
Copy link
Contributor

Fixes #294

This adds a class where one could add "headers" and "items", and it'll internally split it nicely to fit inside an encrypted message, allowing enormous listings to be posted to the chat.

This also alters the rules command to use this class for this.

Copy link
Contributor

@Gnuxie Gnuxie left a comment

Choose a reason for hiding this comment

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

Thanks @ShadowJonathan , this is something we have needed for awhile.

I think some documentation about how the implementation works will go along way, as I don't think I quite understand what this is doing 😸

I think testing the public methods of MessageListing would help too, but probably not a requirement for the moment

Thanks!

src/ListMessageSplitter.ts Outdated Show resolved Hide resolved
src/ListMessageSplitter.ts Outdated Show resolved Hide resolved
src/commands/DumpRulesCommand.ts Outdated Show resolved Hide resolved
src/ListMessageSplitter.ts Outdated Show resolved Hide resolved
@Gnuxie
Copy link
Contributor

Gnuxie commented Oct 4, 2022

(A general note for maintainers) Maybe time to take a look at this adhoc string concatenation and fallback mess and instead consider using templates for the messages. I guess even duplicate templates for the text fallback is better if stripping html isn't good enough.

- added documentation
- moved sending to splitter function
@ShadowJonathan ShadowJonathan requested a review from Gnuxie October 8, 2022 08:51
src/ListMessageSplitter.ts Show resolved Hide resolved
src/ListMessageSplitter.ts Outdated Show resolved Hide resolved
// Returns:
// `sized` != null, if sized was adequate, or had to be split
// `rest` != null, if sized was not adequate (and had to be split),
// or the first item is too big to be split at the desired size.
Copy link
Contributor

Choose a reason for hiding this comment

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

How is the caller going to handle a first item that is too big to split?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The idea here is that the listings are split to be fit into a single message, if the first item is too big, it has to go into the next message.

So, "sized" (what goes into the current message still) is "null" for this, "you cannot put more of this in the currently composing message"

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, sorry, my message assumed that a listing item could be over the limit here so i was confused about how this method would handle that situation

while (current_item !== undefined) {
// Add the new item tentatively
// Add the new item to `sized` tentatively.
Copy link
Contributor

Choose a reason for hiding this comment

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

tentatively? Wouldn't it be safer/clearer to guard the push with sized.size() + current_item.size()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no, because there might be things about a listing's size that are optimised or changed as result of an item being added.

For example, if sized has no items in it, it will not emit a <ul></ul>, reducing 8 bytes of the final size. If it does have an item, it'll add that and the item.

So it is safer to try, and then back off to the last version of the listing if it becomes too big.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ohh, I see what you mean. That is quite unfortunate .

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I also don't want to duplicate logic to calculate it, as that's prone to desync if the original logic is updated.

src/ListMessageSplitter.ts Outdated Show resolved Hide resolved
src/ListMessageSplitter.ts Outdated Show resolved Hide resolved
src/ListMessageSplitter.ts Outdated Show resolved Hide resolved
@Gnuxie
Copy link
Contributor

Gnuxie commented Oct 11, 2022

Thanks for taking the time to document this in the detail you have, it's much clearer now 😸

Copy link
Contributor

@Gnuxie Gnuxie left a comment

Choose a reason for hiding this comment

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

Just some style pointers since this seems to have been written in a very rustic way 👍

Let me know if you need help, i don't mind refactoring the style for you

src/ListMessageSplitter.ts Outdated Show resolved Hide resolved
src/ListMessageSplitter.ts Outdated Show resolved Hide resolved
src/ListMessageSplitter.ts Outdated Show resolved Hide resolved
@ShadowJonathan ShadowJonathan requested a review from Gnuxie October 15, 2022 18:08
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.

Internal: Have a class/function that splits text into multiple events at max size
2 participants