Support domain in config file

This commit is contained in:
Joscha 2024-01-01 19:35:46 +01:00
parent c094f526a5
commit 5995d06cad
3 changed files with 41 additions and 36 deletions

View file

@ -35,7 +35,13 @@ pub struct EuphRoom {
}
#[derive(Debug, Default, Deserialize, Document)]
pub struct Euph {
pub struct EuphServer {
#[document(metavar = "room")]
pub rooms: HashMap<String, EuphRoom>,
}
#[derive(Debug, Default, Deserialize, Document)]
pub struct Euph {
#[document(metavar = "domain")]
pub servers: HashMap<String, EuphServer>,
}

View file

@ -107,7 +107,12 @@ impl Config {
})
}
pub fn euph_room(&self, name: &str) -> EuphRoom {
self.euph.rooms.get(name).cloned().unwrap_or_default()
pub fn euph_room(&self, domain: &str, name: &str) -> EuphRoom {
if let Some(server) = self.euph.servers.get(domain) {
if let Some(room) = server.rooms.get(name) {
return room.clone();
}
}
EuphRoom::default()
}
}