room/ev_emitter: add tombstone to emitted events

master
Devin R 2020-04-23 07:05:59 -04:00
parent ef4d69b0ac
commit 07053cfe26
4 changed files with 24 additions and 4 deletions

View File

@ -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;
}
}
}
_ => {} _ => {}
} }
} }

View File

@ -29,6 +29,7 @@ use crate::events::{
name::NameEvent, name::NameEvent,
power_levels::PowerLevelsEvent, power_levels::PowerLevelsEvent,
redaction::RedactionEvent, redaction::RedactionEvent,
tombstone::TombstoneEvent,
}, },
}; };
use crate::models::Room; use crate::models::Room;
@ -98,6 +99,8 @@ pub trait EventEmitter: Send + Sync {
async fn on_room_redaction(&self, _: Arc<RwLock<Room>>, _: &RedactionEvent) {} async fn on_room_redaction(&self, _: Arc<RwLock<Room>>, _: &RedactionEvent) {}
/// Fires when `AsyncClient` receives a `RoomEvent::RoomPowerLevels` event. /// Fires when `AsyncClient` receives a `RoomEvent::RoomPowerLevels` event.
async fn on_room_power_levels(&self, _: Arc<RwLock<Room>>, _: &PowerLevelsEvent) {} async fn on_room_power_levels(&self, _: Arc<RwLock<Room>>, _: &PowerLevelsEvent) {}
/// Fires when `AsyncClient` receives a `RoomEvent::Tombstone` event.
async fn on_room_tombstone(&self, _: Arc<RwLock<Room>>, _: &TombstoneEvent) {}
// `RoomEvent`s from `IncomingState` // `RoomEvent`s from `IncomingState`
/// Fires when `AsyncClient` receives a `StateEvent::RoomMember` event. /// Fires when `AsyncClient` receives a `StateEvent::RoomMember` event.
@ -167,6 +170,9 @@ mod test {
async fn on_room_power_levels(&self, _: Arc<RwLock<Room>>, _: &PowerLevelsEvent) { async fn on_room_power_levels(&self, _: Arc<RwLock<Room>>, _: &PowerLevelsEvent) {
self.0.lock().await.push("power".to_string()) self.0.lock().await.push("power".to_string())
} }
async fn on_room_tombstone(&self, _: Arc<RwLock<Room>>, _: &TombstoneEvent) {
self.0.lock().await.push("tombstone".to_string())
}
async fn on_state_member(&self, _: Arc<RwLock<Room>>, _: &MemberEvent) { async fn on_state_member(&self, _: Arc<RwLock<Room>>, _: &MemberEvent) {
self.0.lock().await.push("state member".to_string()) self.0.lock().await.push("state member".to_string())

View File

@ -165,6 +165,7 @@ impl RoomName {
.take(3) .take(3)
.map(|mem| mem.user_id.localpart().to_string()) .map(|mem| mem.user_id.localpart().to_string())
.collect::<Vec<String>>(); .collect::<Vec<String>>();
// stabilize ordering
names.sort(); names.sort();
names.join(", ") names.join(", ")
} else if heroes < invited_joined && invited + joined > one { } else if heroes < invited_joined && invited + joined > one {

View File

@ -290,7 +290,7 @@ impl Into<get_message_events::Request> for MessagesRequestBuilder {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use std::collections::{BTreeMap, HashMap}; use std::collections::BTreeMap;
use super::*; use super::*;
use crate::events::room::power_levels::NotificationPowerLevels; use crate::events::room::power_levels::NotificationPowerLevels;
@ -371,9 +371,8 @@ mod test {
.from("t47429-4392820_219380_26003_2265".to_string()) .from("t47429-4392820_219380_26003_2265".to_string())
.to("t4357353_219380_26003_2265".to_string()) .to("t4357353_219380_26003_2265".to_string())
.direction(Direction::Backward) .direction(Direction::Backward)
.limit(UInt::new(10).unwrap()); .limit(UInt::new(10).unwrap())
// TODO this makes ruma error `Err(IntoHttp(IntoHttpError(Query(Custom("unsupported value")))))`?? .filter(RoomEventFilter::default());
// .filter(RoomEventFilter::default());
let cli = AsyncClient::new(homeserver, Some(session)).unwrap(); let cli = AsyncClient::new(homeserver, Some(session)).unwrap();
assert!(cli.room_messages(builder).await.is_ok()); assert!(cli.room_messages(builder).await.is_ok());