room: receive AnyStrippedStateEvent and handle within Room struct

master
Devin R 2020-05-06 20:46:06 -04:00
parent 7b2ffd1f25
commit fa4a99504e
1 changed files with 16 additions and 4 deletions

View File

@ -30,7 +30,7 @@ use crate::events::room::{
power_levels::{NotificationPowerLevels, PowerLevelsEvent, PowerLevelsEventContent}, power_levels::{NotificationPowerLevels, PowerLevelsEvent, PowerLevelsEventContent},
tombstone::TombstoneEvent, tombstone::TombstoneEvent,
}; };
use crate::events::stripped::AnyStrippedStateEvent; use crate::events::stripped::{AnyStrippedStateEvent, StrippedRoomName};
use crate::events::EventType; use crate::events::EventType;
use crate::identifiers::{RoomAliasId, RoomId, UserId}; use crate::identifiers::{RoomAliasId, RoomId, UserId};
@ -352,6 +352,16 @@ 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_stripped_room_name(&mut self, event: &StrippedRoomName) -> bool {
match event.content.name() {
Some(name) => self.set_room_name(name),
_ => false,
}
}
/// 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.
@ -438,9 +448,11 @@ impl Room {
/// ///
/// * `event` - The `AnyStrippedStateEvent` sent by the server for invited but not /// * `event` - The `AnyStrippedStateEvent` sent by the server for invited but not
/// joined rooms. /// joined rooms.
pub fn receive_stripped_state_event(&mut self, _event: &AnyStrippedStateEvent) -> bool { pub fn receive_stripped_state_event(&mut self, event: &AnyStrippedStateEvent) -> bool {
// TODO do we want to do anything with the events from an invited room? match event {
true AnyStrippedStateEvent::RoomName(n) => self.handle_stripped_room_name(n),
_ => false,
}
} }
/// Receive a presence event from an `IncomingResponse` and updates the client state. /// Receive a presence event from an `IncomingResponse` and updates the client state.