Skip to content

Commit

Permalink
Merge branch 'main' into rav/fix_wait_if_user_pending
Browse files Browse the repository at this point in the history
  • Loading branch information
richvdh authored Mar 13, 2023
2 parents fc9dbae + 483bef0 commit e1c6ac9
Show file tree
Hide file tree
Showing 28 changed files with 217 additions and 161 deletions.
28 changes: 13 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ base64 = "0.21.0"
byteorder = "1.4.3"
ctor = "0.1.26"
dashmap = "5.2.0"
eyeball = "0.1.4"
eyeball = "0.4.0"
eyeball-im = "0.1.0"
futures-util = { version = "0.3.26", default-features = false, features = ["alloc"] }
http = "0.2.6"
Expand Down
6 changes: 6 additions & 0 deletions bindings/matrix-sdk-ffi/src/api.udl
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,12 @@ interface Room {

[Throws=ClientError]
void send_reaction(string event_id, string key);

[Throws=ClientError]
void leave();

[Throws=ClientError]
void reject_invitation();
};

callback interface TimelineListener {
Expand Down
2 changes: 1 addition & 1 deletion bindings/matrix-sdk-ffi/src/authentication_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ impl AuthenticationService {
})
.map_err(AuthenticationError::from)?;

let details = RUNTIME.block_on(async { self.details_from_client(&client).await })?;
let details = RUNTIME.block_on(self.details_from_client(&client))?;

// Now we've verified that it's a valid homeserver, make sure
// there's a sliding sync proxy available one way or another.
Expand Down
3 changes: 2 additions & 1 deletion bindings/matrix-sdk-ffi/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,8 @@ impl Client {
impl Client {
/// The homeserver this client is configured to use.
pub fn homeserver(&self) -> String {
RUNTIME.block_on(async move { self.async_homeserver().await })
#[allow(unknown_lints, clippy::redundant_async_block)] // false positive
RUNTIME.block_on(self.async_homeserver())
}

pub fn rooms(&self) -> Vec<Arc<Room>> {
Expand Down
33 changes: 32 additions & 1 deletion bindings/matrix-sdk-ffi/src/room.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,8 @@ impl Room {
.unwrap()
.get_or_insert_with(|| {
let room = self.room.clone();
let timeline = RUNTIME.block_on(async move { room.timeline().await });
#[allow(unknown_lints, clippy::redundant_async_block)] // false positive
let timeline = RUNTIME.block_on(room.timeline());
Arc::new(timeline)
})
.clone();
Expand Down Expand Up @@ -501,6 +502,36 @@ impl Room {
Ok(())
})
}

/// Leaves the joined room.
///
/// Will throw an error if used on an room that isn't in a joined state
pub fn leave(&self) -> Result<()> {
let room = match &self.room {
SdkRoom::Joined(j) => j.clone(),
_ => bail!("Can't leave a room that isn't in joined state"),
};

RUNTIME.block_on(async move {
room.leave().await?;
Ok(())
})
}

/// Rejects invitation for the invited room.
///
/// Will throw an error if used on an room that isn't in an invited state
pub fn reject_invitation(&self) -> Result<()> {
let room = match &self.room {
SdkRoom::Invited(i) => i.clone(),
_ => bail!("Can't reject an invite for a room that isn't in invited state"),
};

RUNTIME.block_on(async move {
room.reject_invitation().await?;
Ok(())
})
}
}

impl std::ops::Deref for Room {
Expand Down
6 changes: 3 additions & 3 deletions bindings/matrix-sdk-ffi/src/sliding_sync.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::sync::{Arc, RwLock};

use anyhow::Context;
use eyeball::Observable;
use eyeball::unique::Observable;
use eyeball_im::VectorDiff;
use futures_util::{future::join, pin_mut, StreamExt};
use matrix_sdk::ruma::{
Expand Down Expand Up @@ -194,8 +194,8 @@ impl SlidingSyncRoom {
}
};

let (timeline_items, timeline_stream) =
RUNTIME.block_on(async { timeline.subscribe().await });
#[allow(unknown_lints, clippy::redundant_async_block)] // false positive
let (timeline_items, timeline_stream) = RUNTIME.block_on(timeline.subscribe());

let handle_events = async move {
let listener: Arc<dyn TimelineListener> = listener.into();
Expand Down
13 changes: 8 additions & 5 deletions crates/matrix-sdk-base/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@ use std::{
borrow::Borrow,
collections::{BTreeMap, BTreeSet},
fmt,
sync::RwLockReadGuard as StdRwLockReadGuard,
};
#[cfg(feature = "e2e-encryption")]
use std::{ops::Deref, sync::Arc};

use eyeball::Observable;
use eyeball::Subscriber;
use matrix_sdk_common::{instant::Instant, locks::RwLock};
#[cfg(feature = "e2e-encryption")]
use matrix_sdk_crypto::{
Expand Down Expand Up @@ -134,10 +133,14 @@ impl BaseClient {

/// Get the session tokens.
///
/// If the client is currently logged in, this will return a
/// This returns a subscriber object that you can use both to
/// [`get`](Subscriber::get) the current value as well as to react to
/// changes to the tokens.
///
/// If the client is currently logged in, the inner value is a
/// [`SessionTokens`] object which contains the access token and optional
/// refresh token. Otherwise it returns `None`.
pub fn session_tokens(&self) -> StdRwLockReadGuard<'_, Observable<Option<SessionTokens>>> {
/// refresh token. Otherwise it is `None`.
pub fn session_tokens(&self) -> Subscriber<Option<SessionTokens>> {
self.store.session_tokens()
}

Expand Down
10 changes: 5 additions & 5 deletions crates/matrix-sdk-base/src/store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ use std::{
pin::Pin,
result::Result as StdResult,
str::Utf8Error,
sync::{Arc, RwLockReadGuard as StdRwLockReadGuard},
sync::Arc,
};

use eyeball::{Observable, SharedObservable};
use eyeball::{shared::Observable as SharedObservable, Subscriber};
use once_cell::sync::OnceCell;

#[cfg(any(test, feature = "testing"))]
Expand Down Expand Up @@ -210,8 +210,8 @@ impl Store {

/// The [`SessionTokens`] containing our access token and optional refresh
/// token.
pub fn session_tokens(&self) -> StdRwLockReadGuard<'_, Observable<Option<SessionTokens>>> {
self.session_tokens.read()
pub fn session_tokens(&self) -> Subscriber<Option<SessionTokens>> {
self.session_tokens.subscribe()
}

/// Set the current [`SessionTokens`].
Expand All @@ -223,7 +223,7 @@ impl Store {
/// token and optional refresh token.
pub fn session(&self) -> Option<Session> {
let meta = self.session_meta.get()?;
let tokens = self.session_tokens().clone()?;
let tokens = self.session_tokens().get()?;
Some(Session::from_parts(meta.to_owned(), tokens))
}

Expand Down
Loading

0 comments on commit e1c6ac9

Please sign in to comment.