Refactoring mail collection class.
This commit is contained in:
31
Wino.Mail.ViewModels/Collections/ThreadingManager.cs
Normal file
31
Wino.Mail.ViewModels/Collections/ThreadingManager.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using Wino.Core.Domain.Entities.Mail;
|
||||
using Wino.Core.Domain.Interfaces;
|
||||
using Wino.Core.Domain.Models.MailItem;
|
||||
|
||||
namespace Wino.Mail.ViewModels.Collections;
|
||||
|
||||
internal class ThreadingManager
|
||||
{
|
||||
private readonly IThreadingStrategyProvider _threadingStrategyProvider;
|
||||
|
||||
public ThreadingManager(IThreadingStrategyProvider threadingStrategyProvider)
|
||||
{
|
||||
_threadingStrategyProvider = threadingStrategyProvider;
|
||||
}
|
||||
|
||||
public bool ShouldThread(MailCopy newItem, IMailItem existingItem)
|
||||
{
|
||||
if (_threadingStrategyProvider == null) return false;
|
||||
|
||||
var strategy = _threadingStrategyProvider.GetStrategy(newItem.AssignedAccount.ProviderType);
|
||||
return strategy?.ShouldThreadWithItem(newItem, existingItem) ?? false;
|
||||
}
|
||||
|
||||
public ThreadMailItem CreateNewThread(IMailItem existingItem, MailCopy newItem)
|
||||
{
|
||||
var thread = new ThreadMailItem();
|
||||
thread.AddThreadItem(existingItem);
|
||||
thread.AddThreadItem(newItem);
|
||||
return thread;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user