Add local mail pinning support

This commit is contained in:
Burak Kaan Köse
2026-04-21 23:17:08 +02:00
parent c0023614ad
commit 09820dda71
19 changed files with 531 additions and 53 deletions
@@ -6,6 +6,7 @@ using FluentAssertions;
using Wino.Core.Domain.Entities.Mail;
using Wino.Core.Domain.Enums;
using Wino.Core.Domain.Interfaces;
using Wino.Core.Domain.Models.MailItem;
using Wino.Mail.ViewModels.Collections;
using Wino.Mail.ViewModels.Data;
using Xunit;
@@ -167,7 +168,7 @@ public class WinoMailCollectionTests
groupItems.Add(item);
}
groups.Add(((DateTime)group.Key, groupItems));
groups.Add((((MailListGroupKey)group.Key).Value is DateTime keyDate ? keyDate : default, groupItems));
}
groups.Should().NotBeEmpty();
@@ -188,6 +189,45 @@ public class WinoMailCollectionTests
}
}
[Fact]
public async Task AddRangeAsync_ShouldPlacePinnedItemsBeforeUnpinnedItems()
{
var sut = CreateCollection();
var olderPinned = CreateMailCopy(threadId: "pinned", creationDate: DateTime.UtcNow.AddDays(-3));
olderPinned.IsPinned = true;
var newerUnpinned = CreateMailCopy(threadId: "regular", creationDate: DateTime.UtcNow);
await sut.AddRangeAsync(
[
new MailItemViewModel(newerUnpinned),
new MailItemViewModel(olderPinned)
],
clearIdCache: true);
var firstItem = FlattenItems(sut).First().Should().BeOfType<MailItemViewModel>().Subject;
firstItem.MailCopy.UniqueId.Should().Be(olderPinned.UniqueId);
}
[Fact]
public async Task UpdateMailCopy_ShouldMovePinnedItemToTop()
{
var sut = CreateCollection();
var older = CreateMailCopy(threadId: "older", creationDate: DateTime.UtcNow.AddDays(-2));
var newer = CreateMailCopy(threadId: "newer", creationDate: DateTime.UtcNow);
await sut.AddAsync(older);
await sut.AddAsync(newer);
var updatedOlder = CloneMailCopy(older);
updatedOlder.IsPinned = true;
await sut.UpdateMailCopy(updatedOlder, EntityUpdateSource.Server, MailCopyChangeFlags.IsPinned);
var firstItem = FlattenItems(sut).First().Should().BeOfType<MailItemViewModel>().Subject;
firstItem.MailCopy.UniqueId.Should().Be(older.UniqueId);
}
[Fact]
public async Task UpdateMailCopy_ShouldMergeExistingSingles_WhenThreadIdChangesToMatch()
{
@@ -371,6 +411,7 @@ public class WinoMailCollectionTests
Importance = source.Importance,
IsRead = source.IsRead,
IsFlagged = source.IsFlagged,
IsPinned = source.IsPinned,
IsFocused = source.IsFocused,
HasAttachments = source.HasAttachments,
ItemType = source.ItemType,
@@ -59,6 +59,29 @@ public class MailItemViewModelUpdateTests
nameof(MailItemViewModel.SortingName));
}
[Fact]
public void UpdateFrom_ShouldNotifyPinnedState_WhenPinnedChanges()
{
var original = CreateMailCopy("thread-1", DateTime.UtcNow);
var updated = CloneMailCopy(original);
updated.IsPinned = true;
var sut = new MailItemViewModel(original);
var raisedProperties = new List<string>();
sut.PropertyChanged += (_, e) =>
{
if (!string.IsNullOrEmpty(e.PropertyName))
{
raisedProperties.Add(e.PropertyName);
}
};
sut.UpdateFrom(updated);
raisedProperties.Should().Contain(nameof(MailItemViewModel.IsPinned));
}
[Fact]
public async Task UpdateMailCopy_ShouldNotifyThreadOnlyForReadState_WhenReadStateChanges()
{
@@ -125,6 +148,7 @@ public class MailItemViewModelUpdateTests
Importance = MailImportance.Normal,
IsRead = false,
IsFlagged = false,
IsPinned = false,
IsFocused = false,
HasAttachments = false,
ItemType = MailItemType.Mail,
@@ -151,6 +175,7 @@ public class MailItemViewModelUpdateTests
Importance = source.Importance,
IsRead = source.IsRead,
IsFlagged = source.IsFlagged,
IsPinned = source.IsPinned,
IsFocused = source.IsFocused,
HasAttachments = source.HasAttachments,
ItemType = source.ItemType,