Fix Async hiccup in chat.

This commit is contained in:
defnotken
2025-12-27 21:57:01 -06:00
parent ff88e5f856
commit 759066731e

View File

@@ -1000,23 +1000,26 @@ public sealed class ZoneChatUi : WindowMediatorSubscriberBase
if (sanitized is not null) if (sanitized is not null)
{ {
TrackPendingDraftClear(channel.Key, sanitized); TrackPendingDraftClear(channel.Key, sanitized);
draft = string.Empty;
_draftMessages[channel.Key] = draft;
_scrollToBottom = true;
if (TrySendDraft(channel, sanitized)) _ = Task.Run(async () =>
{ {
_scrollToBottom = true; try
if (_draftMessages.TryGetValue(channel.Key, out var current) &&
string.Equals(current, draftAtSend, StringComparison.Ordinal))
{ {
draft = string.Empty; var succeeded = await _zoneChatService.SendMessageAsync(channel.Descriptor, sanitized).ConfigureAwait(false);
_draftMessages[channel.Key] = draft; if (!succeeded)
{
RemovePendingDraftClear(channel.Key, sanitized);
}
} }
catch (Exception ex)
} {
else _logger.LogWarning(ex, "Failed to send chat message");
{ RemovePendingDraftClear(channel.Key, sanitized);
RemovePendingDraftClear(channel.Key, sanitized); }
} });
} }
} }
} }