Add local mail pinning support
This commit is contained in:
@@ -92,6 +92,11 @@ public class MailCopy
|
||||
/// </summary>
|
||||
public bool IsFlagged { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether this mail should stay pinned to the top locally.
|
||||
/// </summary>
|
||||
public bool IsPinned { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// To support Outlook.
|
||||
/// Gmail doesn't use it.
|
||||
|
||||
@@ -20,17 +20,18 @@ public enum MailCopyChangeFlags
|
||||
Importance = 1 << 11,
|
||||
IsRead = 1 << 12,
|
||||
IsFlagged = 1 << 13,
|
||||
IsFocused = 1 << 14,
|
||||
HasAttachments = 1 << 15,
|
||||
ItemType = 1 << 16,
|
||||
DraftId = 1 << 17,
|
||||
IsDraft = 1 << 18,
|
||||
FileId = 1 << 19,
|
||||
AssignedFolder = 1 << 20,
|
||||
AssignedAccount = 1 << 21,
|
||||
SenderContact = 1 << 22,
|
||||
UniqueId = 1 << 23,
|
||||
ReadReceiptState = 1 << 24,
|
||||
IsPinned = 1 << 14,
|
||||
IsFocused = 1 << 15,
|
||||
HasAttachments = 1 << 16,
|
||||
ItemType = 1 << 17,
|
||||
DraftId = 1 << 18,
|
||||
IsDraft = 1 << 19,
|
||||
FileId = 1 << 20,
|
||||
AssignedFolder = 1 << 21,
|
||||
AssignedAccount = 1 << 22,
|
||||
SenderContact = 1 << 23,
|
||||
UniqueId = 1 << 24,
|
||||
ReadReceiptState = 1 << 25,
|
||||
All = Id |
|
||||
FolderId |
|
||||
ThreadId |
|
||||
@@ -45,6 +46,7 @@ public enum MailCopyChangeFlags
|
||||
Importance |
|
||||
IsRead |
|
||||
IsFlagged |
|
||||
IsPinned |
|
||||
IsFocused |
|
||||
HasAttachments |
|
||||
ItemType |
|
||||
|
||||
@@ -6,4 +6,5 @@ public interface IMailListItemSorting
|
||||
{
|
||||
DateTime SortingDate { get; }
|
||||
string SortingName { get; }
|
||||
bool IsPinned { get; }
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ public interface IMailService
|
||||
/// </summary>
|
||||
Task<List<MailCopy>> GetMailItemsAsync(IEnumerable<string> mailCopyIds);
|
||||
Task<List<MailCopy>> FetchMailsAsync(MailListInitializationOptions options, CancellationToken cancellationToken = default);
|
||||
Task<List<MailCopy>> FetchPinnedMailsAsync(MailListInitializationOptions options, CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Deletes all mail copies for all folders.
|
||||
@@ -36,6 +37,7 @@ public interface IMailService
|
||||
|
||||
Task ChangeReadStatusAsync(string mailCopyId, bool isRead);
|
||||
Task ChangeFlagStatusAsync(string mailCopyId, bool isFlagged);
|
||||
Task ChangePinnedStatusAsync(IEnumerable<Guid> uniqueMailIds, bool isPinned);
|
||||
Task ApplyMailStateUpdatesAsync(IEnumerable<MailCopyStateUpdate> updates);
|
||||
|
||||
Task CreateAssignmentAsync(Guid accountId, string mailCopyId, string remoteFolderId);
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Wino.Core.Domain.Entities.Mail;
|
||||
using Wino.Core.Domain.Interfaces;
|
||||
using Wino.Core.Domain.Models.MailItem;
|
||||
|
||||
public class ListItemComparer : IComparer<object>
|
||||
{
|
||||
@@ -9,14 +10,48 @@ public class ListItemComparer : IComparer<object>
|
||||
|
||||
public int Compare(object x, object y)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
if (x is IMailListItemSorting xSorting && y is IMailListItemSorting ySorting)
|
||||
return SortByName ? string.Compare(xSorting.SortingName, ySorting.SortingName, StringComparison.OrdinalIgnoreCase) : DateTime.Compare(ySorting.SortingDate, xSorting.SortingDate);
|
||||
else if (x is MailCopy xMail && y is MailCopy yMail)
|
||||
return SortByName ? string.Compare(xMail.FromName, yMail.FromName, StringComparison.OrdinalIgnoreCase) : DateTime.Compare(yMail.CreationDate, xMail.CreationDate);
|
||||
else if (x is DateTime dateX && y is DateTime dateY)
|
||||
{
|
||||
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)
|
||||
return DateTime.Compare(dateY, dateX);
|
||||
else if (x is string stringX && y is string stringY)
|
||||
|
||||
if (x is string stringX && y is string stringY)
|
||||
return stringY.CompareTo(stringX);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Wino.Core.Domain.Models.MailItem;
|
||||
|
||||
public sealed record MailListGroupKey(bool IsPinned, object Value)
|
||||
{
|
||||
public static MailListGroupKey Pinned { get; } = new(true, null);
|
||||
}
|
||||
Reference in New Issue
Block a user