From 759066731e7f199583e69852a50c7a7f91307199 Mon Sep 17 00:00:00 2001 From: defnotken Date: Sat, 27 Dec 2025 21:57:01 -0600 Subject: [PATCH] Fix Async hiccup in chat. --- LightlessSync/UI/ZoneChatUi.cs | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/LightlessSync/UI/ZoneChatUi.cs b/LightlessSync/UI/ZoneChatUi.cs index 036e7d3..cb6dae8 100644 --- a/LightlessSync/UI/ZoneChatUi.cs +++ b/LightlessSync/UI/ZoneChatUi.cs @@ -1000,23 +1000,26 @@ public sealed class ZoneChatUi : WindowMediatorSubscriberBase if (sanitized is not null) { TrackPendingDraftClear(channel.Key, sanitized); + draft = string.Empty; + _draftMessages[channel.Key] = draft; + _scrollToBottom = true; - if (TrySendDraft(channel, sanitized)) + _ = Task.Run(async () => { - _scrollToBottom = true; - - if (_draftMessages.TryGetValue(channel.Key, out var current) && - string.Equals(current, draftAtSend, StringComparison.Ordinal)) + try { - draft = string.Empty; - _draftMessages[channel.Key] = draft; + var succeeded = await _zoneChatService.SendMessageAsync(channel.Descriptor, sanitized).ConfigureAwait(false); + if (!succeeded) + { + RemovePendingDraftClear(channel.Key, sanitized); + } } - - } - else - { - RemovePendingDraftClear(channel.Key, sanitized); - } + catch (Exception ex) + { + _logger.LogWarning(ex, "Failed to send chat message"); + RemovePendingDraftClear(channel.Key, sanitized); + } + }); } } }