mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 06:55:59 +00:00
Update the SDK and enable event permalinks. (#2748)
This commit is contained in:
@@ -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
|
||||
|
||||
+4
-4
@@ -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 }
|
||||
@@ -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()
|
||||
@@ -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 }
|
||||
|
||||
@@ -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)
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
+6
-1
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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>()
|
||||
@@ -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(())
|
||||
@@ -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 {
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user