Files
Wino-Mail/Wino.Core/Integration/Processors/GmailChangeProcessor.cs

97 lines
3.7 KiB
C#
Raw Normal View History

2024-08-29 23:58:39 +02:00
using System;
using System.Collections.Generic;
2024-08-29 23:58:39 +02:00
using System.Threading.Tasks;
using Google.Apis.Calendar.v3.Data;
using Wino.Core.Domain.Entities.Calendar;
using Wino.Core.Domain.Entities.Shared;
using Wino.Core.Domain.Enums;
2024-06-02 21:35:03 +02:00
using Wino.Core.Domain.Interfaces;
using Wino.Core.Domain.Models.MailItem;
using Wino.Services;
2024-06-02 21:35:03 +02:00
2025-02-16 11:54:23 +01:00
namespace Wino.Core.Integration.Processors;
public class GmailChangeProcessor : DefaultChangeProcessor, IGmailChangeProcessor
2024-06-02 21:35:03 +02:00
{
2025-02-16 11:54:23 +01:00
public GmailChangeProcessor(IDatabaseService databaseService,
IFolderService folderService,
IMailService mailService,
ICalendarService calendarService,
IAccountService accountService,
ICalendarServiceEx calendarServiceEx,
IMimeFileService mimeFileService) : base(databaseService, folderService, mailService, calendarService, accountService, calendarServiceEx, mimeFileService)
2024-06-02 21:35:03 +02:00
{
2025-02-16 11:54:23 +01:00
}
2024-08-29 23:58:39 +02:00
2025-02-16 11:54:23 +01:00
public Task MapLocalDraftAsync(string mailCopyId, string newDraftId, string newThreadId)
=> MailService.MapLocalDraftAsync(mailCopyId, newDraftId, newThreadId);
2025-02-16 11:54:23 +01:00
public Task CreateAssignmentAsync(Guid accountId, string mailCopyId, string remoteFolderId)
=> MailService.CreateAssignmentAsync(accountId, mailCopyId, remoteFolderId);
2025-02-16 11:54:23 +01:00
public async Task ManageCalendarEventAsync(Event calendarEvent, AccountCalendar assignedCalendar, MailAccount organizerAccount)
{
// TODO:
2025-02-16 11:54:23 +01:00
}
2025-02-16 11:54:23 +01:00
private string GetOrganizerName(Event calendarEvent, MailAccount account)
{
if (calendarEvent.Organizer == null) return string.Empty;
2025-02-16 11:54:23 +01:00
if (calendarEvent.Organizer.Self == true)
{
2025-02-16 11:54:23 +01:00
return account.SenderName;
}
2025-02-16 11:54:23 +01:00
else
return calendarEvent.Organizer.DisplayName;
}
2025-02-16 11:35:43 +01:00
2025-02-16 11:54:23 +01:00
private string GetOrganizerEmail(Event calendarEvent, MailAccount account)
{
if (calendarEvent.Organizer == null) return string.Empty;
if (calendarEvent.Organizer.Self == true)
{
2025-02-16 11:54:23 +01:00
return account.Address;
}
2025-02-16 11:54:23 +01:00
else
return calendarEvent.Organizer.Email;
}
2025-02-16 11:54:23 +01:00
private CalendarItemStatus GetStatus(string status)
{
return status switch
{
2025-02-16 11:54:23 +01:00
"confirmed" => CalendarItemStatus.Confirmed,
"tentative" => CalendarItemStatus.Tentative,
"cancelled" => CalendarItemStatus.Cancelled,
_ => CalendarItemStatus.Confirmed
};
}
2025-02-16 11:54:23 +01:00
private CalendarItemVisibility GetVisibility(string visibility)
{
/// Visibility of the event. Optional. Possible values are: - "default" - Uses the default visibility for
/// events on the calendar. This is the default value. - "public" - The event is public and event details are
/// visible to all readers of the calendar. - "private" - The event is private and only event attendees may
/// view event details. - "confidential" - The event is private. This value is provided for compatibility
/// reasons.
2025-02-16 11:54:23 +01:00
return visibility switch
{
"default" => CalendarItemVisibility.Default,
"public" => CalendarItemVisibility.Public,
"private" => CalendarItemVisibility.Private,
"confidential" => CalendarItemVisibility.Confidential,
_ => CalendarItemVisibility.Default
};
2024-06-02 21:35:03 +02:00
}
2025-02-16 11:54:23 +01:00
public Task<bool> HasAccountAnyDraftAsync(Guid accountId)
=> MailService.HasAccountAnyDraftAsync(accountId);
public Task<GmailArchiveComparisonResult> GetGmailArchiveComparisonResultAsync(Guid archiveFolderId, List<string> onlineArchiveMailIds)
=> MailService.GetGmailArchiveComparisonResultAsync(archiveFolderId, onlineArchiveMailIds);
2024-06-02 21:35:03 +02:00
}