I dont know some improvements on reacting calendar changes.
This commit is contained in:
@@ -166,7 +166,6 @@ public partial class CalendarPageViewModel : CalendarBaseViewModel,
|
||||
base.RegisterRecipients();
|
||||
|
||||
Messenger.Register<LoadCalendarMessage>(this);
|
||||
Messenger.Register<CalendarItemDeleted>(this);
|
||||
Messenger.Register<CalendarSettingsUpdatedMessage>(this);
|
||||
Messenger.Register<CalendarItemTappedMessage>(this);
|
||||
Messenger.Register<CalendarItemDoubleTappedMessage>(this);
|
||||
@@ -177,7 +176,6 @@ public partial class CalendarPageViewModel : CalendarBaseViewModel,
|
||||
base.UnregisterRecipients();
|
||||
|
||||
Messenger.Unregister<LoadCalendarMessage>(this);
|
||||
Messenger.Unregister<CalendarItemDeleted>(this);
|
||||
Messenger.Unregister<CalendarSettingsUpdatedMessage>(this);
|
||||
Messenger.Unregister<CalendarItemTappedMessage>(this);
|
||||
Messenger.Unregister<CalendarItemDoubleTappedMessage>(this);
|
||||
@@ -613,30 +611,7 @@ public partial class CalendarPageViewModel : CalendarBaseViewModel,
|
||||
}
|
||||
}
|
||||
|
||||
protected override async void OnCalendarItemAdded(CalendarItem calendarItem)
|
||||
{
|
||||
base.OnCalendarItemAdded(calendarItem);
|
||||
|
||||
// Check if event falls into the current date range.
|
||||
|
||||
|
||||
if (DayRanges.DisplayRange == null) return;
|
||||
|
||||
// Check whether this event falls into any of the loaded date ranges.
|
||||
var allDaysForEvent = DayRanges.SelectMany(a => a.CalendarDays).Where(a => a.Period.OverlapsWith(calendarItem.Period));
|
||||
|
||||
foreach (var calendarDay in allDaysForEvent)
|
||||
{
|
||||
var calendarItemViewModel = new CalendarItemViewModel(calendarItem);
|
||||
|
||||
await ExecuteUIThread(() =>
|
||||
{
|
||||
calendarDay.EventsCollection.AddCalendarItem(calendarItemViewModel);
|
||||
});
|
||||
}
|
||||
|
||||
FilterActiveCalendars(DayRanges);
|
||||
}
|
||||
|
||||
private async Task InitializeCalendarEventsForDayRangeAsync(DayRangeRenderModel dayRangeRenderModel)
|
||||
{
|
||||
@@ -871,23 +846,36 @@ public partial class CalendarPageViewModel : CalendarBaseViewModel,
|
||||
|
||||
public void Receive(CalendarItemDoubleTappedMessage message) => NavigateEvent(message.CalendarItemViewModel, CalendarEventTargetType.Single);
|
||||
|
||||
public void Receive(CalendarItemRightTappedMessage message)
|
||||
{
|
||||
public void Receive(CalendarItemRightTappedMessage message) { }
|
||||
|
||||
protected override void OnCalendarItemDeleted(CalendarItem calendarItem)
|
||||
{
|
||||
base.OnCalendarItemDeleted(calendarItem);
|
||||
|
||||
Debug.WriteLine($"Calendar item deleted: {calendarItem.Id}");
|
||||
}
|
||||
|
||||
public async void Receive(CalendarItemDeleted message)
|
||||
protected override async void OnCalendarItemAdded(CalendarItem calendarItem)
|
||||
{
|
||||
// Each deleted recurrence will report for it's own.
|
||||
base.OnCalendarItemAdded(calendarItem);
|
||||
Debug.WriteLine($"Calendar item added: {calendarItem.Id}");
|
||||
|
||||
// Check if event falls into the current date range.
|
||||
if (DayRanges.DisplayRange == null) return;
|
||||
|
||||
// Check whether this event falls into any of the loaded date ranges.
|
||||
var allDaysForEvent = DayRanges.SelectMany(a => a.CalendarDays).Where(a => a.Period.OverlapsWith(calendarItem.Period));
|
||||
|
||||
foreach (var calendarDay in allDaysForEvent)
|
||||
{
|
||||
var calendarItemViewModel = new CalendarItemViewModel(calendarItem);
|
||||
|
||||
await ExecuteUIThread(() =>
|
||||
{
|
||||
var deletedItem = message.CalendarItem;
|
||||
|
||||
// Event might be spreaded into multiple days.
|
||||
// Remove from all.
|
||||
|
||||
// var calendarItems = GetCalendarItems(deletedItem.Id);
|
||||
calendarDay.EventsCollection.AddCalendarItem(calendarItemViewModel);
|
||||
});
|
||||
}
|
||||
|
||||
FilterActiveCalendars(DayRanges);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,4 +37,5 @@ public interface ICalendarService
|
||||
Task<CalendarItem> GetCalendarItemAsync(Guid id);
|
||||
Task<List<CalendarEventAttendee>> GetAttendeesAsync(Guid calendarEventTrackingId);
|
||||
Task<List<CalendarEventAttendee>> ManageEventAttendeesAsync(Guid calendarItemId, List<CalendarEventAttendee> allAttendees);
|
||||
Task UpdateCalendarItemAsync(CalendarItem calendarItem, List<CalendarEventAttendee> attendees);
|
||||
}
|
||||
|
||||
@@ -4,17 +4,26 @@ using Wino.Messaging.Client.Calendar;
|
||||
|
||||
namespace Wino.Core.ViewModels;
|
||||
|
||||
public class CalendarBaseViewModel : CoreBaseViewModel, IRecipient<CalendarItemAdded>
|
||||
public class CalendarBaseViewModel : CoreBaseViewModel,
|
||||
IRecipient<CalendarItemAdded>,
|
||||
IRecipient<CalendarItemUpdated>,
|
||||
IRecipient<CalendarItemDeleted>
|
||||
{
|
||||
public void Receive(CalendarItemAdded message) => OnCalendarItemAdded(message.CalendarItem);
|
||||
public void Receive(CalendarItemUpdated message) => OnCalendarItemUpdated(message.CalendarItem);
|
||||
public void Receive(CalendarItemDeleted message) => OnCalendarItemDeleted(message.CalendarItem);
|
||||
|
||||
protected virtual void OnCalendarItemAdded(CalendarItem calendarItem) { }
|
||||
protected virtual void OnCalendarItemUpdated(CalendarItem calendarItem) { }
|
||||
protected virtual void OnCalendarItemDeleted(CalendarItem calendarItem) { }
|
||||
|
||||
protected override void RegisterRecipients()
|
||||
{
|
||||
base.RegisterRecipients();
|
||||
|
||||
Messenger.Register<CalendarItemAdded>(this);
|
||||
Messenger.Register<CalendarItemUpdated>(this);
|
||||
Messenger.Register<CalendarItemDeleted>(this);
|
||||
}
|
||||
|
||||
protected override void UnregisterRecipients()
|
||||
@@ -22,5 +31,7 @@ public class CalendarBaseViewModel : CoreBaseViewModel, IRecipient<CalendarItemA
|
||||
base.UnregisterRecipients();
|
||||
|
||||
Messenger.Unregister<CalendarItemAdded>(this);
|
||||
Messenger.Unregister<CalendarItemUpdated>(this);
|
||||
Messenger.Unregister<CalendarItemDeleted>(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Graph.Models;
|
||||
@@ -49,6 +50,7 @@ public class OutlookChangeProcessor(IDatabaseService databaseService,
|
||||
var savingItem = await CalendarService.GetCalendarItemAsync(assignedCalendar.Id, calendarEvent.Id);
|
||||
|
||||
Guid savingItemId = Guid.Empty;
|
||||
bool isNewItem = savingItem == null;
|
||||
|
||||
if (savingItem != null)
|
||||
savingItemId = savingItem.Id;
|
||||
@@ -164,15 +166,23 @@ public class OutlookChangeProcessor(IDatabaseService databaseService,
|
||||
savingItem.Status = CalendarItemStatus.Confirmed;
|
||||
}
|
||||
|
||||
// Upsert the event.
|
||||
await Connection.InsertOrReplaceAsync(savingItem, typeof(CalendarItem));
|
||||
|
||||
// Manage attendees.
|
||||
// Prepare attendees list
|
||||
List<CalendarEventAttendee> attendees = null;
|
||||
if (calendarEvent.Attendees != null)
|
||||
{
|
||||
// Clear all attendees for this event.
|
||||
var attendees = calendarEvent.Attendees.Select(a => a.CreateAttendee(savingItemId)).ToList();
|
||||
await CalendarService.ManageEventAttendeesAsync(savingItemId, attendees).ConfigureAwait(false);
|
||||
attendees = calendarEvent.Attendees.Select(a => a.CreateAttendee(savingItemId)).ToList();
|
||||
}
|
||||
|
||||
// Use CalendarService to create or update the event
|
||||
if (isNewItem)
|
||||
{
|
||||
// New item - use CreateNewCalendarItemAsync
|
||||
await CalendarService.CreateNewCalendarItemAsync(savingItem, attendees).ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Existing item - use UpdateCalendarItemAsync
|
||||
await CalendarService.UpdateCalendarItemAsync(savingItem, attendees).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,8 +24,6 @@ public partial class CustomCalendarFlipView : FlipView
|
||||
// Hide navigation buttons
|
||||
PreviousButton.Opacity = NextButton.Opacity = 0;
|
||||
PreviousButton.IsHitTestVisible = NextButton.IsHitTestVisible = false;
|
||||
|
||||
var t = FindName("ScrollingHost");
|
||||
}
|
||||
|
||||
public void GoPreviousFlip()
|
||||
|
||||
@@ -133,7 +133,6 @@ public partial class WinoCalendarControl : Control
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void OnActiveVerticalScrollViewerChanged(DependencyObject calendar, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
if (calendar is WinoCalendarControl calendarControl)
|
||||
@@ -152,7 +151,6 @@ public partial class WinoCalendarControl : Control
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void OnActiveCanvasChanged(DependencyObject calendar, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
if (calendar is WinoCalendarControl calendarControl)
|
||||
@@ -189,6 +187,8 @@ public partial class WinoCalendarControl : Control
|
||||
canvas.SelectedDateTime = null;
|
||||
canvas.TimelineCellSelected -= ActiveTimelineCellSelected;
|
||||
canvas.TimelineCellUnselected -= ActiveTimelineCellUnselected;
|
||||
|
||||
canvas.Dispose();
|
||||
}
|
||||
|
||||
private void RegisterCanvas(WinoDayTimelineCanvas canvas)
|
||||
|
||||
@@ -8,13 +8,13 @@ using CommunityToolkit.Mvvm.Messaging;
|
||||
using Ical.Net.CalendarComponents;
|
||||
using Ical.Net.DataTypes;
|
||||
using Itenso.TimePeriod;
|
||||
using Serilog;
|
||||
using Wino.Core.Domain;
|
||||
using Wino.Core.Domain.Entities.Calendar;
|
||||
using Wino.Core.Domain.Enums;
|
||||
using Wino.Core.Domain.Interfaces;
|
||||
using Wino.Core.Domain.Models.Calendar;
|
||||
using Wino.Messaging.Client.Calendar;
|
||||
using Wino.Services.Extensions;
|
||||
|
||||
namespace Wino.Services;
|
||||
|
||||
@@ -77,6 +77,8 @@ public class CalendarService : BaseDatabaseService, ICalendarService
|
||||
}
|
||||
|
||||
public async Task CreateNewCalendarItemAsync(CalendarItem calendarItem, List<CalendarEventAttendee> attendees)
|
||||
{
|
||||
try
|
||||
{
|
||||
await Connection.RunInTransactionAsync((conn) =>
|
||||
{
|
||||
@@ -90,6 +92,36 @@ public class CalendarService : BaseDatabaseService, ICalendarService
|
||||
|
||||
WeakReferenceMessenger.Default.Send(new CalendarItemAdded(calendarItem));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, "Error creating new calendar item");
|
||||
}
|
||||
}
|
||||
|
||||
public async Task UpdateCalendarItemAsync(CalendarItem calendarItem, List<CalendarEventAttendee> attendees)
|
||||
{
|
||||
try
|
||||
{
|
||||
await Connection.RunInTransactionAsync((conn) =>
|
||||
{
|
||||
conn.Update(calendarItem, typeof(CalendarItem));
|
||||
|
||||
// Clear existing attendees and add new ones
|
||||
conn.Table<CalendarEventAttendee>().Delete(a => a.CalendarItemId == calendarItem.Id);
|
||||
|
||||
if (attendees != null)
|
||||
{
|
||||
conn.InsertAll(attendees, typeof(CalendarEventAttendee));
|
||||
}
|
||||
});
|
||||
|
||||
WeakReferenceMessenger.Default.Send(new CalendarItemUpdated(calendarItem));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, "Error updating calendar item");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves calendar events for a given calendar within the specified time period.
|
||||
|
||||
Reference in New Issue
Block a user