Skip to content

Commit

Permalink
Fix comment sorting when sort by newest is the default (#6702)
Browse files Browse the repository at this point in the history
  • Loading branch information
absidue authored Feb 1, 2025
1 parent bfa22f4 commit be4a242
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
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

0 comments on commit be4a242

Please sign in to comment.