Skip to content

Commit

Permalink
Filter out some actions for failed local echoes (#1184)
Browse files Browse the repository at this point in the history
* done

* pr suggestion
  • Loading branch information
Velin92 authored Jun 27, 2023
1 parent 13f5ec8 commit f54eb78
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 23 deletions.
27 changes: 20 additions & 7 deletions ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -354,16 +354,16 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
var actions: [TimelineItemMenuAction] = [
.reply
]
if timelineItem is EventBasedMessageTimelineItemProtocol {

if item.isMessage {
actions.append(.forward(itemID: itemId))
}

if item.isEditable {
actions.append(.edit)
}
if timelineItem is EventBasedMessageTimelineItemProtocol {

if item.isMessage {
actions.append(.copy)
}

Expand All @@ -381,7 +381,15 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
case let .megolmV1AesSha2(sessionID) = item.encryptionType {
debugActions.append(.retryDecryption(sessionID: sessionID))
}


if item.hasFailedToSend {
actions = actions.filter(\.canAppearInFailedEcho)
}

if item.isRedacted {
actions = actions.filter(\.canAppearInRedacted)
}

return .init(actions: actions, debugActions: debugActions)
}

Expand Down Expand Up @@ -416,7 +424,12 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
}
case .redact:
Task {
await timelineController.redact(itemID)
if eventTimelineItem.hasFailedToSend,
let transactionID = eventTimelineItem.properties.transactionID {
await timelineController.cancelSend(transactionID)
} else {
await timelineController.redact(itemID)
}
}
case .reply:
state.bindings.composerFocused = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ struct TimelineItemBubbledStylerView<Content: View>: View {

@ViewBuilder
var interactiveLocalizedSendInfo: some View {
if timelineItem.properties.deliveryStatus == .sendingFailed {
if timelineItem.hasFailedToSend {
backgroundedLocalizedSendInfo
.onTapGesture {
context.sendFailedConfirmationDialogInfo = .init(transactionID: timelineItem.properties.transactionID)
Expand Down Expand Up @@ -186,12 +186,12 @@ struct TimelineItemBubbledStylerView<Content: View>: View {
Text(timelineItem.timestamp)
}

if timelineItem.properties.deliveryStatus == .sendingFailed {
if timelineItem.hasFailedToSend {
Image(systemName: "exclamationmark.circle.fill")
}
}
.font(.compound.bodyXS)
.foregroundColor(timelineItem.properties.deliveryStatus == .sendingFailed ? .compound.textCriticalPrimary : .compound.textSecondary)
.foregroundColor(timelineItem.hasFailedToSend ? .compound.textCriticalPrimary : .compound.textSecondary)
.padding(.bottom, shouldFillBubble ? 0 : -4)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ extension TextBasedRoomTimelineViewProtocol {
}

// To account for the extra spacing created by the alert icon
if timelineItem.properties.deliveryStatus == .sendingFailed {
if timelineItem.hasFailedToSend {
whiteSpaces += 3
}

Expand Down
46 changes: 34 additions & 12 deletions ElementX/Sources/Screens/RoomScreen/View/TimelineItemMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,24 @@ enum TimelineItemMenuAction: Identifiable, Hashable {
return true
}
}

var canAppearInFailedEcho: Bool {
switch self {
case .copy, .redact, .viewSource:
return true
default:
return false
}
}

var canAppearInRedacted: Bool {
switch self {
case .viewSource:
return true
default:
return false
}
}
}

public struct TimelineItemMenu: View {
Expand All @@ -70,17 +88,21 @@ public struct TimelineItemMenu: View {

ScrollView {
VStack(alignment: .leading, spacing: 0.0) {
reactionsSection
.padding(.top, 4.0)
.padding(.bottom, 8.0)

Divider()
.background(Color.compound.bgSubtlePrimary)

viewsForActions(actions.actions)

Divider()
.background(Color.compound.bgSubtlePrimary)
if !item.isRedacted, !item.hasFailedToSend {
reactionsSection
.padding(.top, 4.0)
.padding(.bottom, 8.0)

Divider()
.background(Color.compound.bgSubtlePrimary)
}

if !actions.actions.isEmpty {
viewsForActions(actions.actions)

Divider()
.background(Color.compound.bgSubtlePrimary)
}

viewsForActions(actions.debugActions)
}
Expand Down Expand Up @@ -238,7 +260,7 @@ public struct TimelineItemMenu: View {

struct TimelineItemMenu_Previews: PreviewProvider {
static let viewModel = RoomScreenViewModel.mock

static var previews: some View {
VStack {
if let item = RoomTimelineItemFixtures.singleMessageChunk.first as? EventBasedTimelineItemProtocol,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class MockRoomTimelineController: RoomTimelineControllerProtocol {
func editMessage(_ newMessage: String, original itemID: String) async { }

func redact(_ itemID: String) async { }

func cancelSend(_ transactionID: String) async { }

func debugInfo(for itemID: String) -> TimelineItemDebugInfo {
.init(model: "Mock debug description", originalJSON: nil, latestEditJSON: nil)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ class RoomTimelineController: RoomTimelineControllerProtocol {
MXLog.error("Failed redacting message with error: \(error)")
}
}

func cancelSend(_ transactionID: String) async {
MXLog.info("Cancelling send in \(roomID)")
await roomProxy.cancelSend(transactionID: transactionID)
}

// Handle this parallel to the timeline items so we're not forced
// to bundle the Rust side objects within them
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ protocol RoomTimelineControllerProtocol {
func toggleReaction(_ reaction: String, to itemID: String) async

func redact(_ itemID: String) async

func cancelSend(_ transactionID: String) async

func debugInfo(for itemID: String) -> TimelineItemDebugInfo

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,16 @@ extension EventBasedTimelineItemProtocol {
var description: String {
"\(String(describing: Self.self)): id: \(id), timestamp: \(timestamp), isOutgoing: \(isOutgoing), properties: \(properties)"
}

var hasFailedToSend: Bool {
properties.deliveryStatus == .sendingFailed
}

var isMessage: Bool {
self is EventBasedMessageTimelineItemProtocol
}

var isRedacted: Bool {
self is RedactedRoomTimelineItem
}
}
1 change: 1 addition & 0 deletions changelog.d/1151.change
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Filter out some message actions and reactions for failed local echoes and redacted messages.

0 comments on commit f54eb78

Please sign in to comment.