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

Update subscription details from search results #5795

Merged
merged 1 commit into from
Oct 5, 2024
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
5 changes: 1 addition & 4 deletions src/renderer/views/Channel/Channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,7 @@ export default defineComponent({
},

isSubscribedInAnyProfile: function () {
const profileList = this.$store.getters.getProfileList

// check the all channels profile
return profileList[0].subscriptions.some((channel) => channel.id === this.id)
return this.$store.getters.getSubscribedChannelIdSet.has(this.id)
},

videoLiveShortSelectValues: function () {
Expand Down
42 changes: 42 additions & 0 deletions src/renderer/views/Search/Search.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ export default defineComponent({
}

this.$store.commit('addToSessionSearchHistory', historyPayload)

this.updateSubscriptionDetails(results)
} catch (err) {
console.error(err)
const errorMessage = this.$t('Local API Error (Click to copy)')
Expand Down Expand Up @@ -194,6 +196,8 @@ export default defineComponent({
}

this.$store.commit('addToSessionSearchHistory', historyPayload)

this.updateSubscriptionDetails(results)
} catch (err) {
console.error(err)
const errorMessage = this.$t('Local API Error (Click to copy)')
Expand Down Expand Up @@ -263,6 +267,8 @@ export default defineComponent({
}

this.$store.commit('addToSessionSearchHistory', historyPayload)

this.updateSubscriptionDetails(returnData)
}).catch((err) => {
console.error(err)
const errorMessage = this.$t('Invidious API Error (Click to copy)')
Expand Down Expand Up @@ -318,6 +324,42 @@ export default defineComponent({

// This is kept in case there is some race condition
this.isLoading = false
},

/**
* @param {any[]} results
*/
updateSubscriptionDetails: function (results) {
/** @type {Set<string>} */
const subscribedChannelIds = this.$store.getters.getSubscribedChannelIdSet

const channels = []

for (const result of results) {
if (result.type !== 'channel' || !subscribedChannelIds.has(result.id ?? result.authorId)) {
continue
}

if (result.dataSource === 'local') {
channels.push({
channelId: result.id,
channelName: result.name,
channelThumbnailUrl: result.thumbnail.replace(/^\/\//, 'https://')
})
} else {
channels.push({
channelId: result.authorId,
channelName: result.author,
channelThumbnailUrl: result.authorThumbnails[0].url.replace(/^\/\//, 'https://')
})
}
}

if (channels.length === 1) {
this.$store.dispatch('updateSubscriptionDetails', channels[0])
} else if (channels.length > 1) {
this.$store.dispatch('batchUpdateSubscriptionDetails', channels)
}
}
}
})