Resolve stying review issues
This commit is contained in:
		
							parent
							
								
									029c60be78
								
							
						
					
					
						commit
						75959cdc10
					
				
					 5 changed files with 59 additions and 31 deletions
				
			
		|  | @ -27,8 +27,4 @@ reqwest = "0.10.6" | ||||||
| base64 = "0.12.1" | base64 = "0.12.1" | ||||||
| thiserror = "1.0.19" | thiserror = "1.0.19" | ||||||
| image = { version = "0.23.4", default-features = false, features = ["jpeg", "png", "gif"] } | image = { version = "0.23.4", default-features = false, features = ["jpeg", "png", "gif"] } | ||||||
| 
 | ruma = { git = "https://github.com/ruma/ruma", features = ["rand", "client-api", "federation-api", "unstable-pre-spec", "unstable-synapse-quirks"], rev = "848b225" } | ||||||
| [dependencies.ruma] |  | ||||||
| git = "https://github.com/ruma/ruma" |  | ||||||
| features = ["rand", "client-api", "federation-api", "unstable-pre-spec", "unstable-synapse-quirks"] |  | ||||||
| rev = "848b225" |  | ||||||
|  |  | ||||||
|  | @ -64,7 +64,7 @@ use ruma::{ | ||||||
|             canonical_alias, guest_access, history_visibility, join_rules, member, name, redaction, |             canonical_alias, guest_access, history_visibility, join_rules, member, name, redaction, | ||||||
|             topic, |             topic, | ||||||
|         }, |         }, | ||||||
|         AnyBasicEvent, AnyEphemeralRoomEvent, AnyEvent as EduEvent, EventJson, EventType, |         AnyBasicEvent, AnyEphemeralRoomEvent, AnyEvent, EventJson, EventType, | ||||||
|     }, |     }, | ||||||
|     identifiers::{RoomAliasId, RoomId, RoomVersionId, UserId}, |     identifiers::{RoomAliasId, RoomId, RoomVersionId, UserId}, | ||||||
| }; | }; | ||||||
|  | @ -285,7 +285,7 @@ pub fn login_route( | ||||||
|         user_id, |         user_id, | ||||||
|         access_token: token, |         access_token: token, | ||||||
|         home_server: Some(db.globals.server_name().to_string()), |         home_server: Some(db.globals.server_name().to_string()), | ||||||
|         device_id: device_id.to_string(), |         device_id: device_id.into(), | ||||||
|         well_known: None, |         well_known: None, | ||||||
|     } |     } | ||||||
|     .into()) |     .into()) | ||||||
|  | @ -479,7 +479,7 @@ pub fn get_pushrules_all_route( | ||||||
| ) -> ConduitResult<get_pushrules_all::Response> { | ) -> ConduitResult<get_pushrules_all::Response> { | ||||||
|     let user_id = body.user_id.as_ref().expect("user is authenticated"); |     let user_id = body.user_id.as_ref().expect("user is authenticated"); | ||||||
| 
 | 
 | ||||||
|     if let EduEvent::Basic(AnyBasicEvent::PushRules(pushrules)) = db |     if let AnyEvent::Basic(AnyBasicEvent::PushRules(pushrules)) = db | ||||||
|         .account_data |         .account_data | ||||||
|         .get(None, &user_id, &EventType::PushRules)? |         .get(None, &user_id, &EventType::PushRules)? | ||||||
|         .ok_or(Error::BadRequest( |         .ok_or(Error::BadRequest( | ||||||
|  | @ -602,13 +602,13 @@ pub fn get_global_account_data_route( | ||||||
|         )? |         )? | ||||||
|         .ok_or(Error::BadRequest(ErrorKind::NotFound, "Data not found."))?; |         .ok_or(Error::BadRequest(ErrorKind::NotFound, "Data not found."))?; | ||||||
| 
 | 
 | ||||||
|     let data: Result<EduEvent, Error> = data |     let data: AnyEvent = data | ||||||
|         .deserialize() |         .deserialize() | ||||||
|         .map_err(|_| Error::bad_database("Deserialization of account data failed")); |         .map_err(|_| Error::bad_database("Deserialization of account data failed"))?; | ||||||
| 
 | 
 | ||||||
|     if let EduEvent::Basic(data) = data? { |     if let AnyEvent::Basic(data) = data { | ||||||
|         Ok(get_global_account_data::Response { |         Ok(get_global_account_data::Response { | ||||||
|             account_data: EventJson::from(data), |             account_data: data.into(), | ||||||
|         } |         } | ||||||
|         .into()) |         .into()) | ||||||
|     } else { |     } else { | ||||||
|  | @ -1145,7 +1145,7 @@ pub fn set_read_marker_route( | ||||||
|         db.rooms.edus.roomlatest_update( |         db.rooms.edus.roomlatest_update( | ||||||
|             &user_id, |             &user_id, | ||||||
|             &body.room_id, |             &body.room_id, | ||||||
|             EduEvent::Ephemeral(AnyEphemeralRoomEvent::Receipt( |             AnyEvent::Ephemeral(AnyEphemeralRoomEvent::Receipt( | ||||||
|                 ruma::events::receipt::ReceiptEvent { |                 ruma::events::receipt::ReceiptEvent { | ||||||
|                     content: ruma::events::receipt::ReceiptEventContent(receipt_content), |                     content: ruma::events::receipt::ReceiptEventContent(receipt_content), | ||||||
|                     room_id: body.room_id.clone(), |                     room_id: body.room_id.clone(), | ||||||
|  | @ -1221,6 +1221,7 @@ pub fn create_room_route( | ||||||
|         .as_ref() |         .as_ref() | ||||||
|         .and_then(|c| c.predecessor.clone()); |         .and_then(|c| c.predecessor.clone()); | ||||||
|     content.room_version = RoomVersionId::version_6(); |     content.room_version = RoomVersionId::version_6(); | ||||||
|  | 
 | ||||||
|     // 1. The room create event
 |     // 1. The room create event
 | ||||||
|     db.rooms.append_pdu( |     db.rooms.append_pdu( | ||||||
|         room_id.clone(), |         room_id.clone(), | ||||||
|  | @ -2511,7 +2512,7 @@ pub fn sync_route( | ||||||
| 
 | 
 | ||||||
|         let room_events = pdus |         let room_events = pdus | ||||||
|             .into_iter() |             .into_iter() | ||||||
|             .map(|pdu| pdu.to_room_event_stub()) |             .map(|pdu| pdu.to_sync_room_event()) | ||||||
|             .collect::<Vec<_>>(); |             .collect::<Vec<_>>(); | ||||||
| 
 | 
 | ||||||
|         let mut edus = db |         let mut edus = db | ||||||
|  | @ -2529,7 +2530,7 @@ pub fn sync_route( | ||||||
|         { |         { | ||||||
|             edus.push( |             edus.push( | ||||||
|                 serde_json::from_str( |                 serde_json::from_str( | ||||||
|                     &serde_json::to_string(&EduEvent::Ephemeral(AnyEphemeralRoomEvent::Typing( |                     &serde_json::to_string(&AnyEvent::Ephemeral(AnyEphemeralRoomEvent::Typing( | ||||||
|                         db.rooms.edus.roomactives_all(&room_id)?, |                         db.rooms.edus.roomactives_all(&room_id)?, | ||||||
|                     ))) |                     ))) | ||||||
|                     .expect("event is valid, we just created it"), |                     .expect("event is valid, we just created it"), | ||||||
|  | @ -2544,14 +2545,14 @@ pub fn sync_route( | ||||||
|                     .account_data |                     .account_data | ||||||
|                     .changes_since(Some(&room_id), &user_id, since)? |                     .changes_since(Some(&room_id), &user_id, since)? | ||||||
|                     .into_iter() |                     .into_iter() | ||||||
|                     .filter_map(|(_, v)| { |                     .map(|(_, v)| { | ||||||
|                         if let Ok(EduEvent::Basic(account_event)) = v.deserialize() { |                         if let Ok(AnyEvent::Basic(account_event)) = v.deserialize() { | ||||||
|                             Some(EventJson::from(account_event)) |                             Ok(EventJson::from(account_event)) | ||||||
|                         } else { |                         } else { | ||||||
|                             None |                             Err(Error::bad_database("found invalid event")) | ||||||
|                         } |                         } | ||||||
|                     }) |                     }) | ||||||
|                     .collect(), |                     .collect::<Result<Vec<_>, _>>()?, | ||||||
|             }, |             }, | ||||||
|             summary: sync_events::RoomSummary { |             summary: sync_events::RoomSummary { | ||||||
|                 heroes, |                 heroes, | ||||||
|  | @ -2573,7 +2574,7 @@ pub fn sync_route( | ||||||
|                     db.rooms |                     db.rooms | ||||||
|                         .room_state_full(&room_id)? |                         .room_state_full(&room_id)? | ||||||
|                         .into_iter() |                         .into_iter() | ||||||
|                         .map(|(_, pdu)| pdu.to_state_event_stub()) |                         .map(|(_, pdu)| pdu.to_sync_state_event()) | ||||||
|                         .collect() |                         .collect() | ||||||
|                 } else { |                 } else { | ||||||
|                     Vec::new() |                     Vec::new() | ||||||
|  | @ -2593,7 +2594,7 @@ pub fn sync_route( | ||||||
|         let pdus = db.rooms.pdus_since(&user_id, &room_id, since)?; |         let pdus = db.rooms.pdus_since(&user_id, &room_id, since)?; | ||||||
|         let room_events = pdus |         let room_events = pdus | ||||||
|             .filter_map(|pdu| pdu.ok()) // Filter out buggy events
 |             .filter_map(|pdu| pdu.ok()) // Filter out buggy events
 | ||||||
|             .map(|pdu| pdu.to_room_event_stub()) |             .map(|pdu| pdu.to_sync_room_event()) | ||||||
|             .collect(); |             .collect(); | ||||||
| 
 | 
 | ||||||
|         // TODO: Only until leave point
 |         // TODO: Only until leave point
 | ||||||
|  | @ -2688,14 +2689,14 @@ pub fn sync_route( | ||||||
|                 .account_data |                 .account_data | ||||||
|                 .changes_since(None, &user_id, since)? |                 .changes_since(None, &user_id, since)? | ||||||
|                 .into_iter() |                 .into_iter() | ||||||
|                 .filter_map(|(_, v)| { |                 .map(|(_, v)| { | ||||||
|                     if let Ok(EduEvent::Basic(account_event)) = v.deserialize() { |                     if let Ok(AnyEvent::Basic(account_event)) = v.deserialize() { | ||||||
|                         Some(EventJson::from(account_event)) |                         Ok(EventJson::from(account_event)) | ||||||
|                     } else { |                     } else { | ||||||
|                         None |                         Err(Error::bad_database("found invalid event")) | ||||||
|                     } |                     } | ||||||
|                 }) |                 }) | ||||||
|                 .collect(), |                 .collect::<Result<Vec<_>, _>>()?, | ||||||
|         }, |         }, | ||||||
|         device_lists: sync_events::DeviceLists { |         device_lists: sync_events::DeviceLists { | ||||||
|             changed: if since != 0 { |             changed: if since != 0 { | ||||||
|  |  | ||||||
|  | @ -62,7 +62,6 @@ impl Database { | ||||||
|                     .to_owned()) |                     .to_owned()) | ||||||
|             })?; |             })?; | ||||||
| 
 | 
 | ||||||
|         println!("{:?}", path); |  | ||||||
|         let db = sled::open(&path)?; |         let db = sled::open(&path)?; | ||||||
|         info!("Opened sled database at {}", path); |         info!("Opened sled database at {}", path); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -31,7 +31,7 @@ impl Globals { | ||||||
|                 .unwrap_or("localhost") |                 .unwrap_or("localhost") | ||||||
|                 .to_string() |                 .to_string() | ||||||
|                 .try_into() |                 .try_into() | ||||||
|                 .map_err(|_| crate::Error::bad_database("Private or public keys are invalid."))?, |                 .map_err(|_| Error::bad_database("Private or public keys are invalid."))?, | ||||||
|             registration_disabled: config.get_bool("registration_disabled").unwrap_or(false), |             registration_disabled: config.get_bool("registration_disabled").unwrap_or(false), | ||||||
|         }) |         }) | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  | @ -1,6 +1,6 @@ | ||||||
| use crate::{utils, Error, Result}; | use crate::{utils, Error, Result}; | ||||||
| use ruma::{ | use ruma::{ | ||||||
|     events::{AnyEvent as EduEvent, EventJson}, |     events::{AnyEvent as EduEvent, EventJson, SyncEphemeralRoomEvent}, | ||||||
|     identifiers::{RoomId, UserId}, |     identifiers::{RoomId, UserId}, | ||||||
| }; | }; | ||||||
| use std::convert::TryFrom; | use std::convert::TryFrom; | ||||||
|  | @ -236,9 +236,41 @@ impl RoomEdus { | ||||||
| 
 | 
 | ||||||
|         Ok(ruma::events::typing::TypingEvent { |         Ok(ruma::events::typing::TypingEvent { | ||||||
|             content: ruma::events::typing::TypingEventContent { user_ids }, |             content: ruma::events::typing::TypingEventContent { user_ids }, | ||||||
|             room_id: room_id.clone(), // Can be inferred
 |             room_id: room_id.clone(), | ||||||
|         }) |         }) | ||||||
|     } |     } | ||||||
|  |     // REMOVE the above method and uncomment the bottom when ruma/ruma PR #141 is merged
 | ||||||
|  |     // pub fn roomactives_all(
 | ||||||
|  |     //     &self,
 | ||||||
|  |     //     room_id: &RoomId,
 | ||||||
|  |     // ) -> Result<SyncEphemeralRoomEvent<ruma::events::typing::TypingEventContent>> {
 | ||||||
|  |     //     let mut prefix = room_id.to_string().as_bytes().to_vec();
 | ||||||
|  |     //     prefix.push(0xff);
 | ||||||
|  | 
 | ||||||
|  |     //     let mut user_ids = Vec::new();
 | ||||||
|  | 
 | ||||||
|  |     //     for user_id in self
 | ||||||
|  |     //         .roomactiveid_userid
 | ||||||
|  |     //         .scan_prefix(prefix)
 | ||||||
|  |     //         .values()
 | ||||||
|  |     //         .map(|user_id| {
 | ||||||
|  |     //             Ok::<_, Error>(
 | ||||||
|  |     //                 UserId::try_from(utils::string_from_bytes(&user_id?).map_err(|_| {
 | ||||||
|  |     //                     Error::bad_database("User ID in roomactiveid_userid is invalid unicode.")
 | ||||||
|  |     //                 })?)
 | ||||||
|  |     //                 .map_err(|_| {
 | ||||||
|  |     //                     Error::bad_database("User ID in roomactiveid_userid is invalid.")
 | ||||||
|  |     //                 })?,
 | ||||||
|  |     //             )
 | ||||||
|  |     //         })
 | ||||||
|  |     //     {
 | ||||||
|  |     //         user_ids.push(user_id?);
 | ||||||
|  |     //     }
 | ||||||
|  | 
 | ||||||
|  |     //     Ok(SyncEphemeralRoomEvent {
 | ||||||
|  |     //         content: ruma::events::typing::TypingEventContent { user_ids },
 | ||||||
|  |     //     })
 | ||||||
|  |     // }
 | ||||||
| 
 | 
 | ||||||
|     /// Sets a private read marker at `count`.
 |     /// Sets a private read marker at `count`.
 | ||||||
|     pub fn room_read_set(&self, room_id: &RoomId, user_id: &UserId, count: u64) -> Result<()> { |     pub fn room_read_set(&self, room_id: &RoomId, user_id: &UserId, count: u64) -> Result<()> { | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue