2007-06-01 06:10:03 +02:00
|
|
|
/* iCalEntityObject+SOGo.m - this file is part of SOGo
|
|
|
|
*
|
2016-11-02 23:16:45 +01:00
|
|
|
* Copyright (C) 2007-2016 Inverse inc.
|
2007-06-01 06:10:03 +02:00
|
|
|
*
|
|
|
|
* This file is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This file is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2008-08-09 10:18:18 +02:00
|
|
|
#import <Foundation/NSCalendarDate.h>
|
2015-01-21 20:46:36 +01:00
|
|
|
#import <Foundation/NSDictionary.h>
|
2008-07-12 00:28:12 +02:00
|
|
|
#import <Foundation/NSValue.h>
|
2008-07-16 23:48:54 +02:00
|
|
|
#import <Foundation/NSTimeZone.h>
|
2007-06-01 06:10:03 +02:00
|
|
|
|
2016-11-02 23:16:45 +01:00
|
|
|
#import <GDLContentStore/GCSAlarmsFolder.h>
|
|
|
|
#import <GDLContentStore/GCSFolderManager.h>
|
|
|
|
|
2015-01-21 20:46:36 +01:00
|
|
|
#import <NGCards/iCalTrigger.h>
|
2014-09-12 14:34:15 +02:00
|
|
|
#import <NGCards/iCalRepeatableEntityObject.h>
|
2015-01-21 20:46:36 +01:00
|
|
|
#import <NGCards/NSString+NGCards.h>
|
2014-09-12 14:34:15 +02:00
|
|
|
|
|
|
|
#import <NGExtensions/NGCalendarDateRange.h>
|
|
|
|
#import <NGExtensions/NSNull+misc.h>
|
2015-02-18 20:55:21 +01:00
|
|
|
#import <NGExtensions/NSObject+Logs.h>
|
2014-09-12 14:34:15 +02:00
|
|
|
|
|
|
|
#import "SOGoAppointmentFolder.h"
|
2007-09-04 17:42:13 +02:00
|
|
|
|
2008-07-16 23:48:54 +02:00
|
|
|
#import <NGObjWeb/WOContext+SoObjects.h>
|
|
|
|
|
2010-01-06 20:21:15 +01:00
|
|
|
#import <SOGo/NSArray+Utilities.h>
|
2015-02-12 21:01:26 +01:00
|
|
|
#import <SOGo/SOGoSource.h>
|
2016-11-02 23:16:45 +01:00
|
|
|
#import <SOGo/SOGoSystemDefaults.h>
|
2010-01-06 20:21:15 +01:00
|
|
|
#import <SOGo/SOGoUser.h>
|
|
|
|
#import <SOGo/SOGoUserDefaults.h>
|
2015-02-12 21:01:26 +01:00
|
|
|
#import <SOGo/SOGoUserManager.h>
|
2007-06-01 06:10:03 +02:00
|
|
|
|
2007-11-18 11:16:25 +01:00
|
|
|
#import "iCalPerson+SOGo.h"
|
2015-02-12 21:01:26 +01:00
|
|
|
#import "iCalAlarm+SOGo.h"
|
2014-09-12 14:34:15 +02:00
|
|
|
#import "iCalCalendar+SOGo.h"
|
2007-06-01 06:10:03 +02:00
|
|
|
#import "iCalEntityObject+SOGo.h"
|
|
|
|
|
2010-01-22 18:32:06 +01:00
|
|
|
NSCalendarDate *iCalDistantFuture = nil;
|
|
|
|
NSNumber *iCalDistantFutureNumber = nil;
|
|
|
|
|
2007-06-01 06:10:03 +02:00
|
|
|
@implementation iCalEntityObject (SOGoExtensions)
|
|
|
|
|
2010-01-22 18:32:06 +01:00
|
|
|
+ (void) initializeSOGoExtensions
|
2008-07-12 00:28:12 +02:00
|
|
|
{
|
|
|
|
if (!iCalDistantFuture)
|
|
|
|
{
|
|
|
|
iCalDistantFuture = [[NSCalendarDate distantFuture] retain];
|
|
|
|
/* INT_MAX due to Postgres constraint */
|
|
|
|
iCalDistantFutureNumber = [[NSNumber numberWithUnsignedInt: INT_MAX] retain];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-21 20:46:36 +01:00
|
|
|
/**
|
|
|
|
* @see [UIxAppointmentEditor viewAction]
|
2015-06-25 17:17:53 +02:00
|
|
|
* @see [UIxTaskEditor viewAction]
|
2015-01-21 20:46:36 +01:00
|
|
|
*/
|
2015-02-12 21:01:26 +01:00
|
|
|
- (NSDictionary *) attributesInContext: (WOContext *) context
|
2015-01-21 20:46:36 +01:00
|
|
|
{
|
|
|
|
NSArray *elements;
|
2015-01-28 16:05:18 +01:00
|
|
|
NSMutableArray *attendees;
|
2015-02-12 21:01:26 +01:00
|
|
|
NSDictionary *contactData;
|
2015-06-22 15:20:35 +02:00
|
|
|
NSMutableDictionary *data, *organizerData, *attendeeData;
|
2015-01-21 20:46:36 +01:00
|
|
|
NSEnumerator *attendeesList;
|
2015-02-12 21:01:26 +01:00
|
|
|
NSString *uid, *domain, *sentBy;
|
|
|
|
NSObject <SOGoSource> *source;
|
|
|
|
SOGoUserManager *um;
|
2015-01-21 20:46:36 +01:00
|
|
|
iCalPerson *organizer, *currentAttendee;
|
|
|
|
id value;
|
|
|
|
|
2015-02-12 21:01:26 +01:00
|
|
|
um = [SOGoUserManager sharedUserManager];
|
|
|
|
|
2015-01-21 20:46:36 +01:00
|
|
|
data = [NSMutableDictionary dictionaryWithObjectsAndKeys:
|
|
|
|
[[self tag] lowercaseString], @"component",
|
|
|
|
[self summary], @"summary",
|
|
|
|
nil];
|
|
|
|
|
2015-02-17 22:09:16 +01:00
|
|
|
value = [self priority];
|
2016-04-21 19:53:57 +02:00
|
|
|
if ([value length]) [data setObject: [NSNumber numberWithInteger: [value intValue]] forKey: @"priority"];
|
2015-02-17 22:09:16 +01:00
|
|
|
|
2015-01-21 20:46:36 +01:00
|
|
|
value = [self location];
|
2015-02-17 22:09:16 +01:00
|
|
|
if ([value length]) [data setObject: value forKey: @"location"];
|
2015-02-12 21:01:26 +01:00
|
|
|
|
|
|
|
value = [self comment];
|
2015-02-17 22:09:16 +01:00
|
|
|
if ([value length]) [data setObject: value forKey: @"comment"];
|
2015-02-12 21:01:26 +01:00
|
|
|
|
|
|
|
value = [self accessClass];
|
2015-06-25 17:17:53 +02:00
|
|
|
if ([value length]) [data setObject: [value lowercaseString] forKey: @"classification"];
|
2015-02-12 21:01:26 +01:00
|
|
|
|
|
|
|
value = [self status];
|
2015-06-25 17:17:53 +02:00
|
|
|
if ([value length]) [data setObject: [value lowercaseString] forKey: @"status"];
|
2015-02-12 21:01:26 +01:00
|
|
|
|
|
|
|
value = [self createdBy];
|
|
|
|
if (value) [data setObject: value forKey: @"createdBy"];
|
2015-01-21 20:46:36 +01:00
|
|
|
|
|
|
|
// Categories
|
2015-01-28 16:05:18 +01:00
|
|
|
elements = [self categories];
|
|
|
|
if ([elements count])
|
|
|
|
[data setObject: elements forKey: @"categories"];
|
2015-01-21 20:46:36 +01:00
|
|
|
|
2015-02-12 21:01:26 +01:00
|
|
|
// Send appointment notifications when the custom tag is *not* set
|
2015-01-21 20:46:36 +01:00
|
|
|
value = [self firstChildWithTag: @"X-SOGo-Send-Appointment-Notifications"];
|
2015-02-12 21:01:26 +01:00
|
|
|
[data setObject: [NSNumber numberWithBool: (value? 0:1)] forKey: @"sendAppointmentNotifications"];
|
2015-01-21 20:46:36 +01:00
|
|
|
|
|
|
|
// Organizer
|
|
|
|
organizer = [self organizer];
|
2015-02-17 22:09:16 +01:00
|
|
|
if ([[organizer email] length])
|
2015-01-21 20:46:36 +01:00
|
|
|
{
|
2015-02-12 21:01:26 +01:00
|
|
|
organizerData = [NSMutableDictionary dictionaryWithObjectsAndKeys:
|
|
|
|
[organizer rfc822Email], @"email",
|
2016-06-21 21:57:35 +02:00
|
|
|
([[organizer cnWithoutQuotes] length] ? [organizer cnWithoutQuotes] : [organizer rfc822Email]), @"name",
|
2015-02-12 21:01:26 +01:00
|
|
|
nil];
|
|
|
|
uid = [organizer uid];
|
|
|
|
if ([uid length]) [organizerData setObject: uid forKey: @"uid"];
|
|
|
|
sentBy = [organizer sentBy];
|
|
|
|
if ([sentBy length]) [organizerData setObject: sentBy forKey: @"sentBy"];
|
2015-01-21 20:46:36 +01:00
|
|
|
[data setObject: organizerData forKey: @"organizer"];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Attendees
|
|
|
|
attendees = [NSMutableArray array];
|
|
|
|
attendeesList = [[self attendees] objectEnumerator];
|
|
|
|
while ((currentAttendee = [attendeesList nextObject]))
|
|
|
|
{
|
|
|
|
attendeeData = [NSMutableDictionary dictionaryWithObjectsAndKeys:
|
|
|
|
[currentAttendee rfc822Email], @"email",
|
2016-06-21 21:57:35 +02:00
|
|
|
([[currentAttendee cnWithoutQuotes] length] ? [currentAttendee cnWithoutQuotes] : [currentAttendee rfc822Email]) , @"name",
|
2015-01-21 20:46:36 +01:00
|
|
|
nil];
|
2015-02-12 21:01:26 +01:00
|
|
|
if ((uid = [currentAttendee uid]))
|
|
|
|
{
|
|
|
|
[attendeeData setObject: uid forKey: @"uid"];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Search for attendee in global contacts sources that are associated with a MS Exchange server
|
|
|
|
domain = [[context activeUser] domain];
|
|
|
|
elements = [um fetchContactsMatching: [currentAttendee rfc822Email] inDomain: domain];
|
|
|
|
if ([elements count] == 1)
|
|
|
|
{
|
|
|
|
contactData = [elements lastObject];
|
|
|
|
source = [contactData objectForKey: @"source"];
|
|
|
|
if ([source conformsToProtocol: @protocol (SOGoDNSource)] &&
|
|
|
|
[[(NSObject <SOGoDNSource>*) source MSExchangeHostname] length])
|
|
|
|
{
|
|
|
|
uid = [NSString stringWithFormat: @"%@:%@", [[context activeUser] login],
|
|
|
|
[contactData valueForKey: @"c_uid"]];
|
|
|
|
[attendeeData setObject: uid forKey: @"uid"];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-06-17 21:24:59 +02:00
|
|
|
[attendeeData setObject: [[currentAttendee partStat] lowercaseString] forKey: @"partstat"];
|
2015-01-21 20:46:36 +01:00
|
|
|
[attendeeData setObject: [[currentAttendee role] lowercaseString] forKey: @"role"];
|
|
|
|
if ([[currentAttendee delegatedTo] length])
|
|
|
|
[attendeeData setObject: [[currentAttendee delegatedTo] rfc822Email] forKey: @"delegatedTo"];
|
|
|
|
if ([[currentAttendee delegatedFrom] length])
|
|
|
|
[attendeeData setObject: [[currentAttendee delegatedFrom] rfc822Email] forKey: @"delegatedFrom"];
|
|
|
|
|
|
|
|
[attendees addObject: attendeeData];
|
|
|
|
}
|
|
|
|
if ([attendees count])
|
|
|
|
[data setObject: attendees forKey: @"attendees"];
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2015-02-17 22:09:16 +01:00
|
|
|
// From [UIxTimeDatePicker takeValuesFromRequest:inContext:]
|
|
|
|
- (void) adjustDate: (NSCalendarDate **) date
|
|
|
|
withTimeString: (NSString *) timeString
|
|
|
|
inContext: (WOContext *) context
|
|
|
|
{
|
|
|
|
unsigned _year, _month, _day, _hour, _minute;
|
|
|
|
SOGoUserDefaults *ud;
|
|
|
|
NSArray *_time;
|
|
|
|
|
|
|
|
_year = [*date yearOfCommonEra];
|
|
|
|
_month = [*date monthOfYear];
|
|
|
|
_day = [*date dayOfMonth];
|
|
|
|
_time = [timeString componentsSeparatedByString: @":"];
|
|
|
|
_hour = [[_time objectAtIndex: 0] intValue];
|
|
|
|
_minute = [[_time objectAtIndex: 1] intValue];
|
|
|
|
|
|
|
|
ud = [[context activeUser] userDefaults];
|
|
|
|
*date = [NSCalendarDate dateWithYear: _year month: _month day: _day
|
|
|
|
hour: _hour minute: _minute second: 0
|
|
|
|
timeZone: [ud timeZone]];
|
|
|
|
}
|
|
|
|
|
2015-02-12 21:01:26 +01:00
|
|
|
- (void) _setAttendees: (NSArray *) attendees
|
|
|
|
{
|
|
|
|
NSMutableArray *newAttendees;
|
|
|
|
NSUInteger count, max;
|
|
|
|
NSString *currentEmail;
|
|
|
|
iCalPerson *currentAttendee;
|
|
|
|
NSString *role, *partstat;
|
|
|
|
NSDictionary *currentData;
|
|
|
|
|
|
|
|
if (attendees)
|
|
|
|
{
|
|
|
|
newAttendees = [NSMutableArray array];
|
|
|
|
max = [attendees count];
|
|
|
|
for (count = 0; count < max; count++)
|
|
|
|
{
|
|
|
|
currentData = [attendees objectAtIndex: count];
|
|
|
|
currentEmail = [currentData objectForKey: @"email"];
|
|
|
|
if ([currentEmail length] > 0)
|
|
|
|
{
|
|
|
|
role = [[currentData objectForKey: @"role"] uppercaseString];
|
|
|
|
if (!role)
|
|
|
|
role = @"REQ-PARTICIPANT";
|
|
|
|
if ([role isEqualToString: @"NON-PARTICIPANT"])
|
|
|
|
partstat = @"";
|
|
|
|
else
|
|
|
|
{
|
|
|
|
partstat = [[currentData objectForKey: @"partstat"] uppercaseString];
|
|
|
|
if (!partstat)
|
|
|
|
partstat = @"NEEDS-ACTION";
|
|
|
|
}
|
|
|
|
currentAttendee = [self findAttendeeWithEmail: currentEmail];
|
|
|
|
if (!currentAttendee)
|
|
|
|
{
|
|
|
|
currentAttendee = [iCalPerson elementWithTag: @"attendee"];
|
|
|
|
[currentAttendee setCn: [currentData objectForKey: @"name"]];
|
|
|
|
[currentAttendee setEmail: currentEmail];
|
|
|
|
}
|
2016-06-17 21:24:59 +02:00
|
|
|
if (!currentAttendee || ![[currentAttendee role] isEqualToString: role])
|
|
|
|
// Set the RSVP only if this is a new attendee or the role has changed
|
|
|
|
[currentAttendee
|
2015-02-12 21:01:26 +01:00
|
|
|
setRsvp: ([role isEqualToString: @"NON-PARTICIPANT"]
|
|
|
|
? @"FALSE"
|
|
|
|
: @"TRUE")];
|
|
|
|
[currentAttendee setRole: role];
|
|
|
|
[currentAttendee setPartStat: partstat];
|
|
|
|
[newAttendees addObject: currentAttendee];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
[self setAttendees: newAttendees];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) _appendAttendeesToEmailAlarm: (iCalAlarm *) alarm
|
|
|
|
{
|
|
|
|
NSArray *attendees;
|
|
|
|
NSMutableArray *aAttendees;
|
|
|
|
int count, max;
|
|
|
|
iCalPerson *currentAttendee, *aAttendee;
|
|
|
|
|
|
|
|
attendees = [self attendees];
|
|
|
|
max = [attendees count];
|
|
|
|
aAttendees = [NSMutableArray arrayWithCapacity: max];
|
|
|
|
for (count = 0; count < max; count++)
|
|
|
|
{
|
|
|
|
currentAttendee = [attendees objectAtIndex: count];
|
|
|
|
aAttendee = [iCalPerson elementWithTag: @"attendee"];
|
|
|
|
[aAttendee setCn: [currentAttendee cn]];
|
|
|
|
[aAttendee setEmail: [currentAttendee rfc822Email]];
|
|
|
|
[aAttendees addObject: aAttendee];
|
|
|
|
}
|
|
|
|
[alarm setAttendees: aAttendees];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) _setAlarm: (NSDictionary *) alarm
|
|
|
|
forOwner: (NSString *) owner
|
|
|
|
{
|
|
|
|
iCalAlarm *anAlarm;
|
|
|
|
NSString *reminderAction, *reminderUnit, *reminderQuantity, *reminderReference, *reminderRelation;
|
|
|
|
BOOL reminderEmailAttendees, reminderEmailOrganizer;
|
|
|
|
|
|
|
|
reminderAction = [alarm objectForKey: @"action"];
|
|
|
|
reminderUnit = [alarm objectForKey: @"unit"];
|
|
|
|
reminderQuantity = [alarm objectForKey: @"quantity"];
|
|
|
|
reminderReference = [alarm objectForKey: @"reference"];
|
|
|
|
reminderRelation = [alarm objectForKey: @"relation"];
|
|
|
|
reminderEmailAttendees = [[alarm objectForKey: @"attendees"] boolValue];
|
|
|
|
reminderEmailOrganizer = [[alarm objectForKey: @"organizer"] boolValue];
|
|
|
|
anAlarm = [iCalAlarm alarmForEvent: self
|
|
|
|
owner: owner
|
|
|
|
action: reminderAction
|
|
|
|
unit: reminderUnit
|
|
|
|
quantity: reminderQuantity
|
|
|
|
reference: reminderReference
|
|
|
|
reminderRelation: reminderRelation
|
|
|
|
emailAttendees: reminderEmailAttendees
|
|
|
|
emailOrganizer: reminderEmailOrganizer];
|
|
|
|
|
|
|
|
// If there was an unsupported alarm defined in the event, it will be deleted.
|
|
|
|
[self removeAllAlarms];
|
|
|
|
if (anAlarm)
|
|
|
|
{
|
|
|
|
[self addToAlarms: anAlarm];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see [UIxAppointmentEditor saveAction]
|
|
|
|
*/
|
|
|
|
- (void) setAttributes: (NSDictionary *) data
|
|
|
|
inContext: (WOContext *) context
|
|
|
|
{
|
|
|
|
NSString *owner;
|
|
|
|
id o, sendAppointmentNotifications;
|
|
|
|
|
|
|
|
o = [data objectForKey: @"summary"];
|
|
|
|
if ([o isKindOfClass: [NSString class]])
|
|
|
|
[self setSummary: o];
|
|
|
|
|
|
|
|
o = [data objectForKey: @"priority"];
|
|
|
|
if ([o isKindOfClass: [NSNumber class]])
|
|
|
|
[self setPriority: [NSString stringWithFormat: @"%d", [o intValue]]];
|
|
|
|
|
|
|
|
o = [data objectForKey: @"location"];
|
|
|
|
if ([o isKindOfClass: [NSString class]])
|
|
|
|
[self setLocation: o];
|
|
|
|
|
|
|
|
o = [data objectForKey: @"comment"];
|
|
|
|
if ([o isKindOfClass: [NSString class]])
|
|
|
|
[self setComment: [o stringByReplacingString: @"\r\n" withString: @"\n"]];
|
|
|
|
|
|
|
|
o = [data objectForKey: @"classification"];
|
|
|
|
if ([o isKindOfClass: [NSString class]])
|
|
|
|
[self setAccessClass: [o uppercaseString]];
|
|
|
|
|
|
|
|
o = [data objectForKey: @"status"];
|
|
|
|
if ([o isKindOfClass: [NSString class]])
|
2015-02-18 20:55:21 +01:00
|
|
|
[self setStatus: [o uppercaseString]];
|
2015-02-12 21:01:26 +01:00
|
|
|
|
|
|
|
o = [data objectForKey: @"categories"];
|
|
|
|
if ([o isKindOfClass: [NSArray class]])
|
|
|
|
[self setCategories: o];
|
|
|
|
|
|
|
|
o = [data objectForKey: @"sendAppointmentNotifications"];
|
|
|
|
if ([o isKindOfClass: [NSNumber class]])
|
|
|
|
{
|
|
|
|
sendAppointmentNotifications = [self firstChildWithTag: @"X-SOGo-Send-Appointment-Notifications"];
|
|
|
|
if (!sendAppointmentNotifications && ![o boolValue])
|
|
|
|
[self addChild: [CardElement simpleElementWithTag: @"X-SOGo-Send-Appointment-Notifications" value: @"NO"]];
|
|
|
|
else if (sendAppointmentNotifications && [o boolValue])
|
|
|
|
[self removeChild: sendAppointmentNotifications];
|
|
|
|
}
|
|
|
|
|
|
|
|
o = [data objectForKey: @"attendees"];
|
|
|
|
if ([o isKindOfClass: [NSArray class]])
|
|
|
|
[self _setAttendees: o];
|
|
|
|
|
|
|
|
o = [data objectForKey: @"alarm"];
|
|
|
|
if ([o isKindOfClass: [NSDictionary class]])
|
|
|
|
{
|
|
|
|
owner = [data objectForKey: @"owner"];
|
|
|
|
[self _setAlarm: o forOwner: owner];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Other attributes depend on the client object and therefore are set in [UIxComponentEditor setAttributes:]:
|
|
|
|
// - organizer & "created-by"
|
|
|
|
// - timestamps (creation/modification)
|
|
|
|
}
|
|
|
|
|
2010-05-05 15:56:19 +02:00
|
|
|
- (BOOL) userIsAttendee: (SOGoUser *) user
|
2007-06-01 06:10:03 +02:00
|
|
|
{
|
2010-05-05 15:56:19 +02:00
|
|
|
NSEnumerator *attendees;
|
|
|
|
iCalPerson *currentAttendee;
|
|
|
|
BOOL isAttendee;
|
|
|
|
|
|
|
|
isAttendee = NO;
|
|
|
|
|
|
|
|
attendees = [[self attendees] objectEnumerator];
|
|
|
|
currentAttendee = [attendees nextObject];
|
|
|
|
while (!isAttendee
|
|
|
|
&& currentAttendee)
|
|
|
|
if ([user hasEmail: [currentAttendee rfc822Email]])
|
|
|
|
isAttendee = YES;
|
2007-06-01 06:10:03 +02:00
|
|
|
else
|
2010-05-05 15:56:19 +02:00
|
|
|
currentAttendee = [attendees nextObject];
|
2007-06-01 06:10:03 +02:00
|
|
|
|
2010-05-05 15:56:19 +02:00
|
|
|
return isAttendee;
|
2007-06-01 06:10:03 +02:00
|
|
|
}
|
|
|
|
|
2010-05-05 15:56:19 +02:00
|
|
|
- (iCalPerson *) userAsAttendee: (SOGoUser *) user
|
2009-08-10 22:57:22 +02:00
|
|
|
{
|
2010-05-05 15:56:19 +02:00
|
|
|
iCalPerson *currentAttendee, *userAttendee;
|
2015-12-15 17:08:30 +01:00
|
|
|
NSEnumerator *attendees;
|
2009-08-10 22:57:22 +02:00
|
|
|
|
2010-05-05 15:56:19 +02:00
|
|
|
userAttendee = nil;
|
2009-08-10 22:57:22 +02:00
|
|
|
|
2010-05-05 15:56:19 +02:00
|
|
|
attendees = [[self attendees] objectEnumerator];
|
|
|
|
while (!userAttendee
|
|
|
|
&& (currentAttendee = [attendees nextObject]))
|
|
|
|
if ([user hasEmail: [currentAttendee rfc822Email]])
|
|
|
|
userAttendee = currentAttendee;
|
2009-08-10 22:57:22 +02:00
|
|
|
|
2010-05-05 15:56:19 +02:00
|
|
|
return userAttendee;
|
2009-08-10 22:57:22 +02:00
|
|
|
}
|
|
|
|
|
2015-12-15 21:05:40 +01:00
|
|
|
- (iCalPerson *) participantForUser: (SOGoUser *) theUser
|
|
|
|
attendee: (iCalPerson *) theAttendee
|
2015-12-15 17:08:30 +01:00
|
|
|
{
|
|
|
|
iCalPerson *currentAttendee;
|
|
|
|
NSEnumerator *attendees;
|
|
|
|
NSMutableArray *a;
|
|
|
|
|
|
|
|
a = [NSMutableArray array];
|
|
|
|
|
|
|
|
attendees = [[self attendees] objectEnumerator];
|
|
|
|
while ((currentAttendee = [attendees nextObject]))
|
|
|
|
if ([theUser hasEmail: [currentAttendee rfc822Email]])
|
|
|
|
{
|
|
|
|
// If the attendee is the same but the partStat is
|
|
|
|
// different, we prioritize this one.
|
|
|
|
if ([[currentAttendee rfc822Email] caseInsensitiveCompare: [theAttendee rfc822Email]] == NSOrderedSame &&
|
|
|
|
[[currentAttendee partStat] caseInsensitiveCompare: [theAttendee partStat]] != NSOrderedSame)
|
|
|
|
[a insertObject: currentAttendee atIndex: 0];
|
|
|
|
else if ([[currentAttendee rfc822Email] caseInsensitiveCompare: [theAttendee rfc822Email]] != NSOrderedSame)
|
|
|
|
[a addObject: currentAttendee];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ([a count] > 0)
|
2015-12-15 21:05:40 +01:00
|
|
|
return [a objectAtIndex: 0];
|
2015-12-15 17:08:30 +01:00
|
|
|
|
2015-12-15 21:05:40 +01:00
|
|
|
return theAttendee;
|
2015-12-15 17:08:30 +01:00
|
|
|
}
|
|
|
|
|
2007-06-01 06:10:03 +02:00
|
|
|
- (BOOL) userIsOrganizer: (SOGoUser *) user
|
|
|
|
{
|
2008-11-05 22:04:16 +01:00
|
|
|
NSString *mail;
|
|
|
|
BOOL b;
|
2007-06-01 06:10:03 +02:00
|
|
|
|
2008-11-05 22:04:16 +01:00
|
|
|
mail = [[self organizer] rfc822Email];
|
|
|
|
b = [user hasEmail: mail];
|
|
|
|
if (b) return YES;
|
2007-06-01 06:10:03 +02:00
|
|
|
|
2008-11-05 22:04:16 +01:00
|
|
|
// We check for the SENT-BY
|
|
|
|
mail = [[self organizer] sentBy];
|
|
|
|
|
|
|
|
if ([mail length])
|
|
|
|
return [user hasEmail: mail];
|
2015-02-12 21:01:26 +01:00
|
|
|
|
2008-11-05 22:04:16 +01:00
|
|
|
return NO;
|
2007-06-01 06:10:03 +02:00
|
|
|
}
|
|
|
|
|
2015-02-12 21:01:26 +01:00
|
|
|
/*
|
2007-11-18 11:16:25 +01:00
|
|
|
- (NSArray *) attendeeUIDs
|
|
|
|
{
|
|
|
|
NSEnumerator *attendees;
|
|
|
|
NSString *uid;
|
|
|
|
iCalPerson *currentAttendee;
|
|
|
|
NSMutableArray *uids;
|
|
|
|
|
|
|
|
uids = [NSMutableArray array];
|
|
|
|
|
|
|
|
attendees = [[self attendees] objectEnumerator];
|
|
|
|
while ((currentAttendee = [attendees nextObject]))
|
|
|
|
{
|
|
|
|
uid = [currentAttendee uid];
|
|
|
|
if (uid)
|
|
|
|
[uids addObject: uid];
|
|
|
|
}
|
|
|
|
|
|
|
|
return uids;
|
|
|
|
}
|
2015-02-12 21:01:26 +01:00
|
|
|
*/
|
2007-11-18 11:16:25 +01:00
|
|
|
|
|
|
|
#warning this method should be implemented in a category of iCalToDo
|
|
|
|
- (BOOL) isStillRelevant
|
|
|
|
{
|
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) itipEntryWithMethod: (NSString *) method
|
|
|
|
{
|
|
|
|
iCalCalendar *newCalendar;
|
2008-11-24 14:58:04 +01:00
|
|
|
iCalEntityObject *currentEvent, *newEntry;
|
|
|
|
iCalPerson *organizer;
|
2007-11-18 11:16:25 +01:00
|
|
|
|
2008-11-24 14:58:04 +01:00
|
|
|
NSArray *events;
|
|
|
|
int i, count;
|
2015-02-12 21:01:26 +01:00
|
|
|
|
2007-11-18 11:16:25 +01:00
|
|
|
newCalendar = [parent mutableCopy];
|
|
|
|
[newCalendar autorelease];
|
|
|
|
[newCalendar setMethod: method];
|
2015-02-12 21:01:26 +01:00
|
|
|
|
2008-11-24 14:58:04 +01:00
|
|
|
events = [newCalendar childrenWithTag: tag];
|
|
|
|
count = [events count];
|
|
|
|
if (count > 1)
|
|
|
|
{
|
|
|
|
// If the event is recurrent, remove all occurences
|
|
|
|
organizer = [[(iCalEntityObject *)[newCalendar firstChildWithTag: tag] organizer] mutableCopy];
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
currentEvent = [events objectAtIndex: i];
|
|
|
|
[[newCalendar children] removeObject: currentEvent];
|
|
|
|
}
|
|
|
|
newEntry = [[self mutableCopy] autorelease];
|
|
|
|
[newEntry setOrganizer: organizer];
|
|
|
|
[newCalendar addChild: newEntry];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
newEntry = (iCalEntityObject *) [newCalendar firstChildWithTag: tag];
|
2007-11-18 11:16:25 +01:00
|
|
|
|
|
|
|
return newEntry;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) attendeesWithoutUser: (SOGoUser *) user
|
|
|
|
{
|
|
|
|
NSMutableArray *newAttendees;
|
|
|
|
NSArray *oldAttendees;
|
|
|
|
unsigned int count, max;
|
|
|
|
iCalPerson *currentAttendee;
|
2015-07-22 22:45:42 +02:00
|
|
|
NSString *userID, *domain;
|
2007-11-18 11:16:25 +01:00
|
|
|
|
|
|
|
userID = [user login];
|
2015-07-22 22:45:42 +02:00
|
|
|
domain = [user domain];
|
2007-11-18 11:16:25 +01:00
|
|
|
oldAttendees = [self attendees];
|
|
|
|
max = [oldAttendees count];
|
|
|
|
newAttendees = [NSMutableArray arrayWithCapacity: max];
|
|
|
|
for (count = 0; count < max; count++)
|
|
|
|
{
|
|
|
|
currentAttendee = [oldAttendees objectAtIndex: count];
|
2015-07-22 22:45:42 +02:00
|
|
|
if (![[currentAttendee uidInDomain: domain] isEqualToString: userID])
|
2007-11-18 11:16:25 +01:00
|
|
|
[newAttendees addObject: currentAttendee];
|
|
|
|
}
|
|
|
|
|
|
|
|
return newAttendees;
|
|
|
|
}
|
|
|
|
|
2008-07-12 00:28:12 +02:00
|
|
|
- (NSNumber *) quickRecordDateAsNumber: (NSCalendarDate *) _date
|
2008-07-16 23:48:54 +02:00
|
|
|
withOffset: (int) offset
|
|
|
|
forAllDay: (BOOL) allDay
|
2008-07-12 00:28:12 +02:00
|
|
|
{
|
2008-08-09 10:18:18 +02:00
|
|
|
NSTimeInterval seconds;
|
2008-07-16 23:48:54 +02:00
|
|
|
NSNumber *dateNumber;
|
|
|
|
|
|
|
|
if (_date == iCalDistantFuture)
|
|
|
|
dateNumber = iCalDistantFutureNumber;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
seconds = [_date timeIntervalSince1970] + offset;
|
|
|
|
if (allDay)
|
2010-01-06 20:21:15 +01:00
|
|
|
seconds += [[_date timeZone] secondsFromGMT];
|
2008-07-16 23:48:54 +02:00
|
|
|
|
2008-08-09 10:18:18 +02:00
|
|
|
dateNumber = [NSNumber numberWithInt: seconds];
|
2008-07-16 23:48:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return dateNumber;
|
2008-07-12 00:28:12 +02:00
|
|
|
}
|
|
|
|
|
2014-09-12 14:34:15 +02:00
|
|
|
- (NSMutableDictionary *) quickRecordFromContent: (NSString *) theContent
|
|
|
|
container: (id) theContainer
|
2016-11-02 23:16:45 +01:00
|
|
|
nameInContainer: (NSString *) nameInContainer
|
2008-07-12 00:28:12 +02:00
|
|
|
{
|
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int) priorityNumber
|
|
|
|
{
|
|
|
|
NSString *prio;
|
|
|
|
NSRange r;
|
|
|
|
int priorityNumber;
|
|
|
|
|
|
|
|
prio = [self priority];
|
|
|
|
if (prio)
|
|
|
|
{
|
|
|
|
r = [prio rangeOfString: @";"];
|
|
|
|
if (r.length)
|
|
|
|
prio = [prio substringToIndex:r.location];
|
|
|
|
priorityNumber = [prio intValue];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
priorityNumber = 0;
|
|
|
|
|
|
|
|
return priorityNumber;
|
|
|
|
}
|
|
|
|
|
2015-02-12 21:01:26 +01:00
|
|
|
- (NSDictionary *) createdBy
|
2013-06-19 16:23:47 +02:00
|
|
|
{
|
2015-02-12 21:01:26 +01:00
|
|
|
NSString *created_by, *created_by_name, *login;
|
|
|
|
NSDictionary *createdByData;
|
|
|
|
SOGoUser *user;
|
2013-06-19 16:23:47 +02:00
|
|
|
|
2015-02-12 21:01:26 +01:00
|
|
|
created_by_name = nil;
|
|
|
|
createdByData = nil;
|
2013-06-19 16:23:47 +02:00
|
|
|
created_by = [[self firstChildWithTag: @"X-SOGo-Component-Created-By"] flattenedValuesForKey: @""];
|
2015-02-12 21:01:26 +01:00
|
|
|
|
2013-06-19 16:23:47 +02:00
|
|
|
if (![created_by length])
|
|
|
|
{
|
2015-02-12 21:01:26 +01:00
|
|
|
// We consider "SENT-BY" in case our custom header isn't found
|
2013-06-19 16:23:47 +02:00
|
|
|
created_by = [[self organizer] sentBy];
|
|
|
|
}
|
|
|
|
|
2015-02-12 21:01:26 +01:00
|
|
|
if ([created_by length])
|
|
|
|
{
|
|
|
|
login = [[SOGoUserManager sharedUserManager] getUIDForEmail: created_by];
|
|
|
|
if (login)
|
|
|
|
{
|
|
|
|
user = [SOGoUser userWithLogin: login];
|
|
|
|
if (user)
|
|
|
|
created_by_name = [user cn];
|
|
|
|
}
|
|
|
|
|
|
|
|
createdByData = [NSDictionary dictionaryWithObjectsAndKeys: created_by, @"email",
|
|
|
|
created_by_name, @"name",
|
|
|
|
nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
return createdByData;
|
2013-06-19 16:23:47 +02:00
|
|
|
}
|
|
|
|
|
2014-09-12 20:09:28 +02:00
|
|
|
//
|
|
|
|
// We ignore ACTION:PROCEDURE for now.
|
|
|
|
//
|
|
|
|
- (iCalAlarm *) firstSupportedAlarm
|
|
|
|
{
|
|
|
|
iCalAlarm *anAlarm;
|
|
|
|
NSArray *alarms;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
alarms = [self alarms];
|
|
|
|
|
|
|
|
for (i = 0; i < [alarms count]; i++)
|
|
|
|
{
|
|
|
|
anAlarm = [[self alarms] objectAtIndex: i];
|
|
|
|
|
|
|
|
if ([[anAlarm action] caseInsensitiveCompare: @"DISPLAY"] == NSOrderedSame ||
|
|
|
|
[[anAlarm action] caseInsensitiveCompare: @"AUDIO"] == NSOrderedSame ||
|
|
|
|
[[anAlarm action] caseInsensitiveCompare: @"EMAIL"] == NSOrderedSame)
|
|
|
|
return anAlarm;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (iCalAlarm *) firstDisplayOrAudioAlarm
|
|
|
|
{
|
|
|
|
iCalAlarm *anAlarm;
|
|
|
|
NSArray *alarms;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
alarms = [self alarms];
|
|
|
|
|
|
|
|
for (i = 0; i < [alarms count]; i++)
|
|
|
|
{
|
|
|
|
anAlarm = [[self alarms] objectAtIndex: i];
|
|
|
|
|
|
|
|
if ([[anAlarm action] caseInsensitiveCompare: @"DISPLAY"] == NSOrderedSame ||
|
|
|
|
[[anAlarm action] caseInsensitiveCompare: @"AUDIO"] == NSOrderedSame)
|
|
|
|
return anAlarm;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2016-11-02 23:16:45 +01:00
|
|
|
- (iCalAlarm *) firstEmailAlarm
|
|
|
|
{
|
|
|
|
iCalAlarm *anAlarm;
|
|
|
|
NSArray *alarms;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
alarms = [self alarms];
|
|
|
|
|
|
|
|
for (i = 0; i < [alarms count]; i++)
|
|
|
|
{
|
|
|
|
anAlarm = [[self alarms] objectAtIndex: i];
|
|
|
|
|
|
|
|
if ([[anAlarm action] caseInsensitiveCompare: @"EMAIL"] == NSOrderedSame)
|
|
|
|
return anAlarm;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-09-12 14:34:15 +02:00
|
|
|
- (void) updateNextAlarmDateInRow: (NSMutableDictionary *) row
|
|
|
|
forContainer: (id) theContainer
|
2016-11-02 23:16:45 +01:00
|
|
|
nameInContainer: (NSString *) nameInContainer
|
2014-09-12 14:34:15 +02:00
|
|
|
{
|
|
|
|
NSCalendarDate *nextAlarmDate;
|
2016-11-02 23:16:45 +01:00
|
|
|
GCSAlarmsFolder *af;
|
|
|
|
NSString *path;
|
|
|
|
|
|
|
|
if ([[SOGoSystemDefaults sharedSystemDefaults] enableEMailAlarms])
|
|
|
|
{
|
|
|
|
af = [[GCSFolderManager defaultFolderManager] alarmsFolder];
|
|
|
|
path = [theContainer ocsPath];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
af = nil;
|
|
|
|
path = nil;
|
|
|
|
}
|
2014-09-12 14:34:15 +02:00
|
|
|
|
|
|
|
nextAlarmDate = nil;
|
|
|
|
|
|
|
|
if ([self hasAlarms])
|
|
|
|
{
|
|
|
|
// We currently have the following limitations for alarms:
|
|
|
|
// - only the first alarm is considered;
|
|
|
|
// - the alarm's action must be of type DISPLAY;
|
|
|
|
//
|
|
|
|
// Morever, we don't update the quick table if the property X-WebStatus
|
|
|
|
// of the trigger is set to "triggered".
|
|
|
|
iCalAlarm *anAlarm;
|
|
|
|
NSString *webstatus;
|
|
|
|
|
|
|
|
if (![(id)self isRecurrent])
|
|
|
|
{
|
2014-09-12 20:09:28 +02:00
|
|
|
anAlarm = [self firstDisplayOrAudioAlarm];
|
2016-11-02 23:16:45 +01:00
|
|
|
if ((anAlarm = [self firstDisplayOrAudioAlarm]))
|
2014-09-12 14:34:15 +02:00
|
|
|
{
|
|
|
|
webstatus = [[anAlarm trigger] value: 0 ofAttribute: @"x-webstatus"];
|
|
|
|
if (!webstatus
|
|
|
|
|| ([webstatus caseInsensitiveCompare: @"TRIGGERED"]
|
|
|
|
!= NSOrderedSame))
|
|
|
|
nextAlarmDate = [anAlarm nextAlarmDate];
|
|
|
|
}
|
2016-11-02 23:16:45 +01:00
|
|
|
else if ((anAlarm = [self firstEmailAlarm]) && af)
|
|
|
|
{
|
|
|
|
nextAlarmDate = [anAlarm nextAlarmDate];
|
|
|
|
|
|
|
|
// The email alarm is too old, let's just remove it
|
|
|
|
if ([nextAlarmDate earlierDate: [NSDate date]] == nextAlarmDate)
|
|
|
|
nextAlarmDate = nil;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int alarmNbr;
|
|
|
|
|
|
|
|
alarmNbr = [[self alarms] indexOfObject: anAlarm];
|
|
|
|
|
|
|
|
[af writeRecordForEntryWithCName: nameInContainer
|
|
|
|
inCalendarAtPath: path
|
|
|
|
forUID: [self uid]
|
|
|
|
recurrenceId: nil
|
|
|
|
alarmNumber: [NSNumber numberWithInt: alarmNbr]
|
|
|
|
andAlarmDate: nextAlarmDate];
|
|
|
|
}
|
|
|
|
}
|
2014-09-12 14:34:15 +02:00
|
|
|
}
|
|
|
|
// Recurring event/task
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NSCalendarDate *start, *end;
|
|
|
|
NGCalendarDateRange *range;
|
|
|
|
NSMutableArray *alarms;
|
2015-02-12 21:01:26 +01:00
|
|
|
|
2014-09-12 14:34:15 +02:00
|
|
|
alarms = [NSMutableArray array];
|
|
|
|
start = [NSCalendarDate date];
|
|
|
|
end = [start addYear:1 month:0 day:0 hour:0 minute:0 second:0];
|
|
|
|
range = [NGCalendarDateRange calendarDateRangeWithStartDate: start
|
|
|
|
endDate: end];
|
2015-02-12 21:01:26 +01:00
|
|
|
|
2014-09-12 14:34:15 +02:00
|
|
|
// Always check if container is defined. If not, that means this method
|
|
|
|
// call was reentrant.
|
|
|
|
if (theContainer)
|
|
|
|
{
|
|
|
|
NSTimeInterval now;
|
|
|
|
int i, v, delta, c_startdate, c_nextalarm;
|
2015-02-12 21:01:26 +01:00
|
|
|
|
2014-09-12 14:34:15 +02:00
|
|
|
//
|
|
|
|
// Here is the logic:
|
|
|
|
//
|
|
|
|
// We flatten the structure. When flattening it (or after), we compute the alarm based on the trigger for every single
|
|
|
|
// event part of the recurrence rule. Exceptions can have their own triggers. Then, we start from NOW and move forward,
|
|
|
|
// and we look at the closest one. When found one, we pick it and store it in c_nextalarm.
|
|
|
|
//
|
|
|
|
// When popping up the alarm, we must find for which occurence it is - so we can show the proper start/end time, or even
|
|
|
|
// infos from the exception. It gets tricky because the user could have snoozed the alarm. So here is the logic:
|
|
|
|
//
|
|
|
|
// We flatten the structure and compute the alarms based on triggers. If c_nextalarm is a match, we have have a winner.
|
|
|
|
// If we don't have a match, we pick the event for which its trigger is the closest to the c_nextalarm.
|
|
|
|
//
|
|
|
|
nextAlarmDate = nil;
|
2015-02-12 21:01:26 +01:00
|
|
|
|
2014-09-12 14:34:15 +02:00
|
|
|
[theContainer flattenCycleRecord: (id)row
|
|
|
|
forRange: range
|
|
|
|
intoArray: alarms
|
|
|
|
withCalendar: [self parent]];
|
2015-02-12 21:01:26 +01:00
|
|
|
|
2014-09-12 14:34:15 +02:00
|
|
|
// We pickup the closest one from now. We remove the actual reminder (ie., 15 mins before - plus 1 minute for roundups)
|
|
|
|
// so we don't pickup the same alarm over and over. This could happen if our alarm popups and the user clicks on "Cancel".
|
|
|
|
// In case of a repetitive event, we want to pickup the next one (next day for example), and not the one that has just
|
|
|
|
// popped up.
|
|
|
|
now = [start timeIntervalSince1970];
|
|
|
|
v = 0;
|
|
|
|
for (i = 0; i < [alarms count]; i++)
|
|
|
|
{
|
|
|
|
c_startdate = [[[alarms objectAtIndex: i] objectForKey: @"c_startdate"] intValue];
|
|
|
|
c_nextalarm = [[[alarms objectAtIndex: i] objectForKey: @"c_nextalarm"] intValue];
|
|
|
|
delta = (c_startdate - now - (c_startdate - c_nextalarm)) - 60;
|
2015-02-12 21:01:26 +01:00
|
|
|
|
2014-09-12 14:34:15 +02:00
|
|
|
// If value is not initialized, we grab it right away
|
|
|
|
if (!v && delta > 0)
|
|
|
|
v = delta;
|
2015-02-12 21:01:26 +01:00
|
|
|
|
2014-09-12 14:34:15 +02:00
|
|
|
// If we found a smaller delta than before, use it.
|
|
|
|
if (v > 0 && delta > 0 && delta <= v)
|
|
|
|
{
|
|
|
|
id o;
|
|
|
|
|
|
|
|
// Find the relevant component
|
|
|
|
if ([self respondsToSelector: @selector(endDate)])
|
|
|
|
o = [[self parent] eventWithRecurrenceID: [[alarms objectAtIndex: i] objectForKey: @"c_recurrence_id"]];
|
|
|
|
else
|
|
|
|
o = [[self parent] todoWithRecurrenceID: [[alarms objectAtIndex: i] objectForKey: @"c_recurrence_id"]];
|
2015-02-12 21:01:26 +01:00
|
|
|
|
2014-09-12 14:34:15 +02:00
|
|
|
if (!o)
|
|
|
|
o = self;
|
2015-02-12 21:01:26 +01:00
|
|
|
|
2014-09-12 14:34:15 +02:00
|
|
|
if ([[o alarms] count])
|
|
|
|
{
|
2016-11-02 23:16:45 +01:00
|
|
|
if ((anAlarm = [self firstDisplayOrAudioAlarm]))
|
2014-09-12 14:34:15 +02:00
|
|
|
{
|
|
|
|
webstatus = [[anAlarm trigger] value: 0 ofAttribute: @"x-webstatus"];
|
|
|
|
if (!webstatus
|
|
|
|
|| ([webstatus caseInsensitiveCompare: @"TRIGGERED"]
|
|
|
|
!= NSOrderedSame))
|
|
|
|
v = delta;
|
|
|
|
nextAlarmDate = [NSDate dateWithTimeIntervalSince1970: [[[alarms objectAtIndex: i] objectForKey: @"c_nextalarm"] intValue]];
|
|
|
|
}
|
2016-11-02 23:16:45 +01:00
|
|
|
else if ((anAlarm = [self firstEmailAlarm]) && af)
|
|
|
|
{
|
|
|
|
int alarmNbr;
|
|
|
|
|
|
|
|
nextAlarmDate = [NSDate dateWithTimeIntervalSince1970: [[[alarms objectAtIndex: i] objectForKey: @"c_nextalarm"] intValue]];
|
|
|
|
alarmNbr = [[self alarms] indexOfObject: anAlarm];
|
|
|
|
|
|
|
|
[af writeRecordForEntryWithCName: nameInContainer
|
|
|
|
inCalendarAtPath: path
|
|
|
|
forUID: [self uid]
|
|
|
|
recurrenceId: [self recurrenceId]
|
|
|
|
alarmNumber: [NSNumber numberWithInt: alarmNbr]
|
|
|
|
andAlarmDate: nextAlarmDate];
|
|
|
|
}
|
|
|
|
}
|
2014-09-12 14:34:15 +02:00
|
|
|
}
|
|
|
|
} // for ( ... )
|
|
|
|
} // if (theContainer)
|
|
|
|
}
|
|
|
|
}
|
2015-02-12 21:01:26 +01:00
|
|
|
|
2014-09-12 14:34:15 +02:00
|
|
|
if ([nextAlarmDate isNotNull])
|
|
|
|
[row setObject: [NSNumber numberWithInt: [nextAlarmDate timeIntervalSince1970]]
|
|
|
|
forKey: @"c_nextalarm"];
|
|
|
|
else
|
2016-11-02 23:16:45 +01:00
|
|
|
{
|
|
|
|
[row setObject: [NSNumber numberWithInt: 0] forKey: @"c_nextalarm"];
|
|
|
|
|
|
|
|
// Delete old email alarms
|
|
|
|
if (af)
|
|
|
|
[af deleteRecordForEntryWithCName: nameInContainer
|
|
|
|
inCalendarAtPath: [theContainer ocsPath]];
|
|
|
|
}
|
2014-09-12 14:34:15 +02:00
|
|
|
}
|
|
|
|
|
2007-06-01 06:10:03 +02:00
|
|
|
@end
|