2024-07-27 00:11:41 +00:00
|
|
|
use clap::Subcommand;
|
|
|
|
use conduit::Result;
|
|
|
|
use ruma::{
|
|
|
|
events::{room::message::RoomMessageEventContent, RoomAccountDataEventType},
|
|
|
|
RoomId, UserId,
|
|
|
|
};
|
2024-04-20 14:44:31 -04:00
|
|
|
|
2024-07-27 00:11:41 +00:00
|
|
|
use crate::Command;
|
2024-04-20 14:44:31 -04:00
|
|
|
|
2024-07-27 00:11:41 +00:00
|
|
|
#[derive(Debug, Subcommand)]
|
2024-04-20 17:02:24 -04:00
|
|
|
/// All the getters and iterators from src/database/key_value/account_data.rs
|
2024-07-27 00:11:41 +00:00
|
|
|
pub(crate) enum AccountDataCommand {
|
|
|
|
/// - Returns all changes to the account data that happened after `since`.
|
|
|
|
ChangesSince {
|
|
|
|
/// Full user ID
|
|
|
|
user_id: Box<UserId>,
|
|
|
|
/// UNIX timestamp since (u64)
|
|
|
|
since: u64,
|
|
|
|
/// Optional room ID of the account data
|
|
|
|
room_id: Option<Box<RoomId>>,
|
|
|
|
},
|
|
|
|
|
|
|
|
/// - Searches the account data for a specific kind.
|
|
|
|
Get {
|
|
|
|
/// Full user ID
|
|
|
|
user_id: Box<UserId>,
|
|
|
|
/// Account data event type
|
|
|
|
kind: RoomAccountDataEventType,
|
|
|
|
/// Optional room ID of the account data
|
|
|
|
room_id: Option<Box<RoomId>>,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
/// All the getters and iterators from src/database/key_value/account_data.rs
|
|
|
|
pub(super) async fn process(subcommand: AccountDataCommand, context: &Command<'_>) -> Result<RoomMessageEventContent> {
|
|
|
|
let services = context.services;
|
|
|
|
|
2024-04-20 14:44:31 -04:00
|
|
|
match subcommand {
|
2024-07-27 00:11:41 +00:00
|
|
|
AccountDataCommand::ChangesSince {
|
2024-04-20 14:44:31 -04:00
|
|
|
user_id,
|
|
|
|
since,
|
|
|
|
room_id,
|
|
|
|
} => {
|
|
|
|
let timer = tokio::time::Instant::now();
|
2024-07-27 00:11:41 +00:00
|
|
|
let results = services
|
2024-04-20 14:44:31 -04:00
|
|
|
.account_data
|
|
|
|
.changes_since(room_id.as_deref(), &user_id, since)?;
|
|
|
|
let query_time = timer.elapsed();
|
|
|
|
|
2024-06-17 10:12:44 +00:00
|
|
|
Ok(RoomMessageEventContent::notice_markdown(format!(
|
|
|
|
"Query completed in {query_time:?}:\n\n```rs\n{results:#?}\n```"
|
|
|
|
)))
|
2024-04-20 14:44:31 -04:00
|
|
|
},
|
2024-07-27 00:11:41 +00:00
|
|
|
AccountDataCommand::Get {
|
2024-04-20 14:44:31 -04:00
|
|
|
user_id,
|
|
|
|
kind,
|
|
|
|
room_id,
|
|
|
|
} => {
|
|
|
|
let timer = tokio::time::Instant::now();
|
2024-07-27 00:11:41 +00:00
|
|
|
let results = services
|
2024-04-20 14:44:31 -04:00
|
|
|
.account_data
|
|
|
|
.get(room_id.as_deref(), &user_id, kind)?;
|
|
|
|
let query_time = timer.elapsed();
|
|
|
|
|
2024-06-17 10:12:44 +00:00
|
|
|
Ok(RoomMessageEventContent::notice_markdown(format!(
|
|
|
|
"Query completed in {query_time:?}:\n\n```rs\n{results:#?}\n```"
|
|
|
|
)))
|
2024-04-20 14:44:31 -04:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|