mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-04 01:20:12 +00:00
Redaction reason (#6098)
This commit is contained in:
@@ -19,6 +19,7 @@ enum TimelineInteractionHandlerAction {
|
||||
case displayEditPollForm(eventID: String, poll: Poll)
|
||||
|
||||
case showActionMenu(TimelineItemActionMenuInfo)
|
||||
case showRedactConfirmation(itemID: TimelineItemIdentifier)
|
||||
case showDebugInfo(TimelineItemDebugInfo)
|
||||
|
||||
case displayAudioRecorderPermissionError
|
||||
@@ -114,13 +115,24 @@ class TimelineInteractionHandler {
|
||||
}
|
||||
}
|
||||
|
||||
// swiftlint:disable:next cyclomatic_complexity
|
||||
func handleTimelineItemMenuAction(_ action: TimelineItemMenuAction, itemID: TimelineItemIdentifier) {
|
||||
func redact(_ itemID: TimelineItemIdentifier, reason: String?) {
|
||||
// Redacting needs the event alone, so it works even when the item isn't part of this timeline,
|
||||
// such as one held by a media preview that was built from a different one.
|
||||
guard case let .event(_, eventOrTransactionID) = itemID else { fatalError() }
|
||||
Task { await timelineController.redact(eventOrTransactionID, reason: reason) }
|
||||
}
|
||||
|
||||
// swiftlint:disable:next cyclomatic_complexity
|
||||
func handleTimelineItemMenuAction(_ action: TimelineItemMenuAction, itemID: TimelineItemIdentifier) {
|
||||
if case .redact = action {
|
||||
guard case let .event(_, eventOrTransactionID) = itemID else { fatalError() }
|
||||
Task { await timelineController.redact(eventOrTransactionID) }
|
||||
// An unsent message is only dropped from the send queue. No redaction event reaches
|
||||
// the server, so there is nothing to attach a reason to, and asking for one would
|
||||
// only delay the abort while the message might still go out.
|
||||
if case .event(_, .eventID) = itemID {
|
||||
actionsSubject.send(.showRedactConfirmation(itemID: itemID))
|
||||
} else {
|
||||
redact(itemID, reason: nil)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -66,6 +66,8 @@ enum TimelineViewAction {
|
||||
|
||||
case displayTimelineItemMenu(itemID: TimelineItemIdentifier)
|
||||
case handleTimelineItemMenuAction(itemID: TimelineItemIdentifier, action: TimelineItemMenuAction)
|
||||
/// The user has confirmed the removal of an item, optionally giving a reason.
|
||||
case redactConfirmed(itemID: TimelineItemIdentifier, reason: String?)
|
||||
|
||||
case tappedOnSenderDetails(sender: TimelineItemSender)
|
||||
case displayReactionSummary(itemID: TimelineItemIdentifier, key: String)
|
||||
@@ -189,6 +191,8 @@ struct TimelineViewStateBindings {
|
||||
|
||||
var manageMemberViewModel: ManageRoomMemberSheetViewModel?
|
||||
|
||||
var redactConfirmationInfo: TimelineRedactConfirmationInfo?
|
||||
|
||||
var showTranslation = false
|
||||
var textToBeTranslated: String?
|
||||
}
|
||||
@@ -219,6 +223,11 @@ struct ReadReceiptSummaryInfo: Identifiable {
|
||||
let id: TimelineItemIdentifier
|
||||
}
|
||||
|
||||
/// The item that the user has asked to remove and must confirm, optionally giving a reason.
|
||||
struct TimelineRedactConfirmationInfo: Identifiable {
|
||||
let id: TimelineItemIdentifier
|
||||
}
|
||||
|
||||
enum TimelineAlertInfoType: Hashable {
|
||||
case audioRecodingPermissionError
|
||||
case pollEndConfirmation(String)
|
||||
|
||||
@@ -198,6 +198,10 @@ class TimelineViewModel: TimelineViewModelType, TimelineViewModelProtocol {
|
||||
timelineInteractionHandler.displayTimelineItemActionMenu(for: itemID)
|
||||
case .handleTimelineItemMenuAction(let itemID, let action):
|
||||
timelineInteractionHandler.handleTimelineItemMenuAction(action, itemID: itemID)
|
||||
case .redactConfirmed(let itemID, let reason):
|
||||
state.bindings.redactConfirmationInfo = nil
|
||||
// A blank reason is no reason at all, so don't send one.
|
||||
timelineInteractionHandler.redact(itemID, reason: reason?.isBlank == false ? reason : nil)
|
||||
case .tappedOnSenderDetails(let sender):
|
||||
handleTappedOnSenderDetails(sender: sender)
|
||||
case .displayEmojiPicker(let itemID):
|
||||
@@ -533,6 +537,8 @@ class TimelineViewModel: TimelineViewModelType, TimelineViewModelProtocol {
|
||||
} else {
|
||||
self.state.bindings.actionMenuInfo = actionMenuInfo
|
||||
}
|
||||
case .showRedactConfirmation(let itemID):
|
||||
state.bindings.redactConfirmationInfo = .init(id: itemID)
|
||||
case .showDebugInfo(let debugInfo):
|
||||
state.bindings.debugInfo = debugInfo
|
||||
case .viewInRoomTimeline(let eventID):
|
||||
@@ -1121,7 +1127,7 @@ class TimelineViewModel: TimelineViewModelType, TimelineViewModelProtocol {
|
||||
verticalButtons: sendHandle.map { sendHandle in
|
||||
[.init(title: L10n.actionRetry) { [weak self] in self?.retrySending(sendHandle) },
|
||||
.init(title: L10n.actionRemoveMessage, role: .destructive) { [weak self] in
|
||||
self?.timelineInteractionHandler.handleTimelineItemMenuAction(.redact(isMedia: false), itemID: sendHandle.itemID)
|
||||
self?.timelineInteractionHandler.redact(sendHandle.itemID, reason: nil)
|
||||
}]
|
||||
})
|
||||
case .encryptionAuthenticity(let message):
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
//
|
||||
// Copyright 2026 Element Creations Ltd.
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
||||
// Please see LICENSE files in the repository root for full details.
|
||||
//
|
||||
|
||||
import Compound
|
||||
import SwiftUI
|
||||
|
||||
/// Asks the user to confirm removing a message, letting them give an optional reason.
|
||||
struct RedactConfirmationView: View {
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
|
||||
@State var reason = ""
|
||||
let confirm: (String) -> Void
|
||||
|
||||
@State private var sheetHeight: CGFloat = .zero
|
||||
private let topPadding: CGFloat = 44 // For the navigation bar
|
||||
|
||||
var body: some View {
|
||||
ElementNavigationStack {
|
||||
ScrollView {
|
||||
VStack(spacing: 0) {
|
||||
header
|
||||
TextField(L10n.screenRoomConfirmRemovalReasonPlaceholder, text: $reason)
|
||||
.textFieldStyle(.compound(labelText: L10n.screenRoomConfirmRemovalReasonLabel))
|
||||
buttons
|
||||
}
|
||||
.padding(.horizontal, 24)
|
||||
.padding(.bottom, 16)
|
||||
.readHeight($sheetHeight)
|
||||
}
|
||||
.scrollBounceBehavior(.basedOnSize)
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .primaryAction) {
|
||||
ToolbarButton(role: .close) { dismiss() }
|
||||
}
|
||||
}
|
||||
}
|
||||
.presentationDetents([.height(sheetHeight + topPadding)])
|
||||
.presentationDragIndicator(.hidden)
|
||||
.presentationBackground(.compound.bgCanvasDefault)
|
||||
.interactiveDismissDisabled()
|
||||
}
|
||||
|
||||
private var header: some View {
|
||||
VStack(spacing: 8) {
|
||||
Text(L10n.screenRoomConfirmRemovalTitle)
|
||||
.font(.compound.headingMDBold)
|
||||
.foregroundStyle(.compound.textPrimary)
|
||||
|
||||
Text(L10n.screenRoomConfirmRemovalMessage)
|
||||
.font(.compound.bodyLG)
|
||||
.foregroundStyle(.compound.textSecondary)
|
||||
}
|
||||
.multilineTextAlignment(.center)
|
||||
.padding(.top, 8)
|
||||
.padding(.bottom, 24)
|
||||
}
|
||||
|
||||
private var buttons: some View {
|
||||
ViewThatFits {
|
||||
HStack(spacing: 12) {
|
||||
cancelButton
|
||||
removeButton
|
||||
}
|
||||
|
||||
VStack(spacing: 16) {
|
||||
removeButton
|
||||
cancelButton
|
||||
}
|
||||
}
|
||||
.padding(.top, 24)
|
||||
}
|
||||
|
||||
private var cancelButton: some View {
|
||||
Button(L10n.actionCancel) {
|
||||
dismiss()
|
||||
}
|
||||
.buttonStyle(.compound(.secondary))
|
||||
}
|
||||
|
||||
private var removeButton: some View {
|
||||
Button(L10n.actionRemove, role: .destructive) {
|
||||
confirm(reason)
|
||||
}
|
||||
.buttonStyle(.compound(.primary))
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Previews
|
||||
|
||||
struct RedactConfirmationView_Previews: PreviewProvider, TestablePreview {
|
||||
static var previews: some View {
|
||||
RedactConfirmationView { _ in }
|
||||
.previewDisplayName("Empty")
|
||||
|
||||
RedactConfirmationView(reason: "Posted in the wrong room.") { _ in }
|
||||
.previewDisplayName("Reason")
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,11 @@ struct TimelineView: View {
|
||||
ManageRoomMemberSheetView(context: $0.context)
|
||||
}
|
||||
.sheet(item: $timelineContext.debugInfo) { TimelineItemDebugView(info: $0) }
|
||||
.sheet(item: $timelineContext.redactConfirmationInfo) { info in
|
||||
RedactConfirmationView { reason in
|
||||
timelineContext.send(viewAction: .redactConfirmed(itemID: info.id, reason: reason))
|
||||
}
|
||||
}
|
||||
.sheet(item: $timelineContext.actionMenuInfo) { info in
|
||||
let actions = TimelineItemMenuActionProvider(timelineItem: info.item,
|
||||
canCurrentUserSendMessage: timelineContext.viewState.canCurrentUserSendMessage,
|
||||
|
||||
Reference in New Issue
Block a user