fix: Nuke src/api/client/utils.rs

This commit is contained in:
Ginger 2025-09-07 18:06:11 -04:00
commit 1e541875ad
No known key found for this signature in database
5 changed files with 9 additions and 19 deletions

View file

@ -35,7 +35,6 @@ use ruma::{
};
use tracing::warn;
use super::utils::{count_to_pagination_token, pagination_token_to_count as parse_token};
use crate::Ruma;
/// list of safe and common non-state events to ignore if the user is ignored
@ -85,14 +84,14 @@ pub(crate) async fn get_message_events_route(
let from: PduCount = body
.from
.as_deref()
.map(parse_token)
.map(str::parse)
.transpose()?
.unwrap_or_else(|| match body.dir {
| Direction::Forward => PduCount::min(),
| Direction::Backward => PduCount::max(),
});
let to: Option<PduCount> = body.to.as_deref().map(parse_token).transpose()?;
let to: Option<PduCount> = body.to.as_deref().map(str::parse).transpose()?;
let limit: usize = body
.limit
@ -181,8 +180,8 @@ pub(crate) async fn get_message_events_route(
.collect();
Ok(get_message_events::v3::Response {
start: count_to_pagination_token(from),
end: next_token.map(count_to_pagination_token),
start: from.to_string(),
end: next_token.as_ref().map(PduCount::to_string),
chunk,
state,
})

View file

@ -37,7 +37,6 @@ pub(super) mod typing;
pub(super) mod unstable;
pub(super) mod unversioned;
pub(super) mod user_directory;
pub(super) mod utils;
pub(super) mod voip;
pub(super) mod well_known;

View file

@ -18,7 +18,6 @@ use ruma::{
events::{TimelineEventType, relation::RelationType},
};
use super::utils::{count_to_pagination_token, pagination_token_to_count as parse_token};
use crate::Ruma;
/// # `GET /_matrix/client/r0/rooms/{roomId}/relations/{eventId}/{relType}/{eventType}`
@ -111,14 +110,14 @@ async fn paginate_relations_with_filter(
dir: Direction,
) -> Result<get_relating_events::v1::Response> {
let start: PduCount = from
.map(parse_token)
.map(str::parse)
.transpose()?
.unwrap_or_else(|| match dir {
| Direction::Forward => PduCount::min(),
| Direction::Backward => PduCount::max(),
});
let to: Option<PduCount> = to.map(parse_token).transpose()?;
let to: Option<PduCount> = to.map(str::parse).transpose()?;
// Use limit or else 30, with maximum 100
let limit: usize = limit
@ -193,7 +192,7 @@ async fn paginate_relations_with_filter(
| Direction::Forward => events.last(),
| Direction::Backward => events.first(),
}
.map(|(count, _)| count_to_pagination_token(*count))
.map(|(count, _)| count.to_string())
} else {
None
};

View file

@ -9,7 +9,7 @@ use conduwuit::{
use futures::StreamExt;
use ruma::{api::client::threads::get_threads, uint};
use crate::{Ruma, client::utils::pagination_token_to_count};
use crate::Ruma;
/// # `GET /_matrix/client/r0/rooms/{roomId}/threads`
pub(crate) async fn get_threads_route(
@ -27,7 +27,7 @@ pub(crate) async fn get_threads_route(
let from: PduCount = body
.from
.as_deref()
.map(pagination_token_to_count)
.map(str::parse)
.transpose()?
.unwrap_or_else(PduCount::max);

View file

@ -1,7 +0,0 @@
use conduwuit::{Result, matrix::pdu::PduCount};
/// Parse a pagination token
pub(crate) fn pagination_token_to_count(token: &str) -> Result<PduCount> { token.parse() }
/// Convert a PduCount to a token string
pub(crate) fn count_to_pagination_token(count: PduCount) -> String { count.to_string() }