diff options
author | Vitaly Takmazov | 2020-12-30 08:57:15 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2020-12-30 08:57:15 +0300 |
commit | 650fd803616d0e782d02b965c49fa06be65cea79 (patch) | |
tree | b6c6400cd72d86de438415e79a9ed41ae6af7e79 /Juick | |
parent | 3d0d75fd56fe5823468318129de4da55e4b27b25 (diff) |
Fetch external users
Diffstat (limited to 'Juick')
-rw-r--r-- | Juick/API.h | 2 | ||||
-rw-r--r-- | Juick/API.m | 16 | ||||
-rw-r--r-- | Juick/Model/User.h | 1 | ||||
-rw-r--r-- | Juick/Model/User.m | 1 | ||||
-rw-r--r-- | Juick/ViewControllers/JuickNavigationController.m | 2 | ||||
-rw-r--r-- | Juick/Views/MessageCell.m | 22 |
6 files changed, 38 insertions, 6 deletions
diff --git a/Juick/API.h b/Juick/API.h index fcf9fb1..de771c4 100644 --- a/Juick/API.h +++ b/Juick/API.h @@ -28,6 +28,7 @@ -(void) me:(void(^)(User *, NSError *))callback; -(void) refreshDeviceRegistration:(DeviceRegistration *)registrationData callback:(void(^)(BOOL))callback; -(void) getUserByName:(NSString *) name callback:(void(^)(User *))callback; +-(void) getUserByUri:(NSString *) uri callback:(void(^)(User *))callback; -(void) fetchImageWithURL:(NSURL *) url callback:(void(^)(NSData *))callback; @property (nonatomic, strong) User * currentUser; @@ -35,5 +36,6 @@ +(NSString *) threadUrl; +(NSString *) feedUrl; +(NSString *) discussionsUrl; ++(NSString *) defaultAvatarUrl; @end diff --git a/Juick/API.m b/Juick/API.m index a18b9b1..ce8915a 100644 --- a/Juick/API.m +++ b/Juick/API.m @@ -290,6 +290,18 @@ }]; } +-(void) getUserByUri:(NSString *)uri callback:(void (^)(User *))callback { + [self post:@"u/" params:@{ + @"uri": uri + } callback:^(NSDictionary *response, NSError *err) { + User *result; + if (!err) { + result = [User fromJSON:response]; + } + callback(result); + }]; +} + -(void) fetchImageWithURL:(NSURL *) url callback:(void(^)(NSData *))callback { [self fetchDataWithURL:url data:nil boundary:nil authorizationHeader:self.authorizationHeader callback:^(NSData *data, NSError *err) { if (err) { @@ -320,4 +332,8 @@ return @"home"; } ++(NSString *) defaultAvatarUrl { + return @"https://i.juick.com/av-96.png";; +} + @end diff --git a/Juick/Model/User.h b/Juick/Model/User.h index 4bbf332..cb63ebc 100644 --- a/Juick/Model/User.h +++ b/Juick/Model/User.h @@ -13,6 +13,7 @@ @property (nonatomic, strong) NSString *uid; @property (nonatomic, strong) NSString *avatar; @property (nonatomic, strong) NSString *token; +@property (nonatomic, strong) NSString *uri; @property (nonatomic) NSInteger unreadCount; + (User *) fromJSON:(NSDictionary *)jsonData; diff --git a/Juick/Model/User.m b/Juick/Model/User.m index f9b2990..ee3cce8 100644 --- a/Juick/Model/User.m +++ b/Juick/Model/User.m @@ -16,6 +16,7 @@ user.uname = jsonData[@"uname"]; user.avatar = jsonData[@"avatar"]; user.token = jsonData[@"hash"]; + user.uri = jsonData[@"uri"]; user.unreadCount = [jsonData[@"messagesCount"] integerValue]; return user; } diff --git a/Juick/ViewControllers/JuickNavigationController.m b/Juick/ViewControllers/JuickNavigationController.m index aaf3765..f535c82 100644 --- a/Juick/ViewControllers/JuickNavigationController.m +++ b/Juick/ViewControllers/JuickNavigationController.m @@ -28,7 +28,7 @@ [[AppDelegate shared].api me:^(User *user, NSError *err) { NSString *avatarUrl; if (err || !user) { - avatarUrl = @"https://i.juick.com/av-96.png"; + avatarUrl = [API defaultAvatarUrl]; } else { avatarUrl = user.avatar; } diff --git a/Juick/Views/MessageCell.m b/Juick/Views/MessageCell.m index f02aa48..122f7d9 100644 --- a/Juick/Views/MessageCell.m +++ b/Juick/Views/MessageCell.m @@ -15,6 +15,7 @@ @property(nonatomic, readonly) NSMutableParagraphStyle *quoteStyle; @property(nonatomic, readonly) UIFont *boldFont; @property(nonatomic, readonly) UIFont *italicFont; +- (void) updateAvatarWithUrl:(NSString *)avatarUrl; @end @implementation MessageCell @@ -46,18 +47,29 @@ const NSString *unreadMarker = @"●"; _italicFont = [UIFont fontWithDescriptor:italicFontDescriptor size: 0.0]; } -- (void) configureWithMessage:(Message *)msg selectable:(BOOL)selectable { +- (void) updateAvatarWithUrl:(NSString *)avatarUrl { self.avatar.image = nil; __weak UIImageView *weakAvatar = self.avatar; - [[AppDelegate shared].api fetchImageWithURL:[NSURL URLWithString:msg.user.avatar] callback:^(NSData *data) { + [[AppDelegate shared].api fetchImageWithURL:[NSURL URLWithString:avatarUrl] callback:^(NSData *data) { [UIView transitionWithView:weakAvatar duration:0.3 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{ - weakAvatar.image = [UIImage imageWithData:data]; - } - completion:nil]; + weakAvatar.image = [UIImage imageWithData:data]; + } completion:nil]; }]; +} + +- (void) configureWithMessage:(Message *)msg selectable:(BOOL)selectable { + [self updateAvatarWithUrl:msg.user.avatar]; + if (!msg.user.uid) { + __weak UILabel *title = self.title; + [[AppDelegate shared].api getUserByUri:msg.user.uri callback:^(User *user) { + title.text = user.uname; + NSString *avatarUrl = user.avatar ? user.avatar : [API defaultAvatarUrl]; + [self updateAvatarWithUrl:avatarUrl]; + }]; + } if ([msg.attach length] > 0) { CGFloat imageHeight = [msg.attachment.small.height floatValue] / [[UIScreen mainScreen] scale]; CGFloat imageWidth = [msg.attachment.small.width floatValue] / [[UIScreen mainScreen] scale]; |