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
@@ -259,6 +259,26 @@ public class MailFetchingTests : IAsyncLifetime
result.Single().FolderId.Should().Be(_inboxFolder.Id, "a copy from the actively searched folder should win over newer non-searched copies");
}
[Fact]
public async Task FetchPinnedMailsAsync_ReturnsPinnedMailsOutsideRegularPage()
{
var oldPinned = BuildMail(_inboxFolder.Id, DateTime.UtcNow.AddDays(-5));
oldPinned.IsPinned = true;
var recentMails = Enumerable.Range(0, 120)
.Select(i => BuildMail(_inboxFolder.Id, DateTime.UtcNow.AddMinutes(-i)))
.ToList();
await _databaseService.Connection.InsertAsync(oldPinned, typeof(MailCopy));
await _databaseService.Connection.InsertAllAsync(recentMails, typeof(MailCopy));
var options = BuildOptions([_inboxFolder], createThreads: false, take: 20);
var result = await _mailService.FetchPinnedMailsAsync(options);
result.Should().ContainSingle(mail => mail.UniqueId == oldPinned.UniqueId);
}
[Fact]
public async Task CreateAssignmentAsync_ExistingAssignment_IsIgnored()
{
@@ -297,6 +317,27 @@ public class MailFetchingTests : IAsyncLifetime
insertedCopies.Select(mail => mail.FolderId).Should().BeEquivalentTo([_inboxFolder.Id, archiveFolder.Id]);
}
[Fact]
public async Task UpdateMailAsync_PreservesLocalPinnedState()
{
var existingMail = BuildMail(_inboxFolder.Id, DateTime.UtcNow.AddHours(-1));
existingMail.IsPinned = true;
await _databaseService.Connection.InsertAsync(existingMail, typeof(MailCopy));
var refreshedMail = BuildMail(_inboxFolder.Id, DateTime.UtcNow, id: existingMail.Id);
refreshedMail.UniqueId = existingMail.UniqueId;
refreshedMail.FileId = existingMail.FileId;
refreshedMail.Subject = "Updated subject";
await _mailService.UpdateMailAsync(refreshedMail);
var storedMail = await _databaseService.Connection.FindAsync<MailCopy>(existingMail.UniqueId);
storedMail.Should().NotBeNull();
storedMail!.IsPinned.Should().BeTrue();
storedMail.Subject.Should().Be("Updated subject");
}
// ── Performance: 1 000 mails / ~70 threads ─────────────────────────────────
/// <summary>