fix: ruma
This commit is contained in:
		
							parent
							
								
									d07762f596
								
							
						
					
					
						commit
						0fcefa4125
					
				
					 8 changed files with 115 additions and 66 deletions
				
			
		
							
								
								
									
										23
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										23
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							|  | @ -2015,7 +2015,6 @@ dependencies = [ | ||||||
| [[package]] | [[package]] | ||||||
| name = "ruma" | name = "ruma" | ||||||
| version = "0.2.0" | version = "0.2.0" | ||||||
| source = "git+https://github.com/ruma/ruma?rev=174555857ef90d49e4b9a672be9e2fe0acdc2687#174555857ef90d49e4b9a672be9e2fe0acdc2687" |  | ||||||
| dependencies = [ | dependencies = [ | ||||||
|  "assign", |  "assign", | ||||||
|  "js_int", |  "js_int", | ||||||
|  | @ -2036,7 +2035,6 @@ dependencies = [ | ||||||
| [[package]] | [[package]] | ||||||
| name = "ruma-api" | name = "ruma-api" | ||||||
| version = "0.17.1" | version = "0.17.1" | ||||||
| source = "git+https://github.com/ruma/ruma?rev=174555857ef90d49e4b9a672be9e2fe0acdc2687#174555857ef90d49e4b9a672be9e2fe0acdc2687" |  | ||||||
| dependencies = [ | dependencies = [ | ||||||
|  "bytes", |  "bytes", | ||||||
|  "http", |  "http", | ||||||
|  | @ -2052,7 +2050,6 @@ dependencies = [ | ||||||
| [[package]] | [[package]] | ||||||
| name = "ruma-api-macros" | name = "ruma-api-macros" | ||||||
| version = "0.17.1" | version = "0.17.1" | ||||||
| source = "git+https://github.com/ruma/ruma?rev=174555857ef90d49e4b9a672be9e2fe0acdc2687#174555857ef90d49e4b9a672be9e2fe0acdc2687" |  | ||||||
| dependencies = [ | dependencies = [ | ||||||
|  "proc-macro-crate", |  "proc-macro-crate", | ||||||
|  "proc-macro2", |  "proc-macro2", | ||||||
|  | @ -2063,7 +2060,6 @@ dependencies = [ | ||||||
| [[package]] | [[package]] | ||||||
| name = "ruma-appservice-api" | name = "ruma-appservice-api" | ||||||
| version = "0.3.0" | version = "0.3.0" | ||||||
| source = "git+https://github.com/ruma/ruma?rev=174555857ef90d49e4b9a672be9e2fe0acdc2687#174555857ef90d49e4b9a672be9e2fe0acdc2687" |  | ||||||
| dependencies = [ | dependencies = [ | ||||||
|  "ruma-api", |  "ruma-api", | ||||||
|  "ruma-common", |  "ruma-common", | ||||||
|  | @ -2077,7 +2073,6 @@ dependencies = [ | ||||||
| [[package]] | [[package]] | ||||||
| name = "ruma-client-api" | name = "ruma-client-api" | ||||||
| version = "0.11.0" | version = "0.11.0" | ||||||
| source = "git+https://github.com/ruma/ruma?rev=174555857ef90d49e4b9a672be9e2fe0acdc2687#174555857ef90d49e4b9a672be9e2fe0acdc2687" |  | ||||||
| dependencies = [ | dependencies = [ | ||||||
|  "assign", |  "assign", | ||||||
|  "bytes", |  "bytes", | ||||||
|  | @ -2097,7 +2092,6 @@ dependencies = [ | ||||||
| [[package]] | [[package]] | ||||||
| name = "ruma-common" | name = "ruma-common" | ||||||
| version = "0.5.4" | version = "0.5.4" | ||||||
| source = "git+https://github.com/ruma/ruma?rev=174555857ef90d49e4b9a672be9e2fe0acdc2687#174555857ef90d49e4b9a672be9e2fe0acdc2687" |  | ||||||
| dependencies = [ | dependencies = [ | ||||||
|  "indexmap", |  "indexmap", | ||||||
|  "js_int", |  "js_int", | ||||||
|  | @ -2111,8 +2105,7 @@ dependencies = [ | ||||||
| 
 | 
 | ||||||
| [[package]] | [[package]] | ||||||
| name = "ruma-events" | name = "ruma-events" | ||||||
| version = "0.23.1" | version = "0.23.2" | ||||||
| source = "git+https://github.com/ruma/ruma?rev=174555857ef90d49e4b9a672be9e2fe0acdc2687#174555857ef90d49e4b9a672be9e2fe0acdc2687" |  | ||||||
| dependencies = [ | dependencies = [ | ||||||
|  "indoc", |  "indoc", | ||||||
|  "js_int", |  "js_int", | ||||||
|  | @ -2122,12 +2115,12 @@ dependencies = [ | ||||||
|  "ruma-serde", |  "ruma-serde", | ||||||
|  "serde", |  "serde", | ||||||
|  "serde_json", |  "serde_json", | ||||||
|  |  "thiserror", | ||||||
| ] | ] | ||||||
| 
 | 
 | ||||||
| [[package]] | [[package]] | ||||||
| name = "ruma-events-macros" | name = "ruma-events-macros" | ||||||
| version = "0.23.1" | version = "0.23.2" | ||||||
| source = "git+https://github.com/ruma/ruma?rev=174555857ef90d49e4b9a672be9e2fe0acdc2687#174555857ef90d49e4b9a672be9e2fe0acdc2687" |  | ||||||
| dependencies = [ | dependencies = [ | ||||||
|  "proc-macro-crate", |  "proc-macro-crate", | ||||||
|  "proc-macro2", |  "proc-macro2", | ||||||
|  | @ -2138,7 +2131,6 @@ dependencies = [ | ||||||
| [[package]] | [[package]] | ||||||
| name = "ruma-federation-api" | name = "ruma-federation-api" | ||||||
| version = "0.2.0" | version = "0.2.0" | ||||||
| source = "git+https://github.com/ruma/ruma?rev=174555857ef90d49e4b9a672be9e2fe0acdc2687#174555857ef90d49e4b9a672be9e2fe0acdc2687" |  | ||||||
| dependencies = [ | dependencies = [ | ||||||
|  "js_int", |  "js_int", | ||||||
|  "ruma-api", |  "ruma-api", | ||||||
|  | @ -2153,7 +2145,6 @@ dependencies = [ | ||||||
| [[package]] | [[package]] | ||||||
| name = "ruma-identifiers" | name = "ruma-identifiers" | ||||||
| version = "0.19.4" | version = "0.19.4" | ||||||
| source = "git+https://github.com/ruma/ruma?rev=174555857ef90d49e4b9a672be9e2fe0acdc2687#174555857ef90d49e4b9a672be9e2fe0acdc2687" |  | ||||||
| dependencies = [ | dependencies = [ | ||||||
|  "paste", |  "paste", | ||||||
|  "rand 0.8.4", |  "rand 0.8.4", | ||||||
|  | @ -2167,7 +2158,6 @@ dependencies = [ | ||||||
| [[package]] | [[package]] | ||||||
| name = "ruma-identifiers-macros" | name = "ruma-identifiers-macros" | ||||||
| version = "0.19.4" | version = "0.19.4" | ||||||
| source = "git+https://github.com/ruma/ruma?rev=174555857ef90d49e4b9a672be9e2fe0acdc2687#174555857ef90d49e4b9a672be9e2fe0acdc2687" |  | ||||||
| dependencies = [ | dependencies = [ | ||||||
|  "quote", |  "quote", | ||||||
|  "ruma-identifiers-validation", |  "ruma-identifiers-validation", | ||||||
|  | @ -2177,12 +2167,10 @@ dependencies = [ | ||||||
| [[package]] | [[package]] | ||||||
| name = "ruma-identifiers-validation" | name = "ruma-identifiers-validation" | ||||||
| version = "0.4.0" | version = "0.4.0" | ||||||
| source = "git+https://github.com/ruma/ruma?rev=174555857ef90d49e4b9a672be9e2fe0acdc2687#174555857ef90d49e4b9a672be9e2fe0acdc2687" |  | ||||||
| 
 | 
 | ||||||
| [[package]] | [[package]] | ||||||
| name = "ruma-identity-service-api" | name = "ruma-identity-service-api" | ||||||
| version = "0.2.0" | version = "0.2.0" | ||||||
| source = "git+https://github.com/ruma/ruma?rev=174555857ef90d49e4b9a672be9e2fe0acdc2687#174555857ef90d49e4b9a672be9e2fe0acdc2687" |  | ||||||
| dependencies = [ | dependencies = [ | ||||||
|  "js_int", |  "js_int", | ||||||
|  "ruma-api", |  "ruma-api", | ||||||
|  | @ -2195,7 +2183,6 @@ dependencies = [ | ||||||
| [[package]] | [[package]] | ||||||
| name = "ruma-push-gateway-api" | name = "ruma-push-gateway-api" | ||||||
| version = "0.2.0" | version = "0.2.0" | ||||||
| source = "git+https://github.com/ruma/ruma?rev=174555857ef90d49e4b9a672be9e2fe0acdc2687#174555857ef90d49e4b9a672be9e2fe0acdc2687" |  | ||||||
| dependencies = [ | dependencies = [ | ||||||
|  "js_int", |  "js_int", | ||||||
|  "ruma-api", |  "ruma-api", | ||||||
|  | @ -2210,7 +2197,6 @@ dependencies = [ | ||||||
| [[package]] | [[package]] | ||||||
| name = "ruma-serde" | name = "ruma-serde" | ||||||
| version = "0.4.1" | version = "0.4.1" | ||||||
| source = "git+https://github.com/ruma/ruma?rev=174555857ef90d49e4b9a672be9e2fe0acdc2687#174555857ef90d49e4b9a672be9e2fe0acdc2687" |  | ||||||
| dependencies = [ | dependencies = [ | ||||||
|  "bytes", |  "bytes", | ||||||
|  "form_urlencoded", |  "form_urlencoded", | ||||||
|  | @ -2224,7 +2210,6 @@ dependencies = [ | ||||||
| [[package]] | [[package]] | ||||||
| name = "ruma-serde-macros" | name = "ruma-serde-macros" | ||||||
| version = "0.4.1" | version = "0.4.1" | ||||||
| source = "git+https://github.com/ruma/ruma?rev=174555857ef90d49e4b9a672be9e2fe0acdc2687#174555857ef90d49e4b9a672be9e2fe0acdc2687" |  | ||||||
| dependencies = [ | dependencies = [ | ||||||
|  "proc-macro-crate", |  "proc-macro-crate", | ||||||
|  "proc-macro2", |  "proc-macro2", | ||||||
|  | @ -2235,7 +2220,6 @@ dependencies = [ | ||||||
| [[package]] | [[package]] | ||||||
| name = "ruma-signatures" | name = "ruma-signatures" | ||||||
| version = "0.8.0" | version = "0.8.0" | ||||||
| source = "git+https://github.com/ruma/ruma?rev=174555857ef90d49e4b9a672be9e2fe0acdc2687#174555857ef90d49e4b9a672be9e2fe0acdc2687" |  | ||||||
| dependencies = [ | dependencies = [ | ||||||
|  "base64 0.13.0", |  "base64 0.13.0", | ||||||
|  "ed25519-dalek", |  "ed25519-dalek", | ||||||
|  | @ -2252,7 +2236,6 @@ dependencies = [ | ||||||
| [[package]] | [[package]] | ||||||
| name = "ruma-state-res" | name = "ruma-state-res" | ||||||
| version = "0.2.0" | version = "0.2.0" | ||||||
| source = "git+https://github.com/ruma/ruma?rev=174555857ef90d49e4b9a672be9e2fe0acdc2687#174555857ef90d49e4b9a672be9e2fe0acdc2687" |  | ||||||
| dependencies = [ | dependencies = [ | ||||||
|  "itertools 0.10.1", |  "itertools 0.10.1", | ||||||
|  "js_int", |  "js_int", | ||||||
|  |  | ||||||
|  | @ -18,8 +18,8 @@ edition = "2018" | ||||||
| rocket = { version = "0.5.0-rc.1", features = ["tls"] } # Used to handle requests | rocket = { version = "0.5.0-rc.1", features = ["tls"] } # Used to handle requests | ||||||
| 
 | 
 | ||||||
| # Used for matrix spec type definitions and helpers | # Used for matrix spec type definitions and helpers | ||||||
| ruma = { git = "https://github.com/ruma/ruma", rev = "174555857ef90d49e4b9a672be9e2fe0acdc2687", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-pre-spec", "unstable-exhaustive-types"] } | #ruma = { git = "https://github.com/ruma/ruma", rev = "174555857ef90d49e4b9a672be9e2fe0acdc2687", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-pre-spec", "unstable-exhaustive-types"] } | ||||||
| #ruma = { path = "../ruma/crates/ruma", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-pre-spec", "unstable-exhaustive-types"] } | ruma = { path = "../ruma/crates/ruma", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-pre-spec", "unstable-exhaustive-types"] } | ||||||
| 
 | 
 | ||||||
| # Used for long polling and federation sender, should be the same as rocket::tokio | # Used for long polling and federation sender, should be the same as rocket::tokio | ||||||
| tokio = "1.2.0" | tokio = "1.2.0" | ||||||
|  | @ -119,5 +119,5 @@ maintainer-scripts = "debian/" | ||||||
| systemd-units = { unit-name = "matrix-conduit" } | systemd-units = { unit-name = "matrix-conduit" } | ||||||
| 
 | 
 | ||||||
| # For flamegraphs: | # For flamegraphs: | ||||||
| #[profile.release] | [profile.release] | ||||||
| #debug = true | debug = true | ||||||
|  |  | ||||||
|  | @ -1,4 +1,8 @@ | ||||||
| use std::{collections::BTreeMap, convert::TryInto, sync::Arc}; | use std::{ | ||||||
|  |     collections::BTreeMap, | ||||||
|  |     convert::{TryFrom, TryInto}, | ||||||
|  |     sync::Arc, | ||||||
|  | }; | ||||||
| 
 | 
 | ||||||
| use super::{DEVICE_ID_LENGTH, SESSION_ID_LENGTH, TOKEN_LENGTH}; | use super::{DEVICE_ID_LENGTH, SESSION_ID_LENGTH, TOKEN_LENGTH}; | ||||||
| use crate::{database::DatabaseGuard, pdu::PduBuilder, utils, ConduitResult, Error, Ruma}; | use crate::{database::DatabaseGuard, pdu::PduBuilder, utils, ConduitResult, Error, Ruma}; | ||||||
|  | @ -16,7 +20,8 @@ use ruma::{ | ||||||
|     }, |     }, | ||||||
|     events::{ |     events::{ | ||||||
|         room::{ |         room::{ | ||||||
|             canonical_alias, guest_access, history_visibility, join_rules, member, message, name, |             canonical_alias, guest_access, history_visibility, join_rules, member, message, | ||||||
|  |             name::{self, RoomName}, | ||||||
|             topic, |             topic, | ||||||
|         }, |         }, | ||||||
|         EventType, |         EventType, | ||||||
|  | @ -375,11 +380,9 @@ pub async fn register_route( | ||||||
|         db.rooms.build_and_append_pdu( |         db.rooms.build_and_append_pdu( | ||||||
|             PduBuilder { |             PduBuilder { | ||||||
|                 event_type: EventType::RoomName, |                 event_type: EventType::RoomName, | ||||||
|                 content: serde_json::to_value( |                 content: serde_json::to_value(name::NameEventContent::new(Some( | ||||||
|                     name::NameEventContent::new("Admin Room".to_owned()).map_err(|_| { |                     RoomName::try_from("Admin Room".to_owned()).expect("Room name is valid"), | ||||||
|                         Error::BadRequest(ErrorKind::InvalidParam, "Name is invalid.") |                 ))) | ||||||
|                     })?, |  | ||||||
|                 ) |  | ||||||
|                 .expect("event is valid, we just created it"), |                 .expect("event is valid, we just created it"), | ||||||
|                 unsigned: None, |                 unsigned: None, | ||||||
|                 state_key: Some("".to_owned()), |                 state_key: Some("".to_owned()), | ||||||
|  |  | ||||||
|  | @ -87,17 +87,17 @@ pub async fn set_room_visibility_route( | ||||||
|     let sender_user = body.sender_user.as_ref().expect("user is authenticated"); |     let sender_user = body.sender_user.as_ref().expect("user is authenticated"); | ||||||
| 
 | 
 | ||||||
|     match &body.visibility { |     match &body.visibility { | ||||||
|         room::Visibility::_Custom(_s) => { |  | ||||||
|             return Err(Error::BadRequest( |  | ||||||
|                 ErrorKind::InvalidParam, |  | ||||||
|                 "Room visibility type is not supported.", |  | ||||||
|             )); |  | ||||||
|         } |  | ||||||
|         room::Visibility::Public => { |         room::Visibility::Public => { | ||||||
|             db.rooms.set_public(&body.room_id, true)?; |             db.rooms.set_public(&body.room_id, true)?; | ||||||
|             info!("{} made {} public", sender_user, body.room_id); |             info!("{} made {} public", sender_user, body.room_id); | ||||||
|         } |         } | ||||||
|         room::Visibility::Private => db.rooms.set_public(&body.room_id, false)?, |         room::Visibility::Private => db.rooms.set_public(&body.room_id, false)?, | ||||||
|  |         _ => { | ||||||
|  |             return Err(Error::BadRequest( | ||||||
|  |                 ErrorKind::InvalidParam, | ||||||
|  |                 "Room visibility type is not supported.", | ||||||
|  |             )); | ||||||
|  |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     db.flush().await?; |     db.flush().await?; | ||||||
|  | @ -231,8 +231,8 @@ pub async fn get_public_rooms_filtered_helper( | ||||||
|                             .map_err(|_| { |                             .map_err(|_| { | ||||||
|                                 Error::bad_database("Invalid room name event in database.") |                                 Error::bad_database("Invalid room name event in database.") | ||||||
|                             })? |                             })? | ||||||
|                             .name() |                             .name | ||||||
|                             .map(|n| n.to_owned())) |                             .map(|n| n.to_owned().into())) | ||||||
|                         })?, |                         })?, | ||||||
|                     num_joined_members: (db.rooms.room_members(&room_id).count() as u32).into(), |                     num_joined_members: (db.rooms.room_members(&room_id).count() as u32).into(), | ||||||
|                     topic: db |                     topic: db | ||||||
|  |  | ||||||
|  | @ -81,7 +81,7 @@ pub async fn get_pushrule_route( | ||||||
|             .content |             .content | ||||||
|             .get(body.rule_id.as_str()) |             .get(body.rule_id.as_str()) | ||||||
|             .map(|rule| rule.clone().into()), |             .map(|rule| rule.clone().into()), | ||||||
|         RuleKind::_Custom(_) => None, |         _ => None, | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|     if let Some(rule) = rule { |     if let Some(rule) = rule { | ||||||
|  | @ -181,7 +181,7 @@ pub async fn set_pushrule_route( | ||||||
|                 .into(), |                 .into(), | ||||||
|             ); |             ); | ||||||
|         } |         } | ||||||
|         RuleKind::_Custom(_) => {} |         _ => {} | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     db.account_data.update( |     db.account_data.update( | ||||||
|  | @ -245,7 +245,7 @@ pub async fn get_pushrule_actions_route( | ||||||
|             .content |             .content | ||||||
|             .get(body.rule_id.as_str()) |             .get(body.rule_id.as_str()) | ||||||
|             .map(|rule| rule.actions.clone()), |             .map(|rule| rule.actions.clone()), | ||||||
|         RuleKind::_Custom(_) => None, |         _ => None, | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|     db.flush().await?; |     db.flush().await?; | ||||||
|  | @ -314,7 +314,7 @@ pub async fn set_pushrule_actions_route( | ||||||
|                 global.content.replace(rule); |                 global.content.replace(rule); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         RuleKind::_Custom(_) => {} |         _ => {} | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|     db.account_data.update( |     db.account_data.update( | ||||||
|  | @ -383,7 +383,7 @@ pub async fn get_pushrule_enabled_route( | ||||||
|             .iter() |             .iter() | ||||||
|             .find(|rule| rule.rule_id == body.rule_id) |             .find(|rule| rule.rule_id == body.rule_id) | ||||||
|             .map_or(false, |rule| rule.enabled), |             .map_or(false, |rule| rule.enabled), | ||||||
|         RuleKind::_Custom(_) => false, |         _ => false, | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|     db.flush().await?; |     db.flush().await?; | ||||||
|  | @ -454,7 +454,7 @@ pub async fn set_pushrule_enabled_route( | ||||||
|                 global.content.insert(rule); |                 global.content.insert(rule); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         RuleKind::_Custom(_) => {} |         _ => {} | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     db.account_data.update( |     db.account_data.update( | ||||||
|  | @ -523,7 +523,7 @@ pub async fn delete_pushrule_route( | ||||||
|                 global.content.remove(&rule); |                 global.content.remove(&rule); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         RuleKind::_Custom(_) => {} |         _ => {} | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     db.account_data.update( |     db.account_data.update( | ||||||
|  |  | ||||||
|  | @ -9,7 +9,11 @@ use ruma::{ | ||||||
|         r0::room::{self, create_room, get_room_event, upgrade_room}, |         r0::room::{self, create_room, get_room_event, upgrade_room}, | ||||||
|     }, |     }, | ||||||
|     events::{ |     events::{ | ||||||
|         room::{guest_access, history_visibility, join_rules, member, name, topic}, |         room::{ | ||||||
|  |             guest_access, history_visibility, join_rules, member, | ||||||
|  |             name::{self, RoomName}, | ||||||
|  |             topic, | ||||||
|  |         }, | ||||||
|         EventType, |         EventType, | ||||||
|     }, |     }, | ||||||
|     serde::Raw, |     serde::Raw, | ||||||
|  | @ -113,7 +117,7 @@ pub async fn create_room_route( | ||||||
|         .unwrap_or_else(|| match &body.visibility { |         .unwrap_or_else(|| match &body.visibility { | ||||||
|             room::Visibility::Private => create_room::RoomPreset::PrivateChat, |             room::Visibility::Private => create_room::RoomPreset::PrivateChat, | ||||||
|             room::Visibility::Public => create_room::RoomPreset::PublicChat, |             room::Visibility::Public => create_room::RoomPreset::PublicChat, | ||||||
|             room::Visibility::_Custom(_) => create_room::RoomPreset::PrivateChat, // Room visibility should not be custom
 |             _ => create_room::RoomPreset::PrivateChat, // Room visibility should not be custom
 | ||||||
|         }); |         }); | ||||||
| 
 | 
 | ||||||
|     let mut users = BTreeMap::new(); |     let mut users = BTreeMap::new(); | ||||||
|  | @ -251,11 +255,11 @@ pub async fn create_room_route( | ||||||
|         db.rooms.build_and_append_pdu( |         db.rooms.build_and_append_pdu( | ||||||
|             PduBuilder { |             PduBuilder { | ||||||
|                 event_type: EventType::RoomName, |                 event_type: EventType::RoomName, | ||||||
|                 content: serde_json::to_value( |                 content: serde_json::to_value(name::NameEventContent::new(Some( | ||||||
|                     name::NameEventContent::new(name.clone()).map_err(|_| { |                     RoomName::try_from(name.clone()).map_err(|_| { | ||||||
|                         Error::BadRequest(ErrorKind::InvalidParam, "Name is invalid.") |                         Error::BadRequest(ErrorKind::InvalidParam, "Name is invalid.") | ||||||
|                     })?, |                     })?, | ||||||
|                 ) |                 ))) | ||||||
|                 .expect("event is valid, we just created it"), |                 .expect("event is valid, we just created it"), | ||||||
|                 unsigned: None, |                 unsigned: None, | ||||||
|                 state_key: Some("".to_owned()), |                 state_key: Some("".to_owned()), | ||||||
|  |  | ||||||
|  | @ -490,6 +490,27 @@ impl Rooms { | ||||||
|             .transpose() |             .transpose() | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     /// Returns the json of a pdu.
 | ||||||
|  |     pub fn get_non_outlier_pdu_json( | ||||||
|  |         &self, | ||||||
|  |         event_id: &EventId, | ||||||
|  |     ) -> Result<Option<CanonicalJsonObject>> { | ||||||
|  |         self.eventid_pduid | ||||||
|  |             .get(event_id.as_bytes())? | ||||||
|  |             .map_or_else::<Result<_>, _, _>( | ||||||
|  |                 || Ok(None), | ||||||
|  |                 |pduid| { | ||||||
|  |                     Ok(Some(self.pduid_pdu.get(&pduid)?.ok_or_else(|| { | ||||||
|  |                         Error::bad_database("Invalid pduid in eventid_pduid.") | ||||||
|  |                     })?)) | ||||||
|  |                 }, | ||||||
|  |             )? | ||||||
|  |             .map(|pdu| { | ||||||
|  |                 serde_json::from_slice(&pdu).map_err(|_| Error::bad_database("Invalid PDU in db.")) | ||||||
|  |             }) | ||||||
|  |             .transpose() | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     /// Returns the pdu's id.
 |     /// Returns the pdu's id.
 | ||||||
|     pub fn get_pdu_id(&self, event_id: &EventId) -> Result<Option<Vec<u8>>> { |     pub fn get_pdu_id(&self, event_id: &EventId) -> Result<Option<Vec<u8>>> { | ||||||
|         self.eventid_pduid |         self.eventid_pduid | ||||||
|  | @ -903,11 +924,59 @@ impl Rooms { | ||||||
|                                 "list_appservices" => { |                                 "list_appservices" => { | ||||||
|                                     db.admin.send(AdminCommand::ListAppservices); |                                     db.admin.send(AdminCommand::ListAppservices); | ||||||
|                                 } |                                 } | ||||||
|  |                                 "get_pdu" => { | ||||||
|  |                                     if args.len() == 1 { | ||||||
|  |                                         if let Ok(event_id) = EventId::try_from(args[0]) { | ||||||
|  |                                             let mut outlier = false; | ||||||
|  |                                             let mut pdu_json = | ||||||
|  |                                                 db.rooms.get_non_outlier_pdu_json(&event_id)?; | ||||||
|  |                                             if pdu_json.is_none() { | ||||||
|  |                                                 outlier = true; | ||||||
|  |                                                 pdu_json = db.rooms.get_pdu_json(&event_id)?; | ||||||
|  |                                             } | ||||||
|  |                                             match pdu_json { | ||||||
|  |                                                 Some(json) => { | ||||||
|  |                                                     db.admin.send(AdminCommand::SendMessage( | ||||||
|  |                                                         message::MessageEventContent::text_html( | ||||||
|  |                                                             format!("{}\n```json\n{:#?}\n```", 
 | ||||||
|  |                                                             if outlier { | ||||||
|  |                                                                 "PDU is outlier" | ||||||
|  |                                                             } else { "PDU was accepted"}, json), | ||||||
|  |                                                             format!("<p>{}</p>\n<pre><code class=\"language-json\">{}\n</code></pre>\n", 
 | ||||||
|  |                                                             if outlier { | ||||||
|  |                                                                 "PDU is outlier" | ||||||
|  |                                                             } else { "PDU was accepted"}, serde_json::to_string_pretty(&json).expect("canonical json is valid json")) | ||||||
|  |                                                         ), | ||||||
|  |                                                     )); | ||||||
|  |                                                 } | ||||||
|  |                                                 None => { | ||||||
|  |                                                     db.admin.send(AdminCommand::SendMessage( | ||||||
|  |                                                         message::MessageEventContent::text_plain( | ||||||
|  |                                                             "PDU not found.", | ||||||
|  |                                                         ), | ||||||
|  |                                                     )); | ||||||
|  |                                                 } | ||||||
|  |                                             } | ||||||
|  |                                         } else { | ||||||
|  |                                             db.admin.send(AdminCommand::SendMessage( | ||||||
|  |                                                 message::MessageEventContent::text_plain( | ||||||
|  |                                                     "Event ID could not be parsed.", | ||||||
|  |                                                 ), | ||||||
|  |                                             )); | ||||||
|  |                                         } | ||||||
|  |                                     } else { | ||||||
|  |                                         db.admin.send(AdminCommand::SendMessage( | ||||||
|  |                                             message::MessageEventContent::text_plain( | ||||||
|  |                                                 "Usage: get_pdu <eventid>", | ||||||
|  |                                             ), | ||||||
|  |                                         )); | ||||||
|  |                                     } | ||||||
|  |                                 } | ||||||
|                                 _ => { |                                 _ => { | ||||||
|                                     db.admin.send(AdminCommand::SendMessage( |                                     db.admin.send(AdminCommand::SendMessage( | ||||||
|                                         message::MessageEventContent::text_plain(format!( |                                         message::MessageEventContent::text_plain(format!( | ||||||
|                                             "Command: {}, Args: {:?}", |                                             "Unrecognized command: {}", | ||||||
|                                             command, args |                                             command | ||||||
|                                         )), |                                         )), | ||||||
|                                     )); |                                     )); | ||||||
|                                 } |                                 } | ||||||
|  |  | ||||||
|  | @ -1254,15 +1254,6 @@ pub fn handle_incoming_pdu<'a>( | ||||||
|             // We do need to force an update to this room's state
 |             // We do need to force an update to this room's state
 | ||||||
|             update_state = true; |             update_state = true; | ||||||
| 
 | 
 | ||||||
|             let mut auth_events = vec![]; |  | ||||||
|             for map in &fork_states { |  | ||||||
|                 let state_auth = map |  | ||||||
|                     .values() |  | ||||||
|                     .flat_map(|pdu| pdu.auth_events.clone()) |  | ||||||
|                     .collect(); |  | ||||||
|                 auth_events.push(state_auth); |  | ||||||
|             } |  | ||||||
| 
 |  | ||||||
|             match state_res::StateResolution::resolve( |             match state_res::StateResolution::resolve( | ||||||
|                 &room_id, |                 &room_id, | ||||||
|                 room_version_id, |                 room_version_id, | ||||||
|  | @ -1274,8 +1265,7 @@ pub fn handle_incoming_pdu<'a>( | ||||||
|                             .collect::<StateMap<_>>() |                             .collect::<StateMap<_>>() | ||||||
|                     }) |                     }) | ||||||
|                     .collect::<Vec<_>>(), |                     .collect::<Vec<_>>(), | ||||||
|                 auth_events, |                 |id| { | ||||||
|                 &|id| { |  | ||||||
|                     let res = db.rooms.get_pdu(id); |                     let res = db.rooms.get_pdu(id); | ||||||
|                     if let Err(e) = &res { |                     if let Err(e) = &res { | ||||||
|                         error!("LOOK AT ME Failed to fetch event: {}", e); |                         error!("LOOK AT ME Failed to fetch event: {}", e); | ||||||
|  | @ -2432,10 +2422,10 @@ pub fn get_profile_information_route( | ||||||
|     let mut avatar_url = None; |     let mut avatar_url = None; | ||||||
| 
 | 
 | ||||||
|     match &body.field { |     match &body.field { | ||||||
|         // TODO: what to do with custom
 |  | ||||||
|         Some(ProfileField::_Custom(_s)) => {} |  | ||||||
|         Some(ProfileField::DisplayName) => displayname = db.users.displayname(&body.user_id)?, |         Some(ProfileField::DisplayName) => displayname = db.users.displayname(&body.user_id)?, | ||||||
|         Some(ProfileField::AvatarUrl) => avatar_url = db.users.avatar_url(&body.user_id)?, |         Some(ProfileField::AvatarUrl) => avatar_url = db.users.avatar_url(&body.user_id)?, | ||||||
|  |         // TODO: what to do with custom
 | ||||||
|  |         Some(_) => {} | ||||||
|         None => { |         None => { | ||||||
|             displayname = db.users.displayname(&body.user_id)?; |             displayname = db.users.displayname(&body.user_id)?; | ||||||
|             avatar_url = db.users.avatar_url(&body.user_id)?; |             avatar_url = db.users.avatar_url(&body.user_id)?; | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue