IV: Allow fetching more community posts (#3466)

* Allow fetching more community posts with IV

* Update src/renderer/views/Channel/Channel.js

Co-authored-by: PikachuEXE <pikachuexe@gmail.com>

---------

Co-authored-by: PikachuEXE <pikachuexe@gmail.com>
This commit is contained in:
ChunkyProgrammer 2023-05-06 08:22:29 -04:00 committed by GitHub
parent 1c29745d98
commit c197b5ac93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 7 deletions

View File

@ -145,16 +145,21 @@ function parseInvidiousCommentData(response) {
})
}
export async function invidiousGetCommunityPosts(channelId) {
export async function invidiousGetCommunityPosts(channelId, continuation = null) {
const payload = {
resource: 'channels',
id: channelId,
subResource: 'community'
subResource: 'community',
params: {}
}
if (continuation) {
payload.params.continuation = continuation
}
const response = await invidiousAPICall(payload)
response.comments = response.comments.map(communityPost => parseInvidiousCommunityData(communityPost))
return response.comments
return { posts: response.comments, continuation: response.continuation ?? null }
}
function parseInvidiousCommunityData(data) {

View File

@ -1119,8 +1119,15 @@ export default defineComponent({
},
getCommunityPostsInvidious: function() {
invidiousGetCommunityPosts(this.id).then(posts => {
this.latestCommunityPosts = posts
const more = !isNullOrEmpty(this.communityContinuationData)
invidiousGetCommunityPosts(this.id, this.communityContinuationData).then(({ posts, continuation }) => {
if (more) {
this.latestCommunityPosts.push(...posts)
} else {
this.latestCommunityPosts = posts
}
this.communityContinuationData = continuation
}).catch(async (err) => {
console.error(err)
const errorMessage = this.$t('Invidious API Error (Click to copy)')
@ -1263,8 +1270,7 @@ export default defineComponent({
this.getCommunityPostsLocalMore()
break
case 'invidious':
// not supported by invidious yet...
// this.getCommunityPostsInvidiousMore()
this.getCommunityPostsInvidious()
break
}
break