diff options
author | Vitaly Takmazov | 2019-03-24 12:22:39 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2019-03-24 12:22:39 +0300 |
commit | cdb89855715018d49f18bbe510b4502e903f75a7 (patch) | |
tree | 77b0e4b59fdb360e2403b073123c9f0e96cccee9 | |
parent | 381780a518601584d645cb4960802046ef6bcaf3 (diff) |
Delay for chat notification
-rw-r--r-- | Juick/APIClient.m | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/Juick/APIClient.m b/Juick/APIClient.m index f2eeb29..24efc60 100644 --- a/Juick/APIClient.m +++ b/Juick/APIClient.m @@ -158,23 +158,25 @@ } -(void) fetchChatWithUser:(NSString *)uname callback:(void (^)(NSArray *, NSError *))callback { NSDictionary *params = @{@"uname": uname}; - [self.backgroundQueue addOperationWithBlock:^{ - [self.manager GET:@"pm" parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) { - NSMutableArray *messages = [NSMutableArray new]; - NSArray *messagesList = (NSArray *)responseObject; - [messagesList 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(@"Error: %@", [error localizedDescription]); - [[NSOperationQueue mainQueue] addOperationWithBlock:^{ - callback(nil, error); + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + [self.backgroundQueue addOperationWithBlock:^{ + [self.manager GET:@"pm" parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) { + NSMutableArray *messages = [NSMutableArray new]; + NSArray *messagesList = (NSArray *)responseObject; + [messagesList 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(@"Error: %@", [error localizedDescription]); + [[NSOperationQueue mainQueue] addOperationWithBlock:^{ + callback(nil, error); + }]; }]; }]; - }]; + }); } -(void) authenticate:(void (^)(User *user, NSError *error))callback { [self.manager GET:@"me" parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) { |