Commit Graph

13223 Commits

Author SHA1 Message Date
Jonas Platte f7d52dfdc1 ffi: Make tracing more flexible
… at the expense of some performance.
2023-08-11 12:10:58 +02:00
Benjamin Bouvier 6e62569b8a feat(sync service): don't intertwine the state of both sliding syncs (#2362)
## Feature

There are now three tasks running in the sync service:

- the room list sliding sync task
- the encryption sync task
- a new scheduler task, that listens to messages sent by both of the previous tasks, and will take care of cleaning up tasks, stopping the services, and setting states after it received a message.

When any of the sliding sync fails, it sends a message to the scheduler task, indicating why it stopped (error or not, was it an expired session or not). Then the scheduler task will do any necessary cleanup.

`stop()` (née `pause()`) can now make use of that scheduler task as well, by sending a report requesting to stop both tasks and services. Responsibilities are now cleanly split: in particular, I like it much better that the room list task doesn't have to stop the encryption sync itself, since it's not really its duty. (And this avoids lots of code duplication to cleanup tasks and stop services.)

## Testing

This also tests the `SyncService` states. Unfortunately it's not perfectly deterministic in two places:

- we can't predict how many requests will be sent to the server (although, with the mocking server responding in 50ms, and considering a waiting time of e.g. 300ms, it should send at least two requests).
- the test `pause()` and re`start()` the sync service at some point, and then we can't guess what the next `pos` will be, in any of the syncs: it could either be the previous value (if we aborted while processing the previous response), or the next value (meaning we could finish processing the sliding sync response).

Still, it confirms at least that pausing and resuming work as expected.

---

