diff options
Diffstat (limited to 'Juick')
-rw-r--r-- | Juick/APIClient.h | 2 | ||||
-rw-r--r-- | Juick/APIClient.m | 13 | ||||
-rw-r--r-- | Juick/Views/MessageCell.m | 6 |
3 files changed, 18 insertions, 3 deletions
diff --git a/Juick/APIClient.h b/Juick/APIClient.h index 078b91f..0f4c9d1 100644 --- a/Juick/APIClient.h +++ b/Juick/APIClient.h @@ -24,6 +24,8 @@ -(void) authenticate:(void(^)(BOOL))callback; -(void) refreshDeviceRegistration:(DeviceRegistration *)registrationData callback:(void(^)(BOOL))callback; -(void) getUserByName:(NSString *) name callback:(void(^)(User *))callback; +-(BOOL) isAuthenticated; +-(void) fetchImageWithURL:(NSURL *) url callback:(void(^)(NSData *))callback; +(NSString *) messagesUrl; +(NSString *) threadUrl; diff --git a/Juick/APIClient.m b/Juick/APIClient.m index d3bd248..fdc4005 100644 --- a/Juick/APIClient.m +++ b/Juick/APIClient.m @@ -12,6 +12,7 @@ @interface APIClient() @property(nonatomic, readwrite) AFHTTPSessionManager *manager; @property(nonatomic, strong) NSOperationQueue *backgroundQueue; +@property(nonatomic, strong) NSURLSession *urlSession; @end @implementation APIClient @@ -36,6 +37,7 @@ self.dateFormatter = [[NSDateFormatter alloc] init]; self.dateFormatter.dateFormat = @"yyyy-MM-dd HH:mm:ss"; [self.dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]]; + _urlSession = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]]; } return self; } @@ -203,6 +205,17 @@ } +- (void)fetchImageWithURL:(NSURL *)url callback:(void (^)(NSData *))callback { + NSURLSessionDataTask *dataTask = [self.urlSession dataTaskWithURL:url completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) { + [[NSOperationQueue mainQueue] addOperationWithBlock:^{ + callback(data); + }]; + }]; + [self.backgroundQueue addOperationWithBlock:^{ + [dataTask resume]; + }]; +} + +(NSString *) messagesUrl { return @"messages"; } diff --git a/Juick/Views/MessageCell.m b/Juick/Views/MessageCell.m index fb6e831..55e6054 100644 --- a/Juick/Views/MessageCell.m +++ b/Juick/Views/MessageCell.m @@ -32,15 +32,15 @@ self.message = msg; self.avatar.image = nil; __weak UIImageView *weakAvatar = self.avatar; - [self.avatar setImageWithURLRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:msg.user.avatar]] placeholderImage:nil success:^(NSURLRequest * _Nonnull request, NSHTTPURLResponse * _Nullable response, UIImage * _Nonnull image) { + [[APIClient sharedClient] fetchImageWithURL:[NSURL URLWithString:msg.user.avatar] callback:^(NSData *data) { [UIView transitionWithView:weakAvatar duration:0.3 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{ - weakAvatar.image = image; + weakAvatar.image = [UIImage imageWithData:data]; } completion:nil]; - } failure:nil]; + }]; if ([msg.attach length] > 0) { CGFloat imageHeight = [msg.attachment.small.height floatValue] / [[UIScreen mainScreen] scale]; self.attachmentHeight.constant = imageHeight; |