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 = { const payload = {
resource: 'channels', resource: 'channels',
id: channelId, id: channelId,
subResource: 'community' subResource: 'community',
params: {}
}
if (continuation) {
payload.params.continuation = continuation
} }
const response = await invidiousAPICall(payload) const response = await invidiousAPICall(payload)
response.comments = response.comments.map(communityPost => parseInvidiousCommunityData(communityPost)) response.comments = response.comments.map(communityPost => parseInvidiousCommunityData(communityPost))
return response.comments return { posts: response.comments, continuation: response.continuation ?? null }
} }
function parseInvidiousCommunityData(data) { function parseInvidiousCommunityData(data) {

View File

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