Pinned events banner goes backwards (#3128)
This commit is contained in:
@@ -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" */ = {
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<String, AttributedString>()
|
||||
|
||||
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 {
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user