Add redaction menu (disabled).

This commit is contained in:
Doug
2022-09-14 09:40:00 +01:00
parent 4660f096f8
commit bd4a698f8b
12 changed files with 78 additions and 10 deletions
@@ -23,6 +23,7 @@ enum TimelineItemContextMenuAction: Hashable {
case copy
case quote
case copyPermalink
case redact
}
enum RoomScreenViewAction {
@@ -116,7 +116,16 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
return []
}
return [.copy, .quote, .copyPermalink]
let actions: [TimelineItemContextMenuAction] = [
.copy, .quote, .copyPermalink
]
#warning("Outgoing actions to be handled with the new Timeline API.")
// if timelineItem.isOutgoing {
// actions.append(.redact)
// }
return actions
}
private func processContentMenuAction(_ action: TimelineItemContextMenuAction, itemId: String) {
@@ -137,6 +146,8 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
} catch {
displayError(.alert(ElementL10n.roomTimelinePermalinkCreationFailure))
}
case .redact:
redactItem(itemId)
}
}
@@ -148,4 +159,10 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
message: message)
}
}
private func redactItem(_ itemID: String) {
Task {
await timelineController.redactItem(itemID)
}
}
}
@@ -25,16 +25,20 @@ public struct TimelineItemContextMenu: View {
ForEach(contextMenuActions, id: \.self) { item in
switch item {
case .copy:
Button(ElementL10n.actionCopy) {
callback(item)
Button { callback(item) } label: {
Label(ElementL10n.actionCopy, systemImage: "doc.on.doc")
}
case .quote:
Button(ElementL10n.actionQuote) {
callback(item)
Button { callback(item) } label: {
Label(ElementL10n.actionQuote, systemImage: "quote.bubble")
}
case .copyPermalink:
Button(ElementL10n.permalink) {
callback(item)
Button { callback(item) } label: {
Label(ElementL10n.permalink, systemImage: "link")
}
case .redact:
Button(role: .destructive) { callback(item) } label: {
Label(ElementL10n.messageActionItemRedact, systemImage: "trash")
}
}
}
@@ -57,4 +57,8 @@ struct MockRoomProxy: RoomProxyProtocol {
func sendMessage(_ message: String) async -> Result<Void, RoomProxyError> {
.failure(.failedSendingMessage)
}
func redactItem(_ itemId: String) async -> Result<Void, RoomProxyError> {
.failure(.failedRedactingEvent)
}
}
@@ -194,6 +194,22 @@ class RoomProxy: RoomProxyProtocol {
.value
}
func redactItem(_ itemId: String) async -> Result<Void, RoomProxyError> {
return .failure(.failedRedactingEvent)
#warning("Redactions to be enabled on next SDK release.")
// let transactionID = genTransactionId()
//
// return await Task {
// do {
// try room.redact(eventId: itemId, reason: nil, txnId: transactionID)
// return .success(())
// } catch {
// return .failure(.failedRedactingEvent)
// }
// }
// .value
}
// MARK: - Private
fileprivate func appendMessage(_ message: AnyMessage) {
@@ -24,6 +24,7 @@ enum RoomProxyError: Error {
case failedRetrievingMemberAvatarURL
case failedRetrievingMemberDisplayName
case failedSendingMessage
case failedRedactingEvent
}
enum RoomProxyCallback {
@@ -56,5 +57,7 @@ protocol RoomProxyProtocol {
func sendMessage(_ message: String) async -> Result<Void, RoomProxyError>
func redactItem(_ itemId: String) async -> Result<Void, RoomProxyError>
var callbacks: PassthroughSubject<RoomProxyCallback, Never> { get }
}
@@ -57,4 +57,6 @@ class MockRoomTimelineController: RoomTimelineControllerProtocol {
func processItemDisappearance(_ itemId: String) async { }
func sendMessage(_ message: String) async { }
func redactItem(_ itemId: String) async { }
}
@@ -104,6 +104,13 @@ class RoomTimelineController: RoomTimelineControllerProtocol {
}
}
func redactItem(_ itemId: String) async {
switch await timelineProvider.redactItem(itemId) {
default:
break
}
}
// MARK: - Private
@objc private func contentSizeCategoryDidChange() {
@@ -40,4 +40,6 @@ protocol RoomTimelineControllerProtocol {
func paginateBackwards(_ count: UInt) async -> Result<Void, RoomTimelineControllerError>
func sendMessage(_ message: String) async
func redactItem(_ itemId: String) async
}
@@ -59,4 +59,13 @@ class RoomTimelineProvider: RoomTimelineProviderProtocol {
return .failure(.failedSendingMessage)
}
}
func redactItem(_ itemID: String) async -> Result<Void, RoomTimelineProviderError> {
switch await roomProxy.redactItem(itemID) {
case .success:
return .success(())
case .failure:
return .failure(.failedRedactingItem)
}
}
}
@@ -23,6 +23,7 @@ enum RoomTimelineProviderCallback {
enum RoomTimelineProviderError: Error {
case failedSendingMessage
case failedRedactingItem
case generic
}
@@ -35,4 +36,6 @@ protocol RoomTimelineProviderProtocol {
func paginateBackwards(_ count: UInt) async -> Result<Void, RoomTimelineProviderError>
func sendMessage(_ message: String) async -> Result<Void, RoomTimelineProviderError>
func redactItem(_ itemID: String) async -> Result<Void, RoomTimelineProviderError>
}
+3 -3
View File
@@ -32,9 +32,9 @@ include:
packages:
MatrixRustSDK:
url: https://github.com/matrix-org/matrix-rust-components-swift
exactVersion: 1.0.13-alpha
# path: ../matrix-rust-components-swift
# url: https://github.com/matrix-org/matrix-rust-components-swift.git
# exactVersion: 1.0.11-alpha
path: ../matrix-rust-components-swift
DesignKit:
path: ./
AnalyticsEvents: