public async Task RevealCurrentStoryAsync(string sessionId, string hostCode) { if (!await _sessionProvider.CheckSessionForHostAsync(sessionId, hostCode, default)) { return; } var session = await _sessionProvider.GetSessionByIdAsync(sessionId, default); var stories = await _storyRepo.GetStoriesBySessionIdAsync(sessionId, default); var currentStory = stories.FirstOrDefault(i => i.StoryId == session.CurrentStoryId); await _storyRepo.RevealStoryAsync(currentStory.StoryId, default); await Clients.Group(sessionId).SendAsync("RevealCurrentStory", sessionId); }
public async Task <JoinSessionResponse> JoinSessionAsync(JoinSessionRequest joinSessionRequest, string sessionId, CancellationToken cancellationToken) { var rejoinCode = GetRandomCode(SessionCodeLength); var authCode = GetRandomCode(AuthCodeLength); var userId = joinSessionRequest.UserId ?? ObjectId.GenerateNewId().ToString(); var session = await _sessionRepo.GetSessionByIdAsync(sessionId, cancellationToken); if (joinSessionRequest.UserId == null) { var user = new UserModel { SessionId = session.SessionId, UserId = userId, Nickname = joinSessionRequest.Nickname, RejoinCode = rejoinCode, AuthCode = authCode }; await _userRepo.InsertUserAsync(user, cancellationToken); } else { await _userRepo.UpdateRejoinCodeAsync(userId, rejoinCode, cancellationToken); } var stories = await _storyRepo.GetStoriesBySessionIdAsync(session.SessionId, cancellationToken); var users = await _userRepo.GetUsersBySessionIdAsync(session.SessionId, cancellationToken); return(new JoinSessionResponse { SessionId = session.SessionId, UserId = userId, RejoinCode = rejoinCode, AuthCode = authCode, Stories = stories, Users = users, PointChoices = session.PointChoices, HasStarted = session.HasStarted, HasFinished = session.HasFinished }); }