Add snooze support for calendar reminders (toast UI, service, DB) (#825)
* Filter reminder snooze options by default reminder * Some updates. * Fixing empty welcome page issue and attendee loading. * Icon system for notifications and snooze options etc.
This commit is contained in:
@@ -50,6 +50,12 @@ public partial class CalendarSettingsPageViewModel : CalendarBaseViewModel
|
||||
[ObservableProperty]
|
||||
public partial int SelectedDefaultReminderIndex { get; set; }
|
||||
|
||||
[ObservableProperty]
|
||||
public partial List<string> SnoozeOptions { get; set; } = [];
|
||||
|
||||
[ObservableProperty]
|
||||
public partial int SelectedDefaultSnoozeIndex { get; set; }
|
||||
|
||||
public IPreferencesService PreferencesService { get; }
|
||||
private readonly ICalendarService _calendarService;
|
||||
private readonly IAccountService _accountService;
|
||||
@@ -108,6 +114,15 @@ public partial class CalendarSettingsPageViewModel : CalendarBaseViewModel
|
||||
SelectedDefaultReminderIndex = index >= 0 ? index + 1 : 0;
|
||||
}
|
||||
|
||||
var supportedSnoozeMinutes = CalendarReminderSnoozeOptions.GetSupportedSnoozeMinutes().ToArray();
|
||||
foreach (var snoozeMinutes in supportedSnoozeMinutes)
|
||||
{
|
||||
SnoozeOptions.Add(string.Format(Translator.CalendarReminder_SnoozeMinutesOption, snoozeMinutes));
|
||||
}
|
||||
|
||||
var selectedSnoozeIndex = Array.IndexOf(supportedSnoozeMinutes, preferencesService.DefaultSnoozeDurationInMinutes);
|
||||
SelectedDefaultSnoozeIndex = selectedSnoozeIndex >= 0 ? selectedSnoozeIndex : 0;
|
||||
|
||||
_isLoaded = true;
|
||||
|
||||
// Load accounts with calendar support
|
||||
@@ -147,6 +162,7 @@ public partial class CalendarSettingsPageViewModel : CalendarBaseViewModel
|
||||
partial void OnWorkingDayStartIndexChanged(int value) => SaveSettings();
|
||||
partial void OnWorkingDayEndIndexChanged(int value) => SaveSettings();
|
||||
partial void OnSelectedDefaultReminderIndexChanged(int value) => SaveSettings();
|
||||
partial void OnSelectedDefaultSnoozeIndexChanged(int value) => SaveSettings();
|
||||
|
||||
public void SaveSettings()
|
||||
{
|
||||
@@ -205,6 +221,13 @@ public partial class CalendarSettingsPageViewModel : CalendarBaseViewModel
|
||||
PreferencesService.DefaultReminderDurationInSeconds = minutes * 60;
|
||||
}
|
||||
|
||||
var supportedSnoozeMinutes = CalendarReminderSnoozeOptions.GetSupportedSnoozeMinutes();
|
||||
if (supportedSnoozeMinutes.Count > 0)
|
||||
{
|
||||
var selectedIndex = Math.Clamp(SelectedDefaultSnoozeIndex, 0, supportedSnoozeMinutes.Count - 1);
|
||||
PreferencesService.DefaultSnoozeDurationInMinutes = supportedSnoozeMinutes[selectedIndex];
|
||||
}
|
||||
|
||||
Messenger.Send(new CalendarSettingsUpdatedMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ public partial class EventDetailsPageViewModel : CalendarBaseViewModel
|
||||
private readonly IWinoRequestDelegator _winoRequestDelegator;
|
||||
private readonly INavigationService _navigationService;
|
||||
private readonly IUnderlyingThemeService _underlyingThemeService;
|
||||
private readonly INotificationBuilder _notificationBuilder;
|
||||
private readonly IContactService _contactService;
|
||||
|
||||
public CalendarSettings CurrentSettings { get; }
|
||||
@@ -144,6 +145,7 @@ public partial class EventDetailsPageViewModel : CalendarBaseViewModel
|
||||
IMailDialogService dialogService,
|
||||
IWinoRequestDelegator winoRequestDelegator,
|
||||
INavigationService navigationService,
|
||||
INotificationBuilder notificationBuilder,
|
||||
IUnderlyingThemeService underlyingThemeService,
|
||||
IContactService contactService)
|
||||
{
|
||||
@@ -154,6 +156,7 @@ public partial class EventDetailsPageViewModel : CalendarBaseViewModel
|
||||
_winoRequestDelegator = winoRequestDelegator;
|
||||
_navigationService = navigationService;
|
||||
_underlyingThemeService = underlyingThemeService;
|
||||
_notificationBuilder = notificationBuilder;
|
||||
_contactService = contactService;
|
||||
|
||||
CurrentSettings = _preferencesService.GetCurrentCalendarSettings();
|
||||
@@ -259,8 +262,6 @@ public partial class EventDetailsPageViewModel : CalendarBaseViewModel
|
||||
|
||||
private async Task LoadAttendeesAsync(Guid calendarItemId, CalendarItem calendarItem)
|
||||
{
|
||||
CurrentEvent.Attendees.Clear();
|
||||
|
||||
var attendees = await _calendarService.GetAttendeesAsync(calendarItemId);
|
||||
|
||||
// Resolve contacts for all attendees in a single batch DB query.
|
||||
@@ -285,10 +286,12 @@ public partial class EventDetailsPageViewModel : CalendarBaseViewModel
|
||||
var organizer = attendees.FirstOrDefault(a => a.IsOrganizer);
|
||||
var nonOrganizerAttendees = attendees.Where(a => !a.IsOrganizer).ToList();
|
||||
|
||||
var attendeesForUi = new List<CalendarEventAttendee>();
|
||||
|
||||
// If the organizer is in the list, add them first
|
||||
if (organizer != null)
|
||||
{
|
||||
CurrentEvent.Attendees.Add(organizer);
|
||||
attendeesForUi.Add(organizer);
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(calendarItem.OrganizerEmail))
|
||||
{
|
||||
@@ -306,14 +309,27 @@ public partial class EventDetailsPageViewModel : CalendarBaseViewModel
|
||||
if (contactLookup.TryGetValue(calendarItem.OrganizerEmail, out var organizerContact))
|
||||
organizerAttendee.ResolvedContact = organizerContact;
|
||||
|
||||
CurrentEvent.Attendees.Add(organizerAttendee);
|
||||
attendeesForUi.Add(organizerAttendee);
|
||||
}
|
||||
|
||||
// Add all other attendees after the organizer
|
||||
foreach (var item in nonOrganizerAttendees)
|
||||
{
|
||||
CurrentEvent.Attendees.Add(item);
|
||||
attendeesForUi.Add(item);
|
||||
}
|
||||
|
||||
await ExecuteUIThread(() =>
|
||||
{
|
||||
if (CurrentEvent == null)
|
||||
return;
|
||||
|
||||
CurrentEvent.Attendees.Clear();
|
||||
|
||||
foreach (var attendee in attendeesForUi)
|
||||
{
|
||||
CurrentEvent.Attendees.Add(attendee);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private async Task LoadAttachmentsAsync(Guid calendarItemId)
|
||||
@@ -491,6 +507,24 @@ public partial class EventDetailsPageViewModel : CalendarBaseViewModel
|
||||
return _nativeAppService.LaunchUriAsync(new Uri(CurrentEvent.CalendarItem.HtmlLink));
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private Task CreateTestNotificationAsync()
|
||||
{
|
||||
if (CurrentEvent?.CalendarItem == null)
|
||||
return Task.CompletedTask;
|
||||
|
||||
var reminderDurationInSeconds = Reminders?
|
||||
.Where(x => x.DurationInSeconds > 0)
|
||||
.OrderByDescending(x => x.DurationInSeconds)
|
||||
.Select(x => x.DurationInSeconds)
|
||||
.FirstOrDefault() ?? 0;
|
||||
|
||||
if (reminderDurationInSeconds <= 0)
|
||||
reminderDurationInSeconds = Math.Max(_preferencesService.DefaultReminderDurationInSeconds, 30 * 60);
|
||||
|
||||
return _notificationBuilder.CreateCalendarReminderNotificationAsync(CurrentEvent.CalendarItem, reminderDurationInSeconds);
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void ToggleRsvpPanel()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user