예제 #1
0
        public async Task HandleAsync(PlaylistEnded args)
        {
            await _logService.LogAppActivityAsync($"Playlist has ended for party with code {args.PartyCode}. Sending to all listeners");

            Party party = await _partyService.GetPartyWithCodeAsync(args.PartyCode);

            if (party.Listeners.Count < 1)
            {
                await party.DeletePlaylistAsync();
                await _partyService.EndPartyAsync(args.PartyCode);
                return;
            }

            List<Track> playlistSongs = await GenerateNewPlaylist(party);
            // If there is atleast 1 person still in the party, regenerate the playlist
            party.Playlist = new Playlist(playlistSongs, party.Listeners, party.PartyCode, party.Playlist.History);

            await party.Playlist.StartAsync();

            await _partyHubContext.Clients.Group(args.PartyCode).SendAsync("UpdatePartyView",
            new
            {
                Song = party.Playlist.CurrentSong,
                Position = party.Playlist.CurrentPositionInSong()
            },
            party.Playlist.History,
            party.Playlist.Queue
            );
        }
예제 #2
0
        public async Task HandleAsync(QueueEnded args)
        {
            await _logService.LogAppActivityAsync($"Playlist has ended for party with code {args.PartyCode}. Sending to all listeners");

            Party party = await _partyService.GetPartyWithCodeAsync(args.PartyCode);

            if (party.GetListeners().Count < 1)
            {
                await _partyService.EndPartyAsync(args.PartyCode);

                return;
            }

            List <Track> playlistSongs = await _partyService.GenerateNewPlaylist(party, args.SeedTracksUris, args.SeedArtistUris);

            await party.AddNewQueueAsync(playlistSongs);

            await _partyHubContext.Clients.Group(args.PartyCode).SendAsync("UpdatePartyView",
                                                                           new
            {
                Song     = party.GetCurrentSong(),
                Position = party.GetCurrentPositionInSong()
            },
                                                                           party.GetHistory(),
                                                                           party.GetQueue()
                                                                           );
        }
예제 #3
0
        public async Task <IActionResult> GetUsersLikesDislikes(string partyCode)
        {
            try
            {
                Party party = await _partyService.GetPartyWithCodeAsync(partyCode);

                PartyGoer user = await _partyGoerService.GetCurrentPartyGoerAsync();

                return(new JsonResult(new Result <LikedDislikedSongs>(ConvertUsersLikedDislikesToDto(party.GetUsersLikesDislikes(user)))));
            }
            catch (Exception ex)
            {
                await _logService.LogExceptionAsync(ex, "Error occurred while trying to get users likes and dislikes");

                return(new JsonResult(new Result(false, "Unable to get your liked and disliked songs")));
            }
        }
예제 #4
0
        public async Task AddTrackFeeling(string partyCode, string trackUri, int feeling)
        {
            Party party = await _partyService.GetPartyWithCodeAsync(partyCode);

            PartyGoer user = await _partyGoerService.GetCurrentPartyGoerAsync();

            switch (feeling)
            {
            case 0:
                await party.UserDislikesTrackAsync(user, trackUri);

                break;

            case 1:
                await party.UserLikesTrackAsync(user, trackUri);

                break;
            }
            await Clients.Group(partyCode).SendAsync(UPDATE_TRACK_FEELINGS_ENDPOINT, party.GetTrackVotes());
        }
예제 #5
0
        public async Task <IActionResult> Index(string partyCode)
        {
            PartyGoer user = new PartyGoer(User.FindFirstValue(ClaimTypes.NameIdentifier));
            Party     party;

            if (string.IsNullOrWhiteSpace(partyCode))
            {
                party = await _partyService.GetPartyWithAttendeeAsync(user);
            }
            else
            {
                party = await _partyService.GetPartyWithCodeAsync(partyCode);
            }

            if (party == null)
            {
                return(RedirectToAction("Index", "Dashboard"));
            }

            List <Track> usersSuggestedSongs = null;

            bool isUserListening = party.Listeners.Contains(user);

            if (party.Listeners.Contains(user))
            {
                usersSuggestedSongs = await _partyGoerService.GetRecommendedSongsAsync(user.Id);
            }

            PartyModel model = new PartyModel
            {
                PartyCode       = party.PartyCode,
                SuggestedSongs  = usersSuggestedSongs?.Select(song => ConvertDomainSongToModelSong(song)).ToList(),
                IsUserListening = isUserListening
            };

            BaseModel baseModel = new BaseModel(true, model.PartyCode);

            return(View(new BaseModel <PartyModel>(model, baseModel)));
        }
예제 #6
0
        public async Task HandleAsync(PlaylistEnded args)
        {
            await _logService.LogAppActivityAsync($"Playlist has ended for party with code {args.PartyCode}. Sending to all listeners");

            Party party = await _partyService.GetPartyWithCodeAsync(args.PartyCode);

            if (party.Listeners.Count < 1)
            {
                await party.DeletePlaylistAsync();

                await _partyService.EndPartyAsync(args.PartyCode);

                return;
            }

            List <Song> songs = new List <Song>();

            foreach (PartyGoer listener in party.Listeners)
            {
                songs.AddRange(await _partyGoerService.GetRecommendedSongsAsync(listener.Id, 5));
            }

            List <Song> playlistSongs = await _spotifyHttpClient.GetRecommendedSongsAsync(party.Listeners.ElementAt(0).Id, songs.GetRandomNItems(5).Select(p => p.TrackUri).ToList(), 0);

            // If there is atleast 1 person still in the party, regenerate the playlist
            party.Playlist = new Playlist(playlistSongs, party.Listeners, party.PartyCode, party.Playlist.History);

            await party.Playlist.StartAsync();

            await _partyHubContext.Clients.Group(args.PartyCode).SendAsync("UpdatePartyView",
                                                                           new
            {
                Song     = party.Playlist.CurrentSong,
                Position = party.Playlist.CurrentPositionInSong()
            },
                                                                           party.Playlist.History,
                                                                           party.Playlist.Queue
                                                                           );
        }
예제 #7
0
        public async Task <PartyDiagnostics> GetPartyDiagnosticAsync(string partyCode)
        {
            Party party = await _partyService.GetPartyWithCodeAsync(partyCode);

            return(party.GetDiagnostics());
        }