From 782219f3cdc8cac644cc33657813a5f8319dbae7 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sun, 4 Mar 2018 10:22:28 +0300 Subject: groups_pms --- Juick/APIClient.m | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'Juick/APIClient.m') diff --git a/Juick/APIClient.m b/Juick/APIClient.m index 3190659..5352320 100644 --- a/Juick/APIClient.m +++ b/Juick/APIClient.m @@ -8,6 +8,7 @@ #import "APIClient.h" #import "PDKeychainBindings.h" #import "Message.h" +#import "Chat.h" @interface APIClient() @property(nonatomic, strong) NSOperationQueue *backgroundQueue; @@ -101,6 +102,26 @@ }]; }]; } +-(void) fetchChats:(void (^)(NSArray *, NSError *))callback { + AFHTTPSessionManager *manager = [APIClient sharedClient].manager; + [self.backgroundQueue addOperationWithBlock:^{ + [manager GET:@"/groups_pms" parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) { + NSMutableArray *groups = [NSMutableArray new]; + NSArray *pms = [(NSDictionary *)responseObject objectForKey:@"pms"]; + [pms enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { + [groups addObject:[Chat yy_modelWithJSON:obj]]; + }]; + [[NSOperationQueue mainQueue] addOperationWithBlock:^{ + callback(groups, nil); + }]; + } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { + NSLog(@"Error: %@", [error localizedDescription]); + [[NSOperationQueue mainQueue] addOperationWithBlock:^{ + callback(nil, error); + }]; + }]; + }]; +} +(NSString *) messagesUrl { -- cgit v1.2.3