events: Replace Thumbnails with a Vec
This commit is contained in:
		
							parent
							
								
									bf6687c92d
								
							
						
					
					
						commit
						e4463dda22
					
				| @ -31,8 +31,8 @@ pub struct ImageEventContent { | ||||
|     pub image: Box<ImageContent>, | ||||
| 
 | ||||
|     /// The thumbnails of the message.
 | ||||
|     #[serde(rename = "m.thumbnail", default, skip_serializing_if = "Thumbnails::is_empty")] | ||||
|     pub thumbnail: Thumbnails, | ||||
|     #[serde(rename = "m.thumbnail", default, skip_serializing_if = "Vec::is_empty")] | ||||
|     pub thumbnail: Vec<ThumbnailContent>, | ||||
| 
 | ||||
|     /// The captions of the message.
 | ||||
|     #[serde(rename = "m.caption", default, skip_serializing_if = "Captions::is_empty")] | ||||
| @ -151,31 +151,6 @@ impl ThumbnailContent { | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| /// An array of thumbnails.
 | ||||
| #[derive(Clone, Debug, Default, Serialize, Deserialize)] | ||||
| pub struct Thumbnails(pub(crate) Vec<ThumbnailContent>); | ||||
| 
 | ||||
| impl Thumbnails { | ||||
|     /// Creates a new `Thumbnails` with the given thumbnails.
 | ||||
|     ///
 | ||||
|     /// The thumbnails must be ordered by most preferred first.
 | ||||
|     pub fn new(thumbnails: &[ThumbnailContent]) -> Self { | ||||
|         Self(thumbnails.to_owned()) | ||||
|     } | ||||
| 
 | ||||
|     /// Get the thumbnails.
 | ||||
|     ///
 | ||||
|     /// The thumbnails are ordered by most preferred first.
 | ||||
|     pub fn thumbnails(&self) -> &[ThumbnailContent] { | ||||
|         &self.0 | ||||
|     } | ||||
| 
 | ||||
|     /// Whether this is empty.
 | ||||
|     pub fn is_empty(&self) -> bool { | ||||
|         self.0.is_empty() | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| /// An array of captions.
 | ||||
| #[derive(Clone, Debug, Default, Serialize, Deserialize)] | ||||
| pub struct Captions(pub(crate) Vec<Text>); | ||||
|  | ||||
| @ -10,7 +10,7 @@ use serde::{Deserialize, Serialize}; | ||||
| 
 | ||||
| use super::{ | ||||
|     file::FileContent, | ||||
|     image::{Captions, Thumbnails}, | ||||
|     image::{Captions, ThumbnailContent}, | ||||
|     message::MessageContent, | ||||
|     room::message::Relation, | ||||
| }; | ||||
| @ -33,8 +33,8 @@ pub struct VideoEventContent { | ||||
|     pub video: Box<VideoContent>, | ||||
| 
 | ||||
|     /// The thumbnails of the message.
 | ||||
|     #[serde(rename = "m.thumbnail", default, skip_serializing_if = "Thumbnails::is_empty")] | ||||
|     pub thumbnail: Thumbnails, | ||||
|     #[serde(rename = "m.thumbnail", default, skip_serializing_if = "Vec::is_empty")] | ||||
|     pub thumbnail: Vec<ThumbnailContent>, | ||||
| 
 | ||||
|     /// The captions of the message.
 | ||||
|     #[serde(rename = "m.caption", default, skip_serializing_if = "Captions::is_empty")] | ||||
|  | ||||
| @ -9,7 +9,7 @@ use ruma_common::{ | ||||
|         file::{EncryptedContentInit, FileContent, FileContentInfo}, | ||||
|         image::{ | ||||
|             Captions, ImageContent, ImageEventContent, ThumbnailContent, ThumbnailFileContent, | ||||
|             ThumbnailFileContentInfo, Thumbnails, | ||||
|             ThumbnailFileContentInfo, | ||||
|         }, | ||||
|         message::MessageContent, | ||||
|         room::{ | ||||
| @ -118,7 +118,7 @@ fn image_event_serialization() { | ||||
|             ), | ||||
|             { | ||||
|                 image: Box::new(ImageContent::with_size(uint!(1920), uint!(1080))), | ||||
|                 thumbnail: Thumbnails::new(&[ThumbnailContent::new( | ||||
|                 thumbnail: vec![ThumbnailContent::new( | ||||
|                     ThumbnailFileContent::plain( | ||||
|                         mxc_uri!("mxc://notareal.hs/thumbnail").to_owned(), | ||||
|                         Some(Box::new(assign!(ThumbnailFileContentInfo::new(), { | ||||
| @ -127,7 +127,7 @@ fn image_event_serialization() { | ||||
|                         }))) | ||||
|                     ), | ||||
|                     None | ||||
|                 )]), | ||||
|                 )], | ||||
|                 caption: Captions::plain("This is my house"), | ||||
|                 relates_to: Some(Relation::Reply { | ||||
|                     in_reply_to: InReplyTo::new(event_id!("$replyevent:example.com").to_owned()), | ||||
| @ -255,7 +255,7 @@ fn encrypted_content_deserialization() { | ||||
|             && file.encryption_info.is_some() | ||||
|             && image.width.is_none() | ||||
|             && image.height.is_none() | ||||
|             && thumbnail.thumbnails()[0].file.url == "mxc://notareal.hs/thumbnail" | ||||
|             && thumbnail[0].file.url == "mxc://notareal.hs/thumbnail" | ||||
|             && caption.is_empty() | ||||
|     ); | ||||
| } | ||||
|  | ||||
| @ -9,9 +9,7 @@ use ruma_common::{ | ||||
|     event_id, | ||||
|     events::{ | ||||
|         file::{EncryptedContentInit, FileContent, FileContentInfo}, | ||||
|         image::{ | ||||
|             Captions, ThumbnailContent, ThumbnailFileContent, ThumbnailFileContentInfo, Thumbnails, | ||||
|         }, | ||||
|         image::{Captions, ThumbnailContent, ThumbnailFileContent, ThumbnailFileContentInfo}, | ||||
|         message::MessageContent, | ||||
|         room::{ | ||||
|             message::{InReplyTo, Relation}, | ||||
| @ -127,7 +125,7 @@ fn event_serialization() { | ||||
|                         duration: Some(Duration::from_secs(15)), | ||||
|                     } | ||||
|                 )), | ||||
|                 thumbnail: Thumbnails::new(&[ThumbnailContent::new( | ||||
|                 thumbnail: vec![ThumbnailContent::new( | ||||
|                     ThumbnailFileContent::plain( | ||||
|                         mxc_uri!("mxc://notareal.hs/thumbnail").to_owned(), | ||||
|                         Some(Box::new(assign!(ThumbnailFileContentInfo::new(), { | ||||
| @ -136,7 +134,7 @@ fn event_serialization() { | ||||
|                         }))) | ||||
|                     ), | ||||
|                     None | ||||
|                 )]), | ||||
|                 )], | ||||
|                 caption: Captions::plain("This is my awesome vintage lava lamp"), | ||||
|                 relates_to: Some(Relation::Reply { | ||||
|                     in_reply_to: InReplyTo::new(event_id!("$replyevent:example.com").to_owned()), | ||||
| @ -267,7 +265,7 @@ fn encrypted_content_deserialization() { | ||||
|             && video.width.is_none() | ||||
|             && video.height.is_none() | ||||
|             && video.duration.is_none() | ||||
|             && thumbnail.thumbnails()[0].file.url == "mxc://notareal.hs/thumbnail" | ||||
|             && thumbnail[0].file.url == "mxc://notareal.hs/thumbnail" | ||||
|             && caption.is_empty() | ||||
|     ); | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user