diff --git a/submodules/AccountContext/Sources/AccountContext.swift b/submodules/AccountContext/Sources/AccountContext.swift index c5b2d073c7..5b1c19d51f 100644 --- a/submodules/AccountContext/Sources/AccountContext.swift +++ b/submodules/AccountContext/Sources/AccountContext.swift @@ -407,6 +407,7 @@ public protocol SharedAccountContext: class { var currentAutomaticMediaDownloadSettings: Atomic { get } var automaticMediaDownloadSettings: Signal { get } + var currentAutodownloadSettings: Atomic { get } var immediateExperimentalUISettings: ExperimentalUISettings { get } var currentInAppNotificationSettings: Atomic { get } var currentMediaInputSettings: Atomic { get } diff --git a/submodules/LegacyComponents/LegacyComponents/TGAttachmentCarouselItemView.h b/submodules/LegacyComponents/LegacyComponents/TGAttachmentCarouselItemView.h index 54638ed711..562545338a 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGAttachmentCarouselItemView.h +++ b/submodules/LegacyComponents/LegacyComponents/TGAttachmentCarouselItemView.h @@ -3,6 +3,7 @@ #import #import +#import @class TGMediaSelectionContext; @class TGMediaEditingContext; @@ -52,6 +53,7 @@ @property (nonatomic, assign) bool collapsed; @property (nonatomic, strong) NSString *recipientName; +@property (nonatomic, assign) TGMediaVideoConversionPreset defaultVideoPreset; - (instancetype)initWithContext:(id)context camera:(bool)hasCamera selfPortrait:(bool)selfPortrait forProfilePhoto:(bool)forProfilePhoto assetType:(TGMediaAssetType)assetType saveEditedPhotos:(bool)saveEditedPhotos allowGrouping:(bool)allowGrouping; diff --git a/submodules/LegacyComponents/LegacyComponents/TGAttachmentCarouselItemView.m b/submodules/LegacyComponents/LegacyComponents/TGAttachmentCarouselItemView.m index 27e58db3ca..ad79b6f4a0 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGAttachmentCarouselItemView.m +++ b/submodules/LegacyComponents/LegacyComponents/TGAttachmentCarouselItemView.m @@ -801,7 +801,7 @@ const NSUInteger TGAttachmentDisplayedAssetLimit = 500; if ([cell isKindOfClass:[TGAttachmentAssetCell class]]) thumbnailImage = cell.imageView.image; - TGMediaPickerModernGalleryMixin *mixin = [[TGMediaPickerModernGalleryMixin alloc] initWithContext:_context item:asset fetchResult:_fetchResult parentController:self.parentController thumbnailImage:thumbnailImage selectionContext:_selectionContext editingContext:_editingContext suggestionContext:self.suggestionContext hasCaptions:(_allowCaptions && !_forProfilePhoto) allowCaptionEntities:self.allowCaptionEntities hasTimer:self.hasTimer onlyCrop:self.onlyCrop inhibitDocumentCaptions:_inhibitDocumentCaptions inhibitMute:self.inhibitMute asFile:self.asFile itemsLimit:TGAttachmentDisplayedAssetLimit recipientName:self.recipientName hasSilentPosting:self.hasSilentPosting hasSchedule:self.hasSchedule reminder:self.reminder]; + TGMediaPickerModernGalleryMixin *mixin = [[TGMediaPickerModernGalleryMixin alloc] initWithContext:_context item:asset fetchResult:_fetchResult parentController:self.parentController thumbnailImage:thumbnailImage selectionContext:_selectionContext editingContext:_editingContext suggestionContext:self.suggestionContext hasCaptions:(_allowCaptions && !_forProfilePhoto) allowCaptionEntities:self.allowCaptionEntities hasTimer:self.hasTimer onlyCrop:self.onlyCrop inhibitDocumentCaptions:_inhibitDocumentCaptions inhibitMute:self.inhibitMute asFile:self.asFile itemsLimit:TGAttachmentDisplayedAssetLimit recipientName:self.recipientName defaultVideoPreset:self.defaultVideoPreset hasSilentPosting:self.hasSilentPosting hasSchedule:self.hasSchedule reminder:self.reminder]; mixin.presentScheduleController = self.presentScheduleController; __weak TGAttachmentCarouselItemView *weakSelf = self; mixin.thumbnailSignalForItem = ^SSignal *(id item) @@ -864,7 +864,7 @@ const NSUInteger TGAttachmentDisplayedAssetLimit = 500; { id windowManager = [_context makeOverlayWindowManager]; - TGPhotoEditorController *controller = [[TGPhotoEditorController alloc] initWithContext:[windowManager context] item:asset intent:_disableStickers ? TGPhotoEditorControllerSignupAvatarIntent : TGPhotoEditorControllerAvatarIntent adjustments:nil caption:nil screenImage:thumbnailImage availableTabs:[TGPhotoEditorController defaultTabsForAvatarIntent] selectedTab:TGPhotoEditorCropTab]; + TGPhotoEditorController *controller = [[TGPhotoEditorController alloc] initWithContext:[windowManager context] item:asset intent:_disableStickers ? TGPhotoEditorControllerSignupAvatarIntent : TGPhotoEditorControllerAvatarIntent adjustments:nil caption:nil screenImage:thumbnailImage availableTabs:[TGPhotoEditorController defaultTabsForAvatarIntent] selectedTab:TGPhotoEditorCropTab defaultVideoPreset:_defaultVideoPreset]; controller.editingContext = _editingContext; controller.dontHideStatusBar = true; diff --git a/submodules/LegacyComponents/LegacyComponents/TGCameraController.h b/submodules/LegacyComponents/LegacyComponents/TGCameraController.h index 087ed30219..673891afc5 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGCameraController.h +++ b/submodules/LegacyComponents/LegacyComponents/TGCameraController.h @@ -2,6 +2,7 @@ #import #import #import +#import @class PGCamera; @class TGCameraPreviewView; @@ -45,6 +46,7 @@ typedef enum { @property (nonatomic, strong) NSArray *forcedEntities; @property (nonatomic, strong) NSString *recipientName; +@property (nonatomic, assign) TGMediaVideoConversionPreset defaultVideoPreset; @property (nonatomic, copy) void(^finishedWithResults)(TGOverlayController *controller, TGMediaSelectionContext *selectionContext, TGMediaEditingContext *editingContext, id currentItem, bool silentPosting, int32_t scheduleTime); @property (nonatomic, copy) void(^finishedWithPhoto)(TGOverlayController *controller, UIImage *resultImage, NSString *caption, NSArray *entities, NSArray *stickers, NSNumber *timer); diff --git a/submodules/LegacyComponents/LegacyComponents/TGCameraController.m b/submodules/LegacyComponents/LegacyComponents/TGCameraController.m index 9dc0ceded3..340a625835 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGCameraController.m +++ b/submodules/LegacyComponents/LegacyComponents/TGCameraController.m @@ -1247,7 +1247,7 @@ static CGPoint TGCameraControllerClampPointToScreenSize(__unused id self, __unus }]; bool hasCamera = !self.inhibitMultipleCapture && ((_intent == TGCameraControllerGenericIntent && !_shortcut) || (_intent == TGCameraControllerPassportMultipleIntent)); - TGMediaPickerGalleryModel *model = [[TGMediaPickerGalleryModel alloc] initWithContext:windowContext items:galleryItems focusItem:focusItem selectionContext:_items.count > 1 ? selectionContext : nil editingContext:editingContext hasCaptions:self.allowCaptions allowCaptionEntities:self.allowCaptionEntities hasTimer:self.hasTimer onlyCrop:_intent == TGCameraControllerPassportIntent || _intent == TGCameraControllerPassportIdIntent || _intent == TGCameraControllerPassportMultipleIntent inhibitDocumentCaptions:self.inhibitDocumentCaptions hasSelectionPanel:true hasCamera:hasCamera recipientName:self.recipientName]; + TGMediaPickerGalleryModel *model = [[TGMediaPickerGalleryModel alloc] initWithContext:windowContext items:galleryItems focusItem:focusItem selectionContext:_items.count > 1 ? selectionContext : nil editingContext:editingContext hasCaptions:self.allowCaptions allowCaptionEntities:self.allowCaptionEntities hasTimer:self.hasTimer onlyCrop:_intent == TGCameraControllerPassportIntent || _intent == TGCameraControllerPassportIdIntent || _intent == TGCameraControllerPassportMultipleIntent inhibitDocumentCaptions:self.inhibitDocumentCaptions hasSelectionPanel:true hasCamera:hasCamera recipientName:self.recipientName defaultVideoPreset:self.defaultVideoPreset]; model.inhibitMute = self.inhibitMute; model.controller = galleryController; model.suggestionContext = self.suggestionContext; @@ -1651,7 +1651,7 @@ static CGPoint TGCameraControllerClampPointToScreenSize(__unused id self, __unus if (_intent == TGCameraControllerSignupAvatarIntent) { intent = TGPhotoEditorControllerSignupAvatarIntent; } - TGPhotoEditorController *controller = [[TGPhotoEditorController alloc] initWithContext:windowContext item:image intent:(TGPhotoEditorControllerFromCameraIntent | intent) adjustments:nil caption:nil screenImage:image availableTabs:[TGPhotoEditorController defaultTabsForAvatarIntent] selectedTab:TGPhotoEditorCropTab]; + TGPhotoEditorController *controller = [[TGPhotoEditorController alloc] initWithContext:windowContext item:image intent:(TGPhotoEditorControllerFromCameraIntent | intent) adjustments:nil caption:nil screenImage:image availableTabs:[TGPhotoEditorController defaultTabsForAvatarIntent] selectedTab:TGPhotoEditorCropTab defaultVideoPreset:_defaultVideoPreset]; __weak TGPhotoEditorController *weakController = controller; controller.beginTransitionIn = ^UIView *(CGRect *referenceFrame, __unused UIView **parentView) { @@ -1735,7 +1735,7 @@ static CGPoint TGCameraControllerClampPointToScreenSize(__unused id self, __unus default: { - TGCameraPhotoPreviewController *controller = _shortcut ? [[TGCameraPhotoPreviewController alloc] initWithContext:windowContext image:image metadata:metadata recipientName:self.recipientName backButtonTitle:TGLocalized(@"Camera.Retake") doneButtonTitle:TGLocalized(@"Common.Next") saveCapturedMedia:_saveCapturedMedia saveEditedPhotos:_saveEditedPhotos] : [[TGCameraPhotoPreviewController alloc] initWithContext:windowContext image:image metadata:metadata recipientName:self.recipientName saveCapturedMedia:_saveCapturedMedia saveEditedPhotos:_saveEditedPhotos]; + TGCameraPhotoPreviewController *controller = _shortcut ? [[TGCameraPhotoPreviewController alloc] initWithContext:windowContext image:image metadata:metadata recipientName:self.recipientName backButtonTitle:TGLocalized(@"Camera.Retake") doneButtonTitle:TGLocalized(@"Common.Next") saveCapturedMedia:_saveCapturedMedia saveEditedPhotos:_saveEditedPhotos defaultVideoPreset:_defaultVideoPreset] : [[TGCameraPhotoPreviewController alloc] initWithContext:windowContext image:image metadata:metadata recipientName:self.recipientName saveCapturedMedia:_saveCapturedMedia saveEditedPhotos:_saveEditedPhotos defaultVideoPreset:_defaultVideoPreset]; controller.allowCaptions = self.allowCaptions; controller.shouldStoreAssets = self.shouldStoreCapturedAssets; controller.suggestionContext = self.suggestionContext; diff --git a/submodules/LegacyComponents/LegacyComponents/TGCameraPhotoPreviewController.h b/submodules/LegacyComponents/LegacyComponents/TGCameraPhotoPreviewController.h index 19ad139c2a..8aaa1a4636 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGCameraPhotoPreviewController.h +++ b/submodules/LegacyComponents/LegacyComponents/TGCameraPhotoPreviewController.h @@ -1,5 +1,6 @@ #import #import +#import @class PGCameraShotMetadata; @class PGPhotoEditorValues; @@ -26,8 +27,8 @@ @property (nonatomic, assign) bool hasSilentPosting; @property (nonatomic, assign) bool hasSchedule; -- (instancetype)initWithContext:(id)context image:(UIImage *)image metadata:(PGCameraShotMetadata *)metadata recipientName:(NSString *)recipientName saveCapturedMedia:(bool)saveCapturedMedia saveEditedPhotos:(bool)saveEditedPhotos; -- (instancetype)initWithContext:(id)context image:(UIImage *)image metadata:(PGCameraShotMetadata *)metadata recipientName:(NSString *)recipientName backButtonTitle:(NSString *)backButtonTitle doneButtonTitle:(NSString *)doneButtonTitle saveCapturedMedia:(bool)saveCapturedMedia saveEditedPhotos:(bool)saveEditedPhotos; +- (instancetype)initWithContext:(id)context image:(UIImage *)image metadata:(PGCameraShotMetadata *)metadata recipientName:(NSString *)recipientName saveCapturedMedia:(bool)saveCapturedMedia saveEditedPhotos:(bool)saveEditedPhotos defaultVideoPreset:(TGMediaVideoConversionPreset)defaultVideoPreset; +- (instancetype)initWithContext:(id)context image:(UIImage *)image metadata:(PGCameraShotMetadata *)metadata recipientName:(NSString *)recipientName backButtonTitle:(NSString *)backButtonTitle doneButtonTitle:(NSString *)doneButtonTitle saveCapturedMedia:(bool)saveCapturedMedia saveEditedPhotos:(bool)saveEditedPhotos defaultVideoPreset:(TGMediaVideoConversionPreset)defaultVideoPreset; @end diff --git a/submodules/LegacyComponents/LegacyComponents/TGCameraPhotoPreviewController.m b/submodules/LegacyComponents/LegacyComponents/TGCameraPhotoPreviewController.m index aa650c39ee..459c80f6a5 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGCameraPhotoPreviewController.m +++ b/submodules/LegacyComponents/LegacyComponents/TGCameraPhotoPreviewController.m @@ -80,6 +80,8 @@ bool _saveEditedPhotos; id _context; + + TGMediaVideoConversionPreset _defaultVideoPreset; } @property (nonatomic, weak) TGPhotoEditorController *editorController; @@ -88,12 +90,12 @@ @implementation TGCameraPhotoPreviewController -- (instancetype)initWithContext:(id)context image:(UIImage *)image metadata:(PGCameraShotMetadata *)metadata recipientName:(NSString *)recipientName saveCapturedMedia:(bool)saveCapturedMedia saveEditedPhotos:(bool)saveEditedPhotos +- (instancetype)initWithContext:(id)context image:(UIImage *)image metadata:(PGCameraShotMetadata *)metadata recipientName:(NSString *)recipientName saveCapturedMedia:(bool)saveCapturedMedia saveEditedPhotos:(bool)saveEditedPhotos defaultVideoPreset:(TGMediaVideoConversionPreset)defaultVideoPreset { - return [self initWithContext:context image:image metadata:metadata recipientName:recipientName backButtonTitle:TGLocalized(@"Camera.Retake") doneButtonTitle:TGLocalized(@"MediaPicker.Send") saveCapturedMedia:saveCapturedMedia saveEditedPhotos:saveEditedPhotos]; + return [self initWithContext:context image:image metadata:metadata recipientName:recipientName backButtonTitle:TGLocalized(@"Camera.Retake") doneButtonTitle:TGLocalized(@"MediaPicker.Send") saveCapturedMedia:saveCapturedMedia saveEditedPhotos:saveEditedPhotos defaultVideoPreset:defaultVideoPreset]; } -- (instancetype)initWithContext:(id)context image:(UIImage *)image metadata:(PGCameraShotMetadata *)metadata recipientName:(NSString *)recipientName backButtonTitle:(NSString *)backButtonTitle doneButtonTitle:(NSString *)doneButtonTitle saveCapturedMedia:(bool)saveCapturedMedia saveEditedPhotos:(bool)saveEditedPhotos +- (instancetype)initWithContext:(id)context image:(UIImage *)image metadata:(PGCameraShotMetadata *)metadata recipientName:(NSString *)recipientName backButtonTitle:(NSString *)backButtonTitle doneButtonTitle:(NSString *)doneButtonTitle saveCapturedMedia:(bool)saveCapturedMedia saveEditedPhotos:(bool)saveEditedPhotos defaultVideoPreset:(TGMediaVideoConversionPreset)defaultVideoPreset { self = [super initWithContext:context]; if (self != nil) @@ -103,6 +105,7 @@ _metadata = metadata; _imageSize = image.size; _recipientName = recipientName; + _defaultVideoPreset = defaultVideoPreset; _editingContext = [[TGMediaEditingContext alloc] init]; @@ -884,7 +887,7 @@ PGPhotoEditorValues *editorValues = (PGPhotoEditorValues *)[_editingContext adjustmentsForItem:_image]; NSString *caption = [_editingContext captionForItem:_image]; - TGPhotoEditorController *controller = [[TGPhotoEditorController alloc] initWithContext:_context item:editableMediaItem intent:TGPhotoEditorControllerFromCameraIntent adjustments:editorValues caption:caption screenImage:screenImage availableTabs:_portraitToolbarView.currentTabs selectedTab:tab]; + TGPhotoEditorController *controller = [[TGPhotoEditorController alloc] initWithContext:_context item:editableMediaItem intent:TGPhotoEditorControllerFromCameraIntent adjustments:editorValues caption:caption screenImage:screenImage availableTabs:_portraitToolbarView.currentTabs selectedTab:tab defaultVideoPreset:_defaultVideoPreset]; controller.editingContext = _editingContext; self.editorController = controller; controller.metadata = _metadata; diff --git a/submodules/LegacyComponents/LegacyComponents/TGClipboardGalleryMixin.h b/submodules/LegacyComponents/LegacyComponents/TGClipboardGalleryMixin.h index 91029a936f..68a366f226 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGClipboardGalleryMixin.h +++ b/submodules/LegacyComponents/LegacyComponents/TGClipboardGalleryMixin.h @@ -2,6 +2,7 @@ #import #import +#import @class TGClipboardGalleryPhotoItem; @@ -19,7 +20,7 @@ @property (nonatomic, copy) void (^editorOpened)(void); @property (nonatomic, copy) void (^editorClosed)(void); -- (instancetype)initWithContext:(id)context image:(UIImage *)image images:(NSArray *)images parentController:(TGViewController *)parentController thumbnailImage:(UIImage *)thumbnailImage selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext suggestionContext:(TGSuggestionContext *)suggestionContext hasCaptions:(bool)hasCaptions hasTimer:(bool)hasTimer recipientName:(NSString *)recipientName; +- (instancetype)initWithContext:(id)context image:(UIImage *)image images:(NSArray *)images parentController:(TGViewController *)parentController thumbnailImage:(UIImage *)thumbnailImage selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext suggestionContext:(TGSuggestionContext *)suggestionContext hasCaptions:(bool)hasCaptions hasTimer:(bool)hasTimer recipientName:(NSString *)recipientName defaultVideoPreset:(TGMediaVideoConversionPreset)defaultVideoPreset; - (void)present; diff --git a/submodules/LegacyComponents/LegacyComponents/TGClipboardGalleryMixin.m b/submodules/LegacyComponents/LegacyComponents/TGClipboardGalleryMixin.m index 0e7688207a..cc49874cf6 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGClipboardGalleryMixin.m +++ b/submodules/LegacyComponents/LegacyComponents/TGClipboardGalleryMixin.m @@ -35,7 +35,7 @@ @implementation TGClipboardGalleryMixin -- (instancetype)initWithContext:(id)context image:(UIImage *)image images:(NSArray *)images parentController:(TGViewController *)parentController thumbnailImage:(UIImage *)thumbnailImage selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext suggestionContext:(TGSuggestionContext *)suggestionContext hasCaptions:(bool)hasCaptions hasTimer:(bool)hasTimer recipientName:(NSString *)recipientName +- (instancetype)initWithContext:(id)context image:(UIImage *)image images:(NSArray *)images parentController:(TGViewController *)parentController thumbnailImage:(UIImage *)thumbnailImage selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext suggestionContext:(TGSuggestionContext *)suggestionContext hasCaptions:(bool)hasCaptions hasTimer:(bool)hasTimer recipientName:(NSString *)recipientName defaultVideoPreset:(TGMediaVideoConversionPreset)defaultVideoPreset { self = [super init]; if (self != nil) @@ -61,7 +61,7 @@ } }]; - TGClipboardGalleryModel *model = [[TGClipboardGalleryModel alloc] initWithContext:_context images:images focusIndex:focusIndex selectionContext:selectionContext editingContext:editingContext hasCaptions:hasCaptions hasTimer:hasTimer hasSelectionPanel:false recipientName:recipientName]; + TGClipboardGalleryModel *model = [[TGClipboardGalleryModel alloc] initWithContext:_context images:images focusIndex:focusIndex selectionContext:selectionContext editingContext:editingContext hasCaptions:hasCaptions hasTimer:hasTimer hasSelectionPanel:false recipientName:recipientName defaultVideoPreset:defaultVideoPreset]; _galleryModel = model; model.controller = modernGallery; model.suggestionContext = suggestionContext; diff --git a/submodules/LegacyComponents/LegacyComponents/TGClipboardGalleryModel.h b/submodules/LegacyComponents/LegacyComponents/TGClipboardGalleryModel.h index f2a5356d91..68a8809fc6 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGClipboardGalleryModel.h +++ b/submodules/LegacyComponents/LegacyComponents/TGClipboardGalleryModel.h @@ -6,6 +6,7 @@ #import #import +#import @interface TGClipboardGalleryModel : TGModernGalleryModel @@ -26,6 +27,6 @@ @property (nonatomic, readonly) TGMediaSelectionContext *selectionContext; @property (nonatomic, strong) TGSuggestionContext *suggestionContext; -- (instancetype)initWithContext:(id)context images:(NSArray *)images focusIndex:(NSUInteger)focusIndex selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext hasCaptions:(bool)hasCaptions hasTimer:(bool)hasTimer hasSelectionPanel:(bool)hasSelectionPanel recipientName:(NSString *)recipientName; +- (instancetype)initWithContext:(id)context images:(NSArray *)images focusIndex:(NSUInteger)focusIndex selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext hasCaptions:(bool)hasCaptions hasTimer:(bool)hasTimer hasSelectionPanel:(bool)hasSelectionPanel recipientName:(NSString *)recipientName defaultVideoPreset:(TGMediaVideoConversionPreset)defaultVideoPreset; @end diff --git a/submodules/LegacyComponents/LegacyComponents/TGClipboardGalleryModel.m b/submodules/LegacyComponents/LegacyComponents/TGClipboardGalleryModel.m index 32761d6193..df1b4eb441 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGClipboardGalleryModel.m +++ b/submodules/LegacyComponents/LegacyComponents/TGClipboardGalleryModel.m @@ -26,6 +26,7 @@ TGMediaEditingContext *_editingContext; id _context; + TGMediaVideoConversionPreset _defaultVideoPreset; } @property (nonatomic, weak) TGPhotoEditorController *editorController; @@ -34,12 +35,13 @@ @implementation TGClipboardGalleryModel -- (instancetype)initWithContext:(id)context images:(NSArray *)images focusIndex:(NSUInteger)focusIndex selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext hasCaptions:(bool)hasCaptions hasTimer:(bool)hasTimer hasSelectionPanel:(bool)hasSelectionPanel recipientName:(NSString *)recipientName +- (instancetype)initWithContext:(id)context images:(NSArray *)images focusIndex:(NSUInteger)focusIndex selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext hasCaptions:(bool)hasCaptions hasTimer:(bool)hasTimer hasSelectionPanel:(bool)hasSelectionPanel recipientName:(NSString *)recipientName defaultVideoPreset:(TGMediaVideoConversionPreset)defaultVideoPreset { self = [super init]; if (self != nil) { _context = context; + _defaultVideoPreset = defaultVideoPreset; NSMutableArray *items = [[NSMutableArray alloc] init]; TGClipboardGalleryPhotoItem *focusItem = nil; @@ -77,7 +79,7 @@ }; } - _interfaceView = [[TGMediaPickerGalleryInterfaceView alloc] initWithContext:_context focusItem:focusItem selectionContext:selectionContext editingContext:editingContext hasSelectionPanel:hasSelectionPanel hasCameraButton:false recipientName:recipientName]; + _interfaceView = [[TGMediaPickerGalleryInterfaceView alloc] initWithContext:_context focusItem:focusItem selectionContext:selectionContext editingContext:editingContext hasSelectionPanel:hasSelectionPanel hasCameraButton:false recipientName:recipientName defaultVideoPreset:defaultVideoPreset]; _interfaceView.hasCaptions = hasCaptions; _interfaceView.hasTimer = hasTimer; [_interfaceView setEditorTabPressed:^(TGPhotoEditorTab tab) @@ -320,7 +322,7 @@ } TGPhotoEditorControllerIntent intent = isVideo ? TGPhotoEditorControllerVideoIntent : TGPhotoEditorControllerGenericIntent; - TGPhotoEditorController *controller = [[TGPhotoEditorController alloc] initWithContext:_context item:item.editableMediaItem intent:intent adjustments:editorValues caption:caption screenImage:screenImage availableTabs:_interfaceView.currentTabs selectedTab:tab]; + TGPhotoEditorController *controller = [[TGPhotoEditorController alloc] initWithContext:_context item:item.editableMediaItem intent:intent adjustments:editorValues caption:caption screenImage:screenImage availableTabs:_interfaceView.currentTabs selectedTab:tab defaultVideoPreset:_defaultVideoPreset]; controller.editingContext = _editingContext; self.editorController = controller; controller.suggestionContext = self.suggestionContext; diff --git a/submodules/LegacyComponents/LegacyComponents/TGClipboardMenu.h b/submodules/LegacyComponents/LegacyComponents/TGClipboardMenu.h index 3fa226683c..d7fa71c3bb 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGClipboardMenu.h +++ b/submodules/LegacyComponents/LegacyComponents/TGClipboardMenu.h @@ -1,6 +1,7 @@ #import #import +#import @class TGViewController; @class TGMenuSheetController; @@ -12,7 +13,7 @@ @interface TGClipboardMenu : NSObject -+ (TGMenuSheetController *)presentInParentController:(TGViewController *)parentController context:(id)context images:(NSArray *)images hasCaption:(bool)hasCaption hasTimer:(bool)hasTimer recipientName:(NSString *)recipientName completed:(void (^)(TGMediaSelectionContext *selectionContext, TGMediaEditingContext *editingContext, id currentItem))completed dismissed:(void (^)(void))dismissed sourceView:(UIView *)sourceView sourceRect:(CGRect (^)(void))sourceRect; ++ (TGMenuSheetController *)presentInParentController:(TGViewController *)parentController context:(id)context images:(NSArray *)images hasCaption:(bool)hasCaption hasTimer:(bool)hasTimer recipientName:(NSString *)recipientName defaultVideoPreset:(TGMediaVideoConversionPreset)defaultVideoPreset completed:(void (^)(TGMediaSelectionContext *selectionContext, TGMediaEditingContext *editingContext, id currentItem))completed dismissed:(void (^)(void))dismissed sourceView:(UIView *)sourceView sourceRect:(CGRect (^)(void))sourceRect; + (NSArray *)resultSignalsForSelectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext currentItem:(id)currentItem descriptionGenerator:(id (^)(id, NSString *, NSArray *, NSString *))descriptionGenerator; diff --git a/submodules/LegacyComponents/LegacyComponents/TGClipboardMenu.m b/submodules/LegacyComponents/LegacyComponents/TGClipboardMenu.m index 7a3b0c3169..eeae1b04e7 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGClipboardMenu.m +++ b/submodules/LegacyComponents/LegacyComponents/TGClipboardMenu.m @@ -9,7 +9,7 @@ @implementation TGClipboardMenu -+ (TGMenuSheetController *)presentInParentController:(TGViewController *)parentController context:(id)context images:(NSArray *)images hasCaption:(bool)hasCaption hasTimer:(bool)hasTimer recipientName:(NSString *)recipientName completed:(void (^)(TGMediaSelectionContext *selectionContext, TGMediaEditingContext *editingContext, id currentItem))completed dismissed:(void (^)(void))dismissed sourceView:(UIView *)sourceView sourceRect:(CGRect (^)(void))sourceRect ++ (TGMenuSheetController *)presentInParentController:(TGViewController *)parentController context:(id)context images:(NSArray *)images hasCaption:(bool)hasCaption hasTimer:(bool)hasTimer recipientName:(NSString *)recipientName defaultVideoPreset:(TGMediaVideoConversionPreset)defaultVideoPreset completed:(void (^)(TGMediaSelectionContext *selectionContext, TGMediaEditingContext *editingContext, id currentItem))completed dismissed:(void (^)(void))dismissed sourceView:(UIView *)sourceView sourceRect:(CGRect (^)(void))sourceRect { bool centered = false; if (sourceRect == nil) @@ -46,6 +46,7 @@ previewItem.allowCaptions = hasCaption; previewItem.hasTimer = hasTimer; previewItem.recipientName = recipientName; + previewItem.defaultVideoPreset = defaultVideoPreset; previewItem.sendPressed = ^(UIImage *currentItem) { __strong TGClipboardPreviewItemView *strongPreviewItem = weakPreviewItem; diff --git a/submodules/LegacyComponents/LegacyComponents/TGClipboardPreviewItemView.h b/submodules/LegacyComponents/LegacyComponents/TGClipboardPreviewItemView.h index 1283089e83..c40305a54d 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGClipboardPreviewItemView.h +++ b/submodules/LegacyComponents/LegacyComponents/TGClipboardPreviewItemView.h @@ -11,6 +11,7 @@ @property (nonatomic, assign) bool allowCaptions; @property (nonatomic, assign) bool hasTimer; @property (nonatomic, strong) NSString *recipientName; +@property (nonatomic, assign) TGMediaVideoConversionPreset defaultVideoPreset; @property (nonatomic, readonly) TGMediaSelectionContext *selectionContext; @property (nonatomic, readonly) TGMediaEditingContext *editingContext; diff --git a/submodules/LegacyComponents/LegacyComponents/TGClipboardPreviewItemView.m b/submodules/LegacyComponents/LegacyComponents/TGClipboardPreviewItemView.m index 8d05d42cb2..e888889272 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGClipboardPreviewItemView.m +++ b/submodules/LegacyComponents/LegacyComponents/TGClipboardPreviewItemView.m @@ -266,7 +266,7 @@ const CGFloat TGClipboardPreviewEdgeInset = 8.0f; if ([cell isKindOfClass:[TGClipboardPreviewCell class]]) thumbnailImage = cell.imageView.image; - TGClipboardGalleryMixin *mixin = [[TGClipboardGalleryMixin alloc] initWithContext:_context image:image images:_images parentController:self.parentController thumbnailImage:thumbnailImage selectionContext:_selectionContext editingContext:_editingContext suggestionContext:self.suggestionContext hasCaptions:self.allowCaptions hasTimer:self.hasTimer recipientName:self.recipientName]; + TGClipboardGalleryMixin *mixin = [[TGClipboardGalleryMixin alloc] initWithContext:_context image:image images:_images parentController:self.parentController thumbnailImage:thumbnailImage selectionContext:_selectionContext editingContext:_editingContext suggestionContext:self.suggestionContext hasCaptions:self.allowCaptions hasTimer:self.hasTimer recipientName:self.recipientName defaultVideoPreset:self.defaultVideoPreset]; [self _setupGalleryMixin:mixin]; diff --git a/submodules/LegacyComponents/LegacyComponents/TGMediaAssetsController.h b/submodules/LegacyComponents/LegacyComponents/TGMediaAssetsController.h index 348bab118a..da0a4f2cad 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGMediaAssetsController.h +++ b/submodules/LegacyComponents/LegacyComponents/TGMediaAssetsController.h @@ -6,6 +6,8 @@ #import +#import + @class TGMediaAssetsPickerController; @class TGViewController; @@ -91,8 +93,8 @@ typedef enum - (void)dismiss; -+ (instancetype)controllerWithContext:(id)context assetGroup:(TGMediaAssetGroup *)assetGroup intent:(TGMediaAssetsControllerIntent)intent recipientName:(NSString *)recipientName saveEditedPhotos:(bool)saveEditedPhotos allowGrouping:(bool)allowGrouping selectionLimit:(int)selectionLimit; -+ (instancetype)controllerWithContext:(id)context assetGroup:(TGMediaAssetGroup *)assetGroup intent:(TGMediaAssetsControllerIntent)intent recipientName:(NSString *)recipientName saveEditedPhotos:(bool)saveEditedPhotos allowGrouping:(bool)allowGrouping inhibitSelection:(bool)inhibitSelection selectionLimit:(int)selectionLimit; ++ (instancetype)controllerWithContext:(id)context assetGroup:(TGMediaAssetGroup *)assetGroup intent:(TGMediaAssetsControllerIntent)intent recipientName:(NSString *)recipientName defaultVideoPreset:(TGMediaVideoConversionPreset)defaultVideoPreset saveEditedPhotos:(bool)saveEditedPhotos allowGrouping:(bool)allowGrouping selectionLimit:(int)selectionLimit; ++ (instancetype)controllerWithContext:(id)context assetGroup:(TGMediaAssetGroup *)assetGroup intent:(TGMediaAssetsControllerIntent)intent recipientName:(NSString *)recipientName defaultVideoPreset:(TGMediaVideoConversionPreset)defaultVideoPreset saveEditedPhotos:(bool)saveEditedPhotos allowGrouping:(bool)allowGrouping inhibitSelection:(bool)inhibitSelection selectionLimit:(int)selectionLimit; + (TGMediaAssetType)assetTypeForIntent:(TGMediaAssetsControllerIntent)intent; diff --git a/submodules/LegacyComponents/LegacyComponents/TGMediaAssetsController.m b/submodules/LegacyComponents/LegacyComponents/TGMediaAssetsController.m index 8c6fd58736..12b5bad676 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGMediaAssetsController.m +++ b/submodules/LegacyComponents/LegacyComponents/TGMediaAssetsController.m @@ -58,12 +58,12 @@ @implementation TGMediaAssetsController -+ (instancetype)controllerWithContext:(id)context assetGroup:(TGMediaAssetGroup *)assetGroup intent:(TGMediaAssetsControllerIntent)intent recipientName:(NSString *)recipientName saveEditedPhotos:(bool)saveEditedPhotos allowGrouping:(bool)allowGrouping selectionLimit:(int)selectionLimit ++ (instancetype)controllerWithContext:(id)context assetGroup:(TGMediaAssetGroup *)assetGroup intent:(TGMediaAssetsControllerIntent)intent recipientName:(NSString *)recipientName defaultVideoPreset:(TGMediaVideoConversionPreset)defaultVideoPreset saveEditedPhotos:(bool)saveEditedPhotos allowGrouping:(bool)allowGrouping selectionLimit:(int)selectionLimit { - return [self controllerWithContext:context assetGroup:assetGroup intent:intent recipientName:recipientName saveEditedPhotos:saveEditedPhotos allowGrouping:allowGrouping inhibitSelection:false selectionLimit:selectionLimit]; + return [self controllerWithContext:context assetGroup:assetGroup intent:intent recipientName:recipientName defaultVideoPreset:defaultVideoPreset saveEditedPhotos:saveEditedPhotos allowGrouping:allowGrouping inhibitSelection:false selectionLimit:selectionLimit]; } -+ (instancetype)controllerWithContext:(id)context assetGroup:(TGMediaAssetGroup *)assetGroup intent:(TGMediaAssetsControllerIntent)intent recipientName:(NSString *)recipientName saveEditedPhotos:(bool)saveEditedPhotos allowGrouping:(bool)allowGrouping inhibitSelection:(bool)inhibitSelection selectionLimit:(int)selectionLimit ++ (instancetype)controllerWithContext:(id)context assetGroup:(TGMediaAssetGroup *)assetGroup intent:(TGMediaAssetsControllerIntent)intent recipientName:(NSString *)recipientName defaultVideoPreset:(TGMediaVideoConversionPreset)defaultVideoPreset saveEditedPhotos:(bool)saveEditedPhotos allowGrouping:(bool)allowGrouping inhibitSelection:(bool)inhibitSelection selectionLimit:(int)selectionLimit { if (intent != TGMediaAssetsControllerSendMediaIntent) allowGrouping = false; @@ -106,7 +106,7 @@ if ([group isKindOfClass:[TGMediaAssetGroup class]]) { - pickerController = [[TGMediaAssetsPickerController alloc] initWithContext:strongController->_context assetsLibrary:strongController.assetsLibrary assetGroup:group intent:intent selectionContext:inhibitSelection ? nil : strongController->_selectionContext editingContext:strongController->_editingContext saveEditedPhotos:strongController->_saveEditedPhotos]; + pickerController = [[TGMediaAssetsPickerController alloc] initWithContext:strongController->_context assetsLibrary:strongController.assetsLibrary assetGroup:group intent:intent selectionContext:inhibitSelection ? nil : strongController->_selectionContext editingContext:strongController->_editingContext saveEditedPhotos:strongController->_saveEditedPhotos defaultVideoPreset:defaultVideoPreset]; pickerController.pallete = strongController.pallete; } pickerController.suggestionContext = strongController.suggestionContext; @@ -118,6 +118,7 @@ pickerController.liveVideoUploadEnabled = strongController.liveVideoUploadEnabled; pickerController.catchToolbarView = catchToolbarView; pickerController.recipientName = recipientName; + pickerController.defaultVideoPreset = defaultVideoPreset; pickerController.hasTimer = strongController.hasTimer; pickerController.onlyCrop = strongController.onlyCrop; pickerController.hasSilentPosting = strongController.hasSilentPosting; @@ -128,7 +129,7 @@ }; [groupsController loadViewIfNeeded]; - TGMediaAssetsPickerController *pickerController = [[TGMediaAssetsPickerController alloc] initWithContext:context assetsLibrary:assetsController.assetsLibrary assetGroup:assetGroup intent:intent selectionContext:inhibitSelection ? nil : assetsController->_selectionContext editingContext:assetsController->_editingContext saveEditedPhotos:saveEditedPhotos]; + TGMediaAssetsPickerController *pickerController = [[TGMediaAssetsPickerController alloc] initWithContext:context assetsLibrary:assetsController.assetsLibrary assetGroup:assetGroup intent:intent selectionContext:inhibitSelection ? nil : assetsController->_selectionContext editingContext:assetsController->_editingContext saveEditedPhotos:saveEditedPhotos defaultVideoPreset:defaultVideoPreset]; pickerController.pallete = assetsController.pallete; pickerController.catchToolbarView = catchToolbarView; diff --git a/submodules/LegacyComponents/LegacyComponents/TGMediaAssetsPickerController.h b/submodules/LegacyComponents/LegacyComponents/TGMediaAssetsPickerController.h index 6933723a00..0834e8793c 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGMediaAssetsPickerController.h +++ b/submodules/LegacyComponents/LegacyComponents/TGMediaAssetsPickerController.h @@ -1,6 +1,7 @@ #import #import #import +#import @class TGMediaAssetsPreheatMixin; @class TGMediaPickerModernGalleryMixin; @@ -14,6 +15,6 @@ @property (nonatomic, assign) bool liveVideoUploadEnabled; @property (nonatomic, readonly) TGMediaAssetGroup *assetGroup; -- (instancetype)initWithContext:(id)context assetsLibrary:(TGMediaAssetsLibrary *)assetsLibrary assetGroup:(TGMediaAssetGroup *)assetGroup intent:(TGMediaAssetsControllerIntent)intent selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext saveEditedPhotos:(bool)saveEditedPhotos; +- (instancetype)initWithContext:(id)context assetsLibrary:(TGMediaAssetsLibrary *)assetsLibrary assetGroup:(TGMediaAssetGroup *)assetGroup intent:(TGMediaAssetsControllerIntent)intent selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext saveEditedPhotos:(bool)saveEditedPhotos defaultVideoPreset:(TGMediaVideoConversionPreset)defaultVideoPreset; @end diff --git a/submodules/LegacyComponents/LegacyComponents/TGMediaAssetsPickerController.m b/submodules/LegacyComponents/LegacyComponents/TGMediaAssetsPickerController.m index 965c013b24..9b71a6fb5c 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGMediaAssetsPickerController.m +++ b/submodules/LegacyComponents/LegacyComponents/TGMediaAssetsPickerController.m @@ -46,13 +46,15 @@ id _context; bool _saveEditedPhotos; + + TGMediaVideoConversionPreset _defaultVideoPreset; } @end @implementation TGMediaAssetsPickerController -- (instancetype)initWithContext:(id)context assetsLibrary:(TGMediaAssetsLibrary *)assetsLibrary assetGroup:(TGMediaAssetGroup *)assetGroup intent:(TGMediaAssetsControllerIntent)intent selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext saveEditedPhotos:(bool)saveEditedPhotos +- (instancetype)initWithContext:(id)context assetsLibrary:(TGMediaAssetsLibrary *)assetsLibrary assetGroup:(TGMediaAssetGroup *)assetGroup intent:(TGMediaAssetsControllerIntent)intent selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext saveEditedPhotos:(bool)saveEditedPhotos defaultVideoPreset:(TGMediaVideoConversionPreset)defaultVideoPreset { bool hasSelection = false; bool hasEditing = false; @@ -88,6 +90,7 @@ _assetsLibrary = assetsLibrary; _assetGroup = assetGroup; _intent = intent; + _defaultVideoPreset = defaultVideoPreset; [self setTitle:_assetGroup.title]; @@ -323,7 +326,7 @@ - (TGMediaPickerModernGalleryMixin *)_galleryMixinForContext:(id)context item:(id)item thumbnailImage:(UIImage *)thumbnailImage selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext suggestionContext:(TGSuggestionContext *)suggestionContext hasCaptions:(bool)hasCaptions allowCaptionEntities:(bool)allowCaptionEntities inhibitDocumentCaptions:(bool)inhibitDocumentCaptions asFile:(bool)asFile { - return [[TGMediaPickerModernGalleryMixin alloc] initWithContext:context item:item fetchResult:_fetchResult parentController:self thumbnailImage:thumbnailImage selectionContext:selectionContext editingContext:editingContext suggestionContext:suggestionContext hasCaptions:hasCaptions allowCaptionEntities:allowCaptionEntities hasTimer:self.hasTimer onlyCrop:self.onlyCrop inhibitDocumentCaptions:inhibitDocumentCaptions inhibitMute:self.inhibitMute asFile:asFile itemsLimit:0 recipientName:self.recipientName hasSilentPosting:self.hasSilentPosting hasSchedule:self.hasSchedule reminder:self.reminder]; + return [[TGMediaPickerModernGalleryMixin alloc] initWithContext:context item:item fetchResult:_fetchResult parentController:self thumbnailImage:thumbnailImage selectionContext:selectionContext editingContext:editingContext suggestionContext:suggestionContext hasCaptions:hasCaptions allowCaptionEntities:allowCaptionEntities hasTimer:self.hasTimer onlyCrop:self.onlyCrop inhibitDocumentCaptions:inhibitDocumentCaptions inhibitMute:self.inhibitMute asFile:asFile itemsLimit:0 recipientName:self.recipientName defaultVideoPreset:self.defaultVideoPreset hasSilentPosting:self.hasSilentPosting hasSchedule:self.hasSchedule reminder:self.reminder]; } - (TGMediaPickerModernGalleryMixin *)galleryMixinForIndexPath:(NSIndexPath *)indexPath previewMode:(bool)previewMode outAsset:(TGMediaAsset **)outAsset @@ -395,7 +398,7 @@ if (_intent == TGMediaAssetsControllerSetSignupProfilePhotoIntent) { intent = TGPhotoEditorControllerSignupAvatarIntent; } - TGPhotoEditorController *controller = [[TGPhotoEditorController alloc] initWithContext:_context item:asset intent:intent adjustments:nil caption:nil screenImage:thumbnailImage availableTabs:[TGPhotoEditorController defaultTabsForAvatarIntent] selectedTab:TGPhotoEditorCropTab]; + TGPhotoEditorController *controller = [[TGPhotoEditorController alloc] initWithContext:_context item:asset intent:intent adjustments:nil caption:nil screenImage:thumbnailImage availableTabs:[TGPhotoEditorController defaultTabsForAvatarIntent] selectedTab:TGPhotoEditorCropTab defaultVideoPreset:_defaultVideoPreset]; controller.editingContext = self.editingContext; controller.didFinishRenderingFullSizeImage = ^(UIImage *resultImage) { diff --git a/submodules/LegacyComponents/LegacyComponents/TGMediaAvatarMenuMixin.m b/submodules/LegacyComponents/LegacyComponents/TGMediaAvatarMenuMixin.m index ed292c996e..98cf3c2ec2 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGMediaAvatarMenuMixin.m +++ b/submodules/LegacyComponents/LegacyComponents/TGMediaAvatarMenuMixin.m @@ -445,7 +445,7 @@ if (strongSelf == nil) return nil; - TGMediaAssetsController *controller = [TGMediaAssetsController controllerWithContext:context assetGroup:group intent:strongSelf->_signup ? TGMediaAssetsControllerSetSignupProfilePhotoIntent : TGMediaAssetsControllerSetProfilePhotoIntent recipientName:nil saveEditedPhotos:strongSelf->_saveEditedPhotos allowGrouping:false selectionLimit:10]; + TGMediaAssetsController *controller = [TGMediaAssetsController controllerWithContext:context assetGroup:group intent:strongSelf->_signup ? TGMediaAssetsControllerSetSignupProfilePhotoIntent : TGMediaAssetsControllerSetProfilePhotoIntent recipientName:nil defaultVideoPreset:TGMediaVideoConversionPresetCompressedDefault saveEditedPhotos:strongSelf->_saveEditedPhotos allowGrouping:false selectionLimit:10]; __weak TGMediaAssetsController *weakController = controller; controller.avatarCompletionBlock = ^(UIImage *resultImage) { diff --git a/submodules/LegacyComponents/LegacyComponents/TGMediaPickerController.h b/submodules/LegacyComponents/LegacyComponents/TGMediaPickerController.h index 8cd104554b..5351e3fd2d 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGMediaPickerController.h +++ b/submodules/LegacyComponents/LegacyComponents/TGMediaPickerController.h @@ -2,6 +2,8 @@ #import +#import + @class TGMediaPickerLayoutMetrics; @class TGMediaSelectionContext; @class TGMediaEditingContext; @@ -27,6 +29,7 @@ @property (nonatomic, assign) bool onlyCrop; @property (nonatomic, assign) bool inhibitMute; @property (nonatomic, strong) NSString *recipientName; +@property (nonatomic, assign) TGMediaVideoConversionPreset defaultVideoPreset; @property (nonatomic, assign) bool hasSilentPosting; @property (nonatomic, assign) bool hasSchedule; @property (nonatomic, assign) bool reminder; diff --git a/submodules/LegacyComponents/LegacyComponents/TGMediaPickerController.m b/submodules/LegacyComponents/LegacyComponents/TGMediaPickerController.m index de1ef07824..ee45ef34fe 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGMediaPickerController.m +++ b/submodules/LegacyComponents/LegacyComponents/TGMediaPickerController.m @@ -36,6 +36,7 @@ { _selectionContext = selectionContext; _editingContext = editingContext; + _defaultVideoPreset = TGMediaVideoConversionPresetCompressedDefault; } return self; } diff --git a/submodules/LegacyComponents/LegacyComponents/TGMediaPickerGalleryInterfaceView.h b/submodules/LegacyComponents/LegacyComponents/TGMediaPickerGalleryInterfaceView.h index 062b5e8e0e..405a5d519e 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGMediaPickerGalleryInterfaceView.h +++ b/submodules/LegacyComponents/LegacyComponents/TGMediaPickerGalleryInterfaceView.h @@ -4,6 +4,7 @@ #import #import +#import @class TGMediaSelectionContext; @class TGMediaEditingContext; @@ -37,7 +38,7 @@ @property (nonatomic, readonly) UIView *timerButton; -- (instancetype)initWithContext:(id)context focusItem:(id)focusItem selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext hasSelectionPanel:(bool)hasSelectionPanel hasCameraButton:(bool)hasCameraButton recipientName:(NSString *)recipientName; +- (instancetype)initWithContext:(id)context focusItem:(id)focusItem selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext hasSelectionPanel:(bool)hasSelectionPanel hasCameraButton:(bool)hasCameraButton recipientName:(NSString *)recipientName defaultVideoPreset:(TGMediaVideoConversionPreset)defaultVideoPreset; - (void)setSelectedItemsModel:(TGMediaPickerGallerySelectedItemsModel *)selectedItemsModel; - (void)setEditorTabPressed:(void (^)(TGPhotoEditorTab tab))editorTabPressed; diff --git a/submodules/LegacyComponents/LegacyComponents/TGMediaPickerGalleryInterfaceView.m b/submodules/LegacyComponents/LegacyComponents/TGMediaPickerGalleryInterfaceView.m index 7bcdea25b5..6512cca1f2 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGMediaPickerGalleryInterfaceView.m +++ b/submodules/LegacyComponents/LegacyComponents/TGMediaPickerGalleryInterfaceView.m @@ -92,6 +92,8 @@ id _context; bool _ignoreSelectionUpdates; + + TGMediaVideoConversionPreset _defaultVideoPreset; } @property (nonatomic, strong) ASHandle *actionHandle; @@ -103,7 +105,7 @@ @synthesize safeAreaInset = _safeAreaInset; -- (instancetype)initWithContext:(id)context focusItem:(id)focusItem selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext hasSelectionPanel:(bool)hasSelectionPanel hasCameraButton:(bool)hasCameraButton recipientName:(NSString *)recipientName +- (instancetype)initWithContext:(id)context focusItem:(id)focusItem selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext hasSelectionPanel:(bool)hasSelectionPanel hasCameraButton:(bool)hasCameraButton recipientName:(NSString *)recipientName defaultVideoPreset:(TGMediaVideoConversionPreset)defaultVideoPreset { self = [super initWithFrame:CGRectZero]; if (self != nil) @@ -116,6 +118,8 @@ _hasSwipeGesture = true; + _defaultVideoPreset = defaultVideoPreset; + _itemHeaderViews = [[NSMutableArray alloc] init]; _itemFooterViews = [[NSMutableArray alloc] init]; @@ -850,11 +854,7 @@ } else { - NSNumber *presetValue = [[NSUserDefaults standardUserDefaults] objectForKey:@"TG_preferredVideoPreset_v0"]; - if (presetValue != nil) - preset = (TGMediaVideoConversionPreset)[presetValue integerValue]; - else - preset = TGMediaVideoConversionPresetCompressedMedium; + preset = _defaultVideoPreset; } TGMediaVideoConversionPreset bestPreset = [TGMediaVideoConverter bestAvailablePresetForDimensions:dimensions]; diff --git a/submodules/LegacyComponents/LegacyComponents/TGMediaPickerGalleryModel.h b/submodules/LegacyComponents/LegacyComponents/TGMediaPickerGalleryModel.h index 40d8da8921..565fdf7b56 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGMediaPickerGalleryModel.h +++ b/submodules/LegacyComponents/LegacyComponents/TGMediaPickerGalleryModel.h @@ -7,6 +7,7 @@ #import #import +#import @class TGModernGalleryController; @class TGMediaPickerGallerySelectedItemsModel; @@ -45,6 +46,6 @@ @property (nonatomic, readonly) TGMediaSelectionContext *selectionContext; @property (nonatomic, strong) TGSuggestionContext *suggestionContext; -- (instancetype)initWithContext:(id)context items:(NSArray *)items focusItem:(id)focusItem selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext hasCaptions:(bool)hasCaptions allowCaptionEntities:(bool)allowCaptionEntities hasTimer:(bool)hasTimer onlyCrop:(bool)onlyCrop inhibitDocumentCaptions:(bool)inhibitDocumentCaptions hasSelectionPanel:(bool)hasSelectionPanel hasCamera:(bool)hasCamera recipientName:(NSString *)recipientName; +- (instancetype)initWithContext:(id)context items:(NSArray *)items focusItem:(id)focusItem selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext hasCaptions:(bool)hasCaptions allowCaptionEntities:(bool)allowCaptionEntities hasTimer:(bool)hasTimer onlyCrop:(bool)onlyCrop inhibitDocumentCaptions:(bool)inhibitDocumentCaptions hasSelectionPanel:(bool)hasSelectionPanel hasCamera:(bool)hasCamera recipientName:(NSString *)recipientName defaultVideoPreset:(TGMediaVideoConversionPreset)defaultVideoPreset; @end diff --git a/submodules/LegacyComponents/LegacyComponents/TGMediaPickerGalleryModel.m b/submodules/LegacyComponents/LegacyComponents/TGMediaPickerGalleryModel.m index 445e471e2d..6d8de38086 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGMediaPickerGalleryModel.m +++ b/submodules/LegacyComponents/LegacyComponents/TGMediaPickerGalleryModel.m @@ -38,6 +38,7 @@ bool _inhibitDocumentCaptions; NSString *_recipientName; bool _hasCamera; + TGMediaVideoConversionPreset _defaultVideoPreset; } @property (nonatomic, weak) TGPhotoEditorController *editorController; @@ -46,7 +47,7 @@ @implementation TGMediaPickerGalleryModel -- (instancetype)initWithContext:(id)context items:(NSArray *)items focusItem:(id)focusItem selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext hasCaptions:(bool)hasCaptions allowCaptionEntities:(bool)allowCaptionEntities hasTimer:(bool)hasTimer onlyCrop:(bool)onlyCrop inhibitDocumentCaptions:(bool)inhibitDocumentCaptions hasSelectionPanel:(bool)hasSelectionPanel hasCamera:(bool)hasCamera recipientName:(NSString *)recipientName +- (instancetype)initWithContext:(id)context items:(NSArray *)items focusItem:(id)focusItem selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext hasCaptions:(bool)hasCaptions allowCaptionEntities:(bool)allowCaptionEntities hasTimer:(bool)hasTimer onlyCrop:(bool)onlyCrop inhibitDocumentCaptions:(bool)inhibitDocumentCaptions hasSelectionPanel:(bool)hasSelectionPanel hasCamera:(bool)hasCamera recipientName:(NSString *)recipientName defaultVideoPreset:(TGMediaVideoConversionPreset)defaultVideoPreset { self = [super init]; if (self != nil) @@ -66,6 +67,7 @@ _hasSelectionPanel = hasSelectionPanel; _inhibitDocumentCaptions = inhibitDocumentCaptions; _recipientName = recipientName; + _defaultVideoPreset = defaultVideoPreset; _hasCamera = hasCamera; __weak TGMediaPickerGalleryModel *weakSelf = self; @@ -182,7 +184,7 @@ if (_interfaceView == nil) { __weak TGMediaPickerGalleryModel *weakSelf = self; - _interfaceView = [[TGMediaPickerGalleryInterfaceView alloc] initWithContext:_context focusItem:_initialFocusItem selectionContext:_selectionContext editingContext:_editingContext hasSelectionPanel:_hasSelectionPanel hasCameraButton:_hasCamera recipientName:_recipientName]; + _interfaceView = [[TGMediaPickerGalleryInterfaceView alloc] initWithContext:_context focusItem:_initialFocusItem selectionContext:_selectionContext editingContext:_editingContext hasSelectionPanel:_hasSelectionPanel hasCameraButton:_hasCamera recipientName:_recipientName defaultVideoPreset:_defaultVideoPreset]; [_interfaceView setSuggestionContext:_suggestionContext]; _interfaceView.hasCaptions = _hasCaptions; _interfaceView.allowCaptionEntities = _allowCaptionEntities; @@ -385,7 +387,7 @@ self.storeOriginalImageForItem(item.editableMediaItem, screenImage); TGPhotoEditorControllerIntent intent = isVideo ? TGPhotoEditorControllerVideoIntent : TGPhotoEditorControllerGenericIntent; - TGPhotoEditorController *controller = [[TGPhotoEditorController alloc] initWithContext:_context item:item.editableMediaItem intent:intent adjustments:editorValues caption:caption screenImage:screenImage availableTabs:_interfaceView.currentTabs selectedTab:tab]; + TGPhotoEditorController *controller = [[TGPhotoEditorController alloc] initWithContext:_context item:item.editableMediaItem intent:intent adjustments:editorValues caption:caption screenImage:screenImage availableTabs:_interfaceView.currentTabs selectedTab:tab defaultVideoPreset:_defaultVideoPreset]; controller.editingContext = _editingContext; self.editorController = controller; controller.suggestionContext = self.suggestionContext; diff --git a/submodules/LegacyComponents/LegacyComponents/TGMediaPickerModernGalleryMixin.h b/submodules/LegacyComponents/LegacyComponents/TGMediaPickerModernGalleryMixin.h index f35fd05706..cef013441f 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGMediaPickerModernGalleryMixin.h +++ b/submodules/LegacyComponents/LegacyComponents/TGMediaPickerModernGalleryMixin.h @@ -29,9 +29,9 @@ @property (nonatomic, copy) void (^presentScheduleController)(void (^)(int32_t)); -- (instancetype)initWithContext:(id)context item:(id)item fetchResult:(TGMediaAssetFetchResult *)fetchResult parentController:(TGViewController *)parentController thumbnailImage:(UIImage *)thumbnailImage selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext suggestionContext:(TGSuggestionContext *)suggestionContext hasCaptions:(bool)hasCaptions allowCaptionEntities:(bool)allowCaptionEntities hasTimer:(bool)hasTimer onlyCrop:(bool)onlyCrop inhibitDocumentCaptions:(bool)inhibitDocumentCaptions inhibitMute:(bool)inhibitMute asFile:(bool)asFile itemsLimit:(NSUInteger)itemsLimit recipientName:(NSString *)recipientName hasSilentPosting:(bool)hasSilentPosting hasSchedule:(bool)hasSchedule reminder:(bool)reminder; +- (instancetype)initWithContext:(id)context item:(id)item fetchResult:(TGMediaAssetFetchResult *)fetchResult parentController:(TGViewController *)parentController thumbnailImage:(UIImage *)thumbnailImage selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext suggestionContext:(TGSuggestionContext *)suggestionContext hasCaptions:(bool)hasCaptions allowCaptionEntities:(bool)allowCaptionEntities hasTimer:(bool)hasTimer onlyCrop:(bool)onlyCrop inhibitDocumentCaptions:(bool)inhibitDocumentCaptions inhibitMute:(bool)inhibitMute asFile:(bool)asFile itemsLimit:(NSUInteger)itemsLimit recipientName:(NSString *)recipientName defaultVideoPreset:(TGMediaVideoConversionPreset)defaultVideoPreset hasSilentPosting:(bool)hasSilentPosting hasSchedule:(bool)hasSchedule reminder:(bool)reminder; -- (instancetype)initWithContext:(id)context item:(id)item momentList:(TGMediaAssetMomentList *)momentList parentController:(TGViewController *)parentController thumbnailImage:(UIImage *)thumbnailImage selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext suggestionContext:(TGSuggestionContext *)suggestionContext hasCaptions:(bool)hasCaptions allowCaptionEntities:(bool)allowCaptionEntities hasTimer:(bool)hasTimer onlyCrop:(bool)onlyCrop inhibitDocumentCaptions:(bool)inhibitDocumentCaptions inhibitMute:(bool)inhibitMute asFile:(bool)asFile itemsLimit:(NSUInteger)itemsLimit hasSilentPosting:(bool)hasSilentPosting hasSchedule:(bool)hasSchedule reminder:(bool)reminder; +- (instancetype)initWithContext:(id)context item:(id)item momentList:(TGMediaAssetMomentList *)momentList parentController:(TGViewController *)parentController thumbnailImage:(UIImage *)thumbnailImage selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext suggestionContext:(TGSuggestionContext *)suggestionContext hasCaptions:(bool)hasCaptions allowCaptionEntities:(bool)allowCaptionEntities hasTimer:(bool)hasTimer onlyCrop:(bool)onlyCrop inhibitDocumentCaptions:(bool)inhibitDocumentCaptions inhibitMute:(bool)inhibitMute asFile:(bool)asFile itemsLimit:(NSUInteger)itemsLimit defaultVideoPreset:(TGMediaVideoConversionPreset)defaultVideoPreset hasSilentPosting:(bool)hasSilentPosting hasSchedule:(bool)hasSchedule reminder:(bool)reminder; - (void)present; - (void)updateWithFetchResult:(TGMediaAssetFetchResult *)fetchResult; diff --git a/submodules/LegacyComponents/LegacyComponents/TGMediaPickerModernGalleryMixin.m b/submodules/LegacyComponents/LegacyComponents/TGMediaPickerModernGalleryMixin.m index 3ba245c3b8..755e57ee21 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGMediaPickerModernGalleryMixin.m +++ b/submodules/LegacyComponents/LegacyComponents/TGMediaPickerModernGalleryMixin.m @@ -41,17 +41,17 @@ @implementation TGMediaPickerModernGalleryMixin -- (instancetype)initWithContext:(id)context item:(id)item fetchResult:(TGMediaAssetFetchResult *)fetchResult parentController:(TGViewController *)parentController thumbnailImage:(UIImage *)thumbnailImage selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext suggestionContext:(TGSuggestionContext *)suggestionContext hasCaptions:(bool)hasCaptions allowCaptionEntities:(bool)allowCaptionEntities hasTimer:(bool)hasTimer onlyCrop:(bool)onlyCrop inhibitDocumentCaptions:(bool)inhibitDocumentCaptions inhibitMute:(bool)inhibitMute asFile:(bool)asFile itemsLimit:(NSUInteger)itemsLimit recipientName:(NSString *)recipientName hasSilentPosting:(bool)hasSilentPosting hasSchedule:(bool)hasSchedule reminder:(bool)reminder +- (instancetype)initWithContext:(id)context item:(id)item fetchResult:(TGMediaAssetFetchResult *)fetchResult parentController:(TGViewController *)parentController thumbnailImage:(UIImage *)thumbnailImage selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext suggestionContext:(TGSuggestionContext *)suggestionContext hasCaptions:(bool)hasCaptions allowCaptionEntities:(bool)allowCaptionEntities hasTimer:(bool)hasTimer onlyCrop:(bool)onlyCrop inhibitDocumentCaptions:(bool)inhibitDocumentCaptions inhibitMute:(bool)inhibitMute asFile:(bool)asFile itemsLimit:(NSUInteger)itemsLimit recipientName:(NSString *)recipientName defaultVideoPreset:(TGMediaVideoConversionPreset)defaultVideoPreset hasSilentPosting:(bool)hasSilentPosting hasSchedule:(bool)hasSchedule reminder:(bool)reminder { - return [self initWithContext:context item:item fetchResult:fetchResult momentList:nil parentController:parentController thumbnailImage:thumbnailImage selectionContext:selectionContext editingContext:editingContext suggestionContext:suggestionContext hasCaptions:hasCaptions allowCaptionEntities:allowCaptionEntities hasTimer:hasTimer onlyCrop:onlyCrop inhibitDocumentCaptions:inhibitDocumentCaptions inhibitMute:inhibitMute asFile:asFile itemsLimit:itemsLimit recipientName:recipientName hasSilentPosting:hasSilentPosting hasSchedule:hasSchedule reminder:reminder]; + return [self initWithContext:context item:item fetchResult:fetchResult momentList:nil parentController:parentController thumbnailImage:thumbnailImage selectionContext:selectionContext editingContext:editingContext suggestionContext:suggestionContext hasCaptions:hasCaptions allowCaptionEntities:allowCaptionEntities hasTimer:hasTimer onlyCrop:onlyCrop inhibitDocumentCaptions:inhibitDocumentCaptions inhibitMute:inhibitMute asFile:asFile itemsLimit:itemsLimit recipientName:recipientName defaultVideoPreset:defaultVideoPreset hasSilentPosting:hasSilentPosting hasSchedule:hasSchedule reminder:reminder]; } -- (instancetype)initWithContext:(id)context item:(id)item momentList:(TGMediaAssetMomentList *)momentList parentController:(TGViewController *)parentController thumbnailImage:(UIImage *)thumbnailImage selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext suggestionContext:(TGSuggestionContext *)suggestionContext hasCaptions:(bool)hasCaptions allowCaptionEntities:(bool)allowCaptionEntities hasTimer:(bool)hasTimer onlyCrop:(bool)onlyCrop inhibitDocumentCaptions:(bool)inhibitDocumentCaptions inhibitMute:(bool)inhibitMute asFile:(bool)asFile itemsLimit:(NSUInteger)itemsLimit hasSilentPosting:(bool)hasSilentPosting hasSchedule:(bool)hasSchedule reminder:(bool)reminder +- (instancetype)initWithContext:(id)context item:(id)item momentList:(TGMediaAssetMomentList *)momentList parentController:(TGViewController *)parentController thumbnailImage:(UIImage *)thumbnailImage selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext suggestionContext:(TGSuggestionContext *)suggestionContext hasCaptions:(bool)hasCaptions allowCaptionEntities:(bool)allowCaptionEntities hasTimer:(bool)hasTimer onlyCrop:(bool)onlyCrop inhibitDocumentCaptions:(bool)inhibitDocumentCaptions inhibitMute:(bool)inhibitMute asFile:(bool)asFile itemsLimit:(NSUInteger)itemsLimit defaultVideoPreset:(TGMediaVideoConversionPreset)defaultVideoPreset hasSilentPosting:(bool)hasSilentPosting hasSchedule:(bool)hasSchedule reminder:(bool)reminder { - return [self initWithContext:context item:item fetchResult:nil momentList:momentList parentController:parentController thumbnailImage:thumbnailImage selectionContext:selectionContext editingContext:editingContext suggestionContext:suggestionContext hasCaptions:hasCaptions allowCaptionEntities:allowCaptionEntities hasTimer:hasTimer onlyCrop:onlyCrop inhibitDocumentCaptions:inhibitDocumentCaptions inhibitMute:inhibitMute asFile:asFile itemsLimit:itemsLimit recipientName:nil hasSilentPosting:hasSilentPosting hasSchedule:hasSchedule reminder:reminder]; + return [self initWithContext:context item:item fetchResult:nil momentList:momentList parentController:parentController thumbnailImage:thumbnailImage selectionContext:selectionContext editingContext:editingContext suggestionContext:suggestionContext hasCaptions:hasCaptions allowCaptionEntities:allowCaptionEntities hasTimer:hasTimer onlyCrop:onlyCrop inhibitDocumentCaptions:inhibitDocumentCaptions inhibitMute:inhibitMute asFile:asFile itemsLimit:itemsLimit recipientName:nil defaultVideoPreset:defaultVideoPreset hasSilentPosting:hasSilentPosting hasSchedule:hasSchedule reminder:reminder]; } -- (instancetype)initWithContext:(id)context item:(id)item fetchResult:(TGMediaAssetFetchResult *)fetchResult momentList:(TGMediaAssetMomentList *)momentList parentController:(TGViewController *)parentController thumbnailImage:(UIImage *)thumbnailImage selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext suggestionContext:(TGSuggestionContext *)suggestionContext hasCaptions:(bool)hasCaptions allowCaptionEntities:(bool)allowCaptionEntities hasTimer:(bool)hasTimer onlyCrop:(bool)onlyCrop inhibitDocumentCaptions:(bool)inhibitDocumentCaptions inhibitMute:(bool)inhibitMute asFile:(bool)asFile itemsLimit:(NSUInteger)itemsLimit recipientName:(NSString *)recipientName hasSilentPosting:(bool)hasSilentPosting hasSchedule:(bool)hasSchedule reminder:(bool)reminder +- (instancetype)initWithContext:(id)context item:(id)item fetchResult:(TGMediaAssetFetchResult *)fetchResult momentList:(TGMediaAssetMomentList *)momentList parentController:(TGViewController *)parentController thumbnailImage:(UIImage *)thumbnailImage selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext suggestionContext:(TGSuggestionContext *)suggestionContext hasCaptions:(bool)hasCaptions allowCaptionEntities:(bool)allowCaptionEntities hasTimer:(bool)hasTimer onlyCrop:(bool)onlyCrop inhibitDocumentCaptions:(bool)inhibitDocumentCaptions inhibitMute:(bool)inhibitMute asFile:(bool)asFile itemsLimit:(NSUInteger)itemsLimit recipientName:(NSString *)recipientName defaultVideoPreset:(TGMediaVideoConversionPreset)defaultVideoPreset hasSilentPosting:(bool)hasSilentPosting hasSchedule:(bool)hasSchedule reminder:(bool)reminder { self = [super init]; if (self != nil) @@ -83,7 +83,7 @@ NSArray *galleryItems = fetchResult != nil ? [self prepareGalleryItemsForFetchResult:fetchResult selectionContext:selectionContext editingContext:editingContext asFile:asFile enumerationBlock:enumerationBlock] : [self prepareGalleryItemsForMomentList:momentList selectionContext:selectionContext editingContext:editingContext asFile:asFile enumerationBlock:enumerationBlock]; - TGMediaPickerGalleryModel *model = [[TGMediaPickerGalleryModel alloc] initWithContext:[_windowManager context] items:galleryItems focusItem:focusItem selectionContext:selectionContext editingContext:editingContext hasCaptions:hasCaptions allowCaptionEntities:allowCaptionEntities hasTimer:hasTimer onlyCrop:onlyCrop inhibitDocumentCaptions:inhibitDocumentCaptions hasSelectionPanel:true hasCamera:false recipientName:recipientName]; + TGMediaPickerGalleryModel *model = [[TGMediaPickerGalleryModel alloc] initWithContext:[_windowManager context] items:galleryItems focusItem:focusItem selectionContext:selectionContext editingContext:editingContext hasCaptions:hasCaptions allowCaptionEntities:allowCaptionEntities hasTimer:hasTimer onlyCrop:onlyCrop inhibitDocumentCaptions:inhibitDocumentCaptions hasSelectionPanel:true hasCamera:false recipientName:recipientName defaultVideoPreset:defaultVideoPreset]; _galleryModel = model; model.inhibitMute = inhibitMute; model.controller = modernGallery; diff --git a/submodules/LegacyComponents/LegacyComponents/TGPassportAttachMenu.m b/submodules/LegacyComponents/LegacyComponents/TGPassportAttachMenu.m index fe894de053..cdf22f0e98 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGPassportAttachMenu.m +++ b/submodules/LegacyComponents/LegacyComponents/TGPassportAttachMenu.m @@ -227,7 +227,7 @@ TGMediaAssetsControllerIntent assetsIntent = (intent == TGPassportAttachIntentMultiple) ? TGMediaAssetsControllerPassportMultipleIntent : TGMediaAssetsControllerPassportIntent; [strongParentController presentWithContext:^UIViewController *(id context) { - TGMediaAssetsController *controller = [TGMediaAssetsController controllerWithContext:context assetGroup:group intent:assetsIntent recipientName:nil saveEditedPhotos:false allowGrouping:false selectionLimit:10]; + TGMediaAssetsController *controller = [TGMediaAssetsController controllerWithContext:context assetGroup:group intent:assetsIntent recipientName:nil defaultVideoPreset:TGMediaVideoConversionPresetCompressedDefault saveEditedPhotos:false allowGrouping:false selectionLimit:10]; controller.onlyCrop = true; __weak TGMediaAssetsController *weakController = controller; controller.singleCompletionBlock = ^(id currentItem, TGMediaEditingContext *editingContext) { diff --git a/submodules/LegacyComponents/LegacyComponents/TGPhotoEditorController.h b/submodules/LegacyComponents/LegacyComponents/TGPhotoEditorController.h index ae25ee29ad..6d41e41855 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGPhotoEditorController.h +++ b/submodules/LegacyComponents/LegacyComponents/TGPhotoEditorController.h @@ -51,7 +51,7 @@ typedef enum { @property (nonatomic, assign) bool dontHideStatusBar; @property (nonatomic, strong) PGCameraShotMetadata *metadata; -- (instancetype)initWithContext:(id)context item:(id)item intent:(TGPhotoEditorControllerIntent)intent adjustments:(id)adjustments caption:(NSString *)caption screenImage:(UIImage *)screenImage availableTabs:(TGPhotoEditorTab)availableTabs selectedTab:(TGPhotoEditorTab)selectedTab; +- (instancetype)initWithContext:(id)context item:(id)item intent:(TGPhotoEditorControllerIntent)intent adjustments:(id)adjustments caption:(NSString *)caption screenImage:(UIImage *)screenImage availableTabs:(TGPhotoEditorTab)availableTabs selectedTab:(TGPhotoEditorTab)selectedTab defaultVideoPreset:(TGMediaVideoConversionPreset)defaultVideoPreset; - (void)dismissEditor; - (void)applyEditor; diff --git a/submodules/LegacyComponents/LegacyComponents/TGPhotoEditorController.m b/submodules/LegacyComponents/LegacyComponents/TGPhotoEditorController.m index 0233810df4..5688ff7883 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGPhotoEditorController.m +++ b/submodules/LegacyComponents/LegacyComponents/TGPhotoEditorController.m @@ -88,6 +88,8 @@ TGMessageImageViewOverlayView *_progressView; id _context; + + TGMediaVideoConversionPreset _defaultVideoPreset; } @property (nonatomic, weak) UIImage *fullSizeImage; @@ -98,7 +100,7 @@ @synthesize actionHandle = _actionHandle; -- (instancetype)initWithContext:(id)context item:(id)item intent:(TGPhotoEditorControllerIntent)intent adjustments:(id)adjustments caption:(NSString *)caption screenImage:(UIImage *)screenImage availableTabs:(TGPhotoEditorTab)availableTabs selectedTab:(TGPhotoEditorTab)selectedTab +- (instancetype)initWithContext:(id)context item:(id)item intent:(TGPhotoEditorControllerIntent)intent adjustments:(id)adjustments caption:(NSString *)caption screenImage:(UIImage *)screenImage availableTabs:(TGPhotoEditorTab)availableTabs selectedTab:(TGPhotoEditorTab)selectedTab defaultVideoPreset:(TGMediaVideoConversionPreset)defaultVideoPreset { self = [super initWithContext:context]; if (self != nil) @@ -120,6 +122,8 @@ _initialAdjustments = adjustments; _screenImage = screenImage; + _defaultVideoPreset = defaultVideoPreset; + _queue = [[SQueue alloc] init]; _photoEditor = [[PGPhotoEditor alloc] initWithOriginalSize:_item.originalSize adjustments:adjustments forVideo:(intent == TGPhotoEditorControllerVideoIntent) enableStickers:(intent & TGPhotoEditorControllerSignupAvatarIntent) == 0]; if ([self presentedForAvatarCreation]) @@ -1114,7 +1118,7 @@ { _ignoreDefaultPreviewViewTransitionIn = true; - TGPhotoQualityController *qualityController = [[TGPhotoQualityController alloc] initWithContext:_context photoEditor:_photoEditor previewView:_previewView]; + TGPhotoQualityController *qualityController = [[TGPhotoQualityController alloc] initWithContext:_context photoEditor:_photoEditor previewView:_previewView defaultPreset:_defaultVideoPreset]; qualityController.item = _item; qualityController.toolbarLandscapeSize = TGPhotoEditorToolbarSize; qualityController.beginTransitionIn = ^UIView *(CGRect *referenceFrame, UIView **parentView, bool *noTransitionView) diff --git a/submodules/LegacyComponents/LegacyComponents/TGPhotoQualityController.h b/submodules/LegacyComponents/LegacyComponents/TGPhotoQualityController.h index 0a33e72154..c8eb807858 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGPhotoQualityController.h +++ b/submodules/LegacyComponents/LegacyComponents/TGPhotoQualityController.h @@ -10,6 +10,6 @@ @property (nonatomic, readonly) TGMediaVideoConversionPreset preset; -- (instancetype)initWithContext:(id)context photoEditor:(PGPhotoEditor *)photoEditor previewView:(TGPhotoEditorPreviewView *)previewView; +- (instancetype)initWithContext:(id)context photoEditor:(PGPhotoEditor *)photoEditor previewView:(TGPhotoEditorPreviewView *)previewView defaultPreset:(TGMediaVideoConversionPreset)defaultPreset; @end diff --git a/submodules/LegacyComponents/LegacyComponents/TGPhotoQualityController.m b/submodules/LegacyComponents/LegacyComponents/TGPhotoQualityController.m index 5df162adfc..03cab474bf 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGPhotoQualityController.m +++ b/submodules/LegacyComponents/LegacyComponents/TGPhotoQualityController.m @@ -69,7 +69,7 @@ const NSTimeInterval TGPhotoQualityPreviewDuration = 15.0f; @implementation TGPhotoQualityController -- (instancetype)initWithContext:(id)context photoEditor:(PGPhotoEditor *)photoEditor previewView:(TGPhotoEditorPreviewView *)previewView +- (instancetype)initWithContext:(id)context photoEditor:(PGPhotoEditor *)photoEditor previewView:(TGPhotoEditorPreviewView *)previewView defaultPreset:(TGMediaVideoConversionPreset)defaultPreset { self = [super initWithContext:context]; if (self != nil) @@ -89,11 +89,7 @@ const NSTimeInterval TGPhotoQualityPreviewDuration = 15.0f; } else { - NSNumber *presetValue = [[NSUserDefaults standardUserDefaults] objectForKey:@"TG_preferredVideoPreset_v0"]; - if (presetValue != nil) - value = [presetValue integerValue]; - else - value = TGMediaVideoConversionPresetCompressedMedium; + value = defaultPreset; } _disposable = [[SMetaDisposable alloc] init]; diff --git a/submodules/LegacyComponents/LegacyComponents/TGPhotoVideoEditor.h b/submodules/LegacyComponents/LegacyComponents/TGPhotoVideoEditor.h index ff8cfd650c..2be5281b6b 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGPhotoVideoEditor.h +++ b/submodules/LegacyComponents/LegacyComponents/TGPhotoVideoEditor.h @@ -2,6 +2,6 @@ @interface TGPhotoVideoEditor : NSObject -+ (void)presentWithContext:(id)context controller:(TGViewController *)controller caption:(NSString *)caption entities:(NSArray *)entities withItem:(id)item recipientName:(NSString *)recipientName completion:(void (^)(id, TGMediaEditingContext *))completion; ++ (void)presentWithContext:(id)context controller:(TGViewController *)controller caption:(NSString *)caption entities:(NSArray *)entities withItem:(id)item recipientName:(NSString *)recipientName defaultVideoPreset:(TGMediaVideoConversionPreset)defaultVideoPreset completion:(void (^)(id, TGMediaEditingContext *))completion; @end diff --git a/submodules/LegacyComponents/LegacyComponents/TGPhotoVideoEditor.m b/submodules/LegacyComponents/LegacyComponents/TGPhotoVideoEditor.m index ee6a2bc03d..6ca62fab90 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGPhotoVideoEditor.m +++ b/submodules/LegacyComponents/LegacyComponents/TGPhotoVideoEditor.m @@ -10,7 +10,7 @@ @implementation TGPhotoVideoEditor -+ (void)presentWithContext:(id)context controller:(TGViewController *)controller caption:(NSString *)caption entities:(NSArray *)entities withItem:(id)item recipientName:(NSString *)recipientName completion:(void (^)(id, TGMediaEditingContext *))completion ++ (void)presentWithContext:(id)context controller:(TGViewController *)controller caption:(NSString *)caption entities:(NSArray *)entities withItem:(id)item recipientName:(NSString *)recipientName defaultVideoPreset:(TGMediaVideoConversionPreset)defaultVideoPreset completion:(void (^)(id, TGMediaEditingContext *))completion { id windowManager = [context makeOverlayWindowManager]; id windowContext = [windowManager context]; @@ -29,7 +29,7 @@ galleryItem = [[TGMediaPickerGalleryPhotoItem alloc] initWithAsset:item]; galleryItem.editingContext = editingContext; - TGMediaPickerGalleryModel *model = [[TGMediaPickerGalleryModel alloc] initWithContext:windowContext items:@[galleryItem] focusItem:galleryItem selectionContext:nil editingContext:editingContext hasCaptions:true allowCaptionEntities:true hasTimer:false onlyCrop:false inhibitDocumentCaptions:false hasSelectionPanel:false hasCamera:false recipientName:recipientName]; + TGMediaPickerGalleryModel *model = [[TGMediaPickerGalleryModel alloc] initWithContext:windowContext items:@[galleryItem] focusItem:galleryItem selectionContext:nil editingContext:editingContext hasCaptions:true allowCaptionEntities:true hasTimer:false onlyCrop:false inhibitDocumentCaptions:false hasSelectionPanel:false hasCamera:false recipientName:recipientName defaultVideoPreset:defaultVideoPreset]; model.controller = galleryController; //model.suggestionContext = self.suggestionContext; diff --git a/submodules/LegacyMediaPickerUI/Sources/LegacyAttachmentMenu.swift b/submodules/LegacyMediaPickerUI/Sources/LegacyAttachmentMenu.swift index 1f8f946163..6b9f656964 100644 --- a/submodules/LegacyMediaPickerUI/Sources/LegacyAttachmentMenu.swift +++ b/submodules/LegacyMediaPickerUI/Sources/LegacyAttachmentMenu.swift @@ -11,6 +11,47 @@ import DeviceAccess import AccountContext import LegacyUI +public func defaultVideoPresetForContext(_ context: AccountContext) -> TGMediaVideoConversionPreset { + var networkType: NetworkType = .wifi + let _ = (context.account.networkType + |> take(1)).start(next: { value in + networkType = value + }) + + let autodownloadSettings = context.sharedContext.currentAutodownloadSettings.with { $0 } + let presetSettings: AutodownloadPresetSettings + switch networkType { + case .wifi: + presetSettings = autodownloadSettings.highPreset + default: + presetSettings = autodownloadSettings.mediumPreset + } + + let effectiveValue: Int + if presetSettings.videoUploadMaxbitrate == 0 { + effectiveValue = 0 + } else { + effectiveValue = Int(presetSettings.videoUploadMaxbitrate) * 5 / 100 + } + + switch effectiveValue { + case 0: + return TGMediaVideoConversionPresetCompressedMedium + case 1: + return TGMediaVideoConversionPresetCompressedVeryLow + case 2: + return TGMediaVideoConversionPresetCompressedLow + case 3: + return TGMediaVideoConversionPresetCompressedMedium + case 4: + return TGMediaVideoConversionPresetCompressedHigh + case 5: + return TGMediaVideoConversionPresetCompressedVeryLow + default: + return TGMediaVideoConversionPresetCompressedMedium + } +} + public struct LegacyAttachmentMenuMediaEditing: OptionSet { public var rawValue: Int32 @@ -62,6 +103,7 @@ public func legacyAttachmentMenu(context: AccountContext, peer: Peer, editMediaO carouselItemView = carouselItem carouselItem.suggestionContext = legacySuggestionContext(context: context, peerId: peer.id) carouselItem.recipientName = peer.displayTitle(strings: presentationData.strings, displayOrder: presentationData.nameDisplayOrder) + carouselItem.defaultVideoPreset = defaultVideoPresetForContext(context) carouselItem.cameraPressed = { [weak controller] cameraView in if let controller = controller { DeviceAccess.authorizeAccess(to: .camera, presentationData: context.sharedContext.currentPresentationData.with { $0 }, present: context.sharedContext.presentGlobalController, openSettings: context.sharedContext.applicationBindings.openSettings, { value in @@ -218,7 +260,7 @@ public func presentLegacyPasteMenu(context: AccountContext, peer: Peer, saveEdit legacyController.enableSizeClassSignal = true - let controller = TGClipboardMenu.present(inParentController: emptyController, context: legacyController.context, images: images, hasCaption: true, hasTimer: hasTimer, recipientName: recipientName, completed: { selectionContext, editingContext, currentItem in + let controller = TGClipboardMenu.present(inParentController: emptyController, context: legacyController.context, images: images, hasCaption: true, hasTimer: hasTimer, recipientName: recipientName, defaultVideoPreset: defaultVideoPresetForContext(context), completed: { selectionContext, editingContext, currentItem in let signals = TGClipboardMenu.resultSignals(for: selectionContext, editingContext: editingContext, currentItem: currentItem, descriptionGenerator: legacyAssetPickerItemGenerator()) sendMessagesWithSignals(signals) }, dismissed: { [weak legacyController] in diff --git a/submodules/LegacyMediaPickerUI/Sources/LegacyMediaPickers.swift b/submodules/LegacyMediaPickerUI/Sources/LegacyMediaPickers.swift index 9ba239a792..ef5fffc786 100644 --- a/submodules/LegacyMediaPickerUI/Sources/LegacyMediaPickers.swift +++ b/submodules/LegacyMediaPickerUI/Sources/LegacyMediaPickers.swift @@ -55,6 +55,7 @@ public func legacyAssetPicker(context: AccountContext, presentationData: Present return Signal { subscriber in let intent = fileMode ? TGMediaAssetsControllerSendFileIntent : TGMediaAssetsControllerSendMediaIntent + let defaultVideoPreset = defaultVideoPresetForContext(context) DeviceAccess.authorizeAccess(to: .mediaLibrary(.send), presentationData: presentationData, present: context.sharedContext.presentGlobalController, openSettings: context.sharedContext.applicationBindings.openSettings, { value in if !value { @@ -69,7 +70,7 @@ public func legacyAssetPicker(context: AccountContext, presentationData: Present } else { Queue.mainQueue().async { subscriber.putNext({ context in - let controller = TGMediaAssetsController(context: context, assetGroup: group, intent: intent, recipientName: peer?.displayTitle(strings: presentationData.strings, displayOrder: presentationData.nameDisplayOrder), saveEditedPhotos: !isSecretChat && saveEditedPhotos, allowGrouping: allowGrouping, inhibitSelection: editingMedia, selectionLimit: Int32(selectionLimit)) + let controller = TGMediaAssetsController(context: context, assetGroup: group, intent: intent, recipientName: peer?.displayTitle(strings: presentationData.strings, displayOrder: presentationData.nameDisplayOrder), defaultVideoPreset: defaultVideoPreset, saveEditedPhotos: !isSecretChat && saveEditedPhotos, allowGrouping: allowGrouping, inhibitSelection: editingMedia, selectionLimit: Int32(selectionLimit)) return controller! }) subscriber.putCompletion() @@ -78,7 +79,7 @@ public func legacyAssetPicker(context: AccountContext, presentationData: Present }) } else { subscriber.putNext({ context in - let controller = TGMediaAssetsController(context: context, assetGroup: nil, intent: intent, recipientName: peer?.displayTitle(strings: presentationData.strings, displayOrder: presentationData.nameDisplayOrder), saveEditedPhotos: !isSecretChat && saveEditedPhotos, allowGrouping: allowGrouping, selectionLimit: Int32(selectionLimit)) + let controller = TGMediaAssetsController(context: context, assetGroup: nil, intent: intent, recipientName: peer?.displayTitle(strings: presentationData.strings, displayOrder: presentationData.nameDisplayOrder), defaultVideoPreset: defaultVideoPreset, saveEditedPhotos: !isSecretChat && saveEditedPhotos, allowGrouping: allowGrouping, selectionLimit: Int32(selectionLimit)) return controller! }) subscriber.putCompletion() diff --git a/submodules/LegacyMediaPickerUI/Sources/LegacyWallpaperPicker.swift b/submodules/LegacyMediaPickerUI/Sources/LegacyWallpaperPicker.swift index 05968635c7..54d110d7f2 100644 --- a/submodules/LegacyMediaPickerUI/Sources/LegacyWallpaperPicker.swift +++ b/submodules/LegacyMediaPickerUI/Sources/LegacyWallpaperPicker.swift @@ -24,7 +24,7 @@ public func legacyWallpaperPicker(context: AccountContext, presentationData: Pre } else { Queue.mainQueue().async { subscriber.putNext({ context in - let controller = TGMediaAssetsController(context: context, assetGroup: group, intent: intent, recipientName: nil, saveEditedPhotos: false, allowGrouping: false, selectionLimit: 1) + let controller = TGMediaAssetsController(context: context, assetGroup: group, intent: intent, recipientName: nil, defaultVideoPreset: TGMediaVideoConversionPresetCompressedDefault, saveEditedPhotos: false, allowGrouping: false, selectionLimit: 1) return controller! }) subscriber.putCompletion() @@ -33,7 +33,7 @@ public func legacyWallpaperPicker(context: AccountContext, presentationData: Pre }) } else { subscriber.putNext({ context in - let controller = TGMediaAssetsController(context: context, assetGroup: nil, intent: intent, recipientName: nil, saveEditedPhotos: false, allowGrouping: false, selectionLimit: 1) + let controller = TGMediaAssetsController(context: context, assetGroup: nil, intent: intent, recipientName: nil, defaultVideoPreset: TGMediaVideoConversionPresetCompressedDefault, saveEditedPhotos: false, allowGrouping: false, selectionLimit: 1) return controller! }) subscriber.putCompletion() diff --git a/submodules/SettingsUI/Sources/Data and Storage/AutodownloadMediaCategoryController.swift b/submodules/SettingsUI/Sources/Data and Storage/AutodownloadMediaCategoryController.swift index 3591b7c92b..222efd9093 100644 --- a/submodules/SettingsUI/Sources/Data and Storage/AutodownloadMediaCategoryController.swift +++ b/submodules/SettingsUI/Sources/Data and Storage/AutodownloadMediaCategoryController.swift @@ -447,7 +447,7 @@ func autodownloadMediaCategoryController(context: AccountContext, connectionType case .wifi: preset = .high } - let settings = AutodownloadPresetSettings(disabled: false, photoSizeMax: categories.photo.sizeLimit, videoSizeMax: categories.video.sizeLimit, fileSizeMax: categories.file.sizeLimit, preloadLargeVideo: categories.video.predownload, lessDataForPhoneCalls: false) + let settings = AutodownloadPresetSettings(disabled: false, photoSizeMax: categories.photo.sizeLimit, videoSizeMax: categories.video.sizeLimit, fileSizeMax: categories.file.sizeLimit, preloadLargeVideo: categories.video.predownload, lessDataForPhoneCalls: false, videoUploadMaxbitrate: 0) return saveAutodownloadSettings(account: context.account, preset: preset, settings: settings) } return .complete() diff --git a/submodules/SyncCore/Sources/AutodownloadSettings.swift b/submodules/SyncCore/Sources/AutodownloadSettings.swift index 3724217966..a8f2af62e2 100644 --- a/submodules/SyncCore/Sources/AutodownloadSettings.swift +++ b/submodules/SyncCore/Sources/AutodownloadSettings.swift @@ -13,14 +13,16 @@ public struct AutodownloadPresetSettings: PostboxCoding, Equatable { public let fileSizeMax: Int32 public let preloadLargeVideo: Bool public let lessDataForPhoneCalls: Bool + public let videoUploadMaxbitrate: Int32 - public init(disabled: Bool, photoSizeMax: Int32, videoSizeMax: Int32, fileSizeMax: Int32, preloadLargeVideo: Bool, lessDataForPhoneCalls: Bool) { + public init(disabled: Bool, photoSizeMax: Int32, videoSizeMax: Int32, fileSizeMax: Int32, preloadLargeVideo: Bool, lessDataForPhoneCalls: Bool, videoUploadMaxbitrate: Int32) { self.disabled = disabled self.photoSizeMax = photoSizeMax self.videoSizeMax = videoSizeMax self.fileSizeMax = fileSizeMax self.preloadLargeVideo = preloadLargeVideo self.lessDataForPhoneCalls = lessDataForPhoneCalls + self.videoUploadMaxbitrate = videoUploadMaxbitrate } public init(decoder: PostboxDecoder) { @@ -30,6 +32,7 @@ public struct AutodownloadPresetSettings: PostboxCoding, Equatable { self.fileSizeMax = decoder.decodeInt32ForKey("fileSizeMax", orElse: 0) self.preloadLargeVideo = decoder.decodeInt32ForKey("preloadLargeVideo", orElse: 0) != 0 self.lessDataForPhoneCalls = decoder.decodeInt32ForKey("lessDataForPhoneCalls", orElse: 0) != 0 + self.videoUploadMaxbitrate = decoder.decodeInt32ForKey("videoUploadMaxbitrate", orElse: 0) } public func encode(_ encoder: PostboxEncoder) { @@ -39,6 +42,7 @@ public struct AutodownloadPresetSettings: PostboxCoding, Equatable { encoder.encodeInt32(self.fileSizeMax, forKey: "fileSizeMax") encoder.encodeInt32(self.preloadLargeVideo ? 1 : 0, forKey: "preloadLargeVideo") encoder.encodeInt32(self.lessDataForPhoneCalls ? 1 : 0, forKey: "lessDataForPhoneCalls") + encoder.encodeInt32(self.videoUploadMaxbitrate, forKey: "videoUploadMaxbitrate") } } @@ -48,9 +52,10 @@ public struct AutodownloadSettings: PreferencesEntry, Equatable { public let highPreset: AutodownloadPresetSettings public static var defaultSettings: AutodownloadSettings { - return AutodownloadSettings(lowPreset: AutodownloadPresetSettings(disabled: false, photoSizeMax: 1 * 1024 * 1024, videoSizeMax: 0, fileSizeMax: 0, preloadLargeVideo: false, lessDataForPhoneCalls: true), - mediumPreset: AutodownloadPresetSettings(disabled: false, photoSizeMax: 1 * 1024 * 1024, videoSizeMax: Int32(2.5 * 1024 * 1024), fileSizeMax: 1 * 1024 * 1024, preloadLargeVideo: false, lessDataForPhoneCalls: false), - highPreset: AutodownloadPresetSettings(disabled: false, photoSizeMax: 1 * 1024 * 1024, videoSizeMax: 10 * 1024 * 1024, fileSizeMax: 3 * 1024 * 1024, preloadLargeVideo: false, lessDataForPhoneCalls: false)) + return AutodownloadSettings( + lowPreset: AutodownloadPresetSettings(disabled: false, photoSizeMax: 1 * 1024 * 1024, videoSizeMax: 0, fileSizeMax: 0, preloadLargeVideo: false, lessDataForPhoneCalls: true, videoUploadMaxbitrate: 0), + mediumPreset: AutodownloadPresetSettings(disabled: false, photoSizeMax: 1 * 1024 * 1024, videoSizeMax: Int32(2.5 * 1024 * 1024), fileSizeMax: 1 * 1024 * 1024, preloadLargeVideo: false, lessDataForPhoneCalls: false, videoUploadMaxbitrate: 0), + highPreset: AutodownloadPresetSettings(disabled: false, photoSizeMax: 1 * 1024 * 1024, videoSizeMax: 10 * 1024 * 1024, fileSizeMax: 3 * 1024 * 1024, preloadLargeVideo: false, lessDataForPhoneCalls: false, videoUploadMaxbitrate: 0)) } public init(lowPreset: AutodownloadPresetSettings, mediumPreset: AutodownloadPresetSettings, highPreset: AutodownloadPresetSettings) { diff --git a/submodules/TelegramApi/Sources/Api0.swift b/submodules/TelegramApi/Sources/Api0.swift index d316fd251e..58d8f497df 100644 --- a/submodules/TelegramApi/Sources/Api0.swift +++ b/submodules/TelegramApi/Sources/Api0.swift @@ -71,7 +71,8 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[1202287072] = { return Api.StatsURL.parse_statsURL($0) } dict[1516793212] = { return Api.ChatInvite.parse_chatInviteAlready($0) } dict[-540871282] = { return Api.ChatInvite.parse_chatInvite($0) } - dict[-767099577] = { return Api.AutoDownloadSettings.parse_autoDownloadSettings($0) } + dict[-532532493] = { return Api.AutoDownloadSettings.parse_autoDownloadSettings($0) } + dict[-767099577] = { return Api.AutoDownloadSettings.parse_autoDownloadSettingsLegacy($0) } dict[1678812626] = { return Api.StickerSetCovered.parse_stickerSetCovered($0) } dict[872932635] = { return Api.StickerSetCovered.parse_stickerSetMultiCovered($0) } dict[1189204285] = { return Api.RecentMeUrl.parse_recentMeUrlUnknown($0) } diff --git a/submodules/TelegramApi/Sources/Api1.swift b/submodules/TelegramApi/Sources/Api1.swift index 3864c7cbc9..4f1d259c20 100644 --- a/submodules/TelegramApi/Sources/Api1.swift +++ b/submodules/TelegramApi/Sources/Api1.swift @@ -1908,11 +1908,22 @@ public extension Api { } public enum AutoDownloadSettings: TypeConstructorDescription { - case autoDownloadSettings(flags: Int32, photoSizeMax: Int32, videoSizeMax: Int32, fileSizeMax: Int32) + case autoDownloadSettings(flags: Int32, photoSizeMax: Int32, videoSizeMax: Int32, fileSizeMax: Int32, videoUploadMaxbitrate: Int32) + case autoDownloadSettingsLegacy(flags: Int32, photoSizeMax: Int32, videoSizeMax: Int32, fileSizeMax: Int32) public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { switch self { - case .autoDownloadSettings(let flags, let photoSizeMax, let videoSizeMax, let fileSizeMax): + case .autoDownloadSettings(let flags, let photoSizeMax, let videoSizeMax, let fileSizeMax, let videoUploadMaxbitrate): + if boxed { + buffer.appendInt32(-532532493) + } + serializeInt32(flags, buffer: buffer, boxed: false) + serializeInt32(photoSizeMax, buffer: buffer, boxed: false) + serializeInt32(videoSizeMax, buffer: buffer, boxed: false) + serializeInt32(fileSizeMax, buffer: buffer, boxed: false) + serializeInt32(videoUploadMaxbitrate, buffer: buffer, boxed: false) + break + case .autoDownloadSettingsLegacy(let flags, let photoSizeMax, let videoSizeMax, let fileSizeMax): if boxed { buffer.appendInt32(-767099577) } @@ -1926,12 +1937,37 @@ public extension Api { public func descriptionFields() -> (String, [(String, Any)]) { switch self { - case .autoDownloadSettings(let flags, let photoSizeMax, let videoSizeMax, let fileSizeMax): - return ("autoDownloadSettings", [("flags", flags), ("photoSizeMax", photoSizeMax), ("videoSizeMax", videoSizeMax), ("fileSizeMax", fileSizeMax)]) + case .autoDownloadSettings(let flags, let photoSizeMax, let videoSizeMax, let fileSizeMax, let videoUploadMaxbitrate): + return ("autoDownloadSettings", [("flags", flags), ("photoSizeMax", photoSizeMax), ("videoSizeMax", videoSizeMax), ("fileSizeMax", fileSizeMax), ("videoUploadMaxbitrate", videoUploadMaxbitrate)]) + case .autoDownloadSettingsLegacy(let flags, let photoSizeMax, let videoSizeMax, let fileSizeMax): + return ("autoDownloadSettingsLegacy", [("flags", flags), ("photoSizeMax", photoSizeMax), ("videoSizeMax", videoSizeMax), ("fileSizeMax", fileSizeMax)]) } } public static func parse_autoDownloadSettings(_ reader: BufferReader) -> AutoDownloadSettings? { + var _1: Int32? + _1 = reader.readInt32() + var _2: Int32? + _2 = reader.readInt32() + var _3: Int32? + _3 = reader.readInt32() + var _4: Int32? + _4 = reader.readInt32() + var _5: Int32? + _5 = reader.readInt32() + let _c1 = _1 != nil + let _c2 = _2 != nil + let _c3 = _3 != nil + let _c4 = _4 != nil + let _c5 = _5 != nil + if _c1 && _c2 && _c3 && _c4 && _c5 { + return Api.AutoDownloadSettings.autoDownloadSettings(flags: _1!, photoSizeMax: _2!, videoSizeMax: _3!, fileSizeMax: _4!, videoUploadMaxbitrate: _5!) + } + else { + return nil + } + } + public static func parse_autoDownloadSettingsLegacy(_ reader: BufferReader) -> AutoDownloadSettings? { var _1: Int32? _1 = reader.readInt32() var _2: Int32? @@ -1945,7 +1981,7 @@ public extension Api { let _c3 = _3 != nil let _c4 = _4 != nil if _c1 && _c2 && _c3 && _c4 { - return Api.AutoDownloadSettings.autoDownloadSettings(flags: _1!, photoSizeMax: _2!, videoSizeMax: _3!, fileSizeMax: _4!) + return Api.AutoDownloadSettings.autoDownloadSettingsLegacy(flags: _1!, photoSizeMax: _2!, videoSizeMax: _3!, fileSizeMax: _4!) } else { return nil diff --git a/submodules/TelegramCore/Sources/AutodownloadSettings.swift b/submodules/TelegramCore/Sources/AutodownloadSettings.swift index 141a6ac9d1..b86130c742 100644 --- a/submodules/TelegramCore/Sources/AutodownloadSettings.swift +++ b/submodules/TelegramCore/Sources/AutodownloadSettings.swift @@ -22,8 +22,10 @@ public func updateAutodownloadSettingsInteractively(accountManager: AccountManag extension AutodownloadPresetSettings { init(apiAutodownloadSettings: Api.AutoDownloadSettings) { switch apiAutodownloadSettings { - case let .autoDownloadSettings(flags, photoSizeMax, videoSizeMax, fileSizeMax): - self.init(disabled: (flags & (1 << 0)) != 0, photoSizeMax: photoSizeMax, videoSizeMax: videoSizeMax, fileSizeMax: fileSizeMax, preloadLargeVideo: (flags & (1 << 1)) != 0, lessDataForPhoneCalls: (flags & (1 << 3)) != 0) + case let .autoDownloadSettings(flags, photoSizeMax, videoSizeMax, fileSizeMax, videoUploadMaxbitrate): + self.init(disabled: (flags & (1 << 0)) != 0, photoSizeMax: photoSizeMax, videoSizeMax: videoSizeMax, fileSizeMax: fileSizeMax, preloadLargeVideo: (flags & (1 << 1)) != 0, lessDataForPhoneCalls: (flags & (1 << 3)) != 0, videoUploadMaxbitrate: videoUploadMaxbitrate) + case let .autoDownloadSettingsLegacy(flags, photoSizeMax, videoSizeMax, fileSizeMax): + self.init(disabled: (flags & (1 << 0)) != 0, photoSizeMax: photoSizeMax, videoSizeMax: videoSizeMax, fileSizeMax: fileSizeMax, preloadLargeVideo: (flags & (1 << 1)) != 0, lessDataForPhoneCalls: (flags & (1 << 3)) != 0, videoUploadMaxbitrate: 0) } } } @@ -48,6 +50,6 @@ func apiAutodownloadPresetSettings(_ autodownloadPresetSettings: AutodownloadPre if autodownloadPresetSettings.lessDataForPhoneCalls { flags |= (1 << 3) } - return .autoDownloadSettings(flags: flags, photoSizeMax: autodownloadPresetSettings.photoSizeMax, videoSizeMax: autodownloadPresetSettings.videoSizeMax, fileSizeMax: autodownloadPresetSettings.fileSizeMax) + return .autoDownloadSettings(flags: flags, photoSizeMax: autodownloadPresetSettings.photoSizeMax, videoSizeMax: autodownloadPresetSettings.videoSizeMax, fileSizeMax: autodownloadPresetSettings.fileSizeMax, videoUploadMaxbitrate: autodownloadPresetSettings.videoUploadMaxbitrate) } diff --git a/submodules/TelegramUI/TelegramUI/LegacyCamera.swift b/submodules/TelegramUI/TelegramUI/LegacyCamera.swift index 8c6af7aefd..f2d54b53f7 100644 --- a/submodules/TelegramUI/TelegramUI/LegacyCamera.swift +++ b/submodules/TelegramUI/TelegramUI/LegacyCamera.swift @@ -20,7 +20,7 @@ func presentedLegacyCamera(context: AccountContext, peer: Peer, cameraView: TGAt legacyController.deferScreenEdgeGestures = [.top] let isSecretChat = peer.id.namespace == Namespaces.Peer.SecretChat - + let controller: TGCameraController if let cameraView = cameraView, let previewView = cameraView.previewView() { controller = TGCameraController(context: legacyController.context, saveEditedPhotos: saveCapturedPhotos && !isSecretChat, saveCapturedMedia: saveCapturedPhotos && !isSecretChat, camera: previewView.camera, previewView: previewView, intent: TGCameraControllerGenericIntent) @@ -28,6 +28,7 @@ func presentedLegacyCamera(context: AccountContext, peer: Peer, cameraView: TGAt } else { controller = TGCameraController() } + controller.defaultVideoPreset = defaultVideoPresetForContext(context) controller.presentScheduleController = { done in presentSchedulePicker { time in diff --git a/submodules/TelegramUI/TelegramUI/SharedAccountContext.swift b/submodules/TelegramUI/TelegramUI/SharedAccountContext.swift index 55fdbc45aa..d2dd2918af 100644 --- a/submodules/TelegramUI/TelegramUI/SharedAccountContext.swift +++ b/submodules/TelegramUI/TelegramUI/SharedAccountContext.swift @@ -129,6 +129,10 @@ public final class SharedAccountContextImpl: SharedAccountContext { return self._automaticMediaDownloadSettings.get() } + public let currentAutodownloadSettings: Atomic + private let _autodownloadSettings = Promise() + private var currentAutodownloadSettingsDisposable = MetaDisposable() + public let currentMediaInputSettings: Atomic private var mediaInputSettingsDisposable: Disposable? @@ -180,6 +184,7 @@ public final class SharedAccountContextImpl: SharedAccountContext { self._currentPresentationData = Atomic(value: initialPresentationDataAndSettings.presentationData) self.currentAutomaticMediaDownloadSettings = Atomic(value: initialPresentationDataAndSettings.automaticMediaDownloadSettings) + self.currentAutodownloadSettings = Atomic(value: initialPresentationDataAndSettings.autodownloadSettings) self.currentMediaInputSettings = Atomic(value: initialPresentationDataAndSettings.mediaInputSettings) self.currentInAppNotificationSettings = Atomic(value: initialPresentationDataAndSettings.inAppNotificationSettings) @@ -196,6 +201,14 @@ public final class SharedAccountContextImpl: SharedAccountContext { } )) + self._autodownloadSettings.set(.single(initialPresentationDataAndSettings.autodownloadSettings) + |> then(accountManager.sharedData(keys: [SharedDataKeys.autodownloadSettings]) + |> map { sharedData in + let autodownloadSettings: AutodownloadSettings = sharedData.entries[SharedDataKeys.autodownloadSettings] as? AutodownloadSettings ?? .defaultSettings + return autodownloadSettings + } + )) + self.presentationDataDisposable.set((self.presentationData |> deliverOnMainQueue).start(next: { [weak self] next in if let strongSelf = self { @@ -267,6 +280,12 @@ public final class SharedAccountContextImpl: SharedAccountContext { } })) + self.currentAutodownloadSettingsDisposable.set(self._autodownloadSettings.get().start(next: { [weak self] next in + if let strongSelf = self { + let _ = strongSelf.currentAutodownloadSettings.swap(next) + } + })) + let startTime = CFAbsoluteTimeGetCurrent() let differenceDisposable = MetaDisposable() @@ -644,6 +663,7 @@ public final class SharedAccountContextImpl: SharedAccountContext { self.registeredNotificationTokensDisposable.dispose() self.presentationDataDisposable.dispose() self.automaticMediaDownloadSettingsDisposable.dispose() + self.currentAutodownloadSettingsDisposable.dispose() self.inAppNotificationSettingsDisposable?.dispose() self.mediaInputSettingsDisposable?.dispose() self.callDisposable?.dispose() diff --git a/submodules/WebSearchUI/Sources/LegacyWebSearchEditor.swift b/submodules/WebSearchUI/Sources/LegacyWebSearchEditor.swift index 5fb3ac16d1..09b4732606 100644 --- a/submodules/WebSearchUI/Sources/LegacyWebSearchEditor.swift +++ b/submodules/WebSearchUI/Sources/LegacyWebSearchEditor.swift @@ -35,7 +35,7 @@ func presentLegacyWebSearchEditor(context: AccountContext, theme: PresentationTh let legacyController = LegacyController(presentation: .custom, theme: theme, initialLayout: initialLayout) legacyController.statusBar.statusBarStyle = theme.rootController.statusBarStyle.style - let controller = TGPhotoEditorController(context: legacyController.context, item: item, intent: TGPhotoEditorControllerAvatarIntent, adjustments: nil, caption: nil, screenImage: screenImage ?? UIImage(), availableTabs: TGPhotoEditorController.defaultTabsForAvatarIntent(), selectedTab: .cropTab)! + let controller = TGPhotoEditorController(context: legacyController.context, item: item, intent: TGPhotoEditorControllerAvatarIntent, adjustments: nil, caption: nil, screenImage: screenImage ?? UIImage(), availableTabs: TGPhotoEditorController.defaultTabsForAvatarIntent(), selectedTab: .cropTab, defaultVideoPreset: TGMediaVideoConversionPresetCompressedDefault)! legacyController.bind(controller: controller) controller.editingContext = TGMediaEditingContext() diff --git a/submodules/WebSearchUI/Sources/LegacyWebSearchGallery.swift b/submodules/WebSearchUI/Sources/LegacyWebSearchGallery.swift index 0462646118..3d51d12c32 100644 --- a/submodules/WebSearchUI/Sources/LegacyWebSearchGallery.swift +++ b/submodules/WebSearchUI/Sources/LegacyWebSearchGallery.swift @@ -323,7 +323,7 @@ func presentLegacyWebSearchGallery(context: AccountContext, peer: Peer?, present let (items, focusItem) = galleryItems(account: context.account, results: results, current: current, selectionContext: selectionContext, editingContext: editingContext) - let model = TGMediaPickerGalleryModel(context: legacyController.context, items: items, focus: focusItem, selectionContext: selectionContext, editingContext: editingContext, hasCaptions: false, allowCaptionEntities: true, hasTimer: false, onlyCrop: false, inhibitDocumentCaptions: false, hasSelectionPanel: false, hasCamera: false, recipientName: peer?.displayTitle(strings: presentationData.strings, displayOrder: presentationData.nameDisplayOrder))! + let model = TGMediaPickerGalleryModel(context: legacyController.context, items: items, focus: focusItem, selectionContext: selectionContext, editingContext: editingContext, hasCaptions: false, allowCaptionEntities: true, hasTimer: false, onlyCrop: false, inhibitDocumentCaptions: false, hasSelectionPanel: false, hasCamera: false, recipientName: peer?.displayTitle(strings: presentationData.strings, displayOrder: presentationData.nameDisplayOrder), defaultVideoPreset: TGMediaVideoConversionPresetCompressedDefault)! if let peer = peer { model.suggestionContext = legacySuggestionContext(context: context, peerId: peer.id) }