using System.Collections.Concurrent; using System.Text.Json; using Serilog; namespace TwitchChatTTS.Hermes.Socket.Requests { public class GetTTSUsersAck : IRequestAck { public string Name => "get_tts_users"; private readonly User _user; private readonly JsonSerializerOptions _options; private readonly ILogger _logger; public GetTTSUsersAck(User user, JsonSerializerOptions options, ILogger logger) { _user = user; _options = options; _logger = logger; } public void Acknowledge(string requestId, string json, IDictionary? requestData) { var users = JsonSerializer.Deserialize>(json, _options); if (users == null) return; var temp = new ConcurrentDictionary(); foreach (var entry in users) temp.TryAdd(entry.Key, entry.Value); _user.VoicesSelected = temp; _logger.Information($"Updated chatters' selected voice [count: {temp.Count()}]"); } } }