@@ -33,6 +33,10 @@ import {
33
33
parseLocalListVideo ,
34
34
parseLocalSubscriberCount
35
35
} from '../../helpers/api/local'
36
+ import {
37
+ addPublishedDatesInvidious ,
38
+ addPublishedDatesLocal
39
+ } from '../../helpers/subscriptions'
36
40
37
41
export default defineComponent ( {
38
42
name : 'Channel' ,
@@ -171,6 +175,13 @@ export default defineComponent({
171
175
return this . subscriptionInfo !== null
172
176
} ,
173
177
178
+ isSubscribedInAnyProfile : function ( ) {
179
+ const profileList = this . $store . getters . getProfileList
180
+
181
+ // check the all channels profile
182
+ return profileList [ 0 ] . subscriptions . some ( ( channel ) => channel . id === this . id )
183
+ } ,
184
+
174
185
videoLiveSelectNames : function ( ) {
175
186
return [
176
187
this . $t ( 'Channel.Videos.Sort Types.Newest' ) ,
@@ -767,6 +778,17 @@ export default defineComponent({
767
778
this . latestVideos = parseLocalChannelVideos ( videosTab . videos , this . id , this . channelName )
768
779
this . videoContinuationData = videosTab . has_continuation ? videosTab : null
769
780
this . isElementListLoading = false
781
+
782
+ if ( this . isSubscribedInAnyProfile && this . latestVideos . length > 0 && this . videoSortBy === 'newest' ) {
783
+ addPublishedDatesLocal ( this . latestVideos )
784
+ this . updateSubscriptionVideosCacheByChannel ( {
785
+ channelId : this . id ,
786
+ // create a copy so that we only cache the first page
787
+ // if we use the same array, the store will get angry at us for modifying it outside of the store,
788
+ // when the user clicks load more
789
+ videos : [ ...this . latestVideos ]
790
+ } )
791
+ }
770
792
} catch ( err ) {
771
793
console . error ( err )
772
794
const errorMessage = this . $t ( 'Local API Error (Click to copy)' )
@@ -825,6 +847,16 @@ export default defineComponent({
825
847
this . latestShorts = parseLocalChannelShorts ( shortsTab . videos , this . id , this . channelName )
826
848
this . shortContinuationData = shortsTab . has_continuation ? shortsTab : null
827
849
this . isElementListLoading = false
850
+
851
+ if ( this . isSubscribedInAnyProfile && this . latestShorts . length > 0 && this . shortSortBy === 'newest' ) {
852
+ // As the shorts tab API response doesn't include the published dates,
853
+ // we can't just write the results to the subscriptions cache like we do with videos and live (can't sort chronologically without the date).
854
+ // However we can still update the metadata in the cache such as the view count and title that might have changed since it was cached
855
+ this . updateSubscriptionShortsCacheWithChannelPageShorts ( {
856
+ channelId : this . id ,
857
+ videos : this . latestShorts
858
+ } )
859
+ }
828
860
} catch ( err ) {
829
861
console . error ( err )
830
862
const errorMessage = this . $t ( 'Local API Error (Click to copy)' )
@@ -883,6 +915,17 @@ export default defineComponent({
883
915
this . latestLive = parseLocalChannelVideos ( liveTab . videos , this . id , this . channelName )
884
916
this . liveContinuationData = liveTab . has_continuation ? liveTab : null
885
917
this . isElementListLoading = false
918
+
919
+ if ( this . isSubscribedInAnyProfile && this . latestLive . length > 0 && this . liveSortBy === 'newest' ) {
920
+ addPublishedDatesLocal ( this . latestLive )
921
+ this . updateSubscriptionLiveCacheByChannel ( {
922
+ channelId : this . id ,
923
+ // create a copy so that we only cache the first page
924
+ // if we use the same array, the store will get angry at us for modifying it outside of the store,
925
+ // when the user clicks load more
926
+ videos : [ ...this . latestLive ]
927
+ } )
928
+ }
886
929
} catch ( err ) {
887
930
console . error ( err )
888
931
const errorMessage = this . $t ( 'Local API Error (Click to copy)' )
@@ -1052,6 +1095,16 @@ export default defineComponent({
1052
1095
}
1053
1096
this . videoContinuationData = response . continuation || null
1054
1097
this . isElementListLoading = false
1098
+
1099
+ if ( this . isSubscribedInAnyProfile && ! more && this . latestVideos . length > 0 && this . videoSortBy === 'newest' ) {
1100
+ addPublishedDatesInvidious ( this . latestVideos )
1101
+ this . updateSubscriptionVideosCacheByChannel ( {
1102
+ channelId : this . id ,
1103
+ // create a copy so that we only cache the first page
1104
+ // if we use the same array, it will also contain all the next pages
1105
+ videos : [ ...this . latestVideos ]
1106
+ } )
1107
+ }
1055
1108
} ) . catch ( ( err ) => {
1056
1109
console . error ( err )
1057
1110
const errorMessage = this . $t ( 'Invidious API Error (Click to copy)' )
@@ -1101,6 +1154,17 @@ export default defineComponent({
1101
1154
}
1102
1155
this . shortContinuationData = response . continuation || null
1103
1156
this . isElementListLoading = false
1157
+
1158
+ if ( this . isSubscribedInAnyProfile && ! more && this . latestShorts . length > 0 && this . shortSortBy === 'newest' ) {
1159
+ // As the shorts tab API response doesn't include the published dates,
1160
+ // we can't just write the results to the subscriptions cache like we do with videos and live (can't sort chronologically without the date).
1161
+ // However we can still update the metadata in the cache e.g. adding the duration, as that isn't included in the RSS feeds
1162
+ // and updating the view count and title that might have changed since it was cached
1163
+ this . updateSubscriptionShortsCacheWithChannelPageShorts ( {
1164
+ channelId : this . id ,
1165
+ videos : this . latestShorts
1166
+ } )
1167
+ }
1104
1168
} ) . catch ( ( err ) => {
1105
1169
console . error ( err )
1106
1170
const errorMessage = this . $t ( 'Invidious API Error (Click to copy)' )
@@ -1142,6 +1206,17 @@ export default defineComponent({
1142
1206
}
1143
1207
this . liveContinuationData = response . continuation || null
1144
1208
this . isElementListLoading = false
1209
+
1210
+ if ( this . isSubscribedInAnyProfile && ! more && this . latestLive . length > 0 && this . liveSortBy === 'newest' ) {
1211
+ addPublishedDatesInvidious ( this . latestLive )
1212
+ this . updateSubscriptionLiveCacheByChannel ( {
1213
+ channelId : this . id ,
1214
+ // create a copy so that we only cache the first page
1215
+ // if we use the same array, the store will get angry at us for modifying it outside of the store,
1216
+ // when the user clicks load more
1217
+ videos : [ ...this . latestLive ]
1218
+ } )
1219
+ }
1145
1220
} ) . catch ( ( err ) => {
1146
1221
console . error ( err )
1147
1222
const errorMessage = this . $t ( 'Invidious API Error (Click to copy)' )
@@ -1444,7 +1519,7 @@ export default defineComponent({
1444
1519
} )
1445
1520
if ( this . backendPreference === 'local' && this . backendFallback ) {
1446
1521
showToast ( this . $t ( 'Falling back to Invidious API' ) )
1447
- this . getChannelPodcastsInvidious ( )
1522
+ this . channelInvidiousPodcasts ( )
1448
1523
} else {
1449
1524
this . isLoading = false
1450
1525
}
@@ -1559,6 +1634,19 @@ export default defineComponent({
1559
1634
1560
1635
this . latestCommunityPosts = parseLocalCommunityPosts ( posts )
1561
1636
this . communityContinuationData = communityTab . has_continuation ? communityTab : null
1637
+
1638
+ if ( this . latestCommunityPosts . length > 0 ) {
1639
+ this . latestCommunityPosts . forEach ( post => {
1640
+ post . authorId = this . id
1641
+ } )
1642
+ this . updateSubscriptionPostsCacheByChannel ( {
1643
+ channelId : this . id ,
1644
+ // create a copy so that we only cache the first page
1645
+ // if we use the same array, the store will get angry at us for modifying it outside of the store,
1646
+ // when the user clicks load more
1647
+ posts : [ ...this . latestCommunityPosts ]
1648
+ } )
1649
+ }
1562
1650
} catch ( err ) {
1563
1651
console . error ( err )
1564
1652
const errorMessage = this . $t ( 'Local API Error (Click to copy)' )
@@ -1610,6 +1698,19 @@ export default defineComponent({
1610
1698
this . latestCommunityPosts = posts
1611
1699
}
1612
1700
this . communityContinuationData = continuation
1701
+
1702
+ if ( this . isSubscribedInAnyProfile && ! more && this . latestCommunityPosts . length > 0 ) {
1703
+ this . latestCommunityPosts . forEach ( post => {
1704
+ post . authorId = this . id
1705
+ } )
1706
+ this . updateSubscriptionPostsCacheByChannel ( {
1707
+ channelId : this . id ,
1708
+ // create a copy so that we only cache the first page
1709
+ // if we use the same array, the store will get angry at us for modifying it outside of the store,
1710
+ // when the user clicks load more
1711
+ posts : [ ...this . latestCommunityPosts ]
1712
+ } )
1713
+ }
1613
1714
} ) . catch ( async ( err ) => {
1614
1715
console . error ( err )
1615
1716
const errorMessage = this . $t ( 'Invidious API Error (Click to copy)' )
@@ -1849,7 +1950,11 @@ export default defineComponent({
1849
1950
1850
1951
...mapActions ( [
1851
1952
'showOutlines' ,
1852
- 'updateSubscriptionDetails'
1953
+ 'updateSubscriptionDetails' ,
1954
+ 'updateSubscriptionVideosCacheByChannel' ,
1955
+ 'updateSubscriptionLiveCacheByChannel' ,
1956
+ 'updateSubscriptionShortsCacheWithChannelPageShorts' ,
1957
+ 'updateSubscriptionPostsCacheByChannel'
1853
1958
] )
1854
1959
}
1855
1960
} )
0 commit comments