Skip to content

Commit

Permalink
Move the media caption composer (and Add Caption action) behind a fea…
Browse files Browse the repository at this point in the history
…ture flag for now.
  • Loading branch information
pixlwave committed Nov 26, 2024
1 parent 3698084 commit 93c2d30
Show file tree
Hide file tree
Showing 14 changed files with 37 additions and 10 deletions.
4 changes: 4 additions & 0 deletions ElementX/Sources/Application/AppSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ final class AppSettings {
case fuzzyRoomListSearchEnabled
case enableOnlySignedDeviceIsolationMode
case knockingEnabled
case createMediaCaptionsEnabled
}

private static var suiteName: String = InfoPlistReader.main.appGroupIdentifier
Expand Down Expand Up @@ -280,6 +281,9 @@ final class AppSettings {
@UserPreference(key: UserDefaultsKeys.knockingEnabled, defaultValue: false, storageType: .userDefaults(store))
var knockingEnabled

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

#endif

// MARK: - Shared
Expand Down
3 changes: 2 additions & 1 deletion ElementX/Sources/FlowCoordinators/RoomFlowCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,8 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol {
roomProxy: roomProxy,
mediaUploadingPreprocessor: MediaUploadingPreprocessor(appSettings: appSettings),
title: url.lastPathComponent,
url: url)
url: url,
createMediaCaptionsEnabled: appSettings.createMediaCaptionsEnabled)

let mediaUploadPreviewScreenCoordinator = MediaUploadPreviewScreenCoordinator(parameters: parameters)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ struct MediaUploadPreviewScreenCoordinatorParameters {
let mediaUploadingPreprocessor: MediaUploadingPreprocessor
let title: String?
let url: URL
let createMediaCaptionsEnabled: Bool
}

enum MediaUploadPreviewScreenCoordinatorAction {
Expand All @@ -34,7 +35,8 @@ final class MediaUploadPreviewScreenCoordinator: CoordinatorProtocol {
roomProxy: parameters.roomProxy,
mediaUploadingPreprocessor: parameters.mediaUploadingPreprocessor,
title: parameters.title,
url: parameters.url)
url: parameters.url,
createMediaCaptionsEnabled: parameters.createMediaCaptionsEnabled)
}

