events: Make TypingEventContent non-exhaustive and derive Default for it
This commit is contained in:
		
							parent
							
								
									624a48a724
								
							
						
					
					
						commit
						7f01a6d73b
					
				| @ -10,9 +10,17 @@ use crate::EphemeralRoomEvent; | ||||
| pub type TypingEvent = EphemeralRoomEvent<TypingEventContent>; | ||||
| 
 | ||||
| /// The payload for `TypingEvent`.
 | ||||
| #[derive(Clone, Debug, Deserialize, Serialize, EphemeralRoomEventContent)] | ||||
| #[derive(Clone, Debug, Default, Deserialize, Serialize, EphemeralRoomEventContent)] | ||||
| #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] | ||||
| #[ruma_event(type = "m.typing")] | ||||
| pub struct TypingEventContent { | ||||
|     /// The list of user IDs typing in this room, if any.
 | ||||
|     pub user_ids: Vec<UserId>, | ||||
| } | ||||
| 
 | ||||
| impl TypingEventContent { | ||||
|     /// Creates a new `TypingEventContent` with the given user IDs.
 | ||||
|     pub fn new(user_ids: Vec<UserId>) -> Self { | ||||
|         Self { user_ids } | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -15,9 +15,9 @@ use ruma_events::{ | ||||
| #[test] | ||||
| fn ephemeral_serialize_typing() { | ||||
|     let aliases_event = EphemeralRoomEvent { | ||||
|         content: AnyEphemeralRoomEventContent::Typing(TypingEventContent { | ||||
|             user_ids: vec![user_id!("@carl:example.com")], | ||||
|         }), | ||||
|         content: AnyEphemeralRoomEventContent::Typing(TypingEventContent::new(vec![user_id!( | ||||
|             "@carl:example.com" | ||||
|         )])), | ||||
|         room_id: room_id!("!roomid:room.com"), | ||||
|     }; | ||||
| 
 | ||||
| @ -49,9 +49,7 @@ fn deserialize_ephemeral_typing() { | ||||
|             .deserialize() | ||||
|             .unwrap(), | ||||
|         EphemeralRoomEvent { | ||||
|             content: AnyEphemeralRoomEventContent::Typing(TypingEventContent { | ||||
|                 user_ids, | ||||
|             }), | ||||
|             content: AnyEphemeralRoomEventContent::Typing(TypingEventContent { user_ids, .. }), | ||||
|             room_id, | ||||
|         } if user_ids[0] == user_id!("@carl:example.com") | ||||
|             && room_id == room_id!("!roomid:room.com") | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user