Add to_*_event_stub methods to pdu, filter for correct event kind
When creating some responses (sync) an AnyRoomEventStub is needed for this PduEvent will deserialize the JSON as a Stub event and a non stub event when needed. Ephemeral and account events are checked to be the correct type and filtered out if not. This requires an extra `deserialize` call which could/should be removed. TODO: Possibly get rid of EventJson in some places.
This commit is contained in:
		
							parent
							
								
									7c38e53839
								
							
						
					
					
						commit
						24b6702047
					
				
					 3 changed files with 136 additions and 102 deletions
				
			
		|  | @ -76,7 +76,7 @@ const TOKEN_LENGTH: usize = 256; | |||
| const MXC_LENGTH: usize = 256; | ||||
| const SESSION_ID_LENGTH: usize = 256; | ||||
| 
 | ||||
| // #[get("/_matrix/client/versions")]
 | ||||
| #[get("/_matrix/client/versions")] | ||||
| pub fn get_supported_versions_route() -> ConduitResult<get_supported_versions::Response> { | ||||
|     let mut unstable_features = BTreeMap::new(); | ||||
| 
 | ||||
|  | @ -89,7 +89,7 @@ pub fn get_supported_versions_route() -> ConduitResult<get_supported_versions::R | |||
|     .into()) | ||||
| } | ||||
| 
 | ||||
| // #[get("/_matrix/client/r0/register/available", data = "<body>")]
 | ||||
| #[get("/_matrix/client/r0/register/available", data = "<body>")] | ||||
| pub fn get_register_available_route( | ||||
|     db: State<'_, Database>, | ||||
|     body: Ruma<get_username_availability::Request>, | ||||
|  | @ -119,7 +119,7 @@ pub fn get_register_available_route( | |||
|     Ok(get_username_availability::Response { available: true }.into()) | ||||
| } | ||||
| 
 | ||||
| // #[post("/_matrix/client/r0/register", data = "<body>")]
 | ||||
| #[post("/_matrix/client/r0/register", data = "<body>")] | ||||
| pub fn register_route( | ||||
|     db: State<'_, Database>, | ||||
|     body: Ruma<register::Request>, | ||||
|  | @ -225,7 +225,7 @@ pub fn register_route( | |||
|     .into()) | ||||
| } | ||||
| 
 | ||||
| // #[get("/_matrix/client/r0/login")]
 | ||||
| #[get("/_matrix/client/r0/login")] | ||||
| pub fn get_login_route() -> ConduitResult<get_login_types::Response> { | ||||
|     Ok(get_login_types::Response { | ||||
|         flows: vec![get_login_types::LoginType::Password], | ||||
|  | @ -233,7 +233,7 @@ pub fn get_login_route() -> ConduitResult<get_login_types::Response> { | |||
|     .into()) | ||||
| } | ||||
| 
 | ||||
| // #[post("/_matrix/client/r0/login", data = "<body>")]
 | ||||
| #[post("/_matrix/client/r0/login", data = "<body>")] | ||||
| pub fn login_route( | ||||
|     db: State<'_, Database>, | ||||
|     body: Ruma<login::Request>, | ||||
|  | @ -291,7 +291,7 @@ pub fn login_route( | |||
|     .into()) | ||||
| } | ||||
| 
 | ||||
| // #[post("/_matrix/client/r0/logout", data = "<body>")]
 | ||||
| #[post("/_matrix/client/r0/logout", data = "<body>")] | ||||
| pub fn logout_route( | ||||
|     db: State<'_, Database>, | ||||
|     body: Ruma<logout::Request>, | ||||
|  | @ -472,7 +472,7 @@ pub fn get_capabilities_route() -> ConduitResult<get_capabilities::Response> { | |||
|     .into()) | ||||
| } | ||||
| 
 | ||||
| // #[get("/_matrix/client/r0/pushrules", data = "<body>")]
 | ||||
| #[get("/_matrix/client/r0/pushrules", data = "<body>")] | ||||
| pub fn get_pushrules_all_route( | ||||
|     db: State<'_, Database>, | ||||
|     body: Ruma<get_pushrules_all::Request>, | ||||
|  | @ -514,7 +514,7 @@ pub fn set_pushrule_route( | |||
|     Ok(set_pushrule::Response.into()) | ||||
| } | ||||
| 
 | ||||
| // #[put("/_matrix/client/r0/pushrules/<_scope>/<_kind>/<_rule_id>/enabled")]
 | ||||
| #[put("/_matrix/client/r0/pushrules/<_scope>/<_kind>/<_rule_id>/enabled")] | ||||
| pub fn set_pushrule_enabled_route( | ||||
|     _scope: String, | ||||
|     _kind: String, | ||||
|  | @ -525,7 +525,7 @@ pub fn set_pushrule_enabled_route( | |||
|     Ok(set_pushrule_enabled::Response.into()) | ||||
| } | ||||
| 
 | ||||
| // #[get("/_matrix/client/r0/user/<_user_id>/filter/<_filter_id>")]
 | ||||
| #[get("/_matrix/client/r0/user/<_user_id>/filter/<_filter_id>")] | ||||
| pub fn get_filter_route( | ||||
|     _user_id: String, | ||||
|     _filter_id: String, | ||||
|  | @ -543,7 +543,7 @@ pub fn get_filter_route( | |||
|     .into()) | ||||
| } | ||||
| 
 | ||||
| // #[post("/_matrix/client/r0/user/<_user_id>/filter")]
 | ||||
| #[post("/_matrix/client/r0/user/<_user_id>/filter")] | ||||
| pub fn create_filter_route(_user_id: String) -> ConduitResult<create_filter::Response> { | ||||
|     // TODO
 | ||||
|     Ok(create_filter::Response { | ||||
|  | @ -552,10 +552,10 @@ pub fn create_filter_route(_user_id: String) -> ConduitResult<create_filter::Res | |||
|     .into()) | ||||
| } | ||||
| 
 | ||||
| // #[put(
 | ||||
| //     "/_matrix/client/r0/user/<_user_id>/account_data/<_type>",
 | ||||
| //     data = "<body>"
 | ||||
| // )]
 | ||||
| #[put(
 | ||||
|     "/_matrix/client/r0/user/<_user_id>/account_data/<_type>", | ||||
|     data = "<body>" | ||||
| )] | ||||
| pub fn set_global_account_data_route( | ||||
|     db: State<'_, Database>, | ||||
|     body: Ruma<set_global_account_data::Request>, | ||||
|  | @ -581,10 +581,10 @@ pub fn set_global_account_data_route( | |||
|     Ok(set_global_account_data::Response.into()) | ||||
| } | ||||
| 
 | ||||
| // #[get(
 | ||||
| //     "/_matrix/client/r0/user/<_user_id>/account_data/<_type>",
 | ||||
| //     data = "<body>"
 | ||||
| // )]
 | ||||
| #[get(
 | ||||
|     "/_matrix/client/r0/user/<_user_id>/account_data/<_type>", | ||||
|     data = "<body>" | ||||
| )] | ||||
| pub fn get_global_account_data_route( | ||||
|     db: State<'_, Database>, | ||||
|     body: Ruma<get_global_account_data::Request>, | ||||
|  | @ -614,7 +614,7 @@ pub fn get_global_account_data_route( | |||
|     } | ||||
| } | ||||
| 
 | ||||
| // #[put("/_matrix/client/r0/profile/<_user_id>/displayname", data = "<body>")]
 | ||||
| #[put("/_matrix/client/r0/profile/<_user_id>/displayname", data = "<body>")] | ||||
| pub fn set_displayname_route( | ||||
|     db: State<'_, Database>, | ||||
|     body: Ruma<set_display_name::Request>, | ||||
|  | @ -680,7 +680,7 @@ pub fn set_displayname_route( | |||
|     Ok(set_display_name::Response.into()) | ||||
| } | ||||
| 
 | ||||
| // #[get("/_matrix/client/r0/profile/<_user_id>/displayname", data = "<body>")]
 | ||||
| #[get("/_matrix/client/r0/profile/<_user_id>/displayname", data = "<body>")] | ||||
| pub fn get_displayname_route( | ||||
|     db: State<'_, Database>, | ||||
|     body: Ruma<get_display_name::Request>, | ||||
|  | @ -693,7 +693,7 @@ pub fn get_displayname_route( | |||
|     .into()) | ||||
| } | ||||
| 
 | ||||
| // #[put("/_matrix/client/r0/profile/<_user_id>/avatar_url", data = "<body>")]
 | ||||
| #[put("/_matrix/client/r0/profile/<_user_id>/avatar_url", data = "<body>")] | ||||
| pub fn set_avatar_url_route( | ||||
|     db: State<'_, Database>, | ||||
|     body: Ruma<set_avatar_url::Request>, | ||||
|  | @ -770,7 +770,7 @@ pub fn set_avatar_url_route( | |||
|     Ok(set_avatar_url::Response.into()) | ||||
| } | ||||
| 
 | ||||
| // #[get("/_matrix/client/r0/profile/<_user_id>/avatar_url", data = "<body>")]
 | ||||
| #[get("/_matrix/client/r0/profile/<_user_id>/avatar_url", data = "<body>")] | ||||
| pub fn get_avatar_url_route( | ||||
|     db: State<'_, Database>, | ||||
|     body: Ruma<get_avatar_url::Request>, | ||||
|  | @ -783,7 +783,7 @@ pub fn get_avatar_url_route( | |||
|     .into()) | ||||
| } | ||||
| 
 | ||||
| // #[get("/_matrix/client/r0/profile/<_user_id>", data = "<body>")]
 | ||||
| #[get("/_matrix/client/r0/profile/<_user_id>", data = "<body>")] | ||||
| pub fn get_profile_route( | ||||
|     db: State<'_, Database>, | ||||
|     body: Ruma<get_profile::Request>, | ||||
|  | @ -808,7 +808,7 @@ pub fn get_profile_route( | |||
|     .into()) | ||||
| } | ||||
| 
 | ||||
| // #[put("/_matrix/client/r0/presence/<_user_id>/status", data = "<body>")]
 | ||||
| #[put("/_matrix/client/r0/presence/<_user_id>/status", data = "<body>")] | ||||
| pub fn set_presence_route( | ||||
|     db: State<'_, Database>, | ||||
|     body: Ruma<set_presence::Request>, | ||||
|  | @ -838,7 +838,7 @@ pub fn set_presence_route( | |||
|     Ok(set_presence::Response.into()) | ||||
| } | ||||
| 
 | ||||
| // #[post("/_matrix/client/r0/keys/upload", data = "<body>")]
 | ||||
| #[post("/_matrix/client/r0/keys/upload", data = "<body>")] | ||||
| pub fn upload_keys_route( | ||||
|     db: State<'_, Database>, | ||||
|     body: Ruma<upload_keys::Request>, | ||||
|  | @ -867,7 +867,7 @@ pub fn upload_keys_route( | |||
|     .into()) | ||||
| } | ||||
| 
 | ||||
| // #[post("/_matrix/client/r0/keys/query", data = "<body>")]
 | ||||
| #[post("/_matrix/client/r0/keys/query", data = "<body>")] | ||||
| pub fn get_keys_route( | ||||
|     db: State<'_, Database>, | ||||
|     body: Ruma<get_keys::Request>, | ||||
|  | @ -944,7 +944,7 @@ pub fn get_keys_route( | |||
|     .into()) | ||||
| } | ||||
| 
 | ||||
| // #[post("/_matrix/client/r0/keys/claim", data = "<body>")]
 | ||||
| #[post("/_matrix/client/r0/keys/claim", data = "<body>")] | ||||
| pub fn claim_keys_route( | ||||
|     db: State<'_, Database>, | ||||
|     body: Ruma<claim_keys::Request>, | ||||
|  | @ -1155,10 +1155,10 @@ pub fn set_read_marker_route( | |||
|     Ok(set_read_marker::Response.into()) | ||||
| } | ||||
| 
 | ||||
| // #[put(
 | ||||
| //     "/_matrix/client/r0/rooms/<_room_id>/typing/<_user_id>",
 | ||||
| //     data = "<body>"
 | ||||
| // )]
 | ||||
| #[put(
 | ||||
|     "/_matrix/client/r0/rooms/<_room_id>/typing/<_user_id>", | ||||
|     data = "<body>" | ||||
| )] | ||||
| pub fn create_typing_event_route( | ||||
|     db: State<'_, Database>, | ||||
|     body: Ruma<create_typing_event::Request>, | ||||
|  | @ -1184,7 +1184,7 @@ pub fn create_typing_event_route( | |||
|     Ok(create_typing_event::Response.into()) | ||||
| } | ||||
| 
 | ||||
| // #[post("/_matrix/client/r0/createRoom", data = "<body>")]
 | ||||
| #[post("/_matrix/client/r0/createRoom", data = "<body>")] | ||||
| pub fn create_room_route( | ||||
|     db: State<'_, Database>, | ||||
|     body: Ruma<create_room::Request>, | ||||
|  | @ -1448,10 +1448,10 @@ pub fn create_room_route( | |||
|     Ok(create_room::Response { room_id }.into()) | ||||
| } | ||||
| 
 | ||||
| // #[put(
 | ||||
| //     "/_matrix/client/r0/rooms/<_room_id>/redact/<_event_id>/<_txn_id>",
 | ||||
| //     data = "<body>"
 | ||||
| // )]
 | ||||
| #[put(
 | ||||
|     "/_matrix/client/r0/rooms/<_room_id>/redact/<_event_id>/<_txn_id>", | ||||
|     data = "<body>" | ||||
| )] | ||||
| pub fn redact_event_route( | ||||
|     db: State<'_, Database>, | ||||
|     body: Ruma<redact_event::Request>, | ||||
|  | @ -1478,7 +1478,7 @@ pub fn redact_event_route( | |||
|     Ok(redact_event::Response { event_id }.into()) | ||||
| } | ||||
| 
 | ||||
| // #[put("/_matrix/client/r0/directory/room/<_room_alias>", data = "<body>")]
 | ||||
| #[put("/_matrix/client/r0/directory/room/<_room_alias>", data = "<body>")] | ||||
| pub fn create_alias_route( | ||||
|     db: State<'_, Database>, | ||||
|     body: Ruma<create_alias::Request>, | ||||
|  | @ -1494,7 +1494,7 @@ pub fn create_alias_route( | |||
|     Ok(create_alias::Response.into()) | ||||
| } | ||||
| 
 | ||||
| // #[delete("/_matrix/client/r0/directory/room/<_room_alias>", data = "<body>")]
 | ||||
| #[delete("/_matrix/client/r0/directory/room/<_room_alias>", data = "<body>")] | ||||
| pub fn delete_alias_route( | ||||
|     db: State<'_, Database>, | ||||
|     body: Ruma<delete_alias::Request>, | ||||
|  | @ -1505,7 +1505,7 @@ pub fn delete_alias_route( | |||
|     Ok(delete_alias::Response.into()) | ||||
| } | ||||
| 
 | ||||
| // #[get("/_matrix/client/r0/directory/room/<_room_alias>", data = "<body>")]
 | ||||
| #[get("/_matrix/client/r0/directory/room/<_room_alias>", data = "<body>")] | ||||
| pub fn get_alias_route( | ||||
|     db: State<'_, Database>, | ||||
|     body: Ruma<get_alias::Request>, | ||||
|  | @ -1530,7 +1530,7 @@ pub fn get_alias_route( | |||
|     .into()) | ||||
| } | ||||
| 
 | ||||
| // #[post("/_matrix/client/r0/rooms/<_room_id>/join", data = "<body>")]
 | ||||
| #[post("/_matrix/client/r0/rooms/<_room_id>/join", data = "<body>")] | ||||
| pub fn join_room_by_id_route( | ||||
|     db: State<'_, Database>, | ||||
|     body: Ruma<join_room_by_id::Request>, | ||||
|  | @ -1565,7 +1565,7 @@ pub fn join_room_by_id_route( | |||
|     .into()) | ||||
| } | ||||
| 
 | ||||
| // #[post("/_matrix/client/r0/join/<_room_id_or_alias>", data = "<body>")]
 | ||||
| #[post("/_matrix/client/r0/join/<_room_id_or_alias>", data = "<body>")] | ||||
| pub fn join_room_by_id_or_alias_route( | ||||
|     db: State<'_, Database>, | ||||
|     body: Ruma<join_room_by_id_or_alias::Request>, | ||||
|  | @ -1594,7 +1594,7 @@ pub fn join_room_by_id_or_alias_route( | |||
|     .into()) | ||||
| } | ||||
| 
 | ||||
| // #[post("/_matrix/client/r0/rooms/<_room_id>/leave", data = "<body>")]
 | ||||
| #[post("/_matrix/client/r0/rooms/<_room_id>/leave", data = "<body>")] | ||||
| pub fn leave_room_route( | ||||
|     db: State<'_, Database>, | ||||
|     body: Ruma<leave_room::Request>, | ||||
|  | @ -1632,7 +1632,7 @@ pub fn leave_room_route( | |||
|     Ok(leave_room::Response.into()) | ||||
| } | ||||
| 
 | ||||
| // #[post("/_matrix/client/r0/rooms/<_room_id>/kick", data = "<body>")]
 | ||||
| #[post("/_matrix/client/r0/rooms/<_room_id>/kick", data = "<body>")] | ||||
| pub fn kick_user_route( | ||||
|     db: State<'_, Database>, | ||||
|     body: Ruma<kick_user::Request>, | ||||
|  | @ -1672,7 +1672,7 @@ pub fn kick_user_route( | |||
|     Ok(kick_user::Response.into()) | ||||
| } | ||||
| 
 | ||||
| // #[post("/_matrix/client/r0/rooms/<_room_id>/ban", data = "<body>")]
 | ||||
| #[post("/_matrix/client/r0/rooms/<_room_id>/ban", data = "<body>")] | ||||
| pub fn ban_user_route( | ||||
|     db: State<'_, Database>, | ||||
|     body: Ruma<ban_user::Request>, | ||||
|  | @ -1719,7 +1719,7 @@ pub fn ban_user_route( | |||
|     Ok(ban_user::Response.into()) | ||||
| } | ||||
| 
 | ||||
| // #[post("/_matrix/client/r0/rooms/<_room_id>/unban", data = "<body>")]
 | ||||
| #[post("/_matrix/client/r0/rooms/<_room_id>/unban", data = "<body>")] | ||||
| pub fn unban_user_route( | ||||
|     db: State<'_, Database>, | ||||
|     body: Ruma<unban_user::Request>, | ||||
|  | @ -1758,7 +1758,7 @@ pub fn unban_user_route( | |||
|     Ok(unban_user::Response.into()) | ||||
| } | ||||
| 
 | ||||
| // #[post("/_matrix/client/r0/rooms/<_room_id>/forget", data = "<body>")]
 | ||||
| #[post("/_matrix/client/r0/rooms/<_room_id>/forget", data = "<body>")] | ||||
| pub fn forget_room_route( | ||||
|     db: State<'_, Database>, | ||||
|     body: Ruma<forget_room::Request>, | ||||
|  | @ -1771,7 +1771,7 @@ pub fn forget_room_route( | |||
|     Ok(forget_room::Response.into()) | ||||
| } | ||||
| 
 | ||||
| // #[post("/_matrix/client/r0/rooms/<_room_id>/invite", data = "<body>")]
 | ||||
| #[post("/_matrix/client/r0/rooms/<_room_id>/invite", data = "<body>")] | ||||
| pub fn invite_user_route( | ||||
|     db: State<'_, Database>, | ||||
|     body: Ruma<invite_user::Request>, | ||||
|  | @ -1802,7 +1802,7 @@ pub fn invite_user_route( | |||
|     } | ||||
| } | ||||
| 
 | ||||
| // #[put("/_matrix/client/r0/directory/list/room/<_room_id>", data = "<body>")]
 | ||||
| #[put("/_matrix/client/r0/directory/list/room/<_room_id>", data = "<body>")] | ||||
| pub async fn set_room_visibility_route( | ||||
|     db: State<'_, Database>, | ||||
|     body: Ruma<set_room_visibility::Request>, | ||||
|  | @ -1816,7 +1816,7 @@ pub async fn set_room_visibility_route( | |||
|     Ok(set_room_visibility::Response.into()) | ||||
| } | ||||
| 
 | ||||
| // #[get("/_matrix/client/r0/directory/list/room/<_room_id>", data = "<body>")]
 | ||||
| #[get("/_matrix/client/r0/directory/list/room/<_room_id>", data = "<body>")] | ||||
| pub async fn get_room_visibility_route( | ||||
|     db: State<'_, Database>, | ||||
|     body: Ruma<get_room_visibility::Request>, | ||||
|  | @ -1832,7 +1832,7 @@ pub async fn get_room_visibility_route( | |||
|     .into()) | ||||
| } | ||||
| 
 | ||||
| // #[get("/_matrix/client/r0/publicRooms", data = "<body>")]
 | ||||
| #[get("/_matrix/client/r0/publicRooms", data = "<body>")] | ||||
| pub async fn get_public_rooms_route( | ||||
|     db: State<'_, Database>, | ||||
|     body: Ruma<get_public_rooms::Request>, | ||||
|  | @ -1881,7 +1881,7 @@ pub async fn get_public_rooms_route( | |||
|     .into()) | ||||
| } | ||||
| 
 | ||||
| // #[post("/_matrix/client/r0/publicRooms", data = "<body>")]
 | ||||
| #[post("/_matrix/client/r0/publicRooms", data = "<body>")] | ||||
| pub async fn get_public_rooms_filtered_route( | ||||
|     db: State<'_, Database>, | ||||
|     body: Ruma<get_public_rooms_filtered::Request>, | ||||
|  | @ -1993,7 +1993,7 @@ pub async fn get_public_rooms_filtered_route( | |||
|     .into()) | ||||
| } | ||||
| 
 | ||||
| // #[post("/_matrix/client/r0/user_directory/search", data = "<body>")]
 | ||||
| #[post("/_matrix/client/r0/user_directory/search", data = "<body>")] | ||||
| pub fn search_users_route( | ||||
|     db: State<'_, Database>, | ||||
|     body: Ruma<search_users::Request>, | ||||
|  | @ -2059,7 +2059,7 @@ pub fn get_member_events_route( | |||
|     .into()) | ||||
| } | ||||
| 
 | ||||
| // #[get("/_matrix/client/r0/thirdparty/protocols")]
 | ||||
| #[get("/_matrix/client/r0/thirdparty/protocols")] | ||||
| pub fn get_protocols_route() -> ConduitResult<get_protocols::Response> { | ||||
|     warn!("TODO: get_protocols_route"); | ||||
|     Ok(get_protocols::Response { | ||||
|  | @ -2133,7 +2133,7 @@ pub fn create_message_event_route( | |||
| } | ||||
| 
 | ||||
| #[put(
 | ||||
|     // "/_matrix/client/r0/rooms/<_room_id>/state/<_event_type>/<_state_key>",
 | ||||
|     "/_matrix/client/r0/rooms/<_room_id>/state/<_event_type>/<_state_key>", | ||||
|     data = "<body>" | ||||
| )] | ||||
| pub fn create_state_event_for_key_route( | ||||
|  | @ -2194,10 +2194,10 @@ pub fn create_state_event_for_key_route( | |||
|     Ok(create_state_event_for_key::Response { event_id }.into()) | ||||
| } | ||||
| 
 | ||||
| // #[put(
 | ||||
| //     "/_matrix/client/r0/rooms/<_room_id>/state/<_event_type>",
 | ||||
| //     data = "<body>"
 | ||||
| // )]
 | ||||
| #[put(
 | ||||
|     "/_matrix/client/r0/rooms/<_room_id>/state/<_event_type>", | ||||
|     data = "<body>" | ||||
| )] | ||||
| pub fn create_state_event_for_empty_key_route( | ||||
|     db: State<'_, Database>, | ||||
|     body: Ruma<create_state_event_for_empty_key::Request>, | ||||
|  | @ -2241,7 +2241,7 @@ pub fn create_state_event_for_empty_key_route( | |||
|     .into()) | ||||
| } | ||||
| 
 | ||||
| // #[get("/_matrix/client/r0/rooms/<_room_id>/state", data = "<body>")]
 | ||||
| #[get("/_matrix/client/r0/rooms/<_room_id>/state", data = "<body>")] | ||||
| pub fn get_state_events_route( | ||||
|     db: State<'_, Database>, | ||||
|     body: Ruma<get_state_events::Request>, | ||||
|  | @ -2267,10 +2267,10 @@ pub fn get_state_events_route( | |||
|     .into()) | ||||
| } | ||||
| 
 | ||||
| // #[get(
 | ||||
| //     "/_matrix/client/r0/rooms/<_room_id>/state/<_event_type>/<_state_key>",
 | ||||
| //     data = "<body>"
 | ||||
| // )]
 | ||||
| #[get(
 | ||||
|     "/_matrix/client/r0/rooms/<_room_id>/state/<_event_type>/<_state_key>", | ||||
|     data = "<body>" | ||||
| )] | ||||
| pub fn get_state_events_for_key_route( | ||||
|     db: State<'_, Database>, | ||||
|     body: Ruma<get_state_events_for_key::Request>, | ||||
|  | @ -2302,10 +2302,10 @@ pub fn get_state_events_for_key_route( | |||
|     .into()) | ||||
| } | ||||
| 
 | ||||
| // #[get(
 | ||||
| //     "/_matrix/client/r0/rooms/<_room_id>/state/<_event_type>",
 | ||||
| //     data = "<body>"
 | ||||
| // )]
 | ||||
| #[get(
 | ||||
|     "/_matrix/client/r0/rooms/<_room_id>/state/<_event_type>", | ||||
|     data = "<body>" | ||||
| )] | ||||
| pub fn get_state_events_for_empty_key_route( | ||||
|     db: State<'_, Database>, | ||||
|     body: Ruma<get_state_events_for_empty_key::Request>, | ||||
|  | @ -2336,7 +2336,7 @@ pub fn get_state_events_for_empty_key_route( | |||
|     .into()) | ||||
| } | ||||
| 
 | ||||
| // #[get("/_matrix/client/r0/sync", data = "<body>")]
 | ||||
| #[get("/_matrix/client/r0/sync", data = "<body>")] | ||||
| pub fn sync_route( | ||||
|     db: State<'_, Database>, | ||||
|     body: Ruma<sync_events::Request>, | ||||
|  | @ -2513,7 +2513,7 @@ pub fn sync_route( | |||
| 
 | ||||
|         let room_events = pdus | ||||
|             .into_iter() | ||||
|             .map(|pdu| pdu.to_room_event()) | ||||
|             .map(|pdu| pdu.to_room_event_stub()) | ||||
|             .collect::<Vec<_>>(); | ||||
| 
 | ||||
|         let mut edus = db | ||||
|  | @ -2521,6 +2521,14 @@ pub fn sync_route( | |||
|             .edus | ||||
|             .roomlatests_since(&room_id, since)? | ||||
|             .filter_map(|r| r.ok()) // Filter out buggy events
 | ||||
|             .filter_map(|r| { | ||||
|                 if let Ok(EduEvent::Ephemeral(ev)) = r.deserialize() { | ||||
|                     // TODO we could get rid of EventJson?
 | ||||
|                     Some(EventJson::from(ev)) | ||||
|                 } else { | ||||
|                     None | ||||
|                 } | ||||
|             }) | ||||
|             .collect::<Vec<_>>(); | ||||
| 
 | ||||
|         if db | ||||
|  | @ -2579,7 +2587,7 @@ pub fn sync_route( | |||
|                     db.rooms | ||||
|                         .room_state_full(&room_id)? | ||||
|                         .into_iter() | ||||
|                         .map(|(_, pdu)| pdu.to_state_event()) | ||||
|                         .map(|(_, pdu)| pdu.to_state_event_stub()) | ||||
|                         .collect() | ||||
|                 } else { | ||||
|                     Vec::new() | ||||
|  | @ -2599,7 +2607,7 @@ pub fn sync_route( | |||
|         let pdus = db.rooms.pdus_since(&user_id, &room_id, since)?; | ||||
|         let room_events = pdus | ||||
|             .filter_map(|pdu| pdu.ok()) // Filter out buggy events
 | ||||
|             .map(|pdu| pdu.to_room_event()) | ||||
|             .map(|pdu| pdu.to_room_event_stub()) | ||||
|             .collect(); | ||||
| 
 | ||||
|         // TODO: Only until leave point
 | ||||
|  | @ -2608,6 +2616,14 @@ pub fn sync_route( | |||
|             .edus | ||||
|             .roomlatests_since(&room_id, since)? | ||||
|             .filter_map(|r| r.ok()) // Filter out buggy events
 | ||||
|             .filter_map(|r| { | ||||
|                 if let Ok(EduEvent::Ephemeral(ev)) = r.deserialize() { | ||||
|                     // TODO we could get rid of EventJson?
 | ||||
|                     Some(EventJson::from(ev)) | ||||
|                 } else { | ||||
|                     None | ||||
|                 } | ||||
|             }) | ||||
|             .collect::<Vec<_>>(); | ||||
| 
 | ||||
|         if db | ||||
|  | @ -2618,9 +2634,9 @@ pub fn sync_route( | |||
|         { | ||||
|             edus.push( | ||||
|                 serde_json::from_str( | ||||
|                     &serde_json::to_string(&EduEvent::Typing( | ||||
|                     &serde_json::to_string(&EduEvent::Ephemeral(AnyEphemeralRoomEvent::Typing( | ||||
|                         db.rooms.edus.roomactives_all(&room_id)?, | ||||
|                     )) | ||||
|                     ))) | ||||
|                     .expect("event is valid, we just created it"), | ||||
|                 ) | ||||
|                 .expect("event is valid, we just created it"), | ||||
|  | @ -2694,7 +2710,13 @@ pub fn sync_route( | |||
|                 .account_data | ||||
|                 .changes_since(None, &user_id, since)? | ||||
|                 .into_iter() | ||||
|                 .map(|(_, v)| v) | ||||
|                 .flat_map(|(_, v)| { | ||||
|                     if let Some(EduEvent::Basic(account_event)) = v.deserialize().ok() { | ||||
|                         Some(EventJson::from(account_event)) | ||||
|                     } else { | ||||
|                         None | ||||
|                     } | ||||
|                 }) | ||||
|                 .collect(), | ||||
|         }, | ||||
|         device_lists: sync_events::DeviceLists { | ||||
|  | @ -2716,10 +2738,10 @@ pub fn sync_route( | |||
|     .into()) | ||||
| } | ||||
| 
 | ||||
| // #[get(
 | ||||
| //     "/_matrix/client/r0/rooms/<_room_id>/context/<_event_id>",
 | ||||
| //     data = "<body>"
 | ||||
| // )]
 | ||||
| #[get(
 | ||||
|     "/_matrix/client/r0/rooms/<_room_id>/context/<_event_id>", | ||||
|     data = "<body>" | ||||
| )] | ||||
| pub fn get_context_route( | ||||
|     db: State<'_, Database>, | ||||
|     body: Ruma<get_context::Request>, | ||||
|  | @ -2817,7 +2839,7 @@ pub fn get_context_route( | |||
|     .into()) | ||||
| } | ||||
| 
 | ||||
| // #[get("/_matrix/client/r0/rooms/<_room_id>/messages", data = "<body>")]
 | ||||
| #[get("/_matrix/client/r0/rooms/<_room_id>/messages", data = "<body>")] | ||||
| pub fn get_message_events_route( | ||||
|     db: State<'_, Database>, | ||||
|     body: Ruma<get_message_events::Request>, | ||||
|  | @ -2913,7 +2935,7 @@ pub fn get_message_events_route( | |||
|     } | ||||
| } | ||||
| 
 | ||||
| // #[get("/_matrix/client/r0/voip/turnServer")]
 | ||||
| #[get("/_matrix/client/r0/voip/turnServer")] | ||||
| pub fn turn_server_route() -> ConduitResult<create_message_event::Response> { | ||||
|     Err(Error::BadRequest( | ||||
|         ErrorKind::NotFound, | ||||
|  | @ -2921,7 +2943,7 @@ pub fn turn_server_route() -> ConduitResult<create_message_event::Response> { | |||
|     )) | ||||
| } | ||||
| 
 | ||||
| // #[post("/_matrix/client/r0/publicised_groups")]
 | ||||
| #[post("/_matrix/client/r0/publicised_groups")] | ||||
| pub fn publicised_groups_route() -> ConduitResult<create_message_event::Response> { | ||||
|     Err(Error::BadRequest( | ||||
|         ErrorKind::NotFound, | ||||
|  | @ -2929,10 +2951,10 @@ pub fn publicised_groups_route() -> ConduitResult<create_message_event::Response | |||
|     )) | ||||
| } | ||||
| 
 | ||||
| // #[put(
 | ||||
| //     "/_matrix/client/r0/sendToDevice/<_event_type>/<_txn_id>",
 | ||||
| //     data = "<body>"
 | ||||
| // )]
 | ||||
| #[put(
 | ||||
|     "/_matrix/client/r0/sendToDevice/<_event_type>/<_txn_id>", | ||||
|     data = "<body>" | ||||
| )] | ||||
| pub fn send_event_to_device_route( | ||||
|     db: State<'_, Database>, | ||||
|     body: Ruma<send_event_to_device::Request>, | ||||
|  | @ -2978,7 +3000,7 @@ pub fn send_event_to_device_route( | |||
|     Ok(send_event_to_device::Response.into()) | ||||
| } | ||||
| 
 | ||||
| // #[get("/_matrix/media/r0/config")]
 | ||||
| #[get("/_matrix/media/r0/config")] | ||||
| pub fn get_media_config_route() -> ConduitResult<get_media_config::Response> { | ||||
|     Ok(get_media_config::Response { | ||||
|         upload_size: (20_u32 * 1024 * 1024).into(), // 20 MB
 | ||||
|  | @ -2986,7 +3008,7 @@ pub fn get_media_config_route() -> ConduitResult<get_media_config::Response> { | |||
|     .into()) | ||||
| } | ||||
| 
 | ||||
| // #[post("/_matrix/media/r0/upload", data = "<body>")]
 | ||||
| #[post("/_matrix/media/r0/upload", data = "<body>")] | ||||
| pub fn create_content_route( | ||||
|     db: State<'_, Database>, | ||||
|     body: Ruma<create_content::Request>, | ||||
|  | @ -3006,10 +3028,10 @@ pub fn create_content_route( | |||
|     Ok(create_content::Response { content_uri: mxc }.into()) | ||||
| } | ||||
| 
 | ||||
| // #[get(
 | ||||
| //     "/_matrix/media/r0/download/<_server_name>/<_media_id>",
 | ||||
| //     data = "<body>"
 | ||||
| // )]
 | ||||
| #[get(
 | ||||
|     "/_matrix/media/r0/download/<_server_name>/<_media_id>", | ||||
|     data = "<body>" | ||||
| )] | ||||
| pub fn get_content_route( | ||||
|     db: State<'_, Database>, | ||||
|     body: Ruma<get_content::Request>, | ||||
|  | @ -3031,10 +3053,10 @@ pub fn get_content_route( | |||
|     } | ||||
| } | ||||
| 
 | ||||
| // #[get(
 | ||||
| //     "/_matrix/media/r0/thumbnail/<_server_name>/<_media_id>",
 | ||||
| //     data = "<body>"
 | ||||
| // )]
 | ||||
| #[get(
 | ||||
|     "/_matrix/media/r0/thumbnail/<_server_name>/<_media_id>", | ||||
|     data = "<body>" | ||||
| )] | ||||
| pub fn get_content_thumbnail_route( | ||||
|     db: State<'_, Database>, | ||||
|     body: Ruma<get_content_thumbnail::Request>, | ||||
|  | @ -3056,7 +3078,7 @@ pub fn get_content_thumbnail_route( | |||
|     } | ||||
| } | ||||
| 
 | ||||
| // #[get("/_matrix/client/r0/devices", data = "<body>")]
 | ||||
| #[get("/_matrix/client/r0/devices", data = "<body>")] | ||||
| pub fn get_devices_route( | ||||
|     db: State<'_, Database>, | ||||
|     body: Ruma<get_devices::Request>, | ||||
|  | @ -3072,7 +3094,7 @@ pub fn get_devices_route( | |||
|     Ok(get_devices::Response { devices }.into()) | ||||
| } | ||||
| 
 | ||||
| // #[get("/_matrix/client/r0/devices/<_device_id>", data = "<body>")]
 | ||||
| #[get("/_matrix/client/r0/devices/<_device_id>", data = "<body>")] | ||||
| pub fn get_device_route( | ||||
|     db: State<'_, Database>, | ||||
|     body: Ruma<get_device::Request>, | ||||
|  | @ -3088,7 +3110,7 @@ pub fn get_device_route( | |||
|     Ok(get_device::Response { device }.into()) | ||||
| } | ||||
| 
 | ||||
| // #[put("/_matrix/client/r0/devices/<_device_id>", data = "<body>")]
 | ||||
| #[put("/_matrix/client/r0/devices/<_device_id>", data = "<body>")] | ||||
| pub fn update_device_route( | ||||
|     db: State<'_, Database>, | ||||
|     body: Ruma<update_device::Request>, | ||||
|  | @ -3109,7 +3131,7 @@ pub fn update_device_route( | |||
|     Ok(update_device::Response.into()) | ||||
| } | ||||
| 
 | ||||
| // #[delete("/_matrix/client/r0/devices/<_device_id>", data = "<body>")]
 | ||||
| #[delete("/_matrix/client/r0/devices/<_device_id>", data = "<body>")] | ||||
| pub fn delete_device_route( | ||||
|     db: State<'_, Database>, | ||||
|     body: Ruma<delete_device::Request>, | ||||
|  | @ -3153,7 +3175,7 @@ pub fn delete_device_route( | |||
|     Ok(delete_device::Response.into()) | ||||
| } | ||||
| 
 | ||||
| // #[post("/_matrix/client/r0/delete_devices", data = "<body>")]
 | ||||
| #[post("/_matrix/client/r0/delete_devices", data = "<body>")] | ||||
| pub fn delete_devices_route( | ||||
|     db: State<'_, Database>, | ||||
|     body: Ruma<delete_devices::Request>, | ||||
|  |  | |||
|  | @ -62,6 +62,8 @@ impl RoomEdus { | |||
|         room_id: &RoomId, | ||||
|         since: u64, | ||||
|     ) -> Result<impl Iterator<Item = Result<EventJson<EduEvent>>>> { | ||||
|         // TODO is this                                ^^^^^^^
 | ||||
|         // only ever a read receipt could we just return EphemeralRoomEvent here?
 | ||||
|         let mut prefix = room_id.to_string().as_bytes().to_vec(); | ||||
|         prefix.push(0xff); | ||||
| 
 | ||||
|  |  | |||
							
								
								
									
										14
									
								
								src/pdu.rs
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								src/pdu.rs
									
									
									
									
									
								
							|  | @ -2,8 +2,8 @@ use crate::{Error, Result}; | |||
| use js_int::UInt; | ||||
| use ruma::{ | ||||
|     events::{ | ||||
|         pdu::EventHash, AnyRoomEvent, AnyStateEvent, AnyStrippedStateEventStub, EventJson, | ||||
|         EventType, | ||||
|         pdu::EventHash, AnyRoomEvent, AnyRoomEventStub, AnyStateEvent, AnyStateEventStub, | ||||
|         AnyStrippedStateEventStub, EventJson, EventType, | ||||
|     }, | ||||
|     identifiers::{EventId, RoomId, UserId}, | ||||
| }; | ||||
|  | @ -78,6 +78,11 @@ impl PduEvent { | |||
|         Ok(()) | ||||
|     } | ||||
| 
 | ||||
|     pub fn to_room_event_stub(&self) -> EventJson<AnyRoomEventStub> { | ||||
|         let json = serde_json::to_string(&self).expect("PDUs are always valid"); | ||||
|         serde_json::from_str::<EventJson<AnyRoomEventStub>>(&json) | ||||
|             .expect("EventJson::from_str always works") | ||||
|     } | ||||
|     pub fn to_room_event(&self) -> EventJson<AnyRoomEvent> { | ||||
|         let json = serde_json::to_string(&self).expect("PDUs are always valid"); | ||||
|         serde_json::from_str::<EventJson<AnyRoomEvent>>(&json) | ||||
|  | @ -88,6 +93,11 @@ impl PduEvent { | |||
|         serde_json::from_str::<EventJson<AnyStateEvent>>(&json) | ||||
|             .expect("EventJson::from_str always works") | ||||
|     } | ||||
|     pub fn to_state_event_stub(&self) -> EventJson<AnyStateEventStub> { | ||||
|         let json = serde_json::to_string(&self).expect("PDUs are always valid"); | ||||
|         serde_json::from_str::<EventJson<AnyStateEventStub>>(&json) | ||||
|             .expect("EventJson::from_str always works") | ||||
|     } | ||||
|     pub fn to_stripped_state_event(&self) -> EventJson<AnyStrippedStateEventStub> { | ||||
|         let json = serde_json::to_string(&self).expect("PDUs are always valid"); | ||||
|         serde_json::from_str::<EventJson<AnyStrippedStateEventStub>>(&json) | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue