forked from lavina/lavina
make GetRooms a client command
This commit is contained in:
parent
ee10e3837a
commit
67f145ad2f
|
@ -96,9 +96,11 @@ impl PlayerConnection {
|
|||
self.player_handle.send(ActorCommand::TerminateConnection(self.connection_id)).await;
|
||||
}
|
||||
|
||||
/// Handled in [Player::get_rooms].
|
||||
pub async fn get_rooms(&self) -> Result<Vec<RoomInfo>> {
|
||||
let (promise, deferred) = oneshot();
|
||||
self.player_handle.send(ActorCommand::GetRooms(promise)).await;
|
||||
let cmd = ClientCommand::GetRooms { promise };
|
||||
self.player_handle.send(ActorCommand::ClientCommand(cmd, self.connection_id.clone())).await;
|
||||
Ok(deferred.await?)
|
||||
}
|
||||
}
|
||||
|
@ -143,8 +145,6 @@ enum ActorCommand {
|
|||
TerminateConnection(ConnectionId),
|
||||
/// Player-issued command.
|
||||
ClientCommand(ClientCommand, ConnectionId),
|
||||
/// Query - responds with a list of rooms the player is a member of.
|
||||
GetRooms(Promise<Vec<RoomInfo>>),
|
||||
/// Update which is sent from a room the player is member of.
|
||||
Update(Updates),
|
||||
Stop,
|
||||
|
@ -170,6 +170,9 @@ pub enum ClientCommand {
|
|||
new_topic: Str,
|
||||
promise: Promise<()>,
|
||||
},
|
||||
GetRooms {
|
||||
promise: Promise<Vec<RoomInfo>>,
|
||||
},
|
||||
}
|
||||
|
||||
pub enum JoinResult {
|
||||
|
@ -294,13 +297,6 @@ impl Player {
|
|||
ActorCommand::TerminateConnection(connection_id) => {
|
||||
self.terminate_connection(connection_id);
|
||||
}
|
||||
ActorCommand::GetRooms(promise) => {
|
||||
let mut response = vec![];
|
||||
for (_, handle) in &self.my_rooms {
|
||||
response.push(handle.get_room_info().await);
|
||||
}
|
||||
let _ = promise.send(response);
|
||||
}
|
||||
ActorCommand::Update(update) => self.handle_update(update).await,
|
||||
ActorCommand::ClientCommand(cmd, connection_id) => self.handle_cmd(cmd, connection_id).await,
|
||||
ActorCommand::Stop => break,
|
||||
|
@ -357,6 +353,10 @@ impl Player {
|
|||
self.change_topic(connection_id, room_id, new_topic).await;
|
||||
let _ = promise.send(());
|
||||
}
|
||||
ClientCommand::GetRooms { promise } => {
|
||||
let result = self.get_rooms().await;
|
||||
let _ = promise.send(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -421,6 +421,14 @@ impl Player {
|
|||
self.broadcast_update(update, connection_id).await;
|
||||
}
|
||||
|
||||
async fn get_rooms(&self) -> Vec<RoomInfo> {
|
||||
let mut response = vec![];
|
||||
for (_, handle) in &self.my_rooms {
|
||||
response.push(handle.get_room_info().await);
|
||||
}
|
||||
response
|
||||
}
|
||||
|
||||
/// Broadcasts an update to all connections except the one with the given id.
|
||||
///
|
||||
/// This is called after handling a client command.
|
||||
|
|
Loading…
Reference in New Issue