Skip to content

Commit

Permalink
fixed alertsfield.
Browse files Browse the repository at this point in the history
fetch calendar's default alerts for caldav and activechange.
  • Loading branch information
dehart committed Jan 17, 2025
1 parent b279f36 commit 1bc4072
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 22 deletions.
2 changes: 1 addition & 1 deletion www/go/modules/community/calendar/model/Alert.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function buildCoreAlert(?CalendarEvent $event = null) : ?\go\core\model\A
$offset = $this->offset;
if($event->isRecurring()) {
list($recurrenceId, $next) = $event->upcomingOccurrence();
if(!isset($recurrenceId)) {
if(!isset($recurrenceId) || !isset($next)) {
return null;
}
$coreAlert->recurrenceId = $recurrenceId->format('Y-m-d\TH:i:s');
Expand Down
8 changes: 7 additions & 1 deletion www/go/modules/community/calendar/model/CalendarEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ private function updateAlerts($userId) {
/**
* @return Alert[]
*/
private function alerts() {
public function alerts() {
if($this->useDefaultAlerts) {
$calendar = Calendar::findById($this->calendarId, ['id', 'ownerId', $this->showWithoutTime?'defaultAlertsWithoutTime':'defaultAlertsWithTime']);
return ($this->showWithoutTime ? $calendar->defaultAlertsWithoutTime : $calendar->defaultAlertsWithTime) ?? [];
Expand Down Expand Up @@ -813,6 +813,12 @@ public function upcomingOccurrence() {
}
}
}
if(is_string($recurrenceId)) {
$recurrenceId = new \DateTime($recurrenceId, $this->timeZone());
}
if(is_string($nextOccurrence)) {
$nextOccurrence = new \DateTime($nextOccurrence, $this->timeZone());
}
$it = ICalendarHelper::makeRecurrenceIterator($this);
$nextRecurrenceId = null;
$rId = null;
Expand Down
29 changes: 14 additions & 15 deletions www/go/modules/community/calendar/model/ICalendarHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,22 @@ static function toVObject(CalendarEvent $event, ?VCalendar $vcalendar = null): V

$vevent = $vcalendar->add(self::toVEvent($vcalendar->createComponent('VEVENT'),$event));

if(!$event->useDefaultAlerts && is_array($event->alerts)) {
foreach($event->alerts as $id => $alert) {
if(!empty($alert->offset)) {
$vevent->add('VALARM', [
'TRIGGER' => $alert->offset, // 15 minutes before the event
'DESCRIPTION' => 'Alarm',
'ACTION' => $alert->action,
]);
} else if (!empty($alert->when)) {
$vevent->add('VALARM', [
'TRIGGER' => $alert->when, // 15 minutes before the event
'DESCRIPTION' => 'Alarm',
'ACTION' => $alert->action,
]);
}
foreach($event->alerts() as $id => $alert) {
if(!empty($alert->getTrigger()['offset'])) {
$vevent->add('VALARM', [
'TRIGGER' => $alert->getTrigger()['offset'], // 15 minutes before the event
'DESCRIPTION' => 'Alarm',
'ACTION' => $alert->action,
]);
} else if (!empty($alert->getTrigger()['when'])) {
$vevent->add('VALARM', [
'TRIGGER' => $alert->getTrigger()['when'], // 15 minutes before the event
'DESCRIPTION' => 'Alarm',
'ACTION' => $alert->action,
]);
}
}

//@todo: ATTACHMENT Files?
if($event->isRecurring()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ export class AlertField extends SelectField {
})
}

public onAdded(index: number){
super.onAdded(index);
if(!this.isForDefault) {
this.defaultValue = 'default';
}
}

drawOptions() {
this.options = this.fullDay ? [
{value: 'P0D', name: t('At the start day') + " (9:00)"},
Expand All @@ -40,7 +47,6 @@ export class AlertField extends SelectField {
{value: 'P0D', name: t('At the start')},
];
if(!this.isForDefault) {
this.value = 'default';
this.options.unshift({value: 'default', name: t('Default')});
}
this.options.unshift({value: null, name: t('None')})
Expand All @@ -56,7 +62,6 @@ export class AlertField extends SelectField {
}

set value(v: {[id:string]:Alert}|'default'|null) {

if(!v) {
v = null;
} else if(!(typeof v === 'string') ) {
Expand Down
7 changes: 4 additions & 3 deletions www/modules/z-push/backend/go/CalendarConvertor.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,11 @@ static function toSyncAppointment(CalendarEvent $event, ?SyncAppointment $except
}
}
//$message->reminder = 0; // timestamp or 0
if(!empty($event->alerts)) {
$firstAlert = array_shift($event->alerts);
$alerts = $event->alerts();
if(!empty($alerts)) {
$firstAlert = array_shift($alerts);

$coreAlert = $firstAlert->buildCoreAlert();
$coreAlert = $firstAlert->buildCoreAlert($event);
if($coreAlert) {
$triggerU = $coreAlert->triggerAt->format("U");
$message->reminder = ($message->starttime - $triggerU) / 60; // Reminder is in minutes before start
Expand Down

0 comments on commit 1bc4072

Please sign in to comment.