mirror of
https://github.com/Stone-Red-Code/Decho.git
synced 2026-09-04 08:56:14 +02:00
Code cleanup
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
using Decho.Models;
|
using Decho.Models;
|
||||||
|
|
||||||
using EchoHub.Client.Commands;
|
|
||||||
using EchoHub.Client.Config;
|
using EchoHub.Client.Config;
|
||||||
using EchoHub.Client.Services;
|
using EchoHub.Client.Services;
|
||||||
using EchoHub.Client.UI.Dialogs;
|
using EchoHub.Client.UI.Dialogs;
|
||||||
@@ -90,7 +89,7 @@ public sealed class ConnectionService : IDisposable
|
|||||||
{
|
{
|
||||||
ConnectDialogResult dialogResult = new ConnectDialogResult(
|
ConnectDialogResult dialogResult = new ConnectDialogResult(
|
||||||
serverUrl, username, "", false, rememberMe, refreshToken);
|
serverUrl, username, "", false, rememberMe, refreshToken);
|
||||||
await ConnectCoreAsync(dialogResult);
|
_ = await ConnectCoreAsync(dialogResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<ServerConnection?> CleanupConnectionAsync(string serverUrl)
|
private async Task<ServerConnection?> CleanupConnectionAsync(string serverUrl)
|
||||||
@@ -122,7 +121,7 @@ public sealed class ConnectionService : IDisposable
|
|||||||
|
|
||||||
public async Task RemoveServerAsync(string serverUrl)
|
public async Task RemoveServerAsync(string serverUrl)
|
||||||
{
|
{
|
||||||
await CleanupConnectionAsync(serverUrl);
|
_ = await CleanupConnectionAsync(serverUrl);
|
||||||
RemoveServerFromConfig(serverUrl);
|
RemoveServerFromConfig(serverUrl);
|
||||||
ServerRemoved?.Invoke(serverUrl);
|
ServerRemoved?.Invoke(serverUrl);
|
||||||
}
|
}
|
||||||
@@ -166,7 +165,7 @@ public sealed class ConnectionService : IDisposable
|
|||||||
|
|
||||||
if (entry.Manager.TrackChannel(channelName))
|
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();
|
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);
|
await using FileStream stream = File.OpenRead(filePath);
|
||||||
string fileName = Path.GetFileName(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);
|
_ = await entry.ApiClient.SendMessageWithAttachmentsAsync(channelName, "", [attachment], size);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -441,11 +440,11 @@ public sealed class ConnectionService : IDisposable
|
|||||||
}
|
}
|
||||||
|
|
||||||
byte[] bytes = await File.ReadAllBytesAsync(tempPath);
|
byte[] bytes = await File.ReadAllBytesAsync(tempPath);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
File.Delete(tempPath);
|
File.Delete(tempPath);
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
// Ignore if deletion fails
|
// Ignore if deletion fails
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -139,21 +139,21 @@ public sealed class MainWindowViewModel : ViewModelBase
|
|||||||
|
|
||||||
private async Task<string?> ShowPasswordPromptWindowAsync()
|
private async Task<string?> ShowPasswordPromptWindowAsync()
|
||||||
{
|
{
|
||||||
var window = new Avalonia.Controls.Window
|
Window window = new Avalonia.Controls.Window
|
||||||
{
|
{
|
||||||
Title = "Channel Password",
|
Title = "Channel Password",
|
||||||
Width = 320,
|
Width = 320,
|
||||||
Height = 180,
|
Height = 180,
|
||||||
WindowStartupLocation = Avalonia.Controls.WindowStartupLocation.CenterOwner,
|
WindowStartupLocation = WindowStartupLocation.CenterOwner,
|
||||||
SizeToContent = Avalonia.Controls.SizeToContent.Height,
|
SizeToContent = SizeToContent.Height,
|
||||||
CanResize = false,
|
CanResize = false,
|
||||||
};
|
};
|
||||||
|
|
||||||
var passwordBox = new Avalonia.Controls.TextBox { Watermark = "Password", PasswordChar = '*' };
|
TextBox passwordBox = new Avalonia.Controls.TextBox { Watermark = "Password", PasswordChar = '*' };
|
||||||
string? result = null;
|
string? result = null;
|
||||||
|
|
||||||
var joinBtn = new Avalonia.Controls.Button { Content = "Join", IsDefault = true };
|
Button joinBtn = new Avalonia.Controls.Button { Content = "Join", IsDefault = true };
|
||||||
var cancelBtn = new Avalonia.Controls.Button { Content = "Cancel", IsCancel = true };
|
Button cancelBtn = new Avalonia.Controls.Button { Content = "Cancel", IsCancel = true };
|
||||||
|
|
||||||
joinBtn.Click += (_, _) =>
|
joinBtn.Click += (_, _) =>
|
||||||
{
|
{
|
||||||
@@ -162,7 +162,7 @@ public sealed class MainWindowViewModel : ViewModelBase
|
|||||||
};
|
};
|
||||||
cancelBtn.Click += (_, _) => window.Close();
|
cancelBtn.Click += (_, _) => window.Close();
|
||||||
|
|
||||||
var buttons = new Avalonia.Controls.StackPanel
|
StackPanel buttons = new Avalonia.Controls.StackPanel
|
||||||
{
|
{
|
||||||
Orientation = Avalonia.Layout.Orientation.Horizontal,
|
Orientation = Avalonia.Layout.Orientation.Horizontal,
|
||||||
HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Right,
|
HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Right,
|
||||||
@@ -170,7 +170,7 @@ public sealed class MainWindowViewModel : ViewModelBase
|
|||||||
Children = { cancelBtn, joinBtn },
|
Children = { cancelBtn, joinBtn },
|
||||||
};
|
};
|
||||||
|
|
||||||
var panel = new Avalonia.Controls.StackPanel
|
StackPanel panel = new Avalonia.Controls.StackPanel
|
||||||
{
|
{
|
||||||
Margin = new Avalonia.Thickness(12),
|
Margin = new Avalonia.Thickness(12),
|
||||||
Spacing = 8,
|
Spacing = 8,
|
||||||
|
|||||||
@@ -22,11 +22,17 @@ public sealed class MessageViewModel(MessageModel model) : ViewModelBase
|
|||||||
string? color = Model.Author.NicknameColor;
|
string? color = Model.Author.NicknameColor;
|
||||||
if (string.IsNullOrEmpty(color))
|
if (string.IsNullOrEmpty(color))
|
||||||
{
|
{
|
||||||
return null;
|
return Brushes.White;
|
||||||
}
|
}
|
||||||
|
|
||||||
try { return new SolidColorBrush(Avalonia.Media.Color.Parse(color)); }
|
try
|
||||||
catch { return null; }
|
{
|
||||||
|
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 IsImage => Type == MessageType.Image;
|
||||||
|
|
||||||
public bool ShowContent => !IsImage && !IsFile;
|
public bool ShowContent => !string.IsNullOrEmpty(Content);
|
||||||
|
|
||||||
public bool IsAudio => Type == MessageType.Audio;
|
public bool IsAudio => Type == MessageType.Audio;
|
||||||
|
|
||||||
|
|||||||
@@ -3,10 +3,9 @@ using Avalonia.Controls;
|
|||||||
using EchoHub.Client.Config;
|
using EchoHub.Client.Config;
|
||||||
|
|
||||||
using MsBox.Avalonia;
|
using MsBox.Avalonia;
|
||||||
|
using MsBox.Avalonia.Base;
|
||||||
using MsBox.Avalonia.Enums;
|
using MsBox.Avalonia.Enums;
|
||||||
|
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
namespace Decho.Views;
|
namespace Decho.Views;
|
||||||
|
|
||||||
public sealed partial class ConnectDialogWindow : Window
|
public sealed partial class ConnectDialogWindow : Window
|
||||||
@@ -69,8 +68,8 @@ public sealed partial class ConnectDialogWindow : Window
|
|||||||
|
|
||||||
if (string.IsNullOrEmpty(url) || string.IsNullOrEmpty(user))
|
if (string.IsNullOrEmpty(url) || string.IsNullOrEmpty(user))
|
||||||
{
|
{
|
||||||
var box = MessageBoxManager.GetMessageBoxStandard("Validation", "Server URL and username are required.", ButtonEnum.Ok);
|
IMsBox<ButtonResult> box = MessageBoxManager.GetMessageBoxStandard("Validation", "Server URL and username are required.", ButtonEnum.Ok);
|
||||||
await box.ShowWindowDialogAsync(this);
|
_ = await box.ShowWindowDialogAsync(this);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,8 +93,8 @@ public sealed partial class ConnectDialogWindow : Window
|
|||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(pass))
|
if (string.IsNullOrEmpty(pass))
|
||||||
{
|
{
|
||||||
var box = MessageBoxManager.GetMessageBoxStandard("Validation", "Password is required.", ButtonEnum.Ok);
|
IMsBox<ButtonResult> box = MessageBoxManager.GetMessageBoxStandard("Validation", "Password is required.", ButtonEnum.Ok);
|
||||||
await box.ShowWindowDialogAsync(this);
|
_ = await box.ShowWindowDialogAsync(this);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,8 +117,8 @@ public sealed partial class ConnectDialogWindow : Window
|
|||||||
|
|
||||||
if (string.IsNullOrEmpty(url) || string.IsNullOrEmpty(user) || string.IsNullOrEmpty(pass))
|
if (string.IsNullOrEmpty(url) || string.IsNullOrEmpty(user) || string.IsNullOrEmpty(pass))
|
||||||
{
|
{
|
||||||
var box = MessageBoxManager.GetMessageBoxStandard("Validation", "Server URL, username, and password are required.", ButtonEnum.Ok);
|
IMsBox<ButtonResult> box = MessageBoxManager.GetMessageBoxStandard("Validation", "Server URL, username, and password are required.", ButtonEnum.Ok);
|
||||||
await box.ShowWindowDialogAsync(this);
|
_ = await box.ShowWindowDialogAsync(this);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -56,29 +56,38 @@ public sealed partial class ProfileWindow : Window
|
|||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string FormatStatus(UserStatus status) => status switch
|
private static string FormatStatus(UserStatus status)
|
||||||
{
|
{
|
||||||
UserStatus.Online => "Online",
|
return status switch
|
||||||
UserStatus.Away => "Away",
|
{
|
||||||
UserStatus.DoNotDisturb => "Do Not Disturb",
|
UserStatus.Online => "Online",
|
||||||
UserStatus.Invisible => "Invisible",
|
UserStatus.Away => "Away",
|
||||||
_ => "Unknown",
|
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),
|
return status switch
|
||||||
UserStatus.Away => new SolidColorBrush(Colors.Goldenrod),
|
{
|
||||||
UserStatus.DoNotDisturb => new SolidColorBrush(Colors.IndianRed),
|
UserStatus.Online => new SolidColorBrush(Colors.LimeGreen),
|
||||||
UserStatus.Invisible => new SolidColorBrush(Colors.Gray),
|
UserStatus.Away => new SolidColorBrush(Colors.Goldenrod),
|
||||||
_ => new SolidColorBrush(Colors.White),
|
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",
|
return role switch
|
||||||
ServerRole.Mod => "Mod",
|
{
|
||||||
ServerRole.Member => "Member",
|
ServerRole.Admin => "Admin",
|
||||||
_ => role.ToString(),
|
ServerRole.Mod => "Mod",
|
||||||
};
|
ServerRole.Member => "Member",
|
||||||
|
_ => role.ToString(),
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
using Avalonia;
|
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
|
|
||||||
using Decho.ViewModels;
|
using Decho.ViewModels;
|
||||||
@@ -8,8 +7,12 @@ namespace Decho.Views;
|
|||||||
internal static class ViewExtensions
|
internal static class ViewExtensions
|
||||||
{
|
{
|
||||||
public static T? GetDataContext<T>(this Control control) where T : class
|
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)
|
public static MainWindowViewModel? GetMainWindowViewModel(this Control control)
|
||||||
=> TopLevel.GetTopLevel(control)?.DataContext as MainWindowViewModel;
|
{
|
||||||
|
return TopLevel.GetTopLevel(control)?.DataContext as MainWindowViewModel;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user