Skip to content

Commit 773e712

Browse files
committed
Merge branch 'main' into feat-sdk-sliding-sync-types
2 parents 770d43f + d9b2b53 commit 773e712

File tree

42 files changed

+486
-172
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+486
-172
lines changed

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ ruma = { git = "https://github.com/matrix-org/ruma", branch = "feat-sss", featur
5353
"compat-encrypted-stickers",
5454
"unstable-msc3401",
5555
"unstable-msc3266",
56-
"unstable-msc4075"
56+
"unstable-msc4075",
57+
"unstable-msc4140",
5758
] }
5859
ruma-common = { git = "https://github.com/matrix-org/ruma", branch = "feat-sss" }
5960
serde = "1.0.151"
@@ -67,6 +68,7 @@ tokio = { version = "1.30.0", default-features = false, features = ["sync"] }
6768
tokio-stream = "0.1.14"
6869
tracing = { version = "0.1.40", default-features = false, features = ["std"] }
6970
tracing-core = "0.1.32"
71+
tracing-subscriber = "0.3.18"
7072
uniffi = { version = "0.27.1" }
7173
uniffi_bindgen = { version = "0.27.1" }
7274
url = "2.5.0"

benchmarks/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ ruma = { workspace = true }
1818
serde = { workspace = true }
1919
serde_json = { workspace = true }
2020
tempfile = "3.3.0"
21-
tokio = { version = "1.24.2", default-features = false, features = ["rt-multi-thread"] }
21+
tokio = { workspace = true, default-features = false, features = ["rt-multi-thread"] }
2222

2323
[target.'cfg(target_os = "linux")'.dependencies]
2424
pprof = { version = "0.13.0", features = ["flamegraph", "criterion"] }

bindings/matrix-sdk-crypto-ffi/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ bundled-sqlite = ["matrix-sdk-sqlite/bundled"]
2222

2323
[dependencies]
2424
anyhow = { workspace = true }
25-
futures-util = "0.3.28"
25+
futures-util = { workspace = true }
2626
hmac = "0.12.1"
2727
http = { workspace = true }
2828
matrix-sdk-common = { workspace = true }
@@ -33,7 +33,7 @@ serde = { workspace = true }
3333
serde_json = { workspace = true }
3434
sha2 = { workspace = true }
3535
thiserror = { workspace = true }
36-
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
36+
tracing-subscriber = { workspace = true, features = ["env-filter"] }
3737
# keep in sync with uniffi dependency in matrix-sdk-ffi, and uniffi_bindgen in ffi CI job
3838
uniffi = { workspace = true , features = ["cli"]}
3939
vodozemac = { workspace = true }

bindings/matrix-sdk-ffi/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ serde_json = { workspace = true }
3838
thiserror = { workspace = true }
3939
tracing = { workspace = true }
4040
tracing-core = { workspace = true }
41-
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
41+
tracing-subscriber = { workspace = true, features = ["env-filter"] }
4242
tracing-appender = { version = "0.2.2" }
43-
tokio = { version = "1", features = ["rt-multi-thread", "macros"] }
43+
tokio = { workspace = true, features = ["rt-multi-thread", "macros"] }
4444
uniffi = { workspace = true, features = ["tokio"] }
4545
url = { workspace = true }
4646
zeroize = { workspace = true }

bindings/matrix-sdk-ffi/src/timeline/mod.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use matrix_sdk::{
2424
AttachmentConfig, AttachmentInfo, BaseAudioInfo, BaseFileInfo, BaseImageInfo,
2525
BaseThumbnailInfo, BaseVideoInfo, Thumbnail,
2626
},
27+
deserialized_responses::ShieldState as RustShieldState,
2728
Error,
2829
};
2930
use matrix_sdk_ui::timeline::{
@@ -922,6 +923,30 @@ impl From<&matrix_sdk_ui::timeline::EventSendState> for EventSendState {
922923
}
923924
}
924925

