Skip to content

Commit

Permalink
[TIMOB-18927] Refactor proxy, add more docs
Browse files Browse the repository at this point in the history
  • Loading branch information
hansemannn committed Jul 23, 2016
1 parent 1d9e3f6 commit cad9a41
Show file tree
Hide file tree
Showing 7 changed files with 163 additions and 81 deletions.
14 changes: 10 additions & 4 deletions apidoc/Titanium/Calendar/Attendee.yml
Expand Up @@ -3,7 +3,6 @@ name: Titanium.Calendar.Attendee
summary: An object that represents a single attendee of an event.
description: |
The API supports retrieving information about the attendee of an event.
extends: Titanium.Proxy
platforms: [iphone, ipad]
since: "6.0.0"
Expand All @@ -23,18 +22,25 @@ properties:
- name: email
summary: The attendee email.
description: |
Due to privacy concerns in iOS this value will be empty if the attendee is the device owner.
Due to privacy concerns in iOS, this value will be empty if the attendee
is the device owner.
type: String
platforms: [iphone, ipad]

- name: role
summary: The attendee role of required or optional.
summary: The role of the attendee.
type: Number
constants: Titanium.Calendar.ATTENDEE_ROLE_*
platforms: [iphone, ipad]

- name: type
summary: The type of the attendee.
type: Number
constants: Titanium.Calendar.ATTENDEE_TYPE_*
platforms: [iphone, ipad]

- name: status
summary: The attendance status.
summary: The status of the attendee.
type: Number
constants: Titanium.Calendar.ATTENDEE_STATUS_*
platforms: [iphone, ipad]
89 changes: 83 additions & 6 deletions apidoc/Titanium/Calendar/Calendar.yml
Expand Up @@ -488,36 +488,57 @@ properties:
permission: read-only
platforms: [android]

- name: ATTENDEE_STATUS_NONE
- name: ATTENDEE_STATUS_UNKNOWN
summary: Attendee status is unknown.
type: Number
permission: read-only
platforms: [iphone, ipad]
since: "6.0.0"

- name: ATTENDEE_STATUS_PENDING
summary: Attendee status is pending.
type: Number
permission: read-only
platforms: [iphone, ipad]
since: "6.0.0"

- name: ATTENDEE_STATUS_ACCEPTED
summary: Attendee accepted the event.
summary: Attendee status is accepted.
type: Number
permission: read-only
platforms: [iphone, ipad]
since: "6.0.0"

- name: ATTENDEE_STATUS_DECLINED
summary: Attendee declined the event.
summary: Attendee status is declined.
type: Number
permission: read-only
platforms: [iphone, ipad]
since: "6.0.0"

- name: ATTENDEE_STATUS_TENTATIVE
summary: Attendee is tentative for the event.
summary: Attendee status is tentative.
type: Number
permission: read-only
platforms: [iphone, ipad]
since: "6.0.0"

- name: ATTENDEE_ROLE_REQUIRED
summary: Attendee role is required.
- name: ATTENDEE_STATUS_DELEGATED
summary: Attendee status is delegated.
type: Number
permission: read-only
platforms: [iphone, ipad]
since: "6.0.0"

- name: ATTENDEE_STATUS_IN_PROCESS
summary: Attendee status is in process.
type: Number
permission: read-only
platforms: [iphone, ipad]
since: "6.0.0"

- name: ATTENDEE_ROLE_UNKNOWN
summary: Attendee role is unknown.
type: Number
permission: read-only
platforms: [iphone, ipad]
Expand All @@ -530,6 +551,62 @@ properties:
platforms: [iphone, ipad]
since: "6.0.0"

- name: ATTENDEE_ROLE_REQUIRED
summary: Attendee role is required.
type: Number
permission: read-only
platforms: [iphone, ipad]
since: "6.0.0"

- name: ATTENDEE_ROLE_CHAIR
summary: Attendee role is chair.
type: Number
permission: read-only
platforms: [iphone, ipad]
since: "6.0.0"

