Code cleanup

This commit is contained in:
Stone_Red
2026-07-16 14:00:45 +02:00
parent 1a18b37279
commit 4b0a06db4e
6 changed files with 67 additions and 51 deletions
+7 -8
View File
@@ -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<ServerConnection?> 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
}
+8 -8
View File
@@ -139,21 +139,21 @@ public sealed class MainWindowViewModel : ViewModelBase
private async Task<string?> 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,
+10 -4
View File
@@ -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;
+7 -8
View File
@@ -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<ButtonResult> 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<ButtonResult> 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<ButtonResult> box = MessageBoxManager.GetMessageBoxStandard("Validation", "Server URL, username, and password are required.", ButtonEnum.Ok);
_ = await box.ShowWindowDialogAsync(this);
return;
}
+29 -20
View File
@@ -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(),
};
}
}
+6 -3
View File
@@ -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<T>(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;
}
}