use anyhow::Result;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Registration {
pub id: String,
pub url: String,
pub as_token: String,
pub hs_token: String,
pub sender_localpart: String,
pub rate_limited: bool,
pub protocols: Vec<String>,
pub namespaces: Namespaces,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Namespaces {
pub users: Vec<Namespace>,
pub aliases: Vec<Namespace>,
pub rooms: Vec<Namespace>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Namespace {
pub exclusive: bool,
pub regex: String,
}
impl Registration {
pub fn from_config(config: &crate::config::BridgeConfig) -> Self {
Self {
id: "teams".to_string(),
url: format!("http://{}:{}", config.bind_address, config.port),
as_token: config.appservice_token.clone(),
hs_token: config.homeserver_token.clone(),
sender_localpart: "_teams_".to_string(),
rate_limited: false,
protocols: vec!["msteams".to_string()],
namespaces: Namespaces {
users: vec![Namespace {
exclusive: true,
regex: "@_teams_.*:".to_string() + &config.domain,
}],
aliases: vec![Namespace {
exclusive: true,
regex: "#_teams_.*:".to_string() + &config.domain,
}],
rooms: vec![],
},
}
}
}