From 650fd803616d0e782d02b965c49fa06be65cea79 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 30 Dec 2020 08:57:15 +0300 Subject: Fetch external users --- Juick/Views/MessageCell.m | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'Juick/Views') 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]; -- cgit v1.2.3