Prepare for event focus and forward pagination (#2745)

Neither are available yet.
This commit is contained in:
Doug 2024-04-25 18:32:33 +01:00 committed by GitHub
parent 8d66572cc9
commit 76e7de40b5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
254 changed files with 1461 additions and 845 deletions

View File

@ -152,7 +152,6 @@
237FC70AA257B935F53316BA /* SessionVerificationControllerProxy.swift in Sources */ = {isa = PBXBuildFile; fileRef = C55D7E514F9DE4E3D72FDCAD /* SessionVerificationControllerProxy.swift */; };
241CDEFE23819867D9B39066 /* RoomChangePermissionsScreenViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AE75941583A033A9EDC9FE0 /* RoomChangePermissionsScreenViewModel.swift */; };
244407B18B2F2D6466BA5961 /* RoomChangeRolesScreenCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82DFA1B7B088D033E0794B82 /* RoomChangeRolesScreenCoordinator.swift */; };
245F7FE5961BD10C145A26E0 /* UITimelineView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EA689E792E679F5E3956F21 /* UITimelineView.swift */; };
24A1BBADAC43DC3F3A7347DA /* AnalyticsPromptScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = E53BFB7E4F329621C844E8C3 /* AnalyticsPromptScreen.swift */; };
24A75F72EEB7561B82D726FD /* Date.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2141693488CE5446BB391964 /* Date.swift */; };
24B7CD41342C143117ADA768 /* Comparable.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2B1CC9AA154F4D5435BF60A /* Comparable.swift */; };
@ -367,6 +366,7 @@
56F0A22972A3BB519DA2261C /* HomeScreenViewModelProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24F5530B2212862FA4BEFF2D /* HomeScreenViewModelProtocol.swift */; };
5710AAB27D5D866292C1FE06 /* SessionVerificationScreenModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF848B41DAF1066F3054D4A1 /* SessionVerificationScreenModels.swift */; };
5780E444F405AA1304E1C23E /* DeveloperOptionsScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38E521D6C2BF8DF0DFB35146 /* DeveloperOptionsScreen.swift */; };
57E115A8C33E599DE564F8C3 /* TimelineView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDEB27575FEBCF414D4DEE31 /* TimelineView.swift */; };
588411C8FD72B2A2DFE5F7DE /* XCUIElement.swift in Sources */ = {isa = PBXBuildFile; fileRef = E992D7B8BE54B2AB454613AF /* XCUIElement.swift */; };
5894C2514400A4FBC9327632 /* ServerConfirmationScreenCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03277E40D0E0DE0712021A71 /* ServerConfirmationScreenCoordinator.swift */; };
5897A59DDBD3592282092223 /* MediaSourceProxy.swift in Sources */ = {isa = PBXBuildFile; fileRef = D49B9785E3AD7D1C15A29F2F /* MediaSourceProxy.swift */; };
@ -511,6 +511,7 @@
7A642EE5F1ADC5D520F21924 /* MediaProviderProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 85EB16E7FE59A947CA441531 /* MediaProviderProtocol.swift */; };
7A71AEF419904209BB8C2833 /* UserAgentBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F2529D434C750ED78ADF1ED /* UserAgentBuilder.swift */; };
7A8B264506D3DDABC01B4EEB /* AppMediator.swift in Sources */ = {isa = PBXBuildFile; fileRef = B53AC78E49A297AC1D72A7CF /* AppMediator.swift */; };
7AE82514D96C725F8BDD0ED4 /* HighlightedTimelineItemModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = D162B2280A15ACAF35360554 /* HighlightedTimelineItemModifier.swift */; };
7B1605C6FFD4D195F264A684 /* RoomPollsHistoryScreenViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B40233F2989AD49906BB310D /* RoomPollsHistoryScreenViewModelTests.swift */; };
7B5DAB915357BE596529BF25 /* MapTilerStaticMapProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20872C3887F835958CE2F1D0 /* MapTilerStaticMapProtocol.swift */; };
7B66DA4E7E5FE4D1A0FCEAA4 /* JoinRoomScreenViewModelProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEAB5662310AE73D93815134 /* JoinRoomScreenViewModelProtocol.swift */; };
@ -1183,7 +1184,6 @@
0DBB08A95EFA668F2CF27211 /* AppLockSetupFlowCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppLockSetupFlowCoordinator.swift; sourceTree = "<group>"; };
0DF5CBAF69BDF5DF31C661E1 /* IntentionalMentions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IntentionalMentions.swift; sourceTree = "<group>"; };
0E8BDC092D817B68CD9040C5 /* UserSessionStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserSessionStore.swift; sourceTree = "<group>"; };
0EA689E792E679F5E3956F21 /* UITimelineView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UITimelineView.swift; sourceTree = "<group>"; };
0EE9EAF0309A2A1D67D8FAF5 /* sv */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = sv; path = sv.lproj/Localizable.stringsdict; sourceTree = "<group>"; };
0F5567A7EF6F2AB9473236F6 /* DocumentPicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DocumentPicker.swift; sourceTree = "<group>"; };
0F64447FF544298A6A3BEF85 /* NotificationSettingsScreenModels.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationSettingsScreenModels.swift; sourceTree = "<group>"; };
@ -1859,6 +1859,7 @@
BBEC57C204D77908E355EF42 /* AudioRecorderProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AudioRecorderProtocol.swift; sourceTree = "<group>"; };
BC8AA23D4F37CC26564F63C5 /* LayoutMocks.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LayoutMocks.swift; sourceTree = "<group>"; };
BCF54536699ACEE3DB6BA3CB /* CompletionSuggestionService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CompletionSuggestionService.swift; sourceTree = "<group>"; };
BDEB27575FEBCF414D4DEE31 /* TimelineView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimelineView.swift; sourceTree = "<group>"; };
BE148A4FFEE853C5A281500C /* UNNotificationContent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UNNotificationContent.swift; sourceTree = "<group>"; };
BE89A8BD65CCE3FCC925CA14 /* TimelineItemReplyDetails.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimelineItemReplyDetails.swift; sourceTree = "<group>"; };
BE9BBB18FB27F09032AD8769 /* NotificationPermissionsScreenViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationPermissionsScreenViewModel.swift; sourceTree = "<group>"; };
@ -1950,6 +1951,7 @@
D0A45283CF1DB96E583BECA6 /* ImageRoomTimelineView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageRoomTimelineView.swift; sourceTree = "<group>"; };
D0C2D52E36AD614B3C003EF6 /* RoomTimelineItemViewState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoomTimelineItemViewState.swift; sourceTree = "<group>"; };
D121B4FCFC38DBCC17BCC6D6 /* ComposerToolbar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ComposerToolbar.swift; sourceTree = "<group>"; };
D162B2280A15ACAF35360554 /* HighlightedTimelineItemModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HighlightedTimelineItemModifier.swift; sourceTree = "<group>"; };
D196116D2DD3F2757D45FCB7 /* hu */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = hu; path = hu.lproj/SAS.strings; sourceTree = "<group>"; };
D1BC84BA0AF11C2128D58ABD /* Common.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Common.swift; sourceTree = "<group>"; };
D1D8479BB704B7EF696F8ABE /* RoomPollsHistoryScreenCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoomPollsHistoryScreenCoordinator.swift; sourceTree = "<group>"; };
@ -4480,6 +4482,7 @@
56C1BCB9E83B09A45387FCA2 /* EncryptedRoomTimelineView.swift */,
E51E3D86A84341C3A0CB8A40 /* FileRoomTimelineView.swift */,
F73FF1A33198F5FAE9D34B1F /* FormattedBodyText.swift */,
D162B2280A15ACAF35360554 /* HighlightedTimelineItemModifier.swift */,
D0A45283CF1DB96E583BECA6 /* ImageRoomTimelineView.swift */,
772334731A8BF8E6D90B194D /* LocationRoomTimelineView.swift */,
B5B243E7818E5E9F6A4EDC7A /* NoticeRoomTimelineView.swift */,
@ -4495,8 +4498,8 @@
F9E785D5137510481733A3E8 /* TextRoomTimelineView.swift */,
F9ED8E731E21055F728E5FED /* TimelineStartRoomTimelineView.swift */,
27B8315A340B46F98B9C5AF0 /* TimelineTableViewController.swift */,
BDEB27575FEBCF414D4DEE31 /* TimelineView.swift */,
CE47A97726F0675DEE387BF9 /* TypingIndicatorView.swift */,
0EA689E792E679F5E3956F21 /* UITimelineView.swift */,
A2AC3C656E960E15B5905E05 /* UnsupportedRoomTimelineView.swift */,
1941C8817E6B6971BA4415F5 /* VideoRoomTimelineView.swift */,
);
@ -6032,6 +6035,7 @@
55D18AA4F4A2257642EBDB94 /* GlobalSearchScreenViewModel.swift in Sources */,
E32A18802EB37EEE3EF7B965 /* GlobalSearchScreenViewModelProtocol.swift in Sources */,
D4D5595C4A2A702CFF4E94FF /* HeroImage.swift in Sources */,
7AE82514D96C725F8BDD0ED4 /* HighlightedTimelineItemModifier.swift in Sources */,
964B9D2EC38C488C360CE0C9 /* HomeScreen.swift in Sources */,
62C5876C4254C58C2086F0DE /* HomeScreenContent.swift in Sources */,
8CC12086CBF91A7E10CDC205 /* HomeScreenCoordinator.swift in Sources */,
@ -6502,6 +6506,7 @@
69BCBB4FB2DC3D61A28D3FD8 /* TimelineStyle.swift in Sources */,
FFD3E4FF948E06C7585317FC /* TimelineStyler.swift in Sources */,
2B1E080B32167AE9EFC763A2 /* TimelineTableViewController.swift in Sources */,
57E115A8C33E599DE564F8C3 /* TimelineView.swift in Sources */,
E37044401D9951D6C02C0855 /* TracingConfiguration.swift in Sources */,
6D6E651ACACE27E9C5690818 /* TypingIndicatorView.swift in Sources */,
36AC963F2F04069B7FF1AA0C /* UIConstants.swift in Sources */,
@ -6511,7 +6516,6 @@
384D6B9A7DFD7260139D6852 /* UITestsNotificationCenter.swift in Sources */,
22882C710BC99EC34A5024A0 /* UITestsScreenIdentifier.swift in Sources */,
706289B086B0A6B0C211763F /* UITestsSignalling.swift in Sources */,
245F7FE5961BD10C145A26E0 /* UITimelineView.swift in Sources */,
D02AA6208C7ACB9BE6332394 /* UNNotificationContent.swift in Sources */,
071A017E415AD378F2961B11 /* URL.swift in Sources */,
6FD8053301C5FEFA82D2F246 /* URLComponents.swift in Sources */,

View File

