diff --git a/src/Decho/Services/ConnectionService.cs b/src/Decho/Services/ConnectionService.cs index 9f00ae9..0f8499c 100644 --- a/src/Decho/Services/ConnectionService.cs +++ b/src/Decho/Services/ConnectionService.cs @@ -1,6 +1,5 @@ using Decho.Models; -using EchoHub.Client.Commands; using EchoHub.Client.Config; using EchoHub.Client.Services; using EchoHub.Client.UI.Dialogs; @@ -90,7 +89,7 @@ public sealed class ConnectionService : IDisposable { ConnectDialogResult dialogResult = new ConnectDialogResult( serverUrl, username, "", false, rememberMe, refreshToken); - await ConnectCoreAsync(dialogResult); + _ = await ConnectCoreAsync(dialogResult); } private async Task CleanupConnectionAsync(string serverUrl) @@ -122,7 +121,7 @@ public sealed class ConnectionService : IDisposable public async Task RemoveServerAsync(string serverUrl) { - await CleanupConnectionAsync(serverUrl); + _ = await CleanupConnectionAsync(serverUrl); RemoveServerFromConfig(serverUrl); ServerRemoved?.Invoke(serverUrl); } @@ -166,7 +165,7 @@ public sealed class ConnectionService : IDisposable if (entry.Manager.TrackChannel(channelName)) { - var outcome = await entry.Manager.JoinChannelAsync(channelName, password); + JoinOutcome outcome = await entry.Manager.JoinChannelAsync(channelName, password); return outcome.History.Select(m => MessageModelFromDto(m, entry)).ToList(); } @@ -357,7 +356,7 @@ public sealed class ConnectionService : IDisposable await using FileStream stream = File.OpenRead(filePath); string fileName = Path.GetFileName(filePath); - var attachment = new OutgoingAttachment(stream, fileName); + OutgoingAttachment attachment = new OutgoingAttachment(stream, fileName); _ = await entry.ApiClient.SendMessageWithAttachmentsAsync(channelName, "", [attachment], size); } @@ -441,11 +440,11 @@ public sealed class ConnectionService : IDisposable } byte[] bytes = await File.ReadAllBytesAsync(tempPath); - try - { + try + { File.Delete(tempPath); } - catch + catch { // Ignore if deletion fails } diff --git a/src/Decho/ViewModels/MainWindowViewModel.cs b/src/Decho/ViewModels/MainWindowViewModel.cs index 454fcbf..118fb0c 100644 --- a/src/Decho/ViewModels/MainWindowViewModel.cs +++ b/src/Decho/ViewModels/MainWindowViewModel.cs @@ -139,21 +139,21 @@ public sealed class MainWindowViewModel : ViewModelBase private async Task ShowPasswordPromptWindowAsync() { - var window = new Avalonia.Controls.Window + Window window = new Avalonia.Controls.Window { Title = "Channel Password", Width = 320, Height = 180, - WindowStartupLocation = Avalonia.Controls.WindowStartupLocation.CenterOwner, - SizeToContent = Avalonia.Controls.SizeToContent.Height, + WindowStartupLocation = WindowStartupLocation.CenterOwner, + SizeToContent = SizeToContent.Height, CanResize = false, }; - var passwordBox = new Avalonia.Controls.TextBox { Watermark = "Password", PasswordChar = '*' }; + TextBox passwordBox = new Avalonia.Controls.TextBox { Watermark = "Password", PasswordChar = '*' }; string? result = null; - var joinBtn = new Avalonia.Controls.Button { Content = "Join", IsDefault = true }; - var cancelBtn = new Avalonia.Controls.Button { Content = "Cancel", IsCancel = true }; + Button joinBtn = new Avalonia.Controls.Button { Content = "Join", IsDefault = true }; + Button cancelBtn = new Avalonia.Controls.Button { Content = "Cancel", IsCancel = true }; joinBtn.Click += (_, _) => { @@ -162,7 +162,7 @@ public sealed class MainWindowViewModel : ViewModelBase }; cancelBtn.Click += (_, _) => window.Close(); - var buttons = new Avalonia.Controls.StackPanel + StackPanel buttons = new Avalonia.Controls.StackPanel { Orientation = Avalonia.Layout.Orientation.Horizontal, HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Right, @@ -170,7 +170,7 @@ public sealed class MainWindowViewModel : ViewModelBase Children = { cancelBtn, joinBtn }, }; - var panel = new Avalonia.Controls.StackPanel + StackPanel panel = new Avalonia.Controls.StackPanel { Margin = new Avalonia.Thickness(12), Spacing = 8, diff --git a/src/Decho/ViewModels/MessageViewModel.cs b/src/Decho/ViewModels/MessageViewModel.cs index f8e919e..42fee20 100644 --- a/src/Decho/ViewModels/MessageViewModel.cs +++ b/src/Decho/ViewModels/MessageViewModel.cs @@ -22,11 +22,17 @@ public sealed class MessageViewModel(MessageModel model) : ViewModelBase string? color = Model.Author.NicknameColor; if (string.IsNullOrEmpty(color)) { - return null; + return Brushes.White; } - try { return new SolidColorBrush(Avalonia.Media.Color.Parse(color)); } - catch { return null; } + try + { + return new SolidColorBrush(Color.Parse(color)); + } + catch + { + return null; + } } } @@ -44,7 +50,7 @@ public sealed class MessageViewModel(MessageModel model) : ViewModelBase public bool IsImage => Type == MessageType.Image; - public bool ShowContent => !IsImage && !IsFile; + public bool ShowContent => !string.IsNullOrEmpty(Content); public bool IsAudio => Type == MessageType.Audio; diff --git a/src/Decho/Views/ConnectDialogWindow.axaml.cs b/src/Decho/Views/ConnectDialogWindow.axaml.cs index 1fa8a9b..66d832a 100644 --- a/src/Decho/Views/ConnectDialogWindow.axaml.cs +++ b/src/Decho/Views/ConnectDialogWindow.axaml.cs @@ -3,10 +3,9 @@ using Avalonia.Controls; using EchoHub.Client.Config; using MsBox.Avalonia; +using MsBox.Avalonia.Base; using MsBox.Avalonia.Enums; -using System.Linq; - namespace Decho.Views; public sealed partial class ConnectDialogWindow : Window @@ -69,8 +68,8 @@ public sealed partial class ConnectDialogWindow : Window if (string.IsNullOrEmpty(url) || string.IsNullOrEmpty(user)) { - var box = MessageBoxManager.GetMessageBoxStandard("Validation", "Server URL and username are required.", ButtonEnum.Ok); - await box.ShowWindowDialogAsync(this); + IMsBox box = MessageBoxManager.GetMessageBoxStandard("Validation", "Server URL and username are required.", ButtonEnum.Ok); + _ = await box.ShowWindowDialogAsync(this); return; } @@ -94,8 +93,8 @@ public sealed partial class ConnectDialogWindow : Window { if (string.IsNullOrEmpty(pass)) { - var box = MessageBoxManager.GetMessageBoxStandard("Validation", "Password is required.", ButtonEnum.Ok); - await box.ShowWindowDialogAsync(this); + IMsBox box = MessageBoxManager.GetMessageBoxStandard("Validation", "Password is required.", ButtonEnum.Ok); + _ = await box.ShowWindowDialogAsync(this); return; } @@ -118,8 +117,8 @@ public sealed partial class ConnectDialogWindow : Window if (string.IsNullOrEmpty(url) || string.IsNullOrEmpty(user) || string.IsNullOrEmpty(pass)) { - var box = MessageBoxManager.GetMessageBoxStandard("Validation", "Server URL, username, and password are required.", ButtonEnum.Ok); - await box.ShowWindowDialogAsync(this); + IMsBox box = MessageBoxManager.GetMessageBoxStandard("Validation", "Server URL, username, and password are required.", ButtonEnum.Ok); + _ = await box.ShowWindowDialogAsync(this); return; } diff --git a/src/Decho/Views/ProfileWindow.axaml.cs b/src/Decho/Views/ProfileWindow.axaml.cs index 682cac1..c362074 100644 --- a/src/Decho/Views/ProfileWindow.axaml.cs +++ b/src/Decho/Views/ProfileWindow.axaml.cs @@ -56,29 +56,38 @@ public sealed partial class ProfileWindow : Window Close(); } - private static string FormatStatus(UserStatus status) => status switch + private static string FormatStatus(UserStatus status) { - UserStatus.Online => "Online", - UserStatus.Away => "Away", - UserStatus.DoNotDisturb => "Do Not Disturb", - UserStatus.Invisible => "Invisible", - _ => "Unknown", - }; + return status switch + { + UserStatus.Online => "Online", + UserStatus.Away => "Away", + UserStatus.DoNotDisturb => "Do Not Disturb", + UserStatus.Invisible => "Invisible", + _ => "Unknown", + }; + } - private static IBrush GetStatusBrush(UserStatus status) => status switch + private static IBrush GetStatusBrush(UserStatus status) { - UserStatus.Online => new SolidColorBrush(Colors.LimeGreen), - UserStatus.Away => new SolidColorBrush(Colors.Goldenrod), - UserStatus.DoNotDisturb => new SolidColorBrush(Colors.IndianRed), - UserStatus.Invisible => new SolidColorBrush(Colors.Gray), - _ => new SolidColorBrush(Colors.White), - }; + return status switch + { + UserStatus.Online => new SolidColorBrush(Colors.LimeGreen), + UserStatus.Away => new SolidColorBrush(Colors.Goldenrod), + UserStatus.DoNotDisturb => new SolidColorBrush(Colors.IndianRed), + UserStatus.Invisible => new SolidColorBrush(Colors.Gray), + _ => new SolidColorBrush(Colors.White), + }; + } - private static string FormatRole(ServerRole role) => role switch + private static string FormatRole(ServerRole role) { - ServerRole.Admin => "Admin", - ServerRole.Mod => "Mod", - ServerRole.Member => "Member", - _ => role.ToString(), - }; + return role switch + { + ServerRole.Admin => "Admin", + ServerRole.Mod => "Mod", + ServerRole.Member => "Member", + _ => role.ToString(), + }; + } } diff --git a/src/Decho/Views/ViewExtensions.cs b/src/Decho/Views/ViewExtensions.cs index 96d356a..58d4776 100644 --- a/src/Decho/Views/ViewExtensions.cs +++ b/src/Decho/Views/ViewExtensions.cs @@ -1,4 +1,3 @@ -using Avalonia; using Avalonia.Controls; using Decho.ViewModels; @@ -8,8 +7,12 @@ namespace Decho.Views; internal static class ViewExtensions { public static T? GetDataContext(this Control control) where T : class - => control.DataContext as T; + { + return control.DataContext as T; + } public static MainWindowViewModel? GetMainWindowViewModel(this Control control) - => TopLevel.GetTopLevel(control)?.DataContext as MainWindowViewModel; + { + return TopLevel.GetTopLevel(control)?.DataContext as MainWindowViewModel; + } }