fix: Correct relations pagination and recursion

Ended up rewriting a fair bit, but should work better.
This commit is contained in:
Henry-Hiles authored and Ellis Git committed 2026-11-08 19:34:25 +00:00
1 parent 7c451888ae
commit 15b4e8e2f9
7 files changed
+232 -201

No files matched your search

+6 -1
View File
@@ -16,7 +16,12 @@ use ruma::{
use serde::Deserialize;
use serde_json::{Value as JsonValue, value::RawValue as RawJsonValue};
pub use self::{filter::Matches, id::*, relation::RelationTypeEqual, type_ext::TypeExt};
pub use self::{
filter::Matches,
id::*,
relation::{RelationTypeEqual, relation_type},
type_ext::TypeExt,
};
use super::{pdu::Pdu, state_key::StateKey};
use crate::{Result, utils};
+10 -5
View File
@@ -8,7 +8,7 @@ pub trait RelationTypeEqual<E: Event> {
}
#[derive(Clone, Debug, Deserialize)]
struct ExtractRelatesToEventId {
struct ExtractRelatesToRelType {
#[serde(rename = "m.relates_to")]
relates_to: ExtractRelType,
}
@@ -18,11 +18,16 @@ struct ExtractRelType {
rel_type: RelationType,
}
/// The type of an event's relation, if it has one
pub fn relation_type<E: Event>(event: &E) -> Option<RelationType> {
event
.get_content()
.map(|c: ExtractRelatesToRelType| c.relates_to.rel_type)
.ok()
}
impl<E: Event> RelationTypeEqual<E> for RelationType {
fn relation_type_equal(&self, event: &E) -> bool {
event
.get_content()
.map(|c: ExtractRelatesToEventId| c.relates_to.rel_type)
.is_ok_and(|r| r == *self)
relation_type(event).is_some_and(|r| r == *self)
}
}
+10
View File
@@ -105,6 +105,16 @@ impl Count {
}
}
/// Whether this comes after `other` when going in the direction of `dir`
#[inline]
#[must_use]
pub fn is_after(self, other: Self, dir: Direction) -> bool {
match dir {
| Direction::Forward => self > other,
| Direction::Backward => self < other,
}
}
#[inline]
#[must_use]
pub fn saturating_add(self, add: u64) -> Self {