Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sliding Sync timeline events and extensions #1054

Merged
merged 29 commits into from
Oct 25, 2022
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
80d2dd5
feat(sliding-sync): Update to sliding-sync extension system
gnunicorn Sep 19, 2022
51c756e
feat: Adding support for e2ee, account-data and to-device-message ext…
gnunicorn Sep 19, 2022
e1f4e00
feat(sliding-sync): Extension configuration on the SlidingSync builder
gnunicorn Sep 19, 2022
7a9eec5
feat(sliding-sync): timeline event items support
gnunicorn Sep 19, 2022
37e4374
fix(sliding-sync): minor fixes for common extensions
gnunicorn Sep 19, 2022
a892e79
feat(sliding-sync): expose common extensions builder over ffi
gnunicorn Sep 19, 2022
ee15ef5
fix(sliding-sync): Update to latest ruma
gnunicorn Sep 20, 2022
97d66f7
fix(sliding-sync): proper e2ee encryption requests sending and handling
gnunicorn Sep 20, 2022
f763fad
fix(sliding-sync): process even if no room-data is present
gnunicorn Sep 21, 2022
2391093
fix(sliding-sync): switch to ruma 0.7.4
gnunicorn Sep 22, 2022
030b10c
fix: code simplification
gnunicorn Sep 22, 2022
cb191c9
fix: update styles, clippy and tests for api changes
gnunicorn Sep 22, 2022
5bd9ad9
test(crypto-js): `receive_sync_changes` has changed its signature.
Hywan Sep 22, 2022
8df3472
Merge remote-tracking branch 'origin/main' into ben-sliding-sync-exte…
gnunicorn Sep 22, 2022
3c86d44
Merge remote-tracking branch 'Hywan/pr/1054-errata' into ben-sliding-…
gnunicorn Sep 22, 2022
7e4e390
feat(jack-in): login and permanent storage support
gnunicorn Sep 27, 2022
3caf083
Merge remote-tracking branch 'origin/main' into ben-sliding-sync-exte…
gnunicorn Oct 12, 2022
87e641e
fix: post-merge error reverted
gnunicorn Oct 12, 2022
f77a66e
refactor: reuse to_device events preprocessing
gnunicorn Oct 12, 2022
38decab
feat(jack-in): runtime log configuration support via -l
gnunicorn Oct 13, 2022
a69fee3
Merge remote-tracking branch 'origin/main' into ben-sliding-sync-exte…
gnunicorn Oct 13, 2022
f8031e2
docs: fix CLI docs
gnunicorn Oct 13, 2022
be2bd63
Merge remote-tracking branch 'origin/main' into ben-sliding-sync-exte…
gnunicorn Oct 17, 2022
46ebc48
test(crypto): update to latest API
gnunicorn Oct 17, 2022
d2cd7c9
style(jack-in): fix minor formatting issues
gnunicorn Oct 17, 2022
b6d1429
style(jack-in): improve code quality
gnunicorn Oct 17, 2022
ea15c2e
fix(jack-in): file-logging feature builds again
gnunicorn Oct 20, 2022
9616653
Merge remote-tracking branch 'origin/main' into ben-sliding-sync-exte…
gnunicorn Oct 25, 2022
773b587
feat: Handle decrypted and deserialized timeline events in sliding sync
gnunicorn Oct 25, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 10 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ debug = 0
# for the extra time of optimizing it for a clean build of matrix-sdk-ffi.
quote = { opt-level = 2 }
sha2 = { opt-level = 2 }

