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

[Feature] MessagePaginator: Paginator-alike Menu but for raw Messages #58

Closed
wants to merge 2 commits into from

Conversation

NotJustAnna
Copy link

It's a copy-paste-replace of Paginator but it's useful nevertheless.

It's a copy-paste-replace of Paginator but it's useful nevertheless.
Copy link
Collaborator

@Shengaero Shengaero left a comment

Choose a reason for hiding this comment

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

Interesting PR.
At the moment, the only issue I see is the documentation errors, but I can definitely see this included in the next release.


/**
* Sets the {@link java.util.function.Consumer Consumer} to perform if the
* {@link com.jagrosh.jdautilities.menu.Paginator Paginator} times out.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Documentation can be partially copied from existing menus of the same structure, however this and all other references to Paginator should be modified to respect the new entity.
IE: Paginator -> MessagePaginator

Copy link
Author

Choose a reason for hiding this comment

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

oops I forgot that one


private Message renderPage(int pageNum)
{
return messageFunction.apply(pageNum, pages);
Copy link
Collaborator

Choose a reason for hiding this comment

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

While I do think the idea is good theoretically, I feel like this should be replaced with an index ordered collection of Message instances.
My worry is that by making the provision based on a function, people will opt to generate a new Message instance on each call.
I am not opposed to this, but I'd like @jagrosh's opinion on it before we consider this functionality appropriate to merge.

Copy link
Author

@NotJustAnna NotJustAnna Feb 27, 2018

Choose a reason for hiding this comment

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

I'm basically generating 1 embed per render currently. How about both approaches?

Copy link
Author

Choose a reason for hiding this comment

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

My setup:

with(MessagePaginator.Builder()) {
    setEventWaiter(Bot.eventWaiter)
    allowTextInput(true)

    setItems(pages.size)
    setLeftRightText("previous", "next")
    setEmbedFunction { p, _ -> pages[p - 1].onHelp(event) }

    build()
}.paginate(event.channel, page)

pages is a List<HelpFactory>, a class that creates MessageEmbeds as required.

Copy link
Author

Choose a reason for hiding this comment

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

while I also agree to the Collection idea, atm you can lazy-load embeds as wanted. And let's be honest, it's just a few CPU cycles to generate vs RAM (Imagine 1000 users parsing a Wikipedia page into 20 parts each and all Message and MessageEmbeds loaded, while a lot of users just stop reading in page 4)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Theoretically you could externally load them into a collection and poll them yes.
I am only raising the concern for the sake of discussing it, as it is a design decision to make.
Also I approve of the Kotlin ❤️

Copy link
Member

Choose a reason for hiding this comment

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

Keeping the function is fine, but it would be wise to just render them once on init and store them in a list instead of calling the function every time to render

@Shengaero Shengaero added Proposal Proposal for a new feature, enhancement, or changes. Feature A new and full feature implementation. labels Feb 27, 2018
@Shengaero Shengaero changed the title MessagePaginator: Paginator-alike Menu but for raw Messages [Feature] MessagePaginator: Paginator-alike Menu but for raw Messages Apr 13, 2018
@Shengaero Shengaero added the Module: Menu Related to the "menu" module. label Apr 13, 2018
@Shengaero Shengaero added Version: 2.2 and removed Proposal Proposal for a new feature, enhancement, or changes. labels May 31, 2018
@Shengaero Shengaero added this to the Version 2.2 milestone May 31, 2018
Copy link
Member

@kantenkugel kantenkugel left a comment

Choose a reason for hiding this comment

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

Some changes that should def. be made for clarity and to remove NOP code

import java.util.function.Consumer;

/**
* A {@link com.jagrosh.jdautilities.menu.Menu Menu} implementation that paginates a set of one or more pages.
Copy link
Member

@kantenkugel kantenkugel Aug 15, 2018

Choose a reason for hiding this comment

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

Would benefit from an addition like "using a custom function for generating the Message(Embed) objects to show"


private Message renderPage(int pageNum)
{
return messageFunction.apply(pageNum, pages);
Copy link
Member

Choose a reason for hiding this comment

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

Keeping the function is fine, but it would be wise to just render them once on init and store them in a list instead of calling the function every time to render

{
private BiFunction<Integer,Integer,Message> function = (page, pages) -> null;
private Consumer<Message> finalAction = m -> m.delete().queue();
private int items = 1;
Copy link
Member

Choose a reason for hiding this comment

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

This is actually the amount of pages as confirmed by variable name and usage of the actual Menu implementation. Therefore renaming this variable would be wise to reflect that.

public MessagePaginator build()
{
Checks.check(waiter != null, "Must set an EventWaiter");
Checks.check(function != null, "Must include at least one item to paginate");
Copy link
Member

Choose a reason for hiding this comment

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

This warning is a bit off, as it checks if a function is present rather than amount of items

}

/**
* Sets the number of items that will appear on each page.
Copy link
Member

Choose a reason for hiding this comment

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

This sets the page count, and not the amount of items per page

*
* @return This builder
*/
public Builder setItems(int num)
Copy link
Member

Choose a reason for hiding this comment

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

Should be renamed to something like setPageCount(int) for more clarity

*
* @return This builder
*/
public Builder showPageNumbers(boolean show)
Copy link
Member

Choose a reason for hiding this comment

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

This is NOP and should be removed if unused

*
* @return This builder
*/
public Builder useNumberedItems(boolean number)
Copy link
Member

Choose a reason for hiding this comment

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

This is NOP and should be removed if unused

@NotJustAnna
Copy link
Author

Not gonna do any further contributions on this PR. I moved on to use another Discord library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature A new and full feature implementation. Module: Menu Related to the "menu" module.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants