From 32c4cc1b993b08c69fc1ca76770bb33a1a6157f4 Mon Sep 17 00:00:00 2001 From: Peter Date: Fri, 20 Jul 2018 21:17:36 +0300 Subject: [PATCH] no message --- LegacyComponents/TGGifConverter.m | 16 +++++++++++++++- LegacyComponents/TGLocationPickerController.m | 1 + LegacyComponents/TGMediaAssetsController.m | 13 ++++++++++++- .../TGVideoMessageCaptureController.m | 18 +++++++++--------- 4 files changed, 37 insertions(+), 11 deletions(-) diff --git a/LegacyComponents/TGGifConverter.m b/LegacyComponents/TGGifConverter.m index 4566e27a5e..7acce7f64a 100644 --- a/LegacyComponents/TGGifConverter.m +++ b/LegacyComponents/TGGifConverter.m @@ -133,6 +133,8 @@ const CGFloat TGGifConverterMaximumSide = 720.0f; [videoWriter startWriting]; [videoWriter startSessionAtSourceTime:CMTimeMakeWithSeconds(totalFrameDelay, TGGifConverterFPS)]; + __block UIImage *previewImage = nil; + while (!cancelled) { if (videoWriterInput.isReadyForMoreMediaData) @@ -149,6 +151,9 @@ const CGFloat TGGifConverterMaximumSide = 720.0f; CVPixelBufferRef pxBuffer = [self newBufferFrom:imgRef withPixelBufferPool:adaptor.pixelBufferPool andAttributes:adaptor.sourcePixelBufferAttributes]; if (pxBuffer != NULL) { + if (previewImage == nil) { + previewImage = TGScaleImageToPixelSize([[UIImage alloc] initWithCGImage:imgRef], targetSize); + } float frameDuration = 0.1f; NSNumber *delayTimeUnclampedProp = CFDictionaryGetValue(gifProperties, kCGImagePropertyGIFUnclampedDelayTime); if (delayTimeUnclampedProp != nil) @@ -194,7 +199,16 @@ const CGFloat TGGifConverterMaximumSide = 720.0f; [videoWriter finishWritingWithCompletionHandler:^ { - [subscriber putNext:[outFilePath path]]; + NSMutableDictionary *dict = [[NSMutableDictionary alloc] init]; + if ([outFilePath path] != nil) { + dict[@"path"] = [outFilePath path]; + } + dict[@"dimensions"] = [NSValue valueWithCGSize:targetSize]; + dict[@"duration"] = @((double)totalFrameDelay); + if (previewImage != nil) { + dict[@"previewImage"] = previewImage; + } + [subscriber putNext:dict]; [subscriber putCompletion]; }]; break; diff --git a/LegacyComponents/TGLocationPickerController.m b/LegacyComponents/TGLocationPickerController.m index 56ffa2e273..495678d64e 100644 --- a/LegacyComponents/TGLocationPickerController.m +++ b/LegacyComponents/TGLocationPickerController.m @@ -909,6 +909,7 @@ const CGPoint TGLocationPickerPinOffset = { 0.0f, 33.0f }; tableView.dataSource = self; tableView.separatorStyle = UITableViewCellSeparatorStyleNone; tableView.tableFooterView = [[UIView alloc] init]; + tableView.backgroundColor = self.pallete != nil ? self.pallete.backgroundColor : [UIColor whiteColor]; return tableView; } diff --git a/LegacyComponents/TGMediaAssetsController.m b/LegacyComponents/TGMediaAssetsController.m index 0c19a623a0..149746da0d 100644 --- a/LegacyComponents/TGMediaAssetsController.m +++ b/LegacyComponents/TGMediaAssetsController.m @@ -857,14 +857,25 @@ const char *gif89Header = "GIF89"; if (data.length >= 5 && (!memcmp(data.bytes, gif87Header, 5) || !memcmp(data.bytes, gif89Header, 5))) { - return [[TGGifConverter convertGifToMp4:data] map:^id(NSString *filePath) + return [[TGGifConverter convertGifToMp4:data] map:^id(NSDictionary *result) { + NSString *filePath = result[@"path"]; + NSMutableDictionary *dict = [[NSMutableDictionary alloc] init]; dict[@"type"] = @"file"; dict[@"tempFileUrl"] = [NSURL fileURLWithPath:filePath]; dict[@"fileName"] = @"animation.mp4"; dict[@"mimeType"] = @"video/mp4"; dict[@"isAnimation"] = @true; + if (result[@"dimensions"] != nil) { + dict[@"dimensions"] = result[@"dimensions"]; + } + if (result[@"duration"] != nil) { + dict[@"duration"] = result[@"duration"]; + } + if (result[@"previewImage"] != nil) { + dict[@"previewImage"] = result[@"previewImage"]; + } id generatedItem = descriptionGenerator(dict, caption, entities, nil); return generatedItem; diff --git a/LegacyComponents/TGVideoMessageCaptureController.m b/LegacyComponents/TGVideoMessageCaptureController.m index 60e0c1b74b..46a3da8e45 100644 --- a/LegacyComponents/TGVideoMessageCaptureController.m +++ b/LegacyComponents/TGVideoMessageCaptureController.m @@ -160,11 +160,6 @@ typedef enum self.isImportant = true; _controlsFrame = controlsFrame; - TGVideoMessageCaptureControllerWindow *window = [[TGVideoMessageCaptureControllerWindow alloc] initWithManager:[_context makeOverlayWindowManager] parentController:parentController contentController:self keepKeyboard:true]; - window.windowLevel = 1000000000.0f - 0.001f; - window.hidden = false; - window.controlsFrame = controlsFrame; - _gpuAvailable = true; _activityDisposable = [[SMetaDisposable alloc] init]; @@ -183,6 +178,11 @@ typedef enum }]; _thumbnailsDisposable = [[SMetaDisposable alloc] init]; + + TGVideoMessageCaptureControllerWindow *window = [[TGVideoMessageCaptureControllerWindow alloc] initWithManager:[_context makeOverlayWindowManager] parentController:parentController contentController:self keepKeyboard:true]; + window.windowLevel = 1000000000.0f - 0.001f; + window.hidden = false; + window.controlsFrame = controlsFrame; } return self; } @@ -1067,17 +1067,17 @@ typedef enum _otherAudioPlaying = [[AVAudioSession sharedInstance] isOtherAudioPlaying]; __weak TGVideoMessageCaptureController *weakSelf = self; - [_currentAudioSession setDisposable:[[LegacyComponentsGlobals provider] requestAudioSession:speaker ? TGAudioSessionTypePlayAndRecordHeadphones : TGAudioSessionTypePlayAndRecord interrupted:^ + id disposable = [[LegacyComponentsGlobals provider] requestAudioSession:speaker ? TGAudioSessionTypePlayAndRecordHeadphones : TGAudioSessionTypePlayAndRecord interrupted:^ { TGDispatchOnMainThread(^{ __strong TGVideoMessageCaptureController *strongSelf = weakSelf; - if (strongSelf != nil) - { + if (strongSelf != nil) { strongSelf->_automaticDismiss = true; [strongSelf complete]; } }); - }]]; + }]; + [_currentAudioSession setDisposable:disposable]; }]; }