Skip to content

Commit

Permalink
Tidy up.
Browse files Browse the repository at this point in the history
  • Loading branch information
pixlwave committed Feb 3, 2023
1 parent fc0d236 commit ec4de39
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 19 deletions.
30 changes: 16 additions & 14 deletions ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
private let timelineController: RoomTimelineControllerProtocol
private let timelineViewFactory: RoomTimelineViewFactoryProtocol

// swiftlint:disable:next cyclomatic_complexity
init(timelineController: RoomTimelineControllerProtocol,
timelineViewFactory: RoomTimelineViewFactoryProtocol,
mediaProvider: MediaProviderProtocol,
Expand Down Expand Up @@ -188,22 +189,14 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
}
}

/// The task responsible for retrying decryption of any encrypted items in the timeline.
private var retryDecryptionTask: Task<Void, Never>? {
didSet { oldValue?.cancel() }
}

/// Retry decrypting any encrypted items in the timeline.
private func retryDecryption() {
retryDecryptionTask = Task {
for timelineItem in state.items.reversed() {
guard !Task.isCancelled else { break }

guard case let .encrypted(item) = timelineItem,
case let .megolmV1AesSha2(sessionID) = item.encryptionType
else { continue }

MXLog.debug("Retrying decryption for: \(sessionID)")
Task {
let firstEncryptedItem = state.items.first { $0.sessionID != nil }

if let sessionID = firstEncryptedItem?.sessionID {
// Request for the first encrypted item to be decrypted as the SDK
// will continue to decrypt any following items automatically.
await timelineController.retryDecryption(for: sessionID)
}
}
Expand Down Expand Up @@ -309,3 +302,12 @@ extension RoomScreenViewModel {
mediaProvider: MockMediaProvider(),
roomName: "Preview room")
}

private extension RoomTimelineViewProvider {
var sessionID: String? {
guard case let .encrypted(item) = self,
case let .megolmV1AesSha2(sessionID) = item.encryptionType
else { return nil }
return sessionID
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ private struct UITextViewWrapper: UIViewRepresentable {
final class Coordinator: NSObject, UITextViewDelegate, TextViewWithKeyDetectionDelegate {
private var text: Binding<String>
private var focused: Binding<Bool>
// private var isMultiline: Binding<Bool>

private let maxHeight: CGFloat

Expand Down
3 changes: 2 additions & 1 deletion ElementX/Sources/Screens/RoomScreen/View/RoomScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct RoomScreen: View {
var body: some View {
timeline
.background(Color.element.background.ignoresSafeArea()) // Kills the toolbar translucency.
.safeAreaInset(edge: .top, spacing: 0) { encryptionBanner }
.overlay(alignment: .top) { encryptionBanner } // Overlay for now, safeAreaInset breaks timeline offset.
.safeAreaInset(edge: .bottom, spacing: 0) { messageComposer }
.navigationBarTitleDisplayMode(.inline)
.toolbar { toolbar }
Expand Down Expand Up @@ -83,6 +83,7 @@ struct RoomScreen: View {
.fill(Color.element.system)
}
.padding([.horizontal, .top], 16)
.background(Color.element.background)
}
}

Expand Down
1 change: 0 additions & 1 deletion ElementX/Sources/Services/Room/RoomProxyProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ protocol RoomProxyProtocol {
}

extension RoomProxyProtocol {

var permalink: URL? {
if let canonicalAlias, let link = try? PermalinkBuilder.permalinkTo(roomAlias: canonicalAlias) {
return link
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ class RoomTimelineController: RoomTimelineControllerProtocol {
updateTimelineItems()
}

// swiftlint:disable:next cyclomatic_complexity
// swiftlint:disable:next cyclomatic_complexity function_body_length
private func updateTimelineItems() {
var newTimelineItems = [RoomTimelineItemProtocol]()
var canBackPaginate = true
Expand Down
2 changes: 1 addition & 1 deletion changelog.d/430.change
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Update the designs for the timeline.
Finish the design review ready for a public TestFlight.

0 comments on commit ec4de39

Please sign in to comment.