diff --git a/src/renderer/components/SubscriptionSettings/SubscriptionSettings.vue b/src/renderer/components/SubscriptionSettings/SubscriptionSettings.vue index 2e7e6f6935816..12c7adf50b156 100644 --- a/src/renderer/components/SubscriptionSettings/SubscriptionSettings.vue +++ b/src/renderer/components/SubscriptionSettings/SubscriptionSettings.vue @@ -24,6 +24,12 @@ compact @change="updateUnsubscriptionPopupStatus" /> +
} */ +const randomizeSubscriptionOrder = computed(() => store.getters.getRandomizeSubscriptionOrder) + +/** + * @param {boolean} value + */ +function updateRandomizeSubscriptionOrder(value) { + store.dispatch('updateRandomizeSubscriptionOrder', value) +} + /** @type {import('vue').ComputedRef} */ const onlyShowLatestFromChannel = computed(() => store.getters.getOnlyShowLatestFromChannel) diff --git a/src/renderer/helpers/subscriptions.js b/src/renderer/helpers/subscriptions.js index 80e83c7e0f872..b53420a0e3072 100644 --- a/src/renderer/helpers/subscriptions.js +++ b/src/renderer/helpers/subscriptions.js @@ -31,9 +31,40 @@ export function updateVideoListAfterProcessing(videos) { }) } - videoList.sort((a, b) => { - return b.published - a.published - }) + // ordered last to show first eligible video from channel + // if the first one incidentally failed one of the above checks + if (store.getters.getOnlyShowLatestFromChannel) { + const authors = new Map() + videoList = videoList.filter((video) => { + if (!video.authorId) { + return true + } + + if (!authors.has(video.authorId)) { + authors.set(video.authorId, 1) + return true + } else { + const currentVideos = authors.get(video.authorId) + + if (currentVideos < store.getters.getOnlyShowLatestFromChannelNumber) { + authors.set(video.authorId, currentVideos + 1) + return true + } + } + + return false + }) + } + + if (store.getters.getRandomizeSubscriptionOrder) { + const shuffled = videoList.map(value => ({ value, sort: Math.random() })) + shuffled.sort((a, b) => a.sort - b.sort) + videoList = shuffled.map(item => item.value) + } else { + videoList.sort((a, b) => { + return b.published - a.published + }) + } return videoList } diff --git a/src/renderer/store/modules/settings.js b/src/renderer/store/modules/settings.js index 99affa66401d0..65cebfdd941d7 100644 --- a/src/renderer/store/modules/settings.js +++ b/src/renderer/store/modules/settings.js @@ -226,6 +226,7 @@ const state = { maxVideoPlaybackRate: 3, onlyShowLatestFromChannel: false, onlyShowLatestFromChannelNumber: 1, + randomizeSubscriptionOrder: false, openDeepLinksInNewWindow: false, playNextVideo: false, proxyHostname: '127.0.0.1', diff --git a/static/locales/en-US.yaml b/static/locales/en-US.yaml index 95aedd31f9d06..5cb1f563f7ff1 100644 --- a/static/locales/en-US.yaml +++ b/static/locales/en-US.yaml @@ -533,6 +533,7 @@ Settings: 'Limit the number of videos displayed for each channel': 'Limit the number of videos displayed for each channel' To: To Confirm Before Unsubscribing: Confirm Before Unsubscribing + Randomize Order: Randomize Order Distraction Free Settings: Distraction Free Settings: Distraction Free Sections: