public async Task TogglePlaybackAsync(PartyGoer partyGoer) { // Grabbing partier by reference, so any change I make to it will change it in the list PartyGoer partier = Listeners.Find(p => p.Equals(partyGoer)); partier.PausedMusic = !partier.PausedMusic; await DomainEvents.RaiseAsync(new ToggleMusicState { Listener = partier, State = DetermineMusicState(partier.PausedMusic) }); }
public bool DoesUserLikeTrack(PartyGoer partyGoer, string trackUri) { if (_usersLikedTracks.ContainsKey(partyGoer.GetId())) { return(_usersLikedTracks[partyGoer.GetId()].Contains(trackUri)); } return(false); }
public Party(PartyGoer host) { Id = Guid.NewGuid(); Host = host; Listeners = new List <PartyGoer>() { host }; PartyCode = GeneratePartyCode(); }
public async Task UserRequestedSkipAsync(PartyGoer partyGoer) { UsersThatRequestedSkip.Add(partyGoer); if (UsersThatRequestedSkip.Count > _listeners.Count * 0.5) { // Skip the song await NextSongAsync(); UsersThatRequestedSkip.Clear(); } }
public async Task UserLikesTrackAsync(PartyGoer user, string trackUri, string partyCode) { if (!_usersLikesDislikes.DoesUserLikeTrack(user, trackUri)) { _usersLikesDislikes.UserLikesTrack(user, trackUri); TrackWithFeelings track = _tracks.Find(p => p.GetTrackWithoutFeelings().Id.Equals(trackUri, StringComparison.OrdinalIgnoreCase)); if (track != null) { track.UserLikesTrack(); _tracks.Sort(new ReorderQueueComparer()); await DomainEvents.RaiseAsync(new UpdateQueue { Tracks = _tracks.Select(p => p.GetTrackWithoutFeelings()).ToList(), PartyCode = partyCode }); } } }
public LikesDislikes GetUsersTrackFeelings(PartyGoer user) { return(_usersLikesDislikes.GetUsersTrackFeelings(user)); }
public void JoinParty(PartyGoer partyGoer) { Listeners.Add(partyGoer); }
public void RemoveListener(PartyGoer listener) { _listeners.RemoveAll(p => p.Id.Equals(listener.Id, StringComparison.OrdinalIgnoreCase)); }
private void StoreUsersLikedTrack(PartyGoer user, string trackUri) { _sumOfLikes.AdjustTrackFeelings(trackUri, Feelings.Like); _usersLikedTracks.AddFeelings(user, trackUri); _usersDislikedTracks.RemoveFeelings(user, trackUri); }
public void UserLikesTrack(PartyGoer user, string trackUri) { StoreUsersLikedTrack(user, trackUri); }
public LikesDislikes GetUsersTrackFeelings(PartyGoer user) { return(new LikesDislikes(_usersLikedTracks.GetUsersTracks(user), _usersDislikedTracks.GetUsersTracks(user))); }
public static List <string> GetUsersTracks(this Dictionary <string, List <string> > dictionary, PartyGoer partyGoer) { if (dictionary.ContainsKey(partyGoer.GetId())) { return(dictionary[partyGoer.GetId()]); } else { return(new List <string>()); } }
public static void RemoveFeelings(this Dictionary <string, List <string> > dictionary, PartyGoer partyGoer, string trackUri) { if (dictionary.ContainsKey(partyGoer.GetId())) { dictionary[partyGoer.GetId()].RemoveAll(p => p.Equals(trackUri)); } }
public static void AddFeelings(this Dictionary <string, List <string> > dictionary, PartyGoer partyGoer, string trackUri) { if (dictionary.ContainsKey(partyGoer.GetId())) { dictionary[partyGoer.GetId()].TryAdd(trackUri); } else { dictionary.Add(partyGoer.GetId(), new List <string> { trackUri }); } }