2006-06-15 21:34:10 +02:00
|
|
|
/*
|
2019-02-04 17:52:26 +01:00
|
|
|
Copyright (C) 2006-2019 Inverse inc.
|
2006-06-15 21:34:10 +02:00
|
|
|
Copyright (C) 2000-2005 SKYRIX Software AG
|
2008-10-01 18:14:56 +02:00
|
|
|
|
2009-04-01 15:49:24 +02:00
|
|
|
This file is part of SOGo.
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2009-04-01 15:49:24 +02:00
|
|
|
SOGo is free software; you can redistribute it and/or modify it under
|
2006-06-15 21:34:10 +02:00
|
|
|
the terms of the GNU Lesser General Public License as published by the
|
|
|
|
Free Software Foundation; either version 2, or (at your option) any
|
|
|
|
later version.
|
|
|
|
|
2009-04-01 15:49:24 +02:00
|
|
|
SOGo is distributed in the hope that it will be useful, but WITHOUT ANY
|
2006-06-15 21:34:10 +02:00
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
|
|
|
License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with OGo; see the file COPYING. If not, write to the
|
|
|
|
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
|
|
|
|
02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2007-08-07 20:37:31 +02:00
|
|
|
#import <Foundation/NSCalendarDate.h>
|
|
|
|
#import <Foundation/NSTimeZone.h>
|
|
|
|
|
2010-05-25 21:40:46 +02:00
|
|
|
#import <NGObjWeb/WOContext+SoObjects.h>
|
2017-04-12 22:13:40 +02:00
|
|
|
#import <NGObjWeb/WOResponse.h>
|
|
|
|
#import <NGExtensions/NSCalendarDate+misc.h>
|
2007-08-07 20:37:31 +02:00
|
|
|
#import <NGExtensions/NSObject+Logs.h>
|
2010-04-09 20:45:14 +02:00
|
|
|
#import <NGCards/iCalEvent.h>
|
2018-09-13 20:56:44 +02:00
|
|
|
#import <NGCards/iCalToDo.h>
|
2010-04-09 20:45:14 +02:00
|
|
|
#import <SOGo/NSDictionary+Utilities.h>
|
|
|
|
#import <SOGo/NSObject+Utilities.h>
|
|
|
|
#import <SOGo/NSString+Utilities.h>
|
2010-11-01 22:18:43 +01:00
|
|
|
#import <SOGo/SOGoDateFormatter.h>
|
2010-05-25 21:40:46 +02:00
|
|
|
#import <SOGo/SOGoUser.h>
|
|
|
|
#import <SOGo/SOGoUserDefaults.h>
|
2007-08-24 00:11:55 +02:00
|
|
|
|
2009-04-01 15:49:24 +02:00
|
|
|
#import "iCalPerson+SOGo.h"
|
2006-09-28 19:24:12 +02:00
|
|
|
#import "SOGoAptMailNotification.h"
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2008-10-01 18:14:56 +02:00
|
|
|
@implementation SOGoAptMailNotification
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2008-10-01 21:32:14 +02:00
|
|
|
- (id) init
|
2008-10-01 18:14:56 +02:00
|
|
|
{
|
2008-10-01 21:32:14 +02:00
|
|
|
if ((self = [super init]))
|
|
|
|
{
|
|
|
|
apt = nil;
|
2010-04-09 20:45:14 +02:00
|
|
|
values = nil;
|
2012-08-27 22:35:10 +02:00
|
|
|
dateFormatter = RETAIN([[context activeUser] dateFormatterInContext: context]);
|
2019-02-04 17:52:26 +01:00
|
|
|
organizerName = nil;
|
|
|
|
currentAttendee = nil;
|
2008-10-01 21:32:14 +02:00
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2008-10-01 21:32:14 +02:00
|
|
|
return self;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
2007-11-12 20:54:16 +01:00
|
|
|
|
2008-10-01 21:32:14 +02:00
|
|
|
- (void) dealloc
|
2008-10-01 18:14:56 +02:00
|
|
|
{
|
2010-04-09 20:45:14 +02:00
|
|
|
[values release];
|
2008-10-01 21:32:14 +02:00
|
|
|
[apt release];
|
2008-11-18 01:06:37 +01:00
|
|
|
[previousApt release];
|
2008-10-24 18:12:21 +02:00
|
|
|
[organizerName release];
|
2019-02-04 17:52:26 +01:00
|
|
|
[currentAttendee release];
|
2008-11-18 01:06:37 +01:00
|
|
|
[viewTZ release];
|
|
|
|
[oldStartDate release];
|
|
|
|
[newStartDate release];
|
2010-10-21 22:12:47 +02:00
|
|
|
[oldEndDate release];
|
|
|
|
[newEndDate release];
|
2012-08-27 22:35:10 +02:00
|
|
|
[dateFormatter release];
|
2008-10-01 21:32:14 +02:00
|
|
|
[super dealloc];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2018-09-13 20:56:44 +02:00
|
|
|
- (iCalRepeatableEntityObject *) apt
|
2008-10-01 18:14:56 +02:00
|
|
|
{
|
2008-10-01 21:32:14 +02:00
|
|
|
return apt;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
2008-10-01 18:14:56 +02:00
|
|
|
|
2018-09-13 20:56:44 +02:00
|
|
|
- (void) setApt: (iCalRepeatableEntityObject *) theApt
|
2008-10-01 18:14:56 +02:00
|
|
|
{
|
2010-04-09 20:45:14 +02:00
|
|
|
ASSIGN (apt, theApt);
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2018-09-13 20:56:44 +02:00
|
|
|
- (iCalRepeatableEntityObject *) previousApt
|
2008-11-18 01:06:37 +01:00
|
|
|
{
|
|
|
|
return previousApt;
|
|
|
|
}
|
|
|
|
|
2018-09-13 20:56:44 +02:00
|
|
|
- (void) setPreviousApt: (iCalRepeatableEntityObject *) theApt
|
2008-11-18 01:06:37 +01:00
|
|
|
{
|
2010-04-09 20:45:14 +02:00
|
|
|
ASSIGN (previousApt, theApt);
|
2008-11-18 01:06:37 +01:00
|
|
|
}
|
|
|
|
|
2008-11-28 21:12:22 +01:00
|
|
|
- (BOOL) hasNewLocation
|
|
|
|
{
|
|
|
|
return ([[apt location] length] > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) hasOldLocation
|
|
|
|
{
|
|
|
|
return ([[previousApt location] length] > 0);
|
|
|
|
}
|
|
|
|
|
2008-11-18 01:06:37 +01:00
|
|
|
- (NSCalendarDate *) oldStartDate
|
|
|
|
{
|
2010-04-09 20:45:14 +02:00
|
|
|
if (!oldStartDate)
|
2008-11-18 01:06:37 +01:00
|
|
|
{
|
2010-04-09 20:45:14 +02:00
|
|
|
ASSIGN (oldStartDate, [[self previousApt] startDate]);
|
2010-05-25 21:40:46 +02:00
|
|
|
[oldStartDate setTimeZone: viewTZ];
|
2008-11-18 01:06:37 +01:00
|
|
|
}
|
2010-04-09 20:45:14 +02:00
|
|
|
return oldStartDate;
|
2008-11-18 01:06:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSCalendarDate *) newStartDate
|
|
|
|
{
|
2010-04-09 20:45:14 +02:00
|
|
|
if (!newStartDate)
|
2008-11-18 01:06:37 +01:00
|
|
|
{
|
2010-04-09 20:45:14 +02:00
|
|
|
ASSIGN (newStartDate, [[self apt] startDate]);
|
2010-05-25 21:40:46 +02:00
|
|
|
[newStartDate setTimeZone: viewTZ];
|
2008-11-18 01:06:37 +01:00
|
|
|
}
|
2010-04-09 20:45:14 +02:00
|
|
|
return newStartDate;
|
2008-10-01 18:14:56 +02:00
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2010-10-21 22:12:47 +02:00
|
|
|
- (NSCalendarDate *) oldEndDate
|
|
|
|
{
|
|
|
|
if (!oldEndDate)
|
|
|
|
{
|
2018-09-13 20:56:44 +02:00
|
|
|
if ([[self previousApt] isKindOfClass: [iCalEvent class]])
|
|
|
|
ASSIGN (oldEndDate, [(iCalEvent*)[self previousApt] endDate]);
|
|
|
|
else
|
|
|
|
ASSIGN (oldEndDate, [(iCalToDo*)[self previousApt] due]);
|
2010-10-21 22:12:47 +02:00
|
|
|
[oldEndDate setTimeZone: viewTZ];
|
|
|
|
}
|
|
|
|
return oldEndDate;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSCalendarDate *) newEndDate
|
|
|
|
{
|
|
|
|
if (!newEndDate)
|
|
|
|
{
|
2018-09-13 20:56:44 +02:00
|
|
|
if ([[self apt] isKindOfClass: [iCalEvent class]])
|
|
|
|
ASSIGN (newEndDate, [(iCalEvent*)[self apt] endDate]);
|
|
|
|
else
|
|
|
|
ASSIGN (newEndDate, [(iCalToDo*)[self apt] due]);
|
2010-10-21 22:12:47 +02:00
|
|
|
[newEndDate setTimeZone: viewTZ];
|
|
|
|
}
|
|
|
|
return newEndDate;
|
|
|
|
}
|
|
|
|
|
2013-07-16 17:31:08 +02:00
|
|
|
- (NSString *) location
|
|
|
|
{
|
2013-09-03 18:05:13 +02:00
|
|
|
return [apt location];
|
2013-07-16 17:31:08 +02:00
|
|
|
}
|
|
|
|
|
2008-10-01 21:32:14 +02:00
|
|
|
- (NSString *) summary
|
2008-10-01 18:14:56 +02:00
|
|
|
{
|
2013-09-03 18:05:13 +02:00
|
|
|
return [apt summary];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2008-10-24 18:12:21 +02:00
|
|
|
- (void) setOrganizerName: (NSString *) theString
|
|
|
|
{
|
2010-04-09 20:45:14 +02:00
|
|
|
ASSIGN (organizerName, theString);
|
2008-10-24 18:12:21 +02:00
|
|
|
}
|
|
|
|
|
2008-10-01 21:32:14 +02:00
|
|
|
- (NSString *) organizerName
|
2008-10-01 18:14:56 +02:00
|
|
|
{
|
2008-10-24 18:12:21 +02:00
|
|
|
return organizerName;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2019-02-04 17:52:26 +01:00
|
|
|
- (void) setCurrentAttendee: (iCalPerson *) theAttendee
|
|
|
|
{
|
|
|
|
ASSIGN(currentAttendee, theAttendee);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (iCalPerson *) currentAttendee
|
|
|
|
{
|
|
|
|
return currentAttendee;
|
|
|
|
}
|
|
|
|
|
2012-08-27 22:35:10 +02:00
|
|
|
- (NSString *) sentByText
|
|
|
|
{
|
|
|
|
NSDictionary *sentByValues;
|
|
|
|
NSString *sentByText;
|
|
|
|
id value;
|
|
|
|
|
|
|
|
sentByText = @"";
|
2008-10-01 21:32:14 +02:00
|
|
|
|
2012-08-27 22:35:10 +02:00
|
|
|
if (organizerName)
|
|
|
|
{
|
|
|
|
value = [[apt organizer] sentBy];
|
|
|
|
|
|
|
|
if (value && [value length])
|
|
|
|
{
|
|
|
|
sentByValues = [NSDictionary dictionaryWithObject: value
|
|
|
|
forKey: @"SentBy"];
|
|
|
|
sentByText
|
|
|
|
= [sentByValues keysWithFormat: [self
|
|
|
|
labelForKey: @"(sent by %{SentBy}) "
|
|
|
|
inContext: context]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return sentByText;
|
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2017-04-12 22:13:40 +02:00
|
|
|
- (NSTimeInterval) duration
|
|
|
|
{
|
|
|
|
return [[self newEndDate] timeIntervalSinceDate:[self newStartDate]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) isEndDateOnSameDay
|
|
|
|
{
|
2018-09-13 20:56:44 +02:00
|
|
|
if ([[self apt] isKindOfClass: [iCalEvent class]] && [(iCalEvent*)[self apt] isAllDay])
|
2017-04-12 22:13:40 +02:00
|
|
|
return ([self duration] <= 86400);
|
|
|
|
|
|
|
|
return [[self newStartDate] isDateOnSameDay: [self newEndDate]];
|
|
|
|
}
|
|
|
|
|
2012-08-27 22:35:10 +02:00
|
|
|
- (NSString *) formattedAptStartDate
|
2008-10-01 18:14:56 +02:00
|
|
|
{
|
2012-08-27 22:35:10 +02:00
|
|
|
NSString *s;
|
|
|
|
id value;
|
|
|
|
|
|
|
|
value = [self newStartDate];
|
|
|
|
s = @"";
|
|
|
|
|
|
|
|
if (value)
|
|
|
|
s = [dateFormatter formattedDate: value];
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
2007-08-24 00:11:55 +02:00
|
|
|
|
2012-08-27 22:35:10 +02:00
|
|
|
|
|
|
|
- (NSString *) formattedAptStartTime
|
|
|
|
{
|
|
|
|
NSString *s;
|
|
|
|
id value;
|
|
|
|
|
|
|
|
value = [self newStartDate];
|
|
|
|
s = @"";
|
|
|
|
|
2018-09-13 20:56:44 +02:00
|
|
|
if (value && (![apt isKindOfClass: [iCalEvent class]] || ![(iCalEvent*)apt isAllDay]))
|
2012-08-27 22:35:10 +02:00
|
|
|
s = [dateFormatter formattedTime: value];
|
|
|
|
|
|
|
|
return s;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2012-08-27 22:35:10 +02:00
|
|
|
- (NSString *) formattedAptEndDate
|
2008-10-01 18:14:56 +02:00
|
|
|
{
|
2012-08-27 22:35:10 +02:00
|
|
|
NSString *s;
|
|
|
|
id value;
|
|
|
|
|
|
|
|
value = [self newEndDate];
|
|
|
|
s = @"";
|
|
|
|
|
|
|
|
if (value)
|
|
|
|
s = [dateFormatter formattedDate: value];
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
2009-08-25 23:28:24 +02:00
|
|
|
|
2012-08-27 22:35:10 +02:00
|
|
|
- (NSString *) formattedAptEndTime
|
|
|
|
{
|
|
|
|
NSString *s;
|
|
|
|
id value;
|
|
|
|
|
|
|
|
value = [self newEndDate];
|
|
|
|
s = @"";
|
|
|
|
|
2018-09-13 20:56:44 +02:00
|
|
|
if (value && (![apt isKindOfClass: [iCalEvent class]] || ![(iCalEvent*)apt isAllDay]))
|
2012-08-27 22:35:10 +02:00
|
|
|
s = [dateFormatter formattedTime: value];
|
|
|
|
|
|
|
|
return s;
|
2010-04-09 20:45:14 +02:00
|
|
|
}
|
2008-10-01 18:14:56 +02:00
|
|
|
|
2010-04-09 20:45:14 +02:00
|
|
|
- (void) setupValues
|
|
|
|
{
|
2010-05-25 21:40:46 +02:00
|
|
|
SOGoUser *user;
|
2012-08-27 22:35:10 +02:00
|
|
|
id value;
|
|
|
|
|
2010-05-25 21:40:46 +02:00
|
|
|
user = [context activeUser];
|
|
|
|
viewTZ = [[user userDefaults] timeZone];
|
|
|
|
[viewTZ retain];
|
2009-08-25 23:28:24 +02:00
|
|
|
|
2010-04-09 20:45:14 +02:00
|
|
|
values = [NSMutableDictionary new];
|
2012-08-27 22:35:10 +02:00
|
|
|
value = [self summary];
|
|
|
|
if (!value)
|
|
|
|
value = @"";
|
|
|
|
|
|
|
|
[values setObject: value forKey: @"Summary"];
|
|
|
|
}
|
2010-11-01 22:18:43 +01:00
|
|
|
|
2012-08-27 22:35:10 +02:00
|
|
|
/* Generate Response */
|
2010-11-01 22:18:43 +01:00
|
|
|
|
2012-08-27 22:35:10 +02:00
|
|
|
- (NSString *) getSubject
|
|
|
|
{
|
|
|
|
[self subclassResponsibility: _cmd];
|
2010-11-01 22:18:43 +01:00
|
|
|
|
2012-08-27 22:35:10 +02:00
|
|
|
return nil;
|
|
|
|
}
|
2010-11-01 22:18:43 +01:00
|
|
|
|
2012-08-27 22:35:10 +02:00
|
|
|
- (NSString *) getBody
|
|
|
|
{
|
|
|
|
[self subclassResponsibility: _cmd];
|
2010-11-01 22:18:43 +01:00
|
|
|
|
2012-08-27 22:35:10 +02:00
|
|
|
return nil;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2019-02-04 17:52:26 +01:00
|
|
|
- (NSString *) getParticipationRole
|
|
|
|
{
|
|
|
|
if ([[currentAttendee role] caseInsensitiveCompare: @"OPT-PARTICIPANT"] == NSOrderedSame)
|
|
|
|
{
|
|
|
|
return [self labelForKey: @"Your participation is optional to this event"
|
|
|
|
inContext: context];
|
|
|
|
}
|
|
|
|
else if ([[currentAttendee role] caseInsensitiveCompare: @"NON-PARTICIPANT"] == NSOrderedSame)
|
|
|
|
{
|
|
|
|
return [self labelForKey: @"Your participation is not required to this event"
|
|
|
|
inContext: context];
|
|
|
|
}
|
|
|
|
|
|
|
|
return [self labelForKey: @"Your participation is required to this event"
|
|
|
|
inContext: context];
|
|
|
|
}
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
@end
|