events: Consistently use relates_to for Relation field name

This commit is contained in:
Jonas Platte 2021-06-20 01:32:29 +02:00
parent 6546add282
commit 090948e04f
No known key found for this signature in database
GPG Key ID: 7D261D771D915378
8 changed files with 37 additions and 37 deletions

View File

@ -55,15 +55,15 @@ pub struct AcceptEventContent {
/// Information about the related event.
#[serde(rename = "m.relates_to")]
pub relation: Relation,
pub relates_to: Relation,
}
#[cfg(feature = "unstable-pre-spec")]
impl AcceptEventContent {
/// Creates a new `AcceptToDeviceEventContent` with the given method-specific content and
/// relation.
pub fn new(method: AcceptMethod, relation: Relation) -> Self {
Self { method, relation }
pub fn new(method: AcceptMethod, relates_to: Relation) -> Self {
Self { method, relates_to }
}
}
@ -255,7 +255,7 @@ mod tests {
let event_id = event_id!("$1598361704261elfgc:localhost");
let key_verification_accept_content = AcceptEventContent {
relation: Relation { event_id: event_id.clone() },
relates_to: Relation { event_id: event_id.clone() },
method: AcceptMethod::SasV1(SasV1Content {
hash: HashAlgorithm::Sha256,
key_agreement_protocol: KeyAgreementProtocol::Curve25519,
@ -417,7 +417,7 @@ mod tests {
.deserialize()
.unwrap(),
AcceptEventContent {
relation: Relation {
relates_to: Relation {
event_id
},
method: AcceptMethod::SasV1(SasV1Content {

View File

@ -55,14 +55,14 @@ pub struct CancelEventContent {
/// Information about the related event.
#[serde(rename = "m.relates_to")]
pub relation: Relation,
pub relates_to: Relation,
}
#[cfg(feature = "unstable-pre-spec")]
impl CancelEventContent {
/// Creates a new `CancelEventContent` with the given reason, code and relation.
pub fn new(reason: String, code: CancelCode, relation: Relation) -> Self {
Self { reason, code, relation }
pub fn new(reason: String, code: CancelCode, relates_to: Relation) -> Self {
Self { reason, code, relates_to }
}
}

View File

@ -35,13 +35,13 @@ impl DoneToDeviceEventContent {
pub struct DoneEventContent {
/// Relation signaling which verification request this event is responding to.
#[serde(rename = "m.relates_to")]
pub relation: Relation,
pub relates_to: Relation,
}
impl DoneEventContent {
/// Creates a new `DoneEventContent` with the given relation:
pub fn new(relation: Relation) -> Self {
Self { relation }
/// Creates a new `DoneEventContent` with the given relation.
pub fn new(relates_to: Relation) -> Self {
Self { relates_to }
}
}
@ -66,7 +66,7 @@ mod tests {
}
});
let content = DoneEventContent { relation: Relation { event_id } };
let content = DoneEventContent { relates_to: Relation { event_id } };
assert_eq!(to_json_value(&content).unwrap(), json_data);
}
@ -88,7 +88,7 @@ mod tests {
.deserialize()
.unwrap(),
DoneEventContent {
relation: Relation {
relates_to: Relation {
event_id
},
} if event_id == id

View File

@ -46,13 +46,13 @@ pub struct KeyEventContent {
/// Information about the related event.
#[serde(rename = "m.relates_to")]
pub relation: Relation,
pub relates_to: Relation,
}
#[cfg(feature = "unstable-pre-spec")]
impl KeyEventContent {
/// Creates a new `KeyEventContent` with the given key and relation.
pub fn new(key: String, relation: Relation) -> Self {
Self { key, relation }
pub fn new(key: String, relates_to: Relation) -> Self {
Self { key, relates_to }
}
}

View File

@ -61,13 +61,13 @@ pub struct MacEventContent {
/// Information about the related event.
#[serde(rename = "m.relates_to")]
pub relation: Relation,
pub relates_to: Relation,
}
#[cfg(feature = "unstable-pre-spec")]
impl MacEventContent {
/// Creates a new `MacEventContent` with the given key ID to MAC map, key MAC and relation.
pub fn new(mac: BTreeMap<String, String>, keys: String, relation: Relation) -> Self {
Self { mac, keys, relation }
pub fn new(mac: BTreeMap<String, String>, keys: String, relates_to: Relation) -> Self {
Self { mac, keys, relates_to }
}
}

View File

@ -55,7 +55,7 @@ pub struct ReadyEventContent {
/// Relation signaling which verification request this event is responding
/// to.
#[serde(rename = "m.relates_to")]
pub relation: Relation,
pub relates_to: Relation,
}
impl ReadyEventContent {
@ -63,9 +63,9 @@ impl ReadyEventContent {
pub fn new(
from_device: DeviceIdBox,
methods: Vec<VerificationMethod>,
relation: Relation,
relates_to: Relation,
) -> Self {
Self { from_device, methods, relation }
Self { from_device, methods, relates_to }
}
}
@ -95,7 +95,7 @@ mod tests {
let content = ReadyEventContent {
from_device: device.clone(),
relation: Relation { event_id },
relates_to: Relation { event_id },
methods: vec![VerificationMethod::SasV1],
};
@ -137,7 +137,7 @@ mod tests {
.unwrap(),
ReadyEventContent {
from_device,
relation: Relation {
relates_to: Relation {
event_id
},
methods,

View File

@ -65,14 +65,14 @@ pub struct StartEventContent {
/// Information about the related event.
#[serde(rename = "m.relates_to")]
pub relation: Relation,
pub relates_to: Relation,
}
#[cfg(feature = "unstable-pre-spec")]
impl StartEventContent {
/// Creates a new `StartEventContent` with the given device ID, method and relation.
pub fn new(from_device: DeviceIdBox, method: StartMethod, relation: Relation) -> Self {
Self { from_device, method, relation }
pub fn new(from_device: DeviceIdBox, method: StartMethod, relates_to: Relation) -> Self {
Self { from_device, method, relates_to }
}
}
@ -420,7 +420,7 @@ mod tests {
let key_verification_start_content = StartEventContent {
from_device: "123".into(),
relation: Relation { event_id: event_id.clone() },
relates_to: Relation { event_id: event_id.clone() },
method: StartMethod::SasV1(
SasV1Content::new(SasV1ContentInit {
hashes: vec![HashAlgorithm::Sha256],
@ -451,7 +451,7 @@ mod tests {
let key_verification_start_content = StartEventContent {
from_device: "123".into(),
relation: Relation { event_id: event_id.clone() },
relates_to: Relation { event_id: event_id.clone() },
method: StartMethod::ReciprocateV1(ReciprocateV1Content::new(secret.clone())),
};
@ -636,7 +636,7 @@ mod tests {
.unwrap(),
StartEventContent {
from_device,
relation: Relation { event_id },
relates_to: Relation { event_id },
method: StartMethod::SasV1(SasV1Content {
hashes,
key_agreement_protocols,
@ -668,7 +668,7 @@ mod tests {
.unwrap(),
StartEventContent {
from_device,
relation: Relation { event_id },
relates_to: Relation { event_id },
method: StartMethod::ReciprocateV1(ReciprocateV1Content { secret }),
} if from_device == "123"
&& event_id == id

View File

@ -42,19 +42,19 @@ pub struct EncryptedEventContent {
///
/// [rich replies]: https://matrix.org/docs/spec/client_server/r0.6.1#rich-replies
#[serde(flatten, with = "relation_serde", skip_serializing_if = "Option::is_none")]
pub relation: Option<Relation>,
pub relates_to: Option<Relation>,
}
impl EncryptedEventContent {
/// Creates a new `EncryptedEventContent` with the given scheme and relation.
pub fn new(scheme: EncryptedEventScheme, relates_to: Option<Relation>) -> Self {
Self { scheme, relation: relates_to }
Self { scheme, relates_to }
}
}
impl From<EncryptedEventScheme> for EncryptedEventContent {
fn from(scheme: EncryptedEventScheme) -> Self {
Self { scheme, relation: None }
Self { scheme, relates_to: None }
}
}
@ -167,7 +167,7 @@ mod tests {
device_id: "device_id".into(),
session_id: "session_id".into(),
}),
relation: Some(Relation::Reply {
relates_to: Some(Relation::Reply {
in_reply_to: InReplyTo { event_id: event_id!("$h29iv0s8:example.com") },
}),
};
@ -223,7 +223,7 @@ mod tests {
);
assert_matches!(
content.relation,
content.relates_to,
Some(Relation::Reply { in_reply_to })
if in_reply_to.event_id == event_id!("$h29iv0s8:example.com")
);