base/async_client: remove deadcode, remove get room name methods from AsyncClient
parent
fa4a99504e
commit
35afd65705
|
@ -315,24 +315,6 @@ impl AsyncClient {
|
||||||
self.base_client.add_event_emitter(emitter).await;
|
self.base_client.add_event_emitter(emitter).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns an `Option` of the room name from a `RoomId`.
|
|
||||||
///
|
|
||||||
/// This is a human readable room name.
|
|
||||||
pub async fn get_room_name(&self, room_id: &RoomId) -> Option<String> {
|
|
||||||
// TODO do we want to use the `RoomStateType` enum here or should we have
|
|
||||||
// 3 separate `room_name` methods. The other option is to remove this and have
|
|
||||||
// the user get a `Room` and use `Room::calculate_name` method?
|
|
||||||
self.base_client.calculate_room_name(room_id).await
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns a `Vec` of the room names this client knows about.
|
|
||||||
///
|
|
||||||
/// This is a human readable list of room names.
|
|
||||||
pub async fn get_room_names(&self) -> Vec<String> {
|
|
||||||
// TODO same as get_room_name
|
|
||||||
self.base_client.calculate_room_names().await
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the joined rooms this client knows about.
|
/// Returns the joined rooms this client knows about.
|
||||||
///
|
///
|
||||||
/// A `HashMap` of room id to `matrix::models::Room`
|
/// A `HashMap` of room id to `matrix::models::Room`
|
||||||
|
@ -396,14 +378,18 @@ impl AsyncClient {
|
||||||
/// # let homeserver = Url::parse("http://example.com").unwrap();
|
/// # let homeserver = Url::parse("http://example.com").unwrap();
|
||||||
/// let store = JsonStore::open("path/to/store").unwrap();
|
/// let store = JsonStore::open("path/to/store").unwrap();
|
||||||
/// let config = AsyncClientConfig::new().state_store(Box::new(store));
|
/// let config = AsyncClientConfig::new().state_store(Box::new(store));
|
||||||
/// let mut cli = AsyncClient::new(homeserver, None).unwrap();
|
/// let mut client = AsyncClient::new(homeserver, None).unwrap();
|
||||||
/// # use futures::executor::block_on;
|
/// # use futures::executor::block_on;
|
||||||
/// # block_on(async {
|
/// # block_on(async {
|
||||||
/// let _ = cli.login("name", "password", None, None).await.unwrap();
|
/// let _ = client.login("name", "password", None, None).await.unwrap();
|
||||||
/// // returns true when a state store sync is successful
|
/// // returns true when a state store sync is successful
|
||||||
/// assert!(cli.sync_with_state_store().await.unwrap());
|
/// assert!(client.sync_with_state_store().await.unwrap());
|
||||||
/// // now state is restored without a request to the server
|
/// // now state is restored without a request to the server
|
||||||
/// assert_eq!(vec!["room".to_string(), "names".to_string()], cli.get_room_names().await)
|
/// let mut names = vec![];
|
||||||
|
/// for r in client.joined_rooms().read().await.values() {
|
||||||
|
/// names.push(r.read().await.calculate_name());
|
||||||
|
/// }
|
||||||
|
/// assert_eq!(vec!["room".to_string(), "names".to_string()], names)
|
||||||
/// # });
|
/// # });
|
||||||
/// ```
|
/// ```
|
||||||
pub async fn sync_with_state_store(&self) -> Result<bool> {
|
pub async fn sync_with_state_store(&self) -> Result<bool> {
|
||||||
|
|
|
@ -267,24 +267,6 @@ impl Client {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn calculate_room_name(&self, room_id: &RoomId) -> Option<String> {
|
|
||||||
if let Some(room) = self.joined_rooms.read().await.get(room_id) {
|
|
||||||
let room = room.read().await;
|
|
||||||
Some(room.room_name.calculate_name(&room.members))
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) async fn calculate_room_names(&self) -> Vec<String> {
|
|
||||||
let mut res = Vec::new();
|
|
||||||
for room in self.joined_rooms.read().await.values() {
|
|
||||||
let room = room.read().await;
|
|
||||||
res.push(room.room_name.calculate_name(&room.members))
|
|
||||||
}
|
|
||||||
res
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) async fn get_or_create_joined_room(&self, room_id: &RoomId) -> Arc<RwLock<Room>> {
|
pub(crate) async fn get_or_create_joined_room(&self, room_id: &RoomId) -> Arc<RwLock<Room>> {
|
||||||
#[allow(clippy::or_fun_call)]
|
#[allow(clippy::or_fun_call)]
|
||||||
let mut rooms = self.joined_rooms.write().await;
|
let mut rooms = self.joined_rooms.write().await;
|
||||||
|
@ -510,33 +492,15 @@ impl Client {
|
||||||
pub async fn receive_left_timeline_event(
|
pub async fn receive_left_timeline_event(
|
||||||
&self,
|
&self,
|
||||||
room_id: &RoomId,
|
room_id: &RoomId,
|
||||||
event: &mut EventJson<RoomEvent>,
|
event: &EventJson<RoomEvent>,
|
||||||
) -> (Option<EventJson<RoomEvent>>, bool) {
|
) -> bool {
|
||||||
match event.deserialize() {
|
match event.deserialize() {
|
||||||
#[allow(unused_mut)]
|
Ok(e) => {
|
||||||
Ok(mut e) => {
|
|
||||||
#[cfg(feature = "encryption")]
|
|
||||||
let mut decrypted_event = None;
|
|
||||||
#[cfg(not(feature = "encryption"))]
|
|
||||||
let decrypted_event = None;
|
|
||||||
|
|
||||||
#[cfg(feature = "encryption")]
|
|
||||||
{
|
|
||||||
if let RoomEvent::RoomEncrypted(ref mut e) = e {
|
|
||||||
e.room_id = Some(room_id.to_owned());
|
|
||||||
let mut olm = self.olm.lock().await;
|
|
||||||
|
|
||||||
if let Some(o) = &mut *olm {
|
|
||||||
decrypted_event = o.decrypt_room_event(&e).await.ok();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let room_lock = self.get_or_create_left_room(room_id).await;
|
let room_lock = self.get_or_create_left_room(room_id).await;
|
||||||
let mut room = room_lock.write().await;
|
let mut room = room_lock.write().await;
|
||||||
(decrypted_event, room.receive_timeline_event(&e))
|
room.receive_timeline_event(&e)
|
||||||
}
|
}
|
||||||
_ => (None, false),
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -652,7 +616,7 @@ impl Client {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// when events change state updated signals to state store to update database
|
// when events change state, updated signals to StateStore to update database
|
||||||
let mut updated = self.iter_joined_rooms(response).await?;
|
let mut updated = self.iter_joined_rooms(response).await?;
|
||||||
|
|
||||||
if self.iter_invited_rooms(&response).await? {
|
if self.iter_invited_rooms(&response).await? {
|
||||||
|
@ -808,18 +772,9 @@ impl Client {
|
||||||
}
|
}
|
||||||
|
|
||||||
for mut event in &mut left_room.timeline.events {
|
for mut event in &mut left_room.timeline.events {
|
||||||
let decrypted_event = {
|
if self.receive_left_timeline_event(room_id, &mut event).await {
|
||||||
let (decrypt_ev, timeline_update) =
|
|
||||||
self.receive_left_timeline_event(room_id, &mut event).await;
|
|
||||||
if timeline_update {
|
|
||||||
updated = true;
|
updated = true;
|
||||||
};
|
};
|
||||||
decrypt_ev
|
|
||||||
};
|
|
||||||
|
|
||||||
if let Some(e) = decrypted_event {
|
|
||||||
*event = e;
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Ok(e) = event.deserialize() {
|
if let Ok(e) = event.deserialize() {
|
||||||
self.emit_timeline_event(&room_id, &e, RoomStateType::Left)
|
self.emit_timeline_event(&room_id, &e, RoomStateType::Left)
|
||||||
|
@ -853,7 +808,7 @@ impl Client {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.get_or_create_left_room(&room_id).await.clone()
|
self.get_or_create_invited_room(&room_id).await.clone()
|
||||||
};
|
};
|
||||||
|
|
||||||
for event in &invited_room.invite_state.events {
|
for event in &invited_room.invite_state.events {
|
||||||
|
|
|
@ -633,6 +633,10 @@ mod test {
|
||||||
let sync_settings = SyncSettings::new().timeout(Duration::from_millis(3000));
|
let sync_settings = SyncSettings::new().timeout(Duration::from_millis(3000));
|
||||||
let _response = client.sync(sync_settings).await.unwrap();
|
let _response = client.sync(sync_settings).await.unwrap();
|
||||||
|
|
||||||
assert_eq!(vec!["example, example2"], client.get_room_names().await);
|
let mut names = vec![];
|
||||||
|
for r in client.joined_rooms().read().await.values() {
|
||||||
|
names.push(r.read().await.calculate_name());
|
||||||
|
}
|
||||||
|
assert_eq!(vec!["example, example2"], names);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,11 +81,15 @@ async fn room_names() {
|
||||||
|
|
||||||
let _response = client.sync(sync_settings).await.unwrap();
|
let _response = client.sync(sync_settings).await.unwrap();
|
||||||
|
|
||||||
assert_eq!(vec!["tutorial"], client.get_room_names().await);
|
let mut names = vec![];
|
||||||
assert_eq!(
|
for r in client.joined_rooms().read().await.values() {
|
||||||
Some("tutorial".into()),
|
names.push(r.read().await.calculate_name());
|
||||||
client
|
}
|
||||||
.get_room_name(&RoomId::try_from("!SVkFJHzfwvuaIEawgC:localhost").unwrap())
|
assert_eq!(vec!["tutorial"], names);
|
||||||
|
let room = client
|
||||||
|
.get_joined_room(&RoomId::try_from("!SVkFJHzfwvuaIEawgC:localhost").unwrap())
|
||||||
.await
|
.await
|
||||||
);
|
.unwrap();
|
||||||
|
|
||||||
|
assert_eq!("tutorial".to_string(), room.read().await.calculate_name());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue