mirror of
https://forgejo.ellis.link/continuwuation/continuwuity/
synced 2026-05-12 10:34:54 +00:00
583cb924f1
- Extract duplicated thread/message pagination functions to shared utils module - Refactor pagination token parsing to use Option combinators instead of defaults - Split access token generation from assignment for clearer error handling - Add appservice token collision detection at startup and registration - Allow appservice re-registration with same token (for config updates) - Simplify thread relation chunk building using iterator chaining - Fix saturating_inc edge case in relation queries with explicit filtering - Add concise comments explaining non-obvious behaviour choices
29 lines
1013 B
Rust
29 lines
1013 B
Rust
use conduwuit::{
|
|
Result, err,
|
|
matrix::pdu::{PduCount, ShortEventId},
|
|
};
|
|
|
|
/// Parse a pagination token, trying ShortEventId first, then falling back to
|
|
/// PduCount
|
|
pub(crate) fn parse_pagination_token(token: &str) -> Result<PduCount> {
|
|
// Try parsing as ShortEventId first
|
|
if let Ok(shorteventid) = token.parse::<ShortEventId>() {
|
|
// ShortEventId maps directly to a PduCount in our database
|
|
Ok(PduCount::Normal(shorteventid))
|
|
} else if let Ok(count) = token.parse::<u64>() {
|
|
// Fallback to PduCount for backwards compatibility
|
|
Ok(PduCount::Normal(count))
|
|
} else if let Ok(count) = token.parse::<i64>() {
|
|
// Also handle negative counts for backfilled events
|
|
Ok(PduCount::from_signed(count))
|
|
} else {
|
|
Err(err!(Request(InvalidParam("Invalid pagination token"))))
|
|
}
|
|
}
|
|
|
|
/// Convert a PduCount to a token string (using the underlying ShortEventId)
|
|
pub(crate) fn count_to_token(count: PduCount) -> String {
|
|
// The PduCount's unsigned value IS the ShortEventId
|
|
count.into_unsigned().to_string()
|
|
}
|