Nullify ChannelMapping

This commit is contained in:
Jordan Dominion
2023-12-14 17:42:35 -05:00
parent a02768e686
commit be29aa0a8e
2 changed files with 14 additions and 7 deletions
@@ -1,4 +1,4 @@
#nullable disable
using System;
namespace Tgstation.Server.Host.Components.Chat
{
@@ -40,6 +40,15 @@ namespace Tgstation.Server.Host.Components.Chat
/// <summary>
/// The <see cref="ChannelRepresentation"/> with the mapped Id.
/// </summary>
public ChannelRepresentation Channel { get; set; }
public ChannelRepresentation Channel { get; }
/// <summary>
/// Initializes a new instance of the <see cref="ChannelMapping"/> class.
/// </summary>
/// <param name="channel">The value of <see cref="Channel"/>.</param>
public ChannelMapping(ChannelRepresentation channel)
{
Channel = channel ?? throw new ArgumentNullException(nameof(channel));
}
}
}
@@ -71,7 +71,7 @@ namespace Tgstation.Server.Host.Components.Chat
readonly Dictionary<long, IProvider> providers;
/// <summary>
/// Map of <see cref="SemaphoreSlim"/>s used to guard concurrent access to <see cref="ChangeChannels(long, IEnumerable{Models.ChatChannel}, CancellationToken)"/>, keyed by <see cref="ChatBotSettings"/> <see cref="Api.Models.EntityId.Id"/>.
/// Map of <see cref="SemaphoreSlim"/>s used to guard concurrent access to <see cref="ChangeChannels(long, IEnumerable{Models.ChatChannel}, CancellationToken)"/>, keyed by <see cref="ChatBotSettings"/> <see cref="EntityId.Id"/>.
/// </summary>
readonly ConcurrentDictionary<long, SemaphoreSlim> changeChannelSemaphores;
@@ -236,7 +236,7 @@ namespace Tgstation.Server.Host.Components.Chat
var newMappings = results.SelectMany(
kvp => kvp.Value.Select(
channelRepresentation => new ChannelMapping
channelRepresentation => new ChannelMapping(channelRepresentation)
{
IsWatchdogChannel = kvp.Key.IsWatchdogChannel == true,
IsUpdatesChannel = kvp.Key.IsUpdatesChannel == true,
@@ -244,7 +244,6 @@ namespace Tgstation.Server.Host.Components.Chat
IsSystemChannel = kvp.Key.IsSystemChannel == true,
ProviderChannelId = channelRepresentation.RealId,
ProviderId = connectionId,
Channel = channelRepresentation,
}));
ulong baseId;
@@ -767,11 +766,10 @@ namespace Tgstation.Server.Host.Components.Chat
message.User.Channel.ConnectionName,
message.User.FriendlyName,
newId);
mappedChannels.Add(newId, new ChannelMapping
mappedChannels.Add(newId, new ChannelMapping(message.User.Channel)
{
ProviderChannelId = message.User.Channel.RealId,
ProviderId = providerId,
Channel = message.User.Channel,
});
logger.LogTrace(