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

Fix comment sorting when sort by newest is the default #6702

Merged
merged 1 commit into from
Feb 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/renderer/components/CommentSection/CommentSection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,9 @@ const nextPageToken = shallowRef(null)
// we need to react to new replies and showReplies being toggled
const commentData = ref([])
/** @type {import('youtubei.js').YT.Comments | undefined} */
let localCommentsInstance
/** @type {import('vue').ComputedRef<'local' | 'invidious'>} */
const backendPreference = computed(() => {
return store.getters.getBackendPreference
Expand Down Expand Up @@ -538,8 +541,13 @@ async function getCommentDataLocal(more = false) {
let comments
if (more) {
comments = await nextPageToken.value.getContinuation()
} else if (localCommentsInstance) {
comments = await localCommentsInstance.applySort(sortNewest.value ? 'NEWEST_FIRST' : 'TOP_COMMENTS')
localCommentsInstance = comments
} else {
comments = await getLocalComments(props.id, sortNewest.value)
comments = await getLocalComments(props.id)
sortNewest.value = comments.header?.sort_menu?.sub_menu_items?.[1].selected ?? false
localCommentsInstance = comments
}
const parsedComments = comments.contents
Expand Down Expand Up @@ -575,6 +583,7 @@ async function getCommentDataLocal(more = false) {
nextPageToken.value = null
isLoading.value = false
showComments.value = true
localCommentsInstance = undefined
return
}
// endregion No comment detection
Expand All @@ -585,6 +594,7 @@ async function getCommentDataLocal(more = false) {
copyToClipboard(err)
})
if (backendFallback.value && backendPreference.value === 'local') {
localCommentsInstance = undefined
showToast(t('Falling back to Invidious API'))
getCommentDataInvidious()
} else {
Expand Down
5 changes: 2 additions & 3 deletions src/renderer/helpers/api/local.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,11 +291,10 @@ export async function getLocalVideoInfo(id) {

/**
* @param {string} id
* @param {boolean | undefined} sortByNewest
*/
export async function getLocalComments(id, sortByNewest = false) {
export async function getLocalComments(id) {
const innertube = await createInnertube()
return innertube.getComments(id, sortByNewest ? 'NEWEST_FIRST' : 'TOP_COMMENTS')
return innertube.getComments(id)
}

// I know `type & type` is typescript syntax and not valid jsdoc but I couldn't get @extends or @augments to work
Expand Down