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.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 ); // check for explicit music if (partier.FilterExplicitSongs && party.HasExplicitSongs()) { 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.Id))) { await Clients.Client(Context.ConnectionId).SendAsync("ConnectSpotify", ""); } await _logService.LogUserActivityAsync(partier, $"Joined real time collobration in party with code {partyCode}"); return; }
public async Task <string> StartPartyAsync() { Party party = new Party(await _partyGoerService.GetCurrentPartyGoerAsync()); _partyRepository.CreateParty(party); return(party.GetPartyCode()); }
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()); }
public async Task <IActionResult> TogglePlaybackState(string partyCode) { try { await _partyService.TogglePlaybackStateAsync(partyCode, await _partyGoerService.GetCurrentPartyGoerAsync()); } catch (Exception ex) { await _logService.LogExceptionAsync(ex, "Error occurred in TogglePlaybackState()"); return(new StatusCodeResult(500)); } return(new StatusCodeResult(200)); }
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()); }
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()); } }
public async Task <IActionResult> UpdateContribution(string partyCode, [FromBody] UpdateContributions updateContributions) { try { if (updateContributions.ContributionsToRemove == null) { updateContributions.ContributionsToRemove = new List <UserContribution>(); } if (updateContributions.NewContributions == null) { updateContributions.NewContributions = new List <UserContribution>(); } if (updateContributions != null && updateContributions.ContributionsToRemove.Count == 0 && updateContributions.NewContributions.Count == 0) { return(Ok()); } PartyGoer partyGoer = await _partyGoerService.GetCurrentPartyGoerAsync(); await _partyService.UpdateContributionsAsync(partyCode, updateContributions.NewContributions.Select(p => CreateContribution(partyGoer, p)).ToList(), updateContributions.ContributionsToRemove.Select(p => CreateContribution(partyGoer, p)).ToList()); } catch (Exception ex) { await _logService.LogExceptionAsync(ex, "Error occurred while trying to add contribution"); return(StatusCode(500)); } return(Ok()); }
public async Task <IActionResult> UsersPlaylists(int limit = 10, int offset = 0) { return(new JsonResult(await _partyGoerService.GetUsersPlaylistsAsync(await _partyGoerService.GetCurrentPartyGoerAsync(), limit, offset))); }
public async Task <IActionResult> SuggestedSongs(int limit = 5) { List <Track> recommendedSongs = await _partyGoerService.GetRecommendedSongsAsync((await _partyGoerService.GetCurrentPartyGoerAsync()).Id); return(new JsonResult(recommendedSongs)); }
public async Task <IActionResult> SearchArtist(string artistId) { try { return(new JsonResult(await _browseSpotifyService.GetArtistInformationAsync(await _partyGoerService.GetCurrentPartyGoerAsync(), artistId))); } catch (Exception) { // TODO: return a 500 return(new JsonResult(new Result(false, "Unable to get artist information"))); } }
public async Task <IActionResult> IsAuthenticated() { return(Ok(new { userName = (await _partyGoerService.GetCurrentPartyGoerAsync()).GetId() })); }