2024-07-09 01:05:16 +02:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using CommunityToolkit.Mvvm.Messaging;
|
2024-11-10 23:28:25 +01:00
|
|
|
using Wino.Core.Domain.Entities.Mail;
|
2024-07-09 01:05:16 +02:00
|
|
|
using Wino.Core.Domain.Enums;
|
|
|
|
|
using Wino.Core.Domain.Interfaces;
|
|
|
|
|
using Wino.Core.Domain.Models.Requests;
|
2024-08-05 00:36:26 +02:00
|
|
|
using Wino.Messaging.UI;
|
2024-07-09 01:05:16 +02:00
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
namespace Wino.Core.Requests.Folder;
|
|
|
|
|
|
|
|
|
|
public record MarkFolderAsReadRequest(MailItemFolder Folder, List<MailCopy> MailsToMarkRead) : FolderRequestBase(Folder, FolderSynchronizerOperation.MarkFolderRead), ICustomFolderSynchronizationRequest
|
2024-07-09 01:05:16 +02:00
|
|
|
{
|
2026-04-05 16:53:51 +02:00
|
|
|
public List<Guid> SynchronizationFolderIds => [Folder.Id];
|
|
|
|
|
|
|
|
|
|
public bool ExcludeMustHaveFolders => true;
|
|
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
public override void ApplyUIChanges()
|
2024-07-09 01:05:16 +02:00
|
|
|
{
|
2026-01-28 03:25:05 +08:00
|
|
|
if (MailsToMarkRead == null || MailsToMarkRead.Count == 0) return;
|
|
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
foreach (var item in MailsToMarkRead)
|
2024-07-09 01:05:16 +02:00
|
|
|
{
|
2026-02-05 12:48:38 +01:00
|
|
|
// Skip if already read
|
|
|
|
|
if (item.IsRead) continue;
|
|
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
item.IsRead = true;
|
2026-01-28 03:25:05 +08:00
|
|
|
|
2026-04-07 16:48:46 +02:00
|
|
|
WeakReferenceMessenger.Default.Send(new MailUpdatedMessage(item, EntityUpdateSource.ClientUpdated, MailCopyChangeFlags.IsRead));
|
2024-07-09 01:05:16 +02:00
|
|
|
}
|
2025-02-16 11:54:23 +01:00
|
|
|
}
|
2024-07-09 01:05:16 +02:00
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
public override void RevertUIChanges()
|
|
|
|
|
{
|
2026-01-28 03:25:05 +08:00
|
|
|
if (MailsToMarkRead == null || MailsToMarkRead.Count == 0) return;
|
|
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
foreach (var item in MailsToMarkRead)
|
2024-07-09 01:05:16 +02:00
|
|
|
{
|
2026-02-05 12:48:38 +01:00
|
|
|
// Skip if already unread (wasn't changed by ApplyUIChanges)
|
|
|
|
|
if (!item.IsRead) continue;
|
|
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
item.IsRead = false;
|
2026-01-28 03:25:05 +08:00
|
|
|
|
2026-04-07 16:48:46 +02:00
|
|
|
WeakReferenceMessenger.Default.Send(new MailUpdatedMessage(item, EntityUpdateSource.ClientReverted, MailCopyChangeFlags.IsRead));
|
2024-07-09 01:05:16 +02:00
|
|
|
}
|
2025-02-16 11:54:23 +01:00
|
|
|
}
|
2024-07-09 01:05:16 +02:00
|
|
|
}
|