summaryrefslogtreecommitdiff
path: root/Juick/APIClient.m
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-03-04 10:22:28 +0300
committerGravatar Vitaly Takmazov2018-03-04 10:22:28 +0300
commit782219f3cdc8cac644cc33657813a5f8319dbae7 (patch)
tree65591cd2beb07dd6364a78f6e1154798ae00cf0a /Juick/APIClient.m
parent5d0e97b3c1a1910a036f455b67205bc5eece1c29 (diff)
groups_pms
Diffstat (limited to 'Juick/APIClient.m')
-rw-r--r--Juick/APIClient.m21
1 files changed, 21 insertions, 0 deletions
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 {