matrix_sdk_test/sync_builder/
test_event.rs1use ruma::{
2 events::{
3 presence::PresenceEvent, AnyGlobalAccountDataEvent, AnyRoomAccountDataEvent,
4 AnyStrippedStateEvent, AnySyncStateEvent,
5 },
6 serde::Raw,
7};
8use serde_json::{from_value as from_json_value, Value as JsonValue};
9
10use crate::test_json;
11
12pub enum StateTestEvent {
14 Alias,
15 Aliases,
16 Create,
17 Encryption,
18 HistoryVisibility,
19 JoinRules,
20 Member,
21 MemberAdditional,
22 MemberBan,
23 MemberInvite,
24 MemberLeave,
25 MemberNameChange,
26 PowerLevels,
27 RedactedInvalid,
28 RedactedState,
29 RoomAvatar,
30 RoomName,
31 RoomPinnedEvents,
32 RoomTopic,
33 Custom(JsonValue),
34}
35
36impl From<StateTestEvent> for JsonValue {
37 fn from(val: StateTestEvent) -> Self {
38 match val {
39 StateTestEvent::Alias => test_json::sync_events::ALIAS.to_owned(),
40 StateTestEvent::Aliases => test_json::sync_events::ALIASES.to_owned(),
41 StateTestEvent::Create => test_json::sync_events::CREATE.to_owned(),
42 StateTestEvent::Encryption => test_json::sync_events::ENCRYPTION.to_owned(),
43 StateTestEvent::HistoryVisibility => {
44 test_json::sync_events::HISTORY_VISIBILITY.to_owned()
45 }
46 StateTestEvent::JoinRules => test_json::sync_events::JOIN_RULES.to_owned(),
47 StateTestEvent::Member => test_json::sync_events::MEMBER.to_owned(),
48 StateTestEvent::MemberAdditional => {
49 test_json::sync_events::MEMBER_ADDITIONAL.to_owned()
50 }
51 StateTestEvent::MemberBan => test_json::sync_events::MEMBER_BAN.to_owned(),
52 StateTestEvent::MemberInvite => test_json::sync_events::MEMBER_INVITE.to_owned(),
53 StateTestEvent::MemberLeave => test_json::sync_events::MEMBER_LEAVE.to_owned(),
54 StateTestEvent::MemberNameChange => {
55 test_json::sync_events::MEMBER_NAME_CHANGE.to_owned()
56 }
57 StateTestEvent::PowerLevels => test_json::sync_events::POWER_LEVELS.to_owned(),
58 StateTestEvent::RedactedInvalid => test_json::sync_events::REDACTED_INVALID.to_owned(),
59 StateTestEvent::RedactedState => test_json::sync_events::REDACTED_STATE.to_owned(),
60 StateTestEvent::RoomAvatar => test_json::sync_events::ROOM_AVATAR.to_owned(),
61 StateTestEvent::RoomName => test_json::sync_events::NAME.to_owned(),
62 StateTestEvent::RoomPinnedEvents => test_json::sync_events::PINNED_EVENTS.to_owned(),
63 StateTestEvent::RoomTopic => test_json::sync_events::TOPIC.to_owned(),
64 StateTestEvent::Custom(json) => json,
65 }
66 }
67}
68
69impl From<StateTestEvent> for Raw<AnySyncStateEvent> {
70 fn from(val: StateTestEvent) -> Self {
71 from_json_value(val.into()).unwrap()
72 }
73}
74
75pub enum StrippedStateTestEvent {
77 Member,
78 RoomName,
79 Custom(JsonValue),
80}
81
82impl From<StrippedStateTestEvent> for JsonValue {
83 fn from(val: StrippedStateTestEvent) -> Self {
84 match val {
85 StrippedStateTestEvent::Member => test_json::sync_events::MEMBER_STRIPPED.to_owned(),
86 StrippedStateTestEvent::RoomName => test_json::sync_events::NAME_STRIPPED.to_owned(),
87 StrippedStateTestEvent::Custom(json) => json,
88 }
89 }
90}
91
92impl From<StrippedStateTestEvent> for Raw<AnyStrippedStateEvent> {
93 fn from(val: StrippedStateTestEvent) -> Self {
94 from_json_value(val.into()).unwrap()
95 }
96}
97
98pub enum RoomAccountDataTestEvent {
100 FullyRead,
101 Tags,
102 MarkedUnread,
103 Custom(JsonValue),
104}
105
106impl From<RoomAccountDataTestEvent> for JsonValue {
107 fn from(val: RoomAccountDataTestEvent) -> Self {
108 match val {
109 RoomAccountDataTestEvent::FullyRead => test_json::sync_events::FULLY_READ.to_owned(),
110 RoomAccountDataTestEvent::Tags => test_json::sync_events::TAG.to_owned(),
111 RoomAccountDataTestEvent::MarkedUnread => {
112 test_json::sync_events::MARKED_UNREAD.to_owned()
113 }
114 RoomAccountDataTestEvent::Custom(json) => json,
115 }
116 }
117}
118
119impl From<RoomAccountDataTestEvent> for Raw<AnyRoomAccountDataEvent> {
120 fn from(val: RoomAccountDataTestEvent) -> Self {
121 from_json_value(val.into()).unwrap()
122 }
123}
124
125pub enum PresenceTestEvent {
127 Presence,
128 Custom(JsonValue),
129}
130
131impl From<PresenceTestEvent> for JsonValue {
132 fn from(val: PresenceTestEvent) -> Self {
133 match val {
134 PresenceTestEvent::Presence => test_json::sync_events::PRESENCE.to_owned(),
135 PresenceTestEvent::Custom(json) => json,
136 }
137 }
138}
139
140impl From<PresenceTestEvent> for Raw<PresenceEvent> {
141 fn from(val: PresenceTestEvent) -> Self {
142 from_json_value(val.into()).unwrap()
143 }
144}
145
146pub enum GlobalAccountDataTestEvent {
148 Direct,
149 PushRules,
150 IgnoredUserList,
151 Custom(JsonValue),
152}
153
154impl From<GlobalAccountDataTestEvent> for JsonValue {
155 fn from(val: GlobalAccountDataTestEvent) -> Self {
156 match val {
157 GlobalAccountDataTestEvent::Direct => test_json::sync_events::DIRECT.to_owned(),
158 GlobalAccountDataTestEvent::PushRules => test_json::sync_events::PUSH_RULES.to_owned(),
159 GlobalAccountDataTestEvent::IgnoredUserList => {
160 test_json::sync_events::IGNORED_USER_LIST.to_owned()
161 }
162 GlobalAccountDataTestEvent::Custom(json) => json,
163 }
164 }
165}
166
167impl From<GlobalAccountDataTestEvent> for Raw<AnyGlobalAccountDataEvent> {
168 fn from(val: GlobalAccountDataTestEvent) -> Self {
169 from_json_value(val.into()).unwrap()
170 }
171}