Skip to content

Commit

Permalink
fix(calendar): update email alarm of yearly events
Browse files Browse the repository at this point in the history
We now compute the next alarms of a yrealy recurrent event for a period
of two years in order to make sure to pickup the next occurrence and
update the email alarms table, otherwise sogo-ealarms-notify was sending
email alarms every minute until the next alarm was properly computed.

Fixes #4991
  • Loading branch information
cgx committed Nov 25, 2021
1 parent fc121ac commit 9c025f6
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions SoObjects/Appointments/iCalEntityObject+SOGo.m
Original file line number Diff line number Diff line change
Expand Up @@ -761,8 +761,11 @@ - (void) updateNextAlarmDateInRow: (NSMutableDictionary *) row
NSMutableArray *alarms;

alarms = [NSMutableArray array];

// Compute the alarms for the next 2 years. We must cover more than 1 year since yearly alarms that are triggered
// 1 day before the event date require a range of at least 1 year and 1 day. Too play safe, we cover 2 years.
start = [NSCalendarDate date];
end = [start addYear:1 month:0 day:0 hour:0 minute:0 second:0];
end = [start addYear:2 month:0 day:0 hour:0 minute:0 second:0];
range = [NGCalendarDateRange calendarDateRangeWithStartDate: start
endDate: end];

Expand Down Expand Up @@ -832,12 +835,12 @@ - (void) updateNextAlarmDateInRow: (NSMutableDictionary *) row
|| ([webstatus caseInsensitiveCompare: @"TRIGGERED"]
!= NSOrderedSame))
v = delta;
nextAlarmDate = [NSDate dateWithTimeIntervalSince1970: [[[alarms objectAtIndex: i] objectForKey: @"c_nextalarm"] intValue]];
nextAlarmDate = [NSDate dateWithTimeIntervalSince1970: c_nextalarm];
}
else if ((anAlarm = [self firstEmailAlarm]) && af)

{
nextAlarmDate = [NSDate dateWithTimeIntervalSince1970: [[[alarms objectAtIndex: i] objectForKey: @"c_nextalarm"] intValue]];
nextAlarmDate = [NSDate dateWithTimeIntervalSince1970: c_nextalarm];
email_alarm_number = [[self alarms] indexOfObject: anAlarm];

if ([anAlarm userIsAttendee: alarmOwner])
Expand All @@ -857,7 +860,7 @@ - (void) updateNextAlarmDateInRow: (NSMutableDictionary *) row
}
}

// Don't update c_nextalarm in the quick table if it's not na email alarm
// Don't update c_nextalarm in the quick table if it's not an email alarm
if ([nextAlarmDate isNotNull] && email_alarm_number < 0)
{
[row setObject: [NSNumber numberWithInt: [nextAlarmDate timeIntervalSince1970]]
Expand Down

0 comments on commit 9c025f6

Please sign in to comment.