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 5352320..aa5530b 100644
--- a/Juick/APIClient.m
+++ b/Juick/APIClient.m
@@ -122,6 +122,27 @@
}];
}];
}
+-(void) fetchChatWithUser:(NSString *)uname callback:(void (^)(NSArray *, NSError *))callback {
+ AFHTTPSessionManager *manager = [APIClient sharedClient].manager;
+ NSDictionary *params = @{@"uname": uname};
+ [self.backgroundQueue addOperationWithBlock:^{
+ [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 yy_modelWithJSON:obj]];
+ }];
+ [[NSOperationQueue mainQueue] addOperationWithBlock:^{
+ callback(messages, nil);
+ }];
+ } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
+ NSLog(@"Error: %@", [error localizedDescription]);
+ [[NSOperationQueue mainQueue] addOperationWithBlock:^{
+ callback(nil, error);
+ }];
+ }];
+ }];
+}
+(NSString *) messagesUrl {