Unify import style across workspace

master
Devin Ragotzy 2020-08-02 08:05:43 -04:00
parent 230b2a229f
commit 0ac2b84c02
18 changed files with 164 additions and 182 deletions

View File

@ -19,44 +19,37 @@ use std::{
collections::HashMap,
convert::{TryFrom, TryInto},
fmt::{self, Debug},
future::Future,
path::Path,
result::Result as StdResult,
sync::Arc,
};
#[cfg(not(target_arch = "wasm32"))]
use crate::VERSION;
use crate::{Error, EventEmitter, Result};
use futures_timer::Delay as sleep;
use http::{Method as HttpMethod, Response as HttpResponse};
use matrix_sdk_base::{BaseClient, BaseClientConfig, Room, Session, StateStore};
#[cfg(feature = "encryption")]
use matrix_sdk_common::identifiers::DeviceId;
use matrix_sdk_common::{
identifiers::ServerName,
api,
events::{room::message::MessageEventContent, EventType},
identifiers::{EventId, RoomId, RoomIdOrAliasId, ServerName, UserId},
instant::{Duration, Instant},
js_int::UInt,
locks::RwLock,
presence::PresenceState,
uuid::Uuid,
Endpoint,
};
use futures_timer::Delay as sleep;
use std::future::Future;
use reqwest::header::{HeaderValue, InvalidHeaderValue, AUTHORIZATION};
#[cfg(feature = "encryption")]
use tracing::{debug, warn};
use tracing::{error, info, instrument, trace};
use http::{Method as HttpMethod, Response as HttpResponse};
use reqwest::header::{HeaderValue, InvalidHeaderValue, AUTHORIZATION};
use url::Url;
use crate::{
events::{room::message::MessageEventContent, EventType},
identifiers::{EventId, RoomId, RoomIdOrAliasId, UserId},
Endpoint,
};
#[cfg(feature = "encryption")]
use crate::identifiers::DeviceId;
#[cfg(not(target_arch = "wasm32"))]
use crate::VERSION;
use crate::{api, Error, EventEmitter, Result};
use matrix_sdk_base::{BaseClient, BaseClientConfig, Room, Session, StateStore};
const DEFAULT_SYNC_TIMEOUT: Duration = Duration::from_secs(30);
/// An async/await enabled Matrix client.

View File

