events: Use Reference instead of events::poll::ReferenceRelation
This commit is contained in:
parent
93bc8a60be
commit
5faff343a0
@ -7,8 +7,8 @@ use super::{
|
||||
Redact, Relations,
|
||||
};
|
||||
use crate::{
|
||||
events::relation::Reference, serde::from_raw_json_value, EventId, MilliSecondsSinceUnixEpoch,
|
||||
OwnedRoomId, RoomId, RoomVersionId, TransactionId, UserId,
|
||||
serde::from_raw_json_value, EventId, MilliSecondsSinceUnixEpoch, OwnedRoomId, RoomId,
|
||||
RoomVersionId, TransactionId, UserId,
|
||||
};
|
||||
|
||||
event_enum! {
|
||||
@ -351,8 +351,7 @@ impl AnyMessageLikeEventContent {
|
||||
#[cfg(feature = "unstable-msc3381")]
|
||||
Self::PollResponse(PollResponseEventContent { relates_to, .. })
|
||||
| Self::PollEnd(PollEndEventContent { relates_to, .. }) => {
|
||||
let super::poll::ReferenceRelation { event_id } = relates_to;
|
||||
Some(encrypted::Relation::Reference(Reference { event_id: event_id.clone() }))
|
||||
Some(encrypted::Relation::Reference(relates_to.clone()))
|
||||
}
|
||||
#[cfg(feature = "unstable-msc3381")]
|
||||
Self::PollStart(_) => None,
|
||||
|
@ -4,26 +4,6 @@
|
||||
//!
|
||||
//! [MSC3381]: https://github.com/matrix-org/matrix-spec-proposals/pull/3381
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::OwnedEventId;
|
||||
|
||||
pub mod end;
|
||||
pub mod response;
|
||||
pub mod start;
|
||||
|
||||
/// An `m.reference` relation.
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
#[serde(tag = "rel_type", rename = "m.reference")]
|
||||
pub struct ReferenceRelation {
|
||||
/// The ID of the event this references.
|
||||
pub event_id: OwnedEventId,
|
||||
}
|
||||
|
||||
impl ReferenceRelation {
|
||||
/// Creates a new `ReferenceRelation` that references the given event ID.
|
||||
pub fn new(event_id: OwnedEventId) -> Self {
|
||||
Self { event_id }
|
||||
}
|
||||
}
|
||||
|
@ -3,8 +3,7 @@
|
||||
use ruma_macros::EventContent;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::ReferenceRelation;
|
||||
use crate::OwnedEventId;
|
||||
use crate::{events::relation::Reference, OwnedEventId};
|
||||
|
||||
/// The payload for a poll end event.
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, EventContent)]
|
||||
@ -17,14 +16,14 @@ pub struct PollEndEventContent {
|
||||
|
||||
/// Information about the poll start event this responds to.
|
||||
#[serde(rename = "m.relates_to")]
|
||||
pub relates_to: ReferenceRelation,
|
||||
pub relates_to: Reference,
|
||||
}
|
||||
|
||||
impl PollEndEventContent {
|
||||
/// Creates a new `PollEndEventContent` that responds to the given poll start event ID,
|
||||
/// with the given poll end content.
|
||||
pub fn new(poll_end: PollEndContent, poll_start_id: OwnedEventId) -> Self {
|
||||
Self { poll_end, relates_to: ReferenceRelation::new(poll_start_id) }
|
||||
Self { poll_end, relates_to: Reference::new(poll_start_id) }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,8 +3,7 @@
|
||||
use ruma_macros::EventContent;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::ReferenceRelation;
|
||||
use crate::OwnedEventId;
|
||||
use crate::{events::relation::Reference, OwnedEventId};
|
||||
|
||||
/// The payload for a poll response event.
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, EventContent)]
|
||||
@ -17,14 +16,14 @@ pub struct PollResponseEventContent {
|
||||
|
||||
/// Information about the poll start event this responds to.
|
||||
#[serde(rename = "m.relates_to")]
|
||||
pub relates_to: ReferenceRelation,
|
||||
pub relates_to: Reference,
|
||||
}
|
||||
|
||||
impl PollResponseEventContent {
|
||||
/// Creates a new `PollResponseEventContent` that responds to the given poll start event ID,
|
||||
/// with the given poll response content.
|
||||
pub fn new(poll_response: PollResponseContent, poll_start_id: OwnedEventId) -> Self {
|
||||
Self { poll_response, relates_to: ReferenceRelation::new(poll_start_id) }
|
||||
Self { poll_response, relates_to: Reference::new(poll_start_id) }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,8 +14,8 @@ use ruma_common::{
|
||||
PollAnswer, PollAnswers, PollAnswersError, PollKind, PollStartContent,
|
||||
PollStartEventContent,
|
||||
},
|
||||
ReferenceRelation,
|
||||
},
|
||||
relation::Reference,
|
||||
AnyMessageLikeEvent, MessageLikeEvent, MessageLikeUnsigned, OriginalMessageLikeEvent,
|
||||
},
|
||||
room_id, user_id, MilliSecondsSinceUnixEpoch,
|
||||
@ -318,7 +318,7 @@ fn response_event_unstable_deserialization() {
|
||||
assert_eq!(answers[0], "my-answer");
|
||||
let event_id = assert_matches!(
|
||||
message_event.content.relates_to,
|
||||
ReferenceRelation { event_id, .. } => event_id
|
||||
Reference { event_id, .. } => event_id
|
||||
);
|
||||
assert_eq!(event_id, "$related_event:notareal.hs");
|
||||
}
|
||||
@ -354,7 +354,7 @@ fn response_event_stable_deserialization() {
|
||||
assert_eq!(answers[1], "second-answer");
|
||||
let event_id = assert_matches!(
|
||||
message_event.content.relates_to,
|
||||
ReferenceRelation { event_id, .. } => event_id
|
||||
Reference { event_id, .. } => event_id
|
||||
);
|
||||
assert_eq!(event_id, "$related_event:notareal.hs");
|
||||
}
|
||||
@ -435,7 +435,7 @@ fn end_event_unstable_deserialization() {
|
||||
);
|
||||
let event_id = assert_matches!(
|
||||
message_event.content.relates_to,
|
||||
ReferenceRelation { event_id, .. } => event_id
|
||||
Reference { event_id, .. } => event_id
|
||||
);
|
||||
assert_eq!(event_id, "$related_event:notareal.hs");
|
||||
}
|
||||
@ -464,7 +464,7 @@ fn end_event_stable_deserialization() {
|
||||
);
|
||||
let event_id = assert_matches!(
|
||||
message_event.content.relates_to,
|
||||
ReferenceRelation { event_id, .. } => event_id
|
||||
Reference { event_id, .. } => event_id
|
||||
);
|
||||
assert_eq!(event_id, "$related_event:notareal.hs");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user