improvement: load aliases from database
This commit is contained in:
		
							parent
							
								
									18bf67748c
								
							
						
					
					
						commit
						9c26e22ad7
					
				
					 2 changed files with 18 additions and 6 deletions
				
			
		|  | @ -1272,17 +1272,17 @@ pub fn join_room_by_id_or_alias_route( | |||
| ) -> MatrixResult<join_room_by_id_or_alias::Response> { | ||||
|     let room_id = match RoomId::try_from(body.room_id_or_alias.clone()) { | ||||
|         Ok(room_id) => room_id, | ||||
|         Err(room_alias) => { | ||||
|             if room_alias.server_name() == db.globals.server_name() { | ||||
|         Err(_) => { | ||||
|             if let Some(room_id) = db.rooms.id_from_alias(body.room_id_or_alias.as_ref()).unwrap() { | ||||
|                 room_id | ||||
|             } else { | ||||
|                 // Ask creator server of the room to join TODO ask someone else when not available
 | ||||
|                 //server_server::send_request(data, destination, request)
 | ||||
|                 return MatrixResult(Err(Error { | ||||
|                     kind: ErrorKind::NotFound, | ||||
|                     message: "Room alias not found.".to_owned(), | ||||
|                     status_code: http::StatusCode::BAD_REQUEST, | ||||
|                 })); | ||||
|             } else { | ||||
|                 // Ask creator server of the room to join TODO ask someone else when not available
 | ||||
|                 //server_server::send_request(data, destination, request)
 | ||||
|                 todo!(); | ||||
|             } | ||||
|         } | ||||
|     }; | ||||
|  |  | |||
|  | @ -26,6 +26,8 @@ pub struct Rooms { | |||
|     pub(super) roomid_pduleaves: sled::Tree, | ||||
|     pub(super) roomstateid_pdu: sled::Tree, // RoomStateId = Room + StateType + StateKey
 | ||||
| 
 | ||||
|     pub(super) alias_roomid: sled::Tree, | ||||
| 
 | ||||
|     pub(super) userroomid_joined: sled::Tree, | ||||
|     pub(super) roomuserid_joined: sled::Tree, | ||||
|     pub(super) userroomid_invited: sled::Tree, | ||||
|  | @ -646,6 +648,16 @@ impl Rooms { | |||
|         Ok(()) | ||||
|     } | ||||
| 
 | ||||
|     pub fn id_from_alias(&self, alias: &str) -> Result<Option<RoomId>> { | ||||
|         if !alias.starts_with('#') { | ||||
|             return Err(Error::BadRequest("room alias does not start with #")); | ||||
|         } | ||||
| 
 | ||||
|         self.alias_roomid.get(alias)?.map_or(Ok(None), |bytes| { | ||||
|             Ok(Some(RoomId::try_from(utils::string_from_bytes(&bytes)?)?)) | ||||
|         }) | ||||
|     } | ||||
| 
 | ||||
|     /// Returns an iterator over all rooms a user joined.
 | ||||
|     pub fn room_members(&self, room_id: &RoomId) -> impl Iterator<Item = Result<UserId>> { | ||||
|         self.roomuserid_joined | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue