@@ -38,17 +38,45 @@ @interface LPActionContext()
3838
3939@implementation LPActionContext
4040
41- @synthesize name=_name;
42- @synthesize messageId=_messageId;
43- @synthesize originalMessageId=_originalMessageId;
44- @synthesize priority=_priority;
4541@synthesize args=_args;
46- @synthesize parentContext=_parentContext;
47- @synthesize contentVersion=_contentVersion;
48- @synthesize key=_key;
49- @synthesize preventRealtimeUpdating=_preventRealtimeUpdating;
50- @synthesize contextualValues=_contextualValues;
51- @synthesize countAggregator=_countAggregator;
42+
43+ - (instancetype )initWithName : (NSString *)name
44+ args : (NSDictionary *)args
45+ messageId : (NSString *)messageId
46+ originalMessageId : (NSString *)originalMessageId
47+ priority : (NSNumber *)priority
48+ {
49+ self = [super init ];
50+ if (self) {
51+ _name = name;
52+ _args = args;
53+ _messageId = messageId;
54+ _originalMessageId = originalMessageId;
55+ _contentVersion = [[LPVarCache sharedCache ] contentVersion ];
56+ _preventRealtimeUpdating = NO ;
57+ _isRooted = YES ;
58+ _isPreview = NO ;
59+ _priority = priority;
60+ _countAggregator = [LPCountAggregator sharedAggregator ];
61+ }
62+
63+ return self;
64+ }
65+
66+ - (instancetype )init : (NSString *)name
67+ args : (NSDictionary *)args
68+ messageId : (NSString *)messageId
69+ preventRealtimeUpdating : (BOOL )preventRealtimeUpdating ;
70+ {
71+ self = [self initWithName: name
72+ args: args
73+ messageId: messageId
74+ originalMessageId: nil
75+ priority: [NSNumber numberWithInt: DEFAULT_PRIORITY]];
76+ _preventRealtimeUpdating = preventRealtimeUpdating;
77+
78+ return self;
79+ }
5280
5381+ (LPActionContext *)actionContextWithName : (NSString *)name
5482 args : (NSDictionary *)args
@@ -68,18 +96,11 @@ + (LPActionContext *)actionContextWithName:(NSString *)name
6896 priority : (NSNumber *)priority
6997
7098{
71- LPActionContext *context = [[LPActionContext alloc ] init ];
72- context->_name = name;
73- context->_args = args;
74- context->_messageId = messageId;
75- context->_originalMessageId = originalMessageId;
76- context->_contentVersion = [[LPVarCache sharedCache ] contentVersion ];
77- context->_preventRealtimeUpdating = NO ;
78- context->_isRooted = YES ;
79- context->_isPreview = NO ;
80- context->_priority = priority;
81- context->_countAggregator = [LPCountAggregator sharedAggregator ];
82- return context;
99+ return [[LPActionContext alloc ] initWithName: name
100+ args: args
101+ messageId: messageId
102+ originalMessageId: originalMessageId
103+ priority: priority];
83104}
84105
85106- (NSDictionary *)defaultValues
@@ -133,7 +154,7 @@ - (id)objectNamed:(NSString *)name
133154 LP_TRY
134155 [self setProperArgs ];
135156 return [[LPVarCache sharedCache ] getValueFromComponentArray: [[LPVarCache sharedCache ] getNameComponents: name]
136- fromDict: _args];
157+ fromDict: _args];
137158 LP_END_TRY
138159 return nil ;
139160}
@@ -152,9 +173,9 @@ - (NSString *)fillTemplate:(NSString *)value
152173 if (!_contextualValues || !value || [value rangeOfString: @" ##" ].location == NSNotFound ) {
153174 return value;
154175 }
155-
176+
156177 NSDictionary *parameters = _contextualValues.parameters ;
157-
178+
158179 for (NSString *parameterName in [parameters keyEnumerator ]) {
159180 NSString *placeholder = [NSString stringWithFormat: @" ##Parameter %@ ##" , parameterName];
160181 value = [value stringByReplacingOccurrencesOfString: placeholder
@@ -165,7 +186,7 @@ - (NSString *)fillTemplate:(NSString *)value
165186 value = [value
166187 stringByReplacingOccurrencesOfString: @" ##Previous Value##"
167188 withString: [_contextualValues
168- .previousAttributeValue description ]];
189+ .previousAttributeValue description ]];
169190 }
170191 if (_contextualValues.attributeValue ) {
171192 value = [value stringByReplacingOccurrencesOfString: @" ##Value##"
@@ -204,30 +225,30 @@ - (NSURL *)htmlWithTemplateNamed:(NSString *)templateName
204225 " Empty name parameter provided." ];
205226 return nil ;
206227 }
207-
228+
208229 LP_TRY
209230 [self setProperArgs ];
210-
231+
211232 NSMutableDictionary *htmlVars = [self replaceFileNameToLocalFilePath: [_args mutableCopy ]
212233 preserveFileNamed: templateName];
213234 htmlVars[@" messageId" ] = self.messageId ;
214-
235+
215236 // Triggering Event.
216237 if (self.contextualValues && self.contextualValues .arguments ) {
217238 htmlVars[@" displayEvent" ] = self.contextualValues .arguments ;
218239 }
219-
240+
220241 // Add HTML Vars.
221242 NSString *jsonString = [LPJSON stringFromJSON: htmlVars];
222243 jsonString = [jsonString stringByReplacingOccurrencesOfString: @" \\ /" withString: @" /" ];
223-
244+
224245 // Template.
225246 NSString *htmlString = [self htmlStringContentsOfFile: [self fileNamed: templateName]];
226247 if (!htmlString) {
227248 LPLog (LPError, @" Fail to get HTML template." );
228249 return nil ;
229250 }
230-
251+
231252 if ([[htmlVars valueForKey: @" Height" ] isEqualToString: @" 100%" ] && [[htmlVars valueForKey: @" Width" ] isEqualToString: @" 100%" ]) {
232253 htmlString = [htmlString stringByReplacingOccurrencesOfString: @" /*##MEDIAQUERY##" withString: @" " ];
233254 htmlString = [htmlString stringByReplacingOccurrencesOfString: @" ##MEDIAQUERY##*/" withString: @" " ];
@@ -239,16 +260,16 @@ - (NSURL *)htmlWithTemplateNamed:(NSString *)templateName
239260
240261 htmlString = [htmlString stringByReplacingOccurrencesOfString: @" ##Vars##"
241262 withString: jsonString];
242-
263+
243264 htmlString = [self fillTemplate: htmlString];
244-
265+
245266 // Save filled template to temp file which will be used by WebKit
246267 NSString *randomUUID = [[[NSUUID UUID ] UUIDString ] lowercaseString ];
247268 NSString *tmpPath = [LPFileManager fileRelativeToDocuments: randomUUID createMissingDirectories: YES ];
248269 NSURL *tmpURL = [[NSURL fileURLWithPath: tmpPath] URLByAppendingPathExtension: @" html" ];
249-
270+
250271 [htmlString writeToURL: tmpURL atomically: YES encoding: NSUTF8StringEncoding error: nil ];
251-
272+
252273 return tmpURL;
253274 LP_END_TRY
254275 return nil ;
@@ -344,7 +365,7 @@ - (NSDictionary *)dictionaryNamed:(NSString *)name
344365 if ([object isKindOfClass: [NSDictionary class ]]) {
345366 return (NSDictionary *) object;
346367 }
347-
368+
348369 if ([object isKindOfClass: [NSString class ]]) {
349370 return [LPJSON JSONFromString: object];
350371 }
@@ -377,7 +398,7 @@ - (NSDictionary *)getChildArgs:(NSString *)name
377398 if (![actionArgs isKindOfClass: [NSDictionary class ]]) {
378399 return nil ;
379400 }
380-
401+
381402 NSDictionary *defaultArgs = [[[LPActionManager shared ] definitionWithName: actionArgs[LP_VALUE_ACTION_ARG]] values ];
382403 actionArgs = [ContentMerger mergeWithVars: defaultArgs diff: actionArgs];
383404
@@ -415,14 +436,14 @@ - (NSString *)eventWithParentEventNamesFromEvent:(NSString *)event
415436 options: NSCaseInsensitiveSearch
416437 range: NSMakeRange (0 ,
417438 actionName.length)
418- ];
419-
439+ ];
440+
420441 if (fullEventName.length ) {
421442 [fullEventName appendString: @" " ];
422443 }
423444 [fullEventName appendString: actionName];
424445 }
425-
446+
426447 return fullEventName;
427448 LP_END_TRY
428449}
@@ -435,12 +456,12 @@ - (void)runActionNamed:(NSString *)name
435456 return ;
436457 }
437458 NSDictionary *args = [self getChildArgs: name];
438-
459+
439460 __weak LPActionContext *weakSelf = self;
440461 if ([self actionDidExecute ]) {
441462 LPActionContext *actionNamedContext = [LPActionContext
442- actionContextWithName: name
443- args: args messageId: _messageId];
463+ actionContextWithName: name
464+ args: args messageId: _messageId];
444465 actionNamedContext->_parentContext = weakSelf;
445466 // notifies our LPActionManager that the action was executed
446467 self.actionDidExecute (actionNamedContext);
@@ -449,11 +470,11 @@ - (void)runActionNamed:(NSString *)name
449470 if (!args) {
450471 return ;
451472 }
452-
473+
453474 // Chain to existing message.
454475 NSString *messageId = args[LP_VALUE_CHAIN_MESSAGE_ARG];
455476 NSString *actionType = args[LP_VALUE_ACTION_ARG];
456-
477+
457478 void (^executeChainedMessage)(void ) = ^void (void ) {
458479 LPActionContext *chainedActionContext = [Leanplum createActionContextForMessageId: messageId];
459480 chainedActionContext.contextualValues = self.contextualValues ;
@@ -465,12 +486,13 @@ - (void)runActionNamed:(NSString *)name
465486 [[LPActionManager shared ] triggerWithContexts: @[chainedActionContext] priority: PriorityHigh trigger: nil ];
466487 });
467488 };
468-
489+
469490 if (messageId && [actionType isEqualToString: LP_VALUE_CHAIN_MESSAGE_ACTION_NAME]) {
470491 NSDictionary *message = [[LPActionManager shared ] messages ][messageId];
471492 if (message) {
472493 executeChainedMessage ();
473494 } else {
495+ BOOL previousPauseState = LPActionManager.shared .isPaused ;
474496 LPActionManager.shared .isPaused = YES ;
475497 // Message doesn't seem to be on the device,
476498 // so let's forceContentUpdate and retry showing it.
@@ -479,7 +501,7 @@ - (void)runActionNamed:(NSString *)name
479501 if (message) {
480502 executeChainedMessage ();
481503 }
482- LPActionManager.shared .isPaused = NO ;
504+ LPActionManager.shared .isPaused = previousPauseState ;
483505 }];
484506 }
485507 } else {
@@ -496,7 +518,7 @@ - (void)runActionNamed:(NSString *)name
496518 [[LPActionManager shared ] triggerWithContexts: @[childContext] priority: PriorityHigh trigger: nil ];
497519 });
498520 }
499-
521+
500522 LP_END_TRY
501523
502524 [self .countAggregator incrementCount: @" run_action_named" ];
@@ -510,6 +532,7 @@ - (void)runTrackedActionNamed:(NSString *)name
510532 @" provided." ];
511533 return ;
512534 }
535+
513536 [self trackMessageEvent: name withValue: 0.0 andInfo: nil andParameters: nil ];
514537 }
515538 [self runActionNamed: name];
0 commit comments