Fixes #2382
2023-08-11 08:55:48 +00:00
Jonas Platte 5943f5f7f3 sdk: Set content-length header when streaming HTTP request body 2023-08-11 09:21:58 +02:00
Alfonso Grillo 364a4ae5a9 ffi: Add create-poll API matrix-sdk-crypto-ffi-0.3.12 2023-08-10 15:38:17 +00:00
Ivan Enderlin 0372467288 chore(uniffi): Update uniffi to another branch.
This patch switches UniFFI from
https://github.com/mozilla/uniffi-rs/pull/1684 to
https://github.com/mozilla/uniffi-rs/pull/1697.
2023-08-10 17:33:36 +02:00
Benjamin Bouvier 159786fe36 feat(notification client): bump sliding sync timeouts (#2403)
The timeouts were a bit too agressive, according to some user logs, resulting in failing to
load the event mentioned in the notification.

Here's the rationale for the new timeouts: we're only limited by the iOS process which has *at
most* 30 seconds to process a notification.

- We're running at most 3 requests of the notification sliding sync, so that will be (1+3)*3 = 12
seconds allocated for that.
- If we've found an event but it required decryption, we're running the encryption sync up to
2 times, (3+4) seconds each => 14 seconds.

At most we're eating up 26 seconds of the entire time, leaving some ballast for the rest of
the program.
2023-08-10 17:31:14 +02:00
Ivan Enderlin e9d6a9bfd7 chore: Remove unnecessary clones
chore: Remove unnecessary clones
2023-08-10 16:51:41 +02:00
Ivan Enderlin 361bc18757 fix(ui): Add m.room.member: $LAZY in the require states of visible_rooms
fix(ui): Add `m.room.member: $LAZY` in the require states of `visible_rooms`
2023-08-10 16:24:58 +02:00
Nicolas Mauri ac42d07de7 sdk+ffi: in notification settings, replace members_count by is_one_to_one for more clarity 2023-08-10 16:19:11 +02:00
Ivan Enderlin 2290bae942 feat(ui): Room::latest_event uses Timeline if it exists.
This patch optimises the previous patch by simplifying the use of
`Timeline`. If the `Timeline` exists, let's return the `latest_event`
every time: whether it is a remote _or_ a local event.
2023-08-10 16:00:06 +02:00
Ivan Enderlin e0163e67be feat(ui): Room::latest_event returns the Timeline local event if any.
This patch updates `Room::latest_event` to return the `Timeline` local
event if any.

First off, it starts by checking if a `Timeline` exists. It won't create
it if it doesn't exist! Second, it checks whether a latest event exists.
Finally it checks whether it's a local event.

This patch also updates the tests accordingly.
2023-08-10 15:59:50 +02:00
Ivan Enderlin e8cd21034b chore: Remove unnecessary clones.
The types used here are not implementing `Clone`, so calling `clone`
on them` copies the reference, which does not do anything and can be
removed.
2023-08-10 15:15:06 +02:00
Ivan Enderlin f64a46a2be Merge pull request #2396 from matrix-org/nicolas/notification_settings_user_defined_room_rules
sdk+ffi: Get the user-defined notification mode for a room and all rooms for which a user-defined rule exists.
2023-08-10 14:11:35 +02:00
Ivan Enderlin 0af918b8a7 feat(sdk): Skip Sliding Sync Response if it's been received already
feat(sdk): Skip Sliding Sync `Response` if it's been received already
2023-08-10 13:35:21 +02:00
Ivan Enderlin c5d2181549 test(sdk): Ensure that avatar is serialized as expected in FrozenSlidingSyncRoom
test(sdk): Ensure that `avatar` is serialized as expected in `FrozenSlidingSyncRoom`
2023-08-10 13:30:40 +02:00
Ivan Enderlin 2b938e3f03 doc(sdk): Fix a typo.
Co-authored-by: Benjamin Bouvier <public@benj.me>
2023-08-10 13:17:15 +02:00
Ivan Enderlin 817690206c feat(sdk): Create SlidingSync::expire_session.
For the sake of clarity, this patch extracts some code into its own
`SlidingSync::expire_session`.
2023-08-10 12:14:42 +02:00
Jonas Platte 4bfcc6669d Use simpler construction functions for tokio::broadcast::Sender 2023-08-10 12:04:40 +02:00
Jonas Platte f8eefadb2d Upgrade tokio to 1.30 2023-08-10 12:04:40 +02:00
Richard van der Hoff f51bc47949 Fix rust doc on IndexedDBStore (#2394)
it's not in-memory
2023-08-10 11:47:56 +02:00
Ivan Enderlin 5d8b0c1a0d feat(sdk): Save positions at the end of handle_response. 2023-08-10 11:31:18 +02:00
Nicolas Mauri 8c6e3949e0 sdk+ffi: allow to get all room IDs for which a user-defined rule exists. 2023-08-10 10:02:11 +02:00
Nicolas Mauri 0a52fc895e ffi: Allow to get the user-defined notification mode for a room 2023-08-10 09:51:10 +02:00
Ivan Enderlin 51c25a4456 feat(ui): Implement RoomList::entries_with_dynamic_filter
feat(ui): Implement `RoomList::entries_with_dynamic_filter`
2023-08-10 08:28:43 +02:00
Ivan Enderlin d20e82380a test(ui): Adjust pos. 2023-08-09 18:07:18 +02:00
Ivan Enderlin 1f7ce2893b feat(sdk): Skip Sliding Sync Response if it's been received already.
A Sliding Sync `v4::Response` contains a `pos` value. It helps to identify
progress during several requests/responses. If two requests with the
same `pos` are sent, the server **must** reply with the same response,
as defined in the specification.

The corollary is: If a response contains a `pos` that has already
been received, the client **must** ignore it, otherwise it can create
duplications. For example, let a response containing sync operations,
like `DELETE` or `INSERT`, with indexes: if this pair of operations are
repeated twice with the same index, it creates a broken state.

To avoid this behaviour, this patch stores the last 20 position markers
received from the server. If a response contains a `pos` that has
already been received, a (new) error is returned. As with all the other
errors, the sync-loop is stopped, and must restarted. The past positions
survive to this restart, as for the rest of the state.

When the server replies with a `M_UNKNOWN_POS`, the `pos` and the
`past_positions` are all cleared.
2023-08-09 17:18:29 +02:00
Ivan Enderlin b1b0641150 test: Ensure that avatar is serialized as expected. 2023-08-09 15:30:26 +02:00
Ivan Enderlin 696e10bdad chore: Use async_test instead of tokio::test. 2023-08-09 15:30:13 +02:00
Ivan Enderlin 0f94f93080 chore: When LSP is broken… :-) 2023-08-09 15:18:24 +02:00
Ivan Enderlin 55ba580c0d chore: Simplify Fn declaration. 2023-08-09 15:08:05 +02:00
Ivan Enderlin da7e05f18f feat(ffi): Use an enum to set dynamic filter.
This patch removes
`RoomListEntriesDynamicFilter::set_with_fuzzy_match_pattern` and
replaces it by a single `::set` method. It takes a new enum as
parameter: `RoomListEntriesDynamicFilterKind`. This enum has a
`FuzzyMatchRoomName` variant to simulate the removed method. It also
adds the `All` variant, to represent the `all` filter.
2023-08-09 15:00:09 +02:00
Ivan Enderlin f35275f4fc feat(ui): Implement a new filter: all.
This patch implements a new `all` filter.
2023-08-09 14:51:15 +02:00
Ivan Enderlin 90682270ae feat(ffi): Implement RoomList::entries_with_dynamic_filter.
First, this patch makes `RoomList::entries` infallible.

Second, this patch implements `RoomList::entries_with_dynamic_filter`.
2023-08-09 14:16:23 +02:00
Ivan Enderlin 3c46a1019b test(ui): Update some tests about fuzzy matcher.
These test cases are more easy to understand than the previous one if
you ask me.
2023-08-09 14:15:10 +02:00
Ivan Enderlin 61f481c126 test(ui): Test RoomList::entries_with_dynamic_filter.
This patch updates the tests to ensure `entries_with_dynamic_filter`
works as expected.
2023-08-09 13:53:14 +02:00
Ivan Enderlin bd2f5119db feat(ui): Rename entries_filtered to entries_with_static_filter.
Because it makes more sense.
2023-08-09 13:52:55 +02:00
Jonas Platte 1b8768becc Use AsyncCell instead of mpsc channel 2023-08-09 13:24:39 +02:00
Damir Jelić 3d3021efc0 Expose bindings to manage dehydrated devices 2023-08-09 12:32:48 +02:00
Damir Jelić 64ca96543e Initial support for dehydrated devices
Co-authored-by: Jonas Platte <jplatte@matrix.org>
2023-08-09 12:32:48 +02:00
Damir Jelić 8ce3b56180 Allow an Olm Account to generate its own device id 2023-08-09 12:32:48 +02:00
Damir Jelić 3e2f531caa Split out the receive_sync_changes method into a helper
This splits the method out so the bigger chunks doesn't persist the
changes in the store.

This will be useful if we need to hijack the changes and persist them in
a different store.
2023-08-09 12:32:48 +02:00
Jonas Platte 56f771a347 ui: Remove unnecessary boxing 2023-08-09 10:46:13 +02:00
Ivan Enderlin 1ab0d2081a doc(ui): Add inline comments. 2023-08-09 10:01:24 +02:00
Ivan Enderlin 90c30e4058 ui: Add RoomList::entries_with_dynamic_filter 2023-08-09 10:01:15 +02:00
Ivan Enderlin 752e814168 fix(ui): Add m.room.member: $LAZY in the require states of visible_rooms.
This patch tries to fix https://github.com/vector-im/element-x-
ios/issues/1204 by adding the following required states in the
`visible_rooms` sliding sync list: `m.room.member: $LAZY`.
2023-08-09 09:11:20 +02:00
Benjamin Bouvier 80c9464f1e chore: fix typo in cargo xtask kotlin doc comment (#2387) 2023-08-08 16:00:20 +02:00
Benjamin Bouvier 625acb056a feat(ffi): add an optional file layer for tracing (#2384)
* feat(ffi): add an optional file logger

Also makes logging to stdout/logcat optional.

* WIP: stupidly duplicate code 🤷

* ffi: Get rid of duplication in tracing initialization

* feat: add OtlpTracingConfiguration too

* feat: log either to stdout on non-android or logcat on android

---------

Co-authored-by: Jonas Platte <jplatte@matrix.org>
2023-08-08 12:37:32 +00:00
Nicolas Mauri ff9923c6a6 Allow to define the default notification mode for a given room type (#2369)
* Add a function to define the default notification mode for a given kind of room

* Code refactoring

* sdk+ffi: code refactoring
2023-08-08 14:20:17 +02:00
Kévin Commaille 1680a7d4d6 sdk: Set the refresh token lock if refresh token is missing
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-08-08 12:16:03 +02:00
Kévin Commaille 302cff6ba9 sdk: Make RefreshTokenError authentication API-agnostic
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-08-08 12:16:03 +02:00