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

feat(ui): Implement Notification API #2023

Merged
merged 23 commits into from
Jun 19, 2023

Conversation

bnjbvr
Copy link
Member

@bnjbvr bnjbvr commented Jun 6, 2023

This is the first PR for splitting the sync loop into two. This offers a new high-level API, NotificationApi, that makes use of a separate SlidingSync instance which sole role is to listen to to-device events and e2ee; it's pre-configured to do so. That means we're not force-enabling e2ee and to-device by default for every sliding sync instance, and as such we won't either generate Olm requests to the home server in general.

In the future, this new high-level API will hide some low-level dirty details so that its can be instantiated in multiple processes at the same time (lock across process, invalidate and refill crypto caches, etc.).

An embedder who would want to make use of this would need the following:

  • a main sliding sync instance, without e2ee and to-device. Using the matrix_sdk_ui::RoomList would be the best bet, at this time.
  • an instance of this matrix_sdk_ui::NotificationApi, with a different identifier.

Note that this is not ready to be used in an external process; or it will cause the same kind of issues that we're seeing as of today: invalid crypto caches resulting in UTD, etc.

This PR can be looked at, commit per commit, at the time of writing this.

Fixes #1961.

@bnjbvr bnjbvr requested a review from a team as a code owner June 6, 2023 17:25
@bnjbvr bnjbvr requested review from poljar and Hywan and removed request for a team June 6, 2023 17:25
@codecov
Copy link

codecov bot commented Jun 6, 2023

Codecov Report

Patch coverage: 88.57% and project coverage change: +0.05 🎉

Comparison is base (76ed351) 75.91% compared to head (62e39ac) 75.96%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2023      +/-   ##
==========================================
+ Coverage   75.91%   75.96%   +0.05%     
==========================================
  Files         152      153       +1     
  Lines       16725    16749      +24     
==========================================
+ Hits        12696    12723      +27     
+ Misses       4029     4026       -3     
Impacted Files Coverage Δ
crates/matrix-sdk-ui/src/notifications/mod.rs 84.21% <84.21%> (ø)
crates/matrix-sdk/src/sliding_sync/mod.rs 92.46% <90.00%> (+0.66%) ⬆️
crates/matrix-sdk-ui/src/room_list/mod.rs 89.47% <100.00%> (+0.28%) ⬆️
crates/matrix-sdk/src/sliding_sync/builder.rs 66.11% <100.00%> (+2.18%) ⬆️

... and 1 file with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Member

@Hywan Hywan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks generally good. Some minors stuff to update. We need to test this for real to see if it behaves as expected.

crates/matrix-sdk-ui/Cargo.toml Outdated Show resolved Hide resolved
crates/matrix-sdk-ui/src/notifications/mod.rs Outdated Show resolved Hide resolved
crates/matrix-sdk-ui/src/notifications/mod.rs Show resolved Hide resolved
crates/matrix-sdk-ui/src/notifications/mod.rs Outdated Show resolved Hide resolved
crates/matrix-sdk-ui/tests/integration/main.rs Outdated Show resolved Hide resolved
crates/matrix-sdk-ui/tests/integration/room_list.rs Outdated Show resolved Hide resolved
crates/matrix-sdk/src/sliding_sync/mod.rs Outdated Show resolved Hide resolved
@Hywan Hywan changed the title sliding sync: implement a NotificationApi feat(ui): Implement Notification Jun 7, 2023
@bnjbvr bnjbvr force-pushed the split-sync-loop-take-3 branch 3 times, most recently from 1dbddde to 9decb06 Compare June 8, 2023 10:32
@bnjbvr bnjbvr changed the title feat(ui): Implement Notification feat(ui): Implement Notification API Jun 8, 2023
bnjbvr added 13 commits June 12, 2023 14:21
…evice events

Signed-off-by: Benjamin Bouvier <public@benj.me>
Signed-off-by: Benjamin Bouvier <public@benj.me>
…nsion

Signed-off-by: Benjamin Bouvier <public@benj.me>
… API testing

