File tree 1 file changed +10
-1
lines changed
crates/matrix-sdk-ui/src/timeline/controller
1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -1947,7 +1947,16 @@ impl AllRemoteEvents {
1947
1947
1948
1948
/// Get the position of an event in the events array by its ID.
1949
1949
pub fn position_by_event_id ( & self , event_id : & EventId ) -> Option < usize > {
1950
- self . 0 . iter ( ) . position ( |event_meta| event_meta. event_id == event_id)
1950
+ // Reverse the iterator to start looking at the end. Since this will give us the
1951
+ // "reverse" position, reverse the index after finding the event.
1952
+ //
1953
+ // If the reversed index was 0 in a array of size 1, then it should stay 0, so
1954
+ // that justifies the `- 1` in the formula below.
1955
+ self . 0
1956
+ . iter ( )
1957
+ . rev ( )
1958
+ . position ( |event_meta| event_meta. event_id == event_id)
1959
+ . map ( |rev_index| self . 0 . len ( ) - 1 - rev_index)
1951
1960
}
1952
1961
1953
1962
/// Shift to the right all timeline item indexes that are equal to or
You can’t perform that action at this time.
0 commit comments