2024-07-27 00:11:41 +00:00
|
|
|
use clap::Subcommand;
|
2024-12-14 21:58:01 -05:00
|
|
|
use conduwuit::Result;
|
2024-11-19 03:08:09 +00:00
|
|
|
use futures::StreamExt;
|
2024-10-02 07:57:18 +00:00
|
|
|
use ruma::{events::room::message::RoomMessageEventContent, RoomId, UserId};
|
2024-04-20 14:44:31 -04:00
|
|
|
|
2025-01-04 16:57:07 +00:00
|
|
|
use crate::{admin_command, admin_command_dispatch};
|
2024-04-20 14:44:31 -04:00
|
|
|
|
2025-01-04 16:57:07 +00:00
|
|
|
#[admin_command_dispatch]
|
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.
|
2025-01-04 16:57:07 +00:00
|
|
|
AccountDataGet {
|
2024-07-27 00:11:41 +00:00
|
|
|
/// Full user ID
|
|
|
|
user_id: Box<UserId>,
|
|
|
|
/// Account data event type
|
2024-10-02 07:57:18 +00:00
|
|
|
kind: String,
|
2024-07-27 00:11:41 +00:00
|
|
|
/// Optional room ID of the account data
|
|
|
|
room_id: Option<Box<RoomId>>,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2025-01-04 16:57:07 +00:00
|
|
|
#[admin_command]
|
|
|
|
async fn changes_since(
|
|
|
|
&self,
|
|
|
|
user_id: Box<UserId>,
|
|
|
|
since: u64,
|
|
|
|
room_id: Option<Box<RoomId>>,
|
2024-12-15 00:05:47 -05:00
|
|
|
) -> Result<RoomMessageEventContent> {
|
2025-01-04 16:57:07 +00:00
|
|
|
let timer = tokio::time::Instant::now();
|
|
|
|
let results: Vec<_> = self
|
|
|
|
.services
|
|
|
|
.account_data
|
2025-01-31 13:51:39 +00:00
|
|
|
.changes_since(room_id.as_deref(), &user_id, since, None)
|
2025-01-04 16:57:07 +00:00
|
|
|
.collect()
|
|
|
|
.await;
|
|
|
|
let query_time = timer.elapsed();
|
2024-07-27 00:11:41 +00:00
|
|
|
|
2025-01-04 16:57:07 +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
|
|
|
|
2025-01-04 16:57:07 +00:00
|
|
|
#[admin_command]
|
|
|
|
async fn account_data_get(
|
|
|
|
&self,
|
|
|
|
user_id: Box<UserId>,
|
|
|
|
kind: String,
|
|
|
|
room_id: Option<Box<RoomId>>,
|
|
|
|
) -> Result<RoomMessageEventContent> {
|
|
|
|
let timer = tokio::time::Instant::now();
|
|
|
|
let results = self
|
|
|
|
.services
|
|
|
|
.account_data
|
|
|
|
.get_raw(room_id.as_deref(), &user_id, &kind)
|
|
|
|
.await;
|
|
|
|
let query_time = timer.elapsed();
|
2024-04-20 14:44:31 -04:00
|
|
|
|
2025-01-04 16:57:07 +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
|
|
|
}
|