Skip to content

Commit

Permalink
Update subscription details from search results (#5795)
Browse files Browse the repository at this point in the history
  • Loading branch information
absidue authored Oct 5, 2024
1 parent fc71293 commit ecb2d7d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
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)
}
}
}
})

0 comments on commit ecb2d7d

Please sign in to comment.