Asynchronously load correct contact data for composer.

This commit is contained in:
Burak Kaan Köse
2024-08-23 02:06:58 +02:00
parent d69b72b77d
commit ff88832cca

View File

@@ -438,7 +438,7 @@ namespace Wino.Mail.ViewModels
var renderModel = _mimeFileService.GetMailRenderModel(replyingMime, mimeFilePath); var renderModel = _mimeFileService.GetMailRenderModel(replyingMime, mimeFilePath);
await ExecuteUIThread(() => await ExecuteUIThread(async () =>
{ {
// Extract information // Extract information
@@ -448,9 +448,9 @@ namespace Wino.Mail.ViewModels
CCItems.Clear(); CCItems.Clear();
BCCItems.Clear(); BCCItems.Clear();
LoadAddressInfo(replyingMime.To, ToItems); await LoadAddressInfoAsync(replyingMime.To, ToItems);
LoadAddressInfo(replyingMime.Cc, CCItems); await LoadAddressInfoAsync(replyingMime.Cc, CCItems);
LoadAddressInfo(replyingMime.Bcc, BCCItems); await LoadAddressInfoAsync(replyingMime.Bcc, BCCItems);
LoadAttachments(); LoadAttachments();
@@ -476,14 +476,19 @@ namespace Wino.Mail.ViewModels
} }
} }
private void LoadAddressInfo(InternetAddressList list, ObservableCollection<AccountContact> collection) private async Task LoadAddressInfoAsync(InternetAddressList list, ObservableCollection<AccountContact> collection)
{ {
foreach (var item in list) foreach (var item in list)
{ {
if (item is MailboxAddress mailboxAddress) if (item is MailboxAddress mailboxAddress)
collection.Add(mailboxAddress.ToAddressInformation()); {
var foundContact = await ContactService.GetAddressInformationByAddressAsync(mailboxAddress.Address).ConfigureAwait(false)
?? new AccountContact() { Name = mailboxAddress.Name, Address = mailboxAddress.Address };
await ExecuteUIThread(() => { collection.Add(foundContact); });
}
else if (item is GroupAddress groupAddress) else if (item is GroupAddress groupAddress)
LoadAddressInfo(groupAddress.Members, collection); await LoadAddressInfoAsync(groupAddress.Members, collection);
} }
} }
@@ -521,7 +526,8 @@ namespace Wino.Mail.ViewModels
{ {
// Get model from the service. This will make sure the name is properly included if there is any record. // Get model from the service. This will make sure the name is properly included if there is any record.
var info = await ContactService.GetAddressInformationByAddressAsync(tokenText); var info = await ContactService.GetAddressInformationByAddressAsync(tokenText)
?? new AccountContact() { Name = tokenText, Address = tokenText };
// Don't add if there is already that address in the collection. // Don't add if there is already that address in the collection.
if (collection.Any(a => a.Address == info.Address)) if (collection.Any(a => a.Address == info.Address))