Attempt to bring back ListView.
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using Wino.Core.Domain.Interfaces;
|
||||
|
||||
namespace Wino.Mail.ViewModels.Data;
|
||||
|
||||
/// <summary>
|
||||
/// Common interface for mail items that can be displayed in a mail list.
|
||||
/// Implemented by both MailItemViewModel and ThreadMailItemViewModel.
|
||||
/// </summary>
|
||||
public interface IMailListItem : IMailHashContainer
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the latest creation date for sorting purposes.
|
||||
/// For MailItemViewModel: the mail's creation date
|
||||
/// For ThreadMailItemViewModel: the latest email's creation date
|
||||
/// </summary>
|
||||
DateTime CreationDate { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the sender's name for grouping purposes.
|
||||
/// For MailItemViewModel: the mail's from name
|
||||
/// For ThreadMailItemViewModel: the latest email's from name
|
||||
/// </summary>
|
||||
string FromName { get; }
|
||||
}
|
||||
@@ -1,13 +1,17 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Wino.Core.Domain.Entities.Mail;
|
||||
using Wino.Core.Domain.Interfaces;
|
||||
|
||||
namespace Wino.Mail.ViewModels.Data;
|
||||
|
||||
/// <summary>
|
||||
/// Single view model for IMailItem representation.
|
||||
/// </summary>
|
||||
public partial class MailItemViewModel(MailCopy mailCopy) : ObservableObject
|
||||
public partial class MailItemViewModel(MailCopy mailCopy) : ObservableObject, IMailListItem
|
||||
{
|
||||
public DateTime CreationDate => MailCopy.CreationDate;
|
||||
[ObservableProperty]
|
||||
public partial MailCopy MailCopy { get; set; } = mailCopy;
|
||||
|
||||
@@ -85,4 +89,6 @@ public partial class MailItemViewModel(MailCopy mailCopy) : ObservableObject
|
||||
get => MailCopy.HasAttachments;
|
||||
set => SetProperty(MailCopy.HasAttachments, value, MailCopy, (u, n) => u.HasAttachments = n);
|
||||
}
|
||||
|
||||
public IEnumerable<Guid> GetContainingIds() => [MailCopy.UniqueId];
|
||||
}
|
||||
|
||||
@@ -2,13 +2,14 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Wino.Core.Domain.Interfaces;
|
||||
|
||||
namespace Wino.Mail.ViewModels.Data;
|
||||
|
||||
/// <summary>
|
||||
/// Thread mail item (multiple IMailItem) view model representation.
|
||||
/// </summary>
|
||||
public partial class ThreadMailItemViewModel : ObservableRecipient, IDisposable
|
||||
public partial class ThreadMailItemViewModel : ObservableRecipient, IDisposable, IMailListItem
|
||||
{
|
||||
private readonly string _threadId;
|
||||
|
||||
@@ -30,21 +31,21 @@ public partial class ThreadMailItemViewModel : ObservableRecipient, IDisposable
|
||||
/// <summary>
|
||||
/// Gets the latest email's subject for display
|
||||
/// </summary>
|
||||
public string? Subject => _threadEmails
|
||||
public string Subject => _threadEmails
|
||||
.OrderByDescending(e => e.MailCopy?.CreationDate)
|
||||
.FirstOrDefault()?.MailCopy?.Subject;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the latest email's sender name for display
|
||||
/// </summary>
|
||||
public string? FromName => _threadEmails
|
||||
public string FromName => _threadEmails
|
||||
.OrderByDescending(e => e.MailCopy?.CreationDate)
|
||||
.FirstOrDefault()?.MailCopy?.SenderContact.Name;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the latest email's creation date for sorting
|
||||
/// </summary>
|
||||
public DateTime LatestEmailDate => _threadEmails
|
||||
public DateTime CreationDate => _threadEmails
|
||||
.OrderByDescending(e => e.MailCopy?.CreationDate)
|
||||
.FirstOrDefault()?.MailCopy?.CreationDate ?? DateTime.MinValue;
|
||||
|
||||
@@ -79,11 +80,11 @@ public partial class ThreadMailItemViewModel : ObservableRecipient, IDisposable
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
private void NotifyPropertyChanges()
|
||||
public void NotifyPropertyChanges()
|
||||
{
|
||||
OnPropertyChanged(nameof(Subject));
|
||||
OnPropertyChanged(nameof(FromName));
|
||||
OnPropertyChanged(nameof(LatestEmailDate));
|
||||
OnPropertyChanged(nameof(CreationDate));
|
||||
OnPropertyChanged(nameof(LatestMailViewModel));
|
||||
}
|
||||
|
||||
@@ -115,4 +116,6 @@ public partial class ThreadMailItemViewModel : ObservableRecipient, IDisposable
|
||||
/// Checks if this thread contains an email with the specified unique ID
|
||||
/// </summary>
|
||||
public bool HasUniqueId(Guid uniqueId) => _threadEmails.Any(email => email.MailCopy.UniqueId == uniqueId);
|
||||
|
||||
public IEnumerable<Guid> GetContainingIds() => ThreadEmails.Select(a => a.MailCopy.UniqueId);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user