From fc210aa663e73336fd515524ab85e3cb59300d10 Mon Sep 17 00:00:00 2001 From: Jason <84899178+jasonhenriquez@users.noreply.github.com> Date: Sat, 2 Dec 2023 09:19:25 +0000 Subject: [PATCH] Order watched recommended videos last (#4394) * Implement change * Update to use local variable to potentially improve performance in non-first load case --- src/renderer/views/Watch/Watch.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/renderer/views/Watch/Watch.js b/src/renderer/views/Watch/Watch.js index 7a8412793d1a6..71d3dfe9c6c50 100644 --- a/src/renderer/views/Watch/Watch.js +++ b/src/renderer/views/Watch/Watch.js @@ -277,10 +277,16 @@ export default defineComponent({ this.isFamilyFriendly = result.basic_info.is_family_safe - this.recommendedVideos = result.watch_next_feed + const recommendedVideos = result.watch_next_feed ?.filter((item) => item.type === 'CompactVideo') .map(parseLocalWatchNextVideo) ?? [] + // place watched recommended videos last + this.recommendedVideos = [ + ...recommendedVideos.filter((video) => !this.isRecommendedVideoWatched(video.videoId)), + ...recommendedVideos.filter((video) => this.isRecommendedVideoWatched(video.videoId)) + ] + if (this.showFamilyFriendlyOnly && !this.isFamilyFriendly) { this.isLoading = false this.handleVideoEnded() @@ -699,7 +705,12 @@ export default defineComponent({ this.videoPublished = result.published * 1000 this.videoDescriptionHtml = result.descriptionHtml - this.recommendedVideos = result.recommendedVideos + const recommendedVideos = result.recommendedVideos + // place watched recommended videos last + this.recommendedVideos = [ + ...recommendedVideos.filter((video) => !this.isRecommendedVideoWatched(video.videoId)), + ...recommendedVideos.filter((video) => this.isRecommendedVideoWatched(video.videoId)) + ] this.adaptiveFormats = await this.getAdaptiveFormatsInvidious(result) this.isLive = result.liveNow this.isFamilyFriendly = result.isFamilyFriendly @@ -1067,6 +1078,10 @@ export default defineComponent({ this.checkIfWatched() }, + isRecommendedVideoWatched: function (videoId) { + return !!this.$store.getters.getHistoryCacheById[videoId] + }, + checkIfWatched: function () { if (!this.isLive) { if (this.timestamp) {