Skip to content

Commit

Permalink
Update the SDK and enable event permalinks.
Browse files Browse the repository at this point in the history
  • Loading branch information
pixlwave committed Apr 25, 2024
1 parent 76e7de4 commit 522fbcb
Show file tree
Hide file tree
Showing 17 changed files with 71 additions and 63 deletions.
2 changes: 1 addition & 1 deletion ElementX.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7332,7 +7332,7 @@
repositoryURL = "https://github.com/matrix-org/matrix-rust-components-swift";
requirement = {
kind = exactVersion;
version = 1.1.60;
version = 1.1.61;
};
};
821C67C9A7F8CC3FD41B28B4 /* XCRemoteSwiftPackageReference "emojibase-bindings" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/matrix-org/matrix-rust-components-swift",
"state" : {
"revision" : "33cad4cb0c95a39bacdd8845d81da17e8a221481",
"version" : "1.1.60"
"revision" : "8def4c4c5cc5a95699431a509f1dcd55ec9b59d2",
"version" : "1.1.61"
}
},
{
Expand Down
6 changes: 2 additions & 4 deletions ElementX/Sources/Application/Navigation/AppRoutes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,9 @@ struct MatrixPermalinkParser: URLParser {
case .user(let id):
return .userProfile(userID: id)
case .eventOnRoomId(let roomID, let eventID):
// return .event(roomID: roomID, eventID: eventID)
return nil
return .event(roomID: roomID, eventID: eventID)
case .eventOnRoomAlias(let alias, let eventID):
// return .eventOnRoomAlias(alias: alias, eventID: eventID)
return nil
return .eventOnRoomAlias(alias: alias, eventID: eventID)
default:
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion ElementX/Sources/Mocks/RoomProxyMock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ struct RoomProxyMockConfiguration {
mock.underlyingActions = Empty(completeImmediately: false).eraseToAnyPublisher()

let timelineProvider = RoomTimelineProviderMock()
timelineProvider.paginationState = .init(backward: timelineStartReached ? .timelineStartReached : .idle, forward: .timelineStartReached)
timelineProvider.paginationState = .init(backward: timelineStartReached ? .timelineEndReached : .idle, forward: .timelineEndReached)
timelineProvider.underlyingMembershipChangePublisher = PassthroughSubject().eraseToAnyPublisher()
mock.underlyingTimelineProvider = timelineProvider
return mock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class RoomPollsHistoryScreenViewModel: RoomPollsHistoryScreenViewModelType, Room
case .updatedTimelineItems:
self.updatePollsList(filter: state.bindings.filter)
case .paginationState(let paginationState):
let canBackPaginate = paginationState.backward != .timelineStartReached
let canBackPaginate = paginationState.backward != .timelineEndReached
if self.state.canBackPaginate != canBackPaginate {
self.state.canBackPaginate = canBackPaginate
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class RoomScreenInteractionHandler {

if let encryptedItem = timelineItem as? EncryptedRoomTimelineItem {
switch encryptedItem.encryptionType {
case .megolmV1AesSha2(let sessionID):
case .megolmV1AesSha2(let sessionID, _):
debugActions.append(.retryDecryption(sessionID: sessionID))
default:
break
Expand Down
4 changes: 2 additions & 2 deletions ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
switch await timelineController.focusOnEvent(eventID, timelineSize: Constants.detachedTimelineSize) {
case .success:
state.timelineViewState.focussedEventID = eventID
case .failure(let error):
case .failure:
MXLog.error("Failed to focus on event \(eventID)")
displayError(.toast(L10n.commonFailed))
}
Expand Down Expand Up @@ -475,7 +475,7 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
break
}

if state.timelineViewState.paginationState.forward == .timelineStartReached {
if state.timelineViewState.paginationState.forward == .timelineEndReached {
focusLive()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ private struct HighlightedTimelineItemModifier: ViewModifier {
}
}

// swiftlint:disable line_length
struct HighlightedTimelineItemModifier_Previews: PreviewProvider, TestablePreview {
static var previews: some View {
ScrollView {
Expand Down Expand Up @@ -83,3 +84,5 @@ struct HighlightedTimelineItemModifier_Previews: PreviewProvider, TestablePrevie
}
}
}

// swiftlint:enable line_length
2 changes: 1 addition & 1 deletion ElementX/Sources/Services/Client/ClientProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ class ClientProxy: ClientProxyProtocol {
do {
let roomListItem = try roomListService?.room(roomId: identifier)
if roomListItem?.isTimelineInitialized() == false {
try await roomListItem?.initTimeline(eventTypeFilter: eventFilters)
try await roomListItem?.initTimeline(eventTypeFilter: eventFilters, internalIdPrefix: nil)
}
let fullRoom = try await roomListItem?.fullRoom()

Expand Down
15 changes: 7 additions & 8 deletions ElementX/Sources/Services/Room/RoomProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,13 @@ class RoomProxy: RoomProxyProtocol {
}

func timelineFocusedOnEvent(eventID: String, numberOfEvents: UInt16) async -> Result<TimelineProxyProtocol, RoomProxyError> {
.failure(.sdkError(RoomProxyMockError.generic))
// do {
// let timeline = try await room.timelineFocusedOnEvent(eventId: eventID, numContextEvents: numberOfEvents, internalIdPrefix: UUID().uuidString)
// return .success(TimelineProxy(timeline: timeline, isLive: false))
// } catch {
// MXLog.error("Failed to create a timeline focussed on: \(eventID) with error: \(error)")
// return .failure(.sdkError(error))
// }
do {
let timeline = try await room.timelineFocusedOnEvent(eventId: eventID, numContextEvents: numberOfEvents, internalIdPrefix: UUID().uuidString)
return .success(TimelineProxy(timeline: timeline, isLive: false))
} catch {
MXLog.error("Failed to create a timeline focussed on: \(eventID) with error: \(error)")
return .failure(.sdkError(error))
}
}

func redact(_ eventID: String) async -> Result<Void, RoomProxyError> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import Foundation
import MatrixRustSDK

struct PaginationState: Equatable {
static var `default` = PaginationState(backward: .idle, forward: .timelineStartReached)
let backward: BackPaginationStatus
let forward: BackPaginationStatus
static var `default` = PaginationState(backward: .idle, forward: .timelineEndReached)
let backward: PaginationStatus
let forward: PaginationStatus
}

@MainActor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class MockRoomTimelineController: RoomTimelineControllerProtocol {
private var client: UITestsSignalling.Client?

init(listenForSignals: Bool = false) {
callbacks.send(.paginationState(PaginationState(backward: .idle, forward: .timelineStartReached)))
callbacks.send(.paginationState(PaginationState(backward: .idle, forward: .timelineEndReached)))
callbacks.send(.isLive(true))

guard listenForSignals else { return }
Expand All @@ -62,7 +62,7 @@ class MockRoomTimelineController: RoomTimelineControllerProtocol {
}

func paginateBackwards(requestSize: UInt16) async -> Result<Void, RoomTimelineControllerError> {
callbacks.send(.paginationState(PaginationState(backward: .paginating, forward: .timelineStartReached)))
callbacks.send(.paginationState(PaginationState(backward: .paginating, forward: .timelineEndReached)))

if client == nil {
try? await simulateBackPagination()
Expand Down Expand Up @@ -173,8 +173,8 @@ class MockRoomTimelineController: RoomTimelineControllerProtocol {
/// Prepends the next chunk of items to the `timelineItems` array.
private func simulateBackPagination() async throws {
defer {
callbacks.send(.paginationState(PaginationState(backward: backPaginationResponses.isEmpty ? .timelineStartReached : .idle,
forward: .timelineStartReached)))
callbacks.send(.paginationState(PaginationState(backward: backPaginationResponses.isEmpty ? .timelineEndReached : .idle,
forward: .timelineEndReached)))
}

guard !backPaginationResponses.isEmpty else { return }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ class RoomTimelineController: RoomTimelineControllerProtocol {

// Check if we need to add anything to the top of the timeline.
switch paginationState.backward {
case .timelineStartReached:
case .timelineEndReached:
if !roomProxy.isEncryptedOneToOneRoom {
let timelineStart = TimelineStartRoomTimelineItem(name: roomProxy.name)
newTimelineItems.insert(timelineStart, at: 0)
Expand All @@ -335,7 +335,7 @@ class RoomTimelineController: RoomTimelineControllerProtocol {
switch paginationState.forward {
case .paginating:
newTimelineItems.insert(PaginationIndicatorRoomTimelineItem(position: .end), at: newTimelineItems.count)
case .idle, .timelineStartReached:
case .idle, .timelineEndReached:
break
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,16 @@ import UIKit

struct EncryptedRoomTimelineItem: EventBasedTimelineItemProtocol, Equatable {
enum EncryptionType: Hashable {
case megolmV1AesSha2(sessionId: String)
case megolmV1AesSha2(sessionID: String, cause: UTDCause)
case olmV1Curve25519AesSha2(senderKey: String)
case unknown
}

enum UTDCause: Hashable {
case membership
case unknown
}

let id: TimelineItemIdentifier
let body: String
let encryptionType: EncryptionType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,15 @@ struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol {
_ isOutgoing: Bool) -> RoomTimelineItemProtocol {
var encryptionType = EncryptedRoomTimelineItem.EncryptionType.unknown
switch encryptedMessage {
case .megolmV1AesSha2(let sessionId):
encryptionType = .megolmV1AesSha2(sessionId: sessionId)
case .megolmV1AesSha2(let sessionID, let cause):
let cause: EncryptedRoomTimelineItem.UTDCause = switch cause {
case .unknown: .unknown
case .membership: .membership
}
encryptionType = .megolmV1AesSha2(sessionID: sessionID, cause: cause)
case .olmV1Curve25519AesSha2(let senderKey):
encryptionType = .olmV1Curve25519AesSha2(senderKey: senderKey)
default:
case .unknown:
break
}

Expand Down
55 changes: 27 additions & 28 deletions ElementX/Sources/Services/Timeline/TimelineProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ final class TimelineProxy: TimelineProxyProtocol {
// periphery:ignore - retaining purpose
private var timelineListener: RoomTimelineListener?

private let backPaginationStatusSubject = CurrentValueSubject<BackPaginationStatus, Never>(.idle)
private let forwardPaginationStatusSubject = CurrentValueSubject<BackPaginationStatus, Never>(.timelineStartReached)
private let backPaginationStatusSubject = CurrentValueSubject<PaginationStatus, Never>(.idle)
private let forwardPaginationStatusSubject = CurrentValueSubject<PaginationStatus, Never>(.timelineEndReached)
private let timelineUpdatesSubject = PassthroughSubject<[TimelineDiff], Never>()

private let actionsSubject = PassthroughSubject<TimelineProxyAction, Never>()
Expand Down Expand Up @@ -150,7 +150,7 @@ final class TimelineProxy: TimelineProxyProtocol {
MXLog.info("Paginating backwards")

do {
_ = try timeline.paginateBackwards(opts: .simpleRequest(eventLimit: requestSize, waitForToken: true))
_ = try await timeline.paginateBackwards(numEvents: requestSize)
MXLog.info("Finished paginating backwards")

return .success(())
Expand All @@ -161,28 +161,27 @@ final class TimelineProxy: TimelineProxyProtocol {
}

func paginateForwards(requestSize: UInt16) async -> Result<Void, TimelineProxyError> {
.failure(.failedPaginatingBackwards)
// This extra check is necessary as forwards pagination status doesn't support subscribing.
// We need it to make sure we send a valid status after a failure.
// guard forwardPaginationStatusSubject.value == .idle else {
// MXLog.error("Attempting to paginate forwards when already at the end.")
// return .failure(.failedPaginatingBackwards)
// }
//
// MXLog.info("Paginating forwards")
// forwardPaginationStatusSubject.send(.paginating)
//
// do {
// let timelineEndReached = try await timeline.paginateForwards(numEvents: requestSize)
// MXLog.info("Finished paginating forwards")
//
// forwardPaginationStatusSubject.send(timelineEndReached ? .timelineEndReached : .idle)
// return .success(())
// } catch {
// MXLog.error("Failed paginating forwards with error: \(error)")
// forwardPaginationStatusSubject.send(.idle)
// return .failure(.failedPaginatingBackwards)
// }
guard forwardPaginationStatusSubject.value == .idle else {
MXLog.error("Attempting to paginate forwards when already at the end.")
return .failure(.failedPaginatingBackwards)
}

MXLog.info("Paginating forwards")
forwardPaginationStatusSubject.send(.paginating)

do {
let timelineEndReached = try await timeline.focusedPaginateForwards(numEvents: 16)
MXLog.info("Finished paginating forwards")

forwardPaginationStatusSubject.send(timelineEndReached ? .timelineEndReached : .idle)
return .success(())
} catch {
MXLog.error("Failed paginating forwards with error: \(error)")
forwardPaginationStatusSubject.send(.idle)
return .failure(.failedPaginatingBackwards)
}
}

func retryDecryption(for sessionID: String) async {
Expand Down Expand Up @@ -560,7 +559,7 @@ final class TimelineProxy: TimelineProxyProtocol {
}

// Forward pagination doesn't support observation, set the initial state ourself.
forwardPaginationStatusSubject.send(isLive ? .timelineStartReached : .idle)
forwardPaginationStatusSubject.send(isLive ? .timelineEndReached : .idle)
}
}

Expand All @@ -576,14 +575,14 @@ private final class RoomTimelineListener: TimelineListener {
}
}

private final class RoomPaginationStatusListener: BackPaginationStatusListener {
private let onUpdateClosure: (BackPaginationStatus) -> Void
private final class RoomPaginationStatusListener: PaginationStatusListener {
private let onUpdateClosure: (PaginationStatus) -> Void

init(_ onUpdateClosure: @escaping (BackPaginationStatus) -> Void) {
init(_ onUpdateClosure: @escaping (PaginationStatus) -> Void) {
self.onUpdateClosure = onUpdateClosure
}

func onUpdate(status: BackPaginationStatus) {
func onUpdate(status: PaginationStatus) {
onUpdateClosure(status)
}
}
Expand Down
2 changes: 1 addition & 1 deletion project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ packages:
# Element/Matrix dependencies
MatrixRustSDK:
url: https://github.com/matrix-org/matrix-rust-components-swift
exactVersion: 1.1.60
exactVersion: 1.1.61
# path: ../matrix-rust-sdk
Compound:
url: https://github.com/element-hq/compound-ios
Expand Down

0 comments on commit 522fbcb

Please sign in to comment.