using System; using System.Threading.Tasks; using LibMatrix.Services; using ModerationClient.Services; namespace ModerationClient.ViewModels; public partial class LoginViewModel(MatrixAuthenticationService authService, HomeserverResolverService hsResolver) : ViewModelBase { private Exception? _exception; public string Username { get; set; } public string? Homeserver { get; set; } public string Password { get; set; } public Exception? Exception { get => _exception; private set => SetProperty(ref _exception, value); } public async Task ResolveHomeserverAsync() { try { string[] parts = Username.Split(':', 2); Homeserver = (await hsResolver.ResolveHomeserverFromWellKnown(Username, enableServer: false)).Client; } catch (Exception e) { Console.WriteLine(e); } } public async Task LoginAsync() { try { Exception = null; await authService.LoginAsync(Username, Password); } catch (Exception e) { Exception = e; } } }