926+
/// Recommended decorations for decrypted messages, representing the message's
927+
/// authenticity properties.
928+
#[derive(uniffi::Enum)]
929+
pub enum ShieldState {
930+
/// A red shield with a tooltip containing the associated message should be
931+
/// presented.
932+
Red { message: String },
933+
/// A grey shield with a tooltip containing the associated message should be
934+
/// presented.
935+
Grey { message: String },
936+
/// No shield should be presented.
937+
None,
938+
}
939+
940+
impl From<RustShieldState> for ShieldState {
941+
fn from(value: RustShieldState) -> Self {
942+
match value {
943+
RustShieldState::Red { message } => Self::Red { message: message.to_owned() },
944+
RustShieldState::Grey { message } => Self::Grey { message: message.to_owned() },
945+
RustShieldState::None => Self::None,
946+
}
947+
}
948+
}
949+
925950
#[derive(uniffi::Object)]
926951
pub struct EventTimelineItem(pub(crate) matrix_sdk_ui::timeline::EventTimelineItem);
927952

@@ -1008,6 +1033,12 @@ impl EventTimelineItem {
10081033
pub fn can_be_replied_to(&self) -> bool {
10091034
self.0.can_be_replied_to()
10101035
}
1036+
1037+
/// Gets the [`ShieldState`] which can be used to decorate messages in the
1038+
/// recommended way.
1039+
pub fn get_shield(&self, strict: bool) -> Option<ShieldState> {
1040+
self.0.get_shield(strict).map(Into::into)
1041+
}
10111042
}
10121043

10131044
#[derive(uniffi::Record)]

crates/matrix-sdk-common/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ futures-util = { workspace = true, features = ["channel"] }
3434
wasm-bindgen-futures = { version = "0.4.33", optional = true }
3535
gloo-timers = { version = "0.3.0", features = ["futures"] }
3636
web-sys = { version = "0.3.60", features = ["console"] }
37-
tracing-subscriber = { version = "0.3.14", default-features = false, features = ["fmt", "ansi"] }
37+
tracing-subscriber = { workspace = true, features = ["fmt", "ansi"] }
3838
wasm-bindgen = "0.2.84"
3939

4040
[dev-dependencies]

crates/matrix-sdk-indexeddb/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ matrix-sdk-common = { workspace = true, features = ["js"] }
5555
matrix-sdk-crypto = { workspace = true, features = ["js", "testing"] }
5656
matrix-sdk-test = { workspace = true }
5757
rand = { workspace = true }
58-
tracing-subscriber = { version = "0.3.18", default-features = false, features = ["registry", "tracing-log"] }
58+
tracing-subscriber = { workspace = true, features = ["registry", "tracing-log"] }
5959
uuid = "1.3.0"
6060
wasm-bindgen-test = "0.3.33"
6161

