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]
entry: cargo fmt -- --check
- id: clippy
name: clippy
language: system
types: [file, rust]
entry: cargo clippy --all-targets --all
pass_filenames: false
# - id: clippy
# name: clippy
# language: system
# types: [file, rust]
# entry: cargo clippy --all-targets --all
# pass_filenames: false
- id: test
name: test
language: system
files: '\.rs$'
entry: cargo test --lib
pass_filenames: false
# - id: test
# name: test
# language: system
# files: '\.rs$'
# entry: cargo test --lib
# pass_filenames: false

View File

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

View File

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

View File

@ -5,7 +5,7 @@ use matrix_sdk::{
self,
events::{
room::message::{MessageEventContent, TextMessageEventContent},
MessageEventStub,
SyncMessageEvent,
},
Client, ClientConfig, EventEmitter, SyncRoom, SyncSettings,
};
@ -15,9 +15,9 @@ struct EventCallback;
#[async_trait]
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 MessageEventStub {
if let SyncMessageEvent {
content: MessageEventContent::Text(TextMessageEventContent { body: msg_body, .. }),
sender,
..

View File

@ -2,7 +2,7 @@ use matrix_sdk::{
api::r0::sync::sync_events::Response as SyncResponse,
events::{
room::message::{MessageEventContent, TextMessageEventContent},
AnyMessageEventStub, AnyRoomEventStub, MessageEventStub,
AnySyncMessageEvent, AnySyncRoomEvent, SyncMessageEvent,
},
identifiers::RoomId,
Client, ClientConfig, SyncSettings,
@ -17,9 +17,9 @@ impl WasmBot {
async fn on_room_message(
&self,
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, .. }),
..
} = event
@ -45,7 +45,7 @@ impl WasmBot {
for (room_id, room) in response.rooms.join {
for event in room.timeline.events {
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
}
}

View File

@ -38,8 +38,8 @@ use crate::session::Session;
use crate::state::{AllRooms, ClientState, StateStore};
use crate::EventEmitter;
use matrix_sdk_common::events::{
AnyBasicEvent, AnyEphemeralRoomEventStub, AnyMessageEventStub, AnyRoomEventStub,
AnyStateEventStub, AnyStrippedStateEventStub, EventJson,
AnyBasicEvent, AnyStrippedStateEvent, AnySyncEphemeralRoomEvent, AnySyncMessageEvent,
AnySyncRoomEvent, AnySyncStateEvent, EventJson,
};
#[cfg(feature = "encryption")]
@ -94,8 +94,8 @@ pub struct AdditionalUnsignedData {
/// [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>
fn hoist_room_event_prev_content(
event: &EventJson<AnyRoomEventStub>,
) -> Option<EventJson<AnyRoomEventStub>> {
event: &EventJson<AnySyncRoomEvent>,
) -> Option<EventJson<AnySyncRoomEvent>> {
let prev_content = serde_json::from_str::<AdditionalEventData>(event.json().get())
.map(|more_unsigned| more_unsigned.unsigned)
.map(|additional| additional.prev_content)
@ -105,7 +105,7 @@ fn hoist_room_event_prev_content(
let mut ev = event.deserialize().ok()?;
match &mut ev {
AnyRoomEventStub::State(AnyStateEventStub::RoomMember(ref mut member))
AnySyncRoomEvent::State(AnySyncStateEvent::RoomMember(ref mut member))
if member.prev_content.is_none() =>
{
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`.
fn hoist_state_event_prev_content(
event: &EventJson<AnyStateEventStub>,
) -> Option<EventJson<AnyStateEventStub>> {
event: &EventJson<AnySyncStateEvent>,
) -> Option<EventJson<AnySyncStateEvent>> {
let prev_content = serde_json::from_str::<AdditionalEventData>(event.json().get())
.map(|more_unsigned| more_unsigned.unsigned)
.map(|additional| additional.prev_content)
@ -132,7 +132,7 @@ fn hoist_state_event_prev_content(
let mut ev = event.deserialize().ok()?;
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()?);
Some(EventJson::from(ev))
}
@ -141,7 +141,7 @@ fn hoist_state_event_prev_content(
}
fn stripped_deserialize_prev_content(
event: &EventJson<AnyStrippedStateEventStub>,
event: &EventJson<AnyStrippedStateEvent>,
) -> Option<AdditionalUnsignedData> {
serde_json::from_str::<AdditionalEventData>(event.json().get())
.map(|more_unsigned| more_unsigned.unsigned)
@ -488,7 +488,7 @@ impl BaseClient {
*olm = Some(
OlmMachine::new_with_store(
session.user_id.to_owned(),
session.device_id.to_owned(),
session.device_id.as_str().into(),
store,
)
.await
@ -713,14 +713,14 @@ impl BaseClient {
pub async fn receive_joined_timeline_event(
&self,
room_id: &RoomId,
event: &mut EventJson<AnyRoomEventStub>,
event: &mut EventJson<AnySyncRoomEvent>,
) -> Result<bool> {
match event.deserialize() {
#[allow(unused_mut)]
Ok(mut e) => {
#[cfg(feature = "encryption")]
{
if let AnyRoomEventStub::Message(AnyMessageEventStub::RoomEncrypted(
if let AnySyncRoomEvent::Message(AnySyncMessageEvent::RoomEncrypted(
ref mut encrypted_event,
)) = e
{
@ -742,7 +742,7 @@ impl BaseClient {
let room_lock = self.get_or_create_joined_room(&room_id).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);
// The memberlist of the room changed, invalidate the group session
@ -774,12 +774,12 @@ impl BaseClient {
pub async fn receive_joined_state_event(
&self,
room_id: &RoomId,
event: &AnyStateEventStub,
event: &AnySyncStateEvent,
) -> Result<bool> {
let room_lock = self.get_or_create_joined_room(room_id).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);
// The memberlist of the room changed, invalidate the group session
@ -808,7 +808,7 @@ impl BaseClient {
pub async fn receive_invite_state_event(
&self,
room_id: &RoomId,
event: &AnyStrippedStateEventStub,
event: &AnyStrippedStateEvent,
) -> Result<bool> {
let room_lock = self.get_or_create_invited_room(room_id).await?;
let mut room = room_lock.write().await;
@ -828,7 +828,7 @@ impl BaseClient {
pub async fn receive_left_timeline_event(
&self,
room_id: &RoomId,
event: &EventJson<AnyRoomEventStub>,
event: &EventJson<AnySyncRoomEvent>,
) -> Result<bool> {
match event.deserialize() {
Ok(e) => {
@ -853,7 +853,7 @@ impl BaseClient {
pub async fn receive_left_state_event(
&self,
room_id: &RoomId,
event: &AnyStateEventStub,
event: &AnySyncStateEvent,
) -> Result<bool> {
let room_lock = self.get_or_create_left_room(room_id).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.
///
/// * `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 {
AnyEphemeralRoomEventStub::FullyRead(_) => {}
AnyEphemeralRoomEventStub::Receipt(_) => {}
AnyEphemeralRoomEventStub::Typing(_) => {}
AnySyncEphemeralRoomEvent::FullyRead(_) => {}
AnySyncEphemeralRoomEvent::Receipt(_) => {}
AnySyncEphemeralRoomEvent::Typing(_) => {}
_ => {}
};
false
@ -1197,7 +1197,7 @@ impl BaseClient {
if let Ok(mut e) = event.deserialize() {
// if the event is a m.room.member event the server will sometimes
// 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) {
let prev_content = match raw_content.prev_content {
Some(json) => json.deserialize().ok(),
@ -1280,7 +1280,7 @@ impl BaseClient {
pub async fn get_missing_sessions(
&self,
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;
match &mut *olm {
@ -1437,7 +1437,7 @@ impl BaseClient {
pub(crate) async fn emit_timeline_event(
&self,
room_id: &RoomId,
event: &AnyRoomEventStub,
event: &AnySyncRoomEvent,
room_state: RoomStateType,
) {
let lock = self.event_emitter.read().await;
@ -1472,54 +1472,54 @@ impl BaseClient {
};
match event {
AnyRoomEventStub::State(event) => match event {
AnyStateEventStub::RoomMember(e) => event_emitter.on_room_member(room, e).await,
AnyStateEventStub::RoomName(e) => event_emitter.on_room_name(room, e).await,
AnyStateEventStub::RoomCanonicalAlias(e) => {
AnySyncRoomEvent::State(event) => match event {
AnySyncStateEvent::RoomMember(e) => event_emitter.on_room_member(room, e).await,
AnySyncStateEvent::RoomName(e) => event_emitter.on_room_name(room, e).await,
AnySyncStateEvent::RoomCanonicalAlias(e) => {
event_emitter.on_room_canonical_alias(room, e).await
}
AnyStateEventStub::RoomAliases(e) => event_emitter.on_room_aliases(room, e).await,
AnyStateEventStub::RoomAvatar(e) => event_emitter.on_room_avatar(room, e).await,
AnyStateEventStub::RoomPowerLevels(e) => {
AnySyncStateEvent::RoomAliases(e) => event_emitter.on_room_aliases(room, e).await,
AnySyncStateEvent::RoomAvatar(e) => event_emitter.on_room_avatar(room, e).await,
AnySyncStateEvent::RoomPowerLevels(e) => {
event_emitter.on_room_power_levels(room, e).await
}
AnyStateEventStub::RoomTombstone(e) => {
AnySyncStateEvent::RoomTombstone(e) => {
event_emitter.on_room_tombstone(room, e).await
}
AnyStateEventStub::RoomJoinRules(e) => {
AnySyncStateEvent::RoomJoinRules(e) => {
event_emitter.on_room_join_rules(room, e).await
}
AnyStateEventStub::Custom(e) => {
AnySyncStateEvent::Custom(e) => {
event_emitter
.on_unrecognized_event(room, &CustomOrRawEvent::State(e))
.await
}
_ => {}
},
AnyRoomEventStub::Message(event) => match event {
AnyMessageEventStub::RoomMessage(e) => event_emitter.on_room_message(room, e).await,
AnyMessageEventStub::RoomMessageFeedback(e) => {
AnySyncRoomEvent::Message(event) => match event {
AnySyncMessageEvent::RoomMessage(e) => event_emitter.on_room_message(room, e).await,
AnySyncMessageEvent::RoomMessageFeedback(e) => {
event_emitter.on_room_message_feedback(room, e).await
}
AnyMessageEventStub::RoomRedaction(e) => {
AnySyncMessageEvent::RoomRedaction(e) => {
event_emitter.on_room_redaction(room, e).await
}
AnyMessageEventStub::Custom(e) => {
AnySyncMessageEvent::Custom(e) => {
event_emitter
.on_unrecognized_event(room, &CustomOrRawEvent::Message(e))
.await
}
_ => {}
},
AnyRoomEventStub::RedactedState(_event) => {}
AnyRoomEventStub::RedactedMessage(_event) => {}
AnySyncRoomEvent::RedactedState(_event) => {}
AnySyncRoomEvent::RedactedMessage(_event) => {}
}
}
pub(crate) async fn emit_state_event(
&self,
room_id: &RoomId,
event: &AnyStateEventStub,
event: &AnySyncStateEvent,
room_state: RoomStateType,
) {
let lock = self.event_emitter.read().await;
@ -1554,32 +1554,32 @@ impl BaseClient {
};
match event {
AnyStateEventStub::RoomMember(member) => {
AnySyncStateEvent::RoomMember(member) => {
event_emitter.on_state_member(room, &member).await
}
AnyStateEventStub::RoomName(name) => event_emitter.on_state_name(room, &name).await,
AnyStateEventStub::RoomCanonicalAlias(canonical) => {
AnySyncStateEvent::RoomName(name) => event_emitter.on_state_name(room, &name).await,
AnySyncStateEvent::RoomCanonicalAlias(canonical) => {
event_emitter
.on_state_canonical_alias(room, &canonical)
.await
}
AnyStateEventStub::RoomAliases(aliases) => {
AnySyncStateEvent::RoomAliases(aliases) => {
event_emitter.on_state_aliases(room, &aliases).await
}
AnyStateEventStub::RoomAvatar(avatar) => {
AnySyncStateEvent::RoomAvatar(avatar) => {
event_emitter.on_state_avatar(room, &avatar).await
}
AnyStateEventStub::RoomPowerLevels(power) => {
AnySyncStateEvent::RoomPowerLevels(power) => {
event_emitter.on_state_power_levels(room, &power).await
}
AnyStateEventStub::RoomJoinRules(rules) => {
AnySyncStateEvent::RoomJoinRules(rules) => {
event_emitter.on_state_join_rules(room, &rules).await
}
AnyStateEventStub::RoomTombstone(tomb) => {
AnySyncStateEvent::RoomTombstone(tomb) => {
// TODO make `on_state_tombstone` method
event_emitter.on_room_tombstone(room, &tomb).await
}
AnyStateEventStub::Custom(custom) => {
AnySyncStateEvent::Custom(custom) => {
event_emitter
.on_unrecognized_event(room, &CustomOrRawEvent::State(custom))
.await
@ -1591,7 +1591,7 @@ impl BaseClient {
pub(crate) async fn emit_stripped_state_event(
&self,
room_id: &RoomId,
event: &AnyStrippedStateEventStub,
event: &AnyStrippedStateEvent,
prev_content: Option<MemberEventContent>,
room_state: RoomStateType,
) {
@ -1627,33 +1627,33 @@ impl BaseClient {
};
match event {
AnyStrippedStateEventStub::RoomMember(member) => {
AnyStrippedStateEvent::RoomMember(member) => {
event_emitter
.on_stripped_state_member(room, &member, prev_content)
.await
}
AnyStrippedStateEventStub::RoomName(name) => {
AnyStrippedStateEvent::RoomName(name) => {
event_emitter.on_stripped_state_name(room, &name).await
}
AnyStrippedStateEventStub::RoomCanonicalAlias(canonical) => {
AnyStrippedStateEvent::RoomCanonicalAlias(canonical) => {
event_emitter
.on_stripped_state_canonical_alias(room, &canonical)
.await
}
AnyStrippedStateEventStub::RoomAliases(aliases) => {
AnyStrippedStateEvent::RoomAliases(aliases) => {
event_emitter
.on_stripped_state_aliases(room, &aliases)
.await
}
AnyStrippedStateEventStub::RoomAvatar(avatar) => {
AnyStrippedStateEvent::RoomAvatar(avatar) => {
event_emitter.on_stripped_state_avatar(room, &avatar).await
}
AnyStrippedStateEventStub::RoomPowerLevels(power) => {
AnyStrippedStateEvent::RoomPowerLevels(power) => {
event_emitter
.on_stripped_state_power_levels(room, &power)
.await
}
AnyStrippedStateEventStub::RoomJoinRules(rules) => {
AnyStrippedStateEvent::RoomJoinRules(rules) => {
event_emitter
.on_stripped_state_join_rules(room, &rules)
.await
@ -1718,7 +1718,7 @@ impl BaseClient {
pub(crate) async fn emit_ephemeral_event(
&self,
room_id: &RoomId,
event: &AnyEphemeralRoomEventStub,
event: &AnySyncEphemeralRoomEvent,
room_state: RoomStateType,
) {
let lock = self.event_emitter.read().await;
@ -1753,13 +1753,13 @@ impl BaseClient {
};
match event {
AnyEphemeralRoomEventStub::FullyRead(full_read) => {
AnySyncEphemeralRoomEvent::FullyRead(full_read) => {
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
}
AnyEphemeralRoomEventStub::Receipt(receipt) => {
AnySyncEphemeralRoomEvent::Receipt(receipt) => {
event_emitter.on_non_room_receipt(room, &receipt).await
}
_ => {}
@ -1838,18 +1838,20 @@ impl BaseClient {
#[cfg(test)]
mod test {
use crate::identifiers::{EventId, RoomId, UserId};
use crate::{BaseClient, BaseClientConfig, Session};
use matrix_sdk_common::events::{AnyRoomEventStub, EventJson};
use crate::identifiers::{RoomId, UserId};
#[cfg(feature = "messages")]
use crate::{
events::{AnySyncRoomEvent, EventJson},
identifiers::EventId,
BaseClientConfig, JsonStore,
};
use crate::{BaseClient, Session};
use matrix_sdk_common_macros::async_trait;
use matrix_sdk_test::{async_test, test_json, EventBuilder, EventsJson};
use serde_json::json;
use std::convert::TryFrom;
use tempfile::tempdir;
#[cfg(feature = "messages")]
use crate::JsonStore;
#[cfg(target_arch = "wasm32")]
use wasm_bindgen_test::*;
@ -2008,7 +2010,7 @@ mod test {
use crate::{EventEmitter, SyncRoom};
use matrix_sdk_common::events::{
room::member::{MemberEventContent, MembershipChange},
StateEventStub,
SyncStateEvent,
};
use matrix_sdk_common::locks::RwLock;
use std::sync::{
@ -2022,7 +2024,7 @@ mod test {
async fn on_room_member(
&self,
room: SyncRoom,
event: &StateEventStub<MemberEventContent>,
event: &SyncStateEvent<MemberEventContent>,
) {
if let SyncRoom::Joined(_) = room {
if let MembershipChange::Joined = event.membership_change() {
@ -2395,7 +2397,7 @@ mod test {
"type": "m.room.redaction",
"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
.receive_joined_timeline_event(&room_id, &mut event)
.await
@ -2404,8 +2406,8 @@ mod test {
// check that the message has actually been redacted
for room in client.joined_rooms().read().await.values() {
let queue = &room.read().await.messages;
if let crate::models::FullOrRedactedEvent::Redacted(
crate::events::AnyRedactedMessageEventStub::RoomMessage(event),
if let crate::events::AnyPossiblyRedactedSyncMessageEvent::Redacted(
crate::events::AnyRedactedSyncMessageEvent::RoomMessage(event),
) = &queue.msgs[0].deref()
{
// this is the id from the message event in the sync response
@ -2432,8 +2434,8 @@ mod test {
// properly
for room in client.joined_rooms().read().await.values() {
let queue = &room.read().await.messages;
if let crate::models::FullOrRedactedEvent::Redacted(
crate::events::AnyRedactedMessageEventStub::RoomMessage(event),
if let crate::events::AnyPossiblyRedactedSyncMessageEvent::Redacted(
crate::events::AnyRedactedSyncMessageEvent::RoomMessage(event),
) = &queue.msgs[0].deref()
{
// 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},
name::NameEventContent,
power_levels::PowerLevelsEventContent,
redaction::RedactionEventStub,
redaction::SyncRedactionEvent,
tombstone::TombstoneEventContent,
},
typing::TypingEventContent,
BasicEvent, EphemeralRoomEvent, MessageEventStub, StateEventStub, StrippedStateEventStub,
BasicEvent, EphemeralRoomEvent, StrippedStateEvent, SyncMessageEvent, SyncStateEvent,
};
use crate::{Room, RoomState};
use matrix_sdk_common_macros::async_trait;
@ -55,11 +55,11 @@ pub enum CustomOrRawEvent<'c> {
/// A custom basic event.
EphemeralRoom(&'c EphemeralRoomEvent<CustomEventContent>),
/// A custom room event.
Message(&'c MessageEventStub<CustomEventContent>),
Message(&'c SyncMessageEvent<CustomEventContent>),
/// A custom state event.
State(&'c StateEventStub<CustomEventContent>),
State(&'c SyncStateEvent<CustomEventContent>),
/// 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.
@ -74,7 +74,7 @@ pub enum CustomOrRawEvent<'c> {
/// # self,
/// # events::{
/// # room::message::{MessageEventContent, TextMessageEventContent},
/// # MessageEventStub
/// # SyncMessageEvent
/// # },
/// # EventEmitter, SyncRoom
/// # };
@ -85,9 +85,9 @@ pub enum CustomOrRawEvent<'c> {
///
/// #[async_trait]
/// 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 MessageEventStub {
/// if let SyncMessageEvent {
/// content: MessageEventContent::Text(TextMessageEventContent { body: msg_body, .. }),
/// sender,
/// ..
@ -112,114 +112,109 @@ pub enum CustomOrRawEvent<'c> {
pub trait EventEmitter: Send + Sync {
// ROOM EVENTS from `IncomingTimeline`
/// 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.
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.
async fn on_room_canonical_alias(
&self,
_: SyncRoom,
_: &StateEventStub<CanonicalAliasEventContent>,
_: &SyncStateEvent<CanonicalAliasEventContent>,
) {
}
/// 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.
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.
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.
async fn on_room_message_feedback(
&self,
_: SyncRoom,
_: &MessageEventStub<FeedbackEventContent>,
_: &SyncMessageEvent<FeedbackEventContent>,
) {
}
/// 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.
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.
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.
async fn on_room_tombstone(&self, _: SyncRoom, _: &StateEventStub<TombstoneEventContent>) {}
async fn on_room_tombstone(&self, _: SyncRoom, _: &SyncStateEvent<TombstoneEventContent>) {}
// `RoomEvent`s from `IncomingState`
/// 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.
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.
async fn on_state_canonical_alias(
&self,
_: SyncRoom,
_: &StateEventStub<CanonicalAliasEventContent>,
_: &SyncStateEvent<CanonicalAliasEventContent>,
) {
}
/// 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.
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.
async fn on_state_power_levels(
&self,
_: SyncRoom,
_: &StateEventStub<PowerLevelsEventContent>,
_: &SyncStateEvent<PowerLevelsEventContent>,
) {
}
/// 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
/// Fires when `Client` receives a `AnyStrippedStateEvent::StrippedRoomMember` event.
async fn on_stripped_state_member(
&self,
_: SyncRoom,
_: &StrippedStateEventStub<MemberEventContent>,
_: &StrippedStateEvent<MemberEventContent>,
_: Option<MemberEventContent>,
) {
}
/// Fires when `Client` receives a `AnyStrippedStateEvent::StrippedRoomName` event.
async fn on_stripped_state_name(
&self,
_: SyncRoom,
_: &StrippedStateEventStub<NameEventContent>,
) {
}
async fn on_stripped_state_name(&self, _: SyncRoom, _: &StrippedStateEvent<NameEventContent>) {}
/// Fires when `Client` receives a `AnyStrippedStateEvent::StrippedRoomCanonicalAlias` event.
async fn on_stripped_state_canonical_alias(
&self,
_: SyncRoom,
_: &StrippedStateEventStub<CanonicalAliasEventContent>,
_: &StrippedStateEvent<CanonicalAliasEventContent>,
) {
}
/// Fires when `Client` receives a `AnyStrippedStateEvent::StrippedRoomAliases` event.
async fn on_stripped_state_aliases(
&self,
_: SyncRoom,
_: &StrippedStateEventStub<AliasesEventContent>,
_: &StrippedStateEvent<AliasesEventContent>,
) {
}
/// Fires when `Client` receives a `AnyStrippedStateEvent::StrippedRoomAvatar` event.
async fn on_stripped_state_avatar(
&self,
_: SyncRoom,
_: &StrippedStateEventStub<AvatarEventContent>,
_: &StrippedStateEvent<AvatarEventContent>,
) {
}
/// Fires when `Client` receives a `AnyStrippedStateEvent::StrippedRoomPowerLevels` event.
async fn on_stripped_state_power_levels(
&self,
_: SyncRoom,
_: &StrippedStateEventStub<PowerLevelsEventContent>,
_: &StrippedStateEvent<PowerLevelsEventContent>,
) {
}
/// Fires when `Client` receives a `AnyStrippedStateEvent::StrippedRoomJoinRules` event.
async fn on_stripped_state_join_rules(
&self,
_: SyncRoom,
_: &StrippedStateEventStub<JoinRulesEventContent>,
_: &StrippedStateEvent<JoinRulesEventContent>,
) {
}
@ -276,79 +271,79 @@ mod test {
#[async_trait]
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())
}
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())
}
async fn on_room_canonical_alias(
&self,
_: SyncRoom,
_: &StateEventStub<CanonicalAliasEventContent>,
_: &SyncStateEvent<CanonicalAliasEventContent>,
) {
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())
}
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())
}
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())
}
async fn on_room_message_feedback(
&self,
_: SyncRoom,
_: &MessageEventStub<FeedbackEventContent>,
_: &SyncMessageEvent<FeedbackEventContent>,
) {
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())
}
async fn on_room_power_levels(
&self,
_: SyncRoom,
_: &StateEventStub<PowerLevelsEventContent>,
_: &SyncStateEvent<PowerLevelsEventContent>,
) {
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())
}
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())
}
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())
}
async fn on_state_canonical_alias(
&self,
_: SyncRoom,
_: &StateEventStub<CanonicalAliasEventContent>,
_: &SyncStateEvent<CanonicalAliasEventContent>,
) {
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())
}
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())
}
async fn on_state_power_levels(
&self,
_: SyncRoom,
_: &StateEventStub<PowerLevelsEventContent>,
_: &SyncStateEvent<PowerLevelsEventContent>,
) {
self.0.lock().await.push("state power".to_string())
}
async fn on_state_join_rules(
&self,
_: SyncRoom,
_: &StateEventStub<JoinRulesEventContent>,
_: &SyncStateEvent<JoinRulesEventContent>,
) {
self.0.lock().await.push("state rules".to_string())
}
@ -358,7 +353,7 @@ mod test {
async fn on_stripped_state_member(
&self,
_: SyncRoom,
_: &StrippedStateEventStub<MemberEventContent>,
_: &StrippedStateEvent<MemberEventContent>,
_: Option<MemberEventContent>,
) {
self.0
@ -370,7 +365,7 @@ mod test {
async fn on_stripped_state_name(
&self,
_: SyncRoom,
_: &StrippedStateEventStub<NameEventContent>,
_: &StrippedStateEvent<NameEventContent>,
) {
self.0.lock().await.push("stripped state name".to_string())
}
@ -378,7 +373,7 @@ mod test {
async fn on_stripped_state_canonical_alias(
&self,
_: SyncRoom,
_: &StrippedStateEventStub<CanonicalAliasEventContent>,
_: &StrippedStateEvent<CanonicalAliasEventContent>,
) {
self.0
.lock()
@ -389,7 +384,7 @@ mod test {
async fn on_stripped_state_aliases(
&self,
_: SyncRoom,
_: &StrippedStateEventStub<AliasesEventContent>,
_: &StrippedStateEvent<AliasesEventContent>,
) {
self.0
.lock()
@ -400,7 +395,7 @@ mod test {
async fn on_stripped_state_avatar(
&self,
_: SyncRoom,
_: &StrippedStateEventStub<AvatarEventContent>,
_: &StrippedStateEvent<AvatarEventContent>,
) {
self.0
.lock()
@ -411,7 +406,7 @@ mod test {
async fn on_stripped_state_power_levels(
&self,
_: SyncRoom,
_: &StrippedStateEventStub<PowerLevelsEventContent>,
_: &StrippedStateEvent<PowerLevelsEventContent>,
) {
self.0.lock().await.push("stripped state power".to_string())
}
@ -419,7 +414,7 @@ mod test {
async fn on_stripped_state_join_rules(
&self,
_: SyncRoom,
_: &StrippedStateEventStub<JoinRulesEventContent>,
_: &StrippedStateEvent<JoinRulesEventContent>,
) {
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 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.
///
@ -21,9 +21,9 @@ use crate::events::{AnyMessageEventStub, AnyRedactedMessageEventStub};
#[derive(Clone, Debug, Deserialize, Serialize)]
pub enum FullOrRedactedEvent {
/// A non-redacted event.
Full(AnyMessageEventStub),
Full(AnySyncMessageEvent),
/// An event that has been redacted.
Redacted(AnyRedactedMessageEventStub),
Redacted(AnyRedactedSyncMessageEvent),
}
impl FullOrRedactedEvent {
@ -228,7 +228,7 @@ mod test {
let json: &serde_json::Value = &test_json::MESSAGE_TEXT;
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();
@ -275,7 +275,7 @@ mod test {
let json: &serde_json::Value = &test_json::MESSAGE_TEXT;
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();

View File

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

View File

@ -15,12 +15,15 @@
use std::convert::TryFrom;
use crate::events::presence::{PresenceEvent, PresenceState};
use crate::events::room::member::MemberEventContent;
use crate::events::StateEventStub;
use crate::identifiers::{RoomId, UserId};
use crate::js_int::{Int, UInt};
use matrix_sdk_common::{
events::{
presence::{PresenceEvent, PresenceState},
room::member::MemberEventContent,
SyncStateEvent,
},
identifiers::{RoomId, UserId},
js_int::{Int, UInt},
};
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.
@ -64,7 +67,7 @@ pub struct RoomMember {
//
// Needs design.
/// 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.
pub presence_events: Vec<PresenceEvent>,
}
@ -83,7 +86,7 @@ impl PartialEq for RoomMember {
}
impl RoomMember {
pub fn new(event: &StateEventStub<MemberEventContent>, room_id: &RoomId) -> Self {
pub fn new(event: &SyncStateEvent<MemberEventContent>, room_id: &RoomId) -> Self {
Self {
name: event.state_key.clone(),
room_id: room_id.clone(),

View File

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

View File

@ -37,7 +37,7 @@ use matrix_sdk_common::events::{
room::message::MessageEventContent,
room_key::RoomKeyEventContent,
room_key_request::RoomKeyRequestEventContent,
Algorithm, AnyRoomEventStub, AnyToDeviceEvent, EventJson, EventType, MessageEventStub,
Algorithm, AnySyncRoomEvent, AnyToDeviceEvent, EventJson, EventType, SyncMessageEvent,
ToDeviceEvent,
};
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.
pub async fn decrypt_room_event(
&mut self,
event: &MessageEventStub<EncryptedEventContent>,
event: &SyncMessageEvent<EncryptedEventContent>,
room_id: &RoomId,
) -> MegolmResult<EventJson<AnyRoomEventStub>> {
) -> MegolmResult<EventJson<AnySyncRoomEvent>> {
let content = match &event.content {
EncryptedEventContent::MegolmV1AesSha2(c) => c,
_ => return Err(EventError::UnsupportedAlgorithm.into()),
@ -1244,8 +1244,8 @@ mod test {
encrypted::EncryptedEventContent,
message::{MessageEventContent, TextMessageEventContent},
},
AnyMessageEventStub, AnyRoomEventStub, AnyToDeviceEvent, EventJson, EventType,
MessageEventStub, ToDeviceEvent, UnsignedData,
AnySyncMessageEvent, AnySyncRoomEvent, AnyToDeviceEvent, EventJson, EventType,
SyncMessageEvent, ToDeviceEvent, Unsigned,
};
use matrix_sdk_common::identifiers::{DeviceId, EventId, RoomId, UserId};
use matrix_sdk_test::test_json;
@ -1762,12 +1762,12 @@ mod test {
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(),
origin_server_ts: SystemTime::now(),
sender: alice.user_id().clone(),
content: encrypted_content,
unsigned: UnsignedData::default(),
unsigned: Unsigned::default(),
};
let decrypted_event = bob
@ -1778,7 +1778,7 @@ mod test {
.unwrap();
match decrypted_event {
AnyRoomEventStub::Message(AnyMessageEventStub::RoomMessage(MessageEventStub {
AnySyncRoomEvent::Message(AnySyncMessageEvent::RoomMessage(SyncMessageEvent {
sender,
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::events::{
presence::PresenceEvent, AnyBasicEvent, AnyEphemeralRoomEventStub, AnyRoomEventStub,
AnyStateEventStub,
presence::PresenceEvent, AnyBasicEvent, AnySyncEphemeralRoomEvent, AnySyncRoomEvent,
AnySyncStateEvent,
};
use matrix_sdk_common::identifiers::RoomId;
use serde_json::Value as JsonValue;
@ -80,17 +80,17 @@ pub enum EventsJson {
#[derive(Default)]
pub struct EventBuilder {
/// 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`.
invited_room_events: HashMap<RoomId, Vec<AnyStateEventStub>>,
invited_room_events: HashMap<RoomId, Vec<AnySyncStateEvent>>,
/// 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`.
presence_events: Vec<PresenceEvent>,
/// 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`.
ephemeral: Vec<AnyEphemeralRoomEventStub>,
ephemeral: Vec<AnySyncEphemeralRoomEvent>,
/// The account data events that determine the state of a `Room`.
account_data: Vec<AnyBasicEvent>,
/// 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),
};
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
}
@ -136,7 +136,7 @@ impl EventBuilder {
_ => 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(
&RoomId::try_from("!SVkFJHzfwvuaIEawgC:localhost").unwrap(),
@ -150,12 +150,12 @@ impl EventBuilder {
room_id: &RoomId,
event: serde_json::Value,
) -> &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
}
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
.entry(room_id.clone())
.or_insert_with(Vec::new)
@ -167,7 +167,7 @@ impl EventBuilder {
room_id: &RoomId,
event: serde_json::Value,
) -> &mut Self {
let event = serde_json::from_value::<AnyStateEventStub>(event).unwrap();
let event = serde_json::from_value::<AnySyncStateEvent>(event).unwrap();
self.invited_room_events
.entry(room_id.clone())
.or_insert_with(Vec::new)
@ -180,7 +180,7 @@ impl EventBuilder {
room_id: &RoomId,
event: serde_json::Value,
) -> &mut Self {
let event = serde_json::from_value::<AnyRoomEventStub>(event).unwrap();
let event = serde_json::from_value::<AnySyncRoomEvent>(event).unwrap();
self.left_room_events
.entry(room_id.clone())
.or_insert_with(Vec::new)
@ -199,7 +199,7 @@ impl EventBuilder {
_ => 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
}