diff --git a/discovery-provider/src/tasks/entity_manager/playlist.py b/discovery-provider/src/tasks/entity_manager/playlist.py index 152ee7b32d6..23cf49bfe12 100644 --- a/discovery-provider/src/tasks/entity_manager/playlist.py +++ b/discovery-provider/src/tasks/entity_manager/playlist.py @@ -3,6 +3,8 @@ from datetime import datetime from typing import Dict, Set +from src.challenges.challenge_event import ChallengeEvent +from src.challenges.challenge_event_bus import ChallengeEventBus from src.models.playlists.playlist import Playlist from src.tasks.entity_manager.utils import ( PLAYLIST_ID_OFFSET, @@ -79,6 +81,20 @@ def create_playlist(params: ManageEntityParameters): ) params.add_playlist_record(playlist_id, create_playlist_record) + if tracks: + dispatch_challenge_playlist_upload( + params.challenge_bus, params.block_number, create_playlist_record + ) + + +def dispatch_challenge_playlist_upload( + bus: ChallengeEventBus, block_number: int, playlist_record: Playlist +): + # Adds challenge for creating your first playlist and adding a track to it. + bus.dispatch( + ChallengeEvent.first_playlist, block_number, playlist_record.playlist_owner_id + ) + def update_playlist(params: ManageEntityParameters): validate_playlist_tx(params) @@ -105,6 +121,11 @@ def update_playlist(params: ManageEntityParameters): ) params.add_playlist_record(playlist_id, updated_playlist) + if updated_playlist.playlist_contents["track_ids"]: + dispatch_challenge_playlist_upload( + params.challenge_bus, params.block_number, updated_playlist + ) + def delete_playlist(params: ManageEntityParameters): validate_playlist_tx(params)