Apply suggestions from code review
Co-authored-by: David Pine <david.pine@microsoft.com>pull/62/head
parent
e6bf41aa52
commit
0dbb1682ce
|
@ -6,52 +6,52 @@ using Orleans.Runtime;
|
|||
|
||||
namespace ListenTogether.Application.Grains
|
||||
{
|
||||
public class RoomGrain : Grain, IRoomGrain
|
||||
public sealed class RoomGrain : Grain, IRoomGrain
|
||||
{
|
||||
IPersistentState<Room> Room { get; set; }
|
||||
public ILogger<RoomGrain> Logger { get; }
|
||||
private readonly IPersistentState<Room> _room;
|
||||
private readonly ILogger<RoomGrain> _logger;
|
||||
|
||||
public RoomGrain([PersistentState("room", "roomStorage")] IPersistentState<Room> room,
|
||||
ILogger<RoomGrain> logger)
|
||||
{
|
||||
Room = room;
|
||||
Logger = logger;
|
||||
_room = room;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task<Room> JoinRoom(string connectionId, string userName)
|
||||
{
|
||||
Logger.LogInformation($"User {userName} is joining {Room.State.Code}, listening to {Room.State.Episode.Show.Title}");
|
||||
Room.State.AddUser(new User(connectionId, userName));
|
||||
await Room.WriteStateAsync();
|
||||
return Room.State;
|
||||
_logger.LogInformation($"User {userName} is joining {_room.State.Code}, listening to {_room.State.Episode.Show.Title}");
|
||||
_room.State.AddUser(new User(connectionId, userName));
|
||||
await _room.WriteStateAsync();
|
||||
return _room.State;
|
||||
}
|
||||
|
||||
public async Task<Room> LeaveRoom(string connectionId)
|
||||
{
|
||||
var user = Room.State.Users.First(x => x.ConnectionId == connectionId);
|
||||
Logger.LogInformation($"User {user.Name} is joining {Room.State.Code}, listening to {Room.State.Episode.Show.Title}");
|
||||
Room.State.RemoveUser(connectionId);
|
||||
await Room.WriteStateAsync();
|
||||
var user = _room.State.Users.First(_ => _.ConnectionId == connectionId);
|
||||
_logger.LogInformation($"User {user.Name} is joining {_room.State.Code}, listening to {_room.State.Episode.Show.Title}");
|
||||
_room.State.RemoveUser(connectionId);
|
||||
await _room.WriteStateAsync();
|
||||
|
||||
if(Room.State.Users.Count == 0)
|
||||
if (_room.State.Users.Count is 0)
|
||||
{
|
||||
base.DeactivateOnIdle();
|
||||
}
|
||||
|
||||
return Room.State;
|
||||
return _room.State;
|
||||
}
|
||||
|
||||
public async Task SetRoom(Room room)
|
||||
{
|
||||
Room.State = room;
|
||||
await Room.WriteStateAsync();
|
||||
_room.State = room;
|
||||
await _room.WriteStateAsync();
|
||||
}
|
||||
|
||||
public Task<Room> UpdatePlayerState(TimeSpan seconds, PlayerState playerState)
|
||||
{
|
||||
Logger.LogInformation($"Updating player state to {playerState} at {seconds}.");
|
||||
Room.State.UpdatePlayerState(seconds, playerState);
|
||||
return Task.FromResult(Room.State);
|
||||
_logger.LogInformation($"Updating player state to {playerState} at {seconds}.");
|
||||
_room.State.UpdatePlayerState(seconds, playerState);
|
||||
return Task.FromResult(_room.State);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
using ListenTogether.Domain;
|
||||
using Orleans;
|
||||
|
||||
namespace ListenTogether.Application.Interfaces
|
||||
namespace ListenTogether.Application.Interfaces;
|
||||
|
||||
public interface IRoomGrain : IGrainWithStringKey
|
||||
{
|
||||
public interface IRoomGrain : IGrainWithStringKey
|
||||
{
|
||||
Task SetRoom(Room room);
|
||||
Task<Room> JoinRoom(string connectionId, string userName);
|
||||
Task<Room> LeaveRoom(string connectionId);
|
||||
Task<Room> UpdatePlayerState(TimeSpan seconds, PlayerState playerState);
|
||||
}
|
||||
Task SetRoom(Room room);
|
||||
Task<Room> JoinRoom(string connectionId, string userName);
|
||||
Task<Room> LeaveRoom(string connectionId);
|
||||
Task<Room> UpdatePlayerState(TimeSpan seconds, PlayerState playerState);
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ public class Room
|
|||
{
|
||||
private const int Length = 5;
|
||||
private const string ValidCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||
private readonly Random _randGenerator = new();
|
||||
private readonly Random _randGenerator = Random.Shared;
|
||||
|
||||
public Room ()
|
||||
{
|
||||
|
|
|
@ -28,7 +28,7 @@ public class PodcastIngestionHandler : IPodcastIngestionHandler
|
|||
CancellationToken stoppingToken)
|
||||
{
|
||||
_logger.LogInformation($"The show {title} at {url} was received by the ingestion worker.");
|
||||
var isExistingShow = await _podcastDbContext.Feeds.AnyAsync(feed => feed.Url.ToLower() == url.ToLower(), stoppingToken);
|
||||
var isExistingShow = await _podcastDbContext.Feeds.AnyAsync(feed => string.Equals(feed.Url, url, StringComparison.OrdinalIgnoreCase), stoppingToken);
|
||||
if (isExistingShow)
|
||||
return;
|
||||
|
||||
|
@ -37,19 +37,9 @@ public class PodcastIngestionHandler : IPodcastIngestionHandler
|
|||
if (!isAcceptedTopic)
|
||||
{
|
||||
_logger.LogInformation($"The show {title} at {url} was not automatically approved.");
|
||||
var categoryStringArray = string.Empty;
|
||||
foreach (var cat in feedCategories)
|
||||
{
|
||||
categoryStringArray += $"{cat},";
|
||||
}
|
||||
|
||||
if(categoryStringArray.Contains(","))
|
||||
{
|
||||
categoryStringArray = categoryStringArray.Substring(0, categoryStringArray.LastIndexOf(','));
|
||||
}
|
||||
|
||||
// Must be manually approved
|
||||
var userFeed = new UserSubmittedFeed(title, url, categoryStringArray);
|
||||
var userFeed = new UserSubmittedFeed(
|
||||
title, url, string.Join(",", feedCategories));
|
||||
await _podcastDbContext.UserSubmittedFeeds.AddAsync(userFeed, stoppingToken);
|
||||
await _podcastDbContext.SaveChangesAsync(stoppingToken);
|
||||
_logger.LogInformation($"The show {title} at {url} was saved as a user-submitted feed.");
|
||||
|
|
Loading…
Reference in New Issue