events: Move relations under events::room::message to events::relation
This commit is contained in:
		
							parent
							
								
									a6ba268796
								
							
						
					
					
						commit
						aeaa4af776
					
				| @ -31,6 +31,8 @@ Breaking changes: | ||||
| * Change the `ignored_users` field of `IgnoredUserListEventContent` to a map of empty structs, to | ||||
|   allow eventual fields to be added, as intended by the spec | ||||
| * Make `SimplePushRule` and associated types generic over the expected type of the `rule_id` | ||||
| * Deduplicate and group relation structs in `events::relation`: | ||||
|   * Move relation structs under `events::room::message` to `events::relation` | ||||
| 
 | ||||
| Improvements: | ||||
| 
 | ||||
|  | ||||
| @ -13,6 +13,23 @@ use crate::{ | ||||
|     MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedUserId, PrivOwnedStr, | ||||
| }; | ||||
| 
 | ||||
| /// Information about the event a [rich reply] is replying to.
 | ||||
| ///
 | ||||
| /// [rich reply]: https://spec.matrix.org/v1.5/client-server-api/#rich-replies
 | ||||
| #[derive(Clone, Debug, Deserialize, Serialize)] | ||||
| #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] | ||||
| pub struct InReplyTo { | ||||
|     /// The event being replied to.
 | ||||
|     pub event_id: OwnedEventId, | ||||
| } | ||||
| 
 | ||||
