Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable the Optimised Media Uploads feature. #3467

Merged
merged 6 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ElementX.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7874,7 +7874,7 @@
repositoryURL = "https://github.com/matrix-org/matrix-analytics-events";
requirement = {
kind = upToNextMinorVersion;
minimumVersion = 0.27.0;
minimumVersion = 0.28.0;
};
};
C13F55E4518415CB4C278E73 /* XCRemoteSwiftPackageReference "DTCoreText" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/matrix-org/matrix-analytics-events",
"state" : {
"revision" : "9bd3c57e84f87d56b69862369f3b9da714d1d151",
"version" : "0.27.0"
"revision" : "632f4266d5ebd5b87b9eb52522f5117723fcd338",
"version" : "0.28.0"
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,8 @@
"screen_account_provider_signup_title" = "You’re about to create an account on %@";
"screen_advanced_settings_developer_mode" = "Developer mode";
"screen_advanced_settings_developer_mode_description" = "Enable to have access to features and functionality for developers.";
"screen_advanced_settings_media_compression_description" = "Optimize for upload";
"screen_advanced_settings_media_compression_title" = "Media";
"screen_advanced_settings_media_compression_description" = "Upload photos and videos faster and reduce data usage";
"screen_advanced_settings_media_compression_title" = "Optimise media quality";
"screen_advanced_settings_rich_text_editor_description" = "Disable the rich text editor to type Markdown manually.";
"screen_advanced_settings_send_read_receipts" = "Read receipts";
"screen_advanced_settings_send_read_receipts_description" = "If turned off, your read receipts won't be sent to anyone. You will still receive read receipts from other users.";
Expand Down
8 changes: 4 additions & 4 deletions ElementX/Sources/Application/AppSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ final class AppSettings {
case pusherProfileTag
case logLevel
case viewSourceEnabled
case optimizeMediaUploads
case appAppearance
case sharePresence
case hideUnreadMessagesBadge
Expand All @@ -42,7 +43,6 @@ final class AppSettings {

// Feature flags
case slidingSyncDiscovery
case optimizeMediaUploads
case publicSearchEnabled
case fuzzyRoomListSearchEnabled
case enableOnlySignedDeviceIsolationMode
Expand Down Expand Up @@ -237,6 +237,9 @@ final class AppSettings {

@UserPreference(key: UserDefaultsKeys.viewSourceEnabled, defaultValue: isDevelopmentBuild, storageType: .userDefaults(store))
var viewSourceEnabled

@UserPreference(key: UserDefaultsKeys.optimizeMediaUploads, defaultValue: true, storageType: .userDefaults(store))
var optimizeMediaUploads

// MARK: - Element Call

Expand Down Expand Up @@ -275,9 +278,6 @@ final class AppSettings {
@UserPreference(key: UserDefaultsKeys.slidingSyncDiscovery, defaultValue: .native, storageType: .userDefaults(store))
var slidingSyncDiscovery: SlidingSyncDiscovery

@UserPreference(key: UserDefaultsKeys.optimizeMediaUploads, defaultValue: false, storageType: .userDefaults(store))
var optimizeMediaUploads

@UserPreference(key: UserDefaultsKeys.knockingEnabled, defaultValue: false, storageType: .userDefaults(store))
var knockingEnabled

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ struct SettingsFlowCoordinatorParameters {
let appSettings: AppSettings
let navigationSplitCoordinator: NavigationSplitCoordinator
let userIndicatorController: UserIndicatorControllerProtocol
let analytics: AnalyticsService
}

class SettingsFlowCoordinator: FlowCoordinatorProtocol {
Expand Down Expand Up @@ -174,7 +175,7 @@ class SettingsFlowCoordinator: FlowCoordinatorProtocol {

private func presentAnalyticsScreen() {
let coordinator = AnalyticsSettingsScreenCoordinator(parameters: .init(appSettings: parameters.appSettings,
analytics: ServiceLocator.shared.analytics))
analytics: parameters.analytics))
navigationStackCoordinator?.push(coordinator)
}

Expand Down Expand Up @@ -221,7 +222,8 @@ class SettingsFlowCoordinator: FlowCoordinatorProtocol {
}

private func presentAdvancedSettings() {
let coordinator = AdvancedSettingsScreenCoordinator()
let coordinator = AdvancedSettingsScreenCoordinator(parameters: .init(appSettings: parameters.appSettings,
analytics: parameters.analytics))
navigationStackCoordinator.push(coordinator)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ class UserSessionFlowCoordinator: FlowCoordinatorProtocol {
secureBackupController: userSession.clientProxy.secureBackupController,
appSettings: appSettings,
navigationSplitCoordinator: navigationSplitCoordinator,
userIndicatorController: ServiceLocator.shared.userIndicatorController))
userIndicatorController: ServiceLocator.shared.userIndicatorController,
analytics: analytics))

onboardingFlowCoordinator = OnboardingFlowCoordinator(userSession: userSession,
appLockService: appLockService,
Expand Down
4 changes: 2 additions & 2 deletions ElementX/Sources/Generated/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -842,9 +842,9 @@ internal enum L10n {
internal static var screenAdvancedSettingsElementCallBaseUrlDescription: String { return L10n.tr("Localizable", "screen_advanced_settings_element_call_base_url_description") }
/// Invalid URL, please make sure you include the protocol (http/https) and the correct address.
internal static var screenAdvancedSettingsElementCallBaseUrlValidationError: String { return L10n.tr("Localizable", "screen_advanced_settings_element_call_base_url_validation_error") }
/// Optimize for upload
/// Upload photos and videos faster and reduce data usage
internal static var screenAdvancedSettingsMediaCompressionDescription: String { return L10n.tr("Localizable", "screen_advanced_settings_media_compression_description") }
/// Media
/// Optimise media quality
internal static var screenAdvancedSettingsMediaCompressionTitle: String { return L10n.tr("Localizable", "screen_advanced_settings_media_compression_title") }
/// Disable the rich text editor to type Markdown manually.
internal static var screenAdvancedSettingsRichTextEditorDescription: String { return L10n.tr("Localizable", "screen_advanced_settings_rich_text_editor_description") }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@
import Combine
import SwiftUI

struct AdvancedSettingsScreenCoordinatorParameters {
let appSettings: AppSettings
let analytics: AnalyticsService
}

final class AdvancedSettingsScreenCoordinator: CoordinatorProtocol {
private var viewModel: AdvancedSettingsScreenViewModelProtocol

init() {
viewModel = AdvancedSettingsScreenViewModel(advancedSettings: ServiceLocator.shared.settings)
init(parameters: AdvancedSettingsScreenCoordinatorParameters) {
viewModel = AdvancedSettingsScreenViewModel(advancedSettings: parameters.appSettings, analytics: parameters.analytics)
}

func toPresentable() -> AnyView {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,16 @@ struct AdvancedSettingsScreenViewStateBindings {
}
}

enum AdvancedSettingsScreenViewAction { }
enum AdvancedSettingsScreenViewAction {
case optimizeMediaUploadsChanged
}

protocol AdvancedSettingsProtocol: AnyObject {
var viewSourceEnabled: Bool { get set }
var appAppearance: AppAppearance { get set }
var sharePresence: Bool { get set }

var optimizeMediaUploads: Bool { get set }
}

extension AppSettings: AdvancedSettingsProtocol { }
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,20 @@ import SwiftUI
typealias AdvancedSettingsScreenViewModelType = StateStoreViewModel<AdvancedSettingsScreenViewState, AdvancedSettingsScreenViewAction>

class AdvancedSettingsScreenViewModel: AdvancedSettingsScreenViewModelType, AdvancedSettingsScreenViewModelProtocol {
init(advancedSettings: AdvancedSettingsProtocol) {
let bindings = AdvancedSettingsScreenViewStateBindings(advancedSettings: advancedSettings)
let state = AdvancedSettingsScreenViewState(bindings: bindings)
private let analytics: AnalyticsService

init(advancedSettings: AdvancedSettingsProtocol, analytics: AnalyticsService) {
self.analytics = analytics

let state = AdvancedSettingsScreenViewState(bindings: .init(advancedSettings: advancedSettings))
super.init(initialViewState: state)
}

override func process(viewAction: AdvancedSettingsScreenViewAction) { }
override func process(viewAction: AdvancedSettingsScreenViewAction) {
switch viewAction {
case .optimizeMediaUploadsChanged:
// Note: Using a view action here as sinking the AppSettings publisher tracks the initial value.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

analytics.trackInteraction(name: state.bindings.optimizeMediaUploads ? .MobileSettingsOptimizeMediaUploadsEnabled : .MobileSettingsOptimizeMediaUploadsDisabled)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,20 @@ struct AdvancedSettingsScreen: View {
kind: .picker(selection: $context.appAppearance,
items: AppAppearance.allCases.map { (title: $0.name, tag: $0) }))

ListRow(label: .plain(title: L10n.actionViewSource),
ListRow(label: .plain(title: L10n.actionViewSource,
description: L10n.screenAdvancedSettingsViewSourceDescription),
kind: .toggle($context.viewSourceEnabled))

ListRow(label: .plain(title: L10n.screenAdvancedSettingsSharePresence,
description: L10n.screenAdvancedSettingsSharePresenceDescription),
kind: .toggle($context.sharePresence))

ListRow(label: .plain(title: L10n.screenAdvancedSettingsMediaCompressionTitle,
description: L10n.screenAdvancedSettingsMediaCompressionDescription),
kind: .toggle($context.optimizeMediaUploads))
.onChange(of: context.optimizeMediaUploads) {
context.send(viewAction: .optimizeMediaUploadsChanged)
}
}
}
.compoundList()
Expand All @@ -48,7 +56,8 @@ private extension AppAppearance {
// MARK: - Previews

struct AdvancedSettingsScreen_Previews: PreviewProvider, TestablePreview {
static let viewModel = AdvancedSettingsScreenViewModel(advancedSettings: ServiceLocator.shared.settings)
static let viewModel = AdvancedSettingsScreenViewModel(advancedSettings: ServiceLocator.shared.settings,
analytics: ServiceLocator.shared.analytics)
static var previews: some View {
NavigationStack {
AdvancedSettingsScreen(context: viewModel.context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ protocol DeveloperOptionsProtocol: AnyObject {
var hideUnreadMessagesBadge: Bool { get set }
var fuzzyRoomListSearchEnabled: Bool { get set }
var hideTimelineMedia: Bool { get set }
var optimizeMediaUploads: Bool { get set }
var enableOnlySignedDeviceIsolationMode: Bool { get set }
var elementCallBaseURLOverride: URL? { get set }
var knockingEnabled: Bool { get set }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,6 @@ struct DeveloperOptionsScreen: View {
}
}

Section("Media") {
Toggle(isOn: $context.optimizeMediaUploads) {
Text("Optimise for upload")
}
}

Section {
Toggle(isOn: $context.enableOnlySignedDeviceIsolationMode) {
Text("Exclude insecure devices when sending/receiving messages")
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions UnitTests/Sources/MediaUploadingPreprocessorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ final class MediaUploadingPreprocessorTests: XCTestCase {
override func setUp() {
AppSettings.resetAllSettings()
appSettings = AppSettings()
appSettings.optimizeMediaUploads = false
ServiceLocator.shared.register(appSettings: appSettings)
mediaUploadingPreprocessor = MediaUploadingPreprocessor(appSettings: appSettings)
}
Expand Down
2 changes: 1 addition & 1 deletion project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ packages:
# path: ../compound-ios
AnalyticsEvents:
url: https://github.com/matrix-org/matrix-analytics-events
minorVersion: 0.27.0
minorVersion: 0.28.0
# path: ../matrix-analytics-events
Emojibase:
url: https://github.com/matrix-org/emojibase-bindings
Expand Down
Loading