diff --git a/ElementX.xcodeproj/project.pbxproj b/ElementX.xcodeproj/project.pbxproj index 9754418b6a..9838235684 100644 --- a/ElementX.xcodeproj/project.pbxproj +++ b/ElementX.xcodeproj/project.pbxproj @@ -7569,7 +7569,7 @@ repositoryURL = "https://github.com/element-hq/matrix-rust-components-swift"; requirement = { kind = exactVersion; - version = 1.0.33; + version = 1.0.35; }; }; 701C7BEF8F70F7A83E852DCC /* XCRemoteSwiftPackageReference "GZIP" */ = { diff --git a/ElementX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/ElementX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 62c76091e0..7372748e50 100644 --- a/ElementX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/ElementX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -149,8 +149,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/element-hq/matrix-rust-components-swift", "state" : { - "revision" : "2f11bfecae2c83218fea4336361cabcf3a899a78", - "version" : "1.0.33" + "revision" : "410fa67337a0af99bbf04a775788520d98d6d8d2", + "version" : "1.0.35" } }, { diff --git a/ElementX/Sources/Screens/RoomScreen/RoomScreenModels.swift b/ElementX/Sources/Screens/RoomScreen/RoomScreenModels.swift index 41e46be6f5..08397682e8 100644 --- a/ElementX/Sources/Screens/RoomScreen/RoomScreenModels.swift +++ b/ElementX/Sources/Screens/RoomScreen/RoomScreenModels.swift @@ -329,20 +329,24 @@ struct PinnedEventsState: Equatable { var selectedPinContent: AttributedString { var content = AttributedString(" ") if let selectedPinEventID, - var pinnedEventContent = pinnedEventContents[selectedPinEventID] { + let pinnedEventContent = pinnedEventContents[selectedPinEventID] { content = pinnedEventContent } content.font = .compound.bodyMD return content } - mutating func nextPin() { + mutating func previousPin() { guard !pinnedEventContents.isEmpty else { return } let currentIndex = selectedPinIndex - let nextIndex = (currentIndex + 1) % pinnedEventContents.count - selectedPinEventID = pinnedEventContents.keys[nextIndex] + let nextIndex = currentIndex - 1 + if nextIndex == -1 { + selectedPinEventID = pinnedEventContents.keys.last + } else { + selectedPinEventID = pinnedEventContents.keys[nextIndex % pinnedEventContents.count] + } } } @@ -415,10 +419,10 @@ enum PinnedEventsBannerState: Equatable { return finalString } - mutating func nextPin() { + mutating func previousPin() { switch self { case .loaded(var state): - state.nextPin() + state.previousPin() self = .loaded(state: state) default: break diff --git a/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift b/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift index cf4a204d1f..d2c457034f 100644 --- a/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift +++ b/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift @@ -228,7 +228,7 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol if let eventID = state.pinnedEventsBannerState.selectedPinEventID { Task { await focusOnEvent(eventID: eventID) } } - state.pinnedEventsBannerState.nextPin() + state.pinnedEventsBannerState.previousPin() case .viewAllPins: // TODO: Implement break @@ -723,7 +723,7 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol private func buildPinnedEventContent(timelineItems: [TimelineItemProxy]) { var pinnedEventContents = OrderedDictionary() - for item in timelineItems.reversed() { + for item in timelineItems { // Only remote events are pinned if case let .event(event) = item, let eventID = event.id.eventID { diff --git a/UnitTests/Sources/PinnedEventsBannerStateTests.swift b/UnitTests/Sources/PinnedEventsBannerStateTests.swift index bddb32baf6..9e35c5664f 100644 --- a/UnitTests/Sources/PinnedEventsBannerStateTests.swift +++ b/UnitTests/Sources/PinnedEventsBannerStateTests.swift @@ -32,7 +32,7 @@ class PinnedEventsBannerStateTests: XCTestCase { var state = originalState // This should not affect the state when loading - state.nextPin() + state.previousPin() XCTAssertEqual(state, originalState) XCTAssertTrue(state.isLoading) @@ -63,18 +63,18 @@ class PinnedEventsBannerStateTests: XCTestCase { XCTAssertEqual(state.bannerIndicatorDescription.string, L10n.screenRoomPinnedBannerIndicatorDescription(L10n.screenRoomPinnedBannerIndicator(2, 2))) } - func testNextPin() { - var state = PinnedEventsBannerState.loaded(state: .init(pinnedEventContents: ["1": "test1", "2": "test2", "3": "test3"], selectedPinEventID: "3")) - XCTAssertEqual(state.selectedPinEventID, "3") - XCTAssertEqual(state.selectedPinIndex, 2) - XCTAssertEqual(state.displayedMessage.string, "test3") - - state.nextPin() + func testPreviousPin() { + var state = PinnedEventsBannerState.loaded(state: .init(pinnedEventContents: ["1": "test1", "2": "test2", "3": "test3"], selectedPinEventID: "1")) XCTAssertEqual(state.selectedPinEventID, "1") XCTAssertEqual(state.selectedPinIndex, 0) XCTAssertEqual(state.displayedMessage.string, "test1") - state.nextPin() + state.previousPin() + XCTAssertEqual(state.selectedPinEventID, "3") + XCTAssertEqual(state.selectedPinIndex, 2) + XCTAssertEqual(state.displayedMessage.string, "test3") + + state.previousPin() XCTAssertEqual(state.selectedPinEventID, "2") XCTAssertEqual(state.selectedPinIndex, 1) XCTAssertEqual(state.displayedMessage.string, "test2") diff --git a/project.yml b/project.yml index 1eace48017..524e2ac84e 100644 --- a/project.yml +++ b/project.yml @@ -60,7 +60,7 @@ packages: # Element/Matrix dependencies MatrixRustSDK: url: https://github.com/element-hq/matrix-rust-components-swift - exactVersion: 1.0.33 + exactVersion: 1.0.35 # path: ../matrix-rust-sdk Compound: url: https://github.com/element-hq/compound-ios