- name: ATTENDEE_ROLE_NON_PARTICIPANT
summary: Attendee is not a participant.
type: Number
permission: read-only
platforms: [iphone, ipad]
since: "6.0.0"

- name: ATTENDEE_TYPE_UNKNOWN
summary: Attendee type is unknown.
type: Number
permission: read-only
platforms: [iphone, ipad]
since: "6.0.0"

- name: ATTENDEE_TYPE_PERSON
summary: Attendee type is person.
type: Number
permission: read-only
platforms: [iphone, ipad]
since: "6.0.0"

- name: ATTENDEE_TYPE_ROOM
summary: Attendee type is room.
type: Number
permission: read-only
platforms: [iphone, ipad]
since: "6.0.0"

- name: ATTENDEE_TYPE_RESOURCE
summary: Attendee type is resource.
type: Number
permission: read-only
platforms: [iphone, ipad]
since: "6.0.0"

- name: ATTENDEE_TYPE_GROUP
summary: Attendee type is group.
type: Number
permission: read-only
platforms: [iphone, ipad]
since: "6.0.0"

- name: eventsAuthorization
summary: Returns an authorization constant indicating if the application has access to the events in the EventKit.
description: |
Expand Down
16 changes: 15 additions & 1 deletion iphone/Classes/CalendarModule.h
Expand Up @@ -47,13 +47,27 @@
@property (nonatomic, readonly)NSNumber* AUTHORIZATION_DENIED;
@property (nonatomic, readonly)NSNumber* AUTHORIZATION_AUTHORIZED;

@property (nonatomic, readonly)NSNumber* ATTENDEE_STATUS_NONE;
@property (nonatomic, readonly)NSNumber* ATTENDEE_STATUS_UNKNOWN;
@property (nonatomic, readonly)NSNumber* ATTENDEE_STATUS_PENDING;
@property (nonatomic, readonly)NSNumber* ATTENDEE_STATUS_ACCEPTED;
@property (nonatomic, readonly)NSNumber* ATTENDEE_STATUS_DECLINED;
@property (nonatomic, readonly)NSNumber* ATTENDEE_STATUS_TENTATIVE;
@property (nonatomic, readonly)NSNumber* ATTENDEE_STATUS_DELEGATED;
@property (nonatomic, readonly)NSNumber* ATTENDEE_STATUS_COMPLETED;
@property (nonatomic, readonly)NSNumber* ATTENDEE_STATUS_IN_PROCESS;

@property (nonatomic, readonly)NSNumber* ATTENDEE_ROLE_UNKNOWN;
@property (nonatomic, readonly)NSNumber* ATTENDEE_ROLE_REQUIRED;
@property (nonatomic, readonly)NSNumber* ATTENDEE_ROLE_OPTIONAL;
@property (nonatomic, readonly)NSNumber* ATTENDEE_ROLE_CHAIR;
@property (nonatomic, readonly)NSNumber* ATTENDEE_ROLE_NON_PARTICIPANT;

@property (nonatomic, readonly)NSNumber* ATTENDEE_TYPE_UNKNOWN;
@property (nonatomic, readonly)NSNumber* ATTENDEE_TYPE_PERSON;
@property (nonatomic, readonly)NSNumber* ATTENDEE_TYPE_ROOM;
@property (nonatomic, readonly)NSNumber* ATTENDEE_TYPE_RESOURCE;
@property (nonatomic, readonly)NSNumber* ATTENDEE_TYPE_GROUP;


@end

Expand Down
15 changes: 14 additions & 1 deletion iphone/Classes/CalendarModule.m
Expand Up @@ -321,13 +321,26 @@ -(NSNumber*) calendarAuthorization
MAKE_SYSTEM_PROP(AUTHORIZATION_DENIED, EKAuthorizationStatusDenied);
MAKE_SYSTEM_PROP(AUTHORIZATION_AUTHORIZED, EKAuthorizationStatusAuthorized);

