matrix_sdk_test/sync_builder/
invited_room.rs

1use ruma::{
2    OwnedRoomId, RoomId, api::client::sync::sync_events::v3::InvitedRoom,
3    events::AnyStrippedStateEvent, serde::Raw,
4};
5
6use crate::DEFAULT_TEST_ROOM_ID;
7
8pub struct InvitedRoomBuilder {
9    pub(super) room_id: OwnedRoomId,
10    pub(super) inner: InvitedRoom,
11}
12
13impl InvitedRoomBuilder {
14    /// Create a new `InvitedRoomBuilder` for the given room ID.
15    ///
16    /// If the room ID is [`DEFAULT_TEST_ROOM_ID`],
17    /// [`InvitedRoomBuilder::default()`] can be used instead.
18    pub fn new(room_id: &RoomId) -> Self {
19        Self { room_id: room_id.to_owned(), inner: Default::default() }
20    }
21
22    /// Get the room ID of this [`InvitedRoomBuilder`].
23    pub fn room_id(&self) -> &RoomId {
24        &self.room_id
25    }
26
27    /// Add an event to the state.
28    pub fn add_state_event(mut self, event: impl Into<Raw<AnyStrippedStateEvent>>) -> Self {
29        self.inner.invite_state.events.push(event.into());
30        self
31    }
32
33    /// Add events to the state in bulk.
34    pub fn add_state_bulk<I>(mut self, events: I) -> Self
35    where
36        I: IntoIterator<Item = Raw<AnyStrippedStateEvent>>,
37    {
38        self.inner.invite_state.events.extend(events);
39        self
40    }
41}
42
43impl Default for InvitedRoomBuilder {
44    fn default() -> Self {
45        Self::new(&DEFAULT_TEST_ROOM_ID)
46    }
47}