Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reintroduce CI for WASM #186

Merged
merged 9 commits into from
Mar 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,31 @@ jobs:
command: clippy
args: --all-targets -- -D warnings

check-wasm:
name: Check if WASM support compiles
needs: [clippy]
runs-on: ubuntu-latest

steps:
- name: Checkout the repo
uses: actions/checkout@v2

- name: Install rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
target: wasm32-unknown-unknown
profile: minimal
override: true

- name: Install emscripten
uses: mymindstorm/setup-emsdk@v7

- name: Check
run: |
cd matrix_sdk/examples/wasm_command_bot
cargo check --target wasm32-unknown-unknown

test:
name: ${{ matrix.name }}
needs: [clippy]
Expand Down
69 changes: 68 additions & 1 deletion matrix_sdk/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ use tracing::{debug, warn};
use tracing::{error, info, instrument};

use matrix_sdk_base::{
deserialized_responses::SyncResponse, BaseClient, BaseClientConfig, Session, Store,
deserialized_responses::SyncResponse, events::AnyMessageEventContent, BaseClient,
BaseClientConfig, Session, Store,
};

#[cfg(feature = "encryption")]
Expand Down Expand Up @@ -1002,6 +1003,72 @@ impl Client {
Ok(self.http_client.upload(request, Some(timeout)).await?)
}

/// Send a room message to a room.
///
/// Returns the parsed response from the server.
///
/// If the encryption feature is enabled this method will transparently
/// encrypt the room message if this room is encrypted.
///
/// **Note**: This method will send an unencrypted message if the room cannot
/// be found in the store, prefer the higher level
/// [send()](room::Joined::send()) method that can be found for the
/// [Joined](room::Joined) room struct to avoid this.
///
/// # Arguments
///
/// * `room_id` - The unique id of the room.
///
/// * `content` - The content of the message event.
///
/// * `txn_id` - A unique `Uuid` that can be attached to a `MessageEvent`
/// held in its unsigned field as `transaction_id`. If not given one is
/// created for the message.
///
/// # Example
/// ```no_run
/// # use std::sync::{Arc, RwLock};
/// # use matrix_sdk::{Client, SyncSettings};
/// # use url::Url;
/// # use futures::executor::block_on;
/// # use matrix_sdk::identifiers::room_id;
/// # use std::convert::TryFrom;
/// use matrix_sdk::events::{
/// AnyMessageEventContent,
/// room::message::{MessageEventContent, TextMessageEventContent},
/// };
/// # block_on(async {
/// # let homeserver = Url::parse("http://localhost:8080").unwrap();
/// # let mut client = Client::new(homeserver).unwrap();
/// # let room_id = room_id!("!test:localhost");
/// use matrix_sdk_common::uuid::Uuid;
///
/// let content = AnyMessageEventContent::RoomMessage(
/// MessageEventContent::text_plain("Hello world")
/// );
///
/// let txn_id = Uuid::new_v4();
/// client.room_send(&room_id, content, Some(txn_id)).await.unwrap();
/// # })
/// ```
pub async fn room_send(
&self,
room_id: &RoomId,
content: impl Into<AnyMessageEventContent>,
txn_id: Option<Uuid>,
) -> Result<send_message_event::Response> {
#[cfg(feature = "encryption")]
if let Some(room) = self.get_joined_room(room_id) {
room.send(content, txn_id).await
} else {
let content = content.into();
let txn_id = txn_id.unwrap_or_else(Uuid::new_v4).to_string();
let request = send_message_event::Request::new(room_id, &txn_id, &content);

self.send(request, None).await
}
}

/// Send an arbitrary request to the server, without updating client state.
///
/// **Warning:** Because this method *does not* update the client state, it is
Expand Down
10 changes: 6 additions & 4 deletions matrix_sdk/src/room/common.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use matrix_sdk_common::api::r0::{
membership::{get_member_events, join_room_by_id, leave_room},
message::get_message_events,
use matrix_sdk_common::{
api::r0::{
membership::{get_member_events, join_room_by_id, leave_room},
message::get_message_events,
},
locks::Mutex,
};
use matrix_sdk_common::locks::Mutex;

use std::{ops::Deref, sync::Arc};

Expand Down
5 changes: 1 addition & 4 deletions matrix_sdk/src/room/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ mod invited;
mod joined;
mod left;

pub use self::common::Common;
pub use self::invited::Invited;
pub use self::joined::Joined;
pub use self::left::Left;
pub use self::{common::Common, invited::Invited, joined::Joined, left::Left};

/// An enum that abstracts over the different states a room can be in.
#[derive(Debug, Clone)]
Expand Down
13 changes: 11 additions & 2 deletions matrix_sdk/src/sas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,24 @@ impl Sas {
///
/// # Examples
///
/// ```ignore
/// ```no_run
/// # use matrix_sdk::Client;
/// # use futures::executor::block_on;
/// # use url::Url;
/// use matrix_sdk::Sas;
/// use matrix_sdk_base::crypto::AcceptSettings;
/// use matrix_sdk::events::key::verification::ShortAuthenticationString;
/// # let homeserver = Url::parse("http://example.com").unwrap();
/// # let client = Client::new(homeserver).unwrap();
/// # let flow_id = "someID";
/// # block_on(async {
/// let sas = client.get_verification(flow_id).await.unwrap();
///
/// let only_decimal = AcceptSettings::with_allowed_methods(
/// vec![ShortAuthenticationString::Decimal]
/// );
/// sas.accept_with_settings(only_decimal);
/// sas.accept_with_settings(only_decimal).await.unwrap();
/// # });
/// ```
pub async fn accept_with_settings(&self, settings: AcceptSettings) -> Result<()> {
if let Some(req) = self.inner.accept_with_settings(settings) {
Expand Down