@ -14,16 +14,14 @@
//! Error conditions.
use reqwest::Error as ReqwestError;
use serde_json::Error as JsonError;
use thiserror::Error;
use matrix_sdk_base::Error as MatrixError;
use crate::{
use matrix_sdk_common::{
api::{r0::uiaa::UiaaResponse as UiaaError, Error as RumaClientError},
FromHttpResponseError as RumaResponseError, IntoHttpError as RumaIntoHttpError,
};
use reqwest::Error as ReqwestError;
use serde_json::Error as JsonError;
use thiserror::Error;
/// Result type of the rust-sdk.
pub type Result<T> = std::result::Result<T, Error>;

View File

@ -42,17 +42,17 @@ pub use matrix_sdk_base::{
CustomOrRawEvent, Error as BaseError, EventEmitter, Room, RoomState, Session, StateStore,
SyncRoom,
};
#[cfg(feature = "messages")]
pub use matrix_sdk_base::{MessageQueue, MessageWrapper, PossiblyRedactedExt};
pub use matrix_sdk_common::*;
pub use reqwest::header::InvalidHeaderValue;
#[cfg(feature = "encryption")]
pub use matrix_sdk_base::{Device, TrustState};
#[cfg(feature = "messages")]
pub use matrix_sdk_base::{MessageQueue, PossiblyRedactedExt};
pub use matrix_sdk_common::*;
pub use reqwest::header::InvalidHeaderValue;
mod client;
mod error;
mod request_builder;
pub use client::{Client, ClientConfig, SyncSettings};
pub use error::{Error, Result};
pub use request_builder::{

View File

@ -18,58 +18,53 @@ use std::collections::{BTreeMap, HashSet};
use std::{
collections::HashMap,
fmt,
ops::Deref,
path::{Path, PathBuf},
result::Result as StdResult,
sync::Arc,
};
use zeroize::Zeroizing;
use std::result::Result as StdResult;
use crate::{api::r0 as api, error::Result, events::presence::PresenceEvent};
// `NonRoomEvent` is what it is aliased as
use crate::{
event_emitter::CustomOrRawEvent,
events::{
ignored_user_list::IgnoredUserListEvent, push_rules::PushRulesEvent,
room::member::MemberEventContent,
},
identifiers::{RoomId, UserId},
models::Room,
push::Ruleset,
session::Session,
state::{AllRooms, ClientState, StateStore},
EventEmitter,
};
use matrix_sdk_common::{
events::{
AnyBasicEvent, AnyStrippedStateEvent, AnySyncEphemeralRoomEvent, AnySyncMessageEvent,
AnySyncRoomEvent, AnySyncStateEvent,
},
Raw,
};
#[cfg(feature = "encryption")]
use matrix_sdk_common::locks::Mutex;
use matrix_sdk_common::locks::RwLock;
use std::ops::Deref;
#[cfg(feature = "encryption")]
use crate::api::r0::keys::{
claim_keys::Response as KeysClaimResponse, get_keys::Response as KeysQueryResponse,
upload_keys::Response as KeysUploadResponse, DeviceKeys, KeyAlgorithm,
use matrix_sdk_common::{
api::r0 as api,
api::r0::keys::{
claim_keys::Response as KeysClaimResponse, get_keys::Response as KeysQueryResponse,
upload_keys::Response as KeysUploadResponse, DeviceKeys, KeyAlgorithm,
},
api::r0::to_device::send_event_to_device,
events::room::{
encrypted::EncryptedEventContent, message::MessageEventContent as MsgEventContent,
},
identifiers::DeviceId,
};
#[cfg(feature = "encryption")]
use crate::api::r0::to_device::send_event_to_device;
#[cfg(feature = "encryption")]
use crate::events::room::{
encrypted::EncryptedEventContent, message::MessageEventContent as MsgEventContent,
use matrix_sdk_common::{
events::{
ignored_user_list::IgnoredUserListEvent, push_rules::PushRulesEvent,
room::member::MemberEventContent, AnyBasicEvent, AnyStrippedStateEvent,
AnySyncEphemeralRoomEvent, AnySyncMessageEvent, AnySyncRoomEvent, AnySyncStateEvent,
},
identifiers::{RoomId, UserId},
locks::RwLock,
push::Ruleset,
Raw,
};
#[cfg(feature = "encryption")]
use crate::identifiers::DeviceId;
#[cfg(not(target_arch = "wasm32"))]
use crate::JsonStore;
#[cfg(feature = "encryption")]
use matrix_sdk_crypto::{CryptoStore, OlmError, OlmMachine, OneTimeKeys};
use zeroize::Zeroizing;
#[cfg(not(target_arch = "wasm32"))]
use crate::JsonStore;
use crate::{
error::Result,
event_emitter::CustomOrRawEvent,
events::presence::PresenceEvent,
models::Room,
session::Session,
state::{AllRooms, ClientState, StateStore},
EventEmitter,
};
pub type Token = String;

View File

@ -5,11 +5,12 @@
use std::{time::SystemTime, vec::IntoIter};
use matrix_sdk_common::identifiers::{EventId, UserId};
use matrix_sdk_common::{
events::AnyPossiblyRedactedSyncMessageEvent,
identifiers::{EventId, UserId},
};
use serde::{de, ser, Serialize};
use crate::events::AnyPossiblyRedactedSyncMessageEvent;
/// Exposes some of the field access methods found in the event held by
/// `AnyPossiblyRedacted*` enums.
///

View File

@ -20,13 +20,11 @@ use std::{
convert::TryFrom,
};
use serde::{Deserialize, Serialize};
use tracing::{debug, error, trace};
#[cfg(feature = "messages")]
use super::message::MessageQueue;
use super::RoomMember;
use crate::{
use matrix_sdk_common::events::{
room::redaction::SyncRedactionEvent, AnyPossiblyRedactedSyncMessageEvent, AnySyncMessageEvent,
};
use matrix_sdk_common::{
api::r0::sync::sync_events::{RoomSummary, UnreadNotificationsCount},
events::{
presence::{PresenceEvent, PresenceEventContent},
@ -42,16 +40,15 @@ use crate::{
Algorithm, AnyStrippedStateEvent, AnySyncRoomEvent, AnySyncStateEvent, EventType,
StrippedStateEvent, SyncStateEvent,
},
identifiers::{RoomAliasId, RoomId, UserId},
js_int::{int, uint, Int, UInt},
};
use serde::{Deserialize, Serialize};
use tracing::{debug, error, trace};
#[cfg(feature = "messages")]
use crate::events::{
room::redaction::SyncRedactionEvent, AnyPossiblyRedactedSyncMessageEvent, AnySyncMessageEvent,
};
use crate::identifiers::{RoomAliasId, RoomId, UserId};
use crate::js_int::{int, uint, Int, UInt};
use super::message::MessageQueue;
use super::RoomMember;
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
/// `RoomName` allows the calculation of a text room name.

View File

@ -15,7 +15,7 @@
//! User sessions.
use crate::identifiers::{DeviceId, UserId};
use matrix_sdk_common::identifiers::{DeviceId, UserId};
/// A user session, containing an access token and information about the
/// associated user account.

View File

@ -15,6 +15,10 @@
use std::collections::HashMap;
use matrix_sdk_common::{
identifiers::{RoomId, UserId},
push::Ruleset,
};
use serde::{Deserialize, Serialize};
#[cfg(not(target_arch = "wasm32"))]
@ -24,8 +28,6 @@ pub use json_store::JsonStore;
use crate::{
client::{BaseClient, Token},
identifiers::{RoomId, UserId},
push::Ruleset,
Result, Room, RoomState, Session,
};

View File

@ -1,6 +1,5 @@
pub use instant;
pub use js_int;
pub use ruma::{
api::{
client as api,

View File

@ -22,16 +22,15 @@ use std::{
};
use atomic::Atomic;
use serde_json::{json, Value};
#[cfg(test)]
use super::OlmMachine;
use matrix_sdk_common::{
api::r0::keys::{AlgorithmAndDeviceId, DeviceKeys, KeyAlgorithm, SignedKey},
events::Algorithm,
identifiers::{DeviceId, UserId},
};
use serde_json::{json, Value};
#[cfg(test)]
use super::OlmMachine;
use crate::{error::SignatureError, verify_json};
/// A device represents a E2EE capable client of an user.

View File

@ -21,19 +21,12 @@ use std::{
result::Result as StdResult,
};
#[cfg(feature = "sqlite-cryptostore")]
use super::store::sqlite::SqliteStore;
use super::{
device::Device,
error::{EventError, MegolmError, MegolmResult, OlmError, OlmResult},
olm::{
Account, GroupSessionKey, IdentityKeys, InboundGroupSession, OlmMessage,
OutboundGroupSession,
},
store::{memorystore::MemoryStore, Result as StoreResult},
CryptoStore,
use api::r0::{
keys,
keys::{AlgorithmAndDeviceId, DeviceKeys, KeyAlgorithm, OneTimeKey},
sync::sync_events::Response as SyncResponse,
to_device::{send_event_to_device::Request as ToDeviceRequest, DeviceIdOrAllDevices},
};
use matrix_sdk_common::{
api,
events::{
@ -47,17 +40,22 @@ use matrix_sdk_common::{
uuid::Uuid,
Raw,
};
use api::r0::{
keys,
keys::{AlgorithmAndDeviceId, DeviceKeys, KeyAlgorithm, OneTimeKey},
sync::sync_events::Response as SyncResponse,
to_device::{send_event_to_device::Request as ToDeviceRequest, DeviceIdOrAllDevices},
};
use serde_json::Value;
use tracing::{debug, error, info, instrument, trace, warn};
#[cfg(feature = "sqlite-cryptostore")]
use super::store::sqlite::SqliteStore;
use super::{
device::Device,
error::{EventError, MegolmError, MegolmResult, OlmError, OlmResult},
olm::{
Account, GroupSessionKey, IdentityKeys, InboundGroupSession, OlmMessage,
OutboundGroupSession,
},
store::{memorystore::MemoryStore, Result as StoreResult},
CryptoStore,
};
/// A map from the algorithm and device id to a one-time key.
///
/// These keys need to be periodically uploaded to the server.

View File

@ -15,13 +15,15 @@
use std::{collections::HashMap, sync::Arc};
use dashmap::{DashMap, ReadOnlyView};
use matrix_sdk_common::locks::Mutex;
use matrix_sdk_common::{
identifiers::{DeviceId, RoomId, UserId},
locks::Mutex,
};
use super::{
device::Device,
olm::{InboundGroupSession, Session},
};
use matrix_sdk_common::identifiers::{DeviceId, RoomId, UserId};
/// In-memory store for Olm Sessions.
#[derive(Debug, Default)]

View File

@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use matrix_sdk_common::instant::Instant;
use std::{
collections::BTreeMap,
convert::{TryFrom, TryInto},
fmt,
sync::{
@ -22,30 +22,28 @@ use std::{
},
};
use matrix_sdk_common::locks::Mutex;
use serde_json::{json, Value};
use std::collections::BTreeMap;
pub use olm_rs::account::IdentityKeys;
use matrix_sdk_common::{
api::r0::keys::{AlgorithmAndDeviceId, DeviceKeys, KeyAlgorithm, OneTimeKey, SignedKey},
events::Algorithm,
identifiers::{DeviceId, RoomId, UserId},
instant::Instant,
locks::Mutex,
};
use olm_rs::{
account::{OlmAccount, OneTimeKeys},
errors::{OlmAccountError, OlmSessionError},
PicklingMode,
};
use serde_json::{json, Value};
use crate::{device::Device, error::SessionCreationError};
pub use olm_rs::{
account::IdentityKeys,
session::{OlmMessage, PreKeyMessage},
utility::OlmUtility,
};
use matrix_sdk_common::{
api::r0::keys::{AlgorithmAndDeviceId, DeviceKeys, KeyAlgorithm, OneTimeKey, SignedKey},
events::Algorithm,
identifiers::{DeviceId, RoomId, UserId},
};
use super::{InboundGroupSession, OutboundGroupSession, Session};
use crate::{device::Device, error::SessionCreationError};
/// Account holding identity keys for which sessions can be created.
///

View File

@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use matrix_sdk_common::instant::Instant;
use std::{
convert::TryInto,
fmt,
@ -22,31 +21,31 @@ use std::{
},
};
use matrix_sdk_common::locks::Mutex;
use serde::Serialize;
use serde_json::{json, Value};
use zeroize::Zeroize;
pub use olm_rs::account::IdentityKeys;
use olm_rs::{
errors::OlmGroupSessionError, inbound_group_session::OlmInboundGroupSession,
outbound_group_session::OlmOutboundGroupSession, PicklingMode,
};
use crate::error::{EventError, MegolmResult};
pub use olm_rs::{
session::{OlmMessage, PreKeyMessage},
utility::OlmUtility,
};
use matrix_sdk_common::{
events::{
room::{encrypted::EncryptedEventContent, message::MessageEventContent},
Algorithm, AnySyncRoomEvent, EventType, SyncMessageEvent,
},
identifiers::{DeviceId, RoomId},
instant::Instant,
locks::Mutex,
Raw,
};
use olm_rs::{
errors::OlmGroupSessionError, inbound_group_session::OlmInboundGroupSession,
outbound_group_session::OlmOutboundGroupSession, PicklingMode,
};
use serde::Serialize;
use serde_json::{json, Value};
use zeroize::Zeroize;
pub use olm_rs::{
account::IdentityKeys,
session::{OlmMessage, PreKeyMessage},
utility::OlmUtility,
};
use crate::error::{EventError, MegolmResult};
/// The private session key of a group session.
/// Can be used to create a new inbound group session.

View File

@ -14,21 +14,6 @@
use std::{collections::BTreeMap, fmt, sync::Arc};
use olm_rs::{errors::OlmSessionError, session::OlmSession, PicklingMode};
use serde_json::{json, Value};
pub use olm_rs::{
session::{OlmMessage, PreKeyMessage},
utility::OlmUtility,
};
use super::IdentityKeys;
use crate::{
error::{EventError, OlmResult},
Device,
};
use matrix_sdk_common::{
api::r0::keys::KeyAlgorithm,
events::{
@ -39,6 +24,19 @@ use matrix_sdk_common::{
instant::Instant,
locks::Mutex,
};
use olm_rs::{errors::OlmSessionError, session::OlmSession, PicklingMode};
use serde_json::{json, Value};
use super::IdentityKeys;
use crate::{
error::{EventError, OlmResult},
Device,
};
pub use olm_rs::{
session::{OlmMessage, PreKeyMessage},
utility::OlmUtility,
};
/// Cryptographic session that enables secure communication between two
/// `Account`s

View File

@ -15,15 +15,16 @@
use std::{collections::HashSet, sync::Arc};
use async_trait::async_trait;
use matrix_sdk_common::locks::Mutex;
use matrix_sdk_common::{
identifiers::{DeviceId, RoomId, UserId},
locks::Mutex,
};
use super::{Account, CryptoStore, InboundGroupSession, Result, Session};
use crate::{
device::Device,
memory_stores::{DeviceStore, GroupSessionStore, SessionStore, UserDevices},
};
use matrix_sdk_common::identifiers::{DeviceId, RoomId, UserId};
#[derive(Debug)]
pub struct MemoryStore {
sessions: SessionStore,

View File

@ -12,23 +12,25 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use core::fmt::Debug;
use std::{collections::HashSet, io::Error as IoError, sync::Arc};
use url::ParseError;
use async_trait::async_trait;
use matrix_sdk_common::locks::Mutex;
use core::fmt::Debug;
use matrix_sdk_common::{
identifiers::{DeviceId, RoomId, UserId},
locks::Mutex,
};
use matrix_sdk_common_macros::send_sync;
use olm_rs::errors::{OlmAccountError, OlmGroupSessionError, OlmSessionError};
use serde_json::Error as SerdeError;
use thiserror::Error;
use url::ParseError;
use super::{
device::Device,
memory_stores::UserDevices,
olm::{Account, InboundGroupSession, Session},
};
use matrix_sdk_common::identifiers::{DeviceId, RoomId, UserId};
use matrix_sdk_common_macros::send_sync;
use olm_rs::errors::{OlmAccountError, OlmGroupSessionError, OlmSessionError};
pub mod memorystore;

View File

@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use matrix_sdk_common::instant::{Duration, Instant};
use std::{
collections::{BTreeMap, HashSet},
convert::TryFrom,
@ -20,12 +19,18 @@ use std::{
result::Result as StdResult,
sync::Arc,
};
use url::Url;
use async_trait::async_trait;
use matrix_sdk_common::locks::Mutex;
use matrix_sdk_common::{
api::r0::keys::{AlgorithmAndDeviceId, KeyAlgorithm},
events::Algorithm,
identifiers::{DeviceId, RoomId, UserId},
instant::{Duration, Instant},
locks::Mutex,
};
use olm_rs::PicklingMode;
use sqlx::{query, query_as, sqlite::SqliteQueryAs, Connect, Executor, SqliteConnection};
use url::Url;
use zeroize::Zeroizing;
use super::{CryptoStore, CryptoStoreError, Result};
@ -34,11 +39,6 @@ use crate::{
memory_stores::{DeviceStore, GroupSessionStore, SessionStore, UserDevices},
Account, IdentityKeys, InboundGroupSession, Session,
};
use matrix_sdk_common::{
api::r0::keys::{AlgorithmAndDeviceId, KeyAlgorithm},
events::Algorithm,
identifiers::{DeviceId, RoomId, UserId},
};
/// SQLite based implementation of a `CryptoStore`.
pub struct SqliteStore {