[patch.crates-io]
ruma = { git = "https://github.com/gnunicorn/ruma", branch = "ben-update-sliding-sync"}
ruma-common = { git = "https://github.com/gnunicorn/ruma", branch = "ben-update-sliding-sync"}
2 changes: 1 addition & 1 deletion bindings/matrix-sdk-crypto-ffi/src/responses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use ruma::{
},
},
message::send_message_event::v3::Response as RoomMessageResponse,
sync::sync_events::v3::DeviceLists as RumaDeviceLists,
sync::sync_events::DeviceLists as RumaDeviceLists,
to_device::send_event_to_device::v3::Response as ToDeviceResponse,
},
assign,
Expand Down
4 changes: 2 additions & 2 deletions bindings/matrix-sdk-crypto-js/src/sync_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{downcast, identifiers};
#[wasm_bindgen]
#[derive(Debug)]
pub struct DeviceLists {
pub(crate) inner: ruma::api::client::sync::sync_events::v3::DeviceLists,
pub(crate) inner: ruma::api::client::sync::sync_events::DeviceLists,
gnunicorn marked this conversation as resolved.
Show resolved Hide resolved
}

#[wasm_bindgen]
Expand All @@ -19,7 +19,7 @@ impl DeviceLists {
/// `changed` and `left` must be an array of `UserId`.
#[wasm_bindgen(constructor)]
pub fn new(changed: Option<Array>, left: Option<Array>) -> Result<DeviceLists, JsError> {
let mut inner = ruma::api::client::sync::sync_events::v3::DeviceLists::default();
let mut inner = ruma::api::client::sync::sync_events::DeviceLists::default();

inner.changed = changed
.unwrap_or_default()
Expand Down
4 changes: 2 additions & 2 deletions bindings/matrix-sdk-crypto-nodejs/src/sync_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::identifiers;
/// Information on E2E device updates.
#[napi]
pub struct DeviceLists {
pub(crate) inner: ruma::api::client::sync::sync_events::v3::DeviceLists,
pub(crate) inner: ruma::api::client::sync::sync_events::DeviceLists,
}

#[napi]
Expand All @@ -18,7 +18,7 @@ impl DeviceLists {
changed: Option<Vec<&identifiers::UserId>>,
left: Option<Vec<&identifiers::UserId>>,
) -> Self {
let mut inner = ruma::api::client::sync::sync_events::v3::DeviceLists::default();
let mut inner = ruma::api::client::sync::sync_events::DeviceLists::default();

inner.changed = changed.into_iter().flatten().map(|user| user.inner.clone()).collect();
inner.left = left.into_iter().flatten().map(|user| user.inner.clone()).collect();
Expand Down
3 changes: 3 additions & 0 deletions bindings/matrix-sdk-ffi/src/api.udl
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@ interface SlidingSyncBuilder {
[Self=ByArc]
SlidingSyncBuilder add_view(SlidingSyncView view);

[Self=ByArc]
SlidingSyncBuilder with_common_extensions();

[Throws=ClientError, Self=ByArc]
SlidingSync build();
};
Expand Down
2 changes: 1 addition & 1 deletion bindings/matrix-sdk-ffi/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ impl Client {
&*session_verification_controller.read().await
{
session_verification_controller
.process_to_device_messages(sync_response.to_device)
.process_to_device_messages(sync_response.to_device_events)
.await;
}

Expand Down
6 changes: 3 additions & 3 deletions bindings/matrix-sdk-ffi/src/session_verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use matrix_sdk::{
verification::{SasVerification, VerificationRequest},
},
ruma::{
api::client::sync::sync_events::v3::ToDevice,
events::{key::verification::VerificationMethod, AnyToDeviceEvent},
serde::Raw,
},
};

Expand Down Expand Up @@ -105,10 +105,10 @@ impl SessionVerificationController {
})
}

pub async fn process_to_device_messages(&self, to_device: ToDevice) {
pub async fn process_to_device_messages(&self, to_device_events: Vec<Raw<AnyToDeviceEvent>>) {
let sas_verification = self.sas_verification.clone();

for event in to_device.events.into_iter().filter_map(|e| e.deserialize().ok()) {
for event in to_device_events.into_iter().filter_map(|e| e.deserialize().ok()) {
match event {
AnyToDeviceEvent::KeyVerificationReady(event) => {
if !self.is_transaction_id_valid(event.content.transaction_id.to_string()) {
Expand Down
6 changes: 6 additions & 0 deletions bindings/matrix-sdk-ffi/src/sliding_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,12 @@ impl SlidingSyncBuilder {
Arc::new(builder)
}

pub fn with_common_extensions(self: Arc<Self>) -> Arc<Self> {
let mut builder = unwrap_or_clone_arc(self);
builder.inner = builder.inner.with_common_extensions();
Arc::new(builder)
}

pub fn build(self: Arc<Self>) -> anyhow::Result<Arc<SlidingSync>> {
let builder = unwrap_or_clone_arc(self);
Ok(Arc::new(SlidingSync::new(builder.inner.build()?, builder.client)))
Expand Down
36 changes: 22 additions & 14 deletions crates/matrix-sdk-base/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,12 @@ impl BaseClient {
}

#[allow(clippy::too_many_arguments)]
async fn handle_timeline(
pub(crate) async fn handle_timeline(
&self,
room: &Room,
ruma_timeline: api::sync::sync_events::v3::Timeline,
limited: bool,
events: Vec<Raw<AnySyncTimelineEvent>>,
prev_batch: Option<String>,
push_rules: &Ruleset,
user_ids: &mut BTreeSet<OwnedUserId>,
room_info: &mut RoomInfo,
Expand All @@ -267,10 +269,10 @@ impl BaseClient {
) -> Result<Timeline> {
let room_id = room.room_id();
let user_id = room.own_user_id();
let mut timeline = Timeline::new(ruma_timeline.limited, ruma_timeline.prev_batch.clone());
let mut timeline = Timeline::new(limited, prev_batch);
let mut push_context = self.get_push_room_context(room, room_info, changes).await?;

for event in ruma_timeline.events {
for event in events {
#[allow(unused_mut)]
let mut event: SyncTimelineEvent = event.into();

Expand Down Expand Up @@ -502,7 +504,7 @@ impl BaseClient {
Ok(user_ids)
}

async fn handle_room_account_data(
pub(crate) async fn handle_room_account_data(
&self,
room_id: &RoomId,
events: &[Raw<AnyRoomAccountDataEvent>],
Expand All @@ -515,7 +517,7 @@ impl BaseClient {
}
}

async fn handle_account_data(
pub(crate) async fn handle_account_data(
&self,
events: &[Raw<AnyGlobalAccountDataEvent>],
changes: &mut StateChanges,
Expand Down Expand Up @@ -589,22 +591,24 @@ impl BaseClient {

let now = Instant::now();

let to_device_events = to_device.events;

#[cfg(feature = "e2e-encryption")]
let to_device = {
let to_device_events = {
if let Some(o) = self.olm_machine() {
// Let the crypto machine handle the sync response, this
// decrypts to-device events, but leaves room events alone.
// This makes sure that we have the decryption keys for the room
// events at hand.
o.receive_sync_changes(
to_device,
to_device_events,
&device_lists,
&device_one_time_keys_count,
device_unused_fallback_key_types.as_deref(),
)
.await?
} else {
to_device
to_device_events
}
};

Expand Down Expand Up @@ -650,7 +654,9 @@ impl BaseClient {
let timeline = self
.handle_timeline(
&room,
new_info.timeline,
new_info.timeline.limited,
new_info.timeline.events,
new_info.timeline.prev_batch,
&push_rules,
&mut user_ids,
&mut room_info,
Expand Down Expand Up @@ -701,7 +707,7 @@ impl BaseClient {
JoinedRoom::new(
timeline,
new_info.state,
new_info.account_data,
new_info.account_data.events,
new_info.ephemeral,
notification_count,
),
Expand All @@ -727,7 +733,9 @@ impl BaseClient {
let timeline = self
.handle_timeline(
&room,
new_info.timeline,
new_info.timeline.limited,
new_info.timeline.events,
new_info.timeline.prev_batch,
&push_rules,
&mut user_ids,
&mut room_info,
Expand Down Expand Up @@ -789,8 +797,8 @@ impl BaseClient {
next_batch,
rooms: new_rooms,
presence,
account_data,
to_device,
account_data: account_data.events,
to_device_events,
device_lists,
device_one_time_keys_count: device_one_time_keys_count
.into_iter()
Expand Down
Loading