Commit b45b14857e
Unsigned
Layout: unified · split
src/room_buffer.rs +5 −4
| @@ -23,6 +23,7 @@ | ||
| 23 | 23 | //! decrypt a previously undecryptable event. |
| 24 | 24 | use matrix_sdk::events::collections::all::{RoomEvent, StateEvent}; |
| 25 | 25 | use matrix_sdk::events::room::encrypted::EncryptedEvent; |
| 26 | use matrix_sdk::identifiers::{RoomId, UserId}; | |
| 26 | 27 | use matrix_sdk::events::room::member::{MemberEvent, MembershipState}; |
| 27 | 28 | use matrix_sdk::events::room::message::{ |
| 28 | 29 | MessageEvent, MessageEventContent, TextMessageEventContent, |
| @@ -49,7 +50,7 @@ pub(crate) struct RoomBuffer { | ||
| 49 | 50 | server_name: String, |
| 50 | 51 | homeserver: Url, |
| 51 | 52 | buffer_handle: BufferHandle, |
| 52 | room_id: String, | |
| 53 | room_id: RoomId, | |
| 53 | 54 | prev_batch: Option<String>, |
| 54 | 55 | typing_notice_time: Option<u64>, |
| 55 | 56 | room: Room, |
| @@ -62,8 +63,8 @@ impl RoomBuffer { | ||
| 62 | 63 | connected_state: &Rc<RefCell<Option<Connection>>>, |
| 63 | 64 | homeserver: &Url, |
| 64 | 65 | config: &Config, |
| 65 | room_id: String, | |
| 66 | own_user_id: &str, | |
| 66 | room_id: RoomId, | |
| 67 | own_user_id: &UserId, | |
| 67 | 68 | ) -> Self { |
| 68 | 69 | let state = Rc::downgrade(connected_state); |
| 69 | 70 | |
| @@ -112,7 +113,7 @@ impl RoomBuffer { | ||
| 112 | 113 | buffer_handle, |
| 113 | 114 | prev_batch: None, |
| 114 | 115 | typing_notice_time: None, |
| 115 | room: Room::new(&room_id, &own_user_id.to_string()), | |
| 116 | room: Room::new(&room_id, &own_user_id), | |
| 116 | 117 | printed_before_ack_queue: Vec::new(), |
| 117 | 118 | } |
| 118 | 119 | } |
src/server.rs +15 −14
| @@ -63,6 +63,7 @@ use matrix_sdk::api::r0::session::login::Response as LoginResponse; | ||
| 63 | 63 | |
| 64 | 64 | use matrix_sdk::{ |
| 65 | 65 | self, |
| 66 | identifiers::{RoomId, UserId}, | |
| 66 | 67 | events::{ |
| 67 | 68 | collections::all::{RoomEvent, StateEvent}, |
| 68 | 69 | room::message::{MessageEventContent, TextMessageEventContent}, |
| @@ -85,8 +86,8 @@ const DEFAULT_SYNC_TIMEOUT: Duration = Duration::from_secs(30); | ||
| 85 | 86 | |
| 86 | 87 | pub enum ThreadMessage { |
| 87 | 88 | LoginMessage(LoginResponse), |
| 88 | SyncState(String, StateEvent), | |
| 89 | SyncEvent(String, RoomEvent), | |
| 89 | SyncState(RoomId, StateEvent), | |
| 90 | SyncEvent(RoomId, RoomEvent), | |
| 90 | 91 | } |
| 91 | 92 | |
| 92 | 93 | #[derive(Debug)] |
| @@ -95,7 +96,7 @@ pub enum ServerError { | ||
| 95 | 96 | } |
| 96 | 97 | |
| 97 | 98 | pub enum ServerMessage { |
| 98 | RoomSend(String, String), | |
| 99 | RoomSend(RoomId, String), | |
| 99 | 100 | } |
| 100 | 101 | |
| 101 | 102 | #[derive(Default)] |
| @@ -114,7 +115,7 @@ impl ServerSettings { | ||
| 114 | 115 | } |
| 115 | 116 | |
| 116 | 117 | pub struct LoginState { |
| 117 | user_id: String, | |
| 118 | user_id: UserId, | |
| 118 | 119 | device_id: String, |
| 119 | 120 | } |
| 120 | 121 | |
| @@ -127,7 +128,7 @@ pub struct Connection { | ||
| 127 | 128 | } |
| 128 | 129 | |
| 129 | 130 | impl Connection { |
| 130 | pub async fn send_message(&self, room_id: &str, message: &str) { | |
| 131 | pub async fn send_message(&self, room_id: &RoomId, message: &str) { | |
| 131 | 132 | self.client_channel |
| 132 | 133 | .send(ServerMessage::RoomSend( |
| 133 | 134 | room_id.to_owned(), |
| @@ -145,7 +146,7 @@ pub(crate) struct MatrixServer { | ||
| 145 | 146 | |
| 146 | 147 | pub(crate) struct InnerServer { |
| 147 | 148 | server_name: Rc<String>, |
| 148 | room_buffers: HashMap<String, RoomBuffer>, | |
| 149 | room_buffers: HashMap<RoomId, RoomBuffer>, | |
| 149 | 150 | settings: ServerSettings, |
| 150 | 151 | config: Config, |
| 151 | 152 | client: Option<AsyncClient>, |
| @@ -356,7 +357,7 @@ impl Drop for MatrixServer { | ||
| 356 | 357 | impl InnerServer { |
| 357 | 358 | pub(crate) fn get_or_create_room( |
| 358 | 359 | &mut self, |
| 359 | room_id: &str, | |
| 360 | room_id: &RoomId, | |
| 360 | 361 | ) -> &mut RoomBuffer { |
| 361 | 362 | if !self.room_buffers.contains_key(room_id) { |
| 362 | 363 | let homeserver = self |
| @@ -373,10 +374,10 @@ impl InnerServer { | ||
| 373 | 374 | &self.connected_state, |
| 374 | 375 | homeserver, |
| 375 | 376 | &self.config, |
| 376 | room_id.to_string(), | |
| 377 | room_id.clone(), | |
| 377 | 378 | &login_state.user_id, |
| 378 | 379 | ); |
| 379 | self.room_buffers.insert(room_id.to_string(), buffer); | |
| 380 | self.room_buffers.insert(room_id.clone(), buffer); | |
| 380 | 381 | } |
| 381 | 382 | |
| 382 | 383 | self.room_buffers.get_mut(room_id).unwrap() |
| @@ -389,7 +390,7 @@ impl InnerServer { | ||
| 389 | 390 | |
| 390 | 391 | pub(crate) fn receive_joined_state_event( |
| 391 | 392 | &mut self, |
| 392 | room_id: &str, | |
| 393 | room_id: &RoomId, | |
| 393 | 394 | event: StateEvent, |
| 394 | 395 | ) { |
| 395 | 396 | let room = self.get_or_create_room(room_id); |
| @@ -398,7 +399,7 @@ impl InnerServer { | ||
| 398 | 399 | |
| 399 | 400 | pub(crate) fn receive_joined_timeline_event( |
| 400 | 401 | &mut self, |
| 401 | room_id: &str, | |
| 402 | room_id: &RoomId, | |
| 402 | 403 | event: RoomEvent, |
| 403 | 404 | ) { |
| 404 | 405 | let room = self.get_or_create_room(room_id); |
| @@ -407,7 +408,7 @@ impl InnerServer { | ||
| 407 | 408 | |
| 408 | 409 | pub fn receive_login(&mut self, response: LoginResponse) { |
| 409 | 410 | let login_state = LoginState { |
| 410 | user_id: response.user_id.to_string(), | |
| 411 | user_id: response.user_id, | |
| 411 | 412 | device_id: response.device_id, |
| 412 | 413 | }; |
| 413 | 414 | self.login_state = Some(login_state); |
| @@ -568,7 +569,7 @@ impl MatrixServer { | ||
| 568 | 569 | if let EventResult::Ok(e) = event { |
| 569 | 570 | channel |
| 570 | 571 | .send(Ok(ThreadMessage::SyncState( |
| 571 | room_id.to_string(), | |
| 572 | room_id.clone(), | |
| 572 | 573 | e, |
| 573 | 574 | ))) |
| 574 | 575 | .await; |
| @@ -578,7 +579,7 @@ impl MatrixServer { | ||
| 578 | 579 | if let EventResult::Ok(e) = event { |
| 579 | 580 | channel |
| 580 | 581 | .send(Ok(ThreadMessage::SyncEvent( |
| 581 | room_id.to_string(), | |
| 582 | room_id.clone(), | |
| 582 | 583 | e, |
| 583 | 584 | ))) |
| 584 | 585 | .await; |