Fix comment sorting when sort by newest is the default #6702
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.
Fix comment sorting when sort by newest is the default
Pull Request Type
Related issue
Description
On some videos the default sorting value is Newest First, at the moment we are unable to switch back to Top Comments on those videos. This pull request fixes that by matching YouTube's default sorting for each video and then using their provided parameter values for the sorting changes.
Thanks to @LuanRT for suggesting this fix.
Technical details on the problem:
The internal value for sorting by top comments is
0
, however due to the way that protobuf v3 works, when YouTube.js generates the protobuf with that value, the protobuf encoder drops the sorting field as0
is considered the default value. This isn't a problem on videos where the default sorting is top comments because then we can do default (top comments) and newest first (explicitly requested with the value1
), but when the default is newest first, our choices are default (newest first) and newest first (explicitly requested with the value1
.Testing
Video with sort by Top Comments as the default: https://youtu.be/jNQXAC9IVRw
Video with sort by Newest First as the default: https://youtu.be/fn3KWM1kuAw
Desktop