diff --git a/VideoCalls/CallParticipantViewCell.m b/VideoCalls/CallParticipantViewCell.m index b40add7a..c4ffad8c 100644 --- a/VideoCalls/CallParticipantViewCell.m +++ b/VideoCalls/CallParticipantViewCell.m @@ -11,6 +11,7 @@ #import "DBImageColorPicker.h" #import "CallViewController.h" #import "NCAPIController.h" +#import "NCUtils.h" #import "UIImageView+AFNetworking.h" #import "UIImageView+Letters.h" @@ -71,21 +72,20 @@ NSString *const kCallParticipantCellNibName = @"CallParticipantViewCell"; self.backgroundView = _backgroundImageView; [_backgroundImageView setImageWithURLRequest:[[NCAPIController sharedInstance] createAvatarRequestForUser:userId andSize:96 usingAccount:[[NCDatabaseManager sharedInstance] activeAccount]] placeholderImage:nil success:^(NSURLRequest * _Nonnull request, NSHTTPURLResponse * _Nullable response, UIImage * _Nonnull image) { - if ([response statusCode] == 200) { - CGFloat inputRadius = 8.0f; - CIContext *context = [CIContext contextWithOptions:nil]; - CIImage *inputImage = [[CIImage alloc] initWithImage:image]; - CIFilter *filter = [CIFilter filterWithName:@"CIGaussianBlur"]; - [filter setValue:inputImage forKey:kCIInputImageKey]; - [filter setValue:[NSNumber numberWithFloat:inputRadius] forKey:@"inputRadius"]; - CIImage *result = [filter valueForKey:kCIOutputImageKey]; - CGRect imageRect = [inputImage extent]; - CGRect cropRect = CGRectMake(imageRect.origin.x + inputRadius, imageRect.origin.y + inputRadius, imageRect.size.width - inputRadius * 2, imageRect.size.height - inputRadius * 2); - CGImageRef cgImage = [context createCGImage:result fromRect:imageRect]; - UIImage *finalImage = [UIImage imageWithCGImage:CGImageCreateWithImageInRect(cgImage, cropRect)]; - [weakBGView setImage:finalImage]; - weakBGView.contentMode = UIViewContentModeScaleAspectFill; + NSDictionary *headers = [response allHeaderFields]; + id customAvatarHeader = [headers objectForKey:@"X-NC-IsCustomAvatar"]; + BOOL shouldShowBlurBackground = YES; + if (customAvatarHeader) { + shouldShowBlurBackground = [customAvatarHeader boolValue]; } else if ([response statusCode] == 201) { + shouldShowBlurBackground = NO; + } + + if (shouldShowBlurBackground) { + UIImage *blurImage = [NCUtils blurImageFromImage:image]; + [weakBGView setImage:blurImage]; + weakBGView.contentMode = UIViewContentModeScaleAspectFill; + } else { DBImageColorPicker *colorPicker = [[DBImageColorPicker alloc] initFromImage:image withBackgroundType:DBImageColorPickerBackgroundTypeDefault]; [weakBGView setBackgroundColor:colorPicker.backgroundColor]; weakBGView.backgroundColor = [weakBGView.backgroundColor colorWithAlphaComponent:0.8]; diff --git a/VideoCalls/CallViewController.m b/VideoCalls/CallViewController.m index b7aca7c5..89b4bfda 100644 --- a/VideoCalls/CallViewController.m +++ b/VideoCalls/CallViewController.m @@ -23,6 +23,7 @@ #import "NCRoomsManager.h" #import "NCSettingsController.h" #import "NCSignalingMessage.h" +#import "NCUtils.h" #import "UIImageView+AFNetworking.h" #import "CallKitManager.h" #import "UIView+Toast.h" @@ -361,21 +362,20 @@ typedef NS_ENUM(NSInteger, CallState) { __weak AvatarBackgroundImageView *weakBGView = self.avatarBackgroundImageView; [self.avatarBackgroundImageView setImageWithURLRequest:[[NCAPIController sharedInstance] createAvatarRequestForUser:_room.name andSize:96 usingAccount:[[NCDatabaseManager sharedInstance] activeAccount]] placeholderImage:nil success:^(NSURLRequest * _Nonnull request, NSHTTPURLResponse * _Nullable response, UIImage * _Nonnull image) { - if ([response statusCode] == 200) { - CGFloat inputRadius = 8.0f; - CIContext *context = [CIContext contextWithOptions:nil]; - CIImage *inputImage = [[CIImage alloc] initWithImage:image]; - CIFilter *filter = [CIFilter filterWithName:@"CIGaussianBlur"]; - [filter setValue:inputImage forKey:kCIInputImageKey]; - [filter setValue:[NSNumber numberWithFloat:inputRadius] forKey:@"inputRadius"]; - CIImage *result = [filter valueForKey:kCIOutputImageKey]; - CGRect imageRect = [inputImage extent]; - CGRect cropRect = CGRectMake(imageRect.origin.x + inputRadius, imageRect.origin.y + inputRadius, imageRect.size.width - inputRadius * 2, imageRect.size.height - inputRadius * 2); - CGImageRef cgImage = [context createCGImage:result fromRect:imageRect]; - UIImage *finalImage = [UIImage imageWithCGImage:CGImageCreateWithImageInRect(cgImage, cropRect)]; - [weakBGView setImage:finalImage]; - weakBGView.contentMode = UIViewContentModeScaleAspectFill; + NSDictionary *headers = [response allHeaderFields]; + id customAvatarHeader = [headers objectForKey:@"X-NC-IsCustomAvatar"]; + BOOL shouldShowBlurBackground = YES; + if (customAvatarHeader) { + shouldShowBlurBackground = [customAvatarHeader boolValue]; } else if ([response statusCode] == 201) { + shouldShowBlurBackground = NO; + } + + if (shouldShowBlurBackground) { + UIImage *blurImage = [NCUtils blurImageFromImage:image]; + [weakBGView setImage:blurImage]; + weakBGView.contentMode = UIViewContentModeScaleAspectFill; + } else { DBImageColorPicker *colorPicker = [[DBImageColorPicker alloc] initFromImage:image withBackgroundType:DBImageColorPickerBackgroundTypeDefault]; [weakBGView setBackgroundColor:colorPicker.backgroundColor]; weakBGView.backgroundColor = [weakBGView.backgroundColor colorWithAlphaComponent:0.8]; diff --git a/VideoCalls/NCUtils.h b/VideoCalls/NCUtils.h index 0aaad957..bdfaedd7 100644 --- a/VideoCalls/NCUtils.h +++ b/VideoCalls/NCUtils.h @@ -7,6 +7,7 @@ // #import +#import NS_ASSUME_NONNULL_BEGIN @@ -25,6 +26,8 @@ NS_ASSUME_NONNULL_BEGIN + (NSString *)sha1FromString:(NSString *)string; ++ (UIImage *)blurImageFromImage:(UIImage *)image; + @end NS_ASSUME_NONNULL_END diff --git a/VideoCalls/NCUtils.m b/VideoCalls/NCUtils.m index ed723c85..0784c2ad 100644 --- a/VideoCalls/NCUtils.m +++ b/VideoCalls/NCUtils.m @@ -8,7 +8,6 @@ #import "NCUtils.h" -#import #import #import @@ -114,4 +113,19 @@ static NSString *const nextcloudScheme = @"nextcloud:"; return output; } ++ (UIImage *)blurImageFromImage:(UIImage *)image +{ + CGFloat inputRadius = 8.0f; + CIContext *context = [CIContext contextWithOptions:nil]; + CIImage *inputImage = [[CIImage alloc] initWithImage:image]; + CIFilter *filter = [CIFilter filterWithName:@"CIGaussianBlur"]; + [filter setValue:inputImage forKey:kCIInputImageKey]; + [filter setValue:[NSNumber numberWithFloat:inputRadius] forKey:@"inputRadius"]; + CIImage *result = [filter valueForKey:kCIOutputImageKey]; + CGRect imageRect = [inputImage extent]; + CGRect cropRect = CGRectMake(imageRect.origin.x + inputRadius, imageRect.origin.y + inputRadius, imageRect.size.width - inputRadius * 2, imageRect.size.height - inputRadius * 2); + CGImageRef cgImage = [context createCGImage:result fromRect:imageRect]; + return [UIImage imageWithCGImage:CGImageCreateWithImageInRect(cgImage, cropRect)]; +} + @end