summaryrefslogtreecommitdiff
path: root/Juick
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2019-03-21 01:24:13 +0300
committerGravatar Vitaly Takmazov2019-03-21 14:08:59 +0300
commit59a340bbfb1be5b4f9f0a36bacaaa7da09127b0d (patch)
treec3a0d201e13713d3f4de67ba315dc4f643b5c986 /Juick
parentd939a7a7f157e022870fcbe0632cdd195ce91f8b (diff)
Pull messages after delay
Diffstat (limited to 'Juick')
-rw-r--r--Juick/APIClient.m36
1 files changed, 19 insertions, 17 deletions
diff --git a/Juick/APIClient.m b/Juick/APIClient.m
index fdc4005..dcc72a8 100644
--- a/Juick/APIClient.m
+++ b/Juick/APIClient.m
@@ -53,26 +53,28 @@
}
-(void) pullNextFromPath:(NSString *)path params:(NSDictionary *) params callback:(void(^)(NSArray *, NSError *))callback {
- [self.backgroundQueue addOperationWithBlock:^{
- [self.manager GET:path parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
- NSMutableArray *messages = [NSMutableArray new];
- [((NSArray *)responseObject) enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
- [messages addObject:[Message fromJSON:obj]];
- }];
- [[NSOperationQueue mainQueue] addOperationWithBlock:^{
- callback(messages, nil);
- }];
-
- } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
- NSLog(@"REST Error: %@", error);
- NSInteger statusCode = ((NSHTTPURLResponse *)task.response).statusCode;
- if (statusCode == 401) {
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
+ [self.backgroundQueue addOperationWithBlock:^{
+ [self.manager GET:path parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
+ NSMutableArray *messages = [NSMutableArray new];
+ [((NSArray *)responseObject) enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
+ [messages addObject:[Message fromJSON:obj]];
+ }];
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
- callback(nil, [[NSError alloc] initWithDomain:@"JuickErrorDomain" code:401 userInfo:nil]);
+ callback(messages, nil);
}];
- }
+
+ } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
+ NSLog(@"REST Error: %@", error);
+ NSInteger statusCode = ((NSHTTPURLResponse *)task.response).statusCode;
+ if (statusCode == 401) {
+ [[NSOperationQueue mainQueue] addOperationWithBlock:^{
+ callback(nil, [[NSError alloc] initWithDomain:@"JuickErrorDomain" code:401 userInfo:nil]);
+ }];
+ }
+ }];
}];
- }];
+ });
}
-(void) postMessage:(NSString *)text result:(void (^)(Message *, NSError *))callback {