summaryrefslogtreecommitdiff
path: root/Juick/APIClient.m
diff options
context:
space:
mode:
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 {