Couple fixes for beta.
This commit is contained in:
@@ -22,12 +22,10 @@ using Wino.Core.Domain.Entities.Mail;
|
||||
using Wino.Core.Domain.Entities.Shared;
|
||||
using Wino.Core.Domain.Models.Reader;
|
||||
using Wino.Mail.ViewModels.Data;
|
||||
using Wino.Mail.ViewModels.Messages;
|
||||
using Wino.Mail.WinUI.Controls;
|
||||
using Wino.Mail.WinUI.Extensions;
|
||||
using Wino.Mail.WinUI.Interfaces;
|
||||
using Wino.Mail.WinUI.Models;
|
||||
using Wino.Messaging.Client.Mails;
|
||||
using Wino.Messaging.Client.Shell;
|
||||
using Wino.Views.Abstract;
|
||||
|
||||
@@ -42,6 +40,7 @@ public sealed partial class ComposePage : ComposePageAbstract,
|
||||
|
||||
private bool _isPoppedOut;
|
||||
private bool _isInitialFocusHandled;
|
||||
private readonly Dictionary<TokenizingTextBox, List<AccountContact>> _recipientSuggestions = [];
|
||||
|
||||
public bool SupportsPopOut => !_isPoppedOut;
|
||||
public event EventHandler<PopOutRequestedEventArgs>? PopOutRequested;
|
||||
@@ -132,12 +131,17 @@ public sealed partial class ComposePage : ComposePageAbstract,
|
||||
{
|
||||
_ = ViewModel.ExecuteUIThread(() =>
|
||||
{
|
||||
var addresses = x.Result;
|
||||
var addresses = x.Result ?? [];
|
||||
|
||||
_recipientSuggestions[box] = addresses;
|
||||
senderBox.ItemsSource = addresses;
|
||||
});
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
_recipientSuggestions[box] = [];
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -293,7 +297,7 @@ public sealed partial class ComposePage : ComposePageAbstract,
|
||||
{
|
||||
base.OnNavigatedTo(e);
|
||||
|
||||
FocusManager.GotFocus += GlobalFocusManagerGotFocus;
|
||||
// FocusManager.GotFocus += GlobalFocusManagerGotFocus;
|
||||
|
||||
var webView = GetWebView();
|
||||
|
||||
@@ -335,36 +339,60 @@ public sealed partial class ComposePage : ComposePageAbstract,
|
||||
|
||||
private async void TokenItemAdding(TokenizingTextBox sender, TokenItemAddingEventArgs args)
|
||||
{
|
||||
// Check is valid email.
|
||||
if (!EmailValidator.Validate(args.TokenText))
|
||||
{
|
||||
args.Cancel = true;
|
||||
ViewModel.NotifyInvalidEmail(args.TokenText);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var deferral = args.GetDeferral();
|
||||
|
||||
var addedItem = (sender.Tag?.ToString()) switch
|
||||
try
|
||||
{
|
||||
"ToBox" => await ViewModel.GetAddressInformationAsync(args.TokenText, ViewModel.ToItems),
|
||||
"CCBox" => await ViewModel.GetAddressInformationAsync(args.TokenText, ViewModel.CCItems),
|
||||
"BCCBox" => await ViewModel.GetAddressInformationAsync(args.TokenText, ViewModel.BCCItems),
|
||||
_ => null
|
||||
};
|
||||
var suggestedContact = GetFirstSuggestedContact(sender);
|
||||
var tokenText = suggestedContact?.Address ?? args.TokenText;
|
||||
var addressCollection = sender.Tag?.ToString() switch
|
||||
{
|
||||
"ToBox" => ViewModel.ToItems,
|
||||
"CCBox" => ViewModel.CCItems,
|
||||
"BCCBox" => ViewModel.BCCItems,
|
||||
_ => null
|
||||
};
|
||||
|
||||
if (addedItem == null)
|
||||
{
|
||||
args.Cancel = true;
|
||||
ViewModel.NotifyAddressExists();
|
||||
if (suggestedContact == null && !EmailValidator.Validate(tokenText))
|
||||
{
|
||||
args.Cancel = true;
|
||||
ViewModel.NotifyInvalidEmail(args.TokenText);
|
||||
return;
|
||||
}
|
||||
|
||||
AccountContact? addedItem = null;
|
||||
|
||||
if (suggestedContact != null)
|
||||
{
|
||||
addedItem = addressCollection?.Any(a => string.Equals(a.Address, suggestedContact.Address, StringComparison.OrdinalIgnoreCase)) == true
|
||||
? null
|
||||
: suggestedContact;
|
||||
}
|
||||
else
|
||||
{
|
||||
addedItem = sender.Tag?.ToString() switch
|
||||
{
|
||||
"ToBox" => await ViewModel.GetAddressInformationAsync(tokenText, ViewModel.ToItems),
|
||||
"CCBox" => await ViewModel.GetAddressInformationAsync(tokenText, ViewModel.CCItems),
|
||||
"BCCBox" => await ViewModel.GetAddressInformationAsync(tokenText, ViewModel.BCCItems),
|
||||
_ => null
|
||||
};
|
||||
}
|
||||
|
||||
if (addedItem == null)
|
||||
{
|
||||
args.Cancel = true;
|
||||
ViewModel.NotifyAddressExists();
|
||||
}
|
||||
else
|
||||
{
|
||||
args.Item = addedItem;
|
||||
}
|
||||
}
|
||||
else
|
||||
finally
|
||||
{
|
||||
args.Item = addedItem;
|
||||
_recipientSuggestions[sender] = [];
|
||||
deferral.Complete();
|
||||
}
|
||||
|
||||
deferral.Complete();
|
||||
}
|
||||
|
||||
void IRecipient<ApplicationThemeChanged>.Receive(ApplicationThemeChanged message)
|
||||
@@ -438,6 +466,11 @@ public sealed partial class ComposePage : ComposePageAbstract,
|
||||
}
|
||||
}
|
||||
|
||||
private AccountContact? GetFirstSuggestedContact(TokenizingTextBox box)
|
||||
=> _recipientSuggestions.TryGetValue(box, out var suggestions)
|
||||
? suggestions.FirstOrDefault()
|
||||
: null;
|
||||
|
||||
private void ComposerLoaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (ShouldFocusRecipients())
|
||||
|
||||
Reference in New Issue
Block a user