Random and less listened radio filter out un-owned content on library section (#2007)

Part-of: <https://dev.funkwhale.audio/funkwhale/funkwhale/-/merge_requests/2285>
This commit is contained in:
Petitminion 2022-12-16 00:10:58 +01:00 committed by Marge
parent 5ff28cb52c
commit 03a5a83a3b
4 changed files with 49 additions and 2 deletions

View File

@ -119,6 +119,17 @@ class RandomRadio(SessionRadio):
return qs.filter(artist__content_category="music").order_by("?")
@registry.register(name="random_library")
class RandomLibraryRadio(SessionRadio):
def get_queryset(self, **kwargs):
qs = super().get_queryset(**kwargs)
tracks_ids = self.session.user.actor.attributed_tracks.all().values_list(
"id", flat=True
)
query = Q(artist__content_category="music") & Q(pk__in=tracks_ids)
return qs.filter(query).order_by("?")
@registry.register(name="favorites")
class FavoritesRadio(SessionRadio):
def get_queryset_kwargs(self):
@ -323,6 +334,22 @@ class LessListenedRadio(SessionRadio):
)
@registry.register(name="less-listened_library")
class LessListenedLibraryRadio(SessionRadio):
def clean(self, instance):
instance.related_object = instance.user
super().clean(instance)
def get_queryset(self, **kwargs):
qs = super().get_queryset(**kwargs)
listened = self.session.user.listenings.all().values_list("track", flat=True)
tracks_ids = self.session.user.actor.attributed_tracks.all().values_list(
"id", flat=True
)
query = Q(artist__content_category="music") & Q(pk__in=tracks_ids)
return qs.filter(query).exclude(pk__in=listened).order_by("?")
@registry.register(name="actor-content")
class ActorContentRadio(RelatedObjectRadio):
"""

View File

@ -0,0 +1 @@
Random and less listened radio filter out un-owned content on library section (#2007)

View File

@ -129,12 +129,23 @@ const paginateOptions = computed(() => sortedUniq([12, 25, 50, paginateBy.value]
v-if="isAuthenticated && hasFavorites"
:type="'favorites'"
/>
<radio-card :type="'random'" />
<radio-card
v-if="scope === 'all'"
:type="'random'"
/>
<radio-card
v-if="scope === 'me'"
:type="'random_library'"
/>
<radio-card :type="'recently-added'" />
<radio-card
v-if="$store.state.auth.authenticated"
v-if="$store.state.auth.authenticated && scope === 'all'"
:type="'less-listened'"
/>
<radio-card
v-if="$store.state.auth.authenticated && scope === 'me'"
:type="'less-listened_library'"
/>
</div>
</div>

View File

@ -52,6 +52,10 @@ const store: Module<State, RootState> = {
name: 'Random',
description: "Totally random picks, maybe you'll discover new things?"
},
random_library: {
name: 'Random',
description: 'Random picks from your library, be surprise by yourself ?'
},
favorites: {
name: 'Favorites',
description: 'Play your favorites tunes in a never-ending happiness loop.'
@ -60,6 +64,10 @@ const store: Module<State, RootState> = {
name: 'Less listened',
description: "Listen to tracks you usually don't. It's time to restore some balance."
},
'less-listened_library': {
name: 'Less listened',
description: "Listen to tracks from your library you usually don't. It's time to restore some balance."
},
'recently-added': {
name: 'Recently Added',
description: 'Newest content on the network. Get some fresh air.'