Record room information (ID, name) in the database #48
|
@ -92,7 +92,9 @@ fn should_process_event(db: &Database, room_id: &str, event_id: &str) -> bool {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn record_room_information(
|
//TODO this needs to be moved to a common API layer.
|
||||||
|
/// Record the information about a room, including users in it.
|
||||||
|
pub async fn record_room_information(
|
||||||
client: &matrix_sdk::Client,
|
client: &matrix_sdk::Client,
|
||||||
db: &crate::db::Database,
|
db: &crate::db::Database,
|
||||||
room: &matrix_sdk::Room,
|
room: &matrix_sdk::Room,
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use super::{Command, Execution};
|
use super::{Command, Execution};
|
||||||
use crate::context::Context;
|
use crate::context::Context;
|
||||||
use crate::db::errors::DataError;
|
use crate::db::errors::DataError;
|
||||||
use crate::matrix;
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use matrix_sdk::identifiers::UserId;
|
use matrix_sdk::identifiers::UserId;
|
||||||
|
|
||||||
|
@ -16,17 +15,16 @@ impl Command for ResyncCommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn execute(&self, ctx: &Context<'_>) -> Execution {
|
async fn execute(&self, ctx: &Context<'_>) -> Execution {
|
||||||
let room_id = &ctx.room.room_id;
|
|
||||||
let our_username: Option<UserId> = ctx.matrix_client.user_id().await;
|
let our_username: Option<UserId> = ctx.matrix_client.user_id().await;
|
||||||
let our_username: &str = our_username.as_ref().map_or("", UserId::as_str);
|
let our_username: &str = our_username.as_ref().map_or("", UserId::as_str);
|
||||||
|
|
||||||
let usernames = matrix::get_users_in_room(&ctx.matrix_client, &room_id).await;
|
let result: ResyncResult = crate::bot::event_handlers::record_room_information(
|
||||||
|
ctx.matrix_client,
|
||||||
let result: ResyncResult = usernames
|
&ctx.db,
|
||||||
.into_iter()
|
&ctx.room,
|
||||||
.filter(|username| username != our_username)
|
our_username,
|
||||||
.map(|username| ctx.db.rooms.add_user_to_room(&username, room_id.as_str()))
|
)
|
||||||
.collect(); //Make use of collect impl on Result.
|
.await;
|
||||||
|
|
||||||
let (plain, html) = match result {
|
let (plain, html) = match result {
|
||||||
Ok(()) => {
|
Ok(()) => {
|
||||||
|
|
Loading…
Reference in New Issue