Exemple #1
0
        public async Task ConnectToParty(string partyCode)
        {
            PartyGoer partier = await _partyGoerService.GetCurrentPartyGoerAsync();

            if (!await _partyService.IsUserPartyingAsync(partier) && !await _partyService.IsUserHostingAPartyAsync(partier))
            {
                await _partyService.JoinPartyAsync(new Domain.DTO.PartyCodeDTO {
                    PartyCode = partyCode
                }, partier);

                await Groups.AddToGroupAsync(Context.ConnectionId, partyCode);

                await Clients.Group(partyCode).SendAsync("UpdateParty", $"{Context.UserIdentifier} has joined the party {partyCode}");
            }

            // Add the partier to real-time connection group
            await Groups.AddToGroupAsync(Context.ConnectionId, partyCode);

            await Clients.GroupExcept(partyCode, new List <string> {
                Context.ConnectionId
            }).SendAsync("NewListener", Context.UserIdentifier);

            Party party = await _partyService.GetPartyWithAttendeeAsync(partier);

            // Update the view of the partier to the current playlist
            await Clients.Client(Context.ConnectionId).SendAsync("InitialPartyLoad",
                                                                 new
            {
                Song     = party.GetCurrentSong(),
                Position = party.GetCurrentPositionInSong()
            },
                                                                 party.GetHistory(),
                                                                 party.GetQueue(),
                                                                 new
            {
                PartyCode = party.GetPartyCode(),
                Listeners = ConvertToListenerModel(party.GetListeners()),
                Host      = party.GetHost().GetId()
            }
                                                                 );;

            // check for explicit music
            if (!partier.CanListenToExplicitSongs() && party.HasExplicitTracks())
            {
                await Clients.Client(Context.ConnectionId).SendAsync("ExplicitSong", "You have filtering explicit music turned on in Spotify and there are explicit songs in the queue. We will not play the explicit song for you but continue playback when a non explicit song comes on.");
            }

            await Clients.Client(Context.ConnectionId).SendAsync("InitializeWebPlayer", await _partyGoerService.GetPartyGoerAccessTokenAsync(partier));

            // make sure that the users spotify is connected
            if (string.IsNullOrEmpty(await _spotifyHttpClient.GetUsersActiveDeviceAsync(partier.GetId())))
            {
                await Clients.Client(Context.ConnectionId).SendAsync("ConnectSpotify", "");
            }

            await _logService.LogUserActivityAsync(partier, $"Joined real time collobration in party with code {partyCode}");

            return;
        }
Exemple #2
0
        public async Task <IActionResult> StartParty(BaseModel <DashboardModel> model)
        {
            PartyGoer user = new PartyGoer(User.FindFirstValue(ClaimTypes.NameIdentifier));

            if (await _partyService.GetPartyWithAttendeeAsync(user) != null)
            {
                return(RedirectToAction("Index", "Dashboard", new { errorMessage = "Cannot create a party when you are joined in one. You need to leave the party you are currently in" }));
            }

            List <string> seedTrackUris = model.PageModel.SuggestedSongs.Where(p => p.Selected).Select(p => p.TrackUri).Take(5).ToList();

            string partyCode = await _partyService.StartPartyWithSeedSongsAsync(seedTrackUris, user);

            return(RedirectToAction("Index", new { PartyCode = partyCode }));
        }
Exemple #3
0
        public async Task PartyGoerAttendingFindsPartyWithAttendee()
        {
            string partyCode1 = await _partyService.StartNewPartyAsync(PartyHost1);

            PartyCodeDTO partyCodeDTO1 = new PartyCodeDTO {
                PartyCode = partyCode1
            };

            string partyCode3 = await _partyService.StartNewPartyAsync(PartyHost2);

            PartyCodeDTO partyCodeDTO3 = new PartyCodeDTO {
                PartyCode = partyCode3
            };

            string partyCode2 = await _partyService.StartNewPartyAsync(PartyHost3);

            PartyCodeDTO partyCodeDTO2 = new PartyCodeDTO {
                PartyCode = partyCode2
            };

            await _partyService.JoinPartyAsync(partyCodeDTO1, PartyAttendee1);

            await _partyService.JoinPartyAsync(partyCodeDTO2, PartyAttendee2);

            await _partyService.JoinPartyAsync(partyCodeDTO3, PartyAttendee3);

            Domain.Party party = await _partyService.GetPartyWithAttendeeAsync(PartyAttendee3);

            Assert.AreEqual(partyCodeDTO3.PartyCode, party.PartyCode);
        }
