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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
use ruma::{
api::client::sync::sync_events::v3::LeftRoom,
events::{AnyRoomAccountDataEvent, AnySyncStateEvent, AnySyncTimelineEvent},
serde::Raw,
OwnedRoomId,
};
use super::{RoomAccountDataTestEvent, StateTestEvent, TimelineTestEvent};
use crate::test_json;
pub struct LeftRoomBuilder {
pub(super) room_id: OwnedRoomId,
pub(super) inner: LeftRoom,
}
impl LeftRoomBuilder {
pub fn new(room_id: impl Into<OwnedRoomId>) -> Self {
Self { room_id: room_id.into(), inner: Default::default() }
}
pub fn add_timeline_event(mut self, event: TimelineTestEvent) -> Self {
self.inner.timeline.events.push(event.into_raw_event());
self
}
pub fn add_timeline_bulk<I>(mut self, events: I) -> Self
where
I: IntoIterator<Item = Raw<AnySyncTimelineEvent>>,
{
self.inner.timeline.events.extend(events);
self
}
pub fn add_timeline_state_bulk<I>(self, events: I) -> Self
where
I: IntoIterator<Item = Raw<AnySyncStateEvent>>,
{
let events = events.into_iter().map(|event| event.cast());
self.add_timeline_bulk(events)
}
pub fn set_timeline_limited(mut self) -> Self {
self.inner.timeline.limited = true;
self
}
pub fn set_timeline_prev_batch(mut self, prev_batch: String) -> Self {
self.inner.timeline.prev_batch = Some(prev_batch);
self
}
pub fn add_state_event(mut self, event: StateTestEvent) -> Self {
self.inner.state.events.push(event.into_raw_event());
self
}
pub fn add_state_bulk<I>(mut self, events: I) -> Self
where
I: IntoIterator<Item = Raw<AnySyncStateEvent>>,
{
self.inner.state.events.extend(events);
self
}
pub fn add_account_data(mut self, event: RoomAccountDataTestEvent) -> Self {
self.inner.account_data.events.push(event.into_raw_event());
self
}
pub fn add_account_data_bulk<I>(mut self, events: I) -> Self
where
I: IntoIterator<Item = Raw<AnyRoomAccountDataEvent>>,
{
self.inner.account_data.events.extend(events);
self
}
}
impl Default for LeftRoomBuilder {
fn default() -> Self {
Self::new(test_json::DEFAULT_SYNC_ROOM_ID.to_owned())
}
}