fix: one time keys are never removed
This commit is contained in:
		
							parent
							
								
									5d6542a8a6
								
							
						
					
					
						commit
						1014388a9c
					
				
					 5 changed files with 54 additions and 102 deletions
				
			
		
							
								
								
									
										5
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										5
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							|  | @ -1296,8 +1296,9 @@ dependencies = [ | |||
| 
 | ||||
| [[package]] | ||||
| name = "ruma-client-api" | ||||
| version = "0.8.0" | ||||
| source = "git+https://github.com/ruma/ruma-client-api.git#3a3ccabbf22c34da5c9de7cac54d9fbd3e571dcf" | ||||
| version = "0.9.0" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "082913ad135ca55ee06a55d295bea954982f2ac5e0150adc09024f5cbb8cb6cf" | ||||
| dependencies = [ | ||||
|  "http", | ||||
|  "js_int", | ||||
|  |  | |||
|  | @ -14,7 +14,7 @@ edition = "2018" | |||
| [dependencies] | ||||
| rocket = { git = "https://github.com/SergioBenitez/Rocket.git", branch = "async", features = ["tls"] } | ||||
| http = "0.2.1" | ||||
| ruma-client-api = { git = "https://github.com/ruma/ruma-client-api.git" } | ||||
| ruma-client-api = "0.9.0" | ||||
| ruma-identifiers = { version = "0.16.1", features = ["rand"] } | ||||
| ruma-api = "0.16.1" | ||||
| ruma-events = "0.21.2" | ||||
|  |  | |||
|  | @ -185,14 +185,20 @@ pub fn register_route( | |||
|                 content: ruma_events::push_rules::PushRulesEventContent { | ||||
|                     global: ruma_events::push_rules::Ruleset { | ||||
|                         content: vec![], | ||||
|                         override_rules: vec![], | ||||
|                         override_rules: vec![ruma_events::push_rules::ConditionalPushRule { | ||||
|                             actions: vec![ruma_events::push_rules::Action::DontNotify], | ||||
|                             default: true, | ||||
|                             enabled: false, | ||||
|                             rule_id: ".m.rule.master".to_owned(), | ||||
|                             conditions: vec![], | ||||
|                         }], | ||||
|                         room: vec![], | ||||
|                         sender: vec![], | ||||
|                         underride: vec![ruma_events::push_rules::ConditionalPushRule { | ||||
|                             actions: vec![ | ||||
|                                 ruma_events::push_rules::Action::Notify, | ||||
|                                 ruma_events::push_rules::Action::SetTweak( | ||||
|                                     ruma_common::push::Tweak::Highlight(false), | ||||
|                                     ruma_common::push::Tweak::Sound("default".to_owned()), | ||||
|                                 ), | ||||
|                             ], | ||||
|                             default: true, | ||||
|  | @ -320,28 +326,27 @@ pub fn get_capabilities_route() -> MatrixResult<get_capabilities::Response> { | |||
|     })) | ||||
| } | ||||
| 
 | ||||
| #[get("/_matrix/client/r0/pushrules")] | ||||
| pub fn get_pushrules_all_route() -> MatrixResult<get_pushrules_all::Response> { | ||||
|     // TODO
 | ||||
|     let mut global = BTreeMap::new(); | ||||
|     global.insert( | ||||
|         push::RuleKind::Underride, | ||||
|         vec![push::PushRule { | ||||
|             actions: vec![ | ||||
|                 push::Action::Notify, | ||||
|                 push::Action::SetTweak(ruma_common::push::Tweak::Highlight(false)), | ||||
|             ], | ||||
|             default: true, | ||||
|             enabled: true, | ||||
|             rule_id: ".m.rule.message".to_owned(), | ||||
|             conditions: Some(vec![push::PushCondition::EventMatch { | ||||
|                 key: "type".to_owned(), | ||||
|                 pattern: "m.room.message".to_owned(), | ||||
|             }]), | ||||
|             pattern: None, | ||||
|         }], | ||||
|     ); | ||||
|     MatrixResult(Ok(get_pushrules_all::Response { global })) | ||||
| #[get("/_matrix/client/r0/pushrules", data = "<body>")] | ||||
| pub fn get_pushrules_all_route( | ||||
|     db: State<'_, Database>, | ||||
|     body: Ruma<get_pushrules_all::Request>, | ||||
| ) -> MatrixResult<get_pushrules_all::Response> { | ||||
|     let user_id = body.user_id.as_ref().expect("user is authenticated"); | ||||
|     if let Some(EduEvent::PushRules(pushrules)) = db | ||||
|         .account_data | ||||
|         .get(None, &user_id, &EventType::PushRules) | ||||
|         .unwrap().map(|edu| edu.deserialize().expect("PushRules event in db is valid")) | ||||
|     { | ||||
|         MatrixResult(Ok(get_pushrules_all::Response { | ||||
|             global: BTreeMap::new(), | ||||
|         })) | ||||
|     } else { | ||||
|         MatrixResult(Err(Error { | ||||
|             kind: ErrorKind::NotFound, | ||||
|             message: "PushRules event not found.".to_owned(), | ||||
|             status_code: http::StatusCode::BAD_REQUEST, | ||||
|         })) | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| #[put(
 | ||||
|  | @ -356,46 +361,7 @@ pub fn set_pushrule_route( | |||
|     _rule_id: String, | ||||
| ) -> MatrixResult<set_pushrule::Response> { | ||||
|     // TODO
 | ||||
|     let user_id = body.user_id.as_ref().expect("user is authenticated"); | ||||
|     db.account_data | ||||
|         .update( | ||||
|             None, | ||||
|             &user_id, | ||||
|             &EventType::PushRules, | ||||
|             serde_json::to_value(ruma_events::push_rules::PushRulesEvent { | ||||
|                 content: ruma_events::push_rules::PushRulesEventContent { | ||||
|                     global: ruma_events::push_rules::Ruleset { | ||||
|                         content: vec![], | ||||
|                         override_rules: vec![], | ||||
|                         room: vec![], | ||||
|                         sender: vec![], | ||||
|                         underride: vec![ruma_events::push_rules::ConditionalPushRule { | ||||
|                             actions: vec![ | ||||
|                                 ruma_events::push_rules::Action::Notify, | ||||
|                                 ruma_events::push_rules::Action::SetTweak( | ||||
|                                     ruma_common::push::Tweak::Highlight(false), | ||||
|                                 ), | ||||
|                             ], | ||||
|                             default: true, | ||||
|                             enabled: true, | ||||
|                             rule_id: ".m.rule.message".to_owned(), | ||||
|                             conditions: vec![ruma_events::push_rules::PushCondition::EventMatch( | ||||
|                                 ruma_events::push_rules::EventMatchCondition { | ||||
|                                     key: "type".to_owned(), | ||||
|                                     pattern: "m.room.message".to_owned(), | ||||
|                                 }, | ||||
|                             )], | ||||
|                         }], | ||||
|                     }, | ||||
|                 }, | ||||
|             }) | ||||
|             .unwrap() | ||||
|             .as_object_mut() | ||||
|             .unwrap(), | ||||
|             &db.globals, | ||||
|         ) | ||||
|         .unwrap(); | ||||
| 
 | ||||
|     warn!("TODO: set_pushrule_route"); | ||||
|     MatrixResult(Ok(set_pushrule::Response)) | ||||
| } | ||||
| 
 | ||||
|  | @ -406,6 +372,7 @@ pub fn set_pushrule_enabled_route( | |||
|     _rule_id: String, | ||||
| ) -> MatrixResult<set_pushrule_enabled::Response> { | ||||
|     // TODO
 | ||||
|     warn!("TODO: set_pushrule_enabled_route"); | ||||
|     MatrixResult(Ok(set_pushrule_enabled::Response)) | ||||
| } | ||||
| 
 | ||||
|  | @ -617,7 +584,6 @@ pub fn set_avatar_url_route( | |||
|             .set_avatar_url(&user_id, Some(body.avatar_url.clone())) | ||||
|             .unwrap(); | ||||
| 
 | ||||
| 
 | ||||
|         let mut json = serde_json::Map::new(); | ||||
|         json.insert("membership".to_owned(), "join".into()); | ||||
|         json.insert("avatar_url".to_owned(), (*body.avatar_url).into()); | ||||
|  | @ -962,12 +928,7 @@ pub fn create_room_route( | |||
|         .unwrap(); | ||||
| 
 | ||||
|     db.rooms | ||||
|         .join( | ||||
|             &room_id, | ||||
|             &user_id, | ||||
|             &db.users, | ||||
|             &db.globals, | ||||
|         ) | ||||
|         .join(&room_id, &user_id, &db.users, &db.globals) | ||||
|         .unwrap(); | ||||
| 
 | ||||
|     db.rooms | ||||
|  | @ -1069,12 +1030,7 @@ pub fn join_room_by_id_route( | |||
| 
 | ||||
|     if db | ||||
|         .rooms | ||||
|         .join( | ||||
|             &body.room_id, | ||||
|             &user_id, | ||||
|             &db.users, | ||||
|             &db.globals, | ||||
|         ) | ||||
|         .join(&body.room_id, &user_id, &db.users, &db.globals) | ||||
|         .is_ok() | ||||
|     { | ||||
|         MatrixResult(Ok(join_room_by_id::Response { | ||||
|  | @ -1116,12 +1072,7 @@ pub fn join_room_by_id_or_alias_route( | |||
| 
 | ||||
|     if db | ||||
|         .rooms | ||||
|         .join( | ||||
|             &room_id, | ||||
|             &user_id, | ||||
|             &db.users, | ||||
|             &db.globals, | ||||
|         ) | ||||
|         .join(&room_id, &user_id, &db.users, &db.globals) | ||||
|         .is_ok() | ||||
|     { | ||||
|         MatrixResult(Ok(join_room_by_id_or_alias::Response { room_id })) | ||||
|  | @ -1545,7 +1496,6 @@ pub fn sync_route( | |||
|                 None | ||||
|             }; | ||||
| 
 | ||||
| 
 | ||||
|         // They /sync response doesn't always return all messages, so we say the output is
 | ||||
|         // limited unless there are enough events
 | ||||
|         let mut limited = true; | ||||
|  | @ -1617,7 +1567,7 @@ pub fn sync_route( | |||
|                     }, | ||||
|                 }, | ||||
|                 unread_notifications: sync_events::UnreadNotificationsCount { | ||||
|                     highlight_count: None, | ||||
|                     highlight_count: notification_count, | ||||
|                     notification_count, | ||||
|                 }, | ||||
|                 timeline: sync_events::Timeline { | ||||
|  | @ -1736,8 +1686,8 @@ pub fn sync_route( | |||
|                 changed: db | ||||
|                     .users | ||||
|                     .device_keys_changed(since) | ||||
|                     .map(|u| u.unwrap().to_string()) | ||||
|                     .collect(), // TODO: use userids when ruma changes
 | ||||
|                     .map(|u| u.unwrap()) | ||||
|                     .collect(), | ||||
|                 left: Vec::new(), // TODO
 | ||||
|             }) | ||||
|         } else { | ||||
|  | @ -1843,8 +1793,7 @@ pub fn send_event_to_device_route( | |||
| 
 | ||||
|                 to_device::DeviceIdOrAllDevices::AllDevices => { | ||||
|                     for target_device_id in db.users.all_device_ids(&target_user_id) { | ||||
|                        db | ||||
|                     .users | ||||
|                         db.users | ||||
|                             .add_to_device_event( | ||||
|                                 user_id, | ||||
|                                 &target_user_id, | ||||
|  |  | |||
|  | @ -209,6 +209,8 @@ impl Users { | |||
|             .next() | ||||
|             .map(|r| { | ||||
|                 let (key, value) = r?; | ||||
|                 self.onetimekeyid_onetimekeys.remove(&key)?; | ||||
| 
 | ||||
|                 Ok(( | ||||
|                     serde_json::from_slice( | ||||
|                         &*key | ||||
|  |  | |||
|  | @ -20,7 +20,7 @@ pub fn increment(old: Option<&[u8]>) -> Option<Vec<u8>> { | |||
|             let number = u64::from_be_bytes(array); | ||||
|             number + 1 | ||||
|         } | ||||
|         None => 0, | ||||
|         None => 1, // Start at one. since 0 should return the first event in the db
 | ||||
|     }; | ||||
| 
 | ||||
|     Some(number.to_be_bytes().to_vec()) | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue