Files
letro-ios/ElementX/Sources/Screens/RoomScreen/View/TimelineItemContextMenu.swift
Stefan Ceriu 03dd2cd84d Add retry decryption encrypted timeline item debug menu option (#384)
* Fixed a couple of warnings (+2 squashed commits)
Squashed commits:
[21fbc3b0] Add changelog
[abb092c6] Add retry decryption encrypted timeline item debug menu option

* Cleanup room list state computations

* Bump the RustSDK to v1.0.25-alpha

* Fix brew CI errors: remove imagemagick and brew lock file entirely

* Fix release script version bumping

* Bump ruby dependencies
2022-12-22 13:59:38 +02:00

104 lines
3.4 KiB
Swift

//
// Copyright 2022 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 SwiftUI
struct TimelineItemContextMenuActions {
let actions: [TimelineItemContextMenuAction]
let debugActions: [TimelineItemContextMenuAction]
}
enum TimelineItemContextMenuAction: Identifiable, Hashable {
case react
case copy
case edit
case quote
case copyPermalink
case redact
case reply
case viewSource
case retryDecryption(sessionId: String)
var id: Self { self }
var switchToDefaultComposer: Bool {
switch self {
case .reply, .edit:
return false
default:
return true
}
}
}
public struct TimelineItemContextMenu: View {
let contextMenuActions: TimelineItemContextMenuActions
let callback: (TimelineItemContextMenuAction) -> Void
@ViewBuilder
public var body: some View {
viewsForActions(contextMenuActions.actions)
Menu {
viewsForActions(contextMenuActions.debugActions)
} label: {
Label("Developer", systemImage: "hammer")
}
}
private func viewsForActions(_ actions: [TimelineItemContextMenuAction]) -> some View {
ForEach(actions, id: \.self) { item in
switch item {
case .react:
Button { callback(item) } label: {
Label(ElementL10n.reactions, systemImage: "face.smiling")
}
case .copy:
Button { callback(item) } label: {
Label(ElementL10n.actionCopy, systemImage: "doc.on.doc")
}
case .edit:
Button { callback(item) } label: {
Label(ElementL10n.edit, systemImage: "pencil")
}
case .quote:
Button { callback(item) } label: {
Label(ElementL10n.actionQuote, systemImage: "quote.bubble")
}
case .copyPermalink:
Button { callback(item) } label: {
Label(ElementL10n.permalink, systemImage: "link")
}
case .reply:
Button { callback(item) } label: {
Label(ElementL10n.reply, systemImage: "arrow.uturn.left")
}
case .redact:
Button(role: .destructive) { callback(item) } label: {
Label(ElementL10n.messageActionItemRedact, systemImage: "trash")
}
case .viewSource:
Button { callback(item) } label: {
Label(ElementL10n.viewSource, systemImage: "doc.text.below.ecg")
}
case .retryDecryption:
Button { callback(item) } label: {
Label(ElementL10n.roomTimelineContextMenuRetryDecryption, systemImage: "arrow.down.message")
}
}
}
}
}