net8, language features, bugfixes

This commit is contained in:
kkb 2023-12-18 16:31:00 +01:00
parent 1591618c2c
commit ce99053a10
353 changed files with 3245 additions and 3944 deletions

View file

@ -50,14 +50,16 @@ public partial class ChatDialog : IDisposable
private string? _currentMessage;
private bool _disposed;
private readonly List<IDisposable> _subscriptions = new();
private readonly List<IDisposable> _subscriptions = [];
protected override async Task OnInitializedAsync()
protected override Task OnInitializedAsync()
{
_subscriptions.Add(Bus.SubscribeAsync<ChatUserConnected>(UserConnected, p => p.User.Uid != SessionHandler.State.Uid));
_subscriptions.Add(Bus.SubscribeAsync<ChatUserDisconnected>(UserDisconnected, p => p.User.Uid != SessionHandler.State.Uid));
_subscriptions.Add(Bus.SubscribeAsync<ChatRefresh>(RefreshAsync, null));
_subscriptions.Add(Bus.SubscribeAsync<ChatMessageReceived>(MessageReceived, p => p.Message.SenderId != SessionHandler.State.Uid));
return Task.CompletedTask;
}
protected override async Task OnAfterRenderAsync(bool firstRender)
@ -82,6 +84,8 @@ public partial class ChatDialog : IDisposable
private async Task GetSessionAsync(ChatUser user)
{
if (_currentUser is null) return;
var members = new List<ChatUser>() { _currentUser, user };
var session = await ChatService.AddOrGetSession(members);
@ -93,7 +97,7 @@ public partial class ChatDialog : IDisposable
private async Task SendAsync()
{
if (_currentSession is null || string.IsNullOrWhiteSpace(_currentMessage)) return;
if (_currentSession is null || _currentUser is null || string.IsNullOrWhiteSpace(_currentMessage)) return;
await _currentSession.SendMessage(_currentUser, _currentMessage, default);
_currentMessage = string.Empty;
@ -118,11 +122,11 @@ public partial class ChatDialog : IDisposable
options.VisibleStateDuration = 10000;
});
_ = JSRuntime.InvokeAsync<string>("PlayAudio", "chat_user_online");
await JSRuntime.InvokeAsync<string>("PlayAudio", "chat_user_online");
}
catch (Exception ex)
{
Logger.LogError(ex.Message);
Logger.LogError("{exception}", ex.Message);
}
}
@ -141,17 +145,17 @@ public partial class ChatDialog : IDisposable
options.VisibleStateDuration = 10000;
});
_ = JSRuntime.InvokeAsync<string>("PlayAudio", "chat_user_online");
await JSRuntime.InvokeAsync<string>("PlayAudio", "chat_user_online");
}
catch (Exception ex)
{
Logger.LogError(ex.Message);
Logger.LogError("{exception}", ex.Message);
}
}
private async ValueTask RefreshAsync(ChatRefresh model, CancellationToken cancellationToken)
{
_ = InvokeAsync(StateHasChanged);
await InvokeAsync(StateHasChanged);
}
private async ValueTask MessageReceived(ChatMessageReceived model, CancellationToken cancellationToken)
@ -175,14 +179,14 @@ public partial class ChatDialog : IDisposable
if (_content != Content.Chat)
{
_ = JSRuntime.InvokeAsync<string>("PlayAudio", "chat_message");
await JSRuntime.InvokeAsync<string>("PlayAudio", "chat_message");
}
_ = InvokeAsync(StateHasChanged);
await InvokeAsync(StateHasChanged);
}
catch (Exception ex)
{
Logger.LogError(ex.ToString());
Logger.LogError("{exception}", ex.ToString());
}
}