From e8bc470bd2a353eb22bd1124976114326cf847a7 Mon Sep 17 00:00:00 2001 From: Doug Date: Tue, 7 Sep 2021 14:46:02 +0100 Subject: [PATCH] Add MediaCompressionHelper.defaultCompressionMode for use in RoomViewController. --- Riot/Modules/Room/RoomViewController.m | 45 +++++-------------------- Riot/Utils/MediaCompressionHelper.swift | 32 ++++++++++++++++++ 2 files changed, 41 insertions(+), 36 deletions(-) create mode 100644 Riot/Utils/MediaCompressionHelper.swift diff --git a/Riot/Modules/Room/RoomViewController.m b/Riot/Modules/Room/RoomViewController.m index ede241008b..33eb91962d 100644 --- a/Riot/Modules/Room/RoomViewController.m +++ b/Riot/Modules/Room/RoomViewController.m @@ -6113,18 +6113,10 @@ - (void)cameraPresenter:(CameraPresenter *)cameraPresenter didSelectImageData:(N RoomInputToolbarView *roomInputToolbarView = [self inputToolbarViewAsRoomInputToolbarView]; if (roomInputToolbarView) { - // When the compression mode build setting hasn't been customised, use the media compression prompt setting to determine what to do. - MXKRoomInputToolbarCompressionMode compressionMode; - if (BuildSettings.roomInputToolbarCompressionMode == MXKRoomInputToolbarCompressionModePrompt) - { - compressionMode = RiotSettings.shared.showMediaCompressionPrompt ? MXKRoomInputToolbarCompressionModePrompt : MXKRoomInputToolbarCompressionModeNone; - } - // Otherwise use the compression mode defined in the build settings. - else - { - compressionMode = BuildSettings.roomInputToolbarCompressionMode; - } - [roomInputToolbarView sendSelectedImage:imageData withMimeType:uti.mimeType andCompressionMode:compressionMode isPhotoLibraryAsset:NO]; + [roomInputToolbarView sendSelectedImage:imageData + withMimeType:uti.mimeType + andCompressionMode:MediaCompressionHelper.defaultCompressionMode + isPhotoLibraryAsset:NO]; } } @@ -6153,18 +6145,10 @@ - (void)mediaPickerCoordinatorBridgePresenter:(MediaPickerCoordinatorBridgePrese RoomInputToolbarView *roomInputToolbarView = [self inputToolbarViewAsRoomInputToolbarView]; if (roomInputToolbarView) { - // When the compression mode build setting hasn't been customised, use the media compression prompt setting to determine what to do. - MXKRoomInputToolbarCompressionMode compressionMode; - if (BuildSettings.roomInputToolbarCompressionMode == MXKRoomInputToolbarCompressionModePrompt) - { - compressionMode = RiotSettings.shared.showMediaCompressionPrompt ? MXKRoomInputToolbarCompressionModePrompt : MXKRoomInputToolbarCompressionModeNone; - } - // Otherwise use the compression mode defined in the build settings. - else - { - compressionMode = BuildSettings.roomInputToolbarCompressionMode; - } - [roomInputToolbarView sendSelectedImage:imageData withMimeType:uti.mimeType andCompressionMode:compressionMode isPhotoLibraryAsset:YES]; + [roomInputToolbarView sendSelectedImage:imageData + withMimeType:uti.mimeType + andCompressionMode:MediaCompressionHelper.defaultCompressionMode + isPhotoLibraryAsset:YES]; } } @@ -6187,18 +6171,7 @@ - (void)mediaPickerCoordinatorBridgePresenter:(MediaPickerCoordinatorBridgePrese // Set a 1080p video conversion preset as compression mode only has an effect on the images. [MXSDKOptions sharedInstance].videoConversionPresetName = AVAssetExportPreset1920x1080; - // When the compression mode build setting hasn't been customised, use the media compression prompt setting to determine what to do. - MXKRoomInputToolbarCompressionMode compressionMode; - if (BuildSettings.roomInputToolbarCompressionMode == MXKRoomInputToolbarCompressionModePrompt) - { - compressionMode = RiotSettings.shared.showMediaCompressionPrompt ? MXKRoomInputToolbarCompressionModePrompt : MXKRoomInputToolbarCompressionModeNone; - } - // Otherwise use the compression mode defined in the build settings. - else - { - compressionMode = BuildSettings.roomInputToolbarCompressionMode; - } - [roomInputToolbarView sendSelectedAssets:assets withCompressionMode:compressionMode]; + [roomInputToolbarView sendSelectedAssets:assets withCompressionMode:MediaCompressionHelper.defaultCompressionMode]; } } diff --git a/Riot/Utils/MediaCompressionHelper.swift b/Riot/Utils/MediaCompressionHelper.swift new file mode 100644 index 0000000000..143321d941 --- /dev/null +++ b/Riot/Utils/MediaCompressionHelper.swift @@ -0,0 +1,32 @@ +// +// Copyright 2021 New Vector Ltd +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +import Foundation + +/// A collection of helpful functions for media compression. +class MediaCompressionHelper: NSObject { + /// The default compression mode taking into account the `roomInputToolbarCompressionMode` build setting + /// and the `showMediaCompressionPrompt` Riot setting. + @objc static var defaultCompressionMode: MXKRoomInputToolbarCompressionMode { + // When the compression mode build setting hasn't been customised, use the media compression prompt setting to determine what to do. + if BuildSettings.roomInputToolbarCompressionMode == MXKRoomInputToolbarCompressionModePrompt { + return RiotSettings.shared.showMediaCompressionPrompt ? MXKRoomInputToolbarCompressionModePrompt : MXKRoomInputToolbarCompressionModeNone + } else { + // Otherwise use the compression mode defined in the build settings. + return BuildSettings.roomInputToolbarCompressionMode + } + } +}