2020-02-21 15:54:05 +00:00
|
|
|
// Copyright 2020 Damir Jelić
|
|
|
|
// Copyright 2020 The Matrix.org Foundation C.I.C.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2019-11-26 18:06:29 +00:00
|
|
|
use futures::future::{BoxFuture, Future, FutureExt};
|
2019-10-23 20:47:00 +00:00
|
|
|
use std::convert::{TryFrom, TryInto};
|
2020-03-18 13:15:56 +00:00
|
|
|
use std::result::Result as StdResult;
|
2019-11-10 10:44:03 +00:00
|
|
|
use std::sync::atomic::{AtomicU64, Ordering};
|
2020-03-11 10:42:59 +00:00
|
|
|
use std::sync::{Arc, Mutex, RwLock as SyncLock};
|
2020-02-28 09:33:17 +00:00
|
|
|
use std::time::{Duration, Instant};
|
2020-03-11 10:42:59 +00:00
|
|
|
use tokio::sync::RwLock;
|
2020-03-16 12:31:03 +00:00
|
|
|
use tokio::time::delay_for as sleep;
|
2020-03-19 12:55:04 +00:00
|
|
|
use tracing::{debug, info, instrument, trace};
|
2019-10-23 20:47:00 +00:00
|
|
|
|
|
|
|
use http::Method as HttpMethod;
|
|
|
|
use http::Response as HttpResponse;
|
2019-10-24 20:34:58 +00:00
|
|
|
use reqwest::header::{HeaderValue, InvalidHeaderValue};
|
2019-10-23 20:47:00 +00:00
|
|
|
use url::Url;
|
|
|
|
|
2019-12-04 18:31:33 +00:00
|
|
|
use ruma_api::{Endpoint, Outgoing};
|
2019-10-23 20:47:00 +00:00
|
|
|
use ruma_events::collections::all::RoomEvent;
|
2020-03-29 12:07:25 +00:00
|
|
|
use ruma_events::presence::PresenceEvent;
|
2019-11-10 10:44:03 +00:00
|
|
|
use ruma_events::room::message::MessageEventContent;
|
2019-11-26 19:34:11 +00:00
|
|
|
use ruma_events::EventResult;
|
2019-10-23 20:47:00 +00:00
|
|
|
pub use ruma_events::EventType;
|
2019-11-10 17:33:06 +00:00
|
|
|
use ruma_identifiers::RoomId;
|
2019-10-23 20:47:00 +00:00
|
|
|
|
|
|
|
use crate::api;
|
|
|
|
use crate::base_client::Client as BaseClient;
|
2020-03-28 10:58:30 +00:00
|
|
|
use crate::models::Room;
|
2019-10-23 20:47:00 +00:00
|
|
|
use crate::session::Session;
|
2019-11-17 18:55:59 +00:00
|
|
|
use crate::VERSION;
|
2020-03-18 13:15:56 +00:00
|
|
|
use crate::{Error, Result};
|
2019-10-23 20:47:00 +00:00
|
|
|
|
2020-03-11 10:42:59 +00:00
|
|
|
type RoomEventCallback = Box<
|
|
|
|
dyn FnMut(Arc<SyncLock<Room>>, Arc<EventResult<RoomEvent>>) -> BoxFuture<'static, ()> + Send,
|
|
|
|
>;
|
2019-10-30 18:30:55 +00:00
|
|
|
|
2020-03-29 12:05:40 +00:00
|
|
|
type PresenceEventCallback = Box<
|
2020-03-29 12:07:25 +00:00
|
|
|
dyn FnMut(Arc<SyncLock<Room>>, Arc<EventResult<PresenceEvent>>) -> BoxFuture<'static, ()>
|
|
|
|
+ Send,
|
2020-03-29 12:05:40 +00:00
|
|
|
>;
|
|
|
|
|
2020-03-24 15:18:56 +00:00
|
|
|
const DEFAULT_SYNC_TIMEOUT: Duration = Duration::from_secs(30);
|
2020-02-28 09:33:17 +00:00
|
|
|
|
2019-11-10 10:44:03 +00:00
|
|
|
#[derive(Clone)]
|
2020-02-21 13:29:25 +00:00
|
|
|
/// An async/await enabled Matrix client.
|
2019-10-23 20:47:00 +00:00
|
|
|
pub struct AsyncClient {
|
|
|
|
/// The URL of the homeserver to connect to.
|
|
|
|
homeserver: Url,
|
|
|
|
/// The underlying HTTP client.
|
|
|
|
http_client: reqwest::Client,
|
|
|
|
/// User session data.
|
2019-11-10 10:44:03 +00:00
|
|
|
base_client: Arc<RwLock<BaseClient>>,
|
|
|
|
/// The transaction id.
|
|
|
|
transaction_id: Arc<AtomicU64>,
|
2019-12-04 18:31:33 +00:00
|
|
|
/// Event callbacks
|
|
|
|
event_callbacks: Arc<Mutex<Vec<RoomEventCallback>>>,
|
2020-03-29 12:05:40 +00:00
|
|
|
presence_callbacks: Arc<Mutex<Vec<PresenceEventCallback>>>,
|
2019-10-23 20:47:00 +00:00
|
|
|
}
|
|
|
|
|
2020-03-19 12:55:04 +00:00
|
|
|
impl std::fmt::Debug for AsyncClient {
|
|
|
|
fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> StdResult<(), std::fmt::Error> {
|
|
|
|
write!(fmt, "AsyncClient {{ homeserver: {} }}", self.homeserver)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-23 20:47:00 +00:00
|
|
|
#[derive(Default, Debug)]
|
2020-02-21 13:29:25 +00:00
|
|
|
/// Configuration for the creation of the `AsyncClient`.
|
|
|
|
///
|
|
|
|
/// # Example
|
|
|
|
///
|
|
|
|
/// ```
|
2020-03-02 10:31:03 +00:00
|
|
|
/// # use matrix_sdk::AsyncClientConfig;
|
2020-02-21 13:29:25 +00:00
|
|
|
/// // To pass all the request through mitmproxy set the proxy and disable SSL
|
|
|
|
/// // verification
|
|
|
|
/// let client_config = AsyncClientConfig::new()
|
|
|
|
/// .proxy("http://localhost:8080")
|
|
|
|
/// .unwrap()
|
|
|
|
/// .disable_ssl_verification();
|
|
|
|
/// ```
|
2019-10-23 20:47:00 +00:00
|
|
|
pub struct AsyncClientConfig {
|
|
|
|
proxy: Option<reqwest::Proxy>,
|
2019-10-24 20:34:58 +00:00
|
|
|
user_agent: Option<HeaderValue>,
|
2019-10-23 20:47:00 +00:00
|
|
|
disable_ssl_verification: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl AsyncClientConfig {
|
2020-02-21 13:29:25 +00:00
|
|
|
/// Create a new default `AsyncClientConfig`.
|
2019-10-23 20:47:00 +00:00
|
|
|
pub fn new() -> Self {
|
|
|
|
Default::default()
|
|
|
|
}
|
|
|
|
|
2020-02-21 13:29:25 +00:00
|
|
|
/// Set the proxy through which all the HTTP requests should go.
|
|
|
|
///
|
|
|
|
/// Note, only HTTP proxies are supported.
|
|
|
|
///
|
|
|
|
/// # Arguments
|
|
|
|
///
|
|
|
|
/// * `proxy` - The HTTP URL of the proxy.
|
|
|
|
///
|
|
|
|
/// # Example
|
|
|
|
///
|
|
|
|
/// ```
|
2020-02-24 11:51:42 +00:00
|
|
|
/// use matrix_sdk::AsyncClientConfig;
|
2020-02-21 13:29:25 +00:00
|
|
|
///
|
|
|
|
/// let client_config = AsyncClientConfig::new()
|
|
|
|
/// .proxy("http://localhost:8080")
|
|
|
|
/// .unwrap();
|
|
|
|
/// ```
|
2020-03-18 13:15:56 +00:00
|
|
|
pub fn proxy(mut self, proxy: &str) -> Result<Self> {
|
2019-10-23 20:47:00 +00:00
|
|
|
self.proxy = Some(reqwest::Proxy::all(proxy)?);
|
|
|
|
Ok(self)
|
|
|
|
}
|
|
|
|
|
2020-02-21 13:29:25 +00:00
|
|
|
/// Disable SSL verification for the HTTP requests.
|
2019-10-23 20:47:00 +00:00
|
|
|
pub fn disable_ssl_verification(mut self) -> Self {
|
|
|
|
self.disable_ssl_verification = true;
|
|
|
|
self
|
|
|
|
}
|
2019-10-24 20:34:58 +00:00
|
|
|
|
2020-02-21 13:29:25 +00:00
|
|
|
/// Set a custom HTTP user agent for the client.
|
2020-03-18 13:15:56 +00:00
|
|
|
pub fn user_agent(mut self, user_agent: &str) -> StdResult<Self, InvalidHeaderValue> {
|
2019-10-24 20:34:58 +00:00
|
|
|
self.user_agent = Some(HeaderValue::from_str(user_agent)?);
|
|
|
|
Ok(self)
|
|
|
|
}
|
2019-10-23 20:47:00 +00:00
|
|
|
}
|
|
|
|
|
2019-12-04 18:31:33 +00:00
|
|
|
#[derive(Debug, Default, Clone)]
|
2020-02-21 13:29:25 +00:00
|
|
|
/// Settings for a sync call.
|
2019-10-23 20:47:00 +00:00
|
|
|
pub struct SyncSettings {
|
2020-03-24 15:18:56 +00:00
|
|
|
pub(crate) timeout: Option<Duration>,
|
2019-10-23 20:47:00 +00:00
|
|
|
pub(crate) token: Option<String>,
|
|
|
|
pub(crate) full_state: Option<bool>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl SyncSettings {
|
2020-02-21 13:29:25 +00:00
|
|
|
/// Create new default sync settings.
|
2019-10-23 20:47:00 +00:00
|
|
|
pub fn new() -> Self {
|
|
|
|
Default::default()
|
|
|
|
}
|
|
|
|
|
2020-02-21 13:29:25 +00:00
|
|
|
/// Set the sync token.
|
|
|
|
///
|
|
|
|
/// # Arguments
|
|
|
|
///
|
|
|
|
/// * `token` - The sync token that should be used for the sync call.
|
2019-10-23 20:47:00 +00:00
|
|
|
pub fn token<S: Into<String>>(mut self, token: S) -> Self {
|
|
|
|
self.token = Some(token.into());
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2020-02-21 13:29:25 +00:00
|
|
|
/// Set the maximum time the server can wait, in milliseconds, before
|
|
|
|
/// responding to the sync request.
|
|
|
|
///
|
|
|
|
/// # Arguments
|
|
|
|
///
|
|
|
|
/// * `timeout` - The time the server is allowed to wait.
|
2020-03-24 15:18:56 +00:00
|
|
|
pub fn timeout(mut self, timeout: Duration) -> Self {
|
|
|
|
self.timeout = Some(timeout);
|
|
|
|
self
|
2019-10-23 20:47:00 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 13:29:25 +00:00
|
|
|
/// Should the server return the full state from the start of the timeline.
|
|
|
|
///
|
|
|
|
/// This does nothing if no sync token is set.
|
|
|
|
///
|
|
|
|
/// # Arguments
|
|
|
|
/// * `full_state` - A boolean deciding if the server should return the full
|
|
|
|
/// state or not.
|
2019-10-23 20:47:00 +00:00
|
|
|
pub fn full_state(mut self, full_state: bool) -> Self {
|
|
|
|
self.full_state = Some(full_state);
|
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-11 10:42:59 +00:00
|
|
|
#[cfg(feature = "encryption")]
|
|
|
|
use api::r0::keys::upload_keys;
|
2020-02-21 15:33:08 +00:00
|
|
|
use api::r0::message::create_message_event;
|
2019-10-23 20:47:00 +00:00
|
|
|
use api::r0::session::login;
|
|
|
|
use api::r0::sync::sync_events;
|
|
|
|
|
|
|
|
impl AsyncClient {
|
|
|
|
/// Creates a new client for making HTTP requests to the given homeserver.
|
2020-02-21 13:29:25 +00:00
|
|
|
///
|
|
|
|
/// # Arguments
|
|
|
|
///
|
|
|
|
/// * `homeserver_url` - The homeserver that the client should connect to.
|
|
|
|
/// * `session` - If a previous login exists, the access token can be
|
|
|
|
/// reused by giving a session object here.
|
2020-03-18 13:15:56 +00:00
|
|
|
pub fn new<U: TryInto<Url>>(homeserver_url: U, session: Option<Session>) -> Result<Self> {
|
2019-10-24 20:34:58 +00:00
|
|
|
let config = AsyncClientConfig::new();
|
|
|
|
AsyncClient::new_with_config(homeserver_url, session, config)
|
2019-10-23 20:47:00 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 13:29:25 +00:00
|
|
|
/// Create a new client with the given configuration.
|
|
|
|
///
|
|
|
|
/// # Arguments
|
|
|
|
///
|
|
|
|
/// * `homeserver_url` - The homeserver that the client should connect to.
|
|
|
|
/// * `session` - If a previous login exists, the access token can be
|
|
|
|
/// reused by giving a session object here.
|
|
|
|
/// * `config` - Configuration for the client.
|
2019-11-10 10:44:03 +00:00
|
|
|
pub fn new_with_config<U: TryInto<Url>>(
|
|
|
|
homeserver_url: U,
|
2019-10-23 20:47:00 +00:00
|
|
|
session: Option<Session>,
|
|
|
|
config: AsyncClientConfig,
|
2020-03-18 13:15:56 +00:00
|
|
|
) -> Result<Self> {
|
2019-11-10 10:44:03 +00:00
|
|
|
let homeserver: Url = match homeserver_url.try_into() {
|
|
|
|
Ok(u) => u,
|
2020-02-21 13:29:46 +00:00
|
|
|
Err(_e) => panic!("Error parsing homeserver url"),
|
2019-11-10 10:44:03 +00:00
|
|
|
};
|
|
|
|
|
2019-10-23 20:47:00 +00:00
|
|
|
let http_client = reqwest::Client::builder();
|
|
|
|
|
|
|
|
let http_client = if config.disable_ssl_verification {
|
|
|
|
http_client.danger_accept_invalid_certs(true)
|
|
|
|
} else {
|
|
|
|
http_client
|
|
|
|
};
|
|
|
|
|
|
|
|
let http_client = match config.proxy {
|
|
|
|
Some(p) => http_client.proxy(p),
|
|
|
|
None => http_client,
|
|
|
|
};
|
|
|
|
|
|
|
|
let mut headers = reqwest::header::HeaderMap::new();
|
|
|
|
|
2019-10-24 20:34:58 +00:00
|
|
|
let user_agent = match config.user_agent {
|
|
|
|
Some(a) => a,
|
2020-03-11 10:43:31 +00:00
|
|
|
None => HeaderValue::from_str(&format!("matrix-rust-sdk {}", VERSION)).unwrap(),
|
2019-10-24 20:34:58 +00:00
|
|
|
};
|
|
|
|
|
2019-11-10 17:33:06 +00:00
|
|
|
headers.insert(reqwest::header::USER_AGENT, user_agent);
|
2019-10-23 20:47:00 +00:00
|
|
|
|
2020-02-21 11:13:38 +00:00
|
|
|
let http_client = http_client.default_headers(headers).build()?;
|
2019-10-23 20:47:00 +00:00
|
|
|
|
|
|
|
Ok(Self {
|
|
|
|
homeserver,
|
|
|
|
http_client,
|
2020-03-18 13:15:56 +00:00
|
|
|
base_client: Arc::new(RwLock::new(BaseClient::new(session)?)),
|
2019-11-10 10:44:03 +00:00
|
|
|
transaction_id: Arc::new(AtomicU64::new(0)),
|
2019-12-04 18:31:33 +00:00
|
|
|
event_callbacks: Arc::new(Mutex::new(Vec::new())),
|
2020-03-29 12:05:40 +00:00
|
|
|
presence_callbacks: Arc::new(Mutex::new(Vec::new())),
|
2019-10-23 20:47:00 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-01-11 21:24:32 +00:00
|
|
|
/// Is the client logged in.
|
2020-03-11 10:42:59 +00:00
|
|
|
pub async fn logged_in(&self) -> bool {
|
|
|
|
// TODO turn this into a atomic bool so this method doesn't need to be
|
|
|
|
// async.
|
|
|
|
self.base_client.read().await.logged_in()
|
2019-11-17 18:55:27 +00:00
|
|
|
}
|
|
|
|
|
2020-01-11 21:24:32 +00:00
|
|
|
/// The Homeserver of the client.
|
|
|
|
pub fn homeserver(&self) -> &Url {
|
|
|
|
&self.homeserver
|
|
|
|
}
|
|
|
|
|
2020-03-27 21:22:11 +00:00
|
|
|
#[doc(hidden)]
|
|
|
|
/// Access to the underlying `BaseClient`. Used for testing and debugging so far.
|
2020-03-28 00:17:06 +00:00
|
|
|
pub fn base_client(&self) -> Arc<RwLock<BaseClient>> {
|
|
|
|
Arc::clone(&self.base_client)
|
2020-03-27 21:22:11 +00:00
|
|
|
}
|
2020-03-28 12:58:02 +00:00
|
|
|
|
2020-03-27 21:22:11 +00:00
|
|
|
/// Calculate the room name from a `RoomId`, returning a string.
|
|
|
|
pub async fn get_room_name(&self, room_id: &str) -> Option<String> {
|
|
|
|
self.base_client.read().await.calculate_room_name(room_id)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Calculate the room names this client knows about.
|
|
|
|
pub async fn get_room_names(&self) -> Vec<String> {
|
|
|
|
self.base_client.read().await.calculate_room_names()
|
|
|
|
}
|
|
|
|
|
2020-02-21 13:29:25 +00:00
|
|
|
/// Add a callback that will be called every time the client receives a room
|
|
|
|
/// event
|
|
|
|
///
|
|
|
|
/// # Arguments
|
|
|
|
///
|
|
|
|
/// * `callback` - The callback that should be called once a RoomEvent is
|
|
|
|
/// received.
|
|
|
|
///
|
|
|
|
/// # Examples
|
2020-03-02 10:31:03 +00:00
|
|
|
/// ```
|
|
|
|
/// # use matrix_sdk::events::{
|
|
|
|
/// # collections::all::RoomEvent,
|
|
|
|
/// # room::message::{MessageEvent, MessageEventContent, TextMessageEventContent},
|
|
|
|
/// # EventResult,
|
|
|
|
/// # };
|
|
|
|
/// # use matrix_sdk::Room;
|
|
|
|
/// # use std::sync::{Arc, RwLock};
|
|
|
|
/// # use matrix_sdk::AsyncClient;
|
|
|
|
/// # use url::Url;
|
|
|
|
///
|
2020-02-21 13:29:25 +00:00
|
|
|
/// async fn async_cb(room: Arc<RwLock<Room>>, event: Arc<EventResult<RoomEvent>>) {
|
|
|
|
/// let room = room.read().unwrap();
|
|
|
|
/// let event = if let EventResult::Ok(event) = &*event {
|
|
|
|
/// event
|
|
|
|
/// } else {
|
|
|
|
/// return;
|
|
|
|
/// };
|
|
|
|
/// if let RoomEvent::RoomMessage(MessageEvent {
|
|
|
|
/// content: MessageEventContent::Text(TextMessageEventContent { body: msg_body, .. }),
|
|
|
|
/// sender,
|
|
|
|
/// ..
|
|
|
|
/// }) = event
|
|
|
|
/// {
|
2020-03-28 10:58:30 +00:00
|
|
|
/// let member = room.members.get(&sender.to_string()).unwrap();
|
2020-02-21 13:29:25 +00:00
|
|
|
/// println!(
|
|
|
|
/// "{}: {}",
|
2020-03-28 10:58:30 +00:00
|
|
|
/// member.user.display_name.as_ref().unwrap_or(&sender.to_string()),
|
2020-02-21 13:29:25 +00:00
|
|
|
/// msg_body
|
|
|
|
/// );
|
|
|
|
/// }
|
|
|
|
/// }
|
2020-03-02 10:31:03 +00:00
|
|
|
/// # fn main() -> Result<(), matrix_sdk::Error> {
|
|
|
|
/// let homeserver = Url::parse("http://localhost:8080")?;
|
2020-02-21 13:29:25 +00:00
|
|
|
///
|
2020-03-02 10:31:03 +00:00
|
|
|
/// let mut client = AsyncClient::new(homeserver, None)?;
|
|
|
|
///
|
|
|
|
/// client.add_event_callback(async_cb);
|
|
|
|
/// # Ok(())
|
|
|
|
/// # }
|
|
|
|
/// ```
|
2019-12-04 18:31:33 +00:00
|
|
|
pub fn add_event_callback<C: 'static>(
|
2019-11-26 18:06:29 +00:00
|
|
|
&mut self,
|
2020-03-11 10:42:59 +00:00
|
|
|
mut callback: impl FnMut(Arc<SyncLock<Room>>, Arc<EventResult<RoomEvent>>) -> C + 'static + Send,
|
2019-11-26 18:06:29 +00:00
|
|
|
) where
|
|
|
|
C: Future<Output = ()> + Send,
|
|
|
|
{
|
2019-12-04 18:31:33 +00:00
|
|
|
let mut futures = self.event_callbacks.lock().unwrap();
|
2019-11-26 18:06:29 +00:00
|
|
|
|
|
|
|
let future = move |room, event| callback(room, event).boxed();
|
|
|
|
|
|
|
|
futures.push(Box::new(future));
|
|
|
|
}
|
2019-10-30 22:26:26 +00:00
|
|
|
|
2020-03-29 12:05:40 +00:00
|
|
|
/// Add a callback that will be called every time the client receives a room
|
|
|
|
/// event
|
|
|
|
///
|
|
|
|
/// # Arguments
|
|
|
|
///
|
|
|
|
/// * `callback` - The callback that should be called once a RoomEvent is
|
|
|
|
/// received.
|
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
/// ```
|
|
|
|
/// # use matrix_sdk::events::{
|
|
|
|
/// # collections::all::RoomEvent,
|
|
|
|
/// # room::message::{MessageEvent, MessageEventContent, TextMessageEventContent},
|
|
|
|
/// # presence::{PresenceEvent, PresenceEventContent},
|
|
|
|
/// # EventResult,
|
|
|
|
/// # };
|
|
|
|
/// # use matrix_sdk::Room;
|
|
|
|
/// # use std::sync::{Arc, RwLock};
|
|
|
|
/// # use matrix_sdk::AsyncClient;
|
|
|
|
/// # use url::Url;
|
|
|
|
///
|
|
|
|
/// async fn async_cb(room: Arc<RwLock<Room>>, event: Arc<EventResult<PresenceEvent>>) {
|
|
|
|
/// let room = room.read().unwrap();
|
|
|
|
/// let event = if let EventResult::Ok(event) = &*event {
|
|
|
|
/// event
|
|
|
|
/// } else {
|
|
|
|
/// return;
|
|
|
|
/// };
|
|
|
|
/// let PresenceEvent {
|
|
|
|
/// content: PresenceEventContent {
|
|
|
|
/// avatar_url,
|
|
|
|
/// currently_active,
|
|
|
|
/// displayname,
|
|
|
|
/// last_active_ago,
|
|
|
|
/// presence,
|
|
|
|
/// status_msg,
|
|
|
|
/// },
|
|
|
|
/// sender,
|
|
|
|
/// } = event;
|
|
|
|
/// {
|
|
|
|
/// let member = room.members.get(&sender.to_string()).unwrap();
|
|
|
|
/// println!(
|
|
|
|
/// "{} is {}",
|
|
|
|
/// displayname.as_deref().unwrap_or(&sender.to_string()),
|
|
|
|
/// status_msg.as_deref().unwrap_or("not here")
|
|
|
|
/// );
|
|
|
|
/// }
|
|
|
|
/// }
|
|
|
|
/// # fn main() -> Result<(), matrix_sdk::Error> {
|
|
|
|
/// let homeserver = Url::parse("http://localhost:8080")?;
|
|
|
|
///
|
|
|
|
/// let mut client = AsyncClient::new(homeserver, None)?;
|
|
|
|
///
|
|
|
|
/// client.add_presence_callback(async_cb);
|
|
|
|
/// # Ok(())
|
|
|
|
/// # }
|
|
|
|
/// ```
|
|
|
|
pub fn add_presence_callback<C: 'static>(
|
|
|
|
&mut self,
|
2020-03-29 12:07:25 +00:00
|
|
|
mut callback: impl FnMut(Arc<SyncLock<Room>>, Arc<EventResult<PresenceEvent>>) -> C
|
|
|
|
+ 'static
|
|
|
|
+ Send,
|
2020-03-29 12:05:40 +00:00
|
|
|
) where
|
|
|
|
C: Future<Output = ()> + Send,
|
|
|
|
{
|
|
|
|
let mut futures = self.presence_callbacks.lock().unwrap();
|
|
|
|
|
|
|
|
let future = move |room, event| callback(room, event).boxed();
|
|
|
|
|
|
|
|
futures.push(Box::new(future));
|
|
|
|
}
|
|
|
|
|
2020-02-21 13:29:25 +00:00
|
|
|
/// Login to the server.
|
|
|
|
///
|
|
|
|
/// # Arguments
|
|
|
|
///
|
2020-03-02 10:31:03 +00:00
|
|
|
/// * `user` - The user that should be logged in to the homeserver.
|
|
|
|
///
|
|
|
|
/// * `password` - The password of the user.
|
|
|
|
///
|
|
|
|
/// * `device_id` - A unique id that will be associated with this session. If
|
2020-02-21 13:29:25 +00:00
|
|
|
/// not given the homeserver will create one. Can be an exising
|
|
|
|
/// device_id from a previous login call. Note that this should be done
|
|
|
|
/// only if the client also holds the encryption keys for this devcie.
|
2020-03-19 12:55:04 +00:00
|
|
|
#[instrument(skip(password))]
|
|
|
|
pub async fn login<S: Into<String> + std::fmt::Debug>(
|
2019-10-23 20:47:00 +00:00
|
|
|
&mut self,
|
|
|
|
user: S,
|
|
|
|
password: S,
|
|
|
|
device_id: Option<S>,
|
2020-03-27 08:22:29 +00:00
|
|
|
initial_device_display_name: Option<S>,
|
2020-03-18 13:15:56 +00:00
|
|
|
) -> Result<login::Response> {
|
2020-03-19 12:55:04 +00:00
|
|
|
info!("Logging in to {} as {:?}", self.homeserver, user);
|
|
|
|
|
2019-10-23 20:47:00 +00:00
|
|
|
let request = login::Request {
|
2020-02-21 15:33:08 +00:00
|
|
|
user: login::UserInfo::MatrixId(user.into()),
|
|
|
|
login_info: login::LoginInfo::Password {
|
|
|
|
password: password.into(),
|
|
|
|
},
|
2019-10-23 20:47:00 +00:00
|
|
|
device_id: device_id.map(|d| d.into()),
|
2020-03-27 08:22:29 +00:00
|
|
|
initial_device_display_name: initial_device_display_name.map(|d| d.into()),
|
2019-10-23 20:47:00 +00:00
|
|
|
};
|
|
|
|
|
2019-10-30 18:30:55 +00:00
|
|
|
let response = self.send(request).await?;
|
2020-03-11 10:42:59 +00:00
|
|
|
let mut client = self.base_client.write().await;
|
2020-03-18 13:15:56 +00:00
|
|
|
client.receive_login_response(&response).await?;
|
2019-10-23 20:47:00 +00:00
|
|
|
|
|
|
|
Ok(response)
|
|
|
|
}
|
|
|
|
|
2020-02-21 13:29:25 +00:00
|
|
|
/// Synchronise the client's state with the latest state on the server.
|
|
|
|
///
|
|
|
|
/// # Arguments
|
|
|
|
///
|
|
|
|
/// * `sync_settings` - Settings for the sync call.
|
2020-03-19 12:55:04 +00:00
|
|
|
#[instrument]
|
2019-10-23 20:47:00 +00:00
|
|
|
pub async fn sync(
|
|
|
|
&mut self,
|
|
|
|
sync_settings: SyncSettings,
|
2020-03-18 13:15:56 +00:00
|
|
|
) -> Result<sync_events::IncomingResponse> {
|
2019-10-23 20:47:00 +00:00
|
|
|
let request = sync_events::Request {
|
|
|
|
filter: None,
|
|
|
|
since: sync_settings.token,
|
|
|
|
full_state: sync_settings.full_state,
|
|
|
|
set_presence: None,
|
|
|
|
timeout: sync_settings.timeout,
|
|
|
|
};
|
|
|
|
|
2020-03-12 14:41:11 +00:00
|
|
|
let mut response = self.send(request).await?;
|
2019-10-23 20:47:00 +00:00
|
|
|
|
2020-03-25 14:03:10 +00:00
|
|
|
for (room_id, room) in &mut response.rooms.join {
|
|
|
|
let room_id_string = room_id.to_string();
|
2019-10-23 21:36:57 +00:00
|
|
|
|
2019-11-26 19:34:11 +00:00
|
|
|
let matrix_room = {
|
2020-03-11 10:42:59 +00:00
|
|
|
let mut client = self.base_client.write().await;
|
2019-10-30 18:30:55 +00:00
|
|
|
|
2019-11-26 19:34:11 +00:00
|
|
|
for event in &room.state.events {
|
|
|
|
if let EventResult::Ok(e) = event {
|
2020-03-25 14:03:10 +00:00
|
|
|
client.receive_joined_state_event(&room_id_string, &e);
|
2019-11-26 19:34:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-25 14:03:10 +00:00
|
|
|
client.get_or_create_room(&room_id_string).clone()
|
2019-11-26 19:34:11 +00:00
|
|
|
};
|
2019-10-23 21:36:57 +00:00
|
|
|
|
2020-03-25 14:03:10 +00:00
|
|
|
for mut event in &mut room.timeline.events {
|
|
|
|
let decrypted_event = {
|
2020-03-11 10:42:59 +00:00
|
|
|
let mut client = self.base_client.write().await;
|
2020-03-25 14:03:10 +00:00
|
|
|
client
|
|
|
|
.receive_joined_timeline_event(room_id, &mut event)
|
|
|
|
.await
|
|
|
|
};
|
2019-10-30 18:30:55 +00:00
|
|
|
|
2020-03-26 10:23:39 +00:00
|
|
|
if let Some(e) = decrypted_event {
|
|
|
|
*event = e;
|
|
|
|
}
|
2020-03-28 12:58:02 +00:00
|
|
|
|
2019-11-26 19:34:11 +00:00
|
|
|
let callbacks = {
|
2019-12-04 18:31:33 +00:00
|
|
|
let mut cb_futures = self.event_callbacks.lock().unwrap();
|
2020-03-26 10:23:39 +00:00
|
|
|
|
|
|
|
let event = if !cb_futures.is_empty() {
|
|
|
|
Arc::new(event.clone())
|
|
|
|
} else {
|
|
|
|
continue;
|
|
|
|
};
|
|
|
|
|
2019-11-26 19:34:11 +00:00
|
|
|
let mut callbacks = Vec::new();
|
|
|
|
|
|
|
|
for cb in &mut cb_futures.iter_mut() {
|
2020-03-28 12:58:02 +00:00
|
|
|
callbacks.push(cb(matrix_room.clone(), Arc::clone(&event)));
|
2019-11-26 19:34:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
callbacks
|
|
|
|
};
|
|
|
|
|
|
|
|
for cb in callbacks {
|
|
|
|
cb.await;
|
2019-11-26 18:06:29 +00:00
|
|
|
}
|
2019-10-23 20:47:00 +00:00
|
|
|
}
|
2020-03-29 12:05:40 +00:00
|
|
|
|
|
|
|
// After the room has been created and state/timeline events accounted for we use the room_id of the newly created
|
|
|
|
// to add any presence events that relate to a user in the current room. This is not super
|
|
|
|
// efficient but we need a room_id so we would loop through now or later.
|
|
|
|
for presence in &response.presence.events {
|
|
|
|
let mut client = self.base_client.write().await;
|
|
|
|
if let EventResult::Ok(e) = presence {
|
|
|
|
client.receive_presence_event(&room_id_string, e);
|
|
|
|
}
|
|
|
|
|
|
|
|
let callbacks = {
|
|
|
|
let mut cb_futures = self.presence_callbacks.lock().unwrap();
|
|
|
|
let event = if !cb_futures.is_empty() {
|
|
|
|
Arc::new(presence.clone())
|
|
|
|
} else {
|
|
|
|
continue;
|
|
|
|
};
|
|
|
|
let mut callbacks = Vec::new();
|
|
|
|
for cb in &mut cb_futures.iter_mut() {
|
|
|
|
callbacks.push(cb(matrix_room.clone(), Arc::clone(&event)));
|
|
|
|
}
|
|
|
|
|
|
|
|
callbacks
|
|
|
|
};
|
|
|
|
for cb in callbacks {
|
|
|
|
cb.await;
|
|
|
|
}
|
|
|
|
}
|
2019-10-23 20:47:00 +00:00
|
|
|
}
|
|
|
|
|
2020-03-11 10:42:59 +00:00
|
|
|
let mut client = self.base_client.write().await;
|
2020-03-12 14:41:11 +00:00
|
|
|
client.receive_sync_response(&mut response).await;
|
2020-03-11 10:42:59 +00:00
|
|
|
|
2019-10-23 20:47:00 +00:00
|
|
|
Ok(response)
|
|
|
|
}
|
|
|
|
|
2020-02-21 13:29:25 +00:00
|
|
|
/// Repeatedly call sync to synchronize the client state with the server.
|
|
|
|
///
|
|
|
|
/// # Arguments
|
|
|
|
///
|
|
|
|
/// * `sync_settings` - Settings for the sync call. Note that those settings
|
|
|
|
/// will be only used for the first sync call.
|
2020-03-02 10:31:03 +00:00
|
|
|
///
|
2020-02-21 13:29:25 +00:00
|
|
|
/// * `callback` - A callback that will be called every time a successful
|
|
|
|
/// response has been fetched from the server.
|
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// The following example demonstrates how to sync forever while sending all
|
|
|
|
/// the interesting events through a mpsc channel to another thread e.g. a
|
|
|
|
/// UI thread.
|
|
|
|
///
|
2020-03-02 10:31:03 +00:00
|
|
|
/// ```compile_fail,E0658
|
|
|
|
/// # use matrix_sdk::events::{
|
|
|
|
/// # collections::all::RoomEvent,
|
|
|
|
/// # room::message::{MessageEvent, MessageEventContent, TextMessageEventContent},
|
|
|
|
/// # EventResult,
|
|
|
|
/// # };
|
|
|
|
/// # use matrix_sdk::Room;
|
|
|
|
/// # use std::sync::{Arc, RwLock};
|
|
|
|
/// # use matrix_sdk::{AsyncClient, SyncSettings};
|
|
|
|
/// # use url::Url;
|
|
|
|
/// # use futures::executor::block_on;
|
|
|
|
/// # block_on(async {
|
|
|
|
/// # let homeserver = Url::parse("http://localhost:8080").unwrap();
|
|
|
|
/// # let mut client = AsyncClient::new(homeserver, None).unwrap();
|
|
|
|
///
|
|
|
|
/// use async_std::sync::channel;
|
|
|
|
///
|
|
|
|
/// let (tx, rx) = channel(100);
|
|
|
|
///
|
|
|
|
/// let sync_channel = &tx;
|
|
|
|
/// let sync_settings = SyncSettings::new()
|
|
|
|
/// .timeout(30_000)
|
|
|
|
/// .unwrap();
|
|
|
|
///
|
2020-02-21 13:29:25 +00:00
|
|
|
/// client
|
|
|
|
/// .sync_forever(sync_settings, async move |response| {
|
|
|
|
/// let channel = sync_channel;
|
2020-03-02 10:31:03 +00:00
|
|
|
///
|
2020-02-21 13:29:25 +00:00
|
|
|
/// for (room_id, room) in response.rooms.join {
|
|
|
|
/// for event in room.timeline.events {
|
|
|
|
/// if let EventResult::Ok(e) = event {
|
|
|
|
/// channel.send(e).await;
|
|
|
|
/// }
|
|
|
|
/// }
|
|
|
|
/// }
|
|
|
|
/// })
|
|
|
|
/// .await;
|
2020-03-02 10:31:03 +00:00
|
|
|
/// })
|
2020-02-21 13:29:25 +00:00
|
|
|
/// ```
|
2020-03-19 12:55:04 +00:00
|
|
|
#[instrument(skip(callback))]
|
2019-12-04 21:33:26 +00:00
|
|
|
pub async fn sync_forever<C>(
|
|
|
|
&mut self,
|
|
|
|
sync_settings: SyncSettings,
|
|
|
|
callback: impl Fn(sync_events::IncomingResponse) -> C + Send,
|
|
|
|
) where
|
|
|
|
C: Future<Output = ()>,
|
|
|
|
{
|
|
|
|
let mut sync_settings = sync_settings;
|
2020-02-28 09:33:17 +00:00
|
|
|
let mut last_sync_time: Option<Instant> = None;
|
2019-12-04 21:33:26 +00:00
|
|
|
|
|
|
|
loop {
|
|
|
|
let response = self.sync(sync_settings.clone()).await;
|
|
|
|
|
|
|
|
let response = if let Ok(r) = response {
|
|
|
|
r
|
|
|
|
} else {
|
|
|
|
sleep(Duration::from_secs(1)).await;
|
|
|
|
continue;
|
|
|
|
};
|
|
|
|
|
|
|
|
callback(response).await;
|
|
|
|
|
2020-03-11 10:43:58 +00:00
|
|
|
// TODO query keys here.
|
|
|
|
// TODO send out to-device messages here
|
|
|
|
|
|
|
|
#[cfg(feature = "encryption")]
|
|
|
|
{
|
|
|
|
if self.base_client.read().await.should_upload_keys().await {
|
|
|
|
let _ = self.keys_upload().await;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-28 09:33:17 +00:00
|
|
|
let now = Instant::now();
|
|
|
|
|
|
|
|
// If the last sync happened less than a second ago, sleep for a
|
|
|
|
// while to not hammer out requests if the server doesn't respect
|
|
|
|
// the sync timeout.
|
|
|
|
if let Some(t) = last_sync_time {
|
|
|
|
if now - t <= Duration::from_secs(1) {
|
|
|
|
sleep(Duration::from_secs(1)).await;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
last_sync_time = Some(now);
|
|
|
|
|
2020-03-24 15:18:56 +00:00
|
|
|
sync_settings = SyncSettings::new().timeout(DEFAULT_SYNC_TIMEOUT).token(
|
|
|
|
self.sync_token()
|
|
|
|
.await
|
|
|
|
.expect("No sync token found after initial sync"),
|
|
|
|
);
|
2019-12-04 21:33:26 +00:00
|
|
|
}
|
|
|
|
}
|
2019-11-26 19:34:11 +00:00
|
|
|
|
2020-03-19 12:55:04 +00:00
|
|
|
async fn send<Request: Endpoint + std::fmt::Debug>(
|
2019-12-04 18:31:33 +00:00
|
|
|
&self,
|
|
|
|
request: Request,
|
2020-03-18 13:15:56 +00:00
|
|
|
) -> Result<<Request::Response as Outgoing>::Incoming>
|
2019-12-04 18:31:33 +00:00
|
|
|
where
|
2020-02-21 15:33:08 +00:00
|
|
|
Request::Incoming:
|
|
|
|
TryFrom<http::Request<Vec<u8>>, Error = ruma_api::error::FromHttpRequestError>,
|
2020-03-24 15:18:56 +00:00
|
|
|
<Request::Response as Outgoing>::Incoming: TryFrom<
|
|
|
|
http::Response<Vec<u8>>,
|
|
|
|
Error = ruma_api::error::FromHttpResponseError<
|
|
|
|
<Request as ruma_api::Endpoint>::ResponseError,
|
|
|
|
>,
|
|
|
|
>,
|
|
|
|
<Request as ruma_api::Endpoint>::ResponseError: std::fmt::Debug,
|
2019-12-04 18:31:33 +00:00
|
|
|
{
|
2019-10-23 20:47:00 +00:00
|
|
|
let request: http::Request<Vec<u8>> = request.try_into()?;
|
|
|
|
let url = request.uri();
|
2019-11-10 17:33:06 +00:00
|
|
|
let url = self
|
|
|
|
.homeserver
|
|
|
|
.join(url.path_and_query().unwrap().as_str())
|
|
|
|
.unwrap();
|
2019-10-23 20:47:00 +00:00
|
|
|
|
2020-03-19 12:55:04 +00:00
|
|
|
trace!("Doing request {:?}", url);
|
|
|
|
|
2019-10-23 20:47:00 +00:00
|
|
|
let request_builder = match Request::METADATA.method {
|
|
|
|
HttpMethod::GET => self.http_client.get(url),
|
|
|
|
HttpMethod::POST => {
|
|
|
|
let body = request.body().clone();
|
|
|
|
self.http_client.post(url).body(body)
|
|
|
|
}
|
2019-11-10 10:44:03 +00:00
|
|
|
HttpMethod::PUT => {
|
|
|
|
let body = request.body().clone();
|
|
|
|
self.http_client.put(url).body(body)
|
|
|
|
}
|
2019-10-23 20:47:00 +00:00
|
|
|
HttpMethod::DELETE => unimplemented!(),
|
|
|
|
_ => panic!("Unsuported method"),
|
|
|
|
};
|
|
|
|
|
|
|
|
let request_builder = if Request::METADATA.requires_authentication {
|
2020-03-11 10:42:59 +00:00
|
|
|
let client = self.base_client.read().await;
|
2019-11-10 10:44:03 +00:00
|
|
|
|
|
|
|
if let Some(ref session) = client.session {
|
2019-10-23 20:47:00 +00:00
|
|
|
request_builder.bearer_auth(&session.access_token)
|
|
|
|
} else {
|
2020-03-18 13:15:56 +00:00
|
|
|
return Err(Error::AuthenticationRequired);
|
2019-10-23 20:47:00 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
request_builder
|
|
|
|
};
|
|
|
|
|
2020-03-19 12:55:04 +00:00
|
|
|
let mut response = request_builder.send().await?;
|
|
|
|
|
|
|
|
trace!("Got response: {:?}", response);
|
2019-10-23 20:47:00 +00:00
|
|
|
|
|
|
|
let status = response.status();
|
2020-03-19 12:55:04 +00:00
|
|
|
let mut http_response = HttpResponse::builder().status(status);
|
|
|
|
let headers = http_response.headers_mut().unwrap();
|
|
|
|
|
|
|
|
for (k, v) in response.headers_mut().drain() {
|
|
|
|
if let Some(key) = k {
|
|
|
|
headers.insert(key, v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-23 20:47:00 +00:00
|
|
|
let body = response.bytes().await?.as_ref().to_owned();
|
2020-03-19 12:55:04 +00:00
|
|
|
let http_response = http_response.body(body).unwrap();
|
2020-03-24 15:18:56 +00:00
|
|
|
let response = <Request::Response as Outgoing>::Incoming::try_from(http_response)
|
|
|
|
.expect("Can't convert http response into ruma response");
|
2019-10-23 20:47:00 +00:00
|
|
|
|
|
|
|
Ok(response)
|
|
|
|
}
|
2019-11-10 10:44:44 +00:00
|
|
|
|
2020-02-21 13:29:25 +00:00
|
|
|
/// Get a new unique transaction id for the client.
|
2019-11-10 10:44:44 +00:00
|
|
|
fn transaction_id(&self) -> u64 {
|
|
|
|
self.transaction_id.fetch_add(1, Ordering::SeqCst)
|
|
|
|
}
|
|
|
|
|
2020-02-21 13:29:25 +00:00
|
|
|
/// Send a room message to the homeserver.
|
|
|
|
///
|
2020-03-02 10:31:03 +00:00
|
|
|
/// Returns the parsed response from the server.
|
|
|
|
///
|
2020-02-21 13:29:25 +00:00
|
|
|
/// # Arguments
|
|
|
|
///
|
2020-03-02 10:31:03 +00:00
|
|
|
/// * `room_id` - The id of the room that should receive the message.
|
2020-02-21 13:29:25 +00:00
|
|
|
///
|
2020-03-02 10:31:03 +00:00
|
|
|
/// * `data` - The content of the message.
|
2019-11-10 17:33:06 +00:00
|
|
|
pub async fn room_send(
|
|
|
|
&mut self,
|
|
|
|
room_id: &str,
|
|
|
|
data: MessageEventContent,
|
2020-03-18 13:15:56 +00:00
|
|
|
) -> Result<create_message_event::Response> {
|
2020-02-21 15:33:08 +00:00
|
|
|
let request = create_message_event::Request {
|
2019-11-10 10:44:44 +00:00
|
|
|
room_id: RoomId::try_from(room_id).unwrap(),
|
|
|
|
event_type: EventType::RoomMessage,
|
|
|
|
txn_id: self.transaction_id().to_string(),
|
|
|
|
data,
|
|
|
|
};
|
|
|
|
|
|
|
|
let response = self.send(request).await?;
|
|
|
|
Ok(response)
|
|
|
|
}
|
2019-11-24 21:40:52 +00:00
|
|
|
|
2020-03-11 10:42:59 +00:00
|
|
|
/// Upload the E2E encryption keys.
|
|
|
|
///
|
|
|
|
/// This uploads the long lived device keys as well as the required amount
|
|
|
|
/// of one-time keys.
|
|
|
|
///
|
|
|
|
/// # Panics
|
|
|
|
///
|
|
|
|
/// Panics if the client isn't logged in, or if no encryption keys need to
|
|
|
|
/// be uploaded.
|
|
|
|
#[cfg(feature = "encryption")]
|
2020-03-19 12:55:04 +00:00
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "encryption")))]
|
|
|
|
#[instrument]
|
2020-03-18 13:15:56 +00:00
|
|
|
async fn keys_upload(&self) -> Result<upload_keys::Response> {
|
2020-03-11 10:42:59 +00:00
|
|
|
let (device_keys, one_time_keys) = self
|
|
|
|
.base_client
|
|
|
|
.read()
|
|
|
|
.await
|
|
|
|
.keys_for_upload()
|
|
|
|
.await
|
|
|
|
.expect("Keys don't need to be uploaded");
|
2020-03-19 12:55:04 +00:00
|
|
|
|
|
|
|
debug!(
|
|
|
|
"Uploading encryption keys device keys: {}, one-time-keys: {}",
|
|
|
|
device_keys.is_some(),
|
|
|
|
one_time_keys.as_ref().map_or(0, |k| k.len())
|
|
|
|
);
|
|
|
|
|
2020-03-11 10:42:59 +00:00
|
|
|
let request = upload_keys::Request {
|
|
|
|
device_keys,
|
|
|
|
one_time_keys,
|
|
|
|
};
|
|
|
|
|
|
|
|
let response = self.send(request).await?;
|
|
|
|
self.base_client
|
|
|
|
.write()
|
|
|
|
.await
|
|
|
|
.receive_keys_upload_response(&response)
|
2020-03-18 14:50:32 +00:00
|
|
|
.await?;
|
2020-03-11 10:42:59 +00:00
|
|
|
Ok(response)
|
|
|
|
}
|
|
|
|
|
2020-02-21 13:29:25 +00:00
|
|
|
/// Get the current, if any, sync token of the client.
|
|
|
|
/// This will be None if the client didn't sync at least once.
|
2020-03-11 10:42:59 +00:00
|
|
|
pub async fn sync_token(&self) -> Option<String> {
|
|
|
|
self.base_client.read().await.sync_token.clone()
|
2019-11-24 21:40:52 +00:00
|
|
|
}
|
2019-10-23 20:47:00 +00:00
|
|
|
}
|