@@ -166,6 +166,50 @@ -(void)tryEnqueue
166
166
}];
167
167
}
168
168
169
+ -(BOOL )isSafetyNet : (NSString *) queueId
170
+ queueURL : (NSString *) queueURL
171
+ {
172
+ bool queueIdExists = queueId != nil && queueId != (id )[NSNull null ];
173
+ bool queueUrlExists = queueURL != nil && queueURL != (id )[NSNull null ];
174
+ return queueIdExists && !queueUrlExists;
175
+ }
176
+
177
+ -(BOOL )isDisabled : (NSString *) queueId
178
+ queueURL : (NSString *) queueURL
179
+ {
180
+ bool queueIdExists = queueId != nil && queueId != (id )[NSNull null ];
181
+ bool queueUrlExists = queueURL != nil && queueURL != (id )[NSNull null ];
182
+ return !queueIdExists && !queueUrlExists;
183
+ }
184
+
185
+ -(void )handleAppEnqueueResponse : (NSString *) queueId
186
+ queueURL : (NSString *) queueURL
187
+ queueURLTTLInMinutes : (int ) ttl
188
+ eventTargetURL : (NSString *) targetURL
189
+ queueItToken : (NSString *) token {
190
+ // SafetyNet
191
+ if ([self isSafetyNet: queueId queueURL: queueURL])
192
+ {
193
+ [self raiseQueuePassed: token];
194
+ return ;
195
+ }
196
+ // Disabled
197
+ else if ([self isDisabled: queueId queueURL: queueURL]){
198
+ self.requestInProgress = NO ;
199
+ [self raiseQueueDisabled ];
200
+ return ;
201
+ }
202
+
203
+ // InQueue, PostQueue or Idle
204
+ self.queueUrlTtl = ttl;
205
+ [self showQueue: queueURL targetUrl: targetURL];
206
+
207
+ if (ttl>0 ){
208
+ NSString * urlTtlString = [self convertTtlMinutesToSecondsString: ttl];
209
+ [self .cache update: queueURL urlTTL: urlTtlString targetUrl: targetURL];
210
+ }
211
+ }
212
+
169
213
-(void )tryEnqueueWithUserAgent : (NSString *)secretAgent
170
214
{
171
215
NSString * userId = [IOSUtils getUserId ];
@@ -186,34 +230,11 @@ -(void)tryEnqueueWithUserAgent:(NSString*)secretAgent
186
230
return ;
187
231
}
188
232
189
- bool queueIdExists = queueStatus.queueId != nil && queueStatus.queueId != (id )[NSNull null ];
190
- bool queueUrlExists = queueStatus.queueUrlString != nil && queueStatus.queueUrlString != (id )[NSNull null ];
191
-
192
- // SafetyNet
193
- if (queueIdExists && !queueUrlExists)
194
- {
195
- [self raiseQueuePassed: queueStatus.queueitToken];
196
- }
197
- // InQueue
198
- else if (queueIdExists && queueUrlExists)
199
- {
200
- self.queueUrlTtl = queueStatus.queueUrlTTL ;
201
- [self showQueue: queueStatus.queueUrlString targetUrl: queueStatus.eventTargetUrl];
202
-
203
- NSString * urlTtlString = [self convertTtlMinutesToSecondsString: queueStatus.queueUrlTTL];
204
- [self .cache update: queueStatus.queueUrlString urlTTL: urlTtlString targetUrl: queueStatus.eventTargetUrl];
205
- }
206
- // PostQueue or Idle
207
- else if (!queueIdExists && queueUrlExists)
208
- {
209
- [self showQueue: queueStatus.queueUrlString targetUrl: queueStatus.eventTargetUrl];
210
- }
211
- // Disabled
212
- else
213
- {
214
- self.requestInProgress = NO ;
215
- [self raiseQueueDisabled ];
216
- }
233
+ [self handleAppEnqueueResponse: queueStatus.queueId
234
+ queueURL: queueStatus.queueUrlString
235
+ queueURLTTLInMinutes: queueStatus.queueUrlTTL
236
+ eventTargetURL: queueStatus.eventTargetUrl
237
+ queueItToken: queueStatus.queueitToken];
217
238
}
218
239
failure: ^(NSError *error, NSString * errorMessage)
219
240
{
0 commit comments