From 07053cfe2637b46c3b998aab91af466235df44ac Mon Sep 17 00:00:00 2001 From: Devin R Date: Thu, 23 Apr 2020 07:05:59 -0400 Subject: [PATCH] room/ev_emitter: add tombstone to emitted events --- src/base_client.rs | 14 ++++++++++++++ src/event_emitter/mod.rs | 6 ++++++ src/models/room.rs | 1 + src/request_builder.rs | 7 +++---- 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/base_client.rs b/src/base_client.rs index 335897b4..d79e94dc 100644 --- a/src/base_client.rs +++ b/src/base_client.rs @@ -637,6 +637,13 @@ impl Client { } } } + RoomEvent::RoomTombstone(tomb) => { + if let Some(ee) = &self.event_emitter { + if let Some(room) = self.get_room(&room_id) { + ee.on_room_tombstone(Arc::clone(&room), &tomb).await; + } + } + } _ => {} } } @@ -693,6 +700,13 @@ impl Client { } } } + StateEvent::RoomTombstone(tomb) => { + if let Some(ee) = &self.event_emitter { + if let Some(room) = self.get_room(&room_id) { + ee.on_room_tombstone(Arc::clone(&room), &tomb).await; + } + } + } _ => {} } } diff --git a/src/event_emitter/mod.rs b/src/event_emitter/mod.rs index 2d675521..b233b2da 100644 --- a/src/event_emitter/mod.rs +++ b/src/event_emitter/mod.rs @@ -29,6 +29,7 @@ use crate::events::{ name::NameEvent, power_levels::PowerLevelsEvent, redaction::RedactionEvent, + tombstone::TombstoneEvent, }, }; use crate::models::Room; @@ -98,6 +99,8 @@ pub trait EventEmitter: Send + Sync { async fn on_room_redaction(&self, _: Arc>, _: &RedactionEvent) {} /// Fires when `AsyncClient` receives a `RoomEvent::RoomPowerLevels` event. async fn on_room_power_levels(&self, _: Arc>, _: &PowerLevelsEvent) {} + /// Fires when `AsyncClient` receives a `RoomEvent::Tombstone` event. + async fn on_room_tombstone(&self, _: Arc>, _: &TombstoneEvent) {} // `RoomEvent`s from `IncomingState` /// Fires when `AsyncClient` receives a `StateEvent::RoomMember` event. @@ -167,6 +170,9 @@ mod test { async fn on_room_power_levels(&self, _: Arc>, _: &PowerLevelsEvent) { self.0.lock().await.push("power".to_string()) } + async fn on_room_tombstone(&self, _: Arc>, _: &TombstoneEvent) { + self.0.lock().await.push("tombstone".to_string()) + } async fn on_state_member(&self, _: Arc>, _: &MemberEvent) { self.0.lock().await.push("state member".to_string()) diff --git a/src/models/room.rs b/src/models/room.rs index 89af2e19..efe8c6c8 100644 --- a/src/models/room.rs +++ b/src/models/room.rs @@ -165,6 +165,7 @@ impl RoomName { .take(3) .map(|mem| mem.user_id.localpart().to_string()) .collect::>(); + // stabilize ordering names.sort(); names.join(", ") } else if heroes < invited_joined && invited + joined > one { diff --git a/src/request_builder.rs b/src/request_builder.rs index 8d61d05d..f00ed1a3 100644 --- a/src/request_builder.rs +++ b/src/request_builder.rs @@ -290,7 +290,7 @@ impl Into for MessagesRequestBuilder { #[cfg(test)] mod test { - use std::collections::{BTreeMap, HashMap}; + use std::collections::BTreeMap; use super::*; use crate::events::room::power_levels::NotificationPowerLevels; @@ -371,9 +371,8 @@ mod test { .from("t47429-4392820_219380_26003_2265".to_string()) .to("t4357353_219380_26003_2265".to_string()) .direction(Direction::Backward) - .limit(UInt::new(10).unwrap()); - // TODO this makes ruma error `Err(IntoHttp(IntoHttpError(Query(Custom("unsupported value")))))`?? - // .filter(RoomEventFilter::default()); + .limit(UInt::new(10).unwrap()) + .filter(RoomEventFilter::default()); let cli = AsyncClient::new(homeserver, Some(session)).unwrap(); assert!(cli.room_messages(builder).await.is_ok());