Commit Graph

2742 Commits

Author SHA1 Message Date
Ivan Enderlin
2f29664fb8 doc(sdk): Fix a typo.
Co-authored-by: Benjamin Bouvier <public@benj.me>
2023-05-20 17:57:11 +02:00
Ivan Enderlin
f01e8dc992 test(sdk): Test SlidingSyncList::set_sync_mode. 2023-05-17 17:10:55 +02:00
Ivan Enderlin
8bb04ed40b test(sdk): Use the Rust inclusive range syntax for ranges. 2023-05-17 17:10:55 +02:00
Ivan Enderlin
d99957d370 feat(sdk): Implement SlidingSyncList::set_sync_mode.
Changing the sync-mode of a list on-the-fly is necessary to optimise the
new `RoomList` API. For example, we can start with a list in a selective
mode, a range of `0..=50` and a `timeline_limit=0` to fetch the
beginning of the room list, and then _change_ the sync-mode to growing
to continue to sync the room list in the background.

Today, this is done with 2 lists and a merge of the lists, but
(i) this is error-prone, (ii) this is not optimal. Thank to
`SlidingSyncList::set_sync_mode`, merging lists is no more necessary,
thus removing a class of bugs in client's code.
2023-05-17 17:10:55 +02:00
Ivan Enderlin
51e6e80b3b feat(sdk): SlidingSyncMode has richer variants
feat(sdk): `SlidingSyncMode` has richer variants
2023-05-17 17:10:26 +02:00
Ivan Enderlin
6dde00ebcf chore(sdk): Simplify code with a matches!. 2023-05-17 16:50:00 +02:00
Ivan Enderlin
74430e127f doc(sdk): Do not use helper constructors in the documentation. 2023-05-17 16:50:00 +02:00
Ivan Enderlin
1c175df6b3 chore(sdk): Move From impl on SSListRequestGenerator as proper constructor. 2023-05-17 16:37:11 +02:00
Ivan Enderlin
ddc8d915cb doc(sdk): Fix syntax error. 2023-05-17 16:34:12 +02:00
Ivan Enderlin
f8e12f6aaf doc(sdk): Update documentation according to last commits. 2023-05-17 15:42:30 +02:00
Ivan Enderlin
63feec1433 test(sdk): Test impl From<SlidingSyncMode> for …RequestGenerator`. 2023-05-17 15:32:35 +02:00
Ivan Enderlin
41c09a5ec5 feat(sdk): SlidingSyncMode has richer variants.
`SlidingSyncMode` was previously declared as:

```rust
enum SlidingSyncMode {
    Selective,
    Paging,
    Growing,
}
```

Now, the new declaration is:

```rust
enum SlidingSyncMode {
    Selective,
    Paging {
        batch_size: u32,
        maximum_number_of_rooms_to_fetch: Option<u32>,
    },
    Growing {
        batch_size: u32,
        maximum_number_of_rooms_to_fetch: Option<u32>,
    }
}
```

First off, it helps to remove the `full_sync_batch_size` and
`full_sync_maximum_number_of_rooms_to_fetch` methods and fields from
`SlidingSyncListBuilder`. It was containing default values in case of.
That was useless and needed to be fixed. Also, calling a `full_sync_*`
method with the `Selective` mode had no effect, which could disturb
the user. Well, now everything is clean on that front.

Second, `SlidingSyncListRequestGenerator` no longer has constructors,
but a `From<SlidingSyncMode>` implementation. However, the constructors
now live in `SlidingSyncMode` with `new_selective`, `new_paging` and
`new_growing` methods which are helpers. All in all, it makes creating a
`SlidingSyncListRequestGeneator` simpler: just call `sync_mode.into()`
and boom.

Finally, this patch removes the `default_with_fullsync` list builder
helper, which makes no sense at all.
2023-05-17 14:49:55 +02:00
Jonas Platte
12a02f0458 Make examples section name consistent in docs 2023-05-17 14:45:24 +02:00
Ivan Enderlin
c618b03f12 feat(sdk): SlidingSync::add_list has an immediate effect
feat(sdk): `SlidingSync::add_list` has an immediate effect
2023-05-17 13:56:35 +02:00
Jonas Platte
f12e827a67 Don't use block_on in no_run doctests
… and clean up formatting around the affected ones.
2023-05-17 13:49:14 +02:00
Ivan Enderlin
64cea091f9 chore(sdk): Clean up test code. 2023-05-17 13:23:21 +02:00
Ivan Enderlin
5ce9790c94 doc(sdk): Fix rebase missing doc. 2023-05-17 13:20:31 +02:00
Ivan Enderlin
63257e6226 fix(sdk): Remove room unsubscriptions once the server has received them
fix(sdk): Remove room unsubscriptions once the server has received them
2023-05-17 11:59:16 +02:00
Ivan Enderlin
53c20fcf1a feat(sdk): SlidingSync::add_list has an immediate effect.
`SlidingSync::add_list` sends `ContinueSyncLoop` on the internal channel.
2023-05-17 11:35:53 +02:00
Ivan Enderlin
501b990248 chore(sdk): Rename SlidingSync::unsubscribe_to_room to …_from_room. 2023-05-17 11:29:26 +02:00
Valere
405db06495 refactor(crypto): get_or_load never returns crypto error 2023-05-17 09:20:37 +00:00
Jonas Platte
be7e162ce1 Restore timeline integration tests
The directory had the wrong name, so it wasn't detected by Cargo.
2023-05-17 11:14:16 +02:00
Ivan Enderlin
b7374a78e9 doc(sdk): Update documentation for SlidingSync::(un)subscribe_to_room. 2023-05-17 11:10:03 +02:00
Ivan Enderlin
d8a9408efe fix(sdk): Remove room unsubscriptions once the server has received them.
This bug has been found by @bnjbvr, all the credits go to him. I've just
added some comments around his code.

Prior to this patch, the room unsubscription buffer
(`SlidingSync::room_unsubscriptions`) was reset before the request was
sent. So if something went wrong, the next request would not include the
room unsubscriptions.

This patch updates this behavior. First, it replaces `Vec` by `HashSet`
to avoid a O(n^2) look up.

Second, a copy of room unsubscriptions used by the request is kept, so
that it can be used to cherry-pick which room unsubscription to remove
from the buffer once a response from the server is received. It's
important to not clear the entire room unsubscriptions buffer as more
unsubscriptions could have been inserted meanwhile.
2023-05-17 10:14:34 +02:00
Ivan Enderlin
9b7122768f chore(sdk): Rename SlidingSync room subscriptions and unsubscriptions API.
Notably, this patch renames `SlidingSync::subscribe` and `::unsubscribe`
to `subscribe_to_room` and `unsubscribe_to_room`.
2023-05-17 10:01:55 +02:00
Jonas Platte
5fa2fff8e5 ui: Re-export TLS features 2023-05-17 09:58:31 +02:00
Jonas Platte
31e32c307f ui: Add missing copyright headers 2023-05-17 09:58:31 +02:00
Jonas Platte
d620f83e0d Enable syntax highlighting in sliding_sync README 2023-05-17 09:58:31 +02:00
Jonas Platte
cfc8effa66 Move timeline API into a new crate
… aimed at interactive user interfaces.
2023-05-17 09:58:31 +02:00
Jonas Platte
91d97cd588 sdk: Re-export matrix_sdk_base::crypto 2023-05-17 09:58:31 +02:00
Jonas Platte
910022bca6 sdk: Make useful push related methods public 2023-05-17 09:58:31 +02:00
Jonas Platte
a6fe0bb34d sdk: Merge identical ensure_members, sync_members methods 2023-05-17 09:58:31 +02:00
Damir Jelić
0144826884 crypto: Log if and which fallback key got removed 2023-05-16 16:25:20 +02:00
Damir Jelić
35a0f3af25 crypto: Improve some logs around Olm decryption and encryption 2023-05-16 16:25:20 +02:00
Damir Jelić
9f1ec9ac3a crypto: Log the result of one-time key generation 2023-05-16 16:25:20 +02:00
Ivan Enderlin
5b55145a1c Merge branch 'main' into test-sliding-sync-room-timeline 2023-05-15 20:06:42 +02:00
Ivan Enderlin
d24a3922a0 test(sdk): Avoid ambiguity in pos. 2023-05-15 20:03:02 +02:00
Benjamin Bouvier
58dbe1e252 feat: add add_cached_list to SlidingSyncBuilder and SlidingSync (#1876)
This has slightly drifted from the initial design I thought about in the issue.

Instead of having `build()` be fallible and mutably borrow some substate (namely `BTreeMap<OwnedRoomId, SlidingSyncRoom>`) from `SlidingSync` (that may or may not already exist), I've introduced a new `add_cached_list` method on `SlidingSync` and `SlidingSyncBuilder`. This method hides all the underlying machinery, and injects the room data read from the list cache into the sliding sync room map.

In particular, with these changes:

- any list added with `add_list` **won't** be loaded from/written to the cache storage,
- any list added with `add_cached_list` will be cached, and an attempt to reload it from the cache will be done during this call (hence `async` + `Result`).
- `SlidingSyncBuilder::build()` now only fetches the `SlidingSync` data from the cache (assuming the storage key has been defined), not that of the lists anymore.

Fixes #1737.

Signed-off-by: Benjamin Bouvier <public@benj.me>
Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
2023-05-15 16:17:45 +00:00
Benjamin Bouvier
c404e378a2 test: sliding sync list fields reloaded from the cache are observable in streams
Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-05-15 17:46:04 +02:00
Jonas Platte
549edeb73b sdk: Instrument sliding response handling task 2023-05-15 17:24:02 +02:00
Ivan Enderlin
d2e9347be4 test(sdk): Put sliding_sync behind its feature flag. 2023-05-15 16:03:54 +02:00
Ivan Enderlin
07267767fc test(sdk): New Sliding Sync integration test suite for a mocked server. 2023-05-15 15:19:45 +02:00
Ivan Enderlin
dca7800a88 chore(cargo): uuid is no longer needed. 2023-05-15 15:19:37 +02:00
Ivan Enderlin
caaeb8130d feat(sdk): Remove txn_id from requests sent by SlidingSync.
We were using `txn_id` as a way to identify the running stream. Now
things are cleaner so we can remove this “debug tool”. This class of
problems should not appear anymore. For the record, the biggest problem
was the following: It was possible to start multiple `stream`s at the
same time, and thus a stream could receive a response sent by another
stream. Since we no longer need to restart SlidingSync anymore (i.e. no
need to start multiple `stream`s at the same time), this problem should
not happen.
2023-05-15 15:16:40 +02:00
Ivan Enderlin
94d5d5187f test(sdk): Rename a test about SlidingSyncRoom. 2023-05-15 15:14:58 +02:00
Ivan Enderlin
d973ac1e93 doc(sdk): Add missing documentation. 2023-05-15 15:14:23 +02:00
Ivan Enderlin
6185b4050a feat(sdk): Process SlidingSync response inside handle_response.
Prior to this patch, the `v4::Response`, aka the SlidingSync response,
was processed by the client and transformed into a `SyncResponse` into
`sync_once` before being passed to `handle_response`. Now it's done in
`handle_response`.

This is not mandatory _now_, but it will be helpful in a close future.
2023-05-15 15:12:20 +02:00
Jonas Platte
ee87ec7b46 Improve logs for pagination 2023-05-15 13:06:30 +02:00
Jonas Platte
ab7aa68c5b Fix lints 2023-05-15 13:06:30 +02:00
Benjamin Bouvier
fc8dd5a1cc Update crates/matrix-sdk/src/room/timeline/inner.rs
Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
2023-05-15 10:29:27 +02:00