Signed-off-by: Benjamin Bouvier <public@benj.me>
Signed-off-by: Benjamin Bouvier <public@benj.me>
Signed-off-by: Benjamin Bouvier <public@benj.me>
Signed-off-by: Benjamin Bouvier <public@benj.me>
Signed-off-by: Benjamin Bouvier <public@benj.me>
Signed-off-by: Benjamin Bouvier <public@benj.me>
Too cute? :)

Signed-off-by: Benjamin Bouvier <public@benj.me>
…loop terminates

Signed-off-by: Benjamin Bouvier <public@benj.me>
…n sync loop

This makes sure that we `sync()` the notification sync loop only once.

Signed-off-by: Benjamin Bouvier <public@benj.me>
Signed-off-by: Benjamin Bouvier <public@benj.me>
Signed-off-by: Benjamin Bouvier <public@benj.me>
Signed-off-by: Benjamin Bouvier <public@benj.me>
Signed-off-by: Benjamin Bouvier <public@benj.me>
@bnjbvr
Copy link
Member Author

bnjbvr commented Jun 13, 2023

The macro used in the RoomList and Notification integration testing now supports sticky parameters \o/

  • The mocked server will parrot the txn_id provided in the request, so that sticky parameters are validated.
  • Before checking the response matches what we expect, we strip the txn_id from the response, as it's been auto-generated it's not possible to include it in the expected side of the assertion.

Signed-off-by: Benjamin Bouvier <public@benj.me>
@bnjbvr bnjbvr requested a review from Hywan June 13, 2023 14:35
Copy link
Member

@Hywan Hywan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm all good, I just want to check again the RoomList modification, esp. on the test suite :-).

crates/matrix-sdk-ui/src/notifications/mod.rs Outdated Show resolved Hide resolved
///
/// See the module's documentation for more details.
#[derive(Clone)]
pub struct NotificationSync {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about E2EESync or EncryptionSync? Because as far as I understand it, it has very little to do with notifications so far, except the lock maybe?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, I've also discussed with other people and thought about EncryptionSync, so let's go with that!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And if that's alright, I'd rather do it in the next PR, to not mess up too much with my rebase 😅

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK!

crates/matrix-sdk-ui/src/notifications/mod.rs Outdated Show resolved Hide resolved
Comment on lines 271 to 281
"e2ee": {
"enabled": true,
},
"to_device": {
"enabled": true,
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's wrong, we should have those :-).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noooo! ... or maybe, you're right, at least on Android :-)

On iOS, the main app will use both the RoomList and EncryptionSync, so the RoomList on iOS mustn't have these two extensions. Maybe we could make it a parameter in the room list ctor? Or have Android spawn both too, at least for symmetry with iOS? (and so it gets some of other benefits: e2ee not being blocked by processing of lists on the ss proxy, etc.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, let's keep this as is for now :-). Sorry for the confusion!

"lists": {
ALL_ROOMS: {
"ranges": [
[0, 49],
],
"timeline_limit": 1,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove this one?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added support for sticky parameters in the test macro, and this one is sticky, so it's not reemitted in the next request, since it's the same :)

Signed-off-by: Benjamin Bouvier <public@benj.me>
@bnjbvr bnjbvr requested a review from Hywan June 16, 2023 14:49
Signed-off-by: Benjamin Bouvier <public@benj.me>
///
/// See the module's documentation for more details.
#[derive(Clone)]
pub struct NotificationSync {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK!

Comment on lines 271 to 281
"e2ee": {
"enabled": true,
},
"to_device": {
"enabled": true,
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, let's keep this as is for now :-). Sorry for the confusion!

Signed-off-by: Benjamin Bouvier <public@benj.me>
@bnjbvr bnjbvr enabled auto-merge (squash) June 19, 2023 08:38
@bnjbvr bnjbvr merged commit 4d3ca15 into matrix-org:main Jun 19, 2023
47 checks passed
@bnjbvr bnjbvr deleted the split-sync-loop-take-3 branch June 19, 2023 08:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Split out the sliding sync loop into two loops
3 participants