@ -7137,6 +7137,74 @@ class RoomProxyMock: RoomProxyProtocol {
unsubscribeFromUpdatesCallsCount += 1
unsubscribeFromUpdatesClosure?()
}
//MARK: - timelineFocusedOnEvent
var timelineFocusedOnEventEventIDNumberOfEventsUnderlyingCallsCount = 0
var timelineFocusedOnEventEventIDNumberOfEventsCallsCount: Int {
get {
if Thread.isMainThread {
return timelineFocusedOnEventEventIDNumberOfEventsUnderlyingCallsCount
} else {
var returnValue: Int? = nil
DispatchQueue.main.sync {
returnValue = timelineFocusedOnEventEventIDNumberOfEventsUnderlyingCallsCount
}
return returnValue!
}
}
set {
if Thread.isMainThread {
timelineFocusedOnEventEventIDNumberOfEventsUnderlyingCallsCount = newValue
} else {
DispatchQueue.main.sync {
timelineFocusedOnEventEventIDNumberOfEventsUnderlyingCallsCount = newValue
}
}
}
}
var timelineFocusedOnEventEventIDNumberOfEventsCalled: Bool {
return timelineFocusedOnEventEventIDNumberOfEventsCallsCount > 0
}
var timelineFocusedOnEventEventIDNumberOfEventsReceivedArguments: (eventID: String, numberOfEvents: UInt16)?
var timelineFocusedOnEventEventIDNumberOfEventsReceivedInvocations: [(eventID: String, numberOfEvents: UInt16)] = []
var timelineFocusedOnEventEventIDNumberOfEventsUnderlyingReturnValue: Result<TimelineProxyProtocol, RoomProxyError>!
var timelineFocusedOnEventEventIDNumberOfEventsReturnValue: Result<TimelineProxyProtocol, RoomProxyError>! {
get {
if Thread.isMainThread {
return timelineFocusedOnEventEventIDNumberOfEventsUnderlyingReturnValue
} else {
var returnValue: Result<TimelineProxyProtocol, RoomProxyError>? = nil
DispatchQueue.main.sync {
returnValue = timelineFocusedOnEventEventIDNumberOfEventsUnderlyingReturnValue
}
return returnValue!
}
}
set {
if Thread.isMainThread {
timelineFocusedOnEventEventIDNumberOfEventsUnderlyingReturnValue = newValue
} else {
DispatchQueue.main.sync {
timelineFocusedOnEventEventIDNumberOfEventsUnderlyingReturnValue = newValue
}
}
}
}
var timelineFocusedOnEventEventIDNumberOfEventsClosure: ((String, UInt16) async -> Result<TimelineProxyProtocol, RoomProxyError>)?
func timelineFocusedOnEvent(eventID: String, numberOfEvents: UInt16) async -> Result<TimelineProxyProtocol, RoomProxyError> {
timelineFocusedOnEventEventIDNumberOfEventsCallsCount += 1
timelineFocusedOnEventEventIDNumberOfEventsReceivedArguments = (eventID: eventID, numberOfEvents: numberOfEvents)
timelineFocusedOnEventEventIDNumberOfEventsReceivedInvocations.append((eventID: eventID, numberOfEvents: numberOfEvents))
if let timelineFocusedOnEventEventIDNumberOfEventsClosure = timelineFocusedOnEventEventIDNumberOfEventsClosure {
return await timelineFocusedOnEventEventIDNumberOfEventsClosure(eventID, numberOfEvents)
} else {
return timelineFocusedOnEventEventIDNumberOfEventsReturnValue
}
}
//MARK: - redact
var redactUnderlyingCallsCount = 0
@ -9585,17 +9653,22 @@ class RoomSummaryProviderMock: RoomSummaryProviderProtocol {
}
}
class RoomTimelineProviderMock: RoomTimelineProviderProtocol {
var updatePublisher: AnyPublisher<Void, Never> {
var updatePublisher: AnyPublisher<([TimelineItemProxy], PaginationState), Never> {
get { return underlyingUpdatePublisher }
set(value) { underlyingUpdatePublisher = value }
}
var underlyingUpdatePublisher: AnyPublisher<Void, Never>!
var underlyingUpdatePublisher: AnyPublisher<([TimelineItemProxy], PaginationState), Never>!
var itemProxies: [TimelineItemProxy] = []
var backPaginationState: BackPaginationStatus {
get { return underlyingBackPaginationState }
set(value) { underlyingBackPaginationState = value }
var paginationState: PaginationState {
get { return underlyingPaginationState }
set(value) { underlyingPaginationState = value }
}
var underlyingBackPaginationState: BackPaginationStatus!
var underlyingPaginationState: PaginationState!
var isLive: Bool {
get { return underlyingIsLive }
set(value) { underlyingIsLive = value }
}
var underlyingIsLive: Bool!
var membershipChangePublisher: AnyPublisher<Void, Never> {
get { return underlyingMembershipChangePublisher }
set(value) { underlyingMembershipChangePublisher = value }
@ -10338,16 +10411,16 @@ class TimelineProxyMock: TimelineProxyProtocol {
set(value) { underlyingActions = value }
}
var underlyingActions: AnyPublisher<TimelineProxyAction, Never>!
var isLive: Bool {
get { return underlyingIsLive }
set(value) { underlyingIsLive = value }
}
var underlyingIsLive: Bool!
var timelineProvider: RoomTimelineProviderProtocol {
get { return underlyingTimelineProvider }
set(value) { underlyingTimelineProvider = value }
}
var underlyingTimelineProvider: RoomTimelineProviderProtocol!
var timelineStartReached: Bool {
get { return underlyingTimelineStartReached }
set(value) { underlyingTimelineStartReached = value }
}
var underlyingTimelineStartReached: Bool!
//MARK: - subscribeForUpdates
@ -10705,8 +10778,8 @@ class TimelineProxyMock: TimelineProxyProtocol {
var paginateBackwardsRequestSizeCalled: Bool {
return paginateBackwardsRequestSizeCallsCount > 0
}
var paginateBackwardsRequestSizeReceivedRequestSize: UInt?
var paginateBackwardsRequestSizeReceivedInvocations: [UInt] = []
var paginateBackwardsRequestSizeReceivedRequestSize: UInt16?
var paginateBackwardsRequestSizeReceivedInvocations: [UInt16] = []
var paginateBackwardsRequestSizeUnderlyingReturnValue: Result<Void, TimelineProxyError>!
var paginateBackwardsRequestSizeReturnValue: Result<Void, TimelineProxyError>! {
@ -10732,9 +10805,9 @@ class TimelineProxyMock: TimelineProxyProtocol {
}
}
}
var paginateBackwardsRequestSizeClosure: ((UInt) async -> Result<Void, TimelineProxyError>)?
var paginateBackwardsRequestSizeClosure: ((UInt16) async -> Result<Void, TimelineProxyError>)?
func paginateBackwards(requestSize: UInt) async -> Result<Void, TimelineProxyError> {
func paginateBackwards(requestSize: UInt16) async -> Result<Void, TimelineProxyError> {
paginateBackwardsRequestSizeCallsCount += 1
paginateBackwardsRequestSizeReceivedRequestSize = requestSize
paginateBackwardsRequestSizeReceivedInvocations.append(requestSize)
@ -10744,17 +10817,17 @@ class TimelineProxyMock: TimelineProxyProtocol {
return paginateBackwardsRequestSizeReturnValue
}
}
//MARK: - paginateBackwards
//MARK: - paginateForwards
var paginateBackwardsRequestSizeUntilNumberOfItemsUnderlyingCallsCount = 0
var paginateBackwardsRequestSizeUntilNumberOfItemsCallsCount: Int {
var paginateForwardsRequestSizeUnderlyingCallsCount = 0
var paginateForwardsRequestSizeCallsCount: Int {
get {
if Thread.isMainThread {
return paginateBackwardsRequestSizeUntilNumberOfItemsUnderlyingCallsCount
return paginateForwardsRequestSizeUnderlyingCallsCount
} else {
var returnValue: Int? = nil
DispatchQueue.main.sync {
returnValue = paginateBackwardsRequestSizeUntilNumberOfItemsUnderlyingCallsCount
returnValue = paginateForwardsRequestSizeUnderlyingCallsCount
}
return returnValue!
@ -10762,29 +10835,29 @@ class TimelineProxyMock: TimelineProxyProtocol {
}
set {
if Thread.isMainThread {
paginateBackwardsRequestSizeUntilNumberOfItemsUnderlyingCallsCount = newValue
paginateForwardsRequestSizeUnderlyingCallsCount = newValue
} else {
DispatchQueue.main.sync {
paginateBackwardsRequestSizeUntilNumberOfItemsUnderlyingCallsCount = newValue
paginateForwardsRequestSizeUnderlyingCallsCount = newValue
}
}
}
}
var paginateBackwardsRequestSizeUntilNumberOfItemsCalled: Bool {
return paginateBackwardsRequestSizeUntilNumberOfItemsCallsCount > 0
var paginateForwardsRequestSizeCalled: Bool {
return paginateForwardsRequestSizeCallsCount > 0
}
var paginateBackwardsRequestSizeUntilNumberOfItemsReceivedArguments: (requestSize: UInt, untilNumberOfItems: UInt)?
var paginateBackwardsRequestSizeUntilNumberOfItemsReceivedInvocations: [(requestSize: UInt, untilNumberOfItems: UInt)] = []
var paginateForwardsRequestSizeReceivedRequestSize: UInt16?
var paginateForwardsRequestSizeReceivedInvocations: [UInt16] = []
var paginateBackwardsRequestSizeUntilNumberOfItemsUnderlyingReturnValue: Result<Void, TimelineProxyError>!
var paginateBackwardsRequestSizeUntilNumberOfItemsReturnValue: Result<Void, TimelineProxyError>! {
var paginateForwardsRequestSizeUnderlyingReturnValue: Result<Void, TimelineProxyError>!
var paginateForwardsRequestSizeReturnValue: Result<Void, TimelineProxyError>! {
get {
if Thread.isMainThread {
return paginateBackwardsRequestSizeUntilNumberOfItemsUnderlyingReturnValue
return paginateForwardsRequestSizeUnderlyingReturnValue
} else {
var returnValue: Result<Void, TimelineProxyError>? = nil
DispatchQueue.main.sync {
returnValue = paginateBackwardsRequestSizeUntilNumberOfItemsUnderlyingReturnValue
returnValue = paginateForwardsRequestSizeUnderlyingReturnValue
}
return returnValue!
@ -10792,24 +10865,24 @@ class TimelineProxyMock: TimelineProxyProtocol {
}
set {
if Thread.isMainThread {
paginateBackwardsRequestSizeUntilNumberOfItemsUnderlyingReturnValue = newValue
paginateForwardsRequestSizeUnderlyingReturnValue = newValue
} else {
DispatchQueue.main.sync {
paginateBackwardsRequestSizeUntilNumberOfItemsUnderlyingReturnValue = newValue
paginateForwardsRequestSizeUnderlyingReturnValue = newValue
}
}
}
}
var paginateBackwardsRequestSizeUntilNumberOfItemsClosure: ((UInt, UInt) async -> Result<Void, TimelineProxyError>)?
var paginateForwardsRequestSizeClosure: ((UInt16) async -> Result<Void, TimelineProxyError>)?
func paginateBackwards(requestSize: UInt, untilNumberOfItems: UInt) async -> Result<Void, TimelineProxyError> {
paginateBackwardsRequestSizeUntilNumberOfItemsCallsCount += 1
paginateBackwardsRequestSizeUntilNumberOfItemsReceivedArguments = (requestSize: requestSize, untilNumberOfItems: untilNumberOfItems)
paginateBackwardsRequestSizeUntilNumberOfItemsReceivedInvocations.append((requestSize: requestSize, untilNumberOfItems: untilNumberOfItems))
if let paginateBackwardsRequestSizeUntilNumberOfItemsClosure = paginateBackwardsRequestSizeUntilNumberOfItemsClosure {
return await paginateBackwardsRequestSizeUntilNumberOfItemsClosure(requestSize, untilNumberOfItems)
func paginateForwards(requestSize: UInt16) async -> Result<Void, TimelineProxyError> {
paginateForwardsRequestSizeCallsCount += 1
paginateForwardsRequestSizeReceivedRequestSize = requestSize
paginateForwardsRequestSizeReceivedInvocations.append(requestSize)
if let paginateForwardsRequestSizeClosure = paginateForwardsRequestSizeClosure {
return await paginateForwardsRequestSizeClosure(requestSize)
} else {
return paginateBackwardsRequestSizeUntilNumberOfItemsReturnValue
return paginateForwardsRequestSizeReturnValue
}
}
//MARK: - sendAudio

View File

@ -30,16 +30,7 @@ struct RoomProxyMockConfiguration {
var hasOngoingCall = true
var canonicalAlias: String?
var timeline = {
let mock = TimelineProxyMock()
mock.underlyingActions = Empty(completeImmediately: false).eraseToAnyPublisher()
mock.timelineStartReached = false
let timelineProvider = RoomTimelineProviderMock()
timelineProvider.underlyingMembershipChangePublisher = PassthroughSubject().eraseToAnyPublisher()
mock.underlyingTimelineProvider = timelineProvider
return mock
}()
var timelineStartReached = false
var members: [RoomMemberProxyMock] = .allMembers
var ownUserID = RoomMemberProxyMock.mockMe.userID
@ -47,6 +38,17 @@ struct RoomProxyMockConfiguration {
var canUserInvite = true
var canUserTriggerRoomNotification = false
var canUserJoinCall = true
func makeTimeline() -> TimelineProxyMock {
let mock = TimelineProxyMock()
mock.underlyingActions = Empty(completeImmediately: false).eraseToAnyPublisher()
let timelineProvider = RoomTimelineProviderMock()
timelineProvider.paginationState = .init(backward: timelineStartReached ? .timelineStartReached : .idle, forward: .timelineStartReached)
timelineProvider.underlyingMembershipChangePublisher = PassthroughSubject().eraseToAnyPublisher()
mock.underlyingTimelineProvider = timelineProvider
return mock
}
}
enum RoomProxyMockError: Error {
@ -69,7 +71,7 @@ extension RoomProxyMock {
hasOngoingCall = configuration.hasOngoingCall
canonicalAlias = configuration.canonicalAlias
timeline = configuration.timeline
timeline = configuration.makeTimeline()
ownUserID = configuration.ownUserID
membership = .joined

View File

@ -23,7 +23,7 @@ typealias RoomPollsHistoryScreenViewModelType = StateStoreViewModel<RoomPollsHis
class RoomPollsHistoryScreenViewModel: RoomPollsHistoryScreenViewModelType, RoomPollsHistoryScreenViewModelProtocol {
private enum Constants {
static let backPaginationEventLimit: UInt = 250
static let backPaginationEventLimit: UInt16 = 250
}
private let pollInteractionHandler: PollInteractionHandlerProtocol
@ -82,11 +82,12 @@ class RoomPollsHistoryScreenViewModel: RoomPollsHistoryScreenViewModelType, Room
switch callback {
case .updatedTimelineItems:
self.updatePollsList(filter: state.bindings.filter)
case .canBackPaginate(let canBackPaginate):
case .paginationState(let paginationState):
let canBackPaginate = paginationState.backward != .timelineStartReached
if self.state.canBackPaginate != canBackPaginate {
self.state.canBackPaginate = canBackPaginate
}
case .isBackPaginating:
case .isLive:
break
}
}

View File

@ -125,7 +125,6 @@ struct RoomPollsHistoryScreen_Previews: PreviewProvider, TestablePreview {
let roomTimelineController = MockRoomTimelineController()
roomTimelineController.timelineItems = []
let roomProxyMockConfiguration = RoomProxyMockConfiguration(name: "Polls")
roomProxyMockConfiguration.timeline.timelineStartReached = false
let viewModel = RoomPollsHistoryScreenViewModel(pollInteractionHandler: PollInteractionHandlerMock(),
roomTimelineController: roomTimelineController,
userIndicatorController: UserIndicatorControllerMock())
@ -147,8 +146,7 @@ struct RoomPollsHistoryScreen_Previews: PreviewProvider, TestablePreview {
roomTimelineController.timelineItemsTimestamp[item.id] = date
}
let roomProxyMockConfiguration = RoomProxyMockConfiguration(name: "Polls")
roomProxyMockConfiguration.timeline.timelineStartReached = true
let roomProxyMockConfiguration = RoomProxyMockConfiguration(name: "Polls", timelineStartReached: true)
let viewModel = RoomPollsHistoryScreenViewModel(pollInteractionHandler: PollInteractionHandlerMock(),
roomTimelineController: roomTimelineController,
userIndicatorController: UserIndicatorControllerMock())

View File

@ -84,6 +84,7 @@ enum RoomScreenViewAction {
case toggleReaction(key: String, itemID: TimelineItemIdentifier)
case sendReadReceiptIfNeeded(TimelineItemIdentifier)
case paginateBackwards
case paginateForwards
case timelineItemMenu(itemID: TimelineItemIdentifier)
case timelineItemMenuAction(itemID: TimelineItemIdentifier, action: TimelineItemMenuAction)
@ -107,7 +108,15 @@ enum RoomScreenViewAction {
case presentCall
/// Focus the timeline onto the specified event ID (switching to a detached timeline if needed).
case focusOnEventID(String)
/// Switch back to a live timeline (from a detached one).
case focusLive
/// Remove the highlighted event without switching timeline.
///
/// This is useful when returning to the bottom of the live timeline
/// if `focusOnEventID` didn't use a detached timeline.
case clearFocussedEvent
}
enum RoomScreenComposerAction {
@ -127,7 +136,7 @@ struct RoomScreenViewState: BindableState {
var showReadReceipts = false
var timelineStyle: TimelineStyle
var isEncryptedOneToOneRoom = false
var timelineViewState = TimelineViewState() // check the doc before changing this
var timelineViewState: TimelineViewState // check the doc before changing this
var ownUserID: String
@ -217,8 +226,10 @@ struct RoomMemberState {
/// Used as the state for the TimelineView, to avoid having the context continuously refresh the list of items on each small change.
/// Is also nice to have this as a wrapper for any state that is directly connected to the timeline.
struct TimelineViewState {
var canBackPaginate = true
var isBackPaginating = true
var isLive = true
var paginationState = PaginationState.default
var focussedEventID: String?
// These can be removed when we have full swiftUI and moved as @State values in the view
var scrollToBottomPublisher = PassthroughSubject<Void, Never>()
@ -232,4 +243,8 @@ struct TimelineViewState {
var itemViewStates: [RoomTimelineItemViewState] {
itemsDictionary.values.elements
}
func hasLoadedItem(with eventID: String) -> Bool {
itemViewStates.contains { $0.identifier.eventID == eventID }
}
}

View File

@ -23,8 +23,9 @@ typealias RoomScreenViewModelType = StateStoreViewModel<RoomScreenViewState, Roo
class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol {
private enum Constants {
static let backPaginationEventLimit: UInt = 20
static let backPaginationPageSize: UInt = 50
static let paginationEventLimit: UInt16 = 20
static let detachedTimelineSize: UInt16 = 100
static let focusTimelineToastIndicatorID = "RoomScreenFocusTimelineToastIndicator"
static let toastErrorID = "RoomScreenToastError"
}
@ -47,6 +48,7 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
}
private var paginateBackwardsTask: Task<Void, Never>?
private var paginateForwardsTask: Task<Void, Never>?
init(roomProxy: RoomProxyProtocol,
focussedEventID: String? = nil,
@ -86,6 +88,7 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
roomAvatarURL: roomProxy.avatarURL,
timelineStyle: appSettings.timelineStyle,
isEncryptedOneToOneRoom: roomProxy.isEncryptedOneToOneRoom,
timelineViewState: TimelineViewState(focussedEventID: focussedEventID),
ownUserID: roomProxy.ownUserID,
hasOngoingCall: roomProxy.hasOngoingCall,
bindings: .init(reactionsCollapsed: [:])),
@ -170,6 +173,8 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
Task { await timelineController.cancelSending(itemID: itemID) }
case .paginateBackwards:
paginateBackwards()
case .paginateForwards:
paginateForwards()
case .poll(let pollAction):
processPollAction(pollAction)
case .audio(let audioAction):
@ -179,8 +184,11 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
case .showReadReceipts(itemID: let itemID):
showReadReceipts(for: itemID)
case .focusOnEventID(let eventID):
// TODO: .. something
break
Task { await focusOnEvent(eventID: eventID) }
case .focusLive:
focusLive()
case .clearFocussedEvent:
state.timelineViewState.focussedEventID = nil
}
}
@ -214,10 +222,31 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
}
}
func focusOnEvent(eventID: String) async { }
func focusOnEvent(eventID: String) async {
if state.timelineViewState.hasLoadedItem(with: eventID) {
state.timelineViewState.focussedEventID = eventID
return
}
showFocusLoadingIndicator()
defer { hideFocusLoadingIndicator() }
switch await timelineController.focusOnEvent(eventID, timelineSize: Constants.detachedTimelineSize) {
case .success:
state.timelineViewState.focussedEventID = eventID
case .failure(let error):
MXLog.error("Failed to focus on event \(eventID)")
displayError(.toast(L10n.commonFailed))
}
}
// MARK: - Private
private func focusLive() {
timelineController.focusLive()
state.timelineViewState.focussedEventID = nil
}
private func attach(_ attachment: ComposerAttachmentType) {
switch attachment {
case .camera:
@ -297,14 +326,19 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
switch callback {
case .updatedTimelineItems:
self.buildTimelineViews()
case .canBackPaginate(let canBackPaginate):
if self.state.timelineViewState.canBackPaginate != canBackPaginate {
self.state.timelineViewState.canBackPaginate = canBackPaginate
buildTimelineViews()
case .paginationState(let paginationState):
if state.timelineViewState.paginationState != paginationState {
state.timelineViewState.paginationState = paginationState
}
case .isBackPaginating(let isBackPaginating):
if self.state.timelineViewState.isBackPaginating != isBackPaginating {
self.state.timelineViewState.isBackPaginating = isBackPaginating
case .isLive(let isLive):
if state.timelineViewState.isLive != isLive {
state.timelineViewState.isLive = isLive
// Remove the event highlight *only* when transitioning from non-live to live.
if isLive, state.timelineViewState.focussedEventID != nil {
state.timelineViewState.focussedEventID = nil
}
}
}
}
@ -414,7 +448,7 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
return
}
switch await timelineController.paginateBackwards(requestSize: Constants.backPaginationEventLimit, untilNumberOfItems: Constants.backPaginationPageSize) {
switch await timelineController.paginateBackwards(requestSize: Constants.paginationEventLimit) {
case .failure:
displayError(.toast(L10n.errorFailedLoadingMessages))
default:
@ -424,6 +458,31 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
}
}
private func paginateForwards() {
guard paginateForwardsTask == nil else {
return
}
paginateForwardsTask = Task { [weak self] in
guard let self else {
return
}
switch await timelineController.paginateForwards(requestSize: Constants.paginationEventLimit) {
case .failure:
displayError(.toast(L10n.errorFailedLoadingMessages))
default:
break
}
if state.timelineViewState.paginationState.forward == .timelineStartReached {
focusLive()
}
paginateForwardsTask = nil
}
}
private func sendReadReceiptIfNeeded(for lastVisibleItemID: TimelineItemIdentifier) async {
guard appMediator.appState == .active else { return }
@ -636,6 +695,17 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
// MARK: - User Indicators
private func showFocusLoadingIndicator() {
userIndicatorController.submitIndicator(UserIndicator(id: Constants.focusTimelineToastIndicatorID,
type: .toast(progress: .indeterminate),
title: L10n.commonLoading,
persistent: true))
}
private func hideFocusLoadingIndicator() {
userIndicatorController.retractIndicatorWithId(Constants.focusTimelineToastIndicatorID)
}
private func displayError(_ type: RoomScreenErrorType) {
switch type {
case .alert(let message):
@ -662,6 +732,7 @@ private extension RoomProxyProtocol {
extension RoomScreenViewModel {
static let mock = RoomScreenViewModel(roomProxy: RoomProxyMock(with: .init(name: "Preview room")),
focussedEventID: nil,
timelineController: MockRoomTimelineController(),
mediaProvider: MockMediaProvider(),
mediaPlayerProvider: MediaPlayerProviderMock(),
@ -674,14 +745,23 @@ extension RoomScreenViewModel {
}
private struct RoomContextKey: EnvironmentKey {
@MainActor
static let defaultValue = RoomScreenViewModel.mock.context
@MainActor static let defaultValue = RoomScreenViewModel.mock.context
}
private struct FocussedEventID: EnvironmentKey {
static let defaultValue: String? = nil
}
extension EnvironmentValues {
/// Used to access and inject and access the room context without observing it
/// Used to access and inject the room context without observing it
var roomContext: RoomScreenViewModel.Context {
get { self[RoomContextKey.self] }
set { self[RoomContextKey.self] = newValue }
}
/// An event ID which will be non-nil when a timeline item should show as focussed.
var focussedEventID: String? {
get { self[FocussedEventID.self] }
set { self[FocussedEventID.self] = newValue }
}
}

View File

@ -92,17 +92,18 @@ struct RoomScreen: View {
}
private var timeline: some View {
UITimelineView()
TimelineView()
.id(context.viewState.roomID)
.environmentObject(context)
.environment(\.timelineStyle, context.viewState.timelineStyle)
.environment(\.focussedEventID, context.viewState.timelineViewState.focussedEventID)
.overlay(alignment: .bottomTrailing) {
scrollToBottomButton
}
}
private var scrollToBottomButton: some View {
Button { context.viewState.timelineViewState.scrollToBottomPublisher.send(()) } label: {
Button(action: scrollToBottom) {
Image(systemName: "chevron.down")
.font(.compound.bodyLG)
.fontWeight(.semibold)
@ -117,9 +118,21 @@ struct RoomScreen: View {
}
.padding()
}
.opacity(context.isScrolledToBottom ? 0.0 : 1.0)
.accessibilityHidden(context.isScrolledToBottom)
.animation(.elementDefault, value: context.isScrolledToBottom)
.opacity(isAtBottomAndLive ? 0.0 : 1.0)
.accessibilityHidden(isAtBottomAndLive)
.animation(.elementDefault, value: isAtBottomAndLive)
}
private var isAtBottomAndLive: Bool {
context.isScrolledToBottom && context.viewState.timelineViewState.isLive
}
private func scrollToBottom() {
if context.viewState.timelineViewState.isLive {
context.viewState.timelineViewState.scrollToBottomPublisher.send(())
} else {
context.send(viewAction: .focusLive)
}
}
@ViewBuilder

View File

@ -22,12 +22,14 @@ import Compound
struct TimelineItemBubbledStylerView<Content: View>: View {
@EnvironmentObject private var context: RoomScreenViewModel.Context
@Environment(\.timelineGroupStyle) private var timelineGroupStyle
@Environment(\.focussedEventID) private var focussedEventID
let timelineItem: EventBasedTimelineItemProtocol
let adjustedDeliveryStatus: TimelineItemDeliveryStatus?
@ViewBuilder let content: () -> Content
private var isEncryptedOneToOneRoom: Bool { context.viewState.isEncryptedOneToOneRoom }
private var isFocussed: Bool { focussedEventID != nil && timelineItem.id.eventID == focussedEventID }
/// The base padding applied to bubbles on either side.
///
@ -71,6 +73,8 @@ struct TimelineItemBubbledStylerView<Content: View>: View {
.padding(.leading, bubbleAvatarPadding)
}
}
.padding(TimelineStyle.bubbles.rowInsets)
.highlightedTimelineItem(isFocussed)
}
@ViewBuilder
@ -528,8 +532,6 @@ struct TimelineItemBubbledStylerView_Previews: PreviewProvider, TestablePreview
VStack(alignment: .leading, spacing: 0) {
ForEach(viewModel.state.timelineViewState.itemViewStates) { viewState in
RoomTimelineItemView(viewState: viewState)
.padding(TimelineStyle.bubbles.rowInsets)
// Insets added in the table view cells
}
}
}

View File

@ -20,10 +20,13 @@ import SwiftUI
struct TimelineItemPlainStylerView<Content: View>: View {
@EnvironmentObject private var context: RoomScreenViewModel.Context
@Environment(\.timelineGroupStyle) private var timelineGroupStyle
@Environment(\.focussedEventID) private var focussedEventID
let timelineItem: EventBasedTimelineItemProtocol
let adjustedDeliveryStatus: TimelineItemDeliveryStatus?
@ViewBuilder let content: () -> Content
private var isFocussed: Bool { focussedEventID != nil && timelineItem.id.eventID == focussedEventID }
var body: some View {
VStack(alignment: .trailing, spacing: 0) {
@ -38,6 +41,8 @@ struct TimelineItemPlainStylerView<Content: View>: View {
TimelineItemStatusView(timelineItem: timelineItem, adjustedDeliveryStatus: adjustedDeliveryStatus)
.environmentObject(context)
}
.padding(TimelineStyle.plain.rowInsets)
.highlightedTimelineItem(isFocussed)
}
@ViewBuilder
@ -151,7 +156,6 @@ struct TimelineItemPlainStylerView_Previews: PreviewProvider, TestablePreview {
ForEach(1..<MockRoomTimelineController().timelineItems.count, id: \.self) { index in
let item = MockRoomTimelineController().timelineItems[index]
RoomTimelineItemView(viewState: .init(item: item, groupStyle: .single))
.padding(TimelineStyle.plain.rowInsets) // Insets added in the table view cells
}
}
.environment(\.timelineStyle, .plain)

View File

@ -0,0 +1,85 @@
//
// Copyright 2024 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
import Compound
import SwiftUI
extension View {
func highlightedTimelineItem(_ isHighlighted: Bool) -> some View {
modifier(HighlightedTimelineItemModifier(isHighlighted: isHighlighted))
}
}
private struct HighlightedTimelineItemModifier: ViewModifier {
let isHighlighted: Bool
func body(content: Content) -> some View {
content
.background {
if isHighlighted {
VStack(spacing: 0) {
Color.compound._bgBubbleHighlighted
LinearGradient(colors: [.compound._bgBubbleHighlighted, .clear],
startPoint: .top,
endPoint: .bottom)
.frame(maxHeight: 200)
.layoutPriority(1)
}
.overlay(alignment: .top) {
Color.compound.bgAccentRest
.frame(height: 1)
}
}
}
}
}
struct HighlightedTimelineItemModifier_Previews: PreviewProvider, TestablePreview {
static var previews: some View {
ScrollView {
VStack(spacing: 16) {
Bubble(text: "Hello 👋")
.highlightedTimelineItem(true)
Bubble(text: "Not highlighted")
.highlightedTimelineItem(false)
Bubble(text: """
Bacon ipsum dolor amet brisket bacon hamburger filet mignon ham hock, capicola meatloaf corned beef tongue. Ribeye filet mignon shoulder drumstick doner shank. Landjaeger shankle chislic brisket short loin pig. Frankfurter sirloin jerky bresaola tri-tip cow buffalo. Beef tongue shankle venison, sirloin boudin biltong ham hock corned beef. Sirloin shankle pork belly, strip steak pancetta brisket flank ribeye cow chislic. Pork ham landjaeger, pastrami beef sausage capicola meatball.
Cow brisket bresaola, burgdoggen cupim turducken sirloin andouille shankle sausage jerky chicken pig. Tail capicola landjaeger frankfurter. Kevin pancetta brisket spare ribs, sausage chuck tail pork. Ground round boudin chuck tri-tip corned beef. Pork belly ham bresaola tail, pork chop meatloaf biltong filet mignon strip steak ribeye boudin shoulder frankfurter.
""",
isOutgoing: true)
.highlightedTimelineItem(true)
}
}
}
struct Bubble: View {
let text: String
var isOutgoing = false
var body: some View {
Text(text)
.padding(10)
.background(isOutgoing ? .compound._bgBubbleOutgoing : .compound._bgBubbleIncoming,
in: RoundedRectangle(cornerRadius: 12))
.padding(isOutgoing ? .leading : .trailing, 40)
.frame(maxWidth: .infinity, alignment: isOutgoing ? .trailing : .leading)
.padding(12)
}
}
}

View File

@ -89,7 +89,6 @@ struct LocationRoomTimelineView_Previews: PreviewProvider, TestablePreview {
ScrollView {
VStack(spacing: 8) {
states
.padding(.horizontal)
}
}
.environmentObject(viewModel.context)
@ -98,7 +97,6 @@ struct LocationRoomTimelineView_Previews: PreviewProvider, TestablePreview {
ScrollView {
VStack(spacing: 0) {
states
.padding(.horizontal)
}
}
.environment(\.timelineStyle, .plain)

View File

@ -28,7 +28,7 @@ struct PaginationIndicatorRoomTimelineView: View {
struct PaginationIndicatorRoomTimelineView_Previews: PreviewProvider, TestablePreview {
static var previews: some View {
let item = PaginationIndicatorRoomTimelineItem()
let item = PaginationIndicatorRoomTimelineItem(position: .start)
PaginationIndicatorRoomTimelineView(timelineItem: item)
}
}

View File

@ -64,7 +64,6 @@ struct ReadMarkerRoomTimelineView_Previews: PreviewProvider, TestablePreview {
sender: .init(id: "", displayName: "Alice"),
content: .init(body: "This is a message"))), groupStyle: .single))
}
.padding(.horizontal, 8)
.environmentObject(viewModel.context)
}
}

View File

@ -15,6 +15,7 @@
//
import Combine
import Compound
import SwiftUI
import OrderedCollections
@ -52,33 +53,71 @@ class TypingMembersObservableObject: ObservableObject {
/// extra keyboard handling magic that wasn't playing well with SwiftUI (as of iOS 16.1).
/// Also this TableViewController uses a **flipped tableview**
class TimelineTableViewController: UIViewController {
private let coordinator: UITimelineView.Coordinator
private let coordinator: TimelineView.Coordinator
private let tableView = UITableView(frame: .zero, style: .plain)
var timelineStyle: TimelineStyle
var timelineItemsDictionary = OrderedDictionary<String, RoomTimelineItemViewState>() {
didSet {
if !isLive, isDraggingScrollView {
// Forward pagination doesn't play well with the user scrolling, so we wait for it to stop.
hasPendingItems = true
return
}
applySnapshot()
if timelineItemsDictionary.isEmpty {
paginateBackwardsPublisher.send()
paginatePublisher.send()
}
sendLastVisibleItemReadReceipt()
}
}
/// Whether or not the timeline has more messages to back paginate.
var canBackPaginate = true
/// There are pending items in `timelineItemsDictionary` that haven't been applied to the data source.
var hasPendingItems = false
/// Whether or not the timeline is waiting for more messages to be added to the top.
var isBackPaginating = false {
/// The user is dragging the scroll view (or it is still decelerating after a drag).
var isDraggingScrollView = false {
didSet {
// Paginate again if the threshold hasn't been satisfied.
paginateBackwardsPublisher.send(())
if !isDraggingScrollView, hasPendingItems {
hasPendingItems = false
applySnapshot()
}
}
}
/// Whether or not the current timeline is live or built around an event ID.
var isLive = true {
didSet {
// Update isScrolledToBottom when switching back to a live timeline.
if isLive { scrollViewDidScroll(tableView) }
}
}
/// The state of pagination (in both directions) of the current timeline.
var paginationState: PaginationState = .default {
didSet {
// Paginate again if the threshold hasn't been satisfied.
paginatePublisher.send(())
}
}
/// The ID of the focussed event if opening the room to an event permalink.
var focussedEventID: String? {
didSet {
guard let focussedEventID else { return }
focussedEventNeedsDisplay = true
scrollToItem(eventID: focussedEventID, animated: false)
}
}
/// Whether the timeline should scroll to `focussedEventID` when that item is added to the data source.
/// This is necessary as the focussed event can be set before the timeline builder has built its item.
var focussedEventNeedsDisplay = false
/// Used to hold an observable object that the typing indicator can use
let typingMembers = TypingMembersObservableObject(members: [])
@ -103,12 +142,13 @@ class TimelineTableViewController: UIViewController {
/// A publisher used to throttle back pagination requests.
///
/// Our view actions get wrapped in a `Task` so it is possible that a second call in
/// quick succession can execute before ``isBackPaginating`` becomes `true`.
private let paginateBackwardsPublisher = PassthroughSubject<Void, Never>()
/// quick succession can execute before ``paginationState`` acknowledges that
/// pagination is in progress.
private let paginatePublisher = PassthroughSubject<Void, Never>()
/// Whether or not the view has been shown on screen yet.
private var hasAppearedOnce = false
init(coordinator: UITimelineView.Coordinator,
init(coordinator: TimelineView.Coordinator,
timelineStyle: TimelineStyle,
isScrolledToBottom: Binding<Bool>,
scrollToBottomPublisher: PassthroughSubject<Void, Never>) {
@ -133,14 +173,17 @@ class TimelineTableViewController: UIViewController {
scrollToBottomPublisher
.sink { [weak self] _ in
self?.scrollToBottom(animated: true)
guard let self else { return }
scrollToNewestItem(animated: true)
coordinator.send(viewAction: .clearFocussedEvent)
}
.store(in: &cancellables)
paginateBackwardsPublisher
paginatePublisher
.collect(.byTime(DispatchQueue.main, 0.1))
.sink { [weak self] _ in
self?.paginateBackwardsIfNeeded()
self?.paginateIfNeeded()
}
.store(in: &cancellables)
@ -164,7 +207,7 @@ class TimelineTableViewController: UIViewController {
guard !hasAppearedOnce else { return }
tableView.contentOffset.y = -1
hasAppearedOnce = true
paginateBackwardsPublisher.send()
paginatePublisher.send()
}
override func viewWillLayoutSubviews() {
@ -210,6 +253,7 @@ class TimelineTableViewController: UIViewController {
guard let viewState else {
return cell
}
cell.contentConfiguration = UIHostingConfiguration {
RoomTimelineItemView(viewState: viewState)
.id(id)
@ -217,7 +261,7 @@ class TimelineTableViewController: UIViewController {
.environmentObject(coordinator.context) // Attempted fix at a crash in TimelineItemContextMenu
.environment(\.roomContext, coordinator.context)
}
.margins(.all, self.timelineStyle.rowInsets)
.margins(.all, 0) // Margins are handled in the stylers
.minSize(height: 1)
.background(Color.clear)
@ -257,42 +301,67 @@ class TimelineTableViewController: UIViewController {
let currentSnapshot = dataSource.snapshot()
MXLog.verbose("DIFF: \(snapshot.itemIdentifiers.difference(from: currentSnapshot.itemIdentifiers))")
// We only animate when new items come at the end of the timeline, ignoring transitions through empty.
let animated = currentSnapshot.sectionIdentifiers.contains(.main) &&
snapshot.sectionIdentifiers.contains(.main) &&
currentSnapshot.numberOfItems(inSection: .main) > 0 &&
snapshot.numberOfItems(inSection: .main) > 0 &&
snapshot.itemIdentifiers(inSection: .main).first != currentSnapshot.itemIdentifiers(inSection: .main).first
// We only animate when new items come at the end of a live timeline, ignoring transitions through empty.
let newestItemIdentifier = snapshot.mainItemIdentifiers.first
let currentNewestItemIdentifier = currentSnapshot.mainItemIdentifiers.first
let newestItemIDChanged = snapshot.numberOfMainItems > 0 && currentSnapshot.numberOfMainItems > 0 && newestItemIdentifier != currentNewestItemIdentifier
let animated = isLive && newestItemIDChanged
let layout: Layout? = if !isLive, newestItemIDChanged {
snapshotLayout()
} else {
nil
}
dataSource.apply(snapshot, animatingDifferences: animated)
if let focussedEventID, focussedEventNeedsDisplay {
scrollToItem(eventID: focussedEventID, animated: false)
} else if let layout {
restoreLayout(layout)
}
}
/// Scrolls to the bottom of the timeline.
private func scrollToBottom(animated: Bool) {
/// Scrolls to the newest item in the timeline.
private func scrollToNewestItem(animated: Bool) {
guard !timelineItemsIDs.isEmpty else {
return
}
tableView.scrollToRow(at: IndexPath(item: 0, section: 0), at: .top, animated: animated)
}
/// Scrolls to the top of the timeline.
private func scrollToTop(animated: Bool) {
/// Scrolls to the oldest item in the timeline.
private func scrollToOldestItem(animated: Bool) {
guard !timelineItemsIDs.isEmpty else {
return
}
tableView.scrollToRow(at: IndexPath(item: timelineItemsIDs.count - 1, section: 1), at: .bottom, animated: animated)
}
/// Checks whether or a backwards pagination is needed and requests one if so.
/// Scrolls to the item with the corresponding event ID if loaded in the timeline.
private func scrollToItem(eventID: String, animated: Bool) {
if let kvPair = timelineItemsDictionary.first(where: { $0.value.identifier.eventID == focussedEventID }),
let indexPath = dataSource?.indexPath(for: kvPair.key) {
tableView.scrollToRow(at: indexPath, at: .middle, animated: animated)
focussedEventNeedsDisplay = false
}
}
/// Checks whether or not pagination is needed in either direction and requests one if so.
///
/// Prefer not to call this directly, instead using ``paginateBackwardsPublisher`` to throttle requests.
private func paginateBackwardsIfNeeded() {
guard canBackPaginate,
!isBackPaginating,
tableView.contentOffset.y > tableView.contentSize.height - tableView.visibleSize.height * 2.0
else { return }
/// **Note:** Prefer not to call this directly, instead using ``paginatePublisher`` to throttle requests.
private func paginateIfNeeded() {
guard !hasPendingItems else { return }
coordinator.send(viewAction: .paginateBackwards)
if paginationState.backward == .idle,
tableView.contentOffset.y > tableView.contentSize.height - tableView.visibleSize.height * 2.0 {
coordinator.send(viewAction: .paginateBackwards)
}
if !isLive,
paginationState.forward == .idle,
tableView.contentOffset.y < tableView.visibleSize.height {
coordinator.send(viewAction: .paginateForwards)
}
}
private func sendLastVisibleItemReadReceipt() {
@ -316,7 +385,7 @@ class TimelineTableViewController: UIViewController {
extension TimelineTableViewController: UITableViewDelegate {
func scrollViewDidScroll(_ scrollView: UIScrollView) {
paginateBackwardsPublisher.send(())
paginatePublisher.send(())
// Dispatch to fix runtime warning about making changes during a view update.
DispatchQueue.main.async { [weak self] in
@ -335,18 +404,26 @@ extension TimelineTableViewController: UITableViewDelegate {
scrollView.contentOffset.y = -1
}
}
func scrollViewShouldScrollToTop(_ scrollView: UIScrollView) -> Bool {
scrollToTop(animated: true)
scrollToOldestItem(animated: true)
return false
}
func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
isDraggingScrollView = true
}
func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
sendLastVisibleItemReadReceipt()
if !decelerate {
isDraggingScrollView = false
}
}
func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
sendLastVisibleItemReadReceipt()
isDraggingScrollView = false
}
func scrollViewDidEndScrollingAnimation(_ scrollView: UIScrollView) {
@ -354,7 +431,7 @@ extension TimelineTableViewController: UITableViewDelegate {
}
}
// MARK: - Layout Types
// MARK: - Layout
extension TimelineTableViewController {
/// The sections of the table view used in the diffable data source.
@ -362,4 +439,67 @@ extension TimelineTableViewController {
case main
case typingIndicator
}
/// A representation of the table's layout based on a particular item.
private struct Layout {
let id: TimelineItemIdentifier
let frame: CGRect
}
/// The current layout of the table, based on the newest timeline item.
private func snapshotLayout() -> Layout? {
guard let newestItemID = newestVisibleItemID(),
let newestCellFrame = cellFrame(for: newestItemID.timelineID) else {
return nil
}
return Layout(id: newestItemID, frame: newestCellFrame)
}
/// Restores the timeline's layout from an old snapshot.
private func restoreLayout(_ layout: Layout) {
if let indexPath = dataSource?.indexPath(for: layout.id.timelineID) {
// Scroll the item into view.
tableView.scrollToRow(at: indexPath, at: .top, animated: false)
// Remove any unwanted offset that was added by scrollToRow.
if let frame = cellFrame(for: layout.id.timelineID) {
let deltaY = frame.maxY - layout.frame.maxY
if deltaY != 0 {
tableView.contentOffset.y -= deltaY
}
}
}
}
/// Returns the frame of the cell for a particular timeline item.
private func cellFrame(for id: String) -> CGRect? {
guard let timelineCell = tableView.visibleCells.first(where: { ($0 as? TimelineItemCell)?.item?.id == id }) else {
return nil
}
return tableView.convert(timelineCell.frame, to: tableView.superview)
}
/// The item ID of the newest visible item in the timeline.
private func newestVisibleItemID() -> TimelineItemIdentifier? {
guard let timelineCell = tableView.visibleCells.first(where: {
guard let cell = $0 as? TimelineItemCell else { return false }
return !(cell.item?.type is PaginationIndicatorRoomTimelineItem)
}) else {
return nil
}
return (timelineCell as? TimelineItemCell)?.item?.identifier
}
}
private extension NSDiffableDataSourceSnapshot<TimelineTableViewController.TimelineSection, String> {
var numberOfMainItems: Int {
guard sectionIdentifiers.contains(.main) else { return 0 }
return numberOfItems(inSection: .main)
}
var mainItemIdentifiers: [String] {
guard sectionIdentifiers.contains(.main) else { return [] }
return itemIdentifiers(inSection: .main)
}
}

View File

@ -18,7 +18,7 @@ import SwiftUI
import WysiwygComposer
/// A table view wrapper that displays the timeline of a room.
struct UITimelineView: UIViewControllerRepresentable {
struct TimelineView: UIViewControllerRepresentable {
@EnvironmentObject private var viewModelContext: RoomScreenViewModel.Context
@Environment(\.timelineStyle) private var timelineStyle
@ -56,11 +56,14 @@ struct UITimelineView: UIViewControllerRepresentable {
if tableViewController.timelineItemsDictionary != context.viewState.timelineViewState.itemsDictionary {
tableViewController.timelineItemsDictionary = context.viewState.timelineViewState.itemsDictionary
}
if tableViewController.canBackPaginate != context.viewState.timelineViewState.canBackPaginate {
tableViewController.canBackPaginate = context.viewState.timelineViewState.canBackPaginate
if tableViewController.paginationState != context.viewState.timelineViewState.paginationState {
tableViewController.paginationState = context.viewState.timelineViewState.paginationState
}
if tableViewController.isBackPaginating != context.viewState.timelineViewState.isBackPaginating {
tableViewController.isBackPaginating = context.viewState.timelineViewState.isBackPaginating
if tableViewController.isLive != context.viewState.timelineViewState.isLive {
tableViewController.isLive = context.viewState.timelineViewState.isLive
}
if tableViewController.focussedEventID != context.viewState.timelineViewState.focussedEventID {
tableViewController.focussedEventID = context.viewState.timelineViewState.focussedEventID
}
if tableViewController.typingMembers.members != context.viewState.typingMembers {
@ -76,7 +79,7 @@ struct UITimelineView: UIViewControllerRepresentable {
// MARK: - Previews
struct UITimelineView_Previews: PreviewProvider, TestablePreview {
struct TimelineView_Previews: PreviewProvider, TestablePreview {
static let viewModel = RoomScreenViewModel(roomProxy: RoomProxyMock(with: .init(name: "Preview room")),
timelineController: MockRoomTimelineController(),
mediaProvider: MockMediaProvider(),

View File

@ -51,59 +51,11 @@ class RoomProxy: RoomProxyProtocol {
actionsSubject.eraseToAnyPublisher()
}
lazy var id: String = room.id()
var ownUserID: String {
room.ownUserId()
}
init?(roomListItem: RoomListItemProtocol,
room: RoomProtocol) async {
self.roomListItem = roomListItem
self.room = room
do {
timeline = try await TimelineProxy(timeline: room.timeline())
} catch {
MXLog.error("Failed creating timeline with error: \(error)")
return nil
}
Task {
await updateMembers()
}
}
func subscribeForUpdates() async {
guard !subscribedForUpdates else {
MXLog.warning("Room already subscribed for updates")
return
}
subscribedForUpdates = true
let settings = RoomSubscription(requiredState: [RequiredState(key: "m.room.name", value: ""),
RequiredState(key: "m.room.topic", value: ""),
RequiredState(key: "m.room.avatar", value: ""),
RequiredState(key: "m.room.canonical_alias", value: ""),
RequiredState(key: "m.room.join_rules", value: "")],
timelineLimit: UInt32(SlidingSyncConstants.defaultTimelineLimit))
roomListItem.subscribe(settings: settings)
Self.subscriptionCountPerRoom[roomListItem.id()] = (Self.subscriptionCountPerRoom[roomListItem.id()] ?? 0) + 1
await timeline.subscribeForUpdates()
subscribeToRoomInfoUpdates()
subscribeToTypingNotifications()
}
func unsubscribeFromUpdates() {
Self.subscriptionCountPerRoom[roomListItem.id()] = max(0, (Self.subscriptionCountPerRoom[roomListItem.id()] ?? 0) - 1)
if Self.subscriptionCountPerRoom[roomListItem.id()] ?? 0 <= 0 {
roomListItem.unsubscribe()
}
}
lazy var id: String = room.id()
var name: String? {
roomListItem.name()
@ -158,6 +110,65 @@ class RoomProxy: RoomProxyProtocol {
var activeMembersCount: Int {
Int(room.activeMembersCount())
}
init?(roomListItem: RoomListItemProtocol,
room: RoomProtocol) async {
self.roomListItem = roomListItem
self.room = room
do {
timeline = try await TimelineProxy(timeline: room.timeline(), isLive: true)
} catch {
MXLog.error("Failed creating timeline with error: \(error)")
return nil
}
Task {
await updateMembers()
}
}
func subscribeForUpdates() async {
guard !subscribedForUpdates else {
MXLog.warning("Room already subscribed for updates")
return
}
subscribedForUpdates = true
let settings = RoomSubscription(requiredState: [RequiredState(key: "m.room.name", value: ""),
RequiredState(key: "m.room.topic", value: ""),
RequiredState(key: "m.room.avatar", value: ""),
RequiredState(key: "m.room.canonical_alias", value: ""),
RequiredState(key: "m.room.join_rules", value: "")],
timelineLimit: UInt32(SlidingSyncConstants.defaultTimelineLimit))
roomListItem.subscribe(settings: settings)
Self.subscriptionCountPerRoom[roomListItem.id()] = (Self.subscriptionCountPerRoom[roomListItem.id()] ?? 0) + 1
await timeline.subscribeForUpdates()
subscribeToRoomInfoUpdates()
subscribeToTypingNotifications()
}
func unsubscribeFromUpdates() {
Self.subscriptionCountPerRoom[roomListItem.id()] = max(0, (Self.subscriptionCountPerRoom[roomListItem.id()] ?? 0) - 1)
if Self.subscriptionCountPerRoom[roomListItem.id()] ?? 0 <= 0 {
roomListItem.unsubscribe()
}
}
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))
// }
}
func redact(_ eventID: String) async -> Result<Void, RoomProxyError> {
await Task.dispatch(on: userInitiatedDispatchQueue) {

View File

@ -64,6 +64,8 @@ protocol RoomProxyProtocol {
func unsubscribeFromUpdates()
func timelineFocusedOnEvent(eventID: String, numberOfEvents: UInt16) async -> Result<TimelineProxyProtocol, RoomProxyError>
func redact(_ eventID: String) async -> Result<Void, RoomProxyError>
func reportContent(_ eventID: String, reason: String?) async -> Result<Void, RoomProxyError>

View File

@ -227,7 +227,7 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
var lastMessageFormattedTimestamp: String?
if let latestRoomMessage = roomInfo.latestEvent {
let lastMessage = EventTimelineItemProxy(item: latestRoomMessage, id: 0)
let lastMessage = EventTimelineItemProxy(item: latestRoomMessage, id: "0")
lastMessageFormattedTimestamp = lastMessage.timestamp.formattedMinimal()
attributedLastMessage = eventStringBuilder.buildAttributedString(for: lastMessage)
}

View File

@ -22,9 +22,9 @@ class RoomTimelineProvider: RoomTimelineProviderProtocol {
private var cancellables = Set<AnyCancellable>()
private let serialDispatchQueue: DispatchQueue
private let backPaginationStateSubject = CurrentValueSubject<BackPaginationStatus, Never>(.idle)
var backPaginationState: BackPaginationStatus {
backPaginationStateSubject.value
private let paginationStateSubject = CurrentValueSubject<PaginationState, Never>(.default)
var paginationState: PaginationState {
paginationStateSubject.value
}
private let itemProxiesSubject: CurrentValueSubject<[TimelineItemProxy], Never>
@ -32,13 +32,14 @@ class RoomTimelineProvider: RoomTimelineProviderProtocol {
itemProxiesSubject.value
}
var updatePublisher: AnyPublisher<Void, Never> {
var updatePublisher: AnyPublisher<([TimelineItemProxy], PaginationState), Never> {
itemProxiesSubject
.combineLatest(backPaginationStateSubject)
.map { _, _ in () }
.combineLatest(paginationStateSubject)
.eraseToAnyPublisher()
}
private(set) var isLive: Bool
private let membershipChangeSubject = PassthroughSubject<Void, Never>()
var membershipChangePublisher: AnyPublisher<Void, Never> {
membershipChangeSubject
@ -46,10 +47,12 @@ class RoomTimelineProvider: RoomTimelineProviderProtocol {
}
init(currentItems: [TimelineItem],
isLive: Bool,
updatePublisher: AnyPublisher<[TimelineDiff], Never>,
backPaginationStatePublisher: AnyPublisher<BackPaginationStatus, Never>) {
paginationStatePublisher: AnyPublisher<PaginationState, Never>) {
serialDispatchQueue = DispatchQueue(label: "io.element.elementx.roomtimelineprovider", qos: .utility)
itemProxiesSubject = CurrentValueSubject<[TimelineItemProxy], Never>(currentItems.map(TimelineItemProxy.init))
self.isLive = isLive
// Manually call it here as the didSet doesn't work from constructors
itemProxiesSubject.send(itemProxies)
@ -59,8 +62,10 @@ class RoomTimelineProvider: RoomTimelineProviderProtocol {
.sink { [weak self] in self?.updateItemsWithDiffs($0) }
.store(in: &cancellables)
backPaginationStatePublisher
.sink { [weak self] in self?.backPaginationStateSubject.send($0) }
paginationStatePublisher
.sink { [weak self] in
self?.paginationStateSubject.send($0)
}
.store(in: &cancellables)
}

View File

@ -16,18 +16,25 @@
import Combine
import Foundation
import MatrixRustSDK
struct PaginationState: Equatable {
static var `default` = PaginationState(backward: .idle, forward: .timelineStartReached)
let backward: BackPaginationStatus
let forward: BackPaginationStatus
}
@MainActor
// sourcery: AutoMockable
protocol RoomTimelineProviderProtocol {
/// A publisher that signals when ``itemProxies`` or ``backPaginationState`` are changed.
var updatePublisher: AnyPublisher<Void, Never> { get }
/// A publisher that signals when ``itemProxies`` or ``paginationState`` are changed.
var updatePublisher: AnyPublisher<([TimelineItemProxy], PaginationState), Never> { get }
/// The current set of items in the timeline.
var itemProxies: [TimelineItemProxy] { get }
/// Whether the timeline is back paginating or not (or has reached the start of the room).
var backPaginationState: BackPaginationStatus { get }
/// Whether the timeline is back/forward paginating or not (or has reached the start/end of the room).
var paginationState: PaginationState { get }
/// Whether or not the provider is for a live timeline.
var isLive: Bool { get }
/// A publisher that signals when changes to the room's membership have occurred through `/sync`.
///
/// This is temporary and will be replace by a subscription on the room itself.

View File

@ -36,6 +36,9 @@ class MockRoomTimelineController: RoomTimelineControllerProtocol {
private var client: UITestsSignalling.Client?
init(listenForSignals: Bool = false) {
callbacks.send(.paginationState(PaginationState(backward: .idle, forward: .timelineStartReached)))
callbacks.send(.isLive(true))
guard listenForSignals else { return }
do {
@ -44,17 +47,35 @@ class MockRoomTimelineController: RoomTimelineControllerProtocol {
fatalError("Failure setting up signalling: \(error)")
}
}
func paginateBackwards(requestSize: UInt) async -> Result<Void, RoomTimelineControllerError> {
try? await simulateBackPagination()
private(set) var focusOnEventCallCount = 0
func focusOnEvent(_ eventID: String, timelineSize: UInt16) async -> Result<Void, RoomTimelineControllerError> {
focusOnEventCallCount += 1
callbacks.send(.isLive(false))
return .success(())
}
private(set) var focusLiveCallCount = 0
func focusLive() {
focusLiveCallCount += 1
callbacks.send(.isLive(true))
}
func paginateBackwards(requestSize: UInt, untilNumberOfItems: UInt) async -> Result<Void, RoomTimelineControllerError> {
callbacks.send(.canBackPaginate(false))
func paginateBackwards(requestSize: UInt16) async -> Result<Void, RoomTimelineControllerError> {
callbacks.send(.paginationState(PaginationState(backward: .paginating, forward: .timelineStartReached)))
if client == nil {
try? await simulateBackPagination()
}
return .success(())
}
func paginateForwards(requestSize: UInt16) async -> Result<Void, RoomTimelineControllerError> {
// try? await simulateForwardPagination()
.success(())
}
func sendReadReceipt(for itemID: TimelineItemIdentifier) async {
guard let roomProxy, let eventID = itemID.eventID else { return }
_ = await roomProxy.timeline.sendReadReceipt(for: eventID, type: .read)
@ -151,14 +172,16 @@ 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)))
}
guard !backPaginationResponses.isEmpty else { return }
callbacks.send(.isBackPaginating(true))
let newItems = backPaginationResponses.removeFirst()
timelineItems.insert(contentsOf: newItems, at: 0)
callbacks.send(.updatedTimelineItems)
callbacks.send(.isBackPaginating(false))
callbacks.send(.canBackPaginate(!backPaginationResponses.isEmpty))
try client?.send(.success)
}

View File

@ -21,7 +21,7 @@ import UIKit
class RoomTimelineController: RoomTimelineControllerProtocol {
private let roomProxy: RoomProxyProtocol
private let timelineProvider: RoomTimelineProviderProtocol
private let liveTimelineProvider: RoomTimelineProviderProtocol
private let timelineItemFactory: RoomTimelineItemFactoryProtocol
private let appSettings: AppSettings
private let serialDispatchQueue: DispatchQueue
@ -30,6 +30,13 @@ class RoomTimelineController: RoomTimelineControllerProtocol {
let callbacks = PassthroughSubject<RoomTimelineControllerCallback, Never>()
private var activeTimeline: TimelineProxyProtocol
private var activeTimelineProvider: RoomTimelineProviderProtocol {
didSet {
configureActiveTimelineProvider(clearExistingItems: true)
}
}
private(set) var timelineItems = [RoomTimelineItemProtocol]()
var roomID: String {
@ -40,34 +47,39 @@ class RoomTimelineController: RoomTimelineControllerProtocol {
timelineItemFactory: RoomTimelineItemFactoryProtocol,
appSettings: AppSettings) {
self.roomProxy = roomProxy
timelineProvider = roomProxy.timeline.timelineProvider
liveTimelineProvider = roomProxy.timeline.timelineProvider
self.timelineItemFactory = timelineItemFactory
self.appSettings = appSettings
serialDispatchQueue = DispatchQueue(label: "io.element.elementx.roomtimelineprovider", qos: .utility)
timelineProvider
.updatePublisher
.receive(on: serialDispatchQueue)
.sink { [weak self] _ in
guard let self else { return }
self.updateTimelineItems()
}
.store(in: &cancellables)
// Inform the world that the initial items are loading from the store
callbacks.send(.isBackPaginating(true))
serialDispatchQueue.async {
self.updateTimelineItems()
self.callbacks.send(.isBackPaginating(false))
}
activeTimeline = roomProxy.timeline
activeTimelineProvider = liveTimelineProvider
configureActiveTimelineProvider()
NotificationCenter.default.addObserver(self, selector: #selector(contentSizeCategoryDidChange), name: UIContentSizeCategory.didChangeNotification, object: nil)
}
func paginateBackwards(requestSize: UInt) async -> Result<Void, RoomTimelineControllerError> {
func focusOnEvent(_ eventID: String, timelineSize: UInt16) async -> Result<Void, RoomTimelineControllerError> {
switch await roomProxy.timelineFocusedOnEvent(eventID: eventID, numberOfEvents: timelineSize) {
case .success(let timeline):
await timeline.subscribeForUpdates()
activeTimeline = timeline
activeTimelineProvider = timeline.timelineProvider
return .success(())
case .failure:
return .failure(.generic)
}
}
func focusLive() {
activeTimeline = roomProxy.timeline
activeTimelineProvider = liveTimelineProvider
callbacks.send(.isLive(true))
}
func paginateBackwards(requestSize: UInt16) async -> Result<Void, RoomTimelineControllerError> {
MXLog.info("Started back pagination request")
switch await roomProxy.timeline.paginateBackwards(requestSize: requestSize) {
switch await activeTimeline.paginateBackwards(requestSize: requestSize) {
case .success:
MXLog.info("Finished back pagination request")
return .success(())
@ -77,14 +89,14 @@ class RoomTimelineController: RoomTimelineControllerProtocol {
}
}
func paginateBackwards(requestSize: UInt, untilNumberOfItems: UInt) async -> Result<Void, RoomTimelineControllerError> {
MXLog.info("Started back pagination request")
switch await roomProxy.timeline.paginateBackwards(requestSize: requestSize, untilNumberOfItems: untilNumberOfItems) {
func paginateForwards(requestSize: UInt16) async -> Result<Void, RoomTimelineControllerError> {
MXLog.info("Started forward pagination request")
switch await activeTimeline.paginateForwards(requestSize: requestSize) {
case .success:
MXLog.info("Finished back pagination request")
MXLog.info("Finished forward pagination request")
return .success(())
case .failure(let error):
MXLog.error("Failed back pagination request with error: \(error)")
MXLog.error("Failed forward pagination request with error: \(error)")
return .failure(.generic)
}
}
@ -149,7 +161,7 @@ class RoomTimelineController: RoomTimelineControllerProtocol {
return
}
switch await roomProxy.timeline.toggleReaction(reaction, to: eventID) {
switch await activeTimeline.toggleReaction(reaction, to: eventID) {
case .success:
MXLog.info("Finished toggling reaction")
case .failure(let error):
@ -169,10 +181,10 @@ class RoomTimelineController: RoomTimelineControllerProtocol {
await cancelSending(itemID: itemID)
await sendMessage(newMessage, html: html, intentionalMentions: intentionalMentions)
} else if let eventID = itemID.eventID {
switch await roomProxy.timeline.editMessage(newMessage,
html: html,
original: eventID,
intentionalMentions: intentionalMentions) {
switch await activeTimeline.editMessage(newMessage,
html: html,
original: eventID,
intentionalMentions: intentionalMentions) {
case .success:
MXLog.info("Finished editing message")
case .failure(let error):
@ -199,7 +211,7 @@ class RoomTimelineController: RoomTimelineControllerProtocol {
// Handle this parallel to the timeline items so we're not forced
// to bundle the Rust side objects within them
func debugInfo(for itemID: TimelineItemIdentifier) -> TimelineItemDebugInfo {
for timelineItemProxy in timelineProvider.itemProxies {
for timelineItemProxy in activeTimelineProvider.itemProxies {
switch timelineItemProxy {
case .event(let item):
if item.id == itemID {
@ -214,7 +226,7 @@ class RoomTimelineController: RoomTimelineControllerProtocol {
}
func retryDecryption(for sessionID: String) async {
await roomProxy.timeline.retryDecryption(for: sessionID)
await activeTimeline.retryDecryption(for: sessionID)
}
func retrySending(itemID: TimelineItemIdentifier) async {
@ -239,19 +251,46 @@ class RoomTimelineController: RoomTimelineControllerProtocol {
// MARK: - Private
@objc private func contentSizeCategoryDidChange() {
// Recompute all attributed strings on content size changes -> DynamicType support
serialDispatchQueue.async {
self.updateTimelineItems()
/// The cancellable used to update the timeline items.
private var updateTimelineItemsCancellable: AnyCancellable?
/// Configures the controller to listen to `activeTimeline` for events.
/// - Parameter clearExistingItems: Whether or not to clear any existing items before loading the timeline's contents.
private func configureActiveTimelineProvider(clearExistingItems: Bool = false) {
updateTimelineItemsCancellable = activeTimelineProvider
.updatePublisher
.receive(on: serialDispatchQueue)
.sink { [weak self] items, paginationState in
self?.updateTimelineItems(itemProxies: items, paginationState: paginationState)
}
// Inform the world that the initial items are loading from the store
callbacks.send(.paginationState(.init(backward: .paginating, forward: .paginating)))
callbacks.send(.isLive(activeTimelineProvider.isLive))
if clearExistingItems {
// Transition through empty to prevent animations.
timelineItems.removeAll()
callbacks.send(.updatedTimelineItems)
}
serialDispatchQueue.async { [activeTimelineProvider] in
self.updateTimelineItems(itemProxies: activeTimelineProvider.itemProxies, paginationState: activeTimelineProvider.paginationState)
self.callbacks.send(.paginationState(.init(backward: .idle, forward: .idle)))
}
}
private func updateTimelineItems() {
@objc private func contentSizeCategoryDidChange() {
// Recompute all attributed strings on content size changes -> DynamicType support
serialDispatchQueue.async { [activeTimelineProvider] in
self.updateTimelineItems(itemProxies: activeTimelineProvider.itemProxies, paginationState: activeTimelineProvider.paginationState)
}
}
private func updateTimelineItems(itemProxies: [TimelineItemProxy], paginationState: PaginationState) {
var newTimelineItems = [RoomTimelineItemProtocol]()
var canBackPaginate = !roomProxy.timeline.timelineStartReached
var isBackPaginating = false
let collapsibleChunks = timelineProvider.itemProxies.groupBy { isItemCollapsible($0) }
let collapsibleChunks = itemProxies.groupBy { isItemCollapsible($0) }
for (index, collapsibleChunk) in collapsibleChunks.enumerated() {
let isLastItem = index == collapsibleChunks.indices.last
@ -281,27 +320,31 @@ class RoomTimelineController: RoomTimelineControllerProtocol {
}
// Check if we need to add anything to the top of the timeline.
switch timelineProvider.backPaginationState {
switch paginationState.backward {
case .timelineStartReached:
if !roomProxy.isEncryptedOneToOneRoom {
let timelineStart = TimelineStartRoomTimelineItem(name: roomProxy.name)
newTimelineItems.insert(timelineStart, at: 0)
}
canBackPaginate = false
case .paginating:
newTimelineItems.insert(PaginationIndicatorRoomTimelineItem(), at: 0)
isBackPaginating = true
newTimelineItems.insert(PaginationIndicatorRoomTimelineItem(position: .start), at: 0)
case .idle:
break
}
switch paginationState.forward {
case .paginating:
newTimelineItems.insert(PaginationIndicatorRoomTimelineItem(position: .end), at: newTimelineItems.count)
case .idle, .timelineStartReached:
break
}
DispatchQueue.main.sync {
timelineItems = newTimelineItems
}
callbacks.send(.updatedTimelineItems)
callbacks.send(.canBackPaginate(canBackPaginate))
callbacks.send(.isBackPaginating(isBackPaginating))
callbacks.send(.paginationState(paginationState))
}
private func buildTimelineItem(for itemProxy: TimelineItemProxy) -> RoomTimelineItemProtocol? {
@ -355,10 +398,10 @@ class RoomTimelineController: RoomTimelineControllerProtocol {
switch timelineItem.replyDetails {
case .notLoaded:
roomProxy.timeline.fetchDetails(for: eventID)
activeTimeline.fetchDetails(for: eventID)
case .error:
if refetchOnError {
roomProxy.timeline.fetchDetails(for: eventID)
activeTimeline.fetchDetails(for: eventID)
}
default:
break
@ -366,7 +409,7 @@ class RoomTimelineController: RoomTimelineControllerProtocol {
}
func eventTimestamp(for itemID: TimelineItemIdentifier) -> Date? {
for itemProxy in roomProxy.timeline.timelineProvider.itemProxies {
for itemProxy in activeTimelineProvider.itemProxies {
switch itemProxy {
case .event(let eventTimelineItemProxy):
if eventTimelineItemProxy.id == itemID {

View File

@ -20,8 +20,8 @@ import UIKit
enum RoomTimelineControllerCallback {
case updatedTimelineItems
case canBackPaginate(Bool)
case isBackPaginating(Bool)
case paginationState(PaginationState)
case isLive(Bool)
}
enum RoomTimelineControllerAction {
@ -45,9 +45,11 @@ protocol RoomTimelineControllerProtocol {
func processItemDisappearance(_ itemID: TimelineItemIdentifier) async
func paginateBackwards(requestSize: UInt) async -> Result<Void, RoomTimelineControllerError>
func focusOnEvent(_ eventID: String, timelineSize: UInt16) async -> Result<Void, RoomTimelineControllerError>
func focusLive()
func paginateBackwards(requestSize: UInt, untilNumberOfItems: UInt) async -> Result<Void, RoomTimelineControllerError>
func paginateBackwards(requestSize: UInt16) async -> Result<Void, RoomTimelineControllerError>
func paginateForwards(requestSize: UInt16) async -> Result<Void, RoomTimelineControllerError>
func sendReadReceipt(for itemID: TimelineItemIdentifier) async

View File

@ -46,7 +46,7 @@ enum TimelineItemProxy {
init(item: MatrixRustSDK.TimelineItem) {
if let eventItem = item.asEvent() {
self = .event(EventTimelineItemProxy(item: eventItem, id: item.uniqueId()))
self = .event(EventTimelineItemProxy(item: eventItem, id: String(item.uniqueId())))
} else if let virtualItem = item.asVirtual() {
self = .virtual(virtualItem, timelineID: String(item.uniqueId()))
} else {
@ -67,9 +67,9 @@ class EventTimelineItemProxy {
let item: MatrixRustSDK.EventTimelineItem
let id: TimelineItemIdentifier
init(item: MatrixRustSDK.EventTimelineItem, id: UInt64) {
init(item: MatrixRustSDK.EventTimelineItem, id: String) {
self.item = item
self.id = TimelineItemIdentifier(timelineID: String(id), eventID: item.eventId(), transactionID: item.transactionId())
self.id = TimelineItemIdentifier(timelineID: id, eventID: item.eventId(), transactionID: item.transactionId())
}
lazy var deliveryStatus: TimelineItemDeliveryStatus? = {

View File

@ -17,5 +17,20 @@
import Foundation
struct PaginationIndicatorRoomTimelineItem: DecorationTimelineItemProtocol, Equatable {
let id = TimelineItemIdentifier(timelineID: "paginationIndicatorTimelineItemIdentifier")
let id: TimelineItemIdentifier
enum Position {
case start, end
var id: String {
switch self {
case .start: "backwardPaginationIndicatorTimelineItemIdentifier"
case .end: "forwardPaginationIndicatorTimelineItemIdentifier"
}
}
}
init(position: Position) {
id = TimelineItemIdentifier(timelineID: position.id)
}
}

View File

@ -25,21 +25,22 @@ final class TimelineProxy: TimelineProxyProtocol {
private let messageSendingDispatchQueue = DispatchQueue(label: "io.element.elementx.roomproxy.message_sending", qos: .userInitiated)
private let userInitiatedDispatchQueue = DispatchQueue(label: "io.element.elementx.roomproxy.user_initiated", qos: .userInitiated)
private var backPaginationStateObservationToken: TaskHandle?
private var backPaginationStatusObservationToken: TaskHandle?
private var roomTimelineObservationToken: TaskHandle?
// periphery:ignore - retaining purpose
private var timelineListener: RoomTimelineListener?
private let backPaginationStateSubject = PassthroughSubject<BackPaginationStatus, Never>()
private let backPaginationStatusSubject = CurrentValueSubject<BackPaginationStatus, Never>(.idle)
private let forwardPaginationStatusSubject = CurrentValueSubject<BackPaginationStatus, Never>(.timelineStartReached)
private let timelineUpdatesSubject = PassthroughSubject<[TimelineDiff], Never>()
private(set) var timelineStartReached = false
private let actionsSubject = PassthroughSubject<TimelineProxyAction, Never>()
var actions: AnyPublisher<TimelineProxyAction, Never> {
actionsSubject.eraseToAnyPublisher()
}
let isLive: Bool
private var innerTimelineProvider: RoomTimelineProviderProtocol!
var timelineProvider: RoomTimelineProviderProtocol {
@ -47,12 +48,13 @@ final class TimelineProxy: TimelineProxyProtocol {
}
deinit {
backPaginationStateObservationToken?.cancel()
backPaginationStatusObservationToken?.cancel()
roomTimelineObservationToken?.cancel()
}
init(timeline: Timeline) {
init(timeline: Timeline, isLive: Bool) {
self.timeline = timeline
self.isLive = isLive
}
func subscribeForUpdates() async {
@ -70,11 +72,17 @@ final class TimelineProxy: TimelineProxyProtocol {
let result = await timeline.addListener(listener: timelineListener)
roomTimelineObservationToken = result.itemsStream
subscribeToBackpagination()
let paginationStatePublisher = backPaginationStatusSubject
.combineLatest(forwardPaginationStatusSubject)
.map { PaginationState(backward: $0.0, forward: $0.1) }
.eraseToAnyPublisher()
subscribeToPagination()
innerTimelineProvider = await RoomTimelineProvider(currentItems: result.items,
isLive: isLive,
updatePublisher: timelineUpdatesSubject.eraseToAnyPublisher(),
backPaginationStatePublisher: backPaginationStateSubject.eraseToAnyPublisher())
paginationStatePublisher: paginationStatePublisher)
}
func cancelSend(transactionID: String) async {
@ -138,38 +146,43 @@ final class TimelineProxy: TimelineProxyProtocol {
}
}
func paginateBackwards(requestSize: UInt) async -> Result<Void, TimelineProxyError> {
MXLog.info("Paginating backwards with requestSize: \(requestSize)")
func paginateBackwards(requestSize: UInt16) async -> Result<Void, TimelineProxyError> {
MXLog.info("Paginating backwards")
do {
try await Task.dispatch(on: .global()) {
try self.timeline.paginateBackwards(opts: .simpleRequest(eventLimit: UInt16(requestSize), waitForToken: true))
}
MXLog.info("Finished paginating backwards with requestSize: \(requestSize)")
_ = try timeline.paginateBackwards(opts: .simpleRequest(eventLimit: requestSize, waitForToken: true))
MXLog.info("Finished paginating backwards")
return .success(())
} catch {
MXLog.error("Failed paginating backwards with requestSize: \(requestSize) with error: \(error)")
MXLog.error("Failed paginating backwards with error: \(error)")
return .failure(.failedPaginatingBackwards)
}
}
func paginateBackwards(requestSize: UInt, untilNumberOfItems: UInt) async -> Result<Void, TimelineProxyError> {
MXLog.info("Paginating backwards with requestSize: \(requestSize), untilNumberOfItems: \(untilNumberOfItems)")
do {
try await Task.dispatch(on: .global()) {
try self.timeline.paginateBackwards(opts: .untilNumItems(eventLimit: UInt16(requestSize), items: UInt16(untilNumberOfItems), waitForToken: true))
}
MXLog.info("Finished paginating backwards with requestSize: \(requestSize), untilNumberOfItems: \(untilNumberOfItems)")
return .success(())
} catch {
MXLog.error("Finished paginating backwards with requestSize: \(requestSize), untilNumberOfItems: \(untilNumberOfItems) with error: \(error)")
return .failure(.failedPaginatingBackwards)
}
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)
// }
}
func retryDecryption(for sessionID: String) async {
@ -536,18 +549,18 @@ final class TimelineProxy: TimelineProxyProtocol {
}
}
private func subscribeToBackpagination() {
let listener = RoomBackpaginationStatusListener { [weak self] status in
if status == .timelineStartReached {
self?.timelineStartReached = true
}
self?.backPaginationStateSubject.send(status)
private func subscribeToPagination() {
let backPaginationListener = RoomPaginationStatusListener { [weak self] status in
self?.backPaginationStatusSubject.send(status)
}
do {
backPaginationStateObservationToken = try timeline.subscribeToBackPaginationStatus(listener: listener)
backPaginationStatusObservationToken = try timeline.subscribeToBackPaginationStatus(listener: backPaginationListener)
} catch {
MXLog.error("Failed to subscribe to back pagination state with error: \(error)")
MXLog.error("Failed to subscribe to back pagination status with error: \(error)")
}
// Forward pagination doesn't support observation, set the initial state ourself.
forwardPaginationStatusSubject.send(isLive ? .timelineStartReached : .idle)
}
}
@ -563,7 +576,7 @@ private final class RoomTimelineListener: TimelineListener {
}
}
private final class RoomBackpaginationStatusListener: BackPaginationStatusListener {
private final class RoomPaginationStatusListener: BackPaginationStatusListener {
private let onUpdateClosure: (BackPaginationStatus) -> Void
init(_ onUpdateClosure: @escaping (BackPaginationStatus) -> Void) {

View File

@ -41,9 +41,9 @@ enum TimelineProxyAction {
protocol TimelineProxyProtocol {
var actions: AnyPublisher<TimelineProxyAction, Never> { get }
var timelineProvider: RoomTimelineProviderProtocol { get }
var isLive: Bool { get }
var timelineStartReached: Bool { get }
var timelineProvider: RoomTimelineProviderProtocol { get }
func subscribeForUpdates() async
@ -64,9 +64,8 @@ protocol TimelineProxyProtocol {
/// Retries sending a failed message given its transaction ID
func retrySend(transactionID: String) async
func paginateBackwards(requestSize: UInt) async -> Result<Void, TimelineProxyError>
func paginateBackwards(requestSize: UInt, untilNumberOfItems: UInt) async -> Result<Void, TimelineProxyError>
func paginateBackwards(requestSize: UInt16) async -> Result<Void, TimelineProxyError>
func paginateForwards(requestSize: UInt16) async -> Result<Void, TimelineProxyError>
func sendAudio(url: URL,
audioInfo: AudioInfo,

Some files were not shown because too many files have changed in this diff Show More