Run cargo fmt with merge-imports true

master
Devin Ragotzy 2020-07-30 19:22:48 -04:00
parent 79e661d1d9
commit ed1f12ce37
25 changed files with 353 additions and 287 deletions

View File

@ -1,5 +1,4 @@
use std::convert::TryFrom; use std::{convert::TryFrom, env, process::exit};
use std::{env, process::exit};
use url::Url; use url::Url;

View File

@ -15,19 +15,23 @@
#[cfg(feature = "encryption")] #[cfg(feature = "encryption")]
use std::collections::BTreeMap; use std::collections::BTreeMap;
use std::collections::HashMap; use std::{
use std::convert::{TryFrom, TryInto}; collections::HashMap,
use std::fmt::{self, Debug}; convert::{TryFrom, TryInto},
use std::path::Path; fmt::{self, Debug},
use std::result::Result as StdResult; path::Path,
use std::sync::Arc; result::Result as StdResult,
sync::Arc,
};
use matrix_sdk_common::identifiers::ServerName; use matrix_sdk_common::{
use matrix_sdk_common::instant::{Duration, Instant}; identifiers::ServerName,
use matrix_sdk_common::js_int::UInt; instant::{Duration, Instant},
use matrix_sdk_common::locks::RwLock; js_int::UInt,
use matrix_sdk_common::presence::PresenceState; locks::RwLock,
use matrix_sdk_common::uuid::Uuid; presence::PresenceState,
uuid::Uuid,
};
use futures_timer::Delay as sleep; use futures_timer::Delay as sleep;
use std::future::Future; use std::future::Future;
@ -35,23 +39,22 @@ use std::future::Future;
use tracing::{debug, warn}; use tracing::{debug, warn};
use tracing::{error, info, instrument, trace}; use tracing::{error, info, instrument, trace};
use http::Method as HttpMethod; use http::{Method as HttpMethod, Response as HttpResponse};
use http::Response as HttpResponse;
use reqwest::header::{HeaderValue, InvalidHeaderValue, AUTHORIZATION}; use reqwest::header::{HeaderValue, InvalidHeaderValue, AUTHORIZATION};
use url::Url; use url::Url;
use crate::events::room::message::MessageEventContent; use crate::{
use crate::events::EventType; events::{room::message::MessageEventContent, EventType},
use crate::identifiers::{EventId, RoomId, RoomIdOrAliasId, UserId}; identifiers::{EventId, RoomId, RoomIdOrAliasId, UserId},
use crate::Endpoint; Endpoint,
};
#[cfg(feature = "encryption")] #[cfg(feature = "encryption")]
use crate::identifiers::DeviceId; use crate::identifiers::DeviceId;
use crate::api;
#[cfg(not(target_arch = "wasm32"))] #[cfg(not(target_arch = "wasm32"))]
use crate::VERSION; use crate::VERSION;
use crate::{Error, EventEmitter, Result}; use crate::{api, Error, EventEmitter, Result};
use matrix_sdk_base::{BaseClient, BaseClientConfig, Room, Session, StateStore}; use matrix_sdk_base::{BaseClient, BaseClientConfig, Room, Session, StateStore};
const DEFAULT_SYNC_TIMEOUT: Duration = Duration::from_secs(30); const DEFAULT_SYNC_TIMEOUT: Duration = Duration::from_secs(30);
@ -269,27 +272,27 @@ impl SyncSettings {
} }
} }
use api::r0::account::register;
use api::r0::directory::get_public_rooms;
use api::r0::directory::get_public_rooms_filtered;
#[cfg(feature = "encryption")] #[cfg(feature = "encryption")]
use api::r0::keys::{claim_keys, get_keys, upload_keys, KeyAlgorithm}; use api::r0::keys::{claim_keys, get_keys, upload_keys, KeyAlgorithm};
use api::r0::membership::{
ban_user, forget_room,
invite_user::{self, InvitationRecipient},
join_room_by_id, join_room_by_id_or_alias, kick_user, leave_room, Invite3pid,
};
use api::r0::message::create_message_event;
use api::r0::message::get_message_events;
use api::r0::read_marker::set_read_marker;
use api::r0::receipt::create_receipt;
use api::r0::room::create_room;
use api::r0::session::login;
use api::r0::sync::sync_events;
#[cfg(feature = "encryption")] #[cfg(feature = "encryption")]
use api::r0::to_device::send_event_to_device; use api::r0::to_device::send_event_to_device;
use api::r0::typing::create_typing_event; use api::r0::{
use api::r0::uiaa::UiaaResponse; account::register,
directory::{get_public_rooms, get_public_rooms_filtered},
membership::{
ban_user, forget_room,
invite_user::{self, InvitationRecipient},
join_room_by_id, join_room_by_id_or_alias, kick_user, leave_room, Invite3pid,
},
message::{create_message_event, get_message_events},
read_marker::set_read_marker,
receipt::create_receipt,
room::create_room,
session::login,
sync::sync_events,
typing::create_typing_event,
uiaa::UiaaResponse,
};
impl Client { impl Client {
/// Creates a new client for making HTTP requests to the given homeserver. /// Creates a new client for making HTTP requests to the given homeserver.
@ -1538,23 +1541,27 @@ mod test {
get_public_rooms_filtered::{self, Filter}, get_public_rooms_filtered::{self, Filter},
invite_user, kick_user, leave_room, invite_user, kick_user, leave_room,
register::RegistrationKind, register::RegistrationKind,
set_read_marker, Invite3pid, MessageEventContent, set_read_marker, Client, ClientConfig, Invite3pid, MessageEventContent, Session,
SyncSettings, Url,
}; };
use super::{Client, ClientConfig, Session, SyncSettings, Url};
use crate::events::room::message::TextMessageEventContent; use crate::events::room::message::TextMessageEventContent;
use crate::identifiers::{EventId, RoomId, RoomIdOrAliasId, UserId}; use crate::{
use crate::{RegistrationBuilder, RoomListFilterBuilder}; identifiers::{EventId, RoomId, RoomIdOrAliasId, UserId},
RegistrationBuilder, RoomListFilterBuilder,
};
use matrix_sdk_base::JsonStore; use matrix_sdk_base::JsonStore;
use matrix_sdk_test::{test_json, EventBuilder, EventsJson}; use matrix_sdk_test::{test_json, EventBuilder, EventsJson};
use mockito::{mock, Matcher}; use mockito::{mock, Matcher};
use tempfile::tempdir; use tempfile::tempdir;
use std::convert::{TryFrom, TryInto}; use std::{
use std::path::Path; convert::{TryFrom, TryInto},
use std::str::FromStr; path::Path,
use std::time::Duration; str::FromStr,
time::Duration,
};
#[tokio::test] #[tokio::test]
async fn test_join_leave_room() { async fn test_join_leave_room() {

View File

@ -20,10 +20,10 @@ use thiserror::Error;
use matrix_sdk_base::Error as MatrixError; use matrix_sdk_base::Error as MatrixError;
use crate::api::r0::uiaa::UiaaResponse as UiaaError; use crate::{
use crate::api::Error as RumaClientError; api::{r0::uiaa::UiaaResponse as UiaaError, Error as RumaClientError},
use crate::FromHttpResponseError as RumaResponseError; FromHttpResponseError as RumaResponseError, IntoHttpError as RumaIntoHttpError,
use crate::IntoHttpError as RumaIntoHttpError; };
/// Result type of the rust-sdk. /// Result type of the rust-sdk.
pub type Result<T> = std::result::Result<T, Error>; pub type Result<T> = std::result::Result<T, Error>;

View File

@ -36,13 +36,14 @@
unused_qualifications unused_qualifications
)] )]
pub use matrix_sdk_base::Error as BaseError;
#[cfg(not(target_arch = "wasm32"))] #[cfg(not(target_arch = "wasm32"))]
pub use matrix_sdk_base::JsonStore; pub use matrix_sdk_base::JsonStore;
pub use matrix_sdk_base::{CustomOrRawEvent, EventEmitter, Room, Session, SyncRoom}; pub use matrix_sdk_base::{
CustomOrRawEvent, Error as BaseError, EventEmitter, Room, RoomState, Session, StateStore,
SyncRoom,
};
#[cfg(feature = "messages")] #[cfg(feature = "messages")]
pub use matrix_sdk_base::{MessageQueue, PossiblyRedactedExt}; pub use matrix_sdk_base::{MessageQueue, MessageWrapper, PossiblyRedactedExt};
pub use matrix_sdk_base::{RoomState, StateStore};
pub use matrix_sdk_common::*; pub use matrix_sdk_common::*;
pub use reqwest::header::InvalidHeaderValue; pub use reqwest::header::InvalidHeaderValue;

