2026-04-21 23:17:08 +02:00
|
|
|
using System;
|
2025-10-25 10:54:38 +02:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using Wino.Core.Domain.Entities.Mail;
|
2025-11-01 12:35:47 +01:00
|
|
|
using Wino.Core.Domain.Interfaces;
|
2026-04-21 23:17:08 +02:00
|
|
|
using Wino.Core.Domain.Models.MailItem;
|
2025-10-25 10:54:38 +02:00
|
|
|
|
|
|
|
|
public class ListItemComparer : IComparer<object>
|
|
|
|
|
{
|
|
|
|
|
public bool SortByName { get; set; }
|
|
|
|
|
|
|
|
|
|
public int Compare(object x, object y)
|
|
|
|
|
{
|
2026-04-21 23:17:08 +02:00
|
|
|
if (x is MailListGroupKey xGroupKey && y is MailListGroupKey yGroupKey)
|
|
|
|
|
{
|
|
|
|
|
if (xGroupKey.IsPinned != yGroupKey.IsPinned)
|
|
|
|
|
return yGroupKey.IsPinned.CompareTo(xGroupKey.IsPinned);
|
|
|
|
|
|
|
|
|
|
if (xGroupKey.IsPinned && yGroupKey.IsPinned)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
return CompareSortValues(xGroupKey.Value, yGroupKey.Value);
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-01 12:35:47 +01:00
|
|
|
if (x is IMailListItemSorting xSorting && y is IMailListItemSorting ySorting)
|
2026-04-21 23:17:08 +02:00
|
|
|
{
|
|
|
|
|
if (xSorting.IsPinned != ySorting.IsPinned)
|
|
|
|
|
return ySorting.IsPinned.CompareTo(xSorting.IsPinned);
|
|
|
|
|
|
|
|
|
|
return SortByName
|
|
|
|
|
? string.Compare(xSorting.SortingName, ySorting.SortingName, StringComparison.OrdinalIgnoreCase)
|
|
|
|
|
: DateTime.Compare(ySorting.SortingDate, xSorting.SortingDate);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (x is MailCopy xMail && y is MailCopy yMail)
|
|
|
|
|
{
|
|
|
|
|
if (xMail.IsPinned != yMail.IsPinned)
|
|
|
|
|
return yMail.IsPinned.CompareTo(xMail.IsPinned);
|
|
|
|
|
|
|
|
|
|
return SortByName
|
|
|
|
|
? string.Compare(xMail.FromName, yMail.FromName, StringComparison.OrdinalIgnoreCase)
|
|
|
|
|
: DateTime.Compare(yMail.CreationDate, xMail.CreationDate);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return CompareSortValues(x, y);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static int CompareSortValues(object x, object y)
|
|
|
|
|
{
|
|
|
|
|
if (x is DateTime dateX && y is DateTime dateY)
|
2025-10-25 10:54:38 +02:00
|
|
|
return DateTime.Compare(dateY, dateX);
|
2026-04-21 23:17:08 +02:00
|
|
|
|
|
|
|
|
if (x is string stringX && y is string stringY)
|
2025-10-25 10:54:38 +02:00
|
|
|
return stringY.CompareTo(stringX);
|
2026-04-21 23:17:08 +02:00
|
|
|
|
2025-10-25 10:54:38 +02:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|