matrix_sdk_test/sync_builder/
knocked_room.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use ruma::{
    api::client::sync::sync_events::v3::KnockedRoom, events::AnyStrippedStateEvent, serde::Raw,
    OwnedRoomId, RoomId,
};

use super::StrippedStateTestEvent;
use crate::DEFAULT_TEST_ROOM_ID;

pub struct KnockedRoomBuilder {
    pub(super) room_id: OwnedRoomId,
    pub(super) inner: KnockedRoom,
}

impl KnockedRoomBuilder {
    /// Create a new `KnockedRoomBuilder` for the given room ID.
    ///
    /// If the room ID is [`DEFAULT_TEST_ROOM_ID`],
    /// [`KnockedRoomBuilder::default()`] can be used instead.
    pub fn new(room_id: &RoomId) -> Self {
        Self { room_id: room_id.to_owned(), inner: Default::default() }
    }

    /// Get the room ID of this [`KnockedRoomBuilder`].
    pub fn room_id(&self) -> &RoomId {
        &self.room_id
    }

    /// Add an event to the state.
    pub fn add_state_event(mut self, event: StrippedStateTestEvent) -> Self {
        self.inner.knock_state.events.push(event.into_raw_event());
        self
    }

    /// Add events to the state in bulk.
    pub fn add_state_bulk<I>(mut self, events: I) -> Self
    where
        I: IntoIterator<Item = Raw<AnyStrippedStateEvent>>,
    {
        self.inner.knock_state.events.extend(events);
        self
    }
}

impl Default for KnockedRoomBuilder {
    fn default() -> Self {
        Self::new(&DEFAULT_TEST_ROOM_ID)
    }
}