From cdb89855715018d49f18bbe510b4502e903f75a7 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sun, 24 Mar 2019 12:22:39 +0300 Subject: Delay for chat notification --- Juick/APIClient.m | 32 +++++++++++++++++--------------- 1 file 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) { -- cgit v1.2.3