Imap flow.
This commit is contained in:
@@ -103,7 +103,10 @@ public partial class AccountManagementViewModel : AccountManagementPageViewModel
|
||||
return;
|
||||
}
|
||||
|
||||
Messenger.Send(new BreadcrumbNavigationRequested(Translator.WelcomeWizard_Step2Title, WinoPage.ProviderSelectionPage));
|
||||
Messenger.Send(new BreadcrumbNavigationRequested(
|
||||
Translator.WelcomeWizard_Step2Title,
|
||||
WinoPage.ProviderSelectionPage,
|
||||
ProviderSelectionNavigationContext.CreateForSettingsAddAccount()));
|
||||
}
|
||||
|
||||
public Task StartAddNewAccountAsync() => AddNewAccountAsync();
|
||||
|
||||
@@ -10,7 +10,8 @@ public enum ImapCalDavSettingsPageMode
|
||||
{
|
||||
Create,
|
||||
Edit,
|
||||
Wizard
|
||||
Wizard,
|
||||
AddAccount
|
||||
}
|
||||
|
||||
public sealed class ImapCalDavSettingsNavigationContext
|
||||
@@ -45,6 +46,14 @@ public sealed class ImapCalDavSettingsNavigationContext
|
||||
AccountCreationDialogResult = accountCreationDialogResult
|
||||
};
|
||||
|
||||
public static ImapCalDavSettingsNavigationContext CreateForAddAccountMode(
|
||||
AccountCreationDialogResult accountCreationDialogResult)
|
||||
=> new()
|
||||
{
|
||||
Mode = ImapCalDavSettingsPageMode.AddAccount,
|
||||
AccountCreationDialogResult = accountCreationDialogResult
|
||||
};
|
||||
|
||||
public bool IsWizardMode => Mode == ImapCalDavSettingsPageMode.Wizard;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ using Wino.Core.Domain.Models.AutoDiscovery;
|
||||
using Wino.Core.Domain.Models.Calendar;
|
||||
using Wino.Core.Domain.Models.Navigation;
|
||||
using Wino.Core.Domain.Models.Synchronization;
|
||||
using Wino.Core.Domain.Validation;
|
||||
using Wino.Core.Services;
|
||||
using Wino.Mail.ViewModels.Data;
|
||||
using Wino.Messaging.Client.Navigation;
|
||||
@@ -135,7 +136,7 @@ public partial class ImapCalDavSettingsPageViewModel : MailBaseViewModel
|
||||
[NotifyPropertyChangedFor(nameof(IsAdvancedSetupSelected))]
|
||||
private int selectedSetupTabIndex;
|
||||
|
||||
public bool IsCreateMode => _pageMode == ImapCalDavSettingsPageMode.Create;
|
||||
public bool IsCreateMode => _pageMode is ImapCalDavSettingsPageMode.Create or ImapCalDavSettingsPageMode.AddAccount;
|
||||
public bool IsEditMode => !IsCreateMode;
|
||||
public bool HasProviderHint => !string.IsNullOrWhiteSpace(ProviderHint);
|
||||
public bool IsBasicSetupSelected => SelectedSetupTabIndex == 0;
|
||||
@@ -289,7 +290,7 @@ public partial class ImapCalDavSettingsPageViewModel : MailBaseViewModel
|
||||
_localOnlyInfoShown = false;
|
||||
SelectedSetupTabIndex = 0;
|
||||
|
||||
if (_pageMode == ImapCalDavSettingsPageMode.Create || _pageMode == ImapCalDavSettingsPageMode.Wizard)
|
||||
if (_pageMode is ImapCalDavSettingsPageMode.Create or ImapCalDavSettingsPageMode.Wizard or ImapCalDavSettingsPageMode.AddAccount)
|
||||
{
|
||||
PageTitle = Translator.ImapCalDavSettingsPage_TitleCreate;
|
||||
ApplyCreateContextDefaults(context.AccountCreationDialogResult);
|
||||
@@ -412,7 +413,7 @@ public partial class ImapCalDavSettingsPageViewModel : MailBaseViewModel
|
||||
? _editingAccountId
|
||||
: (Guid?)null;
|
||||
|
||||
if (!await ValidateAccountUniquenessAsync(excludedAccountId).ConfigureAwait(false))
|
||||
if (!await ValidateAccountUniquenessAsync(excludedAccountId))
|
||||
return;
|
||||
|
||||
await ValidateImapConnectivityAsync(serverInformation);
|
||||
@@ -434,6 +435,12 @@ public partial class ImapCalDavSettingsPageViewModel : MailBaseViewModel
|
||||
return;
|
||||
}
|
||||
|
||||
if (_pageMode == ImapCalDavSettingsPageMode.AddAccount)
|
||||
{
|
||||
CompleteAddAccountFlow(serverInformation);
|
||||
return;
|
||||
}
|
||||
|
||||
if (_pageMode == ImapCalDavSettingsPageMode.Create)
|
||||
{
|
||||
CompleteCreateFlow(serverInformation);
|
||||
@@ -464,6 +471,12 @@ public partial class ImapCalDavSettingsPageViewModel : MailBaseViewModel
|
||||
}
|
||||
|
||||
private void CompleteWizardFlow(CustomServerInformation serverInformation)
|
||||
=> ContinueAccountCreationFlow(serverInformation);
|
||||
|
||||
private void CompleteAddAccountFlow(CustomServerInformation serverInformation)
|
||||
=> ContinueAccountCreationFlow(serverInformation);
|
||||
|
||||
private void ContinueAccountCreationFlow(CustomServerInformation serverInformation)
|
||||
{
|
||||
serverInformation.Id = Guid.NewGuid();
|
||||
serverInformation.AccountId = Guid.Empty;
|
||||
@@ -512,6 +525,31 @@ public partial class ImapCalDavSettingsPageViewModel : MailBaseViewModel
|
||||
}
|
||||
}
|
||||
|
||||
partial void OnEmailAddressChanged(string oldValue, string newValue)
|
||||
{
|
||||
var previousAddress = oldValue?.Trim() ?? string.Empty;
|
||||
var currentAddress = newValue?.Trim() ?? string.Empty;
|
||||
|
||||
ApplyCredentialDefaultsForAddress(previousAddress, currentAddress);
|
||||
ApplyManualServerDefaultsForAddress(previousAddress, currentAddress);
|
||||
|
||||
IsImapValidationSucceeded = false;
|
||||
IsCalDavValidationSucceeded = false;
|
||||
}
|
||||
|
||||
partial void OnPasswordChanged(string oldValue, string newValue)
|
||||
{
|
||||
var previousPassword = oldValue ?? string.Empty;
|
||||
var currentPassword = newValue ?? string.Empty;
|
||||
|
||||
IncomingServerPassword = ReplaceIfEmptyOrMatchingPrevious(IncomingServerPassword, previousPassword, currentPassword);
|
||||
OutgoingServerPassword = ReplaceIfEmptyOrMatchingPrevious(OutgoingServerPassword, previousPassword, currentPassword);
|
||||
CalDavPassword = ReplaceIfEmptyOrMatchingPrevious(CalDavPassword, previousPassword, currentPassword);
|
||||
|
||||
IsImapValidationSucceeded = false;
|
||||
IsCalDavValidationSucceeded = false;
|
||||
}
|
||||
|
||||
private async Task InitializeEditModeAsync(Guid accountId)
|
||||
{
|
||||
var account = await _accountService.GetAccountAsync(accountId);
|
||||
@@ -618,6 +656,50 @@ public partial class ImapCalDavSettingsPageViewModel : MailBaseViewModel
|
||||
SelectedOutgoingServerAuthenticationMethodIndex = 0;
|
||||
}
|
||||
|
||||
private void ApplyCredentialDefaultsForAddress(string previousAddress, string currentAddress)
|
||||
{
|
||||
IncomingServerUsername = ReplaceIfEmptyOrMatchingPrevious(IncomingServerUsername, previousAddress, currentAddress);
|
||||
OutgoingServerUsername = ReplaceIfEmptyOrMatchingPrevious(OutgoingServerUsername, previousAddress, currentAddress);
|
||||
CalDavUsername = ReplaceIfEmptyOrMatchingPrevious(CalDavUsername, previousAddress, currentAddress);
|
||||
}
|
||||
|
||||
private void ApplyManualServerDefaultsForAddress(string previousAddress, string currentAddress)
|
||||
{
|
||||
if (!MailAccountAddressValidator.TryGetDomain(currentAddress, out var currentDomain) ||
|
||||
!MailAccountAddressValidator.IsImplicitlyResolvableHost(currentDomain))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
MailAccountAddressValidator.TryGetDomain(previousAddress, out var previousDomain);
|
||||
|
||||
IncomingServer = ReplaceIfEmptyOrMatchingPrevious(IncomingServer, previousDomain, currentDomain);
|
||||
OutgoingServer = ReplaceIfEmptyOrMatchingPrevious(OutgoingServer, previousDomain, currentDomain);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(IncomingServerPort))
|
||||
IncomingServerPort = "993";
|
||||
|
||||
if (string.IsNullOrWhiteSpace(OutgoingServerPort))
|
||||
OutgoingServerPort = "587";
|
||||
}
|
||||
|
||||
private static string ReplaceIfEmptyOrMatchingPrevious(string currentValue, string previousValue, string replacementValue)
|
||||
{
|
||||
var normalizedCurrentValue = currentValue?.Trim() ?? string.Empty;
|
||||
var normalizedPreviousValue = previousValue?.Trim() ?? string.Empty;
|
||||
var normalizedReplacementValue = replacementValue?.Trim() ?? string.Empty;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(normalizedReplacementValue))
|
||||
return currentValue ?? string.Empty;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(normalizedCurrentValue))
|
||||
return normalizedReplacementValue;
|
||||
|
||||
return string.Equals(normalizedCurrentValue, normalizedPreviousValue, StringComparison.OrdinalIgnoreCase)
|
||||
? normalizedReplacementValue
|
||||
: currentValue ?? string.Empty;
|
||||
}
|
||||
|
||||
private void ApplyServerInformation(CustomServerInformation serverInformation)
|
||||
{
|
||||
if (serverInformation == null)
|
||||
@@ -809,7 +891,7 @@ public partial class ImapCalDavSettingsPageViewModel : MailBaseViewModel
|
||||
|
||||
private async Task SaveEditFlowAsync(CustomServerInformation serverInformation)
|
||||
{
|
||||
var account = await _accountService.GetAccountAsync(_editingAccountId).ConfigureAwait(false);
|
||||
var account = await _accountService.GetAccountAsync(_editingAccountId);
|
||||
if (account == null)
|
||||
throw new InvalidOperationException(Translator.Exception_NullAssignedAccount);
|
||||
|
||||
@@ -823,8 +905,8 @@ public partial class ImapCalDavSettingsPageViewModel : MailBaseViewModel
|
||||
account.ServerInformation = serverInformation;
|
||||
account.AttentionReason = AccountAttentionReason.None;
|
||||
|
||||
await _accountService.UpdateAccountCustomServerInformationAsync(serverInformation).ConfigureAwait(false);
|
||||
await _accountService.UpdateAccountAsync(account).ConfigureAwait(false);
|
||||
await _accountService.UpdateAccountCustomServerInformationAsync(serverInformation);
|
||||
await _accountService.UpdateAccountAsync(account);
|
||||
|
||||
Messenger.Send(new NewMailSynchronizationRequested(new MailSynchronizationOptions
|
||||
{
|
||||
@@ -916,7 +998,7 @@ public partial class ImapCalDavSettingsPageViewModel : MailBaseViewModel
|
||||
if (string.IsNullOrWhiteSpace(EmailAddress))
|
||||
throw new InvalidOperationException(Translator.IMAPAdvancedSetupDialog_ValidationEmailRequired);
|
||||
|
||||
if (!EmailValidation.EmailValidator.Validate(EmailAddress.Trim()))
|
||||
if (!MailAccountAddressValidator.IsValid(EmailAddress))
|
||||
throw new InvalidOperationException(Translator.IMAPAdvancedSetupDialog_ValidationEmailInvalid);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ public partial class ProviderSelectionPageViewModel : MailBaseViewModel
|
||||
private readonly IDialogServiceBase _dialogService;
|
||||
private readonly IProviderService _providerService;
|
||||
private readonly INewThemeService _themeService;
|
||||
private ProviderSelectionHostMode _hostMode = ProviderSelectionHostMode.Wizard;
|
||||
|
||||
public WelcomeWizardContext WizardContext { get; }
|
||||
|
||||
@@ -74,6 +75,16 @@ public partial class ProviderSelectionPageViewModel : MailBaseViewModel
|
||||
{
|
||||
base.OnNavigatedTo(mode, parameters);
|
||||
|
||||
var navigationContext = parameters as ProviderSelectionNavigationContext
|
||||
?? ProviderSelectionNavigationContext.CreateForWizard();
|
||||
|
||||
_hostMode = navigationContext.HostMode;
|
||||
|
||||
if (mode != NavigationMode.Back)
|
||||
{
|
||||
WizardContext.Reset();
|
||||
}
|
||||
|
||||
Providers = _providerService.GetAvailableProviders();
|
||||
AvailableColors = _themeService.GetAvailableAccountColors()
|
||||
.Select(hex => new AppColorViewModel(hex))
|
||||
@@ -135,9 +146,11 @@ public partial class ProviderSelectionPageViewModel : MailBaseViewModel
|
||||
|
||||
if (WizardContext.IsGenericImap)
|
||||
{
|
||||
// Navigate to ImapCalDavSettingsPage in wizard mode
|
||||
var context = ImapCalDavSettingsNavigationContext.CreateForWizardMode(
|
||||
WizardContext.BuildAccountCreationDialogResult());
|
||||
var context = _hostMode == ProviderSelectionHostMode.SettingsAddAccount
|
||||
? ImapCalDavSettingsNavigationContext.CreateForAddAccountMode(
|
||||
WizardContext.BuildAccountCreationDialogResult())
|
||||
: ImapCalDavSettingsNavigationContext.CreateForWizardMode(
|
||||
WizardContext.BuildAccountCreationDialogResult());
|
||||
|
||||
Messenger.Send(new BreadcrumbNavigationRequested(
|
||||
Translator.ImapCalDavSettingsPage_TitleCreate,
|
||||
|
||||
@@ -8,6 +8,7 @@ using Wino.Core.Domain;
|
||||
using Wino.Core.Domain.Enums;
|
||||
using Wino.Core.Domain.Interfaces;
|
||||
using Wino.Core.Domain.Models.Navigation;
|
||||
using Wino.Core.Domain.Validation;
|
||||
using Wino.Mail.ViewModels.Data;
|
||||
using Wino.Messaging.Client.Navigation;
|
||||
|
||||
@@ -99,7 +100,7 @@ public partial class SpecialImapCredentialsPageViewModel : MailBaseViewModel
|
||||
{
|
||||
CanProceed = !string.IsNullOrWhiteSpace(DisplayName)
|
||||
&& !string.IsNullOrWhiteSpace(EmailAddress)
|
||||
&& EmailValidation.EmailValidator.Validate(EmailAddress ?? string.Empty)
|
||||
&& MailAccountAddressValidator.IsValid(EmailAddress)
|
||||
&& !string.IsNullOrWhiteSpace(AppSpecificPassword);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ using Wino.Core.Domain.Interfaces;
|
||||
using Wino.Core.Domain.Models.Accounts;
|
||||
using Wino.Core.Domain.Models.Navigation;
|
||||
using Wino.Core.Domain.Models.Updates;
|
||||
using Wino.Mail.ViewModels.Data;
|
||||
using Wino.Messaging.Client.Navigation;
|
||||
using Wino.Messaging.UI;
|
||||
|
||||
@@ -68,7 +69,8 @@ public partial class WelcomePageV2ViewModel : MailBaseViewModel
|
||||
{
|
||||
Messenger.Send(new BreadcrumbNavigationRequested(
|
||||
Translator.WelcomeWizard_Step2Title,
|
||||
WinoPage.ProviderSelectionPage));
|
||||
WinoPage.ProviderSelectionPage,
|
||||
ProviderSelectionNavigationContext.CreateForWizard()));
|
||||
}
|
||||
|
||||
[RelayCommand(CanExecute = nameof(CanOpenWelcomeActions))]
|
||||
|
||||
Reference in New Issue
Block a user