MAKE_SYSTEM_PROP(ATTENDEE_STATUS_NONE, EKParticipantStatusUnknown);
MAKE_SYSTEM_PROP(ATTENDEE_STATUS_UNKNOWN, EKParticipantStatusUnknown);
MAKE_SYSTEM_PROP(ATTENDEE_STATUS_PENDING, EKParticipantStatusPending);
MAKE_SYSTEM_PROP(ATTENDEE_STATUS_ACCEPTED, EKParticipantStatusAccepted);
MAKE_SYSTEM_PROP(ATTENDEE_STATUS_DECLINED, EKParticipantStatusDeclined);
MAKE_SYSTEM_PROP(ATTENDEE_STATUS_TENTATIVE, EKParticipantStatusTentative);
MAKE_SYSTEM_PROP(ATTENDEE_STATUS_DELEGATED, EKParticipantStatusDelegated);
MAKE_SYSTEM_PROP(ATTENDEE_STATUS_COMPLETED, EKParticipantStatusCompleted);
MAKE_SYSTEM_PROP(ATTENDEE_STATUS_IN_PROCESS, EKParticipantStatusInProcess);

MAKE_SYSTEM_PROP(ATTENDEE_ROLE_UNKNOWN, EKParticipantRoleUnknown);
MAKE_SYSTEM_PROP(ATTENDEE_ROLE_REQUIRED, EKParticipantRoleRequired);
MAKE_SYSTEM_PROP(ATTENDEE_ROLE_OPTIONAL, EKParticipantRoleOptional);
MAKE_SYSTEM_PROP(ATTENDEE_ROLE_CHAIR, EKParticipantRoleChair);
MAKE_SYSTEM_PROP(ATTENDEE_ROLE_NON_PARTICIPANT, EKParticipantRoleNonParticipant);

MAKE_SYSTEM_PROP(ATTENDEE_TYPE_UNKNOWN, EKParticipantTypeUnknown);
MAKE_SYSTEM_PROP(ATTENDEE_TYPE_PERSON, EKParticipantTypePerson);
MAKE_SYSTEM_PROP(ATTENDEE_TYPE_ROOM, EKParticipantTypeRoom);
MAKE_SYSTEM_PROP(ATTENDEE_TYPE_RESOURCE, EKParticipantTypeResource);
MAKE_SYSTEM_PROP(ATTENDEE_TYPE_GROUP, EKParticipantTypeGroup);

@end

Expand Down
8 changes: 3 additions & 5 deletions iphone/Classes/TiCalendarAttendee.h
Expand Up @@ -4,19 +4,17 @@
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
#import "TiProxy.h"

#ifdef USE_TI_CALENDAR
#import "TiProxy.h"
#import "CalendarModule.h"

@interface TiCalendarAttendee : TiProxy {
@private
CalendarModule* module;
EKParticipant* participant;
BOOL isOrganiser;
}

-(id)_initWithPageContext:(id<TiEvaluator>)context participant:(EKParticipant*)participant_ isOrganiser:(BOOL)_isOrganiser module:(CalendarModule*)module_;
-(id)_initWithPageContext:(id<TiEvaluator>)context participant:(EKParticipant*)participant_;

@end

#endif
88 changes: 33 additions & 55 deletions iphone/Classes/TiCalendarAttendee.m
Expand Up @@ -5,94 +5,72 @@
* Please see the LICENSE included with this distribution for details.
*/
#ifdef USE_TI_CALENDAR

#import "CalendarModule.h"
#import "TiCalendarAttendee.h"

@implementation TiCalendarAttendee

#pragma mark - Internals

-(id)_initWithPageContext:(id<TiEvaluator>)context participant:(EKParticipant*)participant_ isOrganiser:(BOOL)_isOrganiser module:(CalendarModule*)module_
- (id)_initWithPageContext:(id<TiEvaluator>)context participant:(EKParticipant*)participant_
{
if (self = [super _initWithPageContext:context]) {
module = [module_ retain];
participant = [participant_ retain];
isOrganiser = _isOrganiser;
}
return self;
}

