From 05d20c92889760d4753a5c2bf64a86e2ce5a72d7 Mon Sep 17 00:00:00 2001 From: Stone_Red <56473591+Stone-Red-Code@users.noreply.github.com> Date: Thu, 16 Jul 2026 00:35:24 +0200 Subject: [PATCH] Add user profile dialog --- src/Decho/Services/ConnectionService.cs | 10 +++ src/Decho/ViewModels/MainWindowViewModel.cs | 39 +++++++++- src/Decho/Views/ProfileWindow.axaml | 72 ++++++++++++++++++ src/Decho/Views/ProfileWindow.axaml.cs | 84 +++++++++++++++++++++ 4 files changed, 204 insertions(+), 1 deletion(-) create mode 100644 src/Decho/Views/ProfileWindow.axaml create mode 100644 src/Decho/Views/ProfileWindow.axaml.cs diff --git a/src/Decho/Services/ConnectionService.cs b/src/Decho/Services/ConnectionService.cs index 6819698..0997c2d 100644 --- a/src/Decho/Services/ConnectionService.cs +++ b/src/Decho/Services/ConnectionService.cs @@ -347,6 +347,16 @@ public sealed class ConnectionService : IDisposable _ = await entry.ApiClient.UpdateProfileAsync(new UpdateProfileRequest(displayName, bio, nickColor)); } + public async Task GetUserProfileAsync(string serverUrl, string username) + { + if (!_connections.TryGetValue(serverUrl, out ServerConnection? entry)) + { + return null; + } + + return await entry.ApiClient.GetUserProfileAsync(username); + } + public async Task SetAvatarAsync(string serverUrl, string target) { if (!_connections.TryGetValue(serverUrl, out ServerConnection? entry)) diff --git a/src/Decho/ViewModels/MainWindowViewModel.cs b/src/Decho/ViewModels/MainWindowViewModel.cs index d96b42c..23cd2f5 100644 --- a/src/Decho/ViewModels/MainWindowViewModel.cs +++ b/src/Decho/ViewModels/MainWindowViewModel.cs @@ -2,6 +2,7 @@ using Avalonia.Controls; using Decho.Models; using Decho.Services; +using Decho.Views; using EchoHub.Client.Commands; using EchoHub.Client.Config; @@ -333,7 +334,43 @@ public sealed class MainWindowViewModel : ViewModelBase _commandHandler.OnOpenProfile += async username => { - StatusText = $"Profile: {username ?? "self"}"; + string serverUrl = GetCurrentServerUrl(); + if (string.IsNullOrEmpty(serverUrl)) + { + return; + } + + string target = username ?? ConnectionService.GetCurrentUsername(serverUrl) ?? string.Empty; + if (string.IsNullOrEmpty(target)) + { + return; + } + + try + { + UserProfileDto? profile = await ConnectionService.GetUserProfileAsync(serverUrl, target); + Avalonia.Threading.Dispatcher.UIThread.Post(() => + { + if (profile is null) + { + StatusText = "User not found"; + return; + } + + ProfileWindow dialog = new ProfileWindow(profile); + if (_mainWindow is not null) + { + _ = dialog.ShowDialog(_mainWindow); + } + }); + } + catch (Exception ex) + { + Avalonia.Threading.Dispatcher.UIThread.Post(() => + { + StatusText = $"Failed to load profile: {ex.Message}"; + }); + } }; _commandHandler.OnOpenServers += () => diff --git a/src/Decho/Views/ProfileWindow.axaml b/src/Decho/Views/ProfileWindow.axaml new file mode 100644 index 0000000..f743584 --- /dev/null +++ b/src/Decho/Views/ProfileWindow.axaml @@ -0,0 +1,72 @@ + + + +