summaryrefslogtreecommitdiff
path: root/Juick/APIClient.m
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-03-04 11:50:14 +0300
committerGravatar Vitaly Takmazov2018-03-04 11:50:22 +0300
commita04f0db29cb280eb45888d3a56967cf9adc6214d (patch)
treeb1625107b75a906b7b402296b3a93ca11a578633 /Juick/APIClient.m
parent782219f3cdc8cac644cc33657813a5f8319dbae7 (diff)
ChatViewController
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 {