matrix-sdk: Allow users to get a reference to the store.

master
Damir Jelić 2020-12-11 09:52:39 +01:00
parent a4e7dc1042
commit 6f35a05311
6 changed files with 20 additions and 6 deletions

View File

@ -40,7 +40,9 @@ use zeroize::Zeroizing;
use tracing::{debug, warn}; use tracing::{debug, warn};
use tracing::{error, info, instrument}; use tracing::{error, info, instrument};
use matrix_sdk_base::{responses::SyncResponse, BaseClient, BaseClientConfig, Room, Session}; use matrix_sdk_base::{
responses::SyncResponse, BaseClient, BaseClientConfig, Room, Session, Store,
};
#[cfg(feature = "encryption")] #[cfg(feature = "encryption")]
use matrix_sdk_base::crypto::{ use matrix_sdk_base::crypto::{
@ -504,6 +506,11 @@ impl Client {
Ok(response.avatar_url) Ok(response.avatar_url)
} }
/// Get a reference to the store.
pub fn store(&self) -> &Store {
self.base_client.store()
}
/// Sets the mxc avatar url of the client's owner. The avatar gets unset if `url` is `None`. /// Sets the mxc avatar url of the client's owner. The avatar gets unset if `url` is `None`.
pub async fn set_avatar_url(&self, url: Option<&str>) -> Result<()> { pub async fn set_avatar_url(&self, url: Option<&str>) -> Result<()> {
let user_id = self.user_id().await.ok_or(Error::AuthenticationRequired)?; let user_id = self.user_id().await.ok_or(Error::AuthenticationRequired)?;

View File

@ -66,7 +66,7 @@ compile_error!("only one of 'native-tls' or 'rustls-tls' features can be enabled
#[cfg(feature = "encryption")] #[cfg(feature = "encryption")]
#[cfg_attr(feature = "docs", doc(cfg(encryption)))] #[cfg_attr(feature = "docs", doc(cfg(encryption)))]
pub use matrix_sdk_base::crypto::LocalTrust; pub use matrix_sdk_base::crypto::LocalTrust;
pub use matrix_sdk_base::{Error as BaseError, Room, RoomMember, Session}; pub use matrix_sdk_base::{Error as BaseError, Room, RoomInfo, RoomMember, Session};
pub use matrix_sdk_common::*; pub use matrix_sdk_common::*;
pub use reqwest; pub use reqwest;

View File

@ -32,7 +32,7 @@ use matrix_sdk_common::{
room::member::MemberEventContent, AnyBasicEvent, AnyStrippedStateEvent, AnySyncRoomEvent, room::member::MemberEventContent, AnyBasicEvent, AnyStrippedStateEvent, AnySyncRoomEvent,
AnySyncStateEvent, StateEvent, SyncStateEvent, AnySyncStateEvent, StateEvent, SyncStateEvent,
}, },
identifiers::{RoomId, UserId, room_id}, identifiers::{room_id, RoomId, UserId},
locks::RwLock, locks::RwLock,
Raw, Raw,
}; };
@ -350,6 +350,11 @@ impl BaseClient {
&self.session &self.session
} }
/// Get a reference to the store.
pub fn store(&self) -> &Store {
&self.store
}
/// Is the client logged in. /// Is the client logged in.
pub async fn logged_in(&self) -> bool { pub async fn logged_in(&self) -> bool {
// TODO turn this into a atomic bool so this method doesn't need to be // TODO turn this into a atomic bool so this method doesn't need to be

View File

@ -49,7 +49,7 @@ mod rooms;
mod session; mod session;
mod store; mod store;
pub use rooms::{RoomInfo, Room, RoomMember}; pub use rooms::{Room, RoomInfo, RoomMember};
pub use store::Store; pub use store::Store;
pub use client::{BaseClient, BaseClientConfig, RoomState, RoomStateType}; pub use client::{BaseClient, BaseClientConfig, RoomState, RoomStateType};

View File

@ -1,5 +1,5 @@
mod joined; mod joined;
mod members; mod members;
pub use joined::{RoomInfo, Room, RoomType}; pub use joined::{Room, RoomInfo, RoomType};
pub use members::RoomMember; pub use members::RoomMember;

View File

@ -337,7 +337,9 @@ impl Store {
pub async fn get_room_infos(&self) -> impl Stream<Item = RoomInfo> { pub async fn get_room_infos(&self) -> impl Stream<Item = RoomInfo> {
stream::iter( stream::iter(
self.room_summaries.iter().map(|r| serde_json::from_slice(&r.unwrap().1).unwrap()) self.room_summaries
.iter()
.map(|r| serde_json::from_slice(&r.unwrap().1).unwrap()),
) )
} }