use clap::Subcommand; use conduwuit::Result; use futures::StreamExt; use ruma::{events::room::message::RoomMessageEventContent, RoomId, UserId}; use crate::Command; #[derive(Debug, Subcommand)] /// All the getters and iterators from src/database/key_value/account_data.rs pub(crate) enum AccountDataCommand { /// - Returns all changes to the account data that happened after `since`. ChangesSince { /// Full user ID user_id: Box, /// UNIX timestamp since (u64) since: u64, /// Optional room ID of the account data room_id: Option>, }, /// - Searches the account data for a specific kind. Get { /// Full user ID user_id: Box, /// Account data event type kind: String, /// Optional room ID of the account data room_id: Option>, }, } /// All the getters and iterators from src/database/key_value/account_data.rs pub(super) async fn process(subcommand: AccountDataCommand, context: &Command<'_>) -> Result { let services = context.services; match subcommand { AccountDataCommand::ChangesSince { user_id, since, room_id, } => { let timer = tokio::time::Instant::now(); let results: Vec<_> = services .account_data .changes_since(room_id.as_deref(), &user_id, since) .collect() .await; let query_time = timer.elapsed(); Ok(RoomMessageEventContent::notice_markdown(format!( "Query completed in {query_time:?}:\n\n```rs\n{results:#?}\n```" ))) }, AccountDataCommand::Get { user_id, kind, room_id, } => { let timer = tokio::time::Instant::now(); let results = services .account_data .get_raw(room_id.as_deref(), &user_id, &kind) .await; let query_time = timer.elapsed(); Ok(RoomMessageEventContent::notice_markdown(format!( "Query completed in {query_time:?}:\n\n```rs\n{results:#?}\n```" ))) }, } }