From b76772e4f9d90cdb19db6f7d8149113c4cb539fc Mon Sep 17 00:00:00 2001 From: Tom Date: Mon, 12 Aug 2024 08:28:55 +0000 Subject: [PATCH] Including more data in Login Acknowledgements --- Socket/Handlers/HermesLoginHandler.cs | 37 +++++++++++++++++++-------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/Socket/Handlers/HermesLoginHandler.cs b/Socket/Handlers/HermesLoginHandler.cs index b692bb7..d425099 100644 --- a/Socket/Handlers/HermesLoginHandler.cs +++ b/Socket/Handlers/HermesLoginHandler.cs @@ -49,11 +49,14 @@ namespace HermesSocketServer.Socket.Handlers sender.WebLogin = data.WebLogin; } - string sql2 = "select name, role from \"User\" where id = @user"; - await _database.Execute(sql2, new Dictionary() { { "user", userId } }, sql => + var userIdDict = new Dictionary() { { "user", userId } }; + string? ttsDefaultVoice = null; + string sql2 = "select name, role, \"ttsDefaultVoice\" from \"User\" where id = @user"; + await _database.Execute(sql2, userIdDict, sql => { sender.Name = sql.GetString(0); sender.Admin = sql.GetString(1) == "ADMIN"; + ttsDefaultVoice = sql.GetString(2); }); if (string.IsNullOrEmpty(sender.Name)) @@ -70,10 +73,10 @@ namespace HermesSocketServer.Socket.Handlers WebLogin = data.WebLogin, }; - var connections = new List(); + ack.Connections = new List(); string sql3 = "select \"name\", \"type\", \"clientId\", \"accessToken\", \"grantType\", \"scope\", \"expiresAt\", \"default\" from \"Connection\" where \"userId\" = @user"; - await _database.Execute(sql3, new Dictionary() { { "user", userId } }, sql => - connections.Add(new Connection() + await _database.Execute(sql3, userIdDict, sql => + ack.Connections.Add(new Connection() { Name = sql.GetString(0), Type = sql.GetString(1), @@ -81,20 +84,32 @@ namespace HermesSocketServer.Socket.Handlers AccessToken = sql.GetString(3), GrantType = sql.GetString(4), Scope = sql.GetString(5), - ExpiresIn = sql.GetDateTime(6), + ExpiresAt = sql.GetDateTime(6), Default = sql.GetBoolean(7) }) ); - ack.Connections = connections.ToArray(); - IList voices = new List(); + ack.TTSVoicesAvailable = new Dictionary(); string sql4 = "SELECT id, name FROM \"TtsVoice\""; - await _database.Execute(sql4, (IDictionary?) null, (r) => voices.Add(new VoiceDetails() + await _database.Execute(sql4, (IDictionary?) null, (r) => ack.TTSVoicesAvailable.Add(r.GetString(0), r.GetString(1))); + + ack.EnabledTTSVoices = new List(); + string sql5 = $"SELECT v.name FROM \"TtsVoiceState\" s " + + "INNER JOIN \"TtsVoice\" v ON s.\"ttsVoiceId\" = v.id " + + "WHERE \"userId\" = @user AND state = true"; + await _database.Execute(sql5, userIdDict, (r) => ack.EnabledTTSVoices.Add(r.GetString(0))); + + ack.WordFilters = new List(); + string sql6 = $"SELECT id, search, replace FROM \"TtsWordFilter\" WHERE \"userId\" = @user"; + await _database.Execute(sql6, userIdDict, (r) => ack.WordFilters.Add(new TTSWordFilter() { Id = r.GetString(0), - Name = r.GetString(1) + Search = r.GetString(1), + Replace = r.GetString(2) })); - ack.TTSVoicesAvailable = voices.ToDictionary(e => e.Id, e => e.Name); + + if (ttsDefaultVoice != null) + ack.DefaultTTSVoice = ttsDefaultVoice; await sender.Send(2, ack);