diff --git a/src/renderer/views/Channel/Channel.js b/src/renderer/views/Channel/Channel.js index d384e55adebe0..eeb6c7b289ff2 100644 --- a/src/renderer/views/Channel/Channel.js +++ b/src/renderer/views/Channel/Channel.js @@ -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 () { diff --git a/src/renderer/views/Search/Search.js b/src/renderer/views/Search/Search.js index 0e06460b22a40..cbd5f9af1adb2 100644 --- a/src/renderer/views/Search/Search.js +++ b/src/renderer/views/Search/Search.js @@ -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)') @@ -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)') @@ -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)') @@ -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} */ + 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) + } } } })