mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 16:10:20 +00:00
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";
|
repositoryURL = "https://github.com/element-hq/matrix-rust-components-swift";
|
||||||
requirement = {
|
requirement = {
|
||||||
kind = exactVersion;
|
kind = exactVersion;
|
||||||
version = 1.0.33;
|
version = 1.0.35;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
701C7BEF8F70F7A83E852DCC /* XCRemoteSwiftPackageReference "GZIP" */ = {
|
701C7BEF8F70F7A83E852DCC /* XCRemoteSwiftPackageReference "GZIP" */ = {
|
||||||
|
|||||||
@@ -149,8 +149,8 @@
|
|||||||
"kind" : "remoteSourceControl",
|
"kind" : "remoteSourceControl",
|
||||||
"location" : "https://github.com/element-hq/matrix-rust-components-swift",
|
"location" : "https://github.com/element-hq/matrix-rust-components-swift",
|
||||||
"state" : {
|
"state" : {
|
||||||
"revision" : "2f11bfecae2c83218fea4336361cabcf3a899a78",
|
"revision" : "410fa67337a0af99bbf04a775788520d98d6d8d2",
|
||||||
"version" : "1.0.33"
|
"version" : "1.0.35"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -329,20 +329,24 @@ struct PinnedEventsState: Equatable {
|
|||||||
var selectedPinContent: AttributedString {
|
var selectedPinContent: AttributedString {
|
||||||
var content = AttributedString(" ")
|
var content = AttributedString(" ")
|
||||||
if let selectedPinEventID,
|
if let selectedPinEventID,
|
||||||
var pinnedEventContent = pinnedEventContents[selectedPinEventID] {
|
let pinnedEventContent = pinnedEventContents[selectedPinEventID] {
|
||||||
content = pinnedEventContent
|
content = pinnedEventContent
|
||||||
}
|
}
|
||||||
content.font = .compound.bodyMD
|
content.font = .compound.bodyMD
|
||||||
return content
|
return content
|
||||||
}
|
}
|
||||||
|
|
||||||
mutating func nextPin() {
|
mutating func previousPin() {
|
||||||
guard !pinnedEventContents.isEmpty else {
|
guard !pinnedEventContents.isEmpty else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
let currentIndex = selectedPinIndex
|
let currentIndex = selectedPinIndex
|
||||||
let nextIndex = (currentIndex + 1) % pinnedEventContents.count
|
let nextIndex = currentIndex - 1
|
||||||
selectedPinEventID = pinnedEventContents.keys[nextIndex]
|
if nextIndex == -1 {
|
||||||
|
selectedPinEventID = pinnedEventContents.keys.last
|
||||||
|
} else {
|
||||||
|
selectedPinEventID = pinnedEventContents.keys[nextIndex % pinnedEventContents.count]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -415,10 +419,10 @@ enum PinnedEventsBannerState: Equatable {
|
|||||||
return finalString
|
return finalString
|
||||||
}
|
}
|
||||||
|
|
||||||
mutating func nextPin() {
|
mutating func previousPin() {
|
||||||
switch self {
|
switch self {
|
||||||
case .loaded(var state):
|
case .loaded(var state):
|
||||||
state.nextPin()
|
state.previousPin()
|
||||||
self = .loaded(state: state)
|
self = .loaded(state: state)
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
|
|||||||
@@ -228,7 +228,7 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
|
|||||||
if let eventID = state.pinnedEventsBannerState.selectedPinEventID {
|
if let eventID = state.pinnedEventsBannerState.selectedPinEventID {
|
||||||
Task { await focusOnEvent(eventID: eventID) }
|
Task { await focusOnEvent(eventID: eventID) }
|
||||||
}
|
}
|
||||||
state.pinnedEventsBannerState.nextPin()
|
state.pinnedEventsBannerState.previousPin()
|
||||||
case .viewAllPins:
|
case .viewAllPins:
|
||||||
// TODO: Implement
|
// TODO: Implement
|
||||||
break
|
break
|
||||||
@@ -723,7 +723,7 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
|
|||||||
private func buildPinnedEventContent(timelineItems: [TimelineItemProxy]) {
|
private func buildPinnedEventContent(timelineItems: [TimelineItemProxy]) {
|
||||||
var pinnedEventContents = OrderedDictionary<String, AttributedString>()
|
var pinnedEventContents = OrderedDictionary<String, AttributedString>()
|
||||||
|
|
||||||
for item in timelineItems.reversed() {
|
for item in timelineItems {
|
||||||
// Only remote events are pinned
|
// Only remote events are pinned
|
||||||
if case let .event(event) = item,
|
if case let .event(event) = item,
|
||||||
let eventID = event.id.eventID {
|
let eventID = event.id.eventID {
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ class PinnedEventsBannerStateTests: XCTestCase {
|
|||||||
|
|
||||||
var state = originalState
|
var state = originalState
|
||||||
// This should not affect the state when loading
|
// This should not affect the state when loading
|
||||||
state.nextPin()
|
state.previousPin()
|
||||||
XCTAssertEqual(state, originalState)
|
XCTAssertEqual(state, originalState)
|
||||||
|
|
||||||
XCTAssertTrue(state.isLoading)
|
XCTAssertTrue(state.isLoading)
|
||||||
@@ -63,18 +63,18 @@ class PinnedEventsBannerStateTests: XCTestCase {
|
|||||||
XCTAssertEqual(state.bannerIndicatorDescription.string, L10n.screenRoomPinnedBannerIndicatorDescription(L10n.screenRoomPinnedBannerIndicator(2, 2)))
|
XCTAssertEqual(state.bannerIndicatorDescription.string, L10n.screenRoomPinnedBannerIndicatorDescription(L10n.screenRoomPinnedBannerIndicator(2, 2)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func testNextPin() {
|
func testPreviousPin() {
|
||||||
var state = PinnedEventsBannerState.loaded(state: .init(pinnedEventContents: ["1": "test1", "2": "test2", "3": "test3"], selectedPinEventID: "3"))
|
var state = PinnedEventsBannerState.loaded(state: .init(pinnedEventContents: ["1": "test1", "2": "test2", "3": "test3"], selectedPinEventID: "1"))
|
||||||
XCTAssertEqual(state.selectedPinEventID, "3")
|
|
||||||
XCTAssertEqual(state.selectedPinIndex, 2)
|
|
||||||
XCTAssertEqual(state.displayedMessage.string, "test3")
|
|
||||||
|
|
||||||
state.nextPin()
|
|
||||||
XCTAssertEqual(state.selectedPinEventID, "1")
|
XCTAssertEqual(state.selectedPinEventID, "1")
|
||||||
XCTAssertEqual(state.selectedPinIndex, 0)
|
XCTAssertEqual(state.selectedPinIndex, 0)
|
||||||
XCTAssertEqual(state.displayedMessage.string, "test1")
|
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.selectedPinEventID, "2")
|
||||||
XCTAssertEqual(state.selectedPinIndex, 1)
|
XCTAssertEqual(state.selectedPinIndex, 1)
|
||||||
XCTAssertEqual(state.displayedMessage.string, "test2")
|
XCTAssertEqual(state.displayedMessage.string, "test2")
|
||||||
|
|||||||
+1
-1
@@ -60,7 +60,7 @@ packages:
|
|||||||
# Element/Matrix dependencies
|
# Element/Matrix dependencies
|
||||||
MatrixRustSDK:
|
MatrixRustSDK:
|
||||||
url: https://github.com/element-hq/matrix-rust-components-swift
|
url: https://github.com/element-hq/matrix-rust-components-swift
|
||||||
exactVersion: 1.0.33
|
exactVersion: 1.0.35
|
||||||
# path: ../matrix-rust-sdk
|
# path: ../matrix-rust-sdk
|
||||||
Compound:
|
Compound:
|
||||||
url: https://github.com/element-hq/compound-ios
|
url: https://github.com/element-hq/compound-ios
|
||||||
|
|||||||
Reference in New Issue
Block a user