identifiers: Allow via on RoomId::matrix_to_event_uri()

This commit is contained in:
Kévin Commaille 2022-06-29 14:17:28 +02:00 committed by Kévin Commaille
parent 4883a3154c
commit 2dacaf2ea0
3 changed files with 29 additions and 3 deletions

View File

@ -23,6 +23,7 @@ Breaking changes:
* Move `CanonicalJson`, `CanonicalJsonObject` and `CanonicalJsonError` out of
the `serde` module and behind the cargo feature flag `canonical-json`
* Make identifiers matrix URI constructors generic over owned parameters
* Allow to add routing servers to `RoomId::matrix_to_event_uri()`
[spec]: https://github.com/matrix-org/matrix-spec-proposals/pull/3669

View File

@ -571,10 +571,19 @@ mod tests {
);
assert_eq!(
room_id!("!ruma:notareal.hs")
.matrix_to_event_uri(event_id!("$event:notareal.hs"))
.matrix_to_event_uri(event_id!("$event:notareal.hs"), Vec::<OwnedServerName>::new())
.to_string(),
"https://matrix.to/#/%21ruma%3Anotareal.hs/%24event%3Anotareal.hs"
);
assert_eq!(
room_id!("!ruma:notareal.hs")
.matrix_to_event_uri(
event_id!("$event:notareal.hs"),
vec![server_name!("notareal.hs")]
)
.to_string(),
"https://matrix.to/#/%21ruma%3Anotareal.hs/%24event%3Anotareal.hs?via=notareal.hs"
);
}
#[test]
@ -822,6 +831,15 @@ mod tests {
.to_string(),
"matrix:roomid/ruma:notareal.hs/e/event:notareal.hs"
);
assert_eq!(
room_id!("!ruma:notareal.hs")
.matrix_event_uri(
event_id!("$event:notareal.hs"),
vec![server_name!("notareal.hs")]
)
.to_string(),
"matrix:roomid/ruma:notareal.hs/e/event:notareal.hs?via=notareal.hs"
);
}
#[test]

View File

@ -67,8 +67,15 @@ impl RoomId {
}
/// Create a `matrix.to` URI for an event scoped under this room ID.
pub fn matrix_to_event_uri(&self, ev_id: impl Into<OwnedEventId>) -> MatrixToUri {
MatrixToUri::new((self.to_owned(), ev_id.into()).into(), Vec::new())
pub fn matrix_to_event_uri<T>(&self, ev_id: impl Into<OwnedEventId>, via: T) -> MatrixToUri
where
T: IntoIterator,
T::Item: Into<OwnedServerName>,
{
MatrixToUri::new(
(self.to_owned(), ev_id.into()).into(),
via.into_iter().map(Into::into).collect(),
)
}
/// Create a `matrix:` URI for this room ID.