refactor: make cargo clippy happier
This commit is contained in:
		
							parent
							
								
									1dbde0e1c1
								
							
						
					
					
						commit
						8e041f90dd
					
				
					 6 changed files with 23 additions and 31 deletions
				
			
		|  | @ -1 +1 @@ | ||||||
| nightly | nightly-2020-05-09 | ||||||
|  |  | ||||||
|  | @ -158,7 +158,6 @@ pub fn register_route( | ||||||
|     // Generate new device id if the user didn't specify one
 |     // Generate new device id if the user didn't specify one
 | ||||||
|     let device_id = body |     let device_id = body | ||||||
|         .device_id |         .device_id | ||||||
|         .clone() |  | ||||||
|         .unwrap_or_else(|| utils::random_string(DEVICE_ID_LENGTH)); |         .unwrap_or_else(|| utils::random_string(DEVICE_ID_LENGTH)); | ||||||
| 
 | 
 | ||||||
|     // Generate new token for the device
 |     // Generate new token for the device
 | ||||||
|  | @ -276,7 +275,6 @@ pub fn login_route( | ||||||
|     // Generate new device id if the user didn't specify one
 |     // Generate new device id if the user didn't specify one
 | ||||||
|     let device_id = body |     let device_id = body | ||||||
|         .device_id |         .device_id | ||||||
|         .clone() |  | ||||||
|         .unwrap_or_else(|| utils::random_string(DEVICE_ID_LENGTH)); |         .unwrap_or_else(|| utils::random_string(DEVICE_ID_LENGTH)); | ||||||
| 
 | 
 | ||||||
|     // Generate a new token for the device
 |     // Generate a new token for the device
 | ||||||
|  | @ -347,7 +345,7 @@ pub fn set_pushrule_route( | ||||||
|     _rule_id: String, |     _rule_id: String, | ||||||
| ) -> MatrixResult<set_pushrule::Response> { | ) -> MatrixResult<set_pushrule::Response> { | ||||||
|     // TODO
 |     // TODO
 | ||||||
|     let user_id = body.user_id.clone().expect("user is authenticated"); |     let user_id = body.user_id.as_ref().expect("user is authenticated"); | ||||||
|     db.account_data |     db.account_data | ||||||
|         .update( |         .update( | ||||||
|             None, |             None, | ||||||
|  | @ -448,7 +446,7 @@ pub fn set_displayname_route( | ||||||
|     body: Ruma<set_display_name::Request>, |     body: Ruma<set_display_name::Request>, | ||||||
|     _user_id: String, |     _user_id: String, | ||||||
| ) -> MatrixResult<set_display_name::Response> { | ) -> MatrixResult<set_display_name::Response> { | ||||||
|     let user_id = body.user_id.clone().expect("user is authenticated"); |     let user_id = body.user_id.as_ref().expect("user is authenticated"); | ||||||
| 
 | 
 | ||||||
|     if let Some(displayname) = &body.displayname { |     if let Some(displayname) = &body.displayname { | ||||||
|         // Some("") will clear the displayname
 |         // Some("") will clear the displayname
 | ||||||
|  | @ -539,7 +537,7 @@ pub fn set_avatar_url_route( | ||||||
|     body: Ruma<set_avatar_url::Request>, |     body: Ruma<set_avatar_url::Request>, | ||||||
|     _user_id: String, |     _user_id: String, | ||||||
| ) -> MatrixResult<set_avatar_url::Response> { | ) -> MatrixResult<set_avatar_url::Response> { | ||||||
|     let user_id = body.user_id.clone().expect("user is authenticated"); |     let user_id = body.user_id.as_ref().expect("user is authenticated"); | ||||||
| 
 | 
 | ||||||
|     if !body.avatar_url.starts_with("mxc://") { |     if !body.avatar_url.starts_with("mxc://") { | ||||||
|         debug!("Request contains an invalid avatar_url."); |         debug!("Request contains an invalid avatar_url."); | ||||||
|  | @ -624,7 +622,7 @@ pub fn set_presence_route( | ||||||
|     body: Ruma<set_presence::Request>, |     body: Ruma<set_presence::Request>, | ||||||
|     _user_id: String, |     _user_id: String, | ||||||
| ) -> MatrixResult<set_presence::Response> { | ) -> MatrixResult<set_presence::Response> { | ||||||
|     let user_id = body.user_id.clone().expect("user is authenticated"); |     let user_id = body.user_id.as_ref().expect("user is authenticated"); | ||||||
| 
 | 
 | ||||||
|     db.global_edus |     db.global_edus | ||||||
|         .update_globallatest( |         .update_globallatest( | ||||||
|  | @ -670,7 +668,7 @@ pub fn set_read_marker_route( | ||||||
|     body: Ruma<set_read_marker::Request>, |     body: Ruma<set_read_marker::Request>, | ||||||
|     _room_id: String, |     _room_id: String, | ||||||
| ) -> MatrixResult<set_read_marker::Response> { | ) -> MatrixResult<set_read_marker::Response> { | ||||||
|     let user_id = body.user_id.clone().expect("user is authenticated"); |     let user_id = body.user_id.as_ref().expect("user is authenticated"); | ||||||
|     db.account_data |     db.account_data | ||||||
|         .update( |         .update( | ||||||
|             Some(&body.room_id), |             Some(&body.room_id), | ||||||
|  | @ -739,7 +737,7 @@ pub fn create_typing_event_route( | ||||||
|     _room_id: String, |     _room_id: String, | ||||||
|     _user_id: String, |     _user_id: String, | ||||||
| ) -> MatrixResult<create_typing_event::Response> { | ) -> MatrixResult<create_typing_event::Response> { | ||||||
|     let user_id = body.user_id.clone().expect("user is authenticated"); |     let user_id = body.user_id.as_ref().expect("user is authenticated"); | ||||||
|     let edu = EduEvent::Typing(ruma_events::typing::TypingEvent { |     let edu = EduEvent::Typing(ruma_events::typing::TypingEvent { | ||||||
|         content: ruma_events::typing::TypingEventContent { |         content: ruma_events::typing::TypingEventContent { | ||||||
|             user_ids: vec![user_id.clone()], |             user_ids: vec![user_id.clone()], | ||||||
|  | @ -772,7 +770,7 @@ pub fn create_room_route( | ||||||
| ) -> MatrixResult<create_room::Response> { | ) -> MatrixResult<create_room::Response> { | ||||||
|     // TODO: check if room is unique
 |     // TODO: check if room is unique
 | ||||||
|     let room_id = RoomId::try_from(db.globals.hostname()).expect("host is valid"); |     let room_id = RoomId::try_from(db.globals.hostname()).expect("host is valid"); | ||||||
|     let user_id = body.user_id.clone().expect("user is authenticated"); |     let user_id = body.user_id.as_ref().expect("user is authenticated"); | ||||||
| 
 | 
 | ||||||
|     db.rooms |     db.rooms | ||||||
|         .append_pdu( |         .append_pdu( | ||||||
|  | @ -890,7 +888,7 @@ pub fn join_room_by_id_route( | ||||||
|     body: Ruma<join_room_by_id::Request>, |     body: Ruma<join_room_by_id::Request>, | ||||||
|     _room_id: String, |     _room_id: String, | ||||||
| ) -> MatrixResult<join_room_by_id::Response> { | ) -> MatrixResult<join_room_by_id::Response> { | ||||||
|     let user_id = body.user_id.clone().expect("user is authenticated"); |     let user_id = body.user_id.as_ref().expect("user is authenticated"); | ||||||
| 
 | 
 | ||||||
|     if db |     if db | ||||||
|         .rooms |         .rooms | ||||||
|  | @ -920,7 +918,7 @@ pub fn join_room_by_id_or_alias_route( | ||||||
|     body: Ruma<join_room_by_id_or_alias::Request>, |     body: Ruma<join_room_by_id_or_alias::Request>, | ||||||
|     _room_id_or_alias: String, |     _room_id_or_alias: String, | ||||||
| ) -> MatrixResult<join_room_by_id_or_alias::Response> { | ) -> MatrixResult<join_room_by_id_or_alias::Response> { | ||||||
|     let user_id = body.user_id.clone().expect("user is authenticated"); |     let user_id = body.user_id.as_ref().expect("user is authenticated"); | ||||||
| 
 | 
 | ||||||
|     let room_id = match RoomId::try_from(body.room_id_or_alias.clone()) { |     let room_id = match RoomId::try_from(body.room_id_or_alias.clone()) { | ||||||
|         Ok(room_id) => room_id, |         Ok(room_id) => room_id, | ||||||
|  | @ -965,7 +963,7 @@ pub fn leave_room_route( | ||||||
|     body: Ruma<leave_room::Request>, |     body: Ruma<leave_room::Request>, | ||||||
|     _room_id: String, |     _room_id: String, | ||||||
| ) -> MatrixResult<leave_room::Response> { | ) -> MatrixResult<leave_room::Response> { | ||||||
|     let user_id = body.user_id.clone().expect("user is authenticated"); |     let user_id = body.user_id.as_ref().expect("user is authenticated"); | ||||||
|     db.rooms |     db.rooms | ||||||
|         .leave(&user_id, &body.room_id, &user_id, &db.globals) |         .leave(&user_id, &body.room_id, &user_id, &db.globals) | ||||||
|         .unwrap(); |         .unwrap(); | ||||||
|  | @ -978,7 +976,7 @@ pub fn forget_room_route( | ||||||
|     body: Ruma<forget_room::Request>, |     body: Ruma<forget_room::Request>, | ||||||
|     _room_id: String, |     _room_id: String, | ||||||
| ) -> MatrixResult<forget_room::Response> { | ) -> MatrixResult<forget_room::Response> { | ||||||
|     let user_id = body.user_id.clone().expect("user is authenticated"); |     let user_id = body.user_id.as_ref().expect("user is authenticated"); | ||||||
|     db.rooms.forget(&body.room_id, &user_id).unwrap(); |     db.rooms.forget(&body.room_id, &user_id).unwrap(); | ||||||
|     MatrixResult(Ok(forget_room::Response)) |     MatrixResult(Ok(forget_room::Response)) | ||||||
| } | } | ||||||
|  | @ -1112,7 +1110,7 @@ pub fn create_message_event_route( | ||||||
|     _txn_id: String, |     _txn_id: String, | ||||||
|     body: Ruma<create_message_event::Request>, |     body: Ruma<create_message_event::Request>, | ||||||
| ) -> MatrixResult<create_message_event::Response> { | ) -> MatrixResult<create_message_event::Response> { | ||||||
|     let user_id = body.user_id.clone().expect("user is authenticated"); |     let user_id = body.user_id.as_ref().expect("user is authenticated"); | ||||||
| 
 | 
 | ||||||
|     let mut unsigned = serde_json::Map::new(); |     let mut unsigned = serde_json::Map::new(); | ||||||
|     unsigned.insert("transaction_id".to_owned(), body.txn_id.clone().into()); |     unsigned.insert("transaction_id".to_owned(), body.txn_id.clone().into()); | ||||||
|  | @ -1146,14 +1144,14 @@ pub fn create_state_event_for_key_route( | ||||||
|     _state_key: String, |     _state_key: String, | ||||||
|     body: Ruma<create_state_event_for_key::Request>, |     body: Ruma<create_state_event_for_key::Request>, | ||||||
| ) -> MatrixResult<create_state_event_for_key::Response> { | ) -> MatrixResult<create_state_event_for_key::Response> { | ||||||
|     let user_id = body.user_id.clone().expect("user is authenticated"); |     let user_id = body.user_id.as_ref().expect("user is authenticated"); | ||||||
| 
 | 
 | ||||||
|     // Reponse of with/without key is the same
 |     // Reponse of with/without key is the same
 | ||||||
|     let event_id = db |     let event_id = db | ||||||
|         .rooms |         .rooms | ||||||
|         .append_pdu( |         .append_pdu( | ||||||
|             body.room_id.clone(), |             body.room_id.clone(), | ||||||
|             user_id, |             user_id.clone(), | ||||||
|             body.event_type.clone(), |             body.event_type.clone(), | ||||||
|             body.json_body.clone(), |             body.json_body.clone(), | ||||||
|             None, |             None, | ||||||
|  | @ -1177,14 +1175,14 @@ pub fn create_state_event_for_empty_key_route( | ||||||
|     _event_type: String, |     _event_type: String, | ||||||
|     body: Ruma<create_state_event_for_empty_key::Request>, |     body: Ruma<create_state_event_for_empty_key::Request>, | ||||||
| ) -> MatrixResult<create_state_event_for_empty_key::Response> { | ) -> MatrixResult<create_state_event_for_empty_key::Response> { | ||||||
|     let user_id = body.user_id.clone().expect("user is authenticated"); |     let user_id = body.user_id.as_ref().expect("user is authenticated"); | ||||||
| 
 | 
 | ||||||
|     // Reponse of with/without key is the same
 |     // Reponse of with/without key is the same
 | ||||||
|     let event_id = db |     let event_id = db | ||||||
|         .rooms |         .rooms | ||||||
|         .append_pdu( |         .append_pdu( | ||||||
|             body.room_id.clone(), |             body.room_id.clone(), | ||||||
|             user_id, |             user_id.clone(), | ||||||
|             body.event_type.clone(), |             body.event_type.clone(), | ||||||
|             body.json_body.clone(), |             body.json_body.clone(), | ||||||
|             None, |             None, | ||||||
|  | @ -1204,7 +1202,7 @@ pub fn sync_route( | ||||||
|     body: Ruma<sync_events::Request>, |     body: Ruma<sync_events::Request>, | ||||||
| ) -> MatrixResult<sync_events::Response> { | ) -> MatrixResult<sync_events::Response> { | ||||||
|     std::thread::sleep(Duration::from_millis(1500)); |     std::thread::sleep(Duration::from_millis(1500)); | ||||||
|     let user_id = body.user_id.clone().expect("user is authenticated"); |     let user_id = body.user_id.as_ref().expect("user is authenticated"); | ||||||
|     let next_batch = db.globals.current_count().unwrap().to_string(); |     let next_batch = db.globals.current_count().unwrap().to_string(); | ||||||
| 
 | 
 | ||||||
|     let mut joined_rooms = BTreeMap::new(); |     let mut joined_rooms = BTreeMap::new(); | ||||||
|  | @ -1344,10 +1342,7 @@ pub fn sync_route( | ||||||
|     for room_id in db.rooms.rooms_left(&user_id) { |     for room_id in db.rooms.rooms_left(&user_id) { | ||||||
|         let room_id = room_id.unwrap(); |         let room_id = room_id.unwrap(); | ||||||
|         let pdus = db.rooms.pdus_since(&room_id, since).unwrap(); |         let pdus = db.rooms.pdus_since(&room_id, since).unwrap(); | ||||||
|         let room_events = pdus |         let room_events = pdus.map(|pdu| pdu.unwrap().to_room_event()).collect(); | ||||||
|             .into_iter() |  | ||||||
|             .map(|pdu| pdu.unwrap().to_room_event()) |  | ||||||
|             .collect(); |  | ||||||
| 
 | 
 | ||||||
|         let mut edus = db |         let mut edus = db | ||||||
|             .rooms |             .rooms | ||||||
|  | @ -1380,7 +1375,6 @@ pub fn sync_route( | ||||||
|             .rooms |             .rooms | ||||||
|             .pdus_since(&room_id, since) |             .pdus_since(&room_id, since) | ||||||
|             .unwrap() |             .unwrap() | ||||||
|             .into_iter() |  | ||||||
|             .map(|pdu| pdu.unwrap().to_stripped_state_event()) |             .map(|pdu| pdu.unwrap().to_stripped_state_event()) | ||||||
|             .collect(); |             .collect(); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -33,13 +33,12 @@ impl AccountData { | ||||||
|             .rev() |             .rev() | ||||||
|             .filter_map(|r| r.ok()) |             .filter_map(|r| r.ok()) | ||||||
|             .take_while(|key| key.starts_with(&prefix)) |             .take_while(|key| key.starts_with(&prefix)) | ||||||
|             .filter(|key| { |             .find(|key| { | ||||||
|                 key.split(|&b| b == 0xff) |                 key.split(|&b| b == 0xff) | ||||||
|                     .nth(1) |                     .nth(1) | ||||||
|                     .filter(|&user| user == user_id.to_string().as_bytes()) |                     .filter(|&user| user == user_id.to_string().as_bytes()) | ||||||
|                     .is_some() |                     .is_some() | ||||||
|             }) |             }) | ||||||
|             .next() |  | ||||||
|         { |         { | ||||||
|             // This is the old room_latest
 |             // This is the old room_latest
 | ||||||
|             self.roomuserdataid_accountdata.remove(old)?; |             self.roomuserdataid_accountdata.remove(old)?; | ||||||
|  |  | ||||||
|  | @ -261,14 +261,14 @@ impl Rooms { | ||||||
|         self.pduid_pdu.insert(&pdu_id, &*pdu_json.to_string())?; |         self.pduid_pdu.insert(&pdu_id, &*pdu_json.to_string())?; | ||||||
| 
 | 
 | ||||||
|         self.eventid_pduid |         self.eventid_pduid | ||||||
|             .insert(pdu.event_id.to_string(), pdu_id.clone())?; |             .insert(pdu.event_id.to_string(), pdu_id)?; | ||||||
| 
 | 
 | ||||||
|         if let Some(state_key) = pdu.state_key { |         if let Some(state_key) = pdu.state_key { | ||||||
|             let mut key = room_id.to_string().as_bytes().to_vec(); |             let mut key = room_id.to_string().as_bytes().to_vec(); | ||||||
|             key.push(0xff); |             key.push(0xff); | ||||||
|             key.extend_from_slice(pdu.kind.to_string().as_bytes()); |             key.extend_from_slice(pdu.kind.to_string().as_bytes()); | ||||||
|             key.push(0xff); |             key.push(0xff); | ||||||
|             key.extend_from_slice(state_key.to_string().as_bytes()); |             key.extend_from_slice(state_key.as_bytes()); | ||||||
|             self.roomstateid_pdu.insert(key, &*pdu_json.to_string())?; |             self.roomstateid_pdu.insert(key, &*pdu_json.to_string())?; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -84,7 +84,7 @@ fn setup_rocket() -> rocket::Rocket { | ||||||
| 
 | 
 | ||||||
| fn main() { | fn main() { | ||||||
|     // Log info by default
 |     // Log info by default
 | ||||||
|     if let Err(_) = std::env::var("RUST_LOG") { |     if std::env::var("RUST_LOG").is_err() { | ||||||
|         std::env::set_var("RUST_LOG", "warn"); |         std::env::set_var("RUST_LOG", "warn"); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -62,7 +62,6 @@ impl<'a, T: Endpoint> FromData<'a> for Ruma<T> { | ||||||
|                     None => return Failure((Status::Unauthorized, ())), |                     None => return Failure((Status::Unauthorized, ())), | ||||||
|                     Some((user_id, device_id)) => (Some(user_id), Some(device_id)), |                     Some((user_id, device_id)) => (Some(user_id), Some(device_id)), | ||||||
|                 } |                 } | ||||||
| 
 |  | ||||||
|             } else { |             } else { | ||||||
|                 (None, None) |                 (None, None) | ||||||
|             }; |             }; | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue