fix: room list over federation
This commit is contained in:
		
							parent
							
								
									c5313b3e8f
								
							
						
					
					
						commit
						4e44fedbcd
					
				
					 3 changed files with 84 additions and 64 deletions
				
			
		
							
								
								
									
										28
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										28
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							|  | @ -1635,7 +1635,7 @@ dependencies = [ | ||||||
| [[package]] | [[package]] | ||||||
| name = "ruma" | name = "ruma" | ||||||
| version = "0.0.1" | version = "0.0.1" | ||||||
| source = "git+https://github.com/timokoesters/ruma?branch=timo-fed-fixes#ee66e30cbd58aecbbfde1d7008d7d6457deef87b" | source = "git+https://github.com/timokoesters/ruma?branch=timo-fed-fixes#088382dbdc176e61fa5bde679ae38093865e7053" | ||||||
| dependencies = [ | dependencies = [ | ||||||
|  "ruma-api", |  "ruma-api", | ||||||
|  "ruma-appservice-api", |  "ruma-appservice-api", | ||||||
|  | @ -1651,7 +1651,7 @@ dependencies = [ | ||||||
| [[package]] | [[package]] | ||||||
| name = "ruma-api" | name = "ruma-api" | ||||||
| version = "0.17.0-alpha.1" | version = "0.17.0-alpha.1" | ||||||
| source = "git+https://github.com/timokoesters/ruma?branch=timo-fed-fixes#ee66e30cbd58aecbbfde1d7008d7d6457deef87b" | source = "git+https://github.com/timokoesters/ruma?branch=timo-fed-fixes#088382dbdc176e61fa5bde679ae38093865e7053" | ||||||
| dependencies = [ | dependencies = [ | ||||||
|  "http", |  "http", | ||||||
|  "percent-encoding", |  "percent-encoding", | ||||||
|  | @ -1666,7 +1666,7 @@ dependencies = [ | ||||||
| [[package]] | [[package]] | ||||||
| name = "ruma-api-macros" | name = "ruma-api-macros" | ||||||
| version = "0.17.0-alpha.1" | version = "0.17.0-alpha.1" | ||||||
| source = "git+https://github.com/timokoesters/ruma?branch=timo-fed-fixes#ee66e30cbd58aecbbfde1d7008d7d6457deef87b" | source = "git+https://github.com/timokoesters/ruma?branch=timo-fed-fixes#088382dbdc176e61fa5bde679ae38093865e7053" | ||||||
| dependencies = [ | dependencies = [ | ||||||
|  "proc-macro-crate", |  "proc-macro-crate", | ||||||
|  "proc-macro2", |  "proc-macro2", | ||||||
|  | @ -1677,7 +1677,7 @@ dependencies = [ | ||||||
| [[package]] | [[package]] | ||||||
| name = "ruma-appservice-api" | name = "ruma-appservice-api" | ||||||
| version = "0.2.0-alpha.1" | version = "0.2.0-alpha.1" | ||||||
| source = "git+https://github.com/timokoesters/ruma?branch=timo-fed-fixes#ee66e30cbd58aecbbfde1d7008d7d6457deef87b" | source = "git+https://github.com/timokoesters/ruma?branch=timo-fed-fixes#088382dbdc176e61fa5bde679ae38093865e7053" | ||||||
| dependencies = [ | dependencies = [ | ||||||
|  "ruma-api", |  "ruma-api", | ||||||
|  "ruma-common", |  "ruma-common", | ||||||
|  | @ -1690,7 +1690,7 @@ dependencies = [ | ||||||
| [[package]] | [[package]] | ||||||
| name = "ruma-client-api" | name = "ruma-client-api" | ||||||
| version = "0.10.0-alpha.1" | version = "0.10.0-alpha.1" | ||||||
| source = "git+https://github.com/timokoesters/ruma?branch=timo-fed-fixes#ee66e30cbd58aecbbfde1d7008d7d6457deef87b" | source = "git+https://github.com/timokoesters/ruma?branch=timo-fed-fixes#088382dbdc176e61fa5bde679ae38093865e7053" | ||||||
| dependencies = [ | dependencies = [ | ||||||
|  "assign", |  "assign", | ||||||
|  "http", |  "http", | ||||||
|  | @ -1709,7 +1709,7 @@ dependencies = [ | ||||||
| [[package]] | [[package]] | ||||||
| name = "ruma-common" | name = "ruma-common" | ||||||
| version = "0.2.0" | version = "0.2.0" | ||||||
| source = "git+https://github.com/timokoesters/ruma?branch=timo-fed-fixes#ee66e30cbd58aecbbfde1d7008d7d6457deef87b" | source = "git+https://github.com/timokoesters/ruma?branch=timo-fed-fixes#088382dbdc176e61fa5bde679ae38093865e7053" | ||||||
| dependencies = [ | dependencies = [ | ||||||
|  "js_int", |  "js_int", | ||||||
|  "ruma-api", |  "ruma-api", | ||||||
|  | @ -1723,7 +1723,7 @@ dependencies = [ | ||||||
| [[package]] | [[package]] | ||||||
| name = "ruma-events" | name = "ruma-events" | ||||||
| version = "0.22.0-alpha.1" | version = "0.22.0-alpha.1" | ||||||
| source = "git+https://github.com/timokoesters/ruma?branch=timo-fed-fixes#ee66e30cbd58aecbbfde1d7008d7d6457deef87b" | source = "git+https://github.com/timokoesters/ruma?branch=timo-fed-fixes#088382dbdc176e61fa5bde679ae38093865e7053" | ||||||
| dependencies = [ | dependencies = [ | ||||||
|  "js_int", |  "js_int", | ||||||
|  "ruma-common", |  "ruma-common", | ||||||
|  | @ -1738,7 +1738,7 @@ dependencies = [ | ||||||
| [[package]] | [[package]] | ||||||
| name = "ruma-events-macros" | name = "ruma-events-macros" | ||||||
| version = "0.22.0-alpha.1" | version = "0.22.0-alpha.1" | ||||||
| source = "git+https://github.com/timokoesters/ruma?branch=timo-fed-fixes#ee66e30cbd58aecbbfde1d7008d7d6457deef87b" | source = "git+https://github.com/timokoesters/ruma?branch=timo-fed-fixes#088382dbdc176e61fa5bde679ae38093865e7053" | ||||||
| dependencies = [ | dependencies = [ | ||||||
|  "proc-macro-crate", |  "proc-macro-crate", | ||||||
|  "proc-macro2", |  "proc-macro2", | ||||||
|  | @ -1749,7 +1749,7 @@ dependencies = [ | ||||||
| [[package]] | [[package]] | ||||||
| name = "ruma-federation-api" | name = "ruma-federation-api" | ||||||
| version = "0.0.3" | version = "0.0.3" | ||||||
| source = "git+https://github.com/timokoesters/ruma?branch=timo-fed-fixes#ee66e30cbd58aecbbfde1d7008d7d6457deef87b" | source = "git+https://github.com/timokoesters/ruma?branch=timo-fed-fixes#088382dbdc176e61fa5bde679ae38093865e7053" | ||||||
| dependencies = [ | dependencies = [ | ||||||
|  "js_int", |  "js_int", | ||||||
|  "ruma-api", |  "ruma-api", | ||||||
|  | @ -1764,7 +1764,7 @@ dependencies = [ | ||||||
| [[package]] | [[package]] | ||||||
| name = "ruma-identifiers" | name = "ruma-identifiers" | ||||||
| version = "0.17.4" | version = "0.17.4" | ||||||
| source = "git+https://github.com/timokoesters/ruma?branch=timo-fed-fixes#ee66e30cbd58aecbbfde1d7008d7d6457deef87b" | source = "git+https://github.com/timokoesters/ruma?branch=timo-fed-fixes#088382dbdc176e61fa5bde679ae38093865e7053" | ||||||
| dependencies = [ | dependencies = [ | ||||||
|  "rand", |  "rand", | ||||||
|  "ruma-identifiers-macros", |  "ruma-identifiers-macros", | ||||||
|  | @ -1776,7 +1776,7 @@ dependencies = [ | ||||||
| [[package]] | [[package]] | ||||||
| name = "ruma-identifiers-macros" | name = "ruma-identifiers-macros" | ||||||
| version = "0.17.4" | version = "0.17.4" | ||||||
| source = "git+https://github.com/timokoesters/ruma?branch=timo-fed-fixes#ee66e30cbd58aecbbfde1d7008d7d6457deef87b" | source = "git+https://github.com/timokoesters/ruma?branch=timo-fed-fixes#088382dbdc176e61fa5bde679ae38093865e7053" | ||||||
| dependencies = [ | dependencies = [ | ||||||
|  "proc-macro2", |  "proc-macro2", | ||||||
|  "quote", |  "quote", | ||||||
|  | @ -1787,7 +1787,7 @@ dependencies = [ | ||||||
| [[package]] | [[package]] | ||||||
| name = "ruma-identifiers-validation" | name = "ruma-identifiers-validation" | ||||||
| version = "0.1.1" | version = "0.1.1" | ||||||
| source = "git+https://github.com/timokoesters/ruma?branch=timo-fed-fixes#ee66e30cbd58aecbbfde1d7008d7d6457deef87b" | source = "git+https://github.com/timokoesters/ruma?branch=timo-fed-fixes#088382dbdc176e61fa5bde679ae38093865e7053" | ||||||
| dependencies = [ | dependencies = [ | ||||||
|  "serde", |  "serde", | ||||||
|  "strum", |  "strum", | ||||||
|  | @ -1796,7 +1796,7 @@ dependencies = [ | ||||||
| [[package]] | [[package]] | ||||||
| name = "ruma-serde" | name = "ruma-serde" | ||||||
| version = "0.2.3" | version = "0.2.3" | ||||||
| source = "git+https://github.com/timokoesters/ruma?branch=timo-fed-fixes#ee66e30cbd58aecbbfde1d7008d7d6457deef87b" | source = "git+https://github.com/timokoesters/ruma?branch=timo-fed-fixes#088382dbdc176e61fa5bde679ae38093865e7053" | ||||||
| dependencies = [ | dependencies = [ | ||||||
|  "form_urlencoded", |  "form_urlencoded", | ||||||
|  "itoa", |  "itoa", | ||||||
|  | @ -1808,7 +1808,7 @@ dependencies = [ | ||||||
| [[package]] | [[package]] | ||||||
| name = "ruma-signatures" | name = "ruma-signatures" | ||||||
| version = "0.6.0-dev.1" | version = "0.6.0-dev.1" | ||||||
| source = "git+https://github.com/timokoesters/ruma?branch=timo-fed-fixes#ee66e30cbd58aecbbfde1d7008d7d6457deef87b" | source = "git+https://github.com/timokoesters/ruma?branch=timo-fed-fixes#088382dbdc176e61fa5bde679ae38093865e7053" | ||||||
| dependencies = [ | dependencies = [ | ||||||
|  "base64", |  "base64", | ||||||
|  "ring", |  "ring", | ||||||
|  |  | ||||||
|  | @ -14,6 +14,7 @@ use ruma::{ | ||||||
|         }, |         }, | ||||||
|         federation, |         federation, | ||||||
|     }, |     }, | ||||||
|  |     directory::RoomNetwork, | ||||||
|     directory::{IncomingFilter, IncomingRoomNetwork, PublicRoomsChunk}, |     directory::{IncomingFilter, IncomingRoomNetwork, PublicRoomsChunk}, | ||||||
|     events::{ |     events::{ | ||||||
|         room::{avatar, canonical_alias, guest_access, history_visibility, name, topic}, |         room::{avatar, canonical_alias, guest_access, history_visibility, name, topic}, | ||||||
|  | @ -33,24 +34,13 @@ pub async fn get_public_rooms_filtered_route( | ||||||
|     db: State<'_, Database>, |     db: State<'_, Database>, | ||||||
|     body: Ruma<get_public_rooms_filtered::Request<'_>>, |     body: Ruma<get_public_rooms_filtered::Request<'_>>, | ||||||
| ) -> ConduitResult<get_public_rooms_filtered::Response> { | ) -> ConduitResult<get_public_rooms_filtered::Response> { | ||||||
|     let Ruma { |  | ||||||
|         body: |  | ||||||
|             get_public_rooms_filtered::IncomingRequest { |  | ||||||
|                 limit, |  | ||||||
|                 server, |  | ||||||
|                 since, |  | ||||||
|                 filter, |  | ||||||
|                 room_network, |  | ||||||
|             }, |  | ||||||
|         .. |  | ||||||
|     } = body; |  | ||||||
|     get_public_rooms_filtered_helper( |     get_public_rooms_filtered_helper( | ||||||
|         &db, |         &db, | ||||||
|         server.as_deref(), |         body.server.as_deref(), | ||||||
|         limit, |         body.limit, | ||||||
|         since.as_deref(), |         body.since.as_deref(), | ||||||
|         filter,             // This is not used yet
 |         &body.filter, | ||||||
|         Some(room_network), // This is not used
 |         &body.room_network, | ||||||
|     ) |     ) | ||||||
|     .await |     .await | ||||||
| } | } | ||||||
|  | @ -68,8 +58,8 @@ pub async fn get_public_rooms_route( | ||||||
|         body.server.as_deref(), |         body.server.as_deref(), | ||||||
|         body.limit, |         body.limit, | ||||||
|         body.since.as_deref(), |         body.since.as_deref(), | ||||||
|         None, // This is not used
 |         &IncomingFilter::default(), | ||||||
|         None, // This is not used
 |         &IncomingRoomNetwork::Matrix, | ||||||
|     ) |     ) | ||||||
|     .await? |     .await? | ||||||
|     .0; |     .0; | ||||||
|  | @ -122,8 +112,8 @@ pub async fn get_public_rooms_filtered_helper( | ||||||
|     server: Option<&ServerName>, |     server: Option<&ServerName>, | ||||||
|     limit: Option<js_int::UInt>, |     limit: Option<js_int::UInt>, | ||||||
|     since: Option<&str>, |     since: Option<&str>, | ||||||
|     _filter: Option<IncomingFilter>, |     _filter: &IncomingFilter, | ||||||
|     _network: Option<IncomingRoomNetwork>, |     _network: &IncomingRoomNetwork, | ||||||
| ) -> ConduitResult<get_public_rooms_filtered::Response> { | ) -> ConduitResult<get_public_rooms_filtered::Response> { | ||||||
|     if let Some(other_server) = server |     if let Some(other_server) = server | ||||||
|         .clone() |         .clone() | ||||||
|  | @ -135,7 +125,7 @@ pub async fn get_public_rooms_filtered_helper( | ||||||
|             federation::directory::get_public_rooms::v1::Request { |             federation::directory::get_public_rooms::v1::Request { | ||||||
|                 limit, |                 limit, | ||||||
|                 since: since.as_deref(), |                 since: since.as_deref(), | ||||||
|                 room_network: ruma::directory::RoomNetwork::Matrix, |                 room_network: RoomNetwork::Matrix, | ||||||
|             }, |             }, | ||||||
|         ) |         ) | ||||||
|         .await?; |         .await?; | ||||||
|  |  | ||||||
|  | @ -2,8 +2,8 @@ use crate::{client_server, ConduitResult, Database, Error, PduEvent, Result, Rum | ||||||
| use http::header::{HeaderValue, AUTHORIZATION}; | use http::header::{HeaderValue, AUTHORIZATION}; | ||||||
| use rocket::{get, post, put, response::content::Json, State}; | use rocket::{get, post, put, response::content::Json, State}; | ||||||
| use ruma::{ | use ruma::{ | ||||||
|  |     api::federation::directory::get_public_rooms_filtered, | ||||||
|     api::{ |     api::{ | ||||||
|         client, |  | ||||||
|         federation::{ |         federation::{ | ||||||
|             directory::get_public_rooms, |             directory::get_public_rooms, | ||||||
|             discovery::{ |             discovery::{ | ||||||
|  | @ -13,6 +13,7 @@ use ruma::{ | ||||||
|         }, |         }, | ||||||
|         OutgoingRequest, |         OutgoingRequest, | ||||||
|     }, |     }, | ||||||
|  |     directory::{IncomingFilter, IncomingRoomNetwork}, | ||||||
|     EventId, ServerName, |     EventId, ServerName, | ||||||
| }; | }; | ||||||
| use serde_json::json; | use serde_json::json; | ||||||
|  | @ -209,38 +210,24 @@ pub fn get_server_keys_deprecated(db: State<'_, Database>) -> Json<String> { | ||||||
|     feature = "conduit_bin", |     feature = "conduit_bin", | ||||||
|     post("/_matrix/federation/v1/publicRooms", data = "<body>") |     post("/_matrix/federation/v1/publicRooms", data = "<body>") | ||||||
| )] | )] | ||||||
| pub async fn get_public_rooms_route( | pub async fn get_public_rooms_filtered_route( | ||||||
|     db: State<'_, Database>, |     db: State<'_, Database>, | ||||||
|     body: Ruma<get_public_rooms::v1::Request<'_>>, |     body: Ruma<get_public_rooms_filtered::v1::Request<'_>>, | ||||||
| ) -> ConduitResult<get_public_rooms::v1::Response> { | ) -> ConduitResult<get_public_rooms_filtered::v1::Response> { | ||||||
|     let Ruma { |     let response = client_server::get_public_rooms_filtered_helper( | ||||||
|         body: |  | ||||||
|             get_public_rooms::v1::IncomingRequest { |  | ||||||
|                 room_network: _room_network, // TODO
 |  | ||||||
|                 limit, |  | ||||||
|                 since, |  | ||||||
|             }, |  | ||||||
|         .. |  | ||||||
|     } = body; |  | ||||||
| 
 |  | ||||||
|     let client::r0::directory::get_public_rooms_filtered::Response { |  | ||||||
|         chunk, |  | ||||||
|         prev_batch, |  | ||||||
|         next_batch, |  | ||||||
|         total_room_count_estimate, |  | ||||||
|     } = client_server::get_public_rooms_filtered_helper( |  | ||||||
|         &db, |         &db, | ||||||
|         None, |         None, | ||||||
|         limit, |         body.limit, | ||||||
|         since.as_deref(), |         body.since.as_deref(), | ||||||
|         None, |         &body.filter, | ||||||
|         Some(ruma::directory::IncomingRoomNetwork::Matrix), |         &body.room_network, | ||||||
|     ) |     ) | ||||||
|     .await? |     .await? | ||||||
|     .0; |     .0; | ||||||
| 
 | 
 | ||||||
|     Ok(get_public_rooms::v1::Response { |     Ok(get_public_rooms_filtered::v1::Response { | ||||||
|         chunk: chunk |         chunk: response | ||||||
|  |             .chunk | ||||||
|             .into_iter() |             .into_iter() | ||||||
|             .map(|c| { |             .map(|c| { | ||||||
|                 // Convert ruma::api::federation::directory::get_public_rooms::v1::PublicRoomsChunk
 |                 // Convert ruma::api::federation::directory::get_public_rooms::v1::PublicRoomsChunk
 | ||||||
|  | @ -255,9 +242,52 @@ pub async fn get_public_rooms_route( | ||||||
|             }) |             }) | ||||||
|             .filter_map(|r| r.ok()) |             .filter_map(|r| r.ok()) | ||||||
|             .collect(), |             .collect(), | ||||||
|         prev_batch, |         prev_batch: response.prev_batch, | ||||||
|         next_batch, |         next_batch: response.next_batch, | ||||||
|         total_room_count_estimate, |         total_room_count_estimate: response.total_room_count_estimate, | ||||||
|  |     } | ||||||
|  |     .into()) | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | #[cfg_attr(
 | ||||||
|  |     feature = "conduit_bin", | ||||||
|  |     get("/_matrix/federation/v1/publicRooms", data = "<body>") | ||||||
|  | )] | ||||||
|  | pub async fn get_public_rooms_route( | ||||||
|  |     db: State<'_, Database>, | ||||||
|  |     body: Ruma<get_public_rooms::v1::Request<'_>>, | ||||||
|  | ) -> ConduitResult<get_public_rooms::v1::Response> { | ||||||
|  |     let response = client_server::get_public_rooms_filtered_helper( | ||||||
|  |         &db, | ||||||
|  |         None, | ||||||
|  |         body.limit, | ||||||
|  |         body.since.as_deref(), | ||||||
|  |         &IncomingFilter::default(), | ||||||
|  |         &IncomingRoomNetwork::Matrix, | ||||||
|  |     ) | ||||||
|  |     .await? | ||||||
|  |     .0; | ||||||
|  | 
 | ||||||
|  |     Ok(get_public_rooms::v1::Response { | ||||||
|  |         chunk: response | ||||||
|  |             .chunk | ||||||
|  |             .into_iter() | ||||||
|  |             .map(|c| { | ||||||
|  |                 // Convert ruma::api::federation::directory::get_public_rooms::v1::PublicRoomsChunk
 | ||||||
|  |                 // to ruma::api::client::r0::directory::PublicRoomsChunk
 | ||||||
|  |                 Ok::<_, Error>( | ||||||
|  |                     serde_json::from_str( | ||||||
|  |                         &serde_json::to_string(&c) | ||||||
|  |                             .expect("PublicRoomsChunk::to_string always works"), | ||||||
|  |                     ) | ||||||
|  |                     .expect("federation and client-server PublicRoomsChunk are the same type"), | ||||||
|  |                 ) | ||||||
|  |             }) | ||||||
|  |             .filter_map(|r| r.ok()) | ||||||
|  |             .collect(), | ||||||
|  |         prev_batch: response.prev_batch, | ||||||
|  |         next_batch: response.next_batch, | ||||||
|  |         total_room_count_estimate: response.total_room_count_estimate, | ||||||
|     } |     } | ||||||
|     .into()) |     .into()) | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue