Settings home refactoring.
This commit is contained in:
@@ -213,14 +213,37 @@ public class WinoMailCollection : ObservableRecipient, IRecipient<SelectedItemsC
|
||||
}
|
||||
}
|
||||
|
||||
private IMailListItem FindThreadableItem(string threadId)
|
||||
private IMailListItem FindThreadableItem(string threadId, Guid? excludedUniqueId = null, IMailListItem excludedItem = null)
|
||||
{
|
||||
if (string.IsNullOrEmpty(threadId) || !_threadIdToItemsMap.TryGetValue(threadId, out var items))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return items.FirstOrDefault();
|
||||
foreach (var item in items)
|
||||
{
|
||||
if (ReferenceEquals(item, excludedItem))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (excludedUniqueId.HasValue)
|
||||
{
|
||||
if (item is MailItemViewModel mailItem && mailItem.MailCopy.UniqueId == excludedUniqueId.Value)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (item is ThreadMailItemViewModel threadItem && threadItem.HasUniqueId(excludedUniqueId.Value))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -380,7 +403,8 @@ public class WinoMailCollection : ObservableRecipient, IRecipient<SelectedItemsC
|
||||
{
|
||||
if (item.MailCopy.UniqueId == addedItem.UniqueId)
|
||||
{
|
||||
await UpdateExistingItemAsync(item, addedItem);
|
||||
var existingItemContainer = GetMailItemContainer(addedItem.UniqueId);
|
||||
await UpdateExistingItemAsync(existingItemContainer, addedItem);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -419,7 +443,7 @@ public class WinoMailCollection : ObservableRecipient, IRecipient<SelectedItemsC
|
||||
var existingItemContainer = GetMailItemContainer(addedItem.UniqueId);
|
||||
if (existingItemContainer?.ItemViewModel != null)
|
||||
{
|
||||
await UpdateExistingItemAsync(existingItemContainer.ItemViewModel, addedItem);
|
||||
await UpdateExistingItemAsync(existingItemContainer, addedItem);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -478,16 +502,83 @@ public class WinoMailCollection : ObservableRecipient, IRecipient<SelectedItemsC
|
||||
await InsertItemInternalAsync(groupKey, newMailItem);
|
||||
}
|
||||
|
||||
private async Task UpdateExistingItemAsync(MailItemViewModel existingItem, MailCopy updatedItem)
|
||||
private async Task ReinsertUpdatedItemAsync(MailCopy updatedItem, bool isSelected, bool isBusy)
|
||||
{
|
||||
UpdateUniqueIdHashes(existingItem, false);
|
||||
await RemoveAsync(updatedItem);
|
||||
await AddAsync(updatedItem);
|
||||
|
||||
var updatedContainer = GetMailItemContainer(updatedItem.UniqueId);
|
||||
if (updatedContainer?.ItemViewModel == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
await ExecuteUIThread(() =>
|
||||
{
|
||||
existingItem.UpdateFrom(updatedItem);
|
||||
updatedContainer.ItemViewModel.IsSelected = isSelected;
|
||||
updatedContainer.ItemViewModel.IsBusy = isBusy;
|
||||
});
|
||||
}
|
||||
|
||||
private async Task UpdateExistingItemAsync(MailItemContainer itemContainer,
|
||||
MailCopy updatedItem,
|
||||
MailUpdateSource mailUpdateSource = MailUpdateSource.Server,
|
||||
MailCopyChangeFlags changeHint = MailCopyChangeFlags.None)
|
||||
{
|
||||
if (itemContainer?.ItemViewModel == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var existingItem = itemContainer.ItemViewModel;
|
||||
var threadOwner = itemContainer.ThreadViewModel as IMailListItem ?? existingItem;
|
||||
var wasSelected = existingItem.IsSelected;
|
||||
MailCopyChangeFlags appliedChanges = MailCopyChangeFlags.None;
|
||||
|
||||
await ExecuteUIThread(() =>
|
||||
{
|
||||
UpdateUniqueIdHashes(existingItem, false);
|
||||
UpdateThreadIdCache(threadOwner, false);
|
||||
|
||||
itemContainer.ThreadViewModel?.SuspendChildPropertyNotifications();
|
||||
|
||||
try
|
||||
{
|
||||
appliedChanges = existingItem.UpdateFrom(updatedItem, changeHint);
|
||||
}
|
||||
finally
|
||||
{
|
||||
itemContainer.ThreadViewModel?.ResumeChildPropertyNotifications();
|
||||
}
|
||||
|
||||
existingItem.IsBusy = mailUpdateSource == MailUpdateSource.ClientUpdated;
|
||||
|
||||
UpdateUniqueIdHashes(existingItem, true);
|
||||
UpdateThreadIdCache(threadOwner, true);
|
||||
|
||||
if (itemContainer.ThreadViewModel != null)
|
||||
{
|
||||
_uniqueIdToThreadMap[existingItem.MailCopy.UniqueId] = itemContainer.ThreadViewModel;
|
||||
}
|
||||
else
|
||||
{
|
||||
_uniqueIdToThreadMap.TryRemove(existingItem.MailCopy.UniqueId, out _);
|
||||
}
|
||||
});
|
||||
|
||||
UpdateUniqueIdHashes(existingItem, true);
|
||||
if ((appliedChanges & MailCopyChangeFlags.ThreadId) != 0)
|
||||
{
|
||||
await ReinsertUpdatedItemAsync(updatedItem, wasSelected, existingItem.IsBusy);
|
||||
return;
|
||||
}
|
||||
|
||||
if (itemContainer.ThreadViewModel != null && appliedChanges != MailCopyChangeFlags.None)
|
||||
{
|
||||
await ExecuteUIThread(() =>
|
||||
{
|
||||
itemContainer.ThreadViewModel.NotifyMailItemUpdated(existingItem, appliedChanges);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -755,45 +846,14 @@ public class WinoMailCollection : ObservableRecipient, IRecipient<SelectedItemsC
|
||||
/// <returns></returns>
|
||||
public Task UpdateMailCopy(MailCopy updatedMailCopy, MailUpdateSource mailUpdateSource, MailCopyChangeFlags changedProperties = MailCopyChangeFlags.None)
|
||||
{
|
||||
return ExecuteUIThread(() =>
|
||||
var itemContainer = GetMailItemContainer(updatedMailCopy.UniqueId);
|
||||
|
||||
if (itemContainer?.ItemViewModel == null)
|
||||
{
|
||||
var itemContainer = GetMailItemContainer(updatedMailCopy.UniqueId);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
if (itemContainer == null) return;
|
||||
MailCopyChangeFlags appliedChanges = MailCopyChangeFlags.None;
|
||||
|
||||
if (itemContainer.ItemViewModel != null)
|
||||
{
|
||||
UpdateUniqueIdHashes(itemContainer.ItemViewModel, false);
|
||||
|
||||
itemContainer.ThreadViewModel?.SuspendChildPropertyNotifications();
|
||||
|
||||
try
|
||||
{
|
||||
appliedChanges = itemContainer.ItemViewModel.UpdateFrom(updatedMailCopy, changedProperties);
|
||||
}
|
||||
finally
|
||||
{
|
||||
itemContainer.ThreadViewModel?.ResumeChildPropertyNotifications();
|
||||
}
|
||||
|
||||
// Mark the item view model as busy until the network operation is completed.
|
||||
itemContainer.ItemViewModel.IsBusy = mailUpdateSource == MailUpdateSource.ClientUpdated;
|
||||
|
||||
UpdateUniqueIdHashes(itemContainer.ItemViewModel, true);
|
||||
|
||||
// Keep thread membership cache in sync for items rendered inside thread containers.
|
||||
if (itemContainer.ThreadViewModel != null)
|
||||
{
|
||||
_uniqueIdToThreadMap[itemContainer.ItemViewModel.MailCopy.UniqueId] = itemContainer.ThreadViewModel;
|
||||
}
|
||||
}
|
||||
|
||||
if (itemContainer.ThreadViewModel != null && appliedChanges != MailCopyChangeFlags.None)
|
||||
{
|
||||
itemContainer.ThreadViewModel.NotifyMailItemUpdated(itemContainer.ItemViewModel, appliedChanges);
|
||||
}
|
||||
});
|
||||
return UpdateExistingItemAsync(itemContainer, updatedMailCopy, mailUpdateSource, changedProperties);
|
||||
}
|
||||
|
||||
public MailItemViewModel GetFirst() => AllItems.ElementAtOrDefault(0);
|
||||
|
||||
@@ -12,22 +12,8 @@ public partial class MessageListPageViewModel : MailBaseViewModel
|
||||
{
|
||||
public IPreferencesService PreferencesService { get; }
|
||||
private readonly IThumbnailService _thumbnailService;
|
||||
|
||||
private int selectedMarkAsOptionIndex;
|
||||
public int SelectedMarkAsOptionIndex
|
||||
{
|
||||
get => selectedMarkAsOptionIndex;
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref selectedMarkAsOptionIndex, value))
|
||||
{
|
||||
if (value >= 0)
|
||||
{
|
||||
PreferencesService.MarkAsPreference = (MailMarkAsOption)Enum.GetValues<MailMarkAsOption>().GetValue(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private readonly IStatePersistanceService _statePersistenceService;
|
||||
private readonly IDialogServiceBase _dialogService;
|
||||
|
||||
private readonly List<MailOperation> availableHoverActions =
|
||||
[
|
||||
@@ -38,6 +24,13 @@ public partial class MessageListPageViewModel : MailBaseViewModel
|
||||
MailOperation.MoveToJunk
|
||||
];
|
||||
|
||||
private readonly List<MailListDisplayMode> availableMailSpacingOptions =
|
||||
[
|
||||
MailListDisplayMode.Compact,
|
||||
MailListDisplayMode.Medium,
|
||||
MailListDisplayMode.Spacious
|
||||
];
|
||||
|
||||
public List<string> AvailableHoverActionsTranslations { get; set; } =
|
||||
[
|
||||
Translator.HoverActionOption_Archive,
|
||||
@@ -47,6 +40,32 @@ public partial class MessageListPageViewModel : MailBaseViewModel
|
||||
Translator.HoverActionOption_MoveJunk
|
||||
];
|
||||
|
||||
private int selectedMarkAsOptionIndex;
|
||||
public int SelectedMarkAsOptionIndex
|
||||
{
|
||||
get => selectedMarkAsOptionIndex;
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref selectedMarkAsOptionIndex, value) && value >= 0)
|
||||
{
|
||||
PreferencesService.MarkAsPreference = (MailMarkAsOption)Enum.GetValues<MailMarkAsOption>().GetValue(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int selectedMailSpacingIndex;
|
||||
public int SelectedMailSpacingIndex
|
||||
{
|
||||
get => selectedMailSpacingIndex;
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref selectedMailSpacingIndex, value) && value >= 0 && value < availableMailSpacingOptions.Count)
|
||||
{
|
||||
PreferencesService.MailItemDisplayMode = availableMailSpacingOptions[value];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#region Properties
|
||||
private int leftHoverActionIndex;
|
||||
public int LeftHoverActionIndex
|
||||
@@ -88,13 +107,19 @@ public partial class MessageListPageViewModel : MailBaseViewModel
|
||||
}
|
||||
#endregion
|
||||
|
||||
public MessageListPageViewModel(IPreferencesService preferencesService, IThumbnailService thumbnailService)
|
||||
public MessageListPageViewModel(IPreferencesService preferencesService,
|
||||
IThumbnailService thumbnailService,
|
||||
IStatePersistanceService statePersistenceService,
|
||||
IDialogServiceBase dialogService)
|
||||
{
|
||||
PreferencesService = preferencesService;
|
||||
_thumbnailService = thumbnailService;
|
||||
_statePersistenceService = statePersistenceService;
|
||||
_dialogService = dialogService;
|
||||
leftHoverActionIndex = availableHoverActions.IndexOf(PreferencesService.LeftHoverAction);
|
||||
centerHoverActionIndex = availableHoverActions.IndexOf(PreferencesService.CenterHoverAction);
|
||||
rightHoverActionIndex = availableHoverActions.IndexOf(PreferencesService.RightHoverAction);
|
||||
selectedMailSpacingIndex = availableMailSpacingOptions.IndexOf(PreferencesService.MailItemDisplayMode);
|
||||
SelectedMarkAsOptionIndex = Array.IndexOf(Enum.GetValues<MailMarkAsOption>(), PreferencesService.MarkAsPreference);
|
||||
}
|
||||
|
||||
@@ -103,4 +128,11 @@ public partial class MessageListPageViewModel : MailBaseViewModel
|
||||
{
|
||||
await _thumbnailService.ClearCache();
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void ResetMailListPaneLength()
|
||||
{
|
||||
_statePersistenceService.MailListPaneLength = 420;
|
||||
_dialogService.InfoBarMessage(Translator.GeneralTitle_Info, Translator.Info_MailListSizeResetSuccessMessage, InfoBarMessageType.Success);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user