Synchronizing calendars for gmail and some events.
This commit is contained in:
71
Wino.Services/CalendarService.cs
Normal file
71
Wino.Services/CalendarService.cs
Normal file
@@ -0,0 +1,71 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using SqlKata;
|
||||
using Wino.Core.Domain.Entities.Calendar;
|
||||
using Wino.Core.Domain.Interfaces;
|
||||
using Wino.Messaging.Client.Calendar;
|
||||
using Wino.Services.Extensions;
|
||||
|
||||
namespace Wino.Services
|
||||
{
|
||||
public class CalendarService : BaseDatabaseService, ICalendarService
|
||||
{
|
||||
public CalendarService(IDatabaseService databaseService) : base(databaseService)
|
||||
{
|
||||
}
|
||||
|
||||
public Task<List<AccountCalendar>> GetAccountCalendarsAsync(Guid accountId)
|
||||
=> Connection.Table<AccountCalendar>().Where(x => x.AccountId == accountId).ToListAsync();
|
||||
|
||||
public async Task InsertAccountCalendarAsync(AccountCalendar accountCalendar)
|
||||
{
|
||||
await Connection.InsertAsync(accountCalendar);
|
||||
|
||||
WeakReferenceMessenger.Default.Send(new CalendarListAdded(accountCalendar));
|
||||
}
|
||||
|
||||
public async Task UpdateAccountCalendarAsync(AccountCalendar accountCalendar)
|
||||
{
|
||||
await Connection.UpdateAsync(accountCalendar);
|
||||
|
||||
WeakReferenceMessenger.Default.Send(new CalendarListUpdated(accountCalendar));
|
||||
}
|
||||
|
||||
public async Task DeleteAccountCalendarAsync(AccountCalendar accountCalendar)
|
||||
{
|
||||
var deleteCalendarItemsQuery = new Query()
|
||||
.From(nameof(CalendarItem))
|
||||
.Where(nameof(CalendarItem.CalendarId), accountCalendar.Id)
|
||||
.Where(nameof(AccountCalendar.AccountId), accountCalendar.AccountId);
|
||||
|
||||
var rawQuery = deleteCalendarItemsQuery.GetRawQuery();
|
||||
|
||||
await Connection.ExecuteAsync(rawQuery);
|
||||
await Connection.DeleteAsync(accountCalendar);
|
||||
|
||||
WeakReferenceMessenger.Default.Send(new CalendarListDeleted(accountCalendar));
|
||||
}
|
||||
|
||||
public async Task DeleteCalendarItemAsync(Guid calendarItemId)
|
||||
{
|
||||
var calendarItem = await Connection.GetAsync<CalendarItem>(calendarItemId);
|
||||
|
||||
if (calendarItem == null) return;
|
||||
|
||||
await Connection.Table<CalendarItem>().DeleteAsync(x => x.Id == calendarItemId);
|
||||
|
||||
WeakReferenceMessenger.Default.Send(new CalendarItemDeleted(calendarItem));
|
||||
}
|
||||
|
||||
public Task CreateNewCalendarItemAsync(CalendarItem calendarItem, List<CalendarEventAttendee> attendees)
|
||||
{
|
||||
return Connection.RunInTransactionAsync((conn) =>
|
||||
{
|
||||
conn.Insert(calendarItem);
|
||||
conn.InsertAll(attendees);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,15 @@ namespace Wino.Services
|
||||
{
|
||||
public ContactService(IDatabaseService databaseService) : base(databaseService) { }
|
||||
|
||||
public async Task<AccountContact> CreateNewContactAsync(string address, string displayName)
|
||||
{
|
||||
var contact = new AccountContact() { Address = address, Name = displayName };
|
||||
|
||||
await Connection.InsertAsync(contact).ConfigureAwait(false);
|
||||
|
||||
return contact;
|
||||
}
|
||||
|
||||
public Task<List<AccountContact>> GetAddressInformationAsync(string queryText)
|
||||
{
|
||||
if (queryText == null || queryText.Length < 2)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using SQLite;
|
||||
using Wino.Core.Domain.Entities.Calendar;
|
||||
using Wino.Core.Domain.Entities.Mail;
|
||||
using Wino.Core.Domain.Entities.Shared;
|
||||
using Wino.Core.Domain.Interfaces;
|
||||
@@ -52,7 +53,11 @@ namespace Wino.Services
|
||||
typeof(AccountSignature),
|
||||
typeof(MergedInbox),
|
||||
typeof(MailAccountPreferences),
|
||||
typeof(MailAccountAlias)
|
||||
typeof(MailAccountAlias),
|
||||
typeof(AccountCalendar),
|
||||
typeof(CalendarEventAttendee),
|
||||
typeof(CalendarItem),
|
||||
typeof(Reminder)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ namespace Wino.Services
|
||||
services.AddSingleton<ILaunchProtocolService, LaunchProtocolService>();
|
||||
services.AddSingleton<IMimeFileService, MimeFileService>();
|
||||
|
||||
services.AddTransient<ICalendarService, CalendarService>();
|
||||
services.AddTransient<IMailService, MailService>();
|
||||
services.AddTransient<IFolderService, FolderService>();
|
||||
services.AddTransient<IAccountService, AccountService>();
|
||||
|
||||
Reference in New Issue
Block a user