| impl InReplyTo { | ||||
|     /// Creates a new `InReplyTo` with the given event ID.
 | ||||
|     pub fn new(event_id: OwnedEventId) -> Self { | ||||
|         Self { event_id } | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| /// Summary of all annotations to an event with the given key and type.
 | ||||
| #[derive(Clone, Debug, Deserialize, PartialEq, Eq, Serialize)] | ||||
| #[cfg(feature = "unstable-msc2677")] | ||||
| @ -106,6 +123,64 @@ impl BundledReplacement { | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| /// The content of a [replacement] relation.
 | ||||
| ///
 | ||||
| /// [replacement]: https://spec.matrix.org/v1.5/client-server-api/#event-replacements
 | ||||
| #[derive(Clone, Debug)] | ||||
| #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] | ||||
| pub struct Replacement<C> { | ||||
|     /// The ID of the event being replaced.
 | ||||
|     pub event_id: OwnedEventId, | ||||
| 
 | ||||
|     /// New content.
 | ||||
|     pub new_content: C, | ||||
| } | ||||
| 
 | ||||
| impl<C> Replacement<C> { | ||||
|     /// Creates a new `Replacement` with the given event ID and new content.
 | ||||
|     pub fn new(event_id: OwnedEventId, new_content: C) -> Self { | ||||
|         Self { event_id, new_content } | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| /// The content of a [thread] relation.
 | ||||
| ///
 | ||||
| /// [thread]: https://spec.matrix.org/v1.5/client-server-api/#threading
 | ||||
| #[derive(Clone, Debug, Deserialize, Serialize)] | ||||
| #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] | ||||
| pub struct Thread { | ||||
|     /// The ID of the root message in the thread.
 | ||||
|     pub event_id: OwnedEventId, | ||||
| 
 | ||||
|     /// A reply relation.
 | ||||
|     ///
 | ||||
|     /// If this event is a reply and belongs to a thread, this points to the message that is being
 | ||||
|     /// replied to, and `is_falling_back` must be set to `false`.
 | ||||
|     ///
 | ||||
|     /// If this event is not a reply, this is used as a fallback mechanism for clients that do not
 | ||||
|     /// support threads. This should point to the latest message-like event in the thread and
 | ||||
|     /// `is_falling_back` must be set to `true`.
 | ||||
|     pub in_reply_to: InReplyTo, | ||||
| 
 | ||||
|     /// Whether the `m.in_reply_to` field is a fallback for older clients or a genuine reply in a
 | ||||
|     /// thread.
 | ||||
|     pub is_falling_back: bool, | ||||
| } | ||||
| 
 | ||||
| impl Thread { | ||||
|     /// Convenience method to create a regular `Thread` with the given event ID and latest
 | ||||
|     /// message-like event ID.
 | ||||
|     pub fn plain(event_id: OwnedEventId, latest_event_id: OwnedEventId) -> Self { | ||||
|         Self { event_id, in_reply_to: InReplyTo::new(latest_event_id), is_falling_back: true } | ||||
|     } | ||||
| 
 | ||||
|     /// Convenience method to create a reply `Thread` with the given event ID and replied-to event
 | ||||
|     /// ID.
 | ||||
|     pub fn reply(event_id: OwnedEventId, reply_to_event_id: OwnedEventId) -> Self { | ||||
|         Self { event_id, in_reply_to: InReplyTo::new(reply_to_event_id), is_falling_back: false } | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| /// A bundled thread.
 | ||||
| #[derive(Clone, Debug, Deserialize, Serialize)] | ||||
| #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] | ||||
|  | ||||
| @ -8,8 +8,8 @@ use js_int::UInt; | ||||
| use ruma_macros::EventContent; | ||||
| use serde::{Deserialize, Serialize}; | ||||
| 
 | ||||
| use super::message::{self, InReplyTo}; | ||||
| use crate::{OwnedDeviceId, OwnedEventId}; | ||||
| use super::message; | ||||
| use crate::{events::relation::InReplyTo, OwnedDeviceId, OwnedEventId}; | ||||
| 
 | ||||
| mod relation_serde; | ||||
| 
 | ||||
| @ -130,9 +130,9 @@ impl<C> From<message::Relation<C>> for Relation { | ||||
| 
 | ||||
| /// The event this relation belongs to [replaces another event].
 | ||||
| ///
 | ||||
| /// In contrast to [`message::Replacement`](super::message::Replacement), this struct doesn't
 | ||||
| /// store the new content, since that is part of the encrypted content of an `m.room.encrypted`
 | ||||
| /// events.
 | ||||
| /// In contrast to [`relation::Replacement`](crate::events::relation::Replacement), this struct
 | ||||
| /// doesn't store the new content, since that is part of the encrypted content of an
 | ||||
| /// `m.room.encrypted` events.
 | ||||
| ///
 | ||||
| /// [replaces another event]: https://spec.matrix.org/v1.4/client-server-api/#event-replacements
 | ||||
| #[derive(Clone, Debug, Deserialize, Serialize)] | ||||
|  | ||||
| @ -9,6 +9,7 @@ use serde::{de::DeserializeOwned, Deserialize, Serialize}; | ||||
| use serde_json::Value as JsonValue; | ||||
| 
 | ||||
| use crate::{ | ||||
|     events::relation::{InReplyTo, Replacement, Thread}, | ||||
|     serde::{JsonObject, StringEnum}, | ||||
|     OwnedEventId, PrivOwnedStr, | ||||
| }; | ||||
| @ -591,77 +592,6 @@ pub enum Relation<C> { | ||||
|     _Custom, | ||||
| } | ||||
| 
 | ||||
| /// Information about the event a "rich reply" is replying to.
 | ||||
| #[derive(Clone, Debug, Deserialize, Serialize)] | ||||
| #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] | ||||
| pub struct InReplyTo { | ||||
|     /// The event being replied to.
 | ||||
|     pub event_id: OwnedEventId, | ||||
| } | ||||
| 
 | ||||
| impl InReplyTo { | ||||
|     /// Creates a new `InReplyTo` with the given event ID.
 | ||||
|     pub fn new(event_id: OwnedEventId) -> Self { | ||||
|         Self { event_id } | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| /// The event this relation belongs to [replaces another event].
 | ||||
| ///
 | ||||
| /// [replaces another event]: https://spec.matrix.org/v1.4/client-server-api/#event-replacements
 | ||||
| #[derive(Clone, Debug)] | ||||
| #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] | ||||
| pub struct Replacement<C> { | ||||
|     /// The ID of the event being replaced.
 | ||||
|     pub event_id: OwnedEventId, | ||||
| 
 | ||||
|     /// New content.
 | ||||
|     pub new_content: C, | ||||
| } | ||||
| 
 | ||||
| impl<C> Replacement<C> { | ||||
|     /// Creates a new `Replacement` with the given event ID and new content.
 | ||||
|     pub fn new(event_id: OwnedEventId, new_content: C) -> Self { | ||||
|         Self { event_id, new_content } | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| /// The content of a thread relation.
 | ||||
| #[derive(Clone, Debug, Deserialize, Serialize)] | ||||
| #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] | ||||
| pub struct Thread { | ||||
|     /// The ID of the root message in the thread.
 | ||||
|     pub event_id: OwnedEventId, | ||||
| 
 | ||||
|     /// A reply relation.
 | ||||
|     ///
 | ||||
|     /// If this event is a reply and belongs to a thread, this points to the message that is being
 | ||||
|     /// replied to, and `is_falling_back` must be set to `false`.
 | ||||
|     ///
 | ||||
|     /// If this event is not a reply, this is used as a fallback mechanism for clients that do not
 | ||||
|     /// support threads. This should point to the latest message-like event in the thread and
 | ||||
|     /// `is_falling_back` must be set to `true`.
 | ||||
|     pub in_reply_to: InReplyTo, | ||||
| 
 | ||||
|     /// Whether the `m.in_reply_to` field is a fallback for older clients or a genuine reply in a
 | ||||
|     /// thread.
 | ||||
|     pub is_falling_back: bool, | ||||
| } | ||||
| 
 | ||||
| impl Thread { | ||||
|     /// Convenience method to create a regular `Thread` with the given event ID and latest
 | ||||
|     /// message-like event ID.
 | ||||
|     pub fn plain(event_id: OwnedEventId, latest_event_id: OwnedEventId) -> Self { | ||||
|         Self { event_id, in_reply_to: InReplyTo::new(latest_event_id), is_falling_back: true } | ||||
|     } | ||||
| 
 | ||||
|     /// Convenience method to create a reply `Thread` with the given event ID and replied-to event
 | ||||
|     /// ID.
 | ||||
|     pub fn reply(event_id: OwnedEventId, reply_to_event_id: OwnedEventId) -> Self { | ||||
|         Self { event_id, in_reply_to: InReplyTo::new(reply_to_event_id), is_falling_back: false } | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| /// The format for the formatted representation of a message body.
 | ||||
| #[doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/doc/string_enum.md"))] | ||||
| #[derive(Clone, Debug, PartialEq, Eq, StringEnum)] | ||||
|  | ||||
| @ -11,10 +11,9 @@ use ruma_common::{ | ||||
|         audio::{Amplitude, AudioContent, AudioEventContent, Waveform, WaveformError}, | ||||
|         file::{EncryptedContentInit, FileContent, FileContentInfo}, | ||||
|         message::MessageContent, | ||||
|         relation::InReplyTo, | ||||
|         room::{ | ||||
|             message::{ | ||||
|                 AudioMessageEventContent, InReplyTo, MessageType, Relation, RoomMessageEventContent, | ||||
|             }, | ||||
|             message::{AudioMessageEventContent, MessageType, Relation, RoomMessageEventContent}, | ||||
|             JsonWebKeyInit, MediaSource, | ||||
|         }, | ||||
|         AnyMessageLikeEvent, MessageLikeEvent, MessageLikeUnsigned, OriginalMessageLikeEvent, | ||||
|  | ||||
| @ -1,12 +1,12 @@ | ||||
| use assert_matches::assert_matches; | ||||
| use ruma_common::{ | ||||
|     device_id, event_id, | ||||
|     events::room::{ | ||||
|         encrypted::{ | ||||
|     events::{ | ||||
|         relation::InReplyTo, | ||||
|         room::encrypted::{ | ||||
|             EncryptedEventScheme, MegolmV1AesSha2ContentInit, Reference, Relation, Replacement, | ||||
|             RoomEncryptedEventContent, Thread, | ||||
|         }, | ||||
|         message::InReplyTo, | ||||
|     }, | ||||
| }; | ||||
| use serde_json::{from_value as from_json_value, json, to_value as to_json_value}; | ||||
|  | ||||
| @ -8,10 +8,9 @@ use ruma_common::{ | ||||
|     events::{ | ||||
|         file::{EncryptedContentInit, FileContentInfo, FileEventContent}, | ||||
|         message::MessageContent, | ||||
|         relation::InReplyTo, | ||||
|         room::{ | ||||
|             message::{ | ||||
|                 FileMessageEventContent, InReplyTo, MessageType, Relation, RoomMessageEventContent, | ||||
|             }, | ||||
|             message::{FileMessageEventContent, MessageType, Relation, RoomMessageEventContent}, | ||||
|             EncryptedFileInit, JsonWebKeyInit, MediaSource, | ||||
|         }, | ||||
|         AnyMessageLikeEvent, MessageLikeEvent, MessageLikeUnsigned, OriginalMessageLikeEvent, | ||||
|  | ||||
| @ -12,10 +12,9 @@ use ruma_common::{ | ||||
|             ThumbnailFileContentInfo, | ||||
|         }, | ||||
|         message::MessageContent, | ||||
|         relation::InReplyTo, | ||||
|         room::{ | ||||
|             message::{ | ||||
|                 ImageMessageEventContent, InReplyTo, MessageType, Relation, RoomMessageEventContent, | ||||
|             }, | ||||
|             message::{ImageMessageEventContent, MessageType, Relation, RoomMessageEventContent}, | ||||
|             JsonWebKeyInit, MediaSource, | ||||
|         }, | ||||
|         AnyMessageLikeEvent, MessageLikeEvent, MessageLikeUnsigned, OriginalMessageLikeEvent, | ||||
|  | ||||
| @ -8,8 +8,9 @@ use ruma_common::{ | ||||
|     events::{ | ||||
|         location::{AssetType, LocationContent, LocationEventContent, ZoomLevel, ZoomLevelError}, | ||||
|         message::MessageContent, | ||||
|         relation::InReplyTo, | ||||
|         room::message::{ | ||||
|             InReplyTo, LocationMessageEventContent, MessageType, Relation, RoomMessageEventContent, | ||||
|             LocationMessageEventContent, MessageType, Relation, RoomMessageEventContent, | ||||
|         }, | ||||
|         AnyMessageLikeEvent, MessageLikeEvent, MessageLikeUnsigned, OriginalMessageLikeEvent, | ||||
|     }, | ||||
|  | ||||
| @ -9,9 +9,8 @@ use ruma_common::{ | ||||
|         emote::EmoteEventContent, | ||||
|         message::{MessageContent, MessageEventContent, Text}, | ||||
|         notice::NoticeEventContent, | ||||
|         room::message::{ | ||||
|             EmoteMessageEventContent, InReplyTo, MessageType, Relation, RoomMessageEventContent, | ||||
|         }, | ||||
|         relation::InReplyTo, | ||||
|         room::message::{EmoteMessageEventContent, MessageType, Relation, RoomMessageEventContent}, | ||||
|         AnyMessageLikeEvent, MessageLikeEvent, MessageLikeUnsigned, OriginalMessageLikeEvent, | ||||
|     }, | ||||
|     room_id, | ||||
|  | ||||
| @ -2,7 +2,10 @@ use assert_matches::assert_matches; | ||||
| use assign::assign; | ||||
| use ruma_common::{ | ||||
|     event_id, | ||||
|     events::room::message::{InReplyTo, MessageType, Relation, RoomMessageEventContent}, | ||||
|     events::{ | ||||
|         relation::{InReplyTo, Replacement, Thread}, | ||||
|         room::message::{MessageType, Relation, RoomMessageEventContent}, | ||||
|     }, | ||||
| }; | ||||
| use serde_json::{from_value as from_json_value, json, to_value as to_json_value}; | ||||
| 
 | ||||
| @ -67,8 +70,6 @@ fn reply_serialize() { | ||||
| 
 | ||||
| #[test] | ||||
| fn replacement_serialize() { | ||||
|     use ruma_common::events::room::message::Replacement; | ||||
| 
 | ||||
|     let content = assign!( | ||||
|         RoomMessageEventContent::text_plain("<text msg>"), | ||||
|         { | ||||
| @ -148,8 +149,6 @@ fn replacement_deserialize() { | ||||
| 
 | ||||
| #[test] | ||||
| fn thread_plain_serialize() { | ||||
|     use ruma_common::events::room::message::Thread; | ||||
| 
 | ||||
|     let content = assign!( | ||||
|         RoomMessageEventContent::text_plain("<text msg>"), | ||||
|         { | ||||
| @ -200,8 +199,6 @@ fn thread_plain_serialize() { | ||||
| 
 | ||||
| #[test] | ||||
| fn thread_reply_serialize() { | ||||
|     use ruma_common::events::room::message::Thread; | ||||
| 
 | ||||
|     let content = assign!( | ||||
|         RoomMessageEventContent::text_plain("<text msg>"), | ||||
|         { | ||||
|  | ||||
| @ -11,10 +11,9 @@ use ruma_common::{ | ||||
|         file::{EncryptedContentInit, FileContent, FileContentInfo}, | ||||
|         image::{ThumbnailContent, ThumbnailFileContent, ThumbnailFileContentInfo}, | ||||
|         message::MessageContent, | ||||
|         relation::InReplyTo, | ||||
|         room::{ | ||||
|             message::{ | ||||
|                 InReplyTo, MessageType, Relation, RoomMessageEventContent, VideoMessageEventContent, | ||||
|             }, | ||||
|             message::{MessageType, Relation, RoomMessageEventContent, VideoMessageEventContent}, | ||||
|             JsonWebKeyInit, MediaSource, | ||||
|         }, | ||||
|         video::{VideoContent, VideoEventContent}, | ||||
|  | ||||
| @ -10,10 +10,9 @@ use ruma_common::{ | ||||
|     events::{ | ||||
|         audio::AudioContent, | ||||
|         file::{FileContent, FileContentInfo}, | ||||
|         relation::InReplyTo, | ||||
|         room::{ | ||||
|             message::{ | ||||
|                 AudioMessageEventContent, InReplyTo, MessageType, Relation, RoomMessageEventContent, | ||||
|             }, | ||||
|             message::{AudioMessageEventContent, MessageType, Relation, RoomMessageEventContent}, | ||||
|             MediaSource, | ||||
|         }, | ||||
|         voice::{VoiceContent, VoiceEventContent}, | ||||
|  | ||||
| @ -1,7 +1,10 @@ | ||||
| use assert_matches::assert_matches; | ||||
| use ruma_common::{ | ||||
|     event_id, | ||||
|     events::room::message::{InReplyTo, MessageType, Relation, RoomMessageEventContent}, | ||||
|     events::{ | ||||
|         relation::InReplyTo, | ||||
|         room::message::{MessageType, Relation, RoomMessageEventContent}, | ||||
|     }, | ||||
| }; | ||||
| use serde_json::{from_value as from_json_value, json, to_value as to_json_value}; | ||||
| 
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user