Skip to content

Commit

Permalink
feat(fii): Implement RoomList::apply_input
Browse files Browse the repository at this point in the history
feat(fii): Implement `RoomList::apply_input`
  • Loading branch information
Hywan authored Jun 15, 2023
2 parents 1fd039c + 5956565 commit 31d8340
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
10 changes: 10 additions & 0 deletions bindings/matrix-sdk-ffi/src/api.udl
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,13 @@ interface RoomListEntriesUpdate {
callback interface RoomListEntriesListener {
void on_update(RoomListEntriesUpdate room_entries_update);
};

[Enum]
interface RoomListInput {
Viewport(sequence<RoomListRange> ranges);
};

dictionary RoomListRange {
u32 start;
u32 end_inclusive;
};
23 changes: 23 additions & 0 deletions bindings/matrix-sdk-ffi/src/room_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,25 @@ impl From<ruma::IdParseError> for RoomListError {
}
}

pub struct RoomListRange {
pub start: u32,
pub end_inclusive: u32,
}

pub enum RoomListInput {
Viewport { ranges: Vec<RoomListRange> },
}

impl From<RoomListInput> for matrix_sdk_ui::room_list::Input {
fn from(value: RoomListInput) -> Self {
match value {
RoomListInput::Viewport { ranges } => Self::Viewport(
ranges.iter().map(|range| range.start..=range.end_inclusive).collect(),
),
}
}
}

#[derive(uniffi::Object)]
pub struct RoomList {
inner: Arc<matrix_sdk_ui::RoomList>,
Expand Down Expand Up @@ -104,6 +123,10 @@ impl RoomList {
})
}

async fn apply_input(&self, input: RoomListInput) -> Result<(), RoomListError> {
self.inner.apply_input(input.into()).await.map_err(Into::into)
}

fn room(&self, room_id: String) -> Result<Arc<RoomListItem>, RoomListError> {
let room_id = <&RoomId>::try_from(room_id.as_str()).map_err(RoomListError::from)?;

Expand Down
8 changes: 4 additions & 4 deletions crates/matrix-sdk-ui/tests/integration/room_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1573,8 +1573,8 @@ async fn test_input_viewport() -> Result<(), Error> {
VISIBLE_ROOMS: {
"ranges": [],
"timeline_limit": 20,
}
}
},
},
},
respond with = {
"pos": "1",
Expand All @@ -1596,8 +1596,8 @@ async fn test_input_viewport() -> Result<(), Error> {
VISIBLE_ROOMS: {
"ranges": [[10, 15], [20, 25]],
"timeline_limit": 20,
}
}
},
},
},
respond with = {
"pos": "1",
Expand Down

0 comments on commit 31d8340

Please sign in to comment.