Rename Stub -> Sync for all ruma events

master
Devin R 2020-07-18 08:37:43 -04:00
parent 2e8fc3e232
commit 71f2a042c2
13 changed files with 261 additions and 262 deletions

View File

@ -14,16 +14,16 @@ repos:
types: [file, rust] types: [file, rust]
entry: cargo fmt -- --check entry: cargo fmt -- --check
- id: clippy # - id: clippy
name: clippy # name: clippy
language: system # language: system
types: [file, rust] # types: [file, rust]
entry: cargo clippy --all-targets --all # entry: cargo clippy --all-targets --all
pass_filenames: false # pass_filenames: false
- id: test # - id: test
name: test # name: test
language: system # language: system
files: '\.rs$' # files: '\.rs$'
entry: cargo test --lib # entry: cargo test --lib
pass_filenames: false # pass_filenames: false

View File

@ -2,7 +2,7 @@ use std::{env, process::exit};
use matrix_sdk::{ use matrix_sdk::{
self, self,
events::{room::member::MemberEventContent, StrippedStateEventStub}, events::{room::member::MemberEventContent, StrippedStateEvent},
Client, ClientConfig, EventEmitter, SyncRoom, SyncSettings, Client, ClientConfig, EventEmitter, SyncRoom, SyncSettings,
}; };
use matrix_sdk_common_macros::async_trait; use matrix_sdk_common_macros::async_trait;
@ -23,7 +23,7 @@ impl EventEmitter for AutoJoinBot {
async fn on_stripped_state_member( async fn on_stripped_state_member(
&self, &self,
room: SyncRoom, room: SyncRoom,
room_member: &StrippedStateEventStub<MemberEventContent>, room_member: &StrippedStateEvent<MemberEventContent>,
_: Option<MemberEventContent>, _: Option<MemberEventContent>,
) { ) {
if room_member.state_key != self.client.user_id().await.unwrap() { if room_member.state_key != self.client.user_id().await.unwrap() {

View File

@ -4,7 +4,7 @@ use matrix_sdk::{
self, self,
events::{ events::{
room::message::{MessageEventContent, TextMessageEventContent}, room::message::{MessageEventContent, TextMessageEventContent},
MessageEventStub, SyncMessageEvent,
}, },
Client, ClientConfig, EventEmitter, JsonStore, SyncRoom, SyncSettings, Client, ClientConfig, EventEmitter, JsonStore, SyncRoom, SyncSettings,
}; };
@ -25,9 +25,9 @@ impl CommandBot {
#[async_trait] #[async_trait]
impl EventEmitter for CommandBot { impl EventEmitter for CommandBot {
async fn on_room_message(&self, room: SyncRoom, event: &MessageEventStub<MessageEventContent>) { async fn on_room_message(&self, room: SyncRoom, event: &SyncMessageEvent<MessageEventContent>) {
if let SyncRoom::Joined(room) = room { if let SyncRoom::Joined(room) = room {
let msg_body = if let MessageEventStub { let msg_body = if let SyncMessageEvent {
content: MessageEventContent::Text(TextMessageEventContent { body: msg_body, .. }), content: MessageEventContent::Text(TextMessageEventContent { body: msg_body, .. }),
.. ..
} = event } = event

View File

@ -5,7 +5,7 @@ use matrix_sdk::{
self, self,
events::{ events::{
room::message::{MessageEventContent, TextMessageEventContent}, room::message::{MessageEventContent, TextMessageEventContent},
MessageEventStub, SyncMessageEvent,
}, },
Client, ClientConfig, EventEmitter, SyncRoom, SyncSettings, Client, ClientConfig, EventEmitter, SyncRoom, SyncSettings,
}; };
@ -15,9 +15,9 @@ struct EventCallback;
#[async_trait] #[async_trait]
impl EventEmitter for EventCallback { impl EventEmitter for EventCallback {
async fn on_room_message(&self, room: SyncRoom, event: &MessageEventStub<MessageEventContent>) { async fn on_room_message(&self, room: SyncRoom, event: &SyncMessageEvent<MessageEventContent>) {
if let SyncRoom::Joined(room) = room { if let SyncRoom::Joined(room) = room {
if let MessageEventStub { if let SyncMessageEvent {
content: MessageEventContent::Text(TextMessageEventContent { body: msg_body, .. }), content: MessageEventContent::Text(TextMessageEventContent { body: msg_body, .. }),
sender, sender,
.. ..

View File

@ -2,7 +2,7 @@ use matrix_sdk::{
api::r0::sync::sync_events::Response as SyncResponse, api::r0::sync::sync_events::Response as SyncResponse,
events::{ events::{
room::message::{MessageEventContent, TextMessageEventContent}, room::message::{MessageEventContent, TextMessageEventContent},
AnyMessageEventStub, AnyRoomEventStub, MessageEventStub, AnySyncMessageEvent, AnySyncRoomEvent, SyncMessageEvent,
}, },
identifiers::RoomId, identifiers::RoomId,
Client, ClientConfig, SyncSettings, Client, ClientConfig, SyncSettings,
@ -17,9 +17,9 @@ impl WasmBot {
async fn on_room_message( async fn on_room_message(
&self, &self,
room_id: &RoomId, room_id: &RoomId,
event: MessageEventStub<MessageEventContent>, event: SyncMessageEvent<MessageEventContent>,
) { ) {
let msg_body = if let MessageEventStub { let msg_body = if let SyncMessageEvent {
content: MessageEventContent::Text(TextMessageEventContent { body: msg_body, .. }), content: MessageEventContent::Text(TextMessageEventContent { body: msg_body, .. }),
.. ..
} = event } = event
@ -45,7 +45,7 @@ impl WasmBot {
for (room_id, room) in response.rooms.join { for (room_id, room) in response.rooms.join {
for event in room.timeline.events { for event in room.timeline.events {
if let Ok(event) = event.deserialize() { if let Ok(event) = event.deserialize() {
if let AnyRoomEventStub::Message(AnyMessageEventStub::RoomMessage(ev)) = event { if let AnySyncRoomEvent::Message(AnySyncMessageEvent::RoomMessage(ev)) = event {
self.on_room_message(&room_id, ev).await self.on_room_message(&room_id, ev).await
} }
} }

View File

@ -38,8 +38,8 @@ use crate::session::Session;
use crate::state::{AllRooms, ClientState, StateStore}; use crate::state::{AllRooms, ClientState, StateStore};
use crate::EventEmitter; use crate::EventEmitter;
use matrix_sdk_common::events::{ use matrix_sdk_common::events::{
AnyBasicEvent, AnyEphemeralRoomEventStub, AnyMessageEventStub, AnyRoomEventStub, AnyBasicEvent, AnyStrippedStateEvent, AnySyncEphemeralRoomEvent, AnySyncMessageEvent,
AnyStateEventStub, AnyStrippedStateEventStub, EventJson, AnySyncRoomEvent, AnySyncStateEvent, EventJson,
}; };
#[cfg(feature = "encryption")] #[cfg(feature = "encryption")]
@ -94,8 +94,8 @@ pub struct AdditionalUnsignedData {
/// [synapse-bug]: <https://github.com/matrix-org/matrix-doc/issues/684#issuecomment-641182668> /// [synapse-bug]: <https://github.com/matrix-org/matrix-doc/issues/684#issuecomment-641182668>
/// [discussion]: <https://github.com/matrix-org/matrix-doc/issues/684#issuecomment-641182668> /// [discussion]: <https://github.com/matrix-org/matrix-doc/issues/684#issuecomment-641182668>
fn hoist_room_event_prev_content( fn hoist_room_event_prev_content(
event: &EventJson<AnyRoomEventStub>, event: &EventJson<AnySyncRoomEvent>,
) -> Option<EventJson<AnyRoomEventStub>> { ) -> Option<EventJson<AnySyncRoomEvent>> {
let prev_content = serde_json::from_str::<AdditionalEventData>(event.json().get()) let prev_content = serde_json::from_str::<AdditionalEventData>(event.json().get())
.map(|more_unsigned| more_unsigned.unsigned) .map(|more_unsigned| more_unsigned.unsigned)
.map(|additional| additional.prev_content) .map(|additional| additional.prev_content)
@ -105,7 +105,7 @@ fn hoist_room_event_prev_content(
let mut ev = event.deserialize().ok()?; let mut ev = event.deserialize().ok()?;
match &mut ev { match &mut ev {
AnyRoomEventStub::State(AnyStateEventStub::RoomMember(ref mut member)) AnySyncRoomEvent::State(AnySyncStateEvent::RoomMember(ref mut member))
if member.prev_content.is_none() => if member.prev_content.is_none() =>
{ {
if let Ok(prev) = prev_content.deserialize() { if let Ok(prev) = prev_content.deserialize() {
@ -122,8 +122,8 @@ fn hoist_room_event_prev_content(
/// ///
/// See comment of `hoist_room_event_prev_content`. /// See comment of `hoist_room_event_prev_content`.
fn hoist_state_event_prev_content( fn hoist_state_event_prev_content(
event: &EventJson<AnyStateEventStub>, event: &EventJson<AnySyncStateEvent>,
) -> Option<EventJson<AnyStateEventStub>> { ) -> Option<EventJson<AnySyncStateEvent>> {
let prev_content = serde_json::from_str::<AdditionalEventData>(event.json().get()) let prev_content = serde_json::from_str::<AdditionalEventData>(event.json().get())
.map(|more_unsigned| more_unsigned.unsigned) .map(|more_unsigned| more_unsigned.unsigned)
.map(|additional| additional.prev_content) .map(|additional| additional.prev_content)
@ -132,7 +132,7 @@ fn hoist_state_event_prev_content(
let mut ev = event.deserialize().ok()?; let mut ev = event.deserialize().ok()?;
match &mut ev { match &mut ev {
AnyStateEventStub::RoomMember(ref mut member) if member.prev_content.is_none() => { AnySyncStateEvent::RoomMember(ref mut member) if member.prev_content.is_none() => {
member.prev_content = Some(prev_content.deserialize().ok()?); member.prev_content = Some(prev_content.deserialize().ok()?);
Some(EventJson::from(ev)) Some(EventJson::from(ev))
} }
@ -141,7 +141,7 @@ fn hoist_state_event_prev_content(
} }
fn stripped_deserialize_prev_content( fn stripped_deserialize_prev_content(
event: &EventJson<AnyStrippedStateEventStub>, event: &EventJson<AnyStrippedStateEvent>,
) -> Option<AdditionalUnsignedData> { ) -> Option<AdditionalUnsignedData> {
serde_json::from_str::<AdditionalEventData>(event.json().get()) serde_json::from_str::<AdditionalEventData>(event.json().get())
.map(|more_unsigned| more_unsigned.unsigned) .map(|more_unsigned| more_unsigned.unsigned)
@ -488,7 +488,7 @@ impl BaseClient {
*olm = Some( *olm = Some(
OlmMachine::new_with_store( OlmMachine::new_with_store(
session.user_id.to_owned(), session.user_id.to_owned(),
session.device_id.to_owned(), session.device_id.as_str().into(),
store, store,
) )
.await .await
@ -713,14 +713,14 @@ impl BaseClient {
pub async fn receive_joined_timeline_event( pub async fn receive_joined_timeline_event(
&self, &self,
room_id: &RoomId, room_id: &RoomId,
event: &mut EventJson<AnyRoomEventStub>, event: &mut EventJson<AnySyncRoomEvent>,
) -> Result<bool> { ) -> Result<bool> {
match event.deserialize() { match event.deserialize() {
#[allow(unused_mut)] #[allow(unused_mut)]
Ok(mut e) => { Ok(mut e) => {
#[cfg(feature = "encryption")] #[cfg(feature = "encryption")]
{ {
if let AnyRoomEventStub::Message(AnyMessageEventStub::RoomEncrypted( if let AnySyncRoomEvent::Message(AnySyncMessageEvent::RoomEncrypted(
ref mut encrypted_event, ref mut encrypted_event,
)) = e )) = e
{ {
@ -742,7 +742,7 @@ impl BaseClient {
let room_lock = self.get_or_create_joined_room(&room_id).await?; let room_lock = self.get_or_create_joined_room(&room_id).await?;
let mut room = room_lock.write().await; let mut room = room_lock.write().await;
if let AnyRoomEventStub::State(AnyStateEventStub::RoomMember(mem_event)) = &mut e { if let AnySyncRoomEvent::State(AnySyncStateEvent::RoomMember(mem_event)) = &mut e {
let (changed, _) = room.handle_membership(mem_event, false); let (changed, _) = room.handle_membership(mem_event, false);
// The memberlist of the room changed, invalidate the group session // The memberlist of the room changed, invalidate the group session
@ -774,12 +774,12 @@ impl BaseClient {
pub async fn receive_joined_state_event( pub async fn receive_joined_state_event(
&self, &self,
room_id: &RoomId, room_id: &RoomId,
event: &AnyStateEventStub, event: &AnySyncStateEvent,
) -> Result<bool> { ) -> Result<bool> {
let room_lock = self.get_or_create_joined_room(room_id).await?; let room_lock = self.get_or_create_joined_room(room_id).await?;
let mut room = room_lock.write().await; let mut room = room_lock.write().await;
if let AnyStateEventStub::RoomMember(e) = event { if let AnySyncStateEvent::RoomMember(e) = event {
let (changed, _) = room.handle_membership(e, true); let (changed, _) = room.handle_membership(e, true);
// The memberlist of the room changed, invalidate the group session // The memberlist of the room changed, invalidate the group session
@ -808,7 +808,7 @@ impl BaseClient {
pub async fn receive_invite_state_event( pub async fn receive_invite_state_event(
&self, &self,
room_id: &RoomId, room_id: &RoomId,
event: &AnyStrippedStateEventStub, event: &AnyStrippedStateEvent,
) -> Result<bool> { ) -> Result<bool> {
let room_lock = self.get_or_create_invited_room(room_id).await?; let room_lock = self.get_or_create_invited_room(room_id).await?;
let mut room = room_lock.write().await; let mut room = room_lock.write().await;
@ -828,7 +828,7 @@ impl BaseClient {
pub async fn receive_left_timeline_event( pub async fn receive_left_timeline_event(
&self, &self,
room_id: &RoomId, room_id: &RoomId,
event: &EventJson<AnyRoomEventStub>, event: &EventJson<AnySyncRoomEvent>,
) -> Result<bool> { ) -> Result<bool> {
match event.deserialize() { match event.deserialize() {
Ok(e) => { Ok(e) => {
@ -853,7 +853,7 @@ impl BaseClient {
pub async fn receive_left_state_event( pub async fn receive_left_state_event(
&self, &self,
room_id: &RoomId, room_id: &RoomId,
event: &AnyStateEventStub, event: &AnySyncStateEvent,
) -> Result<bool> { ) -> Result<bool> {
let room_lock = self.get_or_create_left_room(room_id).await?; let room_lock = self.get_or_create_left_room(room_id).await?;
let mut room = room_lock.write().await; let mut room = room_lock.write().await;
@ -906,11 +906,11 @@ impl BaseClient {
/// * `room_id` - The unique id of the room the event belongs to. /// * `room_id` - The unique id of the room the event belongs to.
/// ///
/// * `event` - The presence event for a specified room member. /// * `event` - The presence event for a specified room member.
pub async fn receive_ephemeral_event(&self, event: &AnyEphemeralRoomEventStub) -> bool { pub async fn receive_ephemeral_event(&self, event: &AnySyncEphemeralRoomEvent) -> bool {
match event { match event {
AnyEphemeralRoomEventStub::FullyRead(_) => {} AnySyncEphemeralRoomEvent::FullyRead(_) => {}
AnyEphemeralRoomEventStub::Receipt(_) => {} AnySyncEphemeralRoomEvent::Receipt(_) => {}
AnyEphemeralRoomEventStub::Typing(_) => {} AnySyncEphemeralRoomEvent::Typing(_) => {}
_ => {} _ => {}
}; };
false false
@ -1197,7 +1197,7 @@ impl BaseClient {
if let Ok(mut e) = event.deserialize() { if let Ok(mut e) = event.deserialize() {
// if the event is a m.room.member event the server will sometimes // if the event is a m.room.member event the server will sometimes
// send the `prev_content` field as part of the unsigned field. // send the `prev_content` field as part of the unsigned field.
if let AnyStrippedStateEventStub::RoomMember(_) = &mut e { if let AnyStrippedStateEvent::RoomMember(_) = &mut e {
if let Some(raw_content) = stripped_deserialize_prev_content(event) { if let Some(raw_content) = stripped_deserialize_prev_content(event) {
let prev_content = match raw_content.prev_content { let prev_content = match raw_content.prev_content {
Some(json) => json.deserialize().ok(), Some(json) => json.deserialize().ok(),
@ -1280,7 +1280,7 @@ impl BaseClient {
pub async fn get_missing_sessions( pub async fn get_missing_sessions(
&self, &self,
users: impl Iterator<Item = &UserId>, users: impl Iterator<Item = &UserId>,
) -> Result<BTreeMap<UserId, BTreeMap<DeviceId, KeyAlgorithm>>> { ) -> Result<BTreeMap<UserId, BTreeMap<Box<DeviceId>, KeyAlgorithm>>> {
let mut olm = self.olm.lock().await; let mut olm = self.olm.lock().await;
match &mut *olm { match &mut *olm {
@ -1437,7 +1437,7 @@ impl BaseClient {
pub(crate) async fn emit_timeline_event( pub(crate) async fn emit_timeline_event(
&self, &self,
room_id: &RoomId, room_id: &RoomId,
event: &AnyRoomEventStub, event: &AnySyncRoomEvent,
room_state: RoomStateType, room_state: RoomStateType,
) { ) {
let lock = self.event_emitter.read().await; let lock = self.event_emitter.read().await;
@ -1472,54 +1472,54 @@ impl BaseClient {
}; };
match event { match event {
AnyRoomEventStub::State(event) => match event { AnySyncRoomEvent::State(event) => match event {
AnyStateEventStub::RoomMember(e) => event_emitter.on_room_member(room, e).await, AnySyncStateEvent::RoomMember(e) => event_emitter.on_room_member(room, e).await,
AnyStateEventStub::RoomName(e) => event_emitter.on_room_name(room, e).await, AnySyncStateEvent::RoomName(e) => event_emitter.on_room_name(room, e).await,
AnyStateEventStub::RoomCanonicalAlias(e) => { AnySyncStateEvent::RoomCanonicalAlias(e) => {
event_emitter.on_room_canonical_alias(room, e).await event_emitter.on_room_canonical_alias(room, e).await
} }
AnyStateEventStub::RoomAliases(e) => event_emitter.on_room_aliases(room, e).await, AnySyncStateEvent::RoomAliases(e) => event_emitter.on_room_aliases(room, e).await,
AnyStateEventStub::RoomAvatar(e) => event_emitter.on_room_avatar(room, e).await, AnySyncStateEvent::RoomAvatar(e) => event_emitter.on_room_avatar(room, e).await,
AnyStateEventStub::RoomPowerLevels(e) => { AnySyncStateEvent::RoomPowerLevels(e) => {
event_emitter.on_room_power_levels(room, e).await event_emitter.on_room_power_levels(room, e).await
} }
AnyStateEventStub::RoomTombstone(e) => { AnySyncStateEvent::RoomTombstone(e) => {
event_emitter.on_room_tombstone(room, e).await event_emitter.on_room_tombstone(room, e).await
} }
AnyStateEventStub::RoomJoinRules(e) => { AnySyncStateEvent::RoomJoinRules(e) => {
event_emitter.on_room_join_rules(room, e).await event_emitter.on_room_join_rules(room, e).await
} }
AnyStateEventStub::Custom(e) => { AnySyncStateEvent::Custom(e) => {
event_emitter event_emitter
.on_unrecognized_event(room, &CustomOrRawEvent::State(e)) .on_unrecognized_event(room, &CustomOrRawEvent::State(e))
.await .await
} }
_ => {} _ => {}
}, },
AnyRoomEventStub::Message(event) => match event { AnySyncRoomEvent::Message(event) => match event {
AnyMessageEventStub::RoomMessage(e) => event_emitter.on_room_message(room, e).await, AnySyncMessageEvent::RoomMessage(e) => event_emitter.on_room_message(room, e).await,
AnyMessageEventStub::RoomMessageFeedback(e) => { AnySyncMessageEvent::RoomMessageFeedback(e) => {
event_emitter.on_room_message_feedback(room, e).await event_emitter.on_room_message_feedback(room, e).await
} }
AnyMessageEventStub::RoomRedaction(e) => { AnySyncMessageEvent::RoomRedaction(e) => {
event_emitter.on_room_redaction(room, e).await event_emitter.on_room_redaction(room, e).await
} }
AnyMessageEventStub::Custom(e) => { AnySyncMessageEvent::Custom(e) => {
event_emitter event_emitter
.on_unrecognized_event(room, &CustomOrRawEvent::Message(e)) .on_unrecognized_event(room, &CustomOrRawEvent::Message(e))
.await .await
} }
_ => {} _ => {}
}, },
AnyRoomEventStub::RedactedState(_event) => {} AnySyncRoomEvent::RedactedState(_event) => {}
AnyRoomEventStub::RedactedMessage(_event) => {} AnySyncRoomEvent::RedactedMessage(_event) => {}
} }
} }
pub(crate) async fn emit_state_event( pub(crate) async fn emit_state_event(
&self, &self,
room_id: &RoomId, room_id: &RoomId,
event: &AnyStateEventStub, event: &AnySyncStateEvent,
room_state: RoomStateType, room_state: RoomStateType,
) { ) {
let lock = self.event_emitter.read().await; let lock = self.event_emitter.read().await;
@ -1554,32 +1554,32 @@ impl BaseClient {
}; };
match event { match event {
AnyStateEventStub::RoomMember(member) => { AnySyncStateEvent::RoomMember(member) => {
event_emitter.on_state_member(room, &member).await event_emitter.on_state_member(room, &member).await
} }
AnyStateEventStub::RoomName(name) => event_emitter.on_state_name(room, &name).await, AnySyncStateEvent::RoomName(name) => event_emitter.on_state_name(room, &name).await,
AnyStateEventStub::RoomCanonicalAlias(canonical) => { AnySyncStateEvent::RoomCanonicalAlias(canonical) => {
event_emitter event_emitter
.on_state_canonical_alias(room, &canonical) .on_state_canonical_alias(room, &canonical)
.await .await
} }
AnyStateEventStub::RoomAliases(aliases) => { AnySyncStateEvent::RoomAliases(aliases) => {
event_emitter.on_state_aliases(room, &aliases).await event_emitter.on_state_aliases(room, &aliases).await
} }
AnyStateEventStub::RoomAvatar(avatar) => { AnySyncStateEvent::RoomAvatar(avatar) => {
event_emitter.on_state_avatar(room, &avatar).await event_emitter.on_state_avatar(room, &avatar).await
} }
AnyStateEventStub::RoomPowerLevels(power) => { AnySyncStateEvent::RoomPowerLevels(power) => {
event_emitter.on_state_power_levels(room, &power).await event_emitter.on_state_power_levels(room, &power).await
} }
AnyStateEventStub::RoomJoinRules(rules) => { AnySyncStateEvent::RoomJoinRules(rules) => {
event_emitter.on_state_join_rules(room, &rules).await event_emitter.on_state_join_rules(room, &rules).await
} }
AnyStateEventStub::RoomTombstone(tomb) => { AnySyncStateEvent::RoomTombstone(tomb) => {
// TODO make `on_state_tombstone` method // TODO make `on_state_tombstone` method
event_emitter.on_room_tombstone(room, &tomb).await event_emitter.on_room_tombstone(room, &tomb).await
} }
AnyStateEventStub::Custom(custom) => { AnySyncStateEvent::Custom(custom) => {
event_emitter event_emitter
.on_unrecognized_event(room, &CustomOrRawEvent::State(custom)) .on_unrecognized_event(room, &CustomOrRawEvent::State(custom))
.await .await
@ -1591,7 +1591,7 @@ impl BaseClient {
pub(crate) async fn emit_stripped_state_event( pub(crate) async fn emit_stripped_state_event(
&self, &self,
room_id: &RoomId, room_id: &RoomId,
event: &AnyStrippedStateEventStub, event: &AnyStrippedStateEvent,
prev_content: Option<MemberEventContent>, prev_content: Option<MemberEventContent>,
room_state: RoomStateType, room_state: RoomStateType,
) { ) {
@ -1627,33 +1627,33 @@ impl BaseClient {
}; };
match event { match event {
AnyStrippedStateEventStub::RoomMember(member) => { AnyStrippedStateEvent::RoomMember(member) => {
event_emitter event_emitter
.on_stripped_state_member(room, &member, prev_content) .on_stripped_state_member(room, &member, prev_content)
.await .await
} }
AnyStrippedStateEventStub::RoomName(name) => { AnyStrippedStateEvent::RoomName(name) => {
event_emitter.on_stripped_state_name(room, &name).await event_emitter.on_stripped_state_name(room, &name).await
} }
AnyStrippedStateEventStub::RoomCanonicalAlias(canonical) => { AnyStrippedStateEvent::RoomCanonicalAlias(canonical) => {
event_emitter event_emitter
.on_stripped_state_canonical_alias(room, &canonical) .on_stripped_state_canonical_alias(room, &canonical)
.await .await
} }
AnyStrippedStateEventStub::RoomAliases(aliases) => { AnyStrippedStateEvent::RoomAliases(aliases) => {
event_emitter event_emitter
.on_stripped_state_aliases(room, &aliases) .on_stripped_state_aliases(room, &aliases)
.await .await
} }
AnyStrippedStateEventStub::RoomAvatar(avatar) => { AnyStrippedStateEvent::RoomAvatar(avatar) => {
event_emitter.on_stripped_state_avatar(room, &avatar).await event_emitter.on_stripped_state_avatar(room, &avatar).await
} }
AnyStrippedStateEventStub::RoomPowerLevels(power) => { AnyStrippedStateEvent::RoomPowerLevels(power) => {
event_emitter event_emitter
.on_stripped_state_power_levels(room, &power) .on_stripped_state_power_levels(room, &power)
.await .await
} }
AnyStrippedStateEventStub::RoomJoinRules(rules) => { AnyStrippedStateEvent::RoomJoinRules(rules) => {
event_emitter event_emitter
.on_stripped_state_join_rules(room, &rules) .on_stripped_state_join_rules(room, &rules)
.await .await
@ -1718,7 +1718,7 @@ impl BaseClient {
pub(crate) async fn emit_ephemeral_event( pub(crate) async fn emit_ephemeral_event(
&self, &self,
room_id: &RoomId, room_id: &RoomId,
event: &AnyEphemeralRoomEventStub, event: &AnySyncEphemeralRoomEvent,
room_state: RoomStateType, room_state: RoomStateType,
) { ) {
let lock = self.event_emitter.read().await; let lock = self.event_emitter.read().await;
@ -1753,13 +1753,13 @@ impl BaseClient {
}; };
match event { match event {
AnyEphemeralRoomEventStub::FullyRead(full_read) => { AnySyncEphemeralRoomEvent::FullyRead(full_read) => {
event_emitter.on_non_room_fully_read(room, &full_read).await event_emitter.on_non_room_fully_read(room, &full_read).await
} }
AnyEphemeralRoomEventStub::Typing(typing) => { AnySyncEphemeralRoomEvent::Typing(typing) => {
event_emitter.on_non_room_typing(room, &typing).await event_emitter.on_non_room_typing(room, &typing).await
} }
AnyEphemeralRoomEventStub::Receipt(receipt) => { AnySyncEphemeralRoomEvent::Receipt(receipt) => {
event_emitter.on_non_room_receipt(room, &receipt).await event_emitter.on_non_room_receipt(room, &receipt).await
} }
_ => {} _ => {}
@ -1838,18 +1838,20 @@ impl BaseClient {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use crate::identifiers::{EventId, RoomId, UserId}; use crate::identifiers::{RoomId, UserId};
use crate::{BaseClient, BaseClientConfig, Session}; #[cfg(feature = "messages")]
use matrix_sdk_common::events::{AnyRoomEventStub, EventJson}; use crate::{
events::{AnySyncRoomEvent, EventJson},
identifiers::EventId,
BaseClientConfig, JsonStore,
};
use crate::{BaseClient, Session};
use matrix_sdk_common_macros::async_trait; use matrix_sdk_common_macros::async_trait;
use matrix_sdk_test::{async_test, test_json, EventBuilder, EventsJson}; use matrix_sdk_test::{async_test, test_json, EventBuilder, EventsJson};
use serde_json::json; use serde_json::json;
use std::convert::TryFrom; use std::convert::TryFrom;
use tempfile::tempdir; use tempfile::tempdir;
#[cfg(feature = "messages")]
use crate::JsonStore;
#[cfg(target_arch = "wasm32")] #[cfg(target_arch = "wasm32")]
use wasm_bindgen_test::*; use wasm_bindgen_test::*;
@ -2008,7 +2010,7 @@ mod test {
use crate::{EventEmitter, SyncRoom}; use crate::{EventEmitter, SyncRoom};
use matrix_sdk_common::events::{ use matrix_sdk_common::events::{
room::member::{MemberEventContent, MembershipChange}, room::member::{MemberEventContent, MembershipChange},
StateEventStub, SyncStateEvent,
}; };
use matrix_sdk_common::locks::RwLock; use matrix_sdk_common::locks::RwLock;
use std::sync::{ use std::sync::{
@ -2022,7 +2024,7 @@ mod test {
async fn on_room_member( async fn on_room_member(
&self, &self,
room: SyncRoom, room: SyncRoom,
event: &StateEventStub<MemberEventContent>, event: &SyncStateEvent<MemberEventContent>,
) { ) {
if let SyncRoom::Joined(_) = room { if let SyncRoom::Joined(_) = room {
if let MembershipChange::Joined = event.membership_change() { if let MembershipChange::Joined = event.membership_change() {
@ -2395,7 +2397,7 @@ mod test {
"type": "m.room.redaction", "type": "m.room.redaction",
"redacts": "$152037280074GZeOm:localhost" "redacts": "$152037280074GZeOm:localhost"
}); });
let mut event: EventJson<AnyRoomEventStub> = serde_json::from_value(json).unwrap(); let mut event: EventJson<AnySyncRoomEvent> = serde_json::from_value(json).unwrap();
client client
.receive_joined_timeline_event(&room_id, &mut event) .receive_joined_timeline_event(&room_id, &mut event)
.await .await
@ -2404,8 +2406,8 @@ mod test {
// check that the message has actually been redacted // check that the message has actually been redacted
for room in client.joined_rooms().read().await.values() { for room in client.joined_rooms().read().await.values() {
let queue = &room.read().await.messages; let queue = &room.read().await.messages;
if let crate::models::FullOrRedactedEvent::Redacted( if let crate::events::AnyPossiblyRedactedSyncMessageEvent::Redacted(
crate::events::AnyRedactedMessageEventStub::RoomMessage(event), crate::events::AnyRedactedSyncMessageEvent::RoomMessage(event),
) = &queue.msgs[0].deref() ) = &queue.msgs[0].deref()
{ {
// this is the id from the message event in the sync response // this is the id from the message event in the sync response
@ -2432,8 +2434,8 @@ mod test {
// properly // properly
for room in client.joined_rooms().read().await.values() { for room in client.joined_rooms().read().await.values() {
let queue = &room.read().await.messages; let queue = &room.read().await.messages;
if let crate::models::FullOrRedactedEvent::Redacted( if let crate::events::AnyPossiblyRedactedSyncMessageEvent::Redacted(
crate::events::AnyRedactedMessageEventStub::RoomMessage(event), crate::events::AnyRedactedSyncMessageEvent::RoomMessage(event),
) = &queue.msgs[0].deref() ) = &queue.msgs[0].deref()
{ {
// this is the id from the message event in the sync response // this is the id from the message event in the sync response

View File

@ -33,11 +33,11 @@ use crate::events::{
message::{feedback::FeedbackEventContent, MessageEventContent as MsgEventContent}, message::{feedback::FeedbackEventContent, MessageEventContent as MsgEventContent},
name::NameEventContent, name::NameEventContent,
power_levels::PowerLevelsEventContent, power_levels::PowerLevelsEventContent,
redaction::RedactionEventStub, redaction::SyncRedactionEvent,
tombstone::TombstoneEventContent, tombstone::TombstoneEventContent,
}, },
typing::TypingEventContent, typing::TypingEventContent,
BasicEvent, EphemeralRoomEvent, MessageEventStub, StateEventStub, StrippedStateEventStub, BasicEvent, EphemeralRoomEvent, StrippedStateEvent, SyncMessageEvent, SyncStateEvent,
}; };
use crate::{Room, RoomState}; use crate::{Room, RoomState};
use matrix_sdk_common_macros::async_trait; use matrix_sdk_common_macros::async_trait;
@ -55,11 +55,11 @@ pub enum CustomOrRawEvent<'c> {
/// A custom basic event. /// A custom basic event.
EphemeralRoom(&'c EphemeralRoomEvent<CustomEventContent>), EphemeralRoom(&'c EphemeralRoomEvent<CustomEventContent>),
/// A custom room event. /// A custom room event.
Message(&'c MessageEventStub<CustomEventContent>), Message(&'c SyncMessageEvent<CustomEventContent>),
/// A custom state event. /// A custom state event.
State(&'c StateEventStub<CustomEventContent>), State(&'c SyncStateEvent<CustomEventContent>),
/// A custom stripped state event. /// A custom stripped state event.
StrippedState(&'c StrippedStateEventStub<CustomEventContent>), StrippedState(&'c StrippedStateEvent<CustomEventContent>),
} }
/// This trait allows any type implementing `EventEmitter` to specify event callbacks for each event. /// This trait allows any type implementing `EventEmitter` to specify event callbacks for each event.
@ -74,7 +74,7 @@ pub enum CustomOrRawEvent<'c> {
/// # self, /// # self,
/// # events::{ /// # events::{
/// # room::message::{MessageEventContent, TextMessageEventContent}, /// # room::message::{MessageEventContent, TextMessageEventContent},
/// # MessageEventStub /// # SyncMessageEvent
/// # }, /// # },
/// # EventEmitter, SyncRoom /// # EventEmitter, SyncRoom
/// # }; /// # };
@ -85,9 +85,9 @@ pub enum CustomOrRawEvent<'c> {
/// ///
/// #[async_trait] /// #[async_trait]
/// impl EventEmitter for EventCallback { /// impl EventEmitter for EventCallback {
/// async fn on_room_message(&self, room: SyncRoom, event: &MessageEventStub<MessageEventContent>) { /// async fn on_room_message(&self, room: SyncRoom, event: &SyncMessageEvent<MessageEventContent>) {
/// if let SyncRoom::Joined(room) = room { /// if let SyncRoom::Joined(room) = room {
/// if let MessageEventStub { /// if let SyncMessageEvent {
/// content: MessageEventContent::Text(TextMessageEventContent { body: msg_body, .. }), /// content: MessageEventContent::Text(TextMessageEventContent { body: msg_body, .. }),
/// sender, /// sender,
/// .. /// ..
@ -112,114 +112,109 @@ pub enum CustomOrRawEvent<'c> {
pub trait EventEmitter: Send + Sync { pub trait EventEmitter: Send + Sync {
// ROOM EVENTS from `IncomingTimeline` // ROOM EVENTS from `IncomingTimeline`
/// Fires when `Client` receives a `RoomEvent::RoomMember` event. /// Fires when `Client` receives a `RoomEvent::RoomMember` event.
async fn on_room_member(&self, _: SyncRoom, _: &StateEventStub<MemberEventContent>) {} async fn on_room_member(&self, _: SyncRoom, _: &SyncStateEvent<MemberEventContent>) {}
/// Fires when `Client` receives a `RoomEvent::RoomName` event. /// Fires when `Client` receives a `RoomEvent::RoomName` event.
async fn on_room_name(&self, _: SyncRoom, _: &StateEventStub<NameEventContent>) {} async fn on_room_name(&self, _: SyncRoom, _: &SyncStateEvent<NameEventContent>) {}
/// Fires when `Client` receives a `RoomEvent::RoomCanonicalAlias` event. /// Fires when `Client` receives a `RoomEvent::RoomCanonicalAlias` event.
async fn on_room_canonical_alias( async fn on_room_canonical_alias(
&self, &self,
_: SyncRoom, _: SyncRoom,
_: &StateEventStub<CanonicalAliasEventContent>, _: &SyncStateEvent<CanonicalAliasEventContent>,
) { ) {
} }
/// Fires when `Client` receives a `RoomEvent::RoomAliases` event. /// Fires when `Client` receives a `RoomEvent::RoomAliases` event.
async fn on_room_aliases(&self, _: SyncRoom, _: &StateEventStub<AliasesEventContent>) {} async fn on_room_aliases(&self, _: SyncRoom, _: &SyncStateEvent<AliasesEventContent>) {}
/// Fires when `Client` receives a `RoomEvent::RoomAvatar` event. /// Fires when `Client` receives a `RoomEvent::RoomAvatar` event.
async fn on_room_avatar(&self, _: SyncRoom, _: &StateEventStub<AvatarEventContent>) {} async fn on_room_avatar(&self, _: SyncRoom, _: &SyncStateEvent<AvatarEventContent>) {}
/// Fires when `Client` receives a `RoomEvent::RoomMessage` event. /// Fires when `Client` receives a `RoomEvent::RoomMessage` event.
async fn on_room_message(&self, _: SyncRoom, _: &MessageEventStub<MsgEventContent>) {} async fn on_room_message(&self, _: SyncRoom, _: &SyncMessageEvent<MsgEventContent>) {}
/// Fires when `Client` receives a `RoomEvent::RoomMessageFeedback` event. /// Fires when `Client` receives a `RoomEvent::RoomMessageFeedback` event.
async fn on_room_message_feedback( async fn on_room_message_feedback(
&self, &self,
_: SyncRoom, _: SyncRoom,
_: &MessageEventStub<FeedbackEventContent>, _: &SyncMessageEvent<FeedbackEventContent>,
) { ) {
} }
/// Fires when `Client` receives a `RoomEvent::RoomRedaction` event. /// Fires when `Client` receives a `RoomEvent::RoomRedaction` event.
async fn on_room_redaction(&self, _: SyncRoom, _: &RedactionEventStub) {} async fn on_room_redaction(&self, _: SyncRoom, _: &SyncRedactionEvent) {}
/// Fires when `Client` receives a `RoomEvent::RoomPowerLevels` event. /// Fires when `Client` receives a `RoomEvent::RoomPowerLevels` event.
async fn on_room_power_levels(&self, _: SyncRoom, _: &StateEventStub<PowerLevelsEventContent>) { async fn on_room_power_levels(&self, _: SyncRoom, _: &SyncStateEvent<PowerLevelsEventContent>) {
} }
/// Fires when `Client` receives a `RoomEvent::Tombstone` event. /// Fires when `Client` receives a `RoomEvent::Tombstone` event.
async fn on_room_join_rules(&self, _: SyncRoom, _: &StateEventStub<JoinRulesEventContent>) {} async fn on_room_join_rules(&self, _: SyncRoom, _: &SyncStateEvent<JoinRulesEventContent>) {}
/// Fires when `Client` receives a `RoomEvent::Tombstone` event. /// Fires when `Client` receives a `RoomEvent::Tombstone` event.
async fn on_room_tombstone(&self, _: SyncRoom, _: &StateEventStub<TombstoneEventContent>) {} async fn on_room_tombstone(&self, _: SyncRoom, _: &SyncStateEvent<TombstoneEventContent>) {}
// `RoomEvent`s from `IncomingState` // `RoomEvent`s from `IncomingState`
/// Fires when `Client` receives a `StateEvent::RoomMember` event. /// Fires when `Client` receives a `StateEvent::RoomMember` event.
async fn on_state_member(&self, _: SyncRoom, _: &StateEventStub<MemberEventContent>) {} async fn on_state_member(&self, _: SyncRoom, _: &SyncStateEvent<MemberEventContent>) {}
/// Fires when `Client` receives a `StateEvent::RoomName` event. /// Fires when `Client` receives a `StateEvent::RoomName` event.
async fn on_state_name(&self, _: SyncRoom, _: &StateEventStub<NameEventContent>) {} async fn on_state_name(&self, _: SyncRoom, _: &SyncStateEvent<NameEventContent>) {}
/// Fires when `Client` receives a `StateEvent::RoomCanonicalAlias` event. /// Fires when `Client` receives a `StateEvent::RoomCanonicalAlias` event.
async fn on_state_canonical_alias( async fn on_state_canonical_alias(
&self, &self,
_: SyncRoom, _: SyncRoom,
_: &StateEventStub<CanonicalAliasEventContent>, _: &SyncStateEvent<CanonicalAliasEventContent>,
) { ) {
} }
/// Fires when `Client` receives a `StateEvent::RoomAliases` event. /// Fires when `Client` receives a `StateEvent::RoomAliases` event.
async fn on_state_aliases(&self, _: SyncRoom, _: &StateEventStub<AliasesEventContent>) {} async fn on_state_aliases(&self, _: SyncRoom, _: &SyncStateEvent<AliasesEventContent>) {}
/// Fires when `Client` receives a `StateEvent::RoomAvatar` event. /// Fires when `Client` receives a `StateEvent::RoomAvatar` event.
async fn on_state_avatar(&self, _: SyncRoom, _: &StateEventStub<AvatarEventContent>) {} async fn on_state_avatar(&self, _: SyncRoom, _: &SyncStateEvent<AvatarEventContent>) {}
/// Fires when `Client` receives a `StateEvent::RoomPowerLevels` event. /// Fires when `Client` receives a `StateEvent::RoomPowerLevels` event.
async fn on_state_power_levels( async fn on_state_power_levels(
&self, &self,
_: SyncRoom, _: SyncRoom,
_: &StateEventStub<PowerLevelsEventContent>, _: &SyncStateEvent<PowerLevelsEventContent>,
) { ) {
} }
/// Fires when `Client` receives a `StateEvent::RoomJoinRules` event. /// Fires when `Client` receives a `StateEvent::RoomJoinRules` event.
async fn on_state_join_rules(&self, _: SyncRoom, _: &StateEventStub<JoinRulesEventContent>) {} async fn on_state_join_rules(&self, _: SyncRoom, _: &SyncStateEvent<JoinRulesEventContent>) {}
// `AnyStrippedStateEvent`s // `AnyStrippedStateEvent`s
/// Fires when `Client` receives a `AnyStrippedStateEvent::StrippedRoomMember` event. /// Fires when `Client` receives a `AnyStrippedStateEvent::StrippedRoomMember` event.
async fn on_stripped_state_member( async fn on_stripped_state_member(
&self, &self,
_: SyncRoom, _: SyncRoom,
_: &StrippedStateEventStub<MemberEventContent>, _: &StrippedStateEvent<MemberEventContent>,
_: Option<MemberEventContent>, _: Option<MemberEventContent>,
) { ) {
} }
/// Fires when `Client` receives a `AnyStrippedStateEvent::StrippedRoomName` event. /// Fires when `Client` receives a `AnyStrippedStateEvent::StrippedRoomName` event.
async fn on_stripped_state_name( async fn on_stripped_state_name(&self, _: SyncRoom, _: &StrippedStateEvent<NameEventContent>) {}
&self,
_: SyncRoom,
_: &StrippedStateEventStub<NameEventContent>,
) {
}
/// Fires when `Client` receives a `AnyStrippedStateEvent::StrippedRoomCanonicalAlias` event. /// Fires when `Client` receives a `AnyStrippedStateEvent::StrippedRoomCanonicalAlias` event.
async fn on_stripped_state_canonical_alias( async fn on_stripped_state_canonical_alias(
&self, &self,
_: SyncRoom, _: SyncRoom,
_: &StrippedStateEventStub<CanonicalAliasEventContent>, _: &StrippedStateEvent<CanonicalAliasEventContent>,
) { ) {
} }
/// Fires when `Client` receives a `AnyStrippedStateEvent::StrippedRoomAliases` event. /// Fires when `Client` receives a `AnyStrippedStateEvent::StrippedRoomAliases` event.
async fn on_stripped_state_aliases( async fn on_stripped_state_aliases(
&self, &self,
_: SyncRoom, _: SyncRoom,
_: &StrippedStateEventStub<AliasesEventContent>, _: &StrippedStateEvent<AliasesEventContent>,
) { ) {
} }
/// Fires when `Client` receives a `AnyStrippedStateEvent::StrippedRoomAvatar` event. /// Fires when `Client` receives a `AnyStrippedStateEvent::StrippedRoomAvatar` event.
async fn on_stripped_state_avatar( async fn on_stripped_state_avatar(
&self, &self,
_: SyncRoom, _: SyncRoom,
_: &StrippedStateEventStub<AvatarEventContent>, _: &StrippedStateEvent<AvatarEventContent>,
) { ) {
} }
/// Fires when `Client` receives a `AnyStrippedStateEvent::StrippedRoomPowerLevels` event. /// Fires when `Client` receives a `AnyStrippedStateEvent::StrippedRoomPowerLevels` event.
async fn on_stripped_state_power_levels( async fn on_stripped_state_power_levels(
&self, &self,
_: SyncRoom, _: SyncRoom,
_: &StrippedStateEventStub<PowerLevelsEventContent>, _: &StrippedStateEvent<PowerLevelsEventContent>,
) { ) {
} }
/// Fires when `Client` receives a `AnyStrippedStateEvent::StrippedRoomJoinRules` event. /// Fires when `Client` receives a `AnyStrippedStateEvent::StrippedRoomJoinRules` event.
async fn on_stripped_state_join_rules( async fn on_stripped_state_join_rules(
&self, &self,
_: SyncRoom, _: SyncRoom,
_: &StrippedStateEventStub<JoinRulesEventContent>, _: &StrippedStateEvent<JoinRulesEventContent>,
) { ) {
} }
@ -276,79 +271,79 @@ mod test {
#[async_trait] #[async_trait]
impl EventEmitter for EvEmitterTest { impl EventEmitter for EvEmitterTest {
async fn on_room_member(&self, _: SyncRoom, _: &StateEventStub<MemberEventContent>) { async fn on_room_member(&self, _: SyncRoom, _: &SyncStateEvent<MemberEventContent>) {
self.0.lock().await.push("member".to_string()) self.0.lock().await.push("member".to_string())
} }
async fn on_room_name(&self, _: SyncRoom, _: &StateEventStub<NameEventContent>) { async fn on_room_name(&self, _: SyncRoom, _: &SyncStateEvent<NameEventContent>) {
self.0.lock().await.push("name".to_string()) self.0.lock().await.push("name".to_string())
} }
async fn on_room_canonical_alias( async fn on_room_canonical_alias(
&self, &self,
_: SyncRoom, _: SyncRoom,
_: &StateEventStub<CanonicalAliasEventContent>, _: &SyncStateEvent<CanonicalAliasEventContent>,
) { ) {
self.0.lock().await.push("canonical".to_string()) self.0.lock().await.push("canonical".to_string())
} }
async fn on_room_aliases(&self, _: SyncRoom, _: &StateEventStub<AliasesEventContent>) { async fn on_room_aliases(&self, _: SyncRoom, _: &SyncStateEvent<AliasesEventContent>) {
self.0.lock().await.push("aliases".to_string()) self.0.lock().await.push("aliases".to_string())
} }
async fn on_room_avatar(&self, _: SyncRoom, _: &StateEventStub<AvatarEventContent>) { async fn on_room_avatar(&self, _: SyncRoom, _: &SyncStateEvent<AvatarEventContent>) {
self.0.lock().await.push("avatar".to_string()) self.0.lock().await.push("avatar".to_string())
} }
async fn on_room_message(&self, _: SyncRoom, _: &MessageEventStub<MsgEventContent>) { async fn on_room_message(&self, _: SyncRoom, _: &SyncMessageEvent<MsgEventContent>) {
self.0.lock().await.push("message".to_string()) self.0.lock().await.push("message".to_string())
} }
async fn on_room_message_feedback( async fn on_room_message_feedback(
&self, &self,
_: SyncRoom, _: SyncRoom,
_: &MessageEventStub<FeedbackEventContent>, _: &SyncMessageEvent<FeedbackEventContent>,
) { ) {
self.0.lock().await.push("feedback".to_string()) self.0.lock().await.push("feedback".to_string())
} }
async fn on_room_redaction(&self, _: SyncRoom, _: &RedactionEventStub) { async fn on_room_redaction(&self, _: SyncRoom, _: &SyncRedactionEvent) {
self.0.lock().await.push("redaction".to_string()) self.0.lock().await.push("redaction".to_string())
} }
async fn on_room_power_levels( async fn on_room_power_levels(
&self, &self,
_: SyncRoom, _: SyncRoom,
_: &StateEventStub<PowerLevelsEventContent>, _: &SyncStateEvent<PowerLevelsEventContent>,
) { ) {
self.0.lock().await.push("power".to_string()) self.0.lock().await.push("power".to_string())
} }
async fn on_room_tombstone(&self, _: SyncRoom, _: &StateEventStub<TombstoneEventContent>) { async fn on_room_tombstone(&self, _: SyncRoom, _: &SyncStateEvent<TombstoneEventContent>) {
self.0.lock().await.push("tombstone".to_string()) self.0.lock().await.push("tombstone".to_string())
} }
async fn on_state_member(&self, _: SyncRoom, _: &StateEventStub<MemberEventContent>) { async fn on_state_member(&self, _: SyncRoom, _: &SyncStateEvent<MemberEventContent>) {
self.0.lock().await.push("state member".to_string()) self.0.lock().await.push("state member".to_string())
} }
async fn on_state_name(&self, _: SyncRoom, _: &StateEventStub<NameEventContent>) { async fn on_state_name(&self, _: SyncRoom, _: &SyncStateEvent<NameEventContent>) {
self.0.lock().await.push("state name".to_string()) self.0.lock().await.push("state name".to_string())
} }
async fn on_state_canonical_alias( async fn on_state_canonical_alias(
&self, &self,
_: SyncRoom, _: SyncRoom,
_: &StateEventStub<CanonicalAliasEventContent>, _: &SyncStateEvent<CanonicalAliasEventContent>,
) { ) {
self.0.lock().await.push("state canonical".to_string()) self.0.lock().await.push("state canonical".to_string())
} }
async fn on_state_aliases(&self, _: SyncRoom, _: &StateEventStub<AliasesEventContent>) { async fn on_state_aliases(&self, _: SyncRoom, _: &SyncStateEvent<AliasesEventContent>) {
self.0.lock().await.push("state aliases".to_string()) self.0.lock().await.push("state aliases".to_string())
} }
async fn on_state_avatar(&self, _: SyncRoom, _: &StateEventStub<AvatarEventContent>) { async fn on_state_avatar(&self, _: SyncRoom, _: &SyncStateEvent<AvatarEventContent>) {
self.0.lock().await.push("state avatar".to_string()) self.0.lock().await.push("state avatar".to_string())
} }
async fn on_state_power_levels( async fn on_state_power_levels(
&self, &self,
_: SyncRoom, _: SyncRoom,
_: &StateEventStub<PowerLevelsEventContent>, _: &SyncStateEvent<PowerLevelsEventContent>,
) { ) {
self.0.lock().await.push("state power".to_string()) self.0.lock().await.push("state power".to_string())
} }
async fn on_state_join_rules( async fn on_state_join_rules(
&self, &self,
_: SyncRoom, _: SyncRoom,
_: &StateEventStub<JoinRulesEventContent>, _: &SyncStateEvent<JoinRulesEventContent>,
) { ) {
self.0.lock().await.push("state rules".to_string()) self.0.lock().await.push("state rules".to_string())
} }
@ -358,7 +353,7 @@ mod test {
async fn on_stripped_state_member( async fn on_stripped_state_member(
&self, &self,
_: SyncRoom, _: SyncRoom,
_: &StrippedStateEventStub<MemberEventContent>, _: &StrippedStateEvent<MemberEventContent>,
_: Option<MemberEventContent>, _: Option<MemberEventContent>,
) { ) {
self.0 self.0
@ -370,7 +365,7 @@ mod test {
async fn on_stripped_state_name( async fn on_stripped_state_name(
&self, &self,
_: SyncRoom, _: SyncRoom,
_: &StrippedStateEventStub<NameEventContent>, _: &StrippedStateEvent<NameEventContent>,
) { ) {
self.0.lock().await.push("stripped state name".to_string()) self.0.lock().await.push("stripped state name".to_string())
} }
@ -378,7 +373,7 @@ mod test {
async fn on_stripped_state_canonical_alias( async fn on_stripped_state_canonical_alias(
&self, &self,
_: SyncRoom, _: SyncRoom,
_: &StrippedStateEventStub<CanonicalAliasEventContent>, _: &StrippedStateEvent<CanonicalAliasEventContent>,
) { ) {
self.0 self.0
.lock() .lock()
@ -389,7 +384,7 @@ mod test {
async fn on_stripped_state_aliases( async fn on_stripped_state_aliases(
&self, &self,
_: SyncRoom, _: SyncRoom,
_: &StrippedStateEventStub<AliasesEventContent>, _: &StrippedStateEvent<AliasesEventContent>,
) { ) {
self.0 self.0
.lock() .lock()
@ -400,7 +395,7 @@ mod test {
async fn on_stripped_state_avatar( async fn on_stripped_state_avatar(
&self, &self,
_: SyncRoom, _: SyncRoom,
_: &StrippedStateEventStub<AvatarEventContent>, _: &StrippedStateEvent<AvatarEventContent>,
) { ) {
self.0 self.0
.lock() .lock()
@ -411,7 +406,7 @@ mod test {
async fn on_stripped_state_power_levels( async fn on_stripped_state_power_levels(
&self, &self,
_: SyncRoom, _: SyncRoom,
_: &StrippedStateEventStub<PowerLevelsEventContent>, _: &StrippedStateEvent<PowerLevelsEventContent>,
) { ) {
self.0.lock().await.push("stripped state power".to_string()) self.0.lock().await.push("stripped state power".to_string())
} }
@ -419,7 +414,7 @@ mod test {
async fn on_stripped_state_join_rules( async fn on_stripped_state_join_rules(
&self, &self,
_: SyncRoom, _: SyncRoom,
_: &StrippedStateEventStub<JoinRulesEventContent>, _: &StrippedStateEvent<JoinRulesEventContent>,
) { ) {
self.0.lock().await.push("stripped state rules".to_string()) self.0.lock().await.push("stripped state rules".to_string())
} }

View File

@ -13,7 +13,7 @@ use std::{
use matrix_sdk_common::identifiers::EventId; use matrix_sdk_common::identifiers::EventId;
use serde::{de, ser, Deserialize, Serialize}; use serde::{de, ser, Deserialize, Serialize};
use crate::events::{AnyMessageEventStub, AnyRedactedMessageEventStub}; use crate::events::{AnyRedactedSyncMessageEvent, AnySyncMessageEvent};
/// Represents either a redacted event or a non-redacted event. /// Represents either a redacted event or a non-redacted event.
/// ///
@ -21,9 +21,9 @@ use crate::events::{AnyMessageEventStub, AnyRedactedMessageEventStub};
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
pub enum FullOrRedactedEvent { pub enum FullOrRedactedEvent {
/// A non-redacted event. /// A non-redacted event.
Full(AnyMessageEventStub), Full(AnySyncMessageEvent),
/// An event that has been redacted. /// An event that has been redacted.
Redacted(AnyRedactedMessageEventStub), Redacted(AnyRedactedSyncMessageEvent),
} }
impl FullOrRedactedEvent { impl FullOrRedactedEvent {
@ -228,7 +228,7 @@ mod test {
let json: &serde_json::Value = &test_json::MESSAGE_TEXT; let json: &serde_json::Value = &test_json::MESSAGE_TEXT;
let msg = FullOrRedactedEvent::Full( let msg = FullOrRedactedEvent::Full(
serde_json::from_value::<AnyMessageEventStub>(json.clone()).unwrap(), serde_json::from_value::<AnySyncMessageEvent>(json.clone()).unwrap(),
); );
let mut msgs = MessageQueue::new(); let mut msgs = MessageQueue::new();
@ -275,7 +275,7 @@ mod test {
let json: &serde_json::Value = &test_json::MESSAGE_TEXT; let json: &serde_json::Value = &test_json::MESSAGE_TEXT;
let msg = FullOrRedactedEvent::Full( let msg = FullOrRedactedEvent::Full(
serde_json::from_value::<AnyMessageEventStub>(json.clone()).unwrap(), serde_json::from_value::<AnySyncMessageEvent>(json.clone()).unwrap(),
); );
let mut msgs = MessageQueue::new(); let mut msgs = MessageQueue::new();

View File

@ -15,6 +15,8 @@
use std::collections::{BTreeMap, HashMap, HashSet}; use std::collections::{BTreeMap, HashMap, HashSet};
use std::convert::TryFrom; use std::convert::TryFrom;
#[cfg(feature = "messages")]
use std::ops::DerefMut;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use tracing::{debug, error, trace}; use tracing::{debug, error, trace};
@ -22,27 +24,26 @@ use tracing::{debug, error, trace};
#[cfg(feature = "messages")] #[cfg(feature = "messages")]
use super::message::{FullOrRedactedEvent, MessageQueue}; use super::message::{FullOrRedactedEvent, MessageQueue};
use super::RoomMember; use super::RoomMember;
use crate::api::r0::sync::sync_events::{RoomSummary, UnreadNotificationsCount}; use crate::api::r0::sync::sync_events::{RoomSummary, UnreadNotificationsCount};
use crate::events::{ use crate::events::{
presence::PresenceEvent, presence::{PresenceEvent, PresenceEventContent},
room::{ room::{
aliases::AliasesEventContent, aliases::AliasesEventContent,
canonical_alias::CanonicalAliasEventContent, canonical_alias::CanonicalAliasEventContent,
encryption::EncryptionEventContent, encryption::EncryptionEventContent,
member::{MemberEventContent, MembershipChange}, member::{MemberEventContent, MembershipChange, MembershipState},
name::NameEventContent, name::NameEventContent,
power_levels::{NotificationPowerLevels, PowerLevelsEventContent}, power_levels::{NotificationPowerLevels, PowerLevelsEventContent},
tombstone::TombstoneEventContent, tombstone::TombstoneEventContent,
}, },
Algorithm, AnyRoomEventStub, AnyStateEventStub, AnyStrippedStateEventStub, EventType, Algorithm, AnyStrippedStateEvent, AnySyncRoomEvent, AnySyncStateEvent, EventType,
StateEventStub, StrippedStateEventStub, StrippedStateEvent, SyncStateEvent,
}; };
#[cfg(feature = "messages")] #[cfg(feature = "messages")]
use crate::events::{ use crate::events::{
room::redaction::{RedactionEvent, RedactionEventStub}, room::redaction::{RedactionEvent, SyncRedactionEvent},
AnyMessageEventStub, EventJson, AnySyncMessageEvent,
}; };
use crate::identifiers::{RoomAliasId, RoomId, UserId}; use crate::identifiers::{RoomAliasId, RoomId, UserId};
@ -51,7 +52,7 @@ use crate::js_int::{int, uint, Int, UInt};
#[cfg(feature = "messages")] #[cfg(feature = "messages")]
fn redaction_event_from_redaction_stub( fn redaction_event_from_redaction_stub(
event: RedactionEventStub, event: SyncRedactionEvent,
room_id: RoomId, room_id: RoomId,
) -> RedactionEvent { ) -> RedactionEvent {
RedactionEvent { RedactionEvent {
@ -145,8 +146,8 @@ impl EncryptionInfo {
} }
} }
impl From<&StateEventStub<EncryptionEventContent>> for EncryptionInfo { impl From<&SyncStateEvent<EncryptionEventContent>> for EncryptionInfo {
fn from(event: &StateEventStub<EncryptionEventContent>) -> Self { fn from(event: &SyncStateEvent<EncryptionEventContent>) -> Self {
EncryptionInfo { EncryptionInfo {
algorithm: event.content.algorithm.clone(), algorithm: event.content.algorithm.clone(),
rotation_period_ms: event rotation_period_ms: event
@ -351,7 +352,7 @@ impl Room {
fn add_member( fn add_member(
&mut self, &mut self,
target_member: &UserId, target_member: &UserId,
event: &StateEventStub<MemberEventContent>, event: &SyncStateEvent<MemberEventContent>,
) -> (bool, HashMap<UserId, bool>) { ) -> (bool, HashMap<UserId, bool>) {
let new_member = RoomMember::new(event, &self.room_id); let new_member = RoomMember::new(event, &self.room_id);
@ -405,7 +406,7 @@ impl Room {
fn remove_member( fn remove_member(
&mut self, &mut self,
target_member: &UserId, target_member: &UserId,
event: &StateEventStub<MemberEventContent>, event: &SyncStateEvent<MemberEventContent>,
) -> (bool, HashMap<UserId, bool>) { ) -> (bool, HashMap<UserId, bool>) {
let leaving_member = RoomMember::new(event, &self.room_id); let leaving_member = RoomMember::new(event, &self.room_id);
@ -554,7 +555,7 @@ impl Room {
true true
} }
fn set_room_power_level(&mut self, event: &StateEventStub<PowerLevelsEventContent>) -> bool { fn set_room_power_level(&mut self, event: &SyncStateEvent<PowerLevelsEventContent>) -> bool {
let PowerLevelsEventContent { let PowerLevelsEventContent {
ban, ban,
events, events,
@ -608,7 +609,7 @@ impl Room {
/// `disambiguation_updates`). /// `disambiguation_updates`).
pub fn handle_membership( pub fn handle_membership(
&mut self, &mut self,
event: &StateEventStub<MemberEventContent>, event: &SyncStateEvent<MemberEventContent>,
state_event: bool, state_event: bool,
) -> (bool, HashMap<UserId, bool>) { ) -> (bool, HashMap<UserId, bool>) {
use MembershipChange::*; use MembershipChange::*;
@ -672,7 +673,7 @@ impl Room {
/// Returns true if `MessageQueue` was added to. /// Returns true if `MessageQueue` was added to.
#[cfg(feature = "messages")] #[cfg(feature = "messages")]
#[cfg_attr(docsrs, doc(cfg(feature = "messages")))] #[cfg_attr(docsrs, doc(cfg(feature = "messages")))]
pub fn handle_message(&mut self, event: &AnyMessageEventStub) -> bool { pub fn handle_message(&mut self, event: &AnySyncMessageEvent) -> bool {
self.messages.push(FullOrRedactedEvent::Full(event.clone())) self.messages.push(FullOrRedactedEvent::Full(event.clone()))
} }
@ -684,12 +685,10 @@ impl Room {
/// field. /// field.
#[cfg(feature = "messages")] #[cfg(feature = "messages")]
#[cfg_attr(docsrs, doc(cfg(feature = "messages")))] #[cfg_attr(docsrs, doc(cfg(feature = "messages")))]
pub fn handle_redaction(&mut self, redacted_event: &RedactionEventStub) -> bool { pub fn handle_redaction(&mut self, redacted_event: &SyncRedactionEvent) -> bool {
use matrix_sdk_common::events::{ use matrix_sdk_common::events::{
AnyRedactedMessageEventStub, MessageEventStub, RedactedMessageEventStub, AnyRedactedSyncMessageEvent, EventJson, RedactedSyncMessageEvent, SyncMessageEvent,
}; };
use std::ops::DerefMut;
if let Some(msg) = self if let Some(msg) = self
.messages .messages
.iter_mut() .iter_mut()
@ -697,8 +696,8 @@ impl Room {
{ {
match msg.deref_mut() { match msg.deref_mut() {
FullOrRedactedEvent::Full(event) => match event { FullOrRedactedEvent::Full(event) => match event {
AnyMessageEventStub::RoomMessage(event) => { AnySyncMessageEvent::RoomMessage(event) => {
let MessageEventStub { let SyncMessageEvent {
content, content,
event_id, event_id,
sender, sender,
@ -712,7 +711,7 @@ impl Room {
))); )));
let redacted = content.redact(); let redacted = content.redact();
msg.0 = FullOrRedactedEvent::Redacted( msg.0 = FullOrRedactedEvent::Redacted(
AnyRedactedMessageEventStub::RoomMessage(RedactedMessageEventStub { AnyRedactedSyncMessageEvent::RoomMessage(RedactedSyncMessageEvent {
content: redacted, content: redacted,
event_id, event_id,
origin_server_ts, origin_server_ts,
@ -721,8 +720,8 @@ impl Room {
}), }),
) )
} }
AnyMessageEventStub::Sticker(event) => { AnySyncMessageEvent::Sticker(event) => {
let MessageEventStub { let SyncMessageEvent {
content, content,
event_id, event_id,
sender, sender,
@ -735,8 +734,8 @@ impl Room {
self.room_id.clone(), self.room_id.clone(),
))); )));
let redacted = content.redact(); let redacted = content.redact();
msg.0 = FullOrRedactedEvent::Redacted(AnyRedactedMessageEventStub::Sticker( msg.0 = FullOrRedactedEvent::Redacted(AnyRedactedSyncMessageEvent::Sticker(
RedactedMessageEventStub { RedactedSyncMessageEvent {
content: redacted, content: redacted,
event_id, event_id,
origin_server_ts, origin_server_ts,
@ -759,7 +758,7 @@ impl Room {
/// Handle a room.aliases event, updating the room state if necessary. /// Handle a room.aliases event, updating the room state if necessary.
/// ///
/// Returns true if the room name changed, false otherwise. /// Returns true if the room name changed, false otherwise.
pub fn handle_room_aliases(&mut self, event: &StateEventStub<AliasesEventContent>) -> bool { pub fn handle_room_aliases(&mut self, event: &SyncStateEvent<AliasesEventContent>) -> bool {
match event.content.aliases.as_slice() { match event.content.aliases.as_slice() {
[alias] => self.push_room_alias(alias), [alias] => self.push_room_alias(alias),
[alias, ..] => self.push_room_alias(alias), [alias, ..] => self.push_room_alias(alias),
@ -771,7 +770,7 @@ impl Room {
/// necessary. /// necessary.
/// ///
/// Returns true if the room name changed, false otherwise. /// Returns true if the room name changed, false otherwise.
pub fn handle_canonical(&mut self, event: &StateEventStub<CanonicalAliasEventContent>) -> bool { pub fn handle_canonical(&mut self, event: &SyncStateEvent<CanonicalAliasEventContent>) -> bool {
match &event.content.alias { match &event.content.alias {
Some(name) => self.canonical_alias(&name), Some(name) => self.canonical_alias(&name),
_ => false, _ => false,
@ -781,7 +780,7 @@ impl Room {
/// Handle a room.name event, updating the room state if necessary. /// Handle a room.name event, updating the room state if necessary.
/// ///
/// Returns true if the room name changed, false otherwise. /// Returns true if the room name changed, false otherwise.
pub fn handle_room_name(&mut self, event: &StateEventStub<NameEventContent>) -> bool { pub fn handle_room_name(&mut self, event: &SyncStateEvent<NameEventContent>) -> bool {
match event.content.name() { match event.content.name() {
Some(name) => self.set_room_name(name), Some(name) => self.set_room_name(name),
_ => false, _ => false,
@ -793,7 +792,7 @@ impl Room {
/// Returns true if the room name changed, false otherwise. /// Returns true if the room name changed, false otherwise.
pub fn handle_stripped_room_name( pub fn handle_stripped_room_name(
&mut self, &mut self,
event: &StrippedStateEventStub<NameEventContent>, event: &StrippedStateEvent<NameEventContent>,
) -> bool { ) -> bool {
match event.content.name() { match event.content.name() {
Some(name) => self.set_room_name(name), Some(name) => self.set_room_name(name),
@ -804,7 +803,7 @@ impl Room {
/// Handle a room.power_levels event, updating the room state if necessary. /// Handle a room.power_levels event, updating the room state if necessary.
/// ///
/// Returns true if the room name changed, false otherwise. /// Returns true if the room name changed, false otherwise.
pub fn handle_power_level(&mut self, event: &StateEventStub<PowerLevelsEventContent>) -> bool { pub fn handle_power_level(&mut self, event: &SyncStateEvent<PowerLevelsEventContent>) -> bool {
// NOTE: this is always true, we assume that if we get an event their is an update. // NOTE: this is always true, we assume that if we get an event their is an update.
let mut updated = self.set_room_power_level(event); let mut updated = self.set_room_power_level(event);
@ -824,7 +823,7 @@ impl Room {
updated updated
} }
fn handle_tombstone(&mut self, event: &StateEventStub<TombstoneEventContent>) -> bool { fn handle_tombstone(&mut self, event: &SyncStateEvent<TombstoneEventContent>) -> bool {
self.tombstone = Some(Tombstone { self.tombstone = Some(Tombstone {
body: event.content.body.clone(), body: event.content.body.clone(),
replacement: event.content.replacement_room.clone(), replacement: event.content.replacement_room.clone(),
@ -832,7 +831,7 @@ impl Room {
true true
} }
fn handle_encryption_event(&mut self, event: &StateEventStub<EncryptionEventContent>) -> bool { fn handle_encryption_event(&mut self, event: &SyncStateEvent<EncryptionEventContent>) -> bool {
self.encrypted = Some(event.into()); self.encrypted = Some(event.into());
true true
} }
@ -844,31 +843,31 @@ impl Room {
/// # Arguments /// # Arguments
/// ///
/// * `event` - The event of the room. /// * `event` - The event of the room.
pub fn receive_timeline_event(&mut self, event: &AnyRoomEventStub) -> bool { pub fn receive_timeline_event(&mut self, event: &AnySyncRoomEvent) -> bool {
match event { match event {
AnyRoomEventStub::State(event) => match event { AnySyncRoomEvent::State(event) => match event {
// update to the current members of the room // update to the current members of the room
AnyStateEventStub::RoomMember(event) => self.handle_membership(event, false).0, AnySyncStateEvent::RoomMember(event) => self.handle_membership(event, false).0,
// finds all events related to the name of the room for later use // finds all events related to the name of the room for later use
AnyStateEventStub::RoomName(event) => self.handle_room_name(event), AnySyncStateEvent::RoomName(event) => self.handle_room_name(event),
AnyStateEventStub::RoomCanonicalAlias(event) => self.handle_canonical(event), AnySyncStateEvent::RoomCanonicalAlias(event) => self.handle_canonical(event),
AnyStateEventStub::RoomAliases(event) => self.handle_room_aliases(event), AnySyncStateEvent::RoomAliases(event) => self.handle_room_aliases(event),
// power levels of the room members // power levels of the room members
AnyStateEventStub::RoomPowerLevels(event) => self.handle_power_level(event), AnySyncStateEvent::RoomPowerLevels(event) => self.handle_power_level(event),
AnyStateEventStub::RoomTombstone(event) => self.handle_tombstone(event), AnySyncStateEvent::RoomTombstone(event) => self.handle_tombstone(event),
AnyStateEventStub::RoomEncryption(event) => self.handle_encryption_event(event), AnySyncStateEvent::RoomEncryption(event) => self.handle_encryption_event(event),
_ => false, _ => false,
}, },
AnyRoomEventStub::Message(event) => match event { AnySyncRoomEvent::Message(event) => match event {
#[cfg(feature = "messages")] #[cfg(feature = "messages")]
// We ignore this variants event because `handle_message` takes the enum // We ignore this variants event because `handle_message` takes the enum
// to store AnyMessageEventStub events in the `MessageQueue`. // to store AnySyncMessageEvent events in the `MessageQueue`.
AnyMessageEventStub::RoomMessage(_) => self.handle_message(event), AnySyncMessageEvent::RoomMessage(_) => self.handle_message(event),
#[cfg(feature = "messages")] #[cfg(feature = "messages")]
AnyMessageEventStub::RoomRedaction(event) => self.handle_redaction(event), AnySyncMessageEvent::RoomRedaction(event) => self.handle_redaction(event),
_ => false, _ => false,
}, },
AnyRoomEventStub::RedactedMessage(_) | AnyRoomEventStub::RedactedState(_) => false, AnySyncRoomEvent::RedactedMessage(_) | AnySyncRoomEvent::RedactedState(_) => false,
} }
} }
@ -879,18 +878,18 @@ impl Room {
/// # Arguments /// # Arguments
/// ///
/// * `event` - The event of the room. /// * `event` - The event of the room.
pub fn receive_state_event(&mut self, event: &AnyStateEventStub) -> bool { pub fn receive_state_event(&mut self, event: &AnySyncStateEvent) -> bool {
match event { match event {
// update to the current members of the room // update to the current members of the room
AnyStateEventStub::RoomMember(member) => self.handle_membership(member, true).0, AnySyncStateEvent::RoomMember(member) => self.handle_membership(member, true).0,
// finds all events related to the name of the room for later use // finds all events related to the name of the room for later use
AnyStateEventStub::RoomName(name) => self.handle_room_name(name), AnySyncStateEvent::RoomName(name) => self.handle_room_name(name),
AnyStateEventStub::RoomCanonicalAlias(c_alias) => self.handle_canonical(c_alias), AnySyncStateEvent::RoomCanonicalAlias(c_alias) => self.handle_canonical(c_alias),
AnyStateEventStub::RoomAliases(alias) => self.handle_room_aliases(alias), AnySyncStateEvent::RoomAliases(alias) => self.handle_room_aliases(alias),
// power levels of the room members // power levels of the room members
AnyStateEventStub::RoomPowerLevels(power) => self.handle_power_level(power), AnySyncStateEvent::RoomPowerLevels(power) => self.handle_power_level(power),
AnyStateEventStub::RoomTombstone(tomb) => self.handle_tombstone(tomb), AnySyncStateEvent::RoomTombstone(tomb) => self.handle_tombstone(tomb),
AnyStateEventStub::RoomEncryption(encrypt) => self.handle_encryption_event(encrypt), AnySyncStateEvent::RoomEncryption(encrypt) => self.handle_encryption_event(encrypt),
_ => false, _ => false,
} }
} }
@ -903,9 +902,9 @@ impl Room {
/// ///
/// * `event` - The `AnyStrippedStateEvent` sent by the server for invited /// * `event` - The `AnyStrippedStateEvent` sent by the server for invited
/// but not joined rooms. /// but not joined rooms.
pub fn receive_stripped_state_event(&mut self, event: &AnyStrippedStateEventStub) -> bool { pub fn receive_stripped_state_event(&mut self, event: &AnyStrippedStateEvent) -> bool {
match event { match event {
AnyStrippedStateEventStub::RoomName(event) => self.handle_stripped_room_name(event), AnyStrippedStateEvent::RoomName(event) => self.handle_stripped_room_name(event),
_ => false, _ => false,
} }
} }
@ -977,7 +976,7 @@ impl Room {
pub fn update_member_profile( pub fn update_member_profile(
&mut self, &mut self,
target_member: &UserId, target_member: &UserId,
event: &StateEventStub<MemberEventContent>, event: &SyncStateEvent<MemberEventContent>,
change: MembershipChange, change: MembershipChange,
) -> (bool, HashMap<UserId, bool>) { ) -> (bool, HashMap<UserId, bool>) {
let member = self.get_member(target_member); let member = self.get_member(target_member);
@ -1067,7 +1066,7 @@ impl Room {
/// * `max_power` - Maximum power level allowed. /// * `max_power` - Maximum power level allowed.
pub fn update_member_power( pub fn update_member_power(
member: &mut RoomMember, member: &mut RoomMember,
event: &StateEventStub<PowerLevelsEventContent>, event: &SyncStateEvent<PowerLevelsEventContent>,
max_power: Int, max_power: Int,
) -> bool { ) -> bool {
let changed; let changed;
@ -1142,7 +1141,7 @@ impl Describe for MembershipChange {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::*; use super::*;
use crate::events::{room::encryption::EncryptionEventContent, UnsignedData}; use crate::events::{room::encryption::EncryptionEventContent, EventJson, UnsignedData};
use crate::identifiers::{EventId, UserId}; use crate::identifiers::{EventId, UserId};
use crate::{BaseClient, Session}; use crate::{BaseClient, Session};
use matrix_sdk_test::{async_test, sync_response, EventBuilder, EventsJson, SyncResponseFile}; use matrix_sdk_test::{async_test, sync_response, EventBuilder, EventsJson, SyncResponseFile};
@ -1707,7 +1706,7 @@ mod test {
"type": "m.room.redaction", "type": "m.room.redaction",
"redacts": "$152037280074GZeOm:localhost" "redacts": "$152037280074GZeOm:localhost"
}); });
let mut event: EventJson<AnyRoomEventStub> = serde_json::from_value(json).unwrap(); let mut event: EventJson<AnySyncRoomEvent> = serde_json::from_value(json).unwrap();
client client
.receive_joined_timeline_event(&room_id, &mut event) .receive_joined_timeline_event(&room_id, &mut event)
.await .await
@ -1716,7 +1715,7 @@ mod test {
for room in client.joined_rooms().read().await.values() { for room in client.joined_rooms().read().await.values() {
let queue = &room.read().await.messages; let queue = &room.read().await.messages;
if let crate::models::message::FullOrRedactedEvent::Redacted( if let crate::models::message::FullOrRedactedEvent::Redacted(
crate::events::AnyRedactedMessageEventStub::RoomMessage(event), crate::events::AnyRedactedSyncMessageEvent::RoomMessage(event),
) = &queue.msgs[0].deref() ) = &queue.msgs[0].deref()
{ {
// this is the id from the message event in the sync response // this is the id from the message event in the sync response
@ -1747,7 +1746,7 @@ mod test {
client.restore_login(session).await.unwrap(); client.restore_login(session).await.unwrap();
client.receive_sync_response(&mut response).await.unwrap(); client.receive_sync_response(&mut response).await.unwrap();
let event = StateEventStub { let event = SyncStateEvent {
event_id: EventId::try_from("$h29iv0s8:example.com").unwrap(), event_id: EventId::try_from("$h29iv0s8:example.com").unwrap(),
origin_server_ts: SystemTime::now(), origin_server_ts: SystemTime::now(),
sender: user_id, sender: user_id,

View File

@ -15,12 +15,15 @@
use std::convert::TryFrom; use std::convert::TryFrom;
use crate::events::presence::{PresenceEvent, PresenceState}; use matrix_sdk_common::{
use crate::events::room::member::MemberEventContent; events::{
use crate::events::StateEventStub; presence::{PresenceEvent, PresenceState},
use crate::identifiers::{RoomId, UserId}; room::member::MemberEventContent,
SyncStateEvent,
use crate::js_int::{Int, UInt}; },
identifiers::{RoomId, UserId},
js_int::{Int, UInt},
};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
// Notes: if Alice invites Bob into a room we will get an event with the sender as Alice and the state key as Bob. // Notes: if Alice invites Bob into a room we will get an event with the sender as Alice and the state key as Bob.
@ -64,7 +67,7 @@ pub struct RoomMember {
// //
// Needs design. // Needs design.
/// The events that created the state of this room member. /// The events that created the state of this room member.
pub events: Vec<StateEventStub<MemberEventContent>>, pub events: Vec<SyncStateEvent<MemberEventContent>>,
/// The `PresenceEvent`s connected to this user. /// The `PresenceEvent`s connected to this user.
pub presence_events: Vec<PresenceEvent>, pub presence_events: Vec<PresenceEvent>,
} }
@ -83,7 +86,7 @@ impl PartialEq for RoomMember {
} }
impl RoomMember { impl RoomMember {
pub fn new(event: &StateEventStub<MemberEventContent>, room_id: &RoomId) -> Self { pub fn new(event: &SyncStateEvent<MemberEventContent>, room_id: &RoomId) -> Self {
Self { Self {
name: event.state_key.clone(), name: event.state_key.clone(),
room_id: room_id.clone(), room_id: room_id.clone(),

View File

@ -17,7 +17,7 @@ js_int = "0.1.8"
[dependencies.ruma] [dependencies.ruma]
git = "https://github.com/ruma/ruma" git = "https://github.com/ruma/ruma"
features = ["client-api"] features = ["client-api"]
rev = "5e428ac" rev = "848b225"
[target.'cfg(not(target_arch = "wasm32"))'.dependencies] [target.'cfg(not(target_arch = "wasm32"))'.dependencies]
uuid = { version = "0.8.1", features = ["v4"] } uuid = { version = "0.8.1", features = ["v4"] }

View File

@ -37,7 +37,7 @@ use matrix_sdk_common::events::{
room::message::MessageEventContent, room::message::MessageEventContent,
room_key::RoomKeyEventContent, room_key::RoomKeyEventContent,
room_key_request::RoomKeyRequestEventContent, room_key_request::RoomKeyRequestEventContent,
Algorithm, AnyRoomEventStub, AnyToDeviceEvent, EventJson, EventType, MessageEventStub, Algorithm, AnySyncRoomEvent, AnyToDeviceEvent, EventJson, EventType, SyncMessageEvent,
ToDeviceEvent, ToDeviceEvent,
}; };
use matrix_sdk_common::identifiers::{DeviceId, RoomId, UserId}; use matrix_sdk_common::identifiers::{DeviceId, RoomId, UserId};
@ -1135,9 +1135,9 @@ impl OlmMachine {
/// * `room_id` - The ID of the room where the event was sent to. /// * `room_id` - The ID of the room where the event was sent to.
pub async fn decrypt_room_event( pub async fn decrypt_room_event(
&mut self, &mut self,
event: &MessageEventStub<EncryptedEventContent>, event: &SyncMessageEvent<EncryptedEventContent>,
room_id: &RoomId, room_id: &RoomId,
) -> MegolmResult<EventJson<AnyRoomEventStub>> { ) -> MegolmResult<EventJson<AnySyncRoomEvent>> {
let content = match &event.content { let content = match &event.content {
EncryptedEventContent::MegolmV1AesSha2(c) => c, EncryptedEventContent::MegolmV1AesSha2(c) => c,
_ => return Err(EventError::UnsupportedAlgorithm.into()), _ => return Err(EventError::UnsupportedAlgorithm.into()),
@ -1244,8 +1244,8 @@ mod test {
encrypted::EncryptedEventContent, encrypted::EncryptedEventContent,
message::{MessageEventContent, TextMessageEventContent}, message::{MessageEventContent, TextMessageEventContent},
}, },
AnyMessageEventStub, AnyRoomEventStub, AnyToDeviceEvent, EventJson, EventType, AnySyncMessageEvent, AnySyncRoomEvent, AnyToDeviceEvent, EventJson, EventType,
MessageEventStub, ToDeviceEvent, UnsignedData, SyncMessageEvent, ToDeviceEvent, Unsigned,
}; };
use matrix_sdk_common::identifiers::{DeviceId, EventId, RoomId, UserId}; use matrix_sdk_common::identifiers::{DeviceId, EventId, RoomId, UserId};
use matrix_sdk_test::test_json; use matrix_sdk_test::test_json;
@ -1762,12 +1762,12 @@ mod test {
let encrypted_content = alice.encrypt(&room_id, content.clone()).await.unwrap(); let encrypted_content = alice.encrypt(&room_id, content.clone()).await.unwrap();
let event = MessageEventStub { let event = SyncMessageEvent {
event_id: EventId::try_from("$xxxxx:example.org").unwrap(), event_id: EventId::try_from("$xxxxx:example.org").unwrap(),
origin_server_ts: SystemTime::now(), origin_server_ts: SystemTime::now(),
sender: alice.user_id().clone(), sender: alice.user_id().clone(),
content: encrypted_content, content: encrypted_content,
unsigned: UnsignedData::default(), unsigned: Unsigned::default(),
}; };
let decrypted_event = bob let decrypted_event = bob
@ -1778,7 +1778,7 @@ mod test {
.unwrap(); .unwrap();
match decrypted_event { match decrypted_event {
AnyRoomEventStub::Message(AnyMessageEventStub::RoomMessage(MessageEventStub { AnySyncRoomEvent::Message(AnySyncMessageEvent::RoomMessage(SyncMessageEvent {
sender, sender,
content, content,
.. ..

View File

@ -6,8 +6,8 @@ use http::Response;
use matrix_sdk_common::api::r0::sync::sync_events::Response as SyncResponse; use matrix_sdk_common::api::r0::sync::sync_events::Response as SyncResponse;
use matrix_sdk_common::events::{ use matrix_sdk_common::events::{
presence::PresenceEvent, AnyBasicEvent, AnyEphemeralRoomEventStub, AnyRoomEventStub, presence::PresenceEvent, AnyBasicEvent, AnySyncEphemeralRoomEvent, AnySyncRoomEvent,
AnyStateEventStub, AnySyncStateEvent,
}; };
use matrix_sdk_common::identifiers::RoomId; use matrix_sdk_common::identifiers::RoomId;
use serde_json::Value as JsonValue; use serde_json::Value as JsonValue;
@ -80,17 +80,17 @@ pub enum EventsJson {
#[derive(Default)] #[derive(Default)]
pub struct EventBuilder { pub struct EventBuilder {
/// The events that determine the state of a `Room`. /// The events that determine the state of a `Room`.
joined_room_events: HashMap<RoomId, Vec<AnyRoomEventStub>>, joined_room_events: HashMap<RoomId, Vec<AnySyncRoomEvent>>,
/// The events that determine the state of a `Room`. /// The events that determine the state of a `Room`.
invited_room_events: HashMap<RoomId, Vec<AnyStateEventStub>>, invited_room_events: HashMap<RoomId, Vec<AnySyncStateEvent>>,
/// The events that determine the state of a `Room`. /// The events that determine the state of a `Room`.
left_room_events: HashMap<RoomId, Vec<AnyRoomEventStub>>, left_room_events: HashMap<RoomId, Vec<AnySyncRoomEvent>>,
/// The presence events that determine the presence state of a `RoomMember`. /// The presence events that determine the presence state of a `RoomMember`.
presence_events: Vec<PresenceEvent>, presence_events: Vec<PresenceEvent>,
/// The state events that determine the state of a `Room`. /// The state events that determine the state of a `Room`.
state_events: Vec<AnyStateEventStub>, state_events: Vec<AnySyncStateEvent>,
/// The ephemeral room events that determine the state of a `Room`. /// The ephemeral room events that determine the state of a `Room`.
ephemeral: Vec<AnyEphemeralRoomEventStub>, ephemeral: Vec<AnySyncEphemeralRoomEvent>,
/// The account data events that determine the state of a `Room`. /// The account data events that determine the state of a `Room`.
account_data: Vec<AnyBasicEvent>, account_data: Vec<AnyBasicEvent>,
/// Internal counter to enable the `prev_batch` and `next_batch` of each sync response to vary. /// Internal counter to enable the `prev_batch` and `next_batch` of each sync response to vary.
@ -110,7 +110,7 @@ impl EventBuilder {
_ => panic!("unknown ephemeral event {:?}", json), _ => panic!("unknown ephemeral event {:?}", json),
}; };
let event = serde_json::from_value::<AnyEphemeralRoomEventStub>(val.clone()).unwrap(); let event = serde_json::from_value::<AnySyncEphemeralRoomEvent>(val.clone()).unwrap();
self.ephemeral.push(event); self.ephemeral.push(event);
self self
} }
@ -136,7 +136,7 @@ impl EventBuilder {
_ => panic!("unknown room event json {:?}", json), _ => panic!("unknown room event json {:?}", json),
}; };
let event = serde_json::from_value::<AnyRoomEventStub>(val.clone()).unwrap(); let event = serde_json::from_value::<AnySyncRoomEvent>(val.clone()).unwrap();
self.add_joined_event( self.add_joined_event(
&RoomId::try_from("!SVkFJHzfwvuaIEawgC:localhost").unwrap(), &RoomId::try_from("!SVkFJHzfwvuaIEawgC:localhost").unwrap(),
@ -150,12 +150,12 @@ impl EventBuilder {
room_id: &RoomId, room_id: &RoomId,
event: serde_json::Value, event: serde_json::Value,
) -> &mut Self { ) -> &mut Self {
let event = serde_json::from_value::<AnyRoomEventStub>(event).unwrap(); let event = serde_json::from_value::<AnySyncRoomEvent>(event).unwrap();
self.add_joined_event(room_id, event); self.add_joined_event(room_id, event);
self self
} }
fn add_joined_event(&mut self, room_id: &RoomId, event: AnyRoomEventStub) { fn add_joined_event(&mut self, room_id: &RoomId, event: AnySyncRoomEvent) {
self.joined_room_events self.joined_room_events
.entry(room_id.clone()) .entry(room_id.clone())
.or_insert_with(Vec::new) .or_insert_with(Vec::new)
@ -167,7 +167,7 @@ impl EventBuilder {
room_id: &RoomId, room_id: &RoomId,
event: serde_json::Value, event: serde_json::Value,
) -> &mut Self { ) -> &mut Self {
let event = serde_json::from_value::<AnyStateEventStub>(event).unwrap(); let event = serde_json::from_value::<AnySyncStateEvent>(event).unwrap();
self.invited_room_events self.invited_room_events
.entry(room_id.clone()) .entry(room_id.clone())
.or_insert_with(Vec::new) .or_insert_with(Vec::new)
@ -180,7 +180,7 @@ impl EventBuilder {
room_id: &RoomId, room_id: &RoomId,
event: serde_json::Value, event: serde_json::Value,
) -> &mut Self { ) -> &mut Self {
let event = serde_json::from_value::<AnyRoomEventStub>(event).unwrap(); let event = serde_json::from_value::<AnySyncRoomEvent>(event).unwrap();
self.left_room_events self.left_room_events
.entry(room_id.clone()) .entry(room_id.clone())
.or_insert_with(Vec::new) .or_insert_with(Vec::new)
@ -199,7 +199,7 @@ impl EventBuilder {
_ => panic!("unknown state event {:?}", json), _ => panic!("unknown state event {:?}", json),
}; };
let event = serde_json::from_value::<AnyStateEventStub>(val.clone()).unwrap(); let event = serde_json::from_value::<AnySyncStateEvent>(val.clone()).unwrap();
self.state_events.push(event); self.state_events.push(event);
self self
} }