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

Feat/different subscription behavior #2

Closed
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
18 changes: 18 additions & 0 deletions src/renderer/components/ft-refresh-widget/ft-refresh-widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,29 @@ export default defineComponent({
title: {
type: String,
required: true
},
updatedChannelsCount: {
type: Number,
default: 0
},
totalChannelsCount: {
type: Number,
default: 0
}
},
computed: {
isSideNavOpen: function () {
return this.$store.getters.getIsSideNavOpen
},
lastRefreshTimestampLabel: function () {
return this.updatedChannelsCount === this.totalChannelsCount
? this.$t('Feed.Feed Last Updated', { feedName: this.title, date: this.lastRefreshTimestamp })
: this.$t('Feed.Feed Last Updated For Channels', {
feedName: this.title,
date: this.lastRefreshTimestamp,
someChannelsCount: this.updatedChannelsCount,
allChannelsCount: this.totalChannelsCount
})
}
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
v-if="lastRefreshTimestamp"
class="lastRefreshTimestamp"
>
{{ $t('Feed.Feed Last Updated', { feedName: title, date: lastRefreshTimestamp }) }}
{{ lastRefreshTimestampLabel }}
</p>
<ft-icon-button
:disabled="disableRefresh"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default defineComponent({
postList: [],
errorChannels: [],
attemptedFetch: false,
updatedChannelsCount: 0,
}
},
computed: {
Expand Down Expand Up @@ -58,9 +59,12 @@ export default defineComponent({
if (this.cacheEntriesForAllActiveProfileChannels.length === 0) { return false }
if (this.cacheEntriesForAllActiveProfileChannels.length < this.activeSubscriptionList.length) { return false }

return this.cacheEntriesForAllActiveProfileChannels.every((cacheEntry) => {
return cacheEntry.posts != null
})
return this.nonNullCacheEntriesCount < this.cacheEntriesForAllActiveProfileChannels.length
},

nonNullCacheEntriesCount() {
return this.cacheEntriesForAllActiveProfileChannels
.filter((cacheEntry) => cacheEntry.posts != null).length
},

activeSubscriptionList: function () {
Expand All @@ -73,20 +77,19 @@ export default defineComponent({
},
watch: {
activeProfile: async function (_) {
this.isLoading = true
this.loadPostsFromCacheSometimes()
this.loadPostsFromCacheOrServer()
},
},
mounted: async function () {
this.isLoading = true

this.loadPostsFromCacheSometimes()
this.loadPostsFromCacheOrServer()
},
methods: {
loadPostsFromCacheSometimes() {
async loadPostsFromCacheOrServer() {
this.isLoading = true
// This method is called on view visible
if (this.postCacheForAllActiveProfileChannelsPresent) {
this.loadPostsFromCacheForAllActiveProfileChannels()
if (!this.fetchSubscriptionsAutomatically || this.postCacheForAllActiveProfileChannelsPresent) {
this.updatedChannelsCount = this.nonNullCacheEntriesCount
this.loadPostsFromCacheForActiveProfileChannels()
if (this.cacheEntriesForAllActiveProfileChannels.length > 0) {
let minTimestamp = null
this.cacheEntriesForAllActiveProfileChannels.forEach((cacheEntry) => {
Expand All @@ -99,14 +102,12 @@ export default defineComponent({
return
}

this.maybeLoadPostsForSubscriptionsFromRemote()
this.loadPostsForSubscriptionsFromRemote()
},

async loadPostsFromCacheForAllActiveProfileChannels() {
async loadPostsFromCacheForActiveProfileChannels() {
const postList = []
this.activeSubscriptionList.forEach((channel) => {
const channelCacheEntry = this.$store.getters.getPostsCacheByChannel(channel.id)

this.cacheEntriesForAllActiveProfileChannels.forEach((channelCacheEntry) => {
postList.push(...channelCacheEntry.posts)
})

Expand All @@ -119,6 +120,8 @@ export default defineComponent({
},

loadPostsForSubscriptionsFromRemote: async function () {
this.updatedChannelsCount = this.activeSubscriptionList.length

if (this.activeSubscriptionList.length === 0) {
this.isLoading = false
this.postList = []
Expand Down Expand Up @@ -165,17 +168,6 @@ export default defineComponent({
this.updateShowProgressBar(false)
},

maybeLoadPostsForSubscriptionsFromRemote: async function () {
if (this.fetchSubscriptionsAutomatically) {
// `this.isLoading = false` is called inside `loadPostsForSubscriptionsFromRemote` when needed
await this.loadPostsForSubscriptionsFromRemote()
} else {
this.postList = []
this.attemptedFetch = false
this.isLoading = false
}
},

getChannelPostsLocal: async function (channel) {
try {
const entries = await getLocalChannelCommunity(channel.id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
:is-community="true"
:initial-data-limit="20"
:last-refresh-timestamp="lastCommunityRefreshTimestamp"
:updated-channels-count="updatedChannelsCount"
:total-channels-count="activeSubscriptionList.length"
:title="$t('Global.Community')"
@refresh="loadPostsForSubscriptionsFromRemote"
/>
Expand Down
67 changes: 24 additions & 43 deletions src/renderer/components/subscriptions-live/subscriptions-live.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import SubscriptionsTabUI from '../subscriptions-tab-ui/subscriptions-tab-ui.vue
import { copyToClipboard, getRelativeTimeFromDate, showToast } from '../../helpers/utils'
import { invidiousAPICall } from '../../helpers/api/invidious'
import { getLocalChannelLiveStreams } from '../../helpers/api/local'
import { addPublishedDatesInvidious, addPublishedDatesLocal, parseYouTubeRSSFeed, updateVideoListAfterProcessing } from '../../helpers/subscriptions'
import { addPublishedDatesInvidious, addPublishedDatesLocal, parseYouTubeRSSFeed, updateVideoListAfterProcessing, loadSubscriptionVideosFromCacheOrServer } from '../../helpers/subscriptions'

export default defineComponent({
name: 'SubscriptionsLive',
Expand All @@ -18,6 +18,7 @@ export default defineComponent({
videoList: [],
errorChannels: [],
attemptedFetch: false,
updatedChannelsCount: 0
}
},
computed: {
Expand Down Expand Up @@ -58,9 +59,11 @@ export default defineComponent({
if (this.cacheEntriesForAllActiveProfileChannels.length === 0) { return false }
if (this.cacheEntriesForAllActiveProfileChannels.length < this.activeSubscriptionList.length) { return false }

return this.cacheEntriesForAllActiveProfileChannels.every((cacheEntry) => {
return cacheEntry.videos != null
})
return this.nonNullCacheEntriesCount < this.cacheEntriesForAllActiveProfileChannels.length
},
nonNullCacheEntriesCount() {
return this.cacheEntriesForAllActiveProfileChannels
.filter((cacheEntry) => cacheEntry.videos != null).length
},

activeSubscriptionList: function () {
Expand All @@ -78,46 +81,35 @@ export default defineComponent({
watch: {
activeProfile: async function (_) {
this.isLoading = true
this.loadVideosFromCacheSometimes()
this.loadSubscriptionVideosFromCacheOrServer()
},
},
mounted: async function () {
this.isLoading = true

this.loadVideosFromCacheSometimes()
this.loadSubscriptionVideosFromCacheOrServer()
},
methods: {
loadVideosFromCacheSometimes() {
// This method is called on view visible
if (this.videoCacheForAllActiveProfileChannelsPresent) {
this.loadVideosFromCacheForAllActiveProfileChannels()
if (this.cacheEntriesForAllActiveProfileChannels.length > 0) {
let minTimestamp = null
this.cacheEntriesForAllActiveProfileChannels.forEach((cacheEntry) => {
if (!minTimestamp || cacheEntry.timestamp.getTime() < minTimestamp.getTime()) {
minTimestamp = cacheEntry.timestamp
}
})
this.updateLastLiveRefreshTimestampByProfile({ profileId: this.activeProfileId, timestamp: minTimestamp })
}
loadSubscriptionVideosFromCacheOrServer: function () {
const videoList = loadSubscriptionVideosFromCacheOrServer(
this.cacheEntriesForAllActiveProfileChannels,
this.videoCacheForAllActiveProfileChannelsPresent,
this.updateTimestampByProfile,
this.activeProfileId
)
if (videoList) {
this.isLoading = false
this.updatedChannelsCount = this.nonNullCacheEntriesCount
return
}

this.maybeLoadVideosForSubscriptionsFromRemote()
this.loadVideosForSubscriptionsFromRemote()
},

async loadVideosFromCacheForAllActiveProfileChannels() {
const videoList = []
this.activeSubscriptionList.forEach((channel) => {
const channelCacheEntry = this.$store.getters.getLiveCacheByChannel(channel.id)

videoList.push(...channelCacheEntry.videos)
})
this.videoList = updateVideoListAfterProcessing(videoList)
this.isLoading = false
updateTimestampByProfile(payload) {
this.updateLastLiveRefreshTimestampByProfile(payload)
},

loadVideosForSubscriptionsFromRemote: async function () {
this.updatedChannelsCount = this.activeSubscriptionList.length

if (this.activeSubscriptionList.length === 0) {
this.isLoading = false
this.videoList = []
Expand Down Expand Up @@ -176,17 +168,6 @@ export default defineComponent({
this.updateShowProgressBar(false)
},

maybeLoadVideosForSubscriptionsFromRemote: async function () {
if (this.fetchSubscriptionsAutomatically) {
// `this.isLoading = false` is called inside `loadVideosForSubscriptionsFromRemote` when needed
await this.loadVideosForSubscriptionsFromRemote()
} else {
this.videoList = []
this.attemptedFetch = false
this.isLoading = false
}
},

getChannelLiveLocal: async function (channel, failedAttempts = 0) {
try {
const entries = await getLocalChannelLiveStreams(channel.id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
:error-channels="errorChannels"
:attempted-fetch="attemptedFetch"
:last-refresh-timestamp="lastLiveRefreshTimestamp"
:updated-channels-count="updatedChannelsCount"
:total-channels-count="activeSubscriptionList.length"
:title="$t('Global.Live')"
@refresh="loadVideosForSubscriptionsFromRemote"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { defineComponent } from 'vue'
import { mapActions, mapMutations } from 'vuex'
import SubscriptionsTabUI from '../subscriptions-tab-ui/subscriptions-tab-ui.vue'

import { parseYouTubeRSSFeed, updateVideoListAfterProcessing } from '../../helpers/subscriptions'
import { parseYouTubeRSSFeed, updateVideoListAfterProcessing, loadSubscriptionVideosFromCacheOrServer } from '../../helpers/subscriptions'
import { copyToClipboard, getRelativeTimeFromDate, showToast } from '../../helpers/utils'

export default defineComponent({
Expand All @@ -16,6 +16,7 @@ export default defineComponent({
videoList: [],
errorChannels: [],
attemptedFetch: false,
updatedChannelsCount: 0
}
},
computed: {
Expand Down Expand Up @@ -56,9 +57,11 @@ export default defineComponent({
if (this.cacheEntriesForAllActiveProfileChannels.length === 0) { return false }
if (this.cacheEntriesForAllActiveProfileChannels.length < this.activeSubscriptionList.length) { return false }

return this.cacheEntriesForAllActiveProfileChannels.every((cacheEntry) => {
return cacheEntry.videos != null
})
return this.nonNullCacheEntriesCount < this.cacheEntriesForAllActiveProfileChannels.length
},
nonNullCacheEntriesCount() {
return this.cacheEntriesForAllActiveProfileChannels
.filter((cacheEntry) => cacheEntry.videos != null).length
},

activeSubscriptionList: function () {
Expand All @@ -71,48 +74,19 @@ export default defineComponent({
},
watch: {
activeProfile: async function (_) {
this.isLoading = true
this.loadVideosFromCacheSometimes()
loadSubscriptionVideosFromCacheOrServer(this)
},
},
mounted: async function () {
this.isLoading = true

this.loadVideosFromCacheSometimes()
loadSubscriptionVideosFromCacheOrServer(this)
},
methods: {
loadVideosFromCacheSometimes() {
// This method is called on view visible

if (this.videoCacheForAllActiveProfileChannelsPresent) {
this.loadVideosFromCacheForAllActiveProfileChannels()
if (this.cacheEntriesForAllActiveProfileChannels.length > 0) {
let minTimestamp = null
this.cacheEntriesForAllActiveProfileChannels.forEach((cacheEntry) => {
if (!minTimestamp || cacheEntry.timestamp.getTime() < minTimestamp.getTime()) {
minTimestamp = cacheEntry.timestamp
}
})
this.updateLastShortRefreshTimestampByProfile({ profileId: this.activeProfileId, timestamp: minTimestamp })
}
return
}

this.maybeLoadVideosForSubscriptionsFromRemote()
updateTimestampByProfile(payload) {
this.updateLastShortRefreshTimestampByProfile(payload)
},

async loadVideosFromCacheForAllActiveProfileChannels() {
const videoList = []
this.activeSubscriptionList.forEach((channel) => {
const channelCacheEntry = this.$store.getters.getShortsCacheByChannel(channel.id)

videoList.push(...channelCacheEntry.videos)
})
this.videoList = updateVideoListAfterProcessing(videoList)
this.isLoading = false
},

loadVideosForSubscriptionsFromRemote: async function () {
this.updatedChannelsCount = this.activeSubscriptionList.length

if (this.activeSubscriptionList.length === 0) {
this.isLoading = false
this.videoList = []
Expand Down Expand Up @@ -154,17 +128,6 @@ export default defineComponent({
this.updateShowProgressBar(false)
},

maybeLoadVideosForSubscriptionsFromRemote: async function () {
if (this.fetchSubscriptionsAutomatically) {
// `this.isLoading = false` is called inside `loadVideosForSubscriptionsFromRemote` when needed
await this.loadVideosForSubscriptionsFromRemote()
} else {
this.videoList = []
this.attemptedFetch = false
this.isLoading = false
}
},

getChannelShortsLocal: async function (channel, failedAttempts = 0) {
const playlistId = channel.id.replace('UC', 'UUSH')
const feedUrl = `https://www.youtube.com/feeds/videos.xml?playlist_id=${playlistId}`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
:error-channels="errorChannels"
:attempted-fetch="attemptedFetch"
:last-refresh-timestamp="lastShortRefreshTimestamp"
:updated-channels-count="updatedChannelsCount"
:total-channels-count="activeSubscriptionList.length"
:title="$t('Global.Shorts')"
@refresh="loadVideosForSubscriptionsFromRemote"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ export default defineComponent({
title: {
type: String,
required: true
},
updatedChannelsCount: {
type: Number,
default: 0
},
totalChannelsCount: {
type: Number,
default: 0
}
},
data: function () {
Expand Down
Loading