func start() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ enum MediaUploadPreviewScreenViewModelAction {
struct MediaUploadPreviewScreenViewState: BindableState {
let url: URL
let title: String?
let showMediaCaptionComposer: Bool
var shouldDisableInteraction = false

var bindings = MediaUploadPreviewScreenBindings()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@ class MediaUploadPreviewScreenViewModel: MediaUploadPreviewScreenViewModelType,
roomProxy: JoinedRoomProxyProtocol,
mediaUploadingPreprocessor: MediaUploadingPreprocessor,
title: String?,
url: URL) {
url: URL,
createMediaCaptionsEnabled: Bool) {
self.userIndicatorController = userIndicatorController
self.roomProxy = roomProxy
self.mediaUploadingPreprocessor = mediaUploadingPreprocessor
self.url = url

super.init(initialViewState: MediaUploadPreviewScreenViewState(url: url, title: title))
super.init(initialViewState: MediaUploadPreviewScreenViewState(url: url, title: title, showMediaCaptionComposer: createMediaCaptionsEnabled))
}

override func process(viewAction: MediaUploadPreviewScreenViewAction) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ struct MediaUploadPreviewScreen: View {
.id(context.viewState.url)
.ignoresSafeArea(edges: [.horizontal])
.safeAreaInset(edge: .bottom, spacing: 0) {
composer
.padding(.horizontal, 12)
.padding(.vertical, 16)
.background() // Don't use compound so we match the QLPreviewController.
if context.viewState.showMediaCaptionComposer {
composer
.padding(.horizontal, 12)
.padding(.vertical, 16)
.background() // Don't use compound so we match the QLPreviewController.
}
}
.navigationTitle(title)
.navigationBarTitleDisplayMode(.inline)
Expand Down Expand Up @@ -156,7 +158,8 @@ struct MediaUploadPreviewScreen_Previews: PreviewProvider, TestablePreview {
roomProxy: JoinedRoomProxyMock(),
mediaUploadingPreprocessor: MediaUploadingPreprocessor(appSettings: ServiceLocator.shared.settings),
title: "App Icon.png",
url: snapshotURL)
url: snapshotURL,
createMediaCaptionsEnabled: true)
static var previews: some View {
NavigationStack {
MediaUploadPreviewScreen(context: viewModel.context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ struct PinnedEventsTimelineScreen: View {
pinnedEventIDs: timelineContext.viewState.pinnedEventIDs,
isDM: timelineContext.viewState.isEncryptedOneToOneRoom,
isViewSourceEnabled: timelineContext.viewState.isViewSourceEnabled,
isCreateMediaCaptionsEnabled: timelineContext.viewState.isCreateMediaCaptionsEnabled,
isPinnedEventsTimeline: timelineContext.viewState.isPinnedEventsTimeline,
emojiProvider: timelineContext.viewState.emojiProvider)
.makeActions()
Expand Down
1 change: 1 addition & 0 deletions ElementX/Sources/Screens/RoomScreen/View/RoomScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ struct RoomScreen: View {
pinnedEventIDs: timelineContext.viewState.pinnedEventIDs,
isDM: timelineContext.viewState.isEncryptedOneToOneRoom,
isViewSourceEnabled: timelineContext.viewState.isViewSourceEnabled,
isCreateMediaCaptionsEnabled: timelineContext.viewState.isCreateMediaCaptionsEnabled,
isPinnedEventsTimeline: timelineContext.viewState.isPinnedEventsTimeline,
emojiProvider: timelineContext.viewState.emojiProvider)
.makeActions()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ protocol DeveloperOptionsProtocol: AnyObject {
var enableOnlySignedDeviceIsolationMode: Bool { get set }
var elementCallBaseURLOverride: URL? { get set }
var knockingEnabled: Bool { get set }
var createMediaCaptionsEnabled: Bool { get set }
}

extension AppSettings: DeveloperOptionsProtocol { }
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ struct DeveloperOptionsScreen: View {
Toggle(isOn: $context.hideTimelineMedia) {
Text("Hide image & video previews")
}

Toggle(isOn: $context.createMediaCaptionsEnabled) {
Text("Allow creation of media captions")
}
}

Section("Join rules") {
Expand Down
1 change: 1 addition & 0 deletions ElementX/Sources/Screens/Timeline/TimelineModels.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ struct TimelineViewState: BindableState {
var canCurrentUserRedactSelf = false
var canCurrentUserPin = false
var isViewSourceEnabled: Bool
var isCreateMediaCaptionsEnabled: Bool
var hideTimelineMedia: Bool

// The `pinnedEventIDs` are used only to determine if an item is already pinned or not.
Expand Down
5 changes: 5 additions & 0 deletions ElementX/Sources/Screens/Timeline/TimelineViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class TimelineViewModel: TimelineViewModelType, TimelineViewModelProtocol {
timelineViewState: TimelineState(focussedEvent: focussedEventID.map { .init(eventID: $0, appearance: .immediate) }),
ownUserID: roomProxy.ownUserID,
isViewSourceEnabled: appSettings.viewSourceEnabled,
isCreateMediaCaptionsEnabled: appSettings.createMediaCaptionsEnabled,
hideTimelineMedia: appSettings.hideTimelineMedia,
pinnedEventIDs: roomProxy.infoPublisher.value.pinnedEventIDs,
bindings: .init(reactionsCollapsed: [:]),
Expand Down Expand Up @@ -447,6 +448,10 @@ class TimelineViewModel: TimelineViewModelType, TimelineViewModelProtocol {
.weakAssign(to: \.state.isViewSourceEnabled, on: self)
.store(in: &cancellables)

appSettings.$createMediaCaptionsEnabled
.weakAssign(to: \.state.isCreateMediaCaptionsEnabled, on: self)
.store(in: &cancellables)

appSettings.$hideTimelineMedia
.weakAssign(to: \.state.hideTimelineMedia, on: self)
.store(in: &cancellables)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ struct TimelineItemMenuActionProvider {
let pinnedEventIDs: Set<String>
let isDM: Bool
let isViewSourceEnabled: Bool
let isCreateMediaCaptionsEnabled: Bool
let isPinnedEventsTimeline: Bool
let emojiProvider: EmojiProviderProtocol

Expand Down Expand Up @@ -68,7 +69,7 @@ struct TimelineItemMenuActionProvider {
if let messageItem = item as? EventBasedMessageTimelineItemProtocol, messageItem.supportsMediaCaption {
if messageItem.hasMediaCaption {
actions.append(contentsOf: [.editCaption, .removeCaption])
} else {
} else if isCreateMediaCaptionsEnabled {
actions.append(.addCaption)
}
} else if !(item is VoiceMessageRoomTimelineItem) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ struct TimelineItemBubbledStylerView<Content: View>: View {
pinnedEventIDs: context.viewState.pinnedEventIDs,
isDM: context.viewState.isEncryptedOneToOneRoom,
isViewSourceEnabled: context.viewState.isViewSourceEnabled,
isCreateMediaCaptionsEnabled: context.viewState.isCreateMediaCaptionsEnabled,
isPinnedEventsTimeline: context.viewState.isPinnedEventsTimeline,
emojiProvider: context.viewState.emojiProvider)
TimelineItemMacContextMenu(item: timelineItem, actionProvider: provider) { action in
Expand Down

0 comments on commit 93c2d30

Please sign in to comment.