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

Account for decimals in unread chapter count #335

Merged
merged 5 commits into from Feb 22, 2024
Merged

Conversation

crxssed7
Copy link
Contributor

@crxssed7 crxssed7 commented Feb 3, 2024

Fixes #298

I was hesitating on whether I should open a PR for this as I think the behaviour is intentional (however I don't really agree with the current implementation).

I tracked it down to the markChapter method which at first seemed like it was over engineering something really simple, but I think the original dev who wrote this intended for chapters with decimal points to be consolidated as one chapter (e.g 41.1, 41.2, 41.3, 41.4 is just chapter 41). I think this is a pretty odd way of looking at it and is very confusing at first glance - it took me a second to figure out why this was implemented the way that it is. As it relies heavily on chapter numbers being present, it means that any chapter with no chapter number is completely ignored (as seen in the Moon Knight screenshot in the original issue).

Feel free to close this PR if you think the current implementation is correct.

This removes reliance on Chapter.chapterNumber (which is nullable)
@xgi
Copy link
Owner

xgi commented Feb 14, 2024

So the current logic you see is mainly for 3 reasons:

  • The chapterList passed to getNumberUnreadChapters can contain chapters from multiple languages (depending on the user's settings). This is the main reason for the "highestRead" logic -- sometimes only one language will have recent chapters, and oftentimes a chapter will be available in both languages. I think showing the user a "2" if there's one new chapter available in 2 languages is almost certainly wrong.
  • The chapterList can also contain multiple chapter objects with the same number and language (e.g. from different scanlation groups). Showing "2" in this case would probably also be unexpected.
  • Dealing with unmarked chapters. If there are chapters 1-100 available, and the user has only read the 90th, I would expect to show "10". The client makes it easy to mark previous chapters as read, but I'm not sure many people do that, especially when adding a series they started elsewhere. I think it makes sense to only consider chapters above the highest read one.

This is why I chose to work with chapterNumbers instead of chapter objects. Of course, it introduces 2 other issues:

  • Dealing with gaps. If chapter 1 is read and the only other chapter is 10, currently we would show the user "9". That's probably wrong.
  • Rounding. If chapter 40 is read and there are also 40.1, 40.2, 40.3, we currently show "1". That's probably wrong too.

I think it's worth addressing those points, but it's not trivial to consider all of these (and wouldn't be as simple as either of our implementations). Let me know if you disagree!

@crxssed7
Copy link
Contributor Author

So the current logic you see is mainly for 3 reasons:

* The `chapterList` passed to `getNumberUnreadChapters` can contain chapters from multiple languages (depending on the user's settings). This is the main reason for the "highestRead" logic -- sometimes only one language will have recent chapters, and oftentimes a chapter will be available in both languages. I think showing the user a "2" if there's one new chapter available in 2 languages is almost certainly wrong.

* The `chapterList` can also contain multiple chapter objects with the same number and language (e.g. from different scanlation groups). Showing "2" in this case would probably also be unexpected.

* Dealing with unmarked chapters. If there are chapters 1-100 available, and the user has only read the 90th, I would expect to show "10". The client makes it easy to mark previous chapters as read, but I'm not sure many people do that, especially when adding a series they started elsewhere. I think it makes sense to only consider chapters above the highest read one.

This is why I chose to work with chapterNumbers instead of chapter objects. Of course, it introduces 2 other issues:

* Dealing with gaps. If chapter 1 is read and the only other chapter is 10, currently we would show the user "9". That's probably wrong.

* Rounding. If chapter 40 is read and there are also 40.1, 40.2, 40.3, we currently show "1". That's probably wrong too.

I think it's worth addressing those points, but it's not trivial to consider all of these (and wouldn't be as simple as either of our implementations). Let me know if you disagree!

That makes a lot more sense now with context 👍🏾

I agree with all your considerations - sounds like a tricky situation whichever way you look at it. When I get a chance (most likely this weekend) I'll have a go at updating the implementation.

@crxssed7
Copy link
Contributor Author

This should be ready for a re-review. I've tried my best to follow all the considerations but with there being so many it isn't perfect. The code has also become a lot more complicated.

Trade paperback comics on ReadComicOnline will show the unread count inverted (basically the read count) which is completely wrong. This is because there are no chapter numbers present so we can't exactly sort it to get the absolute chapter number. I'm planning on opening a PR on Tiyo that'll hopefully address this.

Copy link
Owner

@xgi xgi left a comment

Choose a reason for hiding this comment

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

Left minor comments but I'm OK with merging. Thank you!

const gap = Math.ceil(chapterNumber - previousChapNumber) - 1;
if (gap > 1) {
// A gap between chapters was found. Account for this in the absolute numbers
absoluteNumber += gap;
Copy link
Owner

Choose a reason for hiding this comment

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

nit: you could avoid needing to increment both here and only set absoluteNumber after this block (since it's not used yet)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahh yes, didn't catch that

Comment on lines +65 to +68
let chapter = groupedChapters.find((chap) => chap.read);
if (chapter === undefined) {
[chapter] = groupedChapters;
}
Copy link
Owner

Choose a reason for hiding this comment

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

The [chapter] assignment here looks pretty weird, it seems to work but I don't really understand why. I think this section is equivalent to just:

let chapter = groupedChapters.find(chap => chap.read) || groupedChapters[0];

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 reason I did this was because the linter kept complaining at me, so I assumed it was because of the project level linter config 😅

In hindsight it was probably just my VSCode extension 🤷🏾

@xgi xgi merged commit 509f509 into xgi:master Feb 22, 2024
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.

Unread chapter number is incorrect (for chapters with decimals)
2 participants