improve appservice::Data interface encap
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
30b5ad3870
commit
0f1432f448
4 changed files with 20 additions and 18 deletions
|
@ -124,7 +124,7 @@ impl Service {
|
|||
let mut registration_info = BTreeMap::new();
|
||||
let db = Data::new(db);
|
||||
// Inserting registrations into cache
|
||||
for appservice in db.all()? {
|
||||
for appservice in iter_ids(&db)? {
|
||||
registration_info.insert(
|
||||
appservice.0,
|
||||
appservice
|
||||
|
@ -140,6 +140,8 @@ impl Service {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn all(&self) -> Result<Vec<(String, Registration)>> { iter_ids(&self.db) }
|
||||
|
||||
/// Registers an appservice and returns the ID to the caller
|
||||
pub async fn register_appservice(&self, yaml: Registration) -> Result<String> {
|
||||
//TODO: Check for collisions between exclusive appservice namespaces
|
||||
|
@ -231,3 +233,16 @@ impl Service {
|
|||
self.registration_info.read()
|
||||
}
|
||||
}
|
||||
|
||||
fn iter_ids(db: &Data) -> Result<Vec<(String, Registration)>> {
|
||||
db.iter_ids()?
|
||||
.filter_map(Result::ok)
|
||||
.map(move |id| {
|
||||
Ok((
|
||||
id.clone(),
|
||||
db.get_registration(&id)?
|
||||
.expect("iter_ids only returns appservices that exist"),
|
||||
))
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue