ItemsView thing.
This commit is contained in:
@@ -1,31 +0,0 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Wino.Core.Domain.Models.MailItem;
|
||||
|
||||
namespace Wino.Core.Domain.Models.Comparers;
|
||||
|
||||
public class DateComparer : IComparer<IMailItem>, IEqualityComparer
|
||||
{
|
||||
public int Compare(IMailItem x, IMailItem y)
|
||||
{
|
||||
return DateTime.Compare(y.CreationDate, x.CreationDate);
|
||||
}
|
||||
|
||||
public new bool Equals(object x, object y)
|
||||
{
|
||||
if (x is IMailItem firstItem && y is IMailItem secondItem)
|
||||
{
|
||||
return firstItem.Equals(secondItem);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public int GetHashCode(object obj) => (obj as IMailItem).GetHashCode();
|
||||
|
||||
public DateComparer()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Wino.Core.Domain.Models.MailItem;
|
||||
|
||||
namespace Wino.Core.Domain.Models.Comparers;
|
||||
|
||||
public class ListItemComparer : IComparer<object>
|
||||
{
|
||||
public bool SortByName { get; set; }
|
||||
|
||||
public DateComparer DateComparer = new DateComparer();
|
||||
public readonly NameComparer NameComparer = new NameComparer();
|
||||
|
||||
public int Compare(object x, object y)
|
||||
{
|
||||
if (x is IMailItem xMail && y is IMailItem yMail)
|
||||
{
|
||||
var itemComparer = GetItemComparer();
|
||||
|
||||
return itemComparer.Compare(xMail, yMail);
|
||||
}
|
||||
else if (x is DateTime dateX && y is DateTime dateY)
|
||||
return DateTime.Compare(dateY, dateX);
|
||||
else if (x is string stringX && y is string stringY)
|
||||
return stringY.CompareTo(stringX);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public IComparer<IMailItem> GetItemComparer()
|
||||
{
|
||||
if (SortByName)
|
||||
return NameComparer;
|
||||
else
|
||||
return DateComparer;
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using Wino.Core.Domain.Models.MailItem;
|
||||
|
||||
namespace Wino.Core.Domain.Models.Comparers;
|
||||
|
||||
public class NameComparer : IComparer<IMailItem>
|
||||
{
|
||||
public int Compare(IMailItem x, IMailItem y)
|
||||
{
|
||||
return string.Compare(x.FromName, y.FromName);
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Wino.Core.Domain.Models.MailItem;
|
||||
|
||||
/// <summary>
|
||||
/// An interface that returns the UniqueId store for IMailItem.
|
||||
/// For threads, it may be multiple items.
|
||||
/// For single mails, it'll always be one item.
|
||||
/// </summary>
|
||||
public interface IMailHashContainer
|
||||
{
|
||||
IEnumerable<Guid> GetContainingIds();
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
using System;
|
||||
using Wino.Core.Domain.Entities.Mail;
|
||||
using Wino.Core.Domain.Entities.Shared;
|
||||
|
||||
namespace Wino.Core.Domain.Models.MailItem;
|
||||
|
||||
/// <summary>
|
||||
/// Interface of simplest representation of a MailCopy.
|
||||
/// </summary>
|
||||
public interface IMailItem : IMailHashContainer
|
||||
{
|
||||
Guid UniqueId { get; }
|
||||
string Id { get; }
|
||||
string Subject { get; }
|
||||
string ThreadId { get; }
|
||||
string MessageId { get; }
|
||||
string References { get; }
|
||||
string InReplyTo { get; }
|
||||
string PreviewText { get; }
|
||||
string FromName { get; }
|
||||
DateTime CreationDate { get; }
|
||||
string FromAddress { get; }
|
||||
bool HasAttachments { get; }
|
||||
bool IsFlagged { get; }
|
||||
bool IsFocused { get; }
|
||||
bool IsRead { get; }
|
||||
string DraftId { get; }
|
||||
bool IsDraft { get; }
|
||||
Guid FileId { get; }
|
||||
|
||||
MailItemFolder AssignedFolder { get; }
|
||||
MailAccount AssignedAccount { get; }
|
||||
AccountContact SenderContact { get; }
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace Wino.Core.Domain.Models.MailItem;
|
||||
|
||||
/// <summary>
|
||||
/// Interface that represents conversation threads.
|
||||
/// Even though this type has 1 single UI representation most of the time,
|
||||
/// it can contain multiple IMailItem.
|
||||
/// </summary>
|
||||
public interface IMailItemThread : IMailItem
|
||||
{
|
||||
ObservableCollection<IMailItem> ThreadItems { get; }
|
||||
IMailItem LatestMailItem { get; }
|
||||
IMailItem FirstMailItem { get; }
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using Wino.Core.Domain.Entities.Mail;
|
||||
|
||||
namespace Wino.Core.Domain.Models.MailItem;
|
||||
|
||||
@@ -7,12 +8,12 @@ namespace Wino.Core.Domain.Models.MailItem;
|
||||
/// </summary>
|
||||
public class MailDragPackage
|
||||
{
|
||||
public MailDragPackage(IEnumerable<IMailItem> draggingMails)
|
||||
public MailDragPackage(IEnumerable<MailCopy> draggingMails)
|
||||
{
|
||||
DraggingMails = draggingMails;
|
||||
}
|
||||
|
||||
public MailDragPackage(IMailItem draggingMail)
|
||||
public MailDragPackage(MailCopy draggingMail)
|
||||
{
|
||||
DraggingMails =
|
||||
[
|
||||
@@ -20,5 +21,5 @@ public class MailDragPackage
|
||||
];
|
||||
}
|
||||
|
||||
public IEnumerable<IMailItem> DraggingMails { get; set; }
|
||||
public IEnumerable<MailCopy> DraggingMails { get; set; }
|
||||
}
|
||||
|
||||
@@ -1,94 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using Wino.Core.Domain.Entities.Mail;
|
||||
using Wino.Core.Domain.Entities.Shared;
|
||||
|
||||
namespace Wino.Core.Domain.Models.MailItem;
|
||||
|
||||
public class ThreadMailItem : IMailItemThread
|
||||
{
|
||||
// TODO: Ideally this should be SortedList.
|
||||
public ObservableCollection<IMailItem> ThreadItems { get; } = new ObservableCollection<IMailItem>();
|
||||
|
||||
public IMailItem LatestMailItem => ThreadItems.LastOrDefault();
|
||||
public IMailItem FirstMailItem => ThreadItems.FirstOrDefault();
|
||||
|
||||
public bool AddThreadItem(IMailItem item)
|
||||
{
|
||||
if (item == null) return false;
|
||||
|
||||
if (ThreadItems.Any(a => a.Id == item.Id))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (item != null && item.IsDraft)
|
||||
{
|
||||
ThreadItems.Insert(0, item);
|
||||
return true;
|
||||
}
|
||||
|
||||
var insertItem = ThreadItems.FirstOrDefault(a => !a.IsDraft && a.CreationDate < item.CreationDate);
|
||||
|
||||
if (insertItem == null)
|
||||
ThreadItems.Insert(ThreadItems.Count, item);
|
||||
else
|
||||
{
|
||||
var index = ThreadItems.IndexOf(insertItem);
|
||||
|
||||
ThreadItems.Insert(index, item);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public IEnumerable<Guid> GetContainingIds() => ThreadItems?.Select(a => a.UniqueId) ?? default;
|
||||
|
||||
#region IMailItem
|
||||
|
||||
public Guid UniqueId => LatestMailItem?.UniqueId ?? Guid.Empty;
|
||||
public string Id => LatestMailItem?.Id ?? string.Empty;
|
||||
|
||||
// Show subject from last item.
|
||||
public string Subject => LatestMailItem?.Subject ?? string.Empty;
|
||||
|
||||
public string ThreadId => LatestMailItem?.ThreadId ?? string.Empty;
|
||||
|
||||
public string PreviewText => FirstMailItem?.PreviewText ?? string.Empty;
|
||||
|
||||
public string FromName => LatestMailItem?.FromName ?? string.Empty;
|
||||
|
||||
public string FromAddress => LatestMailItem?.FromAddress ?? string.Empty;
|
||||
|
||||
public bool HasAttachments => ThreadItems.Any(a => a.HasAttachments);
|
||||
|
||||
public bool IsFlagged => ThreadItems.Any(a => a.IsFlagged);
|
||||
|
||||
public bool IsFocused => LatestMailItem?.IsFocused ?? false;
|
||||
|
||||
public bool IsRead => ThreadItems.All(a => a.IsRead);
|
||||
|
||||
public DateTime CreationDate => FirstMailItem?.CreationDate ?? DateTime.MinValue;
|
||||
|
||||
public bool IsDraft => ThreadItems.Any(a => a.IsDraft);
|
||||
|
||||
public string DraftId => string.Empty;
|
||||
|
||||
public string MessageId => LatestMailItem?.MessageId;
|
||||
|
||||
public string References => LatestMailItem?.References ?? string.Empty;
|
||||
|
||||
public string InReplyTo => LatestMailItem?.InReplyTo ?? string.Empty;
|
||||
|
||||
public MailItemFolder AssignedFolder => LatestMailItem?.AssignedFolder;
|
||||
|
||||
public MailAccount AssignedAccount => LatestMailItem?.AssignedAccount;
|
||||
|
||||
public Guid FileId => LatestMailItem?.FileId ?? Guid.Empty;
|
||||
|
||||
public AccountContact SenderContact => LatestMailItem?.SenderContact;
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Wino.Core.Domain.Entities.Mail;
|
||||
using Wino.Core.Domain.Enums;
|
||||
|
||||
namespace Wino.Core.Domain.Models.MailItem;
|
||||
@@ -10,4 +11,4 @@ namespace Wino.Core.Domain.Models.MailItem;
|
||||
/// <param name="SourceAction"></param>
|
||||
/// <param name="TargetAction"></param>
|
||||
/// <param name="Condition"></param>
|
||||
public record ToggleRequestRule(MailOperation SourceAction, MailOperation TargetAction, Func<IMailItem, bool> Condition);
|
||||
public record ToggleRequestRule(MailOperation SourceAction, MailOperation TargetAction, Func<MailCopy, bool> Condition);
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using Wino.Core.Domain.Enums;
|
||||
using Wino.Core.Domain.Models.Comparers;
|
||||
using Wino.Core.Domain.Models.MailItem;
|
||||
using Wino.Core.Domain.Enums;
|
||||
|
||||
namespace Wino.Core.Domain.Models.Reader;
|
||||
|
||||
@@ -9,16 +6,6 @@ public class SortingOption
|
||||
{
|
||||
public SortingOptionType Type { get; set; }
|
||||
public string Title { get; set; }
|
||||
public IComparer<IMailItem> Comparer
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Type == SortingOptionType.ReceiveDate)
|
||||
return new DateComparer();
|
||||
else
|
||||
return new NameComparer();
|
||||
}
|
||||
}
|
||||
|
||||
public SortingOption(string title, SortingOptionType type)
|
||||
{
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text.Json.Serialization;
|
||||
using Wino.Core.Domain.Entities.Mail;
|
||||
using Wino.Core.Domain.Enums;
|
||||
using Wino.Core.Domain.Models.Accounts;
|
||||
using Wino.Core.Domain.Models.MailItem;
|
||||
|
||||
namespace Wino.Core.Domain.Models.Synchronization;
|
||||
|
||||
@@ -16,7 +16,7 @@ public class MailSynchronizationResult
|
||||
/// It's ignored in serialization. Client should not react to this.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public IEnumerable<IMailItem> DownloadedMessages { get; set; } = [];
|
||||
public IEnumerable<MailCopy> DownloadedMessages { get; set; } = [];
|
||||
|
||||
public ProfileInformation ProfileInformation { get; set; }
|
||||
|
||||
@@ -25,7 +25,7 @@ public class MailSynchronizationResult
|
||||
public static MailSynchronizationResult Empty => new() { CompletedState = SynchronizationCompletedState.Success };
|
||||
|
||||
// Mail synchronization
|
||||
public static MailSynchronizationResult Completed(IEnumerable<IMailItem> downloadedMessages)
|
||||
public static MailSynchronizationResult Completed(IEnumerable<MailCopy> downloadedMessages)
|
||||
=> new()
|
||||
{
|
||||
DownloadedMessages = downloadedMessages,
|
||||
|
||||
Reference in New Issue
Block a user