crates/matrix-sdk-ui/src/timeline/event_handler.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ pub(super) enum Flow {
8787
raw_event: Raw<AnySyncTimelineEvent>,
8888
/// Where should this be added in the timeline.
8989
position: TimelineItemPosition,
90+
/// Information about the encryption for this event.
91+
encryption_info: Option<EncryptionInfo>,
9092
/// Should this event actually be added, based on the event filters.
9193
should_add: bool,
9294
},
@@ -98,7 +100,6 @@ pub(super) struct TimelineEventContext {
98100
pub(super) sender_profile: Option<Profile>,
99101
pub(super) timestamp: MilliSecondsSinceUnixEpoch,
100102
pub(super) is_own_event: bool,
101-
pub(super) encryption_info: Option<EncryptionInfo>,
102103
pub(super) read_receipts: IndexMap<OwnedUserId, Receipt>,
103104
pub(super) is_highlighted: bool,
104105
pub(super) flow: Flow,
@@ -891,7 +892,7 @@ impl<'a, 'o> TimelineEventHandler<'a, 'o> {
891892
}
892893
.into(),
893894

894-
Flow::Remote { event_id, raw_event, position, txn_id, .. } => {
895+
Flow::Remote { event_id, raw_event, position, txn_id, encryption_info, .. } => {
895896
// Drop pending reactions if the message is redacted.
896897
if let TimelineItemContent::RedactedMessage = content {
897898
if !reactions.is_empty() {
@@ -921,7 +922,7 @@ impl<'a, 'o> TimelineEventHandler<'a, 'o> {
921922
read_receipts: self.ctx.read_receipts.clone(),
922923
is_own: self.ctx.is_own_event,
923924
is_highlighted: self.ctx.is_highlighted,
924-
encryption_info: self.ctx.encryption_info.clone(),
925+
encryption_info: encryption_info.clone(),
925926
original_json: Some(raw_event.clone()),
926927
latest_edit_json: None,
927928
origin,

crates/matrix-sdk-ui/src/timeline/event_item/mod.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ use std::sync::Arc;
1616

1717
use as_variant::as_variant;
1818
use indexmap::IndexMap;
19-
use matrix_sdk::{deserialized_responses::EncryptionInfo, Client, Error};
19+
use matrix_sdk::{
20+
deserialized_responses::{EncryptionInfo, ShieldState},
21+
Client, Error,
22+
};
2023
use matrix_sdk_base::{deserialized_responses::SyncTimelineEvent, latest_event::LatestEvent};
2124
use once_cell::sync::Lazy;
2225
use ruma::{
@@ -335,6 +338,18 @@ impl EventTimelineItem {
335338
}
336339
}
337340

341+
/// Gets the [`ShieldState`] which can be used to decorate messages in the
342+
/// recommended way.
343+
pub fn get_shield(&self, strict: bool) -> Option<ShieldState> {
344+
self.encryption_info().map(|info| {
345+
if strict {
346+
info.verification_state.to_shield_state_strict()
347+
} else {
348+
info.verification_state.to_shield_state_lax()
349+
}
350+
})
351+
}
352+
338353
/// Check whether this item can be replied to.
339354
pub fn can_be_replied_to(&self) -> bool {
340355
// This must be in sync with the early returns of `Timeline::send_reply`

crates/matrix-sdk-ui/src/timeline/inner/state.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,6 @@ impl TimelineInnerState {
171171
sender_profile: own_profile,
172172
timestamp: MilliSecondsSinceUnixEpoch::now(),
173173
is_own_event: true,
174-
// FIXME: Should we supply something here for encrypted rooms?
175-
encryption_info: None,
176174
read_receipts: Default::default(),
177175
// An event sent by ourself is never matched against push rules.
178176
is_highlighted: false,
@@ -557,7 +555,6 @@ impl TimelineInnerStateTransaction<'_> {
557555
sender_profile,
558556
timestamp,
559557
is_own_event,
560-
encryption_info: event.encryption_info,
561558
read_receipts: if settings.track_read_receipts && should_add {
562559
self.meta.read_receipts.compute_event_receipts(
563560
&event_id,
@@ -571,6 +568,7 @@ impl TimelineInnerStateTransaction<'_> {
571568
flow: Flow::Remote {
572569
event_id: event_id.clone(),
573570
raw_event: raw.clone(),
571+
encryption_info: event.encryption_info,
574572
txn_id,
575573
position,
576574
should_add,

crates/matrix-sdk/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ Additions:
3535
- Add `send_call_notification` and `send_call_notification_if_needed` methods. This allows to implement sending ring events on call start.
3636
- The `get_media_content`, `get_media_file` and `get_file` methods of the
3737
`Media` api now support the new authenticated media endpoints.
38+
- WidgetDriver: Support the `"future_timeout"` and `"future_group_id"` fields in the `send_event` widget actions.
39+
This allows to send future events, as defined in [MSC4157](https://github.com/matrix-org/matrix-spec-proposals/pull/4157)
3840

3941
# 0.7.0
4042

crates/matrix-sdk/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ once_cell = { workspace = true }
149149
serde_urlencoded = "0.7.1"
150150
similar-asserts = { workspace = true }
151151
stream_assert = { workspace = true }
152-
tracing-subscriber = { version = "0.3.11", features = ["env-filter"] }
152+
tracing-subscriber = { workspace = true, features = ["env-filter"] }
153153

154154
[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
155155
wasm-bindgen-test = "0.3.33"

crates/matrix-sdk/src/event_cache/mod.rs

Lines changed: 77 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ use matrix_sdk_common::executor::{spawn, JoinHandle};
5656
use ruma::{
5757
events::{AnyRoomAccountDataEvent, AnySyncEphemeralRoomEvent},
5858
serde::Raw,
59-
OwnedEventId, OwnedRoomId, RoomId,
59+
EventId, OwnedEventId, OwnedRoomId, RoomId,
6060
};
6161
use tokio::sync::{
6262
broadcast::{error::RecvError, Receiver, Sender},
@@ -196,6 +196,23 @@ impl EventCache {
196196
Ok(())
197197
}
198198

199+
/// Try to find an event by its ID in all the rooms.
200+
// NOTE: this does a linear scan, so it could be slow. If performance
201+
// requires it, we could use a direct mapping of event id -> event, and keep it
202+
// in memory until we store it on disk (and this becomes a SQL query by id).
203+
pub async fn event(&self, event_id: &EventId) -> Option<SyncTimelineEvent> {
204+
let by_room = self.inner.by_room.read().await;
205+
for room in by_room.values() {
206+
let events = room.inner.events.read().await;
207+
for (_pos, event) in events.revents() {
208+
if event.event_id().as_deref() == Some(event_id) {
209+
return Some(event.clone());
210+
}
211+
}
212+
}
213+
None
214+
}
215+
199216
#[instrument(skip_all)]
200217
async fn ignore_user_list_update_task(
201218
inner: Arc<EventCacheInner>,
@@ -759,13 +776,13 @@ pub enum EventsOrigin {
759776
mod tests {
760777
use assert_matches2::assert_matches;
761778
use futures_util::FutureExt as _;
762-
use matrix_sdk_base::sync::JoinedRoomUpdate;
779+
use matrix_sdk_base::sync::{JoinedRoomUpdate, RoomUpdates, Timeline};
763780
use matrix_sdk_test::async_test;
764-
use ruma::{room_id, serde::Raw};
781+
use ruma::{event_id, room_id, serde::Raw, user_id};
765782
use serde_json::json;
766783

767784
use super::{EventCacheError, RoomEventCacheUpdate};
768-
use crate::test_utils::logged_in_client;
785+
use crate::test_utils::{assert_event_matches_msg, events::EventFactory, logged_in_client};
769786

770787
#[async_test]
771788
async fn test_must_explicitly_subscribe() {
@@ -828,4 +845,60 @@ mod tests {
828845

829846
assert!(stream.recv().now_or_never().is_none());
830847
}
848+
849+
#[async_test]
850+
async fn test_get_event_by_id() {
851+
let client = logged_in_client(None).await;
852+
let room1 = room_id!("!galette:saucisse.bzh");
853+
let room2 = room_id!("!crepe:saucisse.bzh");
854+
855+
let event_cache = client.event_cache();
856+
event_cache.subscribe().unwrap();
857+
858+
// Insert two rooms with a few events.
859+
let f = EventFactory::new().room(room1).sender(user_id!("@ben:saucisse.bzh"));
860+
861+
let eid1 = event_id!("$1");
862+
let eid2 = event_id!("$2");
863+
let eid3 = event_id!("$3");
864+
865+
let joined_room_update1 = JoinedRoomUpdate {
866+
timeline: Timeline {
867+
events: vec![
868+
f.text_msg("hey").event_id(eid1).into(),
869+
f.text_msg("you").event_id(eid2).into(),
870+
],
871+
..Default::default()
872+
},
873+
..Default::default()
874+
};
875+
876+
let joined_room_update2 = JoinedRoomUpdate {
877+
timeline: Timeline {
878+
events: vec![f.text_msg("bjr").event_id(eid3).into()],
879+
..Default::default()
880+
},
881+
..Default::default()
882+
};
883+
884+
let mut updates = RoomUpdates::default();
885+
updates.join.insert(room1.to_owned(), joined_room_update1);
886+
updates.join.insert(room2.to_owned(), joined_room_update2);
887+
888+
// Have the event cache handle them.
889+
event_cache.inner.handle_room_updates(updates).await.unwrap();
890+
891+
// Now retrieve all the events one by one.
892+
let found1 = event_cache.event(eid1).await.unwrap();
893+
assert_event_matches_msg(&found1, "hey");
894+
895+
let found2 = event_cache.event(eid2).await.unwrap();
896+
assert_event_matches_msg(&found2, "you");
897+
898+
let found3 = event_cache.event(eid3).await.unwrap();
899+
assert_event_matches_msg(&found3, "bjr");
900+
901+
// An unknown event won't be found.
902+
assert!(event_cache.event(event_id!("$unknown")).await.is_none());
903+
}
831904
}

0 commit comments

Comments
 (0)