Exemple #4
0
        public async Task ConnectToParty(string partyCode)
        {
            var partier = new PartyGoer(Context.UserIdentifier);

            if (!await _partyService.IsUserPartyingAsync(partier) && !await _partyService.IsUserHostingAPartyAsync(partier))
            {
                await _partyService.JoinPartyAsync(new Domain.DTO.PartyCodeDTO {
                    PartyCode = partyCode
                }, partier);

                await Groups.AddToGroupAsync(Context.ConnectionId, partyCode);

                await Clients.Group(partyCode).SendAsync("UpdateParty", $"{Context.UserIdentifier} has joined the party {partyCode}");
            }

            // Add the partier to real-time connection group
            await Groups.AddToGroupAsync(Context.ConnectionId, partyCode);

            await Clients.Group(partyCode).SendAsync("UpdateParty", $"{Context.UserIdentifier} has joined the party {partyCode}");

            await Clients.Group(partyCode).SendAsync("NewListener", Context.UserIdentifier);

            Party party = await _partyService.GetPartyWithAttendeeAsync(partier);

            // Update the view of the partier to the current playlist
            await Clients.Client(Context.ConnectionId).SendAsync("UpdatePartyView",
                                                                 new
            {
                Song     = party.Playlist.CurrentSong,
                Position = party.Playlist.CurrentPositionInSong()
            },
                                                                 party.Playlist.History,
                                                                 party.Playlist.Queue
                                                                 );

            // make sure that the users spotify is connected
            if (string.IsNullOrEmpty(await _spotifyHttpClient.GetUsersActiveDeviceAsync(partier.Id)))
            {
                await Clients.Client(Context.ConnectionId).SendAsync("ConnectSpotify", "");
            }
            await _logService.LogUserActivityAsync(partier, $"Joined real time collobration in party with code {partyCode}");

            return;
        }
Exemple #5
0
        public async Task <IActionResult> Index()
        {
            if (User.Identity.IsAuthenticated)
            {
                //return RedirectToAction("Index", "Dashboard");
                PartyGoer user = new PartyGoer(User.FindFirstValue(ClaimTypes.NameIdentifier));

                Party party = await _partyService.GetPartyWithAttendeeAsync(user);

                return(View(new BaseModel(party != null ? true : false, party?.PartyCode)));
            }

            return(View());
        }
Exemple #6
0
        public async Task <IActionResult> Index()
        {
            if (User.Identity.IsAuthenticated)
            {
                //return RedirectToAction("Index", "Dashboard");
                PartyGoer user = await _partyGoerService.GetCurrentPartyGoerAsync();

                Party party = await _partyService.GetPartyWithAttendeeAsync(user);

                return(View(new BaseModel(party != null ? true : false, party?.GetPartyCode())));
            }

            return(View());
        }
Exemple #7
0
        public async Task <IActionResult> GetUserDetails()
        {
            PartyGoer currentUser = await _partyGoerService.GetCurrentPartyGoerAsync();

            Party party = await _partyService.GetPartyWithAttendeeAsync(currentUser);

            if (party != null)
            {
                return(Ok(new { IsInParty = true, Party = new { PartyCode = party.GetPartyCode() }, Details = new { Id = currentUser.GetId() } }));
            }
            else
            {
                return(Ok(new { IsInParty = false, UserDetails = new { Id = currentUser.GetId() } }));
            }
        }
        public async Task <IActionResult> UpdateSongForParty([FromBody] PartyCodeDTO partyCode)
        {
            PartyGoer user = await _partyGoerService.GetCurrentPartyGoerAsync();

            if (await _partyService.IsUserPartyingAsync(user))
            {
                Party party = await _partyService.GetPartyWithAttendeeAsync(user);

                await _logService.LogUserActivityAsync(user, $"User updated song for party with code {partyCode.PartyCode}");

                return(await UpdateCurrentSongForEveryoneInPartyAsync(party, user));
            }
            else
            {
                await _logService.LogUserActivityAsync(user, $"User failed tp update song for party with code {partyCode.PartyCode}");

                return(BadRequest($"You are currently not hosting a party or attending a party: {partyCode.PartyCode}"));
            }
        }
        public async Task <IActionResult> Index(string errorMessage)
        {
            try
            {
                PartyGoer user = await _partyGoerService.GetCurrentPartyGoerAsync();

                Party party = await _partyService.GetPartyWithAttendeeAsync(user);

                List <Domain.Track> userRecommendedSongs = await _partyGoerService.GetRecommendedSongsAsync(User.FindFirstValue(ClaimTypes.NameIdentifier));

                List <Party> topParties = await _partyService.GetTopParties(3);

                DashboardModel model = new DashboardModel
                {
                    Name             = user.Id,
                    AvailableParties = topParties.Select(p => new PreviewPartyModel
                    {
                        AlbumArtUrl   = p.Playlist?.CurrentSong?.AlbumImageUrl ?? "./assets/unknown-album-art.png",
                        ListenerCount = p.Listeners.Count,
                        Name          = "Default Party Name",
                        PartyCode     = p.PartyCode
                    }).ToList(),
                    SuggestedSongs = userRecommendedSongs.Select(p => new PreviewPlaylistSong {
                        Artist = p.Artist, Title = p.Name, TrackUri = p.Uri, Selected = true
                    }).ToList(),
                    RandomGreeting = GetRandomGreeting()
                };

                BaseModel baseModel = new BaseModel(party == null ? false : true, party?.PartyCode, errorMessage);

                return(View(new BaseModel <DashboardModel>(model, baseModel)));
            }
            catch (Exception ex)
            {
                await _logService.LogExceptionAsync(ex, "Error occurred in Index()");

                // Todo: Add error view
                return(View());
            }
        }