Thread UI fixes.
This commit is contained in:
@@ -108,6 +108,17 @@ public class WinoMailCollection : ObservableRecipient, IRecipient<SelectedItemsC
|
|||||||
{
|
{
|
||||||
await ExecuteUIThread(() =>
|
await ExecuteUIThread(() =>
|
||||||
{
|
{
|
||||||
|
foreach (var group in _mailItemSource)
|
||||||
|
{
|
||||||
|
foreach (var item in group)
|
||||||
|
{
|
||||||
|
if (item is ThreadMailItemViewModel threadItem)
|
||||||
|
{
|
||||||
|
threadItem.UnregisterThreadEmailPropertyChangedHandlers();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_mailItemSource.Clear();
|
_mailItemSource.Clear();
|
||||||
MailCopyIdHashSet.Clear();
|
MailCopyIdHashSet.Clear();
|
||||||
_threadIdToItemsMap.Clear();
|
_threadIdToItemsMap.Clear();
|
||||||
@@ -278,7 +289,7 @@ public class WinoMailCollection : ObservableRecipient, IRecipient<SelectedItemsC
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task RemoveItemInternalAsync(ObservableGroup<object, IMailListItem> group, IMailListItem mailItem)
|
private async Task RemoveItemInternalAsync(ObservableGroup<object, IMailListItem> group, IMailListItem mailItem, bool detachThreadHandlers = true)
|
||||||
{
|
{
|
||||||
UpdateUniqueIdHashes(mailItem, false);
|
UpdateUniqueIdHashes(mailItem, false);
|
||||||
UpdateThreadIdCache(mailItem, false);
|
UpdateThreadIdCache(mailItem, false);
|
||||||
@@ -293,6 +304,11 @@ public class WinoMailCollection : ObservableRecipient, IRecipient<SelectedItemsC
|
|||||||
{
|
{
|
||||||
MailItemRemoved?.Invoke(this, threadMailItem);
|
MailItemRemoved?.Invoke(this, threadMailItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (detachThreadHandlers)
|
||||||
|
{
|
||||||
|
threadViewModel.UnregisterThreadEmailPropertyChangedHandlers();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await ExecuteUIThread(() =>
|
await ExecuteUIThread(() =>
|
||||||
@@ -369,7 +385,7 @@ public class WinoMailCollection : ObservableRecipient, IRecipient<SelectedItemsC
|
|||||||
|
|
||||||
private async Task MoveThreadToNewGroupAsync(ObservableGroup<object, IMailListItem> currentGroup, ThreadMailItemViewModel threadViewModel, object newGroupKey)
|
private async Task MoveThreadToNewGroupAsync(ObservableGroup<object, IMailListItem> currentGroup, ThreadMailItemViewModel threadViewModel, object newGroupKey)
|
||||||
{
|
{
|
||||||
await RemoveItemInternalAsync(currentGroup, threadViewModel);
|
await RemoveItemInternalAsync(currentGroup, threadViewModel, detachThreadHandlers: false);
|
||||||
await InsertItemInternalAsync(newGroupKey, threadViewModel);
|
await InsertItemInternalAsync(newGroupKey, threadViewModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
using Wino.Core.Domain;
|
using Wino.Core.Domain;
|
||||||
@@ -216,10 +217,11 @@ public partial class ThreadMailItemViewModel : ObservableRecipient, IMailListIte
|
|||||||
}
|
}
|
||||||
|
|
||||||
ThreadEmails.Insert(insertIndex, email);
|
ThreadEmails.Insert(insertIndex, email);
|
||||||
|
email.PropertyChanged += ThreadEmailPropertyChanged;
|
||||||
_uniqueIdSet.Add(email.MailCopy.UniqueId);
|
_uniqueIdSet.Add(email.MailCopy.UniqueId);
|
||||||
_cachedLatestMailViewModel = ThreadEmails[0];
|
_cachedLatestMailViewModel = ThreadEmails[0];
|
||||||
// Reassign to trigger property change notifications
|
OnPropertyChanged(nameof(EmailCount));
|
||||||
ThreadEmails = ThreadEmails;
|
NotifyMailItemUpdated(email);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -229,13 +231,36 @@ public partial class ThreadMailItemViewModel : ObservableRecipient, IMailListIte
|
|||||||
{
|
{
|
||||||
if (ThreadEmails.Remove(email))
|
if (ThreadEmails.Remove(email))
|
||||||
{
|
{
|
||||||
|
email.PropertyChanged -= ThreadEmailPropertyChanged;
|
||||||
_uniqueIdSet.Remove(email.MailCopy.UniqueId);
|
_uniqueIdSet.Remove(email.MailCopy.UniqueId);
|
||||||
_cachedLatestMailViewModel = ThreadEmails.Count > 0 ? ThreadEmails[0] : null;
|
_cachedLatestMailViewModel = ThreadEmails.Count > 0 ? ThreadEmails[0] : null;
|
||||||
// Reassign to trigger property change notifications
|
OnPropertyChanged(nameof(EmailCount));
|
||||||
ThreadEmails = ThreadEmails;
|
NotifyMailItemUpdated(email);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void UnregisterThreadEmailPropertyChangedHandlers()
|
||||||
|
{
|
||||||
|
foreach (var email in ThreadEmails)
|
||||||
|
{
|
||||||
|
email.PropertyChanged -= ThreadEmailPropertyChanged;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void ThreadEmailPropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.PropertyName == nameof(MailItemViewModel.IsSelected) || e.PropertyName == nameof(MailItemViewModel.IsDisplayedInThread))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (e.PropertyName == nameof(MailItemViewModel.IsRead))
|
||||||
|
{
|
||||||
|
OnPropertyChanged(nameof(IsRead));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
NotifyMailItemUpdated(sender as MailItemViewModel);
|
||||||
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Notifies that a mail item within this thread has been updated.
|
/// Notifies that a mail item within this thread has been updated.
|
||||||
/// This raises PropertyChanged for all thread-level computed properties that depend on child items.
|
/// This raises PropertyChanged for all thread-level computed properties that depend on child items.
|
||||||
@@ -292,3 +317,4 @@ public partial class ThreadMailItemViewModel : ObservableRecipient, IMailListIte
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user