refactor(sdk)!: Make from in MessageOptions optional

This commit is contained in:
Jonas Platte
2022-07-19 15:25:16 +02:00
committed by GitHub
15 changed files with 46 additions and 29 deletions

View File

@@ -12,7 +12,7 @@ criterion = { version = "0.3.5", features = ["async", "async_tokio", "html_repor
matrix-sdk-crypto = { path = "../crates/matrix-sdk-crypto", version = "0.5.0" }
matrix-sdk-sled = { path = "../crates/matrix-sdk-sled", version = "0.1.0", default-features = false, features = ["crypto-store"] }
matrix-sdk-test = { path = "../crates/matrix-sdk-test", version = "0.5.0" }
ruma = { git = "https://github.com/ruma/ruma", rev = "7ec599e83d8ba6b2ace9e4fe184fc7560b0ff6ae" }
ruma = { git = "https://github.com/ruma/ruma", rev = "da5def6731efd698c63fd2ffdef5f3e1836bff94" }
serde_json = "1.0.79"
tempfile = "3.3.0"
tokio = { version = "1.17.0", default-features = false, features = ["rt-multi-thread"] }

View File

@@ -20,7 +20,7 @@ hmac = "0.12.1"
http = "0.2.6"
pbkdf2 = "0.11.0"
rand = "0.8.5"
ruma = { git = "https://github.com/ruma/ruma", rev = "7ec599e83d8ba6b2ace9e4fe184fc7560b0ff6ae", features = ["client-api-c"] }
ruma = { git = "https://github.com/ruma/ruma", rev = "da5def6731efd698c63fd2ffdef5f3e1836bff94", features = ["client-api-c"] }
serde = "1.0.136"
serde_json = "1.0.79"
sha2 = "0.10.2"

View File

@@ -30,7 +30,7 @@ tracing = []
[dependencies]
matrix-sdk-common = { version = "0.5.0", path = "../../crates/matrix-sdk-common" }
matrix-sdk-crypto = { version = "0.5.0", path = "../../crates/matrix-sdk-crypto" }
ruma = { git = "https://github.com/ruma/ruma", rev = "7ec599e83d8ba6b2ace9e4fe184fc7560b0ff6ae", features = ["client-api-c", "js", "rand", "unstable-msc2676", "unstable-msc2677"] }
ruma = { git = "https://github.com/ruma/ruma", rev = "da5def6731efd698c63fd2ffdef5f3e1836bff94", features = ["client-api-c", "js", "rand", "unstable-msc2676", "unstable-msc2677"] }
vodozemac = { git = "https://github.com/matrix-org/vodozemac/", rev = "2404f83f7d3a3779c1f518e4d949f7da9677c3dd", features = ["js"] }
wasm-bindgen = "0.2.80"
wasm-bindgen-futures = "0.4.30"

View File

@@ -28,7 +28,7 @@ tracing = ["dep:tracing-subscriber"]
matrix-sdk-crypto = { version = "0.5.0", path = "../../crates/matrix-sdk-crypto" }
matrix-sdk-common = { version = "0.5.0", path = "../../crates/matrix-sdk-common" }
matrix-sdk-sled = { version = "0.1.0", path = "../../crates/matrix-sdk-sled", default-features = false, features = ["crypto-store"] }
ruma = { git = "https://github.com/ruma/ruma", rev = "7ec599e83d8ba6b2ace9e4fe184fc7560b0ff6ae", features = ["client-api-c", "rand", "unstable-msc2676", "unstable-msc2677"] }
ruma = { git = "https://github.com/ruma/ruma", rev = "da5def6731efd698c63fd2ffdef5f3e1836bff94", features = ["client-api-c", "rand", "unstable-msc2676", "unstable-msc2677"] }
vodozemac = { git = "https://github.com/matrix-org/vodozemac/", rev = "2404f83f7d3a3779c1f518e4d949f7da9677c3dd" }
napi = { git = "https://github.com/Hywan/napi-rs", branch = "fix-napi-strict-on-t-and-ref-t", default-features = false, features = ["napi6", "tokio_rt"] }
napi-derive = { git = "https://github.com/Hywan/napi-rs", branch = "fix-napi-strict-on-t-and-ref-t" }

View File

@@ -34,7 +34,7 @@ http = "0.2.6"
matrix-sdk = { version = "0.5.0", path = "../matrix-sdk", default-features = false, features = ["appservice"] }
percent-encoding = "2.1.0"
regex = "1.5.5"
ruma = { git = "https://github.com/ruma/ruma", rev = "7ec599e83d8ba6b2ace9e4fe184fc7560b0ff6ae", features = ["client-api-c", "appservice-api-s"] }
ruma = { git = "https://github.com/ruma/ruma", rev = "da5def6731efd698c63fd2ffdef5f3e1836bff94", features = ["client-api-c", "appservice-api-s"] }
serde = "1.0.136"
serde_json = "1.0.79"
serde_yaml = "0.8.23"

View File

@@ -43,10 +43,10 @@ tracing = "0.1.34"
zeroize = { version = "1.3.0", features = ["zeroize_derive"] }
[target.'cfg(target_arch = "wasm32")'.dependencies]
ruma = { git = "https://github.com/ruma/ruma", rev = "7ec599e83d8ba6b2ace9e4fe184fc7560b0ff6ae", features = ["client-api-c", "js", "canonical-json"] }
ruma = { git = "https://github.com/ruma/ruma", rev = "da5def6731efd698c63fd2ffdef5f3e1836bff94", features = ["client-api-c", "js", "canonical-json"] }
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
ruma = { git = "https://github.com/ruma/ruma", rev = "7ec599e83d8ba6b2ace9e4fe184fc7560b0ff6ae", features = ["client-api-c", "canonical-json"] }
ruma = { git = "https://github.com/ruma/ruma", rev = "da5def6731efd698c63fd2ffdef5f3e1836bff94", features = ["client-api-c", "canonical-json"] }
[dev-dependencies]
futures = { version = "0.3.21", default-features = false, features = ["executor"] }

View File

@@ -16,7 +16,7 @@ default-target = "x86_64-unknown-linux-gnu"
targets = ["x86_64-unknown-linux-gnu", "wasm32-unknown-unknown"]
[dependencies]
ruma = { git = "https://github.com/ruma/ruma", rev = "7ec599e83d8ba6b2ace9e4fe184fc7560b0ff6ae", features = ["client-api-c"] }
ruma = { git = "https://github.com/ruma/ruma", rev = "da5def6731efd698c63fd2ffdef5f3e1836bff94", features = ["client-api-c"] }
serde = "1.0.136"
[target.'cfg(target_arch = "wasm32")'.dependencies]

View File

@@ -51,11 +51,11 @@ zeroize = { version = "1.3.0", features = ["zeroize_derive"] }
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
tokio = { version = "1.18", default-features = false, features = ["time"] }
ruma = { git = "https://github.com/ruma/ruma", rev = "7ec599e83d8ba6b2ace9e4fe184fc7560b0ff6ae", features = ["client-api-c", "rand", "canonical-json", "unstable-msc2676", "unstable-msc2677"] }
ruma = { git = "https://github.com/ruma/ruma", rev = "da5def6731efd698c63fd2ffdef5f3e1836bff94", features = ["client-api-c", "rand", "canonical-json", "unstable-msc2676", "unstable-msc2677"] }
vodozemac = { git = "https://github.com/matrix-org/vodozemac/", rev = "2404f83f7d3a3779c1f518e4d949f7da9677c3dd" }
[target.'cfg(target_arch = "wasm32")'.dependencies]
ruma = { git = "https://github.com/ruma/ruma", rev = "7ec599e83d8ba6b2ace9e4fe184fc7560b0ff6ae", features = ["client-api-c", "js", "rand", "canonical-json", "unstable-msc2676", "unstable-msc2677"] }
ruma = { git = "https://github.com/ruma/ruma", rev = "da5def6731efd698c63fd2ffdef5f3e1836bff94", features = ["client-api-c", "js", "rand", "canonical-json", "unstable-msc2676", "unstable-msc2677"] }
vodozemac = { git = "https://github.com/matrix-org/vodozemac/", rev = "2404f83f7d3a3779c1f518e4d949f7da9677c3dd", features = ["js"] }
[dev-dependencies]

View File

@@ -29,7 +29,7 @@ indexed_db_futures = "0.2.3"
matrix-sdk-base = { version = "0.5.0", path = "../matrix-sdk-base" }
matrix-sdk-crypto = { version = "0.5.0", path = "../matrix-sdk-crypto", optional = true }
matrix-sdk-store-encryption = { version = "0.1.0", path = "../matrix-sdk-store-encryption" }
ruma = { git = "https://github.com/ruma/ruma", rev = "7ec599e83d8ba6b2ace9e4fe184fc7560b0ff6ae" }
ruma = { git = "https://github.com/ruma/ruma", rev = "da5def6731efd698c63fd2ffdef5f3e1836bff94" }
serde = "1.0.136"
serde_json = "1.0.79"
thiserror = "1.0.30"

View File

@@ -25,7 +25,7 @@ byteorder = "1.4.3"
image = { version = "0.23.0", optional = true }
qrcode = { version = "0.12.0", default-features = false }
rqrr = { version = "0.4.0", optional = true }
ruma-common = { git = "https://github.com/ruma/ruma", rev = "7ec599e83d8ba6b2ace9e4fe184fc7560b0ff6ae" }
ruma-common = { git = "https://github.com/ruma/ruma", rev = "da5def6731efd698c63fd2ffdef5f3e1836bff94" }
thiserror = "1.0.30"
[dependencies.vodozemac]

View File

@@ -37,7 +37,7 @@ matrix-sdk-base = { version = "0.5.0", path = "../matrix-sdk-base", optional = t
matrix-sdk-common = { version = "0.5.0", path = "../matrix-sdk-common" }
matrix-sdk-crypto = { version = "0.5.0", path = "../matrix-sdk-crypto", optional = true }
matrix-sdk-store-encryption = { version = "0.1.0", path = "../matrix-sdk-store-encryption" }
ruma = { git = "https://github.com/ruma/ruma", rev = "7ec599e83d8ba6b2ace9e4fe184fc7560b0ff6ae" }
ruma = { git = "https://github.com/ruma/ruma", rev = "da5def6731efd698c63fd2ffdef5f3e1836bff94" }
serde = "1.0.136"
serde_json = "1.0.79"
sled = "0.34.7"

View File

@@ -18,6 +18,6 @@ appservice = []
http = "0.2.6"
matrix-sdk-test-macros = { version = "0.2.0", path = "../matrix-sdk-test-macros" }
once_cell = "1.10.0"
ruma = { git = "https://github.com/ruma/ruma", rev = "7ec599e83d8ba6b2ace9e4fe184fc7560b0ff6ae", features = ["client-api-c"] }
ruma = { git = "https://github.com/ruma/ruma", rev = "da5def6731efd698c63fd2ffdef5f3e1836bff94", features = ["client-api-c"] }
serde = "1.0.136"
serde_json = "1.0.79"

View File

@@ -110,12 +110,12 @@ default_features = false
[dependencies.ruma]
git = "https://github.com/ruma/ruma"
rev = "7ec599e83d8ba6b2ace9e4fe184fc7560b0ff6ae"
rev = "da5def6731efd698c63fd2ffdef5f3e1836bff94"
features = ["client-api-c", "compat", "rand", "unstable-msc2448"]
[dependencies.ruma-client-api]
git = "https://github.com/ruma/ruma"
rev = "7ec599e83d8ba6b2ace9e4fe184fc7560b0ff6ae"
rev = "da5def6731efd698c63fd2ffdef5f3e1836bff94"
features = ["unstable-msc2965"]
[dependencies.tokio-stream]

View File

@@ -176,7 +176,7 @@ impl Common {
/// # let homeserver = Url::parse("http://example.com").unwrap();
/// # use futures::executor::block_on;
/// # block_on(async {
/// let request = MessagesOptions::backward("t47429-4392820_219380_26003_2265");
/// let request = MessagesOptions::backward_from("t47429-4392820_219380_26003_2265");
///
/// let mut client = Client::new(homeserver).await.unwrap();
/// let room = client
@@ -461,7 +461,7 @@ impl Common {
let filter = assign!(RoomEventFilter::default(), {
lazy_load_options: LazyLoadOptions::Enabled { include_redundant_members: false },
});
let options = assign!(MessagesOptions::backward(token), {
let options = assign!(MessagesOptions::backward_from(token), {
limit: uint!(10),
filter,
});
@@ -1074,7 +1074,7 @@ impl Common {
/// Options for [`messages`][Common::messages].
///
/// See that method for details.
/// See that method and <https://spec.matrix.org/v1.3/client-server-api/#get_matrixclientv3roomsroomidmessages> for details.
#[derive(Debug)]
#[non_exhaustive]
pub struct MessagesOptions<'a> {
@@ -1083,7 +1083,11 @@ pub struct MessagesOptions<'a> {
/// This token can be obtained from a `prev_batch` token returned for each
/// room from the sync API, or from a start or end token returned by a
/// previous `messages` call.
pub from: &'a str,
///
/// If `from` isn't provided the homeserver shall return a list of messages
/// from the first or last (per the value of the dir parameter) visible
/// event in the room history for the requesting user.
pub from: Option<&'a str>,
/// The token to stop returning events at.
///
@@ -1105,27 +1109,40 @@ pub struct MessagesOptions<'a> {
}
impl<'a> MessagesOptions<'a> {
/// Creates `MessagesOptions` with the given start token and direction.
/// Creates `MessagesOptions` with the given direction.
///
/// All other parameters will be defaulted.
pub fn new(from: &'a str, dir: Direction) -> Self {
Self { from, to: None, dir, limit: uint!(10), filter: RoomEventFilter::default() }
pub fn new(dir: Direction) -> Self {
Self { from: None, to: None, dir, limit: uint!(10), filter: RoomEventFilter::default() }
}
/// Creates `MessagesOptions` with the given optional start token, and `dir`
/// set to `Backward`.
pub fn backward(from: Option<&'a str>) -> Self {
assign!(Self::new(Direction::Backward), { from })
}
/// Creates `MessagesOptions` with the given start token, and `dir` set to
/// `Backward`.
pub fn backward(from: &'a str) -> Self {
Self::new(from, Direction::Backward)
pub fn backward_from(from: &'a str) -> Self {
Self::backward(Some(from))
}
/// Creates `MessagesOptions` with the given optional start token, and `dir`
/// set to `Forward`.
pub fn forward(from: Option<&'a str>) -> Self {
assign!(Self::new(Direction::Forward), { from })
}
/// Creates `MessagesOptions` with the given start token, and `dir` set to
/// `Forward`.
pub fn forward(from: &'a str) -> Self {
Self::new(from, Direction::Forward)
pub fn forward_from(from: &'a str) -> Self {
Self::forward(Some(from))
}
fn into_request(self, room_id: &'a RoomId) -> get_message_events::v3::Request<'_> {
assign!(get_message_events::v3::Request::new(room_id, Some(self.from), self.dir), {
assign!(get_message_events::v3::Request::new(room_id, self.dir), {
from: self.from,
to: self.to,
limit: self.limit,
filter: self.filter,

View File

@@ -10,7 +10,7 @@ clap = "3.2.4"
futures = { version = "0.3.21", default-features = false, features = ["executor"] }
matrix-sdk-base = { path = "../../crates/matrix-sdk-base", version = "0.5.0" }
matrix-sdk-sled = { path = "../../crates/matrix-sdk-sled", version = "0.1.0" }
ruma = { git = "https://github.com/ruma/ruma", rev = "7ec599e83d8ba6b2ace9e4fe184fc7560b0ff6ae" }
ruma = { git = "https://github.com/ruma/ruma", rev = "da5def6731efd698c63fd2ffdef5f3e1836bff94" }
rustyline = "9.1.2"
rustyline-derive = "0.6.0"
serde = "1.0.136"