-(void)dealloc
- (void)dealloc
{
RELEASE_TO_NIL(module);
RELEASE_TO_NIL(participant);
[super dealloc];
}

-(EKParticipant*) participant
- (EKParticipant*)participant
{
return participant;
}

-(NSString*)apiName
- (NSString*)apiName
{
return @"Ti.Calendar.Attendee";
}


#pragma mark - Public API's

-(id)valueForUndefinedKey:(NSString *)key
- (NSString*)name
{
ENSURE_UI_THREAD(valueForUndefinedKey, key);

if ([key isEqualToString:@"name"]) {
return participant.name;
} else if ([key isEqualToString:@"email"]) {
// Apple dont give out device account email since it is a privacy concern.
// We can query through non-documented methods but that is not advisable.
if (participant.isCurrentUser) {
return @"";
}
NSURL* url = participant.URL;
NSString* email = url.resourceSpecifier;
return email;

} else if ([key isEqualToString:@"role"]) {
EKParticipantRole role = participant.participantRole;
EKParticipantRole mappedRole = EKParticipantRoleRequired;
if (role == EKParticipantRoleUnknown ||
role == EKParticipantRoleOptional ||
role == EKParticipantRoleNonParticipant) {
mappedRole = EKParticipantRoleOptional;
}
return NUMINT(mappedRole);

} else if ([key isEqualToString:@"status"]) {
EKParticipantStatus status = participant.participantStatus;
EKParticipantStatus mappedStatus = EKParticipantStatusUnknown;
if (status == EKParticipantStatusTentative ||
status == EKParticipantStatusDelegated) {
mappedStatus = EKParticipantStatusTentative;
} else if(status == EKParticipantStatusAccepted) {
mappedStatus = EKParticipantStatusAccepted;
} else if (status == EKParticipantStatusDeclined) {
mappedStatus = EKParticipantStatusDeclined;
}
return NUMINT(mappedStatus);

} else {
return [super valueForUndefinedKey:key];
}
return [[self participant] name];
}

- (NSString*)email
{
if ([[self participant] isCurrentUser]) {
return @"";
}

return [[[self participant] URL] resourceSpecifier];
}

#pragma mark - Public API
- (NSNumber*)role
{
return NUMUINT([[self participant] participantRole]);
}

- (NSNumber*)isOrganizer {
return NUMBOOL(isOrganiser);
- (NSNumber*)type
{
return NUMUINT([[self participant] participantType]);
}

- (NSNumber*)status
{
return NUMUINT([[self participant] participantStatus]);
}

- (NSNumber*)isOrganizer
{
return NUMBOOL([[self participant] isCurrentUser]);
}

@end

#endif
#endif
14 changes: 5 additions & 9 deletions iphone/Classes/TiCalendarEvent.m
Expand Up @@ -532,19 +532,15 @@ -(NSNumber*) refresh:(id)unused
-(NSArray*) attendees
{
NSArray* participants = [[self event] attendees];
NSMutableArray* result = [NSMutableArray arrayWithCapacity:participants.count];
NSMutableArray* result = [NSMutableArray arrayWithCapacity:[participants count]];

for (EKParticipant* participant in participants) {
BOOL isOrganiser = NO;
if ([participant isCurrentUser]) {
isOrganiser = YES;
}
TiCalendarAttendee* theAttendee = [[[TiCalendarAttendee alloc] _initWithPageContext:self.executionContext participant:participant isOrganiser:isOrganiser module:module] autorelease];
[result addObject:theAttendee];
[result addObject:[[[TiCalendarAttendee alloc] _initWithPageContext:[self executionContext] participant:participant] autorelease]];
}
[participants release];

return result;
}

@end

#endif
#endif

0 comments on commit cad9a41

Please sign in to comment.