use reqwest::Url;
use salvo::prelude::*;
use serde::{Deserialize, Serialize};
use crate::sending::{SendRequest, SendResult};
use crate::serde::RawJsonValue;
use crate::{OwnedEventId, OwnedRoomId, OwnedServerName, UnixMillis};
pub fn backfill_request(origin: &str, args: BackfillReqArgs) -> SendResult<SendRequest> {
let url = Url::parse(&format!(
"{origin}/_matrix/federation/v1/backfill/{}&limit={}&{}",
&args.room_id,
args.limit,
args.v.iter().map(|v| format!("v={v}")).collect::<Vec<_>>().join("&")
))?;
Ok(crate::sending::get(url))
}
#[derive(ToParameters, Deserialize, Debug)]
pub struct BackfillReqArgs {
#[salvo(parameter(parameter_in = Path))]
pub room_id: OwnedRoomId,
#[salvo(parameter(parameter_in = Query))]
pub v: Vec<OwnedEventId>,
#[salvo(parameter(parameter_in = Query))]
pub limit: usize,
}
#[derive(ToSchema, Serialize, Deserialize, Debug)]
pub struct BackfillResBody {
pub origin: OwnedServerName,
pub origin_server_ts: UnixMillis,
#[salvo(schema(value_type = Vec<Object>))]
pub pdus: Vec<Box<RawJsonValue>>,
}
impl BackfillResBody {
pub fn new(origin: OwnedServerName, origin_server_ts: UnixMillis, pdus: Vec<Box<RawJsonValue>>) -> Self {
Self {
origin,
origin_server_ts,
pdus,
}
}
}