View File

@ -454,10 +454,13 @@ mod test {
use std::collections::BTreeMap; use std::collections::BTreeMap;
use super::*; use super::*;
use crate::api::r0::filter::{LazyLoadOptions, RoomEventFilter}; use crate::{
use crate::events::room::power_levels::NotificationPowerLevels; api::r0::filter::{LazyLoadOptions, RoomEventFilter},
use crate::js_int::Int; events::room::power_levels::NotificationPowerLevels,
use crate::{identifiers::RoomId, Client, Session}; identifiers::RoomId,
js_int::Int,
Client, Session,
};
use matrix_sdk_test::test_json; use matrix_sdk_test::test_json;
use mockito::{mock, Matcher}; use mockito::{mock, Matcher};

View File

@ -13,35 +13,40 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use std::collections::HashMap;
#[cfg(feature = "encryption")] #[cfg(feature = "encryption")]
use std::collections::{BTreeMap, HashSet}; use std::collections::{BTreeMap, HashSet};
use std::fmt; use std::{
use std::path::{Path, PathBuf}; collections::HashMap,
use std::sync::Arc; fmt,
path::{Path, PathBuf},
sync::Arc,
};
use zeroize::Zeroizing; use zeroize::Zeroizing;
use std::result::Result as StdResult; use std::result::Result as StdResult;
use crate::api::r0 as api; use crate::{api::r0 as api, error::Result, events::presence::PresenceEvent};
use crate::error::Result;
use crate::events::presence::PresenceEvent;
// `NonRoomEvent` is what it is aliased as // `NonRoomEvent` is what it is aliased as
use crate::event_emitter::CustomOrRawEvent; use crate::{
use crate::events::ignored_user_list::IgnoredUserListEvent; event_emitter::CustomOrRawEvent,
use crate::events::push_rules::PushRulesEvent; events::{
use crate::events::room::member::MemberEventContent; ignored_user_list::IgnoredUserListEvent, push_rules::PushRulesEvent,
use crate::identifiers::{RoomId, UserId}; room::member::MemberEventContent,
use crate::models::Room; },
use crate::push::Ruleset; identifiers::{RoomId, UserId},
use crate::session::Session; models::Room,
use crate::state::{AllRooms, ClientState, StateStore}; push::Ruleset,
use crate::EventEmitter; session::Session,
use matrix_sdk_common::events::{ state::{AllRooms, ClientState, StateStore},
AnyBasicEvent, AnyStrippedStateEvent, AnySyncEphemeralRoomEvent, AnySyncMessageEvent, EventEmitter,
AnySyncRoomEvent, AnySyncStateEvent, };
use matrix_sdk_common::{
events::{
AnyBasicEvent, AnyStrippedStateEvent, AnySyncEphemeralRoomEvent, AnySyncMessageEvent,
AnySyncRoomEvent, AnySyncStateEvent,
},
Raw,
}; };
use matrix_sdk_common::Raw;
#[cfg(feature = "encryption")] #[cfg(feature = "encryption")]
use matrix_sdk_common::locks::Mutex; use matrix_sdk_common::locks::Mutex;
@ -1831,10 +1836,12 @@ impl BaseClient {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use crate::identifiers::{RoomId, UserId};
#[cfg(feature = "messages")] #[cfg(feature = "messages")]
use crate::{events::AnySyncRoomEvent, identifiers::EventId, BaseClientConfig, JsonStore, Raw}; use crate::{events::AnySyncRoomEvent, identifiers::EventId, BaseClientConfig, JsonStore, Raw};
use crate::{BaseClient, Session}; use crate::{
identifiers::{RoomId, UserId},
BaseClient, Session,
};
use matrix_sdk_common_macros::async_trait; use matrix_sdk_common_macros::async_trait;
use matrix_sdk_test::{async_test, test_json, EventBuilder, EventsJson}; use matrix_sdk_test::{async_test, test_json, EventBuilder, EventsJson};
use serde_json::json; use serde_json::json;
@ -1997,11 +2004,13 @@ mod test {
use super::*; use super::*;
use crate::{EventEmitter, SyncRoom}; use crate::{EventEmitter, SyncRoom};
use matrix_sdk_common::events::{ use matrix_sdk_common::{
room::member::{MemberEventContent, MembershipChange}, events::{
SyncStateEvent, room::member::{MemberEventContent, MembershipChange},
SyncStateEvent,
},
locks::RwLock,
}; };
use matrix_sdk_common::locks::RwLock;
use std::sync::{ use std::sync::{
atomic::{AtomicBool, Ordering}, atomic::{AtomicBool, Ordering},
Arc, Arc,
@ -2253,8 +2262,7 @@ mod test {
use super::*; use super::*;
use crate::{EventEmitter, SyncRoom}; use crate::{EventEmitter, SyncRoom};
use matrix_sdk_common::api::r0::sync::sync_events; use matrix_sdk_common::{api::r0::sync::sync_events, locks::RwLock};
use matrix_sdk_common::locks::RwLock;
use std::sync::{ use std::sync::{
atomic::{AtomicBool, Ordering}, atomic::{AtomicBool, Ordering},
Arc, Arc,

View File

@ -17,29 +17,31 @@ use std::sync::Arc;
use matrix_sdk_common::locks::RwLock; use matrix_sdk_common::locks::RwLock;
use serde_json::value::RawValue as RawJsonValue; use serde_json::value::RawValue as RawJsonValue;
use crate::events::{ use crate::{
custom::CustomEventContent, events::{
fully_read::FullyReadEventContent, custom::CustomEventContent,
ignored_user_list::IgnoredUserListEventContent, fully_read::FullyReadEventContent,
presence::PresenceEvent, ignored_user_list::IgnoredUserListEventContent,
push_rules::PushRulesEventContent, presence::PresenceEvent,
receipt::ReceiptEventContent, push_rules::PushRulesEventContent,
room::{ receipt::ReceiptEventContent,
aliases::AliasesEventContent, room::{
avatar::AvatarEventContent, aliases::AliasesEventContent,
canonical_alias::CanonicalAliasEventContent, avatar::AvatarEventContent,
join_rules::JoinRulesEventContent, canonical_alias::CanonicalAliasEventContent,
member::MemberEventContent, join_rules::JoinRulesEventContent,
message::{feedback::FeedbackEventContent, MessageEventContent as MsgEventContent}, member::MemberEventContent,
name::NameEventContent, message::{feedback::FeedbackEventContent, MessageEventContent as MsgEventContent},
power_levels::PowerLevelsEventContent, name::NameEventContent,
redaction::SyncRedactionEvent, power_levels::PowerLevelsEventContent,
tombstone::TombstoneEventContent, redaction::SyncRedactionEvent,
tombstone::TombstoneEventContent,
},
typing::TypingEventContent,
BasicEvent, StrippedStateEvent, SyncEphemeralRoomEvent, SyncMessageEvent, SyncStateEvent,
}, },
typing::TypingEventContent, Room, RoomState,
BasicEvent, StrippedStateEvent, SyncEphemeralRoomEvent, SyncMessageEvent, SyncStateEvent,
}; };
use crate::{Room, RoomState};
use matrix_sdk_common_macros::async_trait; use matrix_sdk_common_macros::async_trait;
/// Type alias for `RoomState` enum when passed to `EventEmitter` methods. /// Type alias for `RoomState` enum when passed to `EventEmitter` methods.
@ -471,8 +473,7 @@ mod test {
} }
} }
use crate::identifiers::UserId; use crate::{identifiers::UserId, BaseClient, Session};
use crate::{BaseClient, Session};
use std::convert::TryFrom; use std::convert::TryFrom;

View File

@ -35,7 +35,10 @@
unused_qualifications unused_qualifications
)] )]
pub use crate::{error::Error, error::Result, session::Session}; pub use crate::{
error::{Error, Result},
session::Session,
};
pub use matrix_sdk_common::*; pub use matrix_sdk_common::*;
mod client; mod client;

View File

@ -160,8 +160,7 @@ pub(crate) mod ser_deser {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use std::collections::HashMap; use std::{collections::HashMap, convert::TryFrom};
use std::convert::TryFrom;
use matrix_sdk_common::{ use matrix_sdk_common::{
events::{AnyPossiblyRedactedSyncMessageEvent, AnySyncMessageEvent}, events::{AnyPossiblyRedactedSyncMessageEvent, AnySyncMessageEvent},

View File

@ -13,10 +13,12 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use std::collections::{BTreeMap, HashMap, HashSet};
use std::convert::TryFrom;
#[cfg(feature = "messages")] #[cfg(feature = "messages")]
use std::ops::DerefMut; use std::ops::DerefMut;
use std::{
collections::{BTreeMap, HashMap, HashSet},
convert::TryFrom,
};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use tracing::{debug, error, trace}; use tracing::{debug, error, trace};
@ -24,20 +26,22 @@ use tracing::{debug, error, trace};
#[cfg(feature = "messages")] #[cfg(feature = "messages")]
use super::message::MessageQueue; use super::message::MessageQueue;
use super::RoomMember; use super::RoomMember;
use crate::api::r0::sync::sync_events::{RoomSummary, UnreadNotificationsCount}; use crate::{
use crate::events::{ api::r0::sync::sync_events::{RoomSummary, UnreadNotificationsCount},
presence::{PresenceEvent, PresenceEventContent}, events::{
room::{ presence::{PresenceEvent, PresenceEventContent},
aliases::AliasesEventContent, room::{
canonical_alias::CanonicalAliasEventContent, aliases::AliasesEventContent,
encryption::EncryptionEventContent, canonical_alias::CanonicalAliasEventContent,
member::{MemberEventContent, MembershipChange, MembershipState}, encryption::EncryptionEventContent,
name::NameEventContent, member::{MemberEventContent, MembershipChange, MembershipState},
power_levels::{NotificationPowerLevels, PowerLevelsEventContent}, name::NameEventContent,
tombstone::TombstoneEventContent, power_levels::{NotificationPowerLevels, PowerLevelsEventContent},
tombstone::TombstoneEventContent,
},
Algorithm, AnyStrippedStateEvent, AnySyncRoomEvent, AnySyncStateEvent, EventType,
StrippedStateEvent, SyncStateEvent,
}, },
Algorithm, AnyStrippedStateEvent, AnySyncRoomEvent, AnySyncStateEvent, EventType,
StrippedStateEvent, SyncStateEvent,
}; };
#[cfg(feature = "messages")] #[cfg(feature = "messages")]
@ -670,8 +674,7 @@ impl Room {
#[cfg(feature = "messages")] #[cfg(feature = "messages")]
#[cfg_attr(docsrs, doc(cfg(feature = "messages")))] #[cfg_attr(docsrs, doc(cfg(feature = "messages")))]
pub fn handle_redaction(&mut self, redacted_event: &SyncRedactionEvent) -> bool { pub fn handle_redaction(&mut self, redacted_event: &SyncRedactionEvent) -> bool {
use crate::identifiers::RoomVersionId; use crate::{identifiers::RoomVersionId, models::message::PossiblyRedactedExt};
use crate::models::message::PossiblyRedactedExt;
if let Some(mut msg) = self if let Some(mut msg) = self
.messages .messages
@ -1080,9 +1083,11 @@ impl Describe for MembershipChange {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::*; use super::*;
use crate::events::{room::encryption::EncryptionEventContent, Unsigned}; use crate::{
use crate::identifiers::{EventId, UserId}; events::{room::encryption::EncryptionEventContent, Unsigned},
use crate::{BaseClient, Raw, Session}; identifiers::{EventId, UserId},
BaseClient, Raw, Session,
};
use matrix_sdk_test::{async_test, sync_response, EventBuilder, EventsJson, SyncResponseFile}; use matrix_sdk_test::{async_test, sync_response, EventBuilder, EventsJson, SyncResponseFile};
use std::time::SystemTime; use std::time::SystemTime;
@ -1090,8 +1095,7 @@ mod test {
#[cfg(target_arch = "wasm32")] #[cfg(target_arch = "wasm32")]
use wasm_bindgen_test::*; use wasm_bindgen_test::*;
use std::convert::TryFrom; use std::{convert::TryFrom, ops::Deref};
use std::ops::Deref;
async fn get_client() -> BaseClient { async fn get_client() -> BaseClient {
let session = Session { let session = Session {

View File

@ -154,8 +154,10 @@ impl RoomMember {
mod test { mod test {
use matrix_sdk_test::{async_test, EventBuilder, EventsJson}; use matrix_sdk_test::{async_test, EventBuilder, EventsJson};
use crate::identifiers::{RoomId, UserId}; use crate::{
use crate::{BaseClient, Session}; identifiers::{RoomId, UserId},
BaseClient, Session,
};
use crate::js_int::int; use crate::js_int::int;

View File

@ -1,16 +1,15 @@
use std::collections::HashMap; use std::{
use std::fmt; collections::HashMap,
use std::fs; fmt, fs,
use std::path::{Path, PathBuf}; path::{Path, PathBuf},
use std::sync::{ sync::{
atomic::{AtomicBool, Ordering}, atomic::{AtomicBool, Ordering},
Arc, Arc,
},
}; };
use matrix_sdk_common::identifiers::RoomId; use matrix_sdk_common::{identifiers::RoomId, locks::RwLock};
use matrix_sdk_common::locks::RwLock; use tokio::{fs as async_fs, io::AsyncWriteExt};
use tokio::fs as async_fs;
use tokio::io::AsyncWriteExt;
use super::{AllRooms, ClientState, StateStore}; use super::{AllRooms, ClientState, StateStore};
use crate::{Error, Result, Room, RoomState, Session}; use crate::{Error, Result, Room, RoomState, Session};
@ -218,14 +217,15 @@ impl StateStore for JsonStore {
mod test { mod test {
use super::*; use super::*;
use std::convert::TryFrom; use std::{convert::TryFrom, path::PathBuf};
use std::path::PathBuf;
use tempfile::tempdir; use tempfile::tempdir;
use crate::identifiers::{RoomId, UserId}; use crate::{
use crate::push::Ruleset; identifiers::{RoomId, UserId},
use crate::{BaseClient, BaseClientConfig, Session}; push::Ruleset,
BaseClient, BaseClientConfig, Session,
};
use matrix_sdk_test::{sync_response, SyncResponseFile}; use matrix_sdk_test::{sync_response, SyncResponseFile};

View File

@ -22,10 +22,12 @@ mod json_store;
#[cfg(not(target_arch = "wasm32"))] #[cfg(not(target_arch = "wasm32"))]
pub use json_store::JsonStore; pub use json_store::JsonStore;
use crate::client::{BaseClient, Token}; use crate::{
use crate::identifiers::{RoomId, UserId}; client::{BaseClient, Token},
use crate::push::Ruleset; identifiers::{RoomId, UserId},
use crate::{Result, Room, RoomState, Session}; push::Ruleset,
Result, Room, RoomState, Session,
};
#[cfg(not(target_arch = "wasm32"))] #[cfg(not(target_arch = "wasm32"))]
use matrix_sdk_common_macros::send_sync; use matrix_sdk_common_macros::send_sync;
@ -117,8 +119,7 @@ pub trait StateStore {
mod test { mod test {
use super::*; use super::*;
use std::collections::HashMap; use std::{collections::HashMap, convert::TryFrom};
use std::convert::TryFrom;
use crate::identifiers::RoomId; use crate::identifiers::RoomId;

View File

@ -12,22 +12,27 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use std::collections::BTreeMap; use std::{
use std::convert::TryFrom; collections::BTreeMap,
use std::sync::atomic::{AtomicBool, Ordering}; convert::TryFrom,
use std::sync::Arc; sync::{
atomic::{AtomicBool, Ordering},
Arc,
},
};
use atomic::Atomic; use atomic::Atomic;
use serde_json::{json, Value}; use serde_json::{json, Value};
#[cfg(test)] #[cfg(test)]
use super::OlmMachine; use super::OlmMachine;
use matrix_sdk_common::api::r0::keys::{AlgorithmAndDeviceId, DeviceKeys, KeyAlgorithm, SignedKey}; use matrix_sdk_common::{
use matrix_sdk_common::events::Algorithm; api::r0::keys::{AlgorithmAndDeviceId, DeviceKeys, KeyAlgorithm, SignedKey},
use matrix_sdk_common::identifiers::{DeviceId, UserId}; events::Algorithm,
identifiers::{DeviceId, UserId},
};
use crate::error::SignatureError; use crate::{error::SignatureError, verify_json};
use crate::verify_json;
/// A device represents a E2EE capable client of an user. /// A device represents a E2EE capable client of an user.
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
@ -230,8 +235,10 @@ pub(crate) mod test {
use std::convert::TryFrom; use std::convert::TryFrom;
use crate::device::{Device, TrustState}; use crate::device::{Device, TrustState};
use matrix_sdk_common::api::r0::keys::{DeviceKeys, KeyAlgorithm}; use matrix_sdk_common::{
use matrix_sdk_common::identifiers::UserId; api::r0::keys::{DeviceKeys, KeyAlgorithm},
identifiers::UserId,
};
fn device_keys() -> DeviceKeys { fn device_keys() -> DeviceKeys {
let device_keys = json!({ let device_keys = json!({

View File

@ -43,8 +43,10 @@ pub use store::sqlite::SqliteStore;
pub use store::{CryptoStore, CryptoStoreError}; pub use store::{CryptoStore, CryptoStoreError};
use error::SignatureError; use error::SignatureError;
use matrix_sdk_common::api::r0::keys::{AlgorithmAndDeviceId, KeyAlgorithm}; use matrix_sdk_common::{
use matrix_sdk_common::identifiers::UserId; api::r0::keys::{AlgorithmAndDeviceId, KeyAlgorithm},
identifiers::UserId,
};
use olm_rs::utility::OlmUtility; use olm_rs::utility::OlmUtility;
use serde_json::Value; use serde_json::Value;

View File

@ -12,35 +12,44 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use std::collections::{BTreeMap, HashMap, HashSet};
use std::convert::TryFrom;
use std::convert::TryInto;
use std::mem;
#[cfg(feature = "sqlite-cryptostore")] #[cfg(feature = "sqlite-cryptostore")]
use std::path::Path; use std::path::Path;
use std::result::Result as StdResult; use std::{
collections::{BTreeMap, HashMap, HashSet},
use super::error::{EventError, MegolmError, MegolmResult, OlmError, OlmResult}; convert::{TryFrom, TryInto},
use super::olm::{ mem,
Account, GroupSessionKey, IdentityKeys, InboundGroupSession, OlmMessage, OutboundGroupSession, result::Result as StdResult,
}; };
use super::store::memorystore::MemoryStore;
#[cfg(feature = "sqlite-cryptostore")] #[cfg(feature = "sqlite-cryptostore")]
use super::store::sqlite::SqliteStore; use super::store::sqlite::SqliteStore;
use super::{device::Device, store::Result as StoreResult, CryptoStore}; use super::{
device::Device,
use matrix_sdk_common::events::{ error::{EventError, MegolmError, MegolmResult, OlmError, OlmResult},
forwarded_room_key::ForwardedRoomKeyEventContent, room::encrypted::EncryptedEventContent, olm::{
room::message::MessageEventContent, room_key::RoomKeyEventContent, Account, GroupSessionKey, IdentityKeys, InboundGroupSession, OlmMessage,
room_key_request::RoomKeyRequestEventContent, Algorithm, AnySyncRoomEvent, AnyToDeviceEvent, OutboundGroupSession,
EventType, SyncMessageEvent, ToDeviceEvent, },
store::{memorystore::MemoryStore, Result as StoreResult},
CryptoStore,
};
use matrix_sdk_common::{
api,
events::{
forwarded_room_key::ForwardedRoomKeyEventContent,
room::{encrypted::EncryptedEventContent, message::MessageEventContent},
room_key::RoomKeyEventContent,
room_key_request::RoomKeyRequestEventContent,
Algorithm, AnySyncRoomEvent, AnyToDeviceEvent, EventType, SyncMessageEvent, ToDeviceEvent,
},
identifiers::{DeviceId, RoomId, UserId},
uuid::Uuid,
Raw,
}; };
use matrix_sdk_common::identifiers::{DeviceId, RoomId, UserId};
use matrix_sdk_common::uuid::Uuid;
use matrix_sdk_common::{api, Raw};
use api::r0::keys;
use api::r0::{ use api::r0::{
keys,
keys::{AlgorithmAndDeviceId, DeviceKeys, KeyAlgorithm, OneTimeKey}, keys::{AlgorithmAndDeviceId, DeviceKeys, KeyAlgorithm, OneTimeKey},
sync::sync_events::Response as SyncResponse, sync::sync_events::Response as SyncResponse,
to_device::{send_event_to_device::Request as ToDeviceRequest, DeviceIdOrAllDevices}, to_device::{send_event_to_device::Request as ToDeviceRequest, DeviceIdOrAllDevices},
@ -1166,30 +1175,33 @@ mod test {
static USER_ID: &str = "@bob:example.org"; static USER_ID: &str = "@bob:example.org";
use matrix_sdk_common::js_int::uint; use matrix_sdk_common::js_int::uint;
use std::collections::BTreeMap; use std::{
use std::convert::TryFrom; collections::BTreeMap,
use std::convert::TryInto; convert::{TryFrom, TryInto},
use std::time::SystemTime; time::SystemTime,
};
use http::Response; use http::Response;
use serde_json::json; use serde_json::json;
use crate::machine::{OlmMachine, OneTimeKeys}; use crate::{
use crate::{verify_json, Device}; machine::{OlmMachine, OneTimeKeys},
verify_json, Device,
};
use matrix_sdk_common::api::r0::{ use matrix_sdk_common::{
keys, to_device::send_event_to_device::Request as ToDeviceRequest, api::r0::{keys, to_device::send_event_to_device::Request as ToDeviceRequest},
}; events::{
use matrix_sdk_common::events::{ room::{
room::{ encrypted::EncryptedEventContent,
encrypted::EncryptedEventContent, message::{MessageEventContent, TextMessageEventContent},
message::{MessageEventContent, TextMessageEventContent}, },
AnySyncMessageEvent, AnySyncRoomEvent, AnyToDeviceEvent, EventType, SyncMessageEvent,
ToDeviceEvent, Unsigned,
}, },
AnySyncMessageEvent, AnySyncRoomEvent, AnyToDeviceEvent, EventType, SyncMessageEvent, identifiers::{DeviceId, EventId, RoomId, UserId},
ToDeviceEvent, Unsigned, Raw,
}; };
use matrix_sdk_common::identifiers::{DeviceId, EventId, RoomId, UserId};
use matrix_sdk_common::Raw;
use matrix_sdk_test::test_json; use matrix_sdk_test::test_json;
fn alice_id() -> UserId { fn alice_id() -> UserId {

View File

@ -12,14 +12,15 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use std::collections::HashMap; use std::{collections::HashMap, sync::Arc};
use std::sync::Arc;
use dashmap::{DashMap, ReadOnlyView}; use dashmap::{DashMap, ReadOnlyView};
use matrix_sdk_common::locks::Mutex; use matrix_sdk_common::locks::Mutex;
use super::device::Device; use super::{
use super::olm::{InboundGroupSession, Session}; device::Device,
olm::{InboundGroupSession, Session},
};
use matrix_sdk_common::identifiers::{DeviceId, RoomId, UserId}; use matrix_sdk_common::identifiers::{DeviceId, RoomId, UserId};
/// In-memory store for Olm Sessions. /// In-memory store for Olm Sessions.
@ -211,10 +212,11 @@ impl DeviceStore {
mod test { mod test {
use std::convert::TryFrom; use std::convert::TryFrom;
use crate::device::test::get_device; use crate::{
use crate::memory_stores::{DeviceStore, GroupSessionStore, SessionStore}; device::test::get_device,
use crate::olm::test::get_account_and_session; memory_stores::{DeviceStore, GroupSessionStore, SessionStore},
use crate::olm::InboundGroupSession; olm::{test::get_account_and_session, InboundGroupSession},
};
use matrix_sdk_common::identifiers::RoomId; use matrix_sdk_common::identifiers::RoomId;
#[tokio::test] #[tokio::test]

View File

@ -13,23 +13,27 @@
// limitations under the License. // limitations under the License.
use matrix_sdk_common::instant::Instant; use matrix_sdk_common::instant::Instant;
use std::convert::TryFrom; use std::{
use std::convert::TryInto; convert::{TryFrom, TryInto},
use std::fmt; fmt,
use std::sync::atomic::{AtomicBool, AtomicI64, Ordering}; sync::{
use std::sync::Arc; atomic::{AtomicBool, AtomicI64, Ordering},
Arc,
},
};
use matrix_sdk_common::locks::Mutex; use matrix_sdk_common::locks::Mutex;
use serde_json::{json, Value}; use serde_json::{json, Value};
use std::collections::BTreeMap; use std::collections::BTreeMap;
pub use olm_rs::account::IdentityKeys; pub use olm_rs::account::IdentityKeys;
use olm_rs::account::{OlmAccount, OneTimeKeys}; use olm_rs::{
use olm_rs::errors::{OlmAccountError, OlmSessionError}; account::{OlmAccount, OneTimeKeys},
use olm_rs::PicklingMode; errors::{OlmAccountError, OlmSessionError},
PicklingMode,
};
use crate::device::Device; use crate::{device::Device, error::SessionCreationError};
use crate::error::SessionCreationError;
pub use olm_rs::{ pub use olm_rs::{
session::{OlmMessage, PreKeyMessage}, session::{OlmMessage, PreKeyMessage},
utility::OlmUtility, utility::OlmUtility,

View File

@ -13,10 +13,14 @@
// limitations under the License. // limitations under the License.
use matrix_sdk_common::instant::Instant; use matrix_sdk_common::instant::Instant;
use std::convert::TryInto; use std::{
use std::fmt; convert::TryInto,
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; fmt,
use std::sync::Arc; sync::{
atomic::{AtomicBool, AtomicUsize, Ordering},
Arc,
},
};
use matrix_sdk_common::locks::Mutex; use matrix_sdk_common::locks::Mutex;
use serde::Serialize; use serde::Serialize;
@ -24,10 +28,10 @@ use serde_json::{json, Value};
use zeroize::Zeroize; use zeroize::Zeroize;
pub use olm_rs::account::IdentityKeys; pub use olm_rs::account::IdentityKeys;
use olm_rs::errors::OlmGroupSessionError; use olm_rs::{
use olm_rs::inbound_group_session::OlmInboundGroupSession; errors::OlmGroupSessionError, inbound_group_session::OlmInboundGroupSession,
use olm_rs::outbound_group_session::OlmOutboundGroupSession; outbound_group_session::OlmOutboundGroupSession, PicklingMode,
use olm_rs::PicklingMode; };
use crate::error::{EventError, MegolmResult}; use crate::error::{EventError, MegolmResult};
pub use olm_rs::{ pub use olm_rs::{

View File

@ -23,11 +23,12 @@ pub use session::{OlmMessage, Session};
#[cfg(test)] #[cfg(test)]
pub(crate) mod test { pub(crate) mod test {
use crate::olm::{Account, InboundGroupSession, Session}; use crate::olm::{Account, InboundGroupSession, Session};
use matrix_sdk_common::api::r0::keys::SignedKey; use matrix_sdk_common::{
use matrix_sdk_common::identifiers::{DeviceId, RoomId, UserId}; api::r0::keys::SignedKey,
identifiers::{DeviceId, RoomId, UserId},
};
use olm_rs::session::OlmMessage; use olm_rs::session::OlmMessage;
use std::collections::BTreeMap; use std::{collections::BTreeMap, convert::TryFrom};
use std::convert::TryFrom;
fn alice_id() -> UserId { fn alice_id() -> UserId {
UserId::try_from("@alice:example.org").unwrap() UserId::try_from("@alice:example.org").unwrap()

View File

@ -12,13 +12,9 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use std::collections::BTreeMap; use std::{collections::BTreeMap, fmt, sync::Arc};
use std::fmt;
use std::sync::Arc;
use olm_rs::errors::OlmSessionError; use olm_rs::{errors::OlmSessionError, session::OlmSession, PicklingMode};
use olm_rs::session::OlmSession;
use olm_rs::PicklingMode;
use serde_json::{json, Value}; use serde_json::{json, Value};
@ -28,8 +24,10 @@ pub use olm_rs::{
}; };
use super::IdentityKeys; use super::IdentityKeys;
use crate::error::{EventError, OlmResult}; use crate::{
use crate::Device; error::{EventError, OlmResult},
Device,
};
use matrix_sdk_common::{ use matrix_sdk_common::{
api::r0::keys::KeyAlgorithm, api::r0::keys::KeyAlgorithm,

View File

@ -12,15 +12,16 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use std::collections::HashSet; use std::{collections::HashSet, sync::Arc};
use std::sync::Arc;
use async_trait::async_trait; use async_trait::async_trait;
use matrix_sdk_common::locks::Mutex; use matrix_sdk_common::locks::Mutex;
use super::{Account, CryptoStore, InboundGroupSession, Result, Session}; use super::{Account, CryptoStore, InboundGroupSession, Result, Session};
use crate::device::Device; use crate::{
use crate::memory_stores::{DeviceStore, GroupSessionStore, SessionStore, UserDevices}; device::Device,
memory_stores::{DeviceStore, GroupSessionStore, SessionStore, UserDevices},
};
use matrix_sdk_common::identifiers::{DeviceId, RoomId, UserId}; use matrix_sdk_common::identifiers::{DeviceId, RoomId, UserId};
#[derive(Debug)] #[derive(Debug)]
@ -126,11 +127,11 @@ impl CryptoStore for MemoryStore {
mod test { mod test {
use std::convert::TryFrom; use std::convert::TryFrom;
use crate::device::test::get_device; use crate::{
use crate::olm::test::get_account_and_session; device::test::get_device,
use crate::olm::InboundGroupSession; olm::{test::get_account_and_session, InboundGroupSession},
use crate::store::memorystore::MemoryStore; store::{memorystore::MemoryStore, CryptoStore},
use crate::store::CryptoStore; };
use matrix_sdk_common::identifiers::RoomId; use matrix_sdk_common::identifiers::RoomId;
#[tokio::test] #[tokio::test]

View File

@ -13,9 +13,7 @@
// limitations under the License. // limitations under the License.
use core::fmt::Debug; use core::fmt::Debug;
use std::collections::HashSet; use std::{collections::HashSet, io::Error as IoError, sync::Arc};
use std::io::Error as IoError;
use std::sync::Arc;
use url::ParseError; use url::ParseError;
use async_trait::async_trait; use async_trait::async_trait;
@ -23,9 +21,11 @@ use matrix_sdk_common::locks::Mutex;
use serde_json::Error as SerdeError; use serde_json::Error as SerdeError;
use thiserror::Error; use thiserror::Error;
use super::device::Device; use super::{
use super::memory_stores::UserDevices; device::Device,
use super::olm::{Account, InboundGroupSession, Session}; memory_stores::UserDevices,
olm::{Account, InboundGroupSession, Session},
};
use matrix_sdk_common::identifiers::{DeviceId, RoomId, UserId}; use matrix_sdk_common::identifiers::{DeviceId, RoomId, UserId};
use matrix_sdk_common_macros::send_sync; use matrix_sdk_common_macros::send_sync;
use olm_rs::errors::{OlmAccountError, OlmGroupSessionError, OlmSessionError}; use olm_rs::errors::{OlmAccountError, OlmGroupSessionError, OlmSessionError};

View File

@ -13,11 +13,13 @@
// limitations under the License. // limitations under the License.
use matrix_sdk_common::instant::{Duration, Instant}; use matrix_sdk_common::instant::{Duration, Instant};
use std::collections::{BTreeMap, HashSet}; use std::{
use std::convert::TryFrom; collections::{BTreeMap, HashSet},
use std::path::{Path, PathBuf}; convert::TryFrom,
use std::result::Result as StdResult; path::{Path, PathBuf},
use std::sync::Arc; result::Result as StdResult,
sync::Arc,
};
use url::Url; use url::Url;
use async_trait::async_trait; use async_trait::async_trait;
@ -27,12 +29,16 @@ use sqlx::{query, query_as, sqlite::SqliteQueryAs, Connect, Executor, SqliteConn
use zeroize::Zeroizing; use zeroize::Zeroizing;
use super::{CryptoStore, CryptoStoreError, Result}; use super::{CryptoStore, CryptoStoreError, Result};
use crate::device::{Device, TrustState}; use crate::{
use crate::memory_stores::{DeviceStore, GroupSessionStore, SessionStore, UserDevices}; device::{Device, TrustState},
use crate::{Account, IdentityKeys, InboundGroupSession, Session}; memory_stores::{DeviceStore, GroupSessionStore, SessionStore, UserDevices},
use matrix_sdk_common::api::r0::keys::{AlgorithmAndDeviceId, KeyAlgorithm}; Account, IdentityKeys, InboundGroupSession, Session,
use matrix_sdk_common::events::Algorithm; };
use matrix_sdk_common::identifiers::{DeviceId, RoomId, UserId}; use matrix_sdk_common::{
api::r0::keys::{AlgorithmAndDeviceId, KeyAlgorithm},
events::Algorithm,
identifiers::{DeviceId, RoomId, UserId},
};
/// SQLite based implementation of a `CryptoStore`. /// SQLite based implementation of a `CryptoStore`.
pub struct SqliteStore { pub struct SqliteStore {
@ -887,10 +893,11 @@ impl std::fmt::Debug for SqliteStore {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use crate::device::test::get_device; use crate::{device::test::get_device, olm::GroupSessionKey};
use crate::olm::GroupSessionKey; use matrix_sdk_common::{
use matrix_sdk_common::api::r0::keys::SignedKey; api::r0::keys::SignedKey,
use matrix_sdk_common::identifiers::{DeviceId, UserId}; identifiers::{DeviceId, UserId},
};
use olm_rs::outbound_group_session::OlmOutboundGroupSession; use olm_rs::outbound_group_session::OlmOutboundGroupSession;
use std::collections::BTreeMap; use std::collections::BTreeMap;
use tempfile::tempdir; use tempfile::tempdir;

View File

@ -1,15 +1,15 @@
use std::collections::HashMap; use std::{collections::HashMap, convert::TryFrom, panic};
use std::convert::TryFrom;
use std::panic;
use http::Response; use http::Response;
use matrix_sdk_common::api::r0::sync::sync_events::Response as SyncResponse; use matrix_sdk_common::{
use matrix_sdk_common::events::{ api::r0::sync::sync_events::Response as SyncResponse,
presence::PresenceEvent, AnyBasicEvent, AnySyncEphemeralRoomEvent, AnySyncRoomEvent, events::{
AnySyncStateEvent, presence::PresenceEvent, AnyBasicEvent, AnySyncEphemeralRoomEvent, AnySyncRoomEvent,
AnySyncStateEvent,
},
identifiers::RoomId,
}; };
use matrix_sdk_common::identifiers::RoomId;
use serde_json::Value as JsonValue; use serde_json::Value as JsonValue;
pub use matrix_sdk_test_macros::async_test; pub use matrix_sdk_test_macros::async_test;