Do wasm sepcific changes:
- Only use send+sync when not using wasm - Use wasm capabale async_trait wrapper macro - Make room and room_member specific structs always clonablemaster
parent
ea427cf366
commit
8b77b4171a
|
@ -6,4 +6,5 @@ members = [
|
|||
"matrix_sdk_test_macros",
|
||||
"matrix_sdk_crypto",
|
||||
"matrix_sdk_common",
|
||||
"matrix_sdk_common_macros",
|
||||
]
|
||||
|
|
|
@ -5,6 +5,7 @@ use matrix_sdk::{
|
|||
events::room::message::{MessageEvent, MessageEventContent, TextMessageEventContent},
|
||||
Client, ClientConfig, EventEmitter, JsonStore, SyncRoom, SyncSettings,
|
||||
};
|
||||
use matrix_sdk_common_macros::async_trait;
|
||||
use url::Url;
|
||||
|
||||
struct CommandBot {
|
||||
|
@ -19,7 +20,7 @@ impl CommandBot {
|
|||
}
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
#[async_trait]
|
||||
impl EventEmitter for CommandBot {
|
||||
async fn on_room_message(&self, room: SyncRoom, event: &MessageEvent) {
|
||||
if let SyncRoom::Joined(room) = room {
|
||||
|
|
|
@ -6,10 +6,11 @@ use matrix_sdk::{
|
|||
events::room::message::{MessageEvent, MessageEventContent, TextMessageEventContent},
|
||||
Client, ClientConfig, EventEmitter, SyncRoom, SyncSettings,
|
||||
};
|
||||
use matrix_sdk_common_macros::async_trait;
|
||||
|
||||
struct EventCallback;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
#[async_trait]
|
||||
impl EventEmitter for EventCallback {
|
||||
async fn on_room_message(&self, room: SyncRoom, event: &MessageEvent) {
|
||||
if let SyncRoom::Joined(room) = room {
|
||||
|
|
|
@ -22,6 +22,7 @@ serde = "1.0.110"
|
|||
serde_json = "1.0.53"
|
||||
zeroize = "1.1.0"
|
||||
|
||||
matrix-sdk-common-macros = { version = "0.1.0", path = "../matrix_sdk_common_macros" }
|
||||
matrix-sdk-common = { version = "0.1.0", path = "../matrix_sdk_common" }
|
||||
matrix-sdk-crypto = { version = "0.1.0", path = "../matrix_sdk_crypto", optional = true }
|
||||
|
||||
|
|
|
@ -1768,6 +1768,7 @@ mod test {
|
|||
BaseClient, Session,
|
||||
};
|
||||
use matrix_sdk_test::{async_test, EventBuilder, EventsFile};
|
||||
use matrix_sdk_common_macros::async_trait;
|
||||
use serde_json::json;
|
||||
use std::convert::TryFrom;
|
||||
|
||||
|
@ -1933,7 +1934,7 @@ mod test {
|
|||
};
|
||||
|
||||
struct EE(Arc<AtomicBool>);
|
||||
#[async_trait::async_trait]
|
||||
#[async_trait]
|
||||
impl EventEmitter for EE {
|
||||
async fn on_room_member(&self, room: SyncRoom, event: &MemberEvent) {
|
||||
if let SyncRoom::Joined(_) = room {
|
||||
|
@ -2029,7 +2030,7 @@ mod test {
|
|||
};
|
||||
|
||||
struct EE(Arc<AtomicBool>);
|
||||
#[async_trait::async_trait]
|
||||
#[async_trait]
|
||||
impl EventEmitter for EE {
|
||||
async fn on_unrecognized_event(&self, room: SyncRoom, event: &CustomOrRawEvent<'_>) {
|
||||
if let SyncRoom::Joined(_) = room {
|
||||
|
@ -2125,7 +2126,7 @@ mod test {
|
|||
};
|
||||
|
||||
struct EE(Arc<AtomicBool>);
|
||||
#[async_trait::async_trait]
|
||||
#[async_trait]
|
||||
impl EventEmitter for EE {
|
||||
async fn on_unrecognized_event(&self, room: SyncRoom, event: &CustomOrRawEvent<'_>) {
|
||||
if let SyncRoom::Joined(_) = room {
|
||||
|
|
|
@ -43,6 +43,7 @@ use crate::events::{
|
|||
CustomEvent, CustomRoomEvent, CustomStateEvent,
|
||||
};
|
||||
use crate::{Room, RoomState};
|
||||
use matrix_sdk_common_macros::async_trait;
|
||||
|
||||
/// Type alias for `RoomState` enum when passed to `EventEmitter` methods.
|
||||
pub type SyncRoom = RoomState<Arc<RwLock<Room>>>;
|
||||
|
@ -78,10 +79,11 @@ pub enum CustomOrRawEvent<'c> {
|
|||
/// # EventEmitter, SyncRoom
|
||||
/// # };
|
||||
/// # use matrix_sdk_common::locks::RwLock;
|
||||
/// # use matrix_sdk_common_macros::async_trait;
|
||||
///
|
||||
/// struct EventCallback;
|
||||
///
|
||||
/// #[async_trait::async_trait]
|
||||
/// #[async_trait]
|
||||
/// impl EventEmitter for EventCallback {
|
||||
/// async fn on_room_message(&self, room: SyncRoom, event: &MessageEvent) {
|
||||
/// if let SyncRoom::Joined(room) = room {
|
||||
|
@ -106,7 +108,7 @@ pub enum CustomOrRawEvent<'c> {
|
|||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
#[async_trait::async_trait]
|
||||
#[async_trait]
|
||||
pub trait EventEmitter: Send + Sync {
|
||||
// ROOM EVENTS from `IncomingTimeline`
|
||||
/// Fires when `Client` receives a `RoomEvent::RoomMember` event.
|
||||
|
@ -202,6 +204,7 @@ mod test {
|
|||
use matrix_sdk_common::locks::Mutex;
|
||||
use matrix_sdk_test::{async_test, sync_response, SyncResponseFile};
|
||||
use std::sync::Arc;
|
||||
use matrix_sdk_common_macros::async_trait;
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
pub use wasm_bindgen_test::*;
|
||||
|
@ -209,7 +212,7 @@ mod test {
|
|||
#[derive(Clone)]
|
||||
pub struct EvEmitterTest(Arc<Mutex<Vec<String>>>);
|
||||
|
||||
#[async_trait::async_trait]
|
||||
#[async_trait]
|
||||
impl EventEmitter for EvEmitterTest {
|
||||
async fn on_room_member(&self, _: SyncRoom, _: &MemberEvent) {
|
||||
self.0.lock().await.push("member".to_string())
|
||||
|
|
|
@ -42,8 +42,7 @@ use crate::identifiers::{RoomAliasId, RoomId, UserId};
|
|||
|
||||
use crate::js_int::{Int, UInt};
|
||||
use serde::{Deserialize, Serialize};
|
||||
#[derive(Debug, Default, PartialEq, Serialize, Deserialize)]
|
||||
#[cfg_attr(test, derive(Clone))]
|
||||
#[derive(Debug, Default, PartialEq, Serialize, Deserialize, Clone)]
|
||||
/// `RoomName` allows the calculation of a text room name.
|
||||
pub struct RoomName {
|
||||
/// The displayed name of the room.
|
||||
|
@ -65,8 +64,7 @@ pub struct RoomName {
|
|||
pub invited_member_count: Option<UInt>,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[cfg_attr(test, derive(Clone))]
|
||||
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone)]
|
||||
pub struct PowerLevels {
|
||||
/// The level required to ban a user.
|
||||
pub ban: Int,
|
||||
|
@ -137,8 +135,7 @@ impl From<&EncryptionEvent> for EncryptionInfo {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[cfg_attr(test, derive(Clone))]
|
||||
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone)]
|
||||
pub struct Tombstone {
|
||||
/// A server-defined message.
|
||||
body: String,
|
||||
|
@ -146,8 +143,7 @@ pub struct Tombstone {
|
|||
replacement: RoomId,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[cfg_attr(test, derive(Clone))]
|
||||
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
|
||||
/// A Matrix room.
|
||||
pub struct Room {
|
||||
/// The unique id of the room.
|
||||
|
|
|
@ -27,8 +27,7 @@ use crate::js_int::{Int, UInt};
|
|||
use serde::{Deserialize, Serialize};
|
||||
// Notes: if Alice invites Bob into a room we will get an event with the sender as Alice and the state key as Bob.
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(test, derive(Clone))]
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
/// A Matrix room member.
|
||||
///
|
||||
pub struct RoomMember {
|
||||
|
|
|
@ -27,6 +27,9 @@ use crate::events::push_rules::Ruleset;
|
|||
use crate::identifiers::{RoomId, UserId};
|
||||
use crate::{Result, Room, RoomState, Session};
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
use matrix_sdk_common_macros::send_sync;
|
||||
|
||||
/// `ClientState` holds all the information to restore a `BaseClient`
|
||||
/// except the `access_token` as the default store is not secure.
|
||||
///
|
||||
|
@ -85,7 +88,8 @@ pub struct AllRooms {
|
|||
|
||||
/// Abstraction around the data store to avoid unnecessary request on client initialization.
|
||||
#[async_trait::async_trait]
|
||||
pub trait StateStore: Send + Sync {
|
||||
#[cfg_attr(not(target_arch = "wasm32"), send_sync)]
|
||||
pub trait StateStore {
|
||||
/// Loads the state of `BaseClient` through `ClientState` type.
|
||||
///
|
||||
/// An `Option::None` should be returned only if the `StateStore` tries to
|
||||
|
|
|
@ -17,6 +17,7 @@ sqlite-cryptostore = ["sqlx"]
|
|||
[dependencies]
|
||||
async-trait = "0.1.31"
|
||||
|
||||
matrix-sdk-common-macros = { version = "0.1.0", path = "../matrix_sdk_common_macros" }
|
||||
matrix-sdk-common = { version = "0.1.0", path = "../matrix_sdk_common" }
|
||||
|
||||
olm-rs = { version = "0.5.0", features = ["serde"] }
|
||||
|
|
|
@ -28,11 +28,15 @@ use super::memory_stores::UserDevices;
|
|||
use super::olm::{Account, InboundGroupSession, Session};
|
||||
use matrix_sdk_common::identifiers::{DeviceId, RoomId, UserId};
|
||||
use olm_rs::errors::{OlmAccountError, OlmGroupSessionError, OlmSessionError};
|
||||
use matrix_sdk_common_macros::send_sync;
|
||||
|
||||
pub mod memorystore;
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[cfg(feature = "sqlite-cryptostore")]
|
||||
pub mod sqlite;
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[cfg(feature = "sqlite-cryptostore")]
|
||||
use sqlx::Error as SqlxError;
|
||||
|
||||
|
@ -83,9 +87,10 @@ pub enum CryptoStoreError {
|
|||
pub type Result<T> = std::result::Result<T, CryptoStoreError>;
|
||||
|
||||
#[async_trait]
|
||||
#[cfg_attr(not(target_arch = "wasm32"), send_sync)]
|
||||
/// Trait abstracting a store that the `OlmMachine` uses to store cryptographic
|
||||
/// keys.
|
||||
pub trait CryptoStore: Debug + Send + Sync {
|
||||
pub trait CryptoStore: Debug {
|
||||
/// Load an account that was previously stored.
|
||||
async fn load_account(&mut self) -> Result<Option<Account>>;
|
||||
|
||||
|
|
Loading…
Reference in New Issue