Skip to content

Commit

Permalink
Add MediaCompressionHelper.defaultCompressionMode for use in RoomView…
Browse files Browse the repository at this point in the history
…Controller.
  • Loading branch information
pixlwave committed Sep 7, 2021
1 parent 46b79be commit e8bc470
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 36 deletions.
45 changes: 9 additions & 36 deletions Riot/Modules/Room/RoomViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
}

Expand Down Expand Up @@ -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];
}
}

Expand All @@ -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];
}
}

Expand Down
32 changes: 32 additions & 0 deletions Riot/Utils/MediaCompressionHelper.swift
Original file line number Diff line number Diff line change
@@ -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
}
}
}

0 comments on commit e8bc470

Please sign in to comment.