Commit Graph

13223 Commits

Author SHA1 Message Date
Benjamin Bouvier 3ef5214587 event cache: add a few smoke tests
This adds a few basic tests for the event cache, notably one for the `add_initial_events`, for something I identified while working on the code, but
that could've caused bad issues:

The `test_add_initial_events` checks that even if we received updates with meaningful events for a room, the room's events are cleared before we add initial events (since
we have no ways to know where to insert the events, in this case). In the future, we can keep this test as a "smoke test" for basic functionality of
the event cache.
2024-02-26 16:05:23 +01:00
Valere 30640ebb65 sdk: Log the successful room message sending and record the received event ID 2024-02-26 11:40:38 +01:00
Doug 4f3cdfacaa docs: Clarify PR title guidelines. 2024-02-26 10:31:28 +01:00
Johannes Marbach b68bcf9cff fix(examples): Fix typos in getting started example
Signed-off-by: Johannes Marbach <n0-0ne+github@mailbox.org>
2024-02-25 11:35:59 +01:00
Doug 8e64341176 ffi: Use a custom RollingFileAppender.
The built in hourly preset doesn't let us specify a max file count. Plus this way we can add a file extension too.
2024-02-23 11:49:47 +01:00
Benjamin Bouvier 40ba98b95e test: fix one potential race in test_room_notification_count
We're subscribing to settings updates *after* sending a request to change a setting. In an unlucky scenario, the following sequence of events could happen:

- sending request to change the settings
- response is received
- we set up the receiver to settings updates, but it's too late

The fix would then be to subscribe to the changes *before* we even send the request to update settings.
2024-02-22 18:01:53 +01:00
Benjamin Bouvier 3541d205e0 test: timeout faster in test_room_notification_count 2024-02-22 18:01:53 +01:00
Benjamin Bouvier 2a201d4218 test: move the with_server methods in the sdk crate
It means the `wiremock` dependency is not a `dev-dependency` anymore, but an optional `dependency` enabled only if `testing` is enabled.
It seems like a fine tradeoff to me.
2024-02-22 18:01:29 +01:00
Benjamin Bouvier 43129441db test: rename another logged_in_client to logged_in_client_with_server 2024-02-22 18:01:29 +01:00
Benjamin Bouvier 5ae2d83457 test: rename one logged_in_client to logged_in_client_with_server 2024-02-22 18:01:29 +01:00
Benjamin Bouvier 193f3331e8 test: remove a few copies of logged_in_client
- in sdk-ui, reuse the same implementation everywhere
- in the sdk integration test, make use of the sdk logged_in_client to remove a few lines
2024-02-22 18:01:29 +01:00
Benjamin Bouvier 65fe3c8b5b test: commonize the logged_in_base_client methods in sdk-base 2024-02-22 18:01:29 +01:00
Benjamin Bouvier 85e8771b5a test: rename one logged_in_client to logged_in_base_client
As it returns a `BaseClient`, it should be distinguished from all the other `logged_in_client`s that return... a `Client`.
2024-02-22 18:01:29 +01:00
Benjamin Bouvier d27bfca5e4 test: rename no_retry_test_client to {{SAME}}_with_server as it also returns a mocking server
And use `no_retry_test_client` in there.
2024-02-22 18:01:29 +01:00
Benjamin Bouvier 77bf972b3f test: rename another test_client_builder to {{SAME}}_with_server as it also returns a mocking server
And use `test_client_builder` in there too.
2024-02-22 18:01:29 +01:00
Benjamin Bouvier 307063e571 test: deduplicate test_client_builder methods
And start deduplicating the other twos as well.
2024-02-22 18:01:29 +01:00
Mauro Romito 18c155beb5 feat: room_directory_sync basic sync loop 2024-02-22 17:50:07 +01:00
Stefan Ceriu 0c1b6e45d5 latest event: Remove edits/replacements from the latest room event (#3150) 2024-02-22 15:19:00 +01:00
Ivan Enderlin b5bda577dd chore(sdk): Remove useless imports or fix unused code. 2024-02-22 14:34:56 +01:00
Benjamin Bouvier 6593e32582 ffi: fix one clippy warning about ToOwned 2024-02-22 14:33:13 +01:00
Benjamin Bouvier d3612ce35b event cache: give each RoomEventCache a sdk::Room
To do so, we need to put the weak reference `EventCache -> Client` back into the `EventCache`.

Putting the `sdk::Room` in the `RoomEventCache` will be useful to run room queries like backpagination (aka call `Room::messages()`).
2024-02-22 14:33:13 +01:00
Damir Jelić bd6d0e959a backups: Better logs for decryption errors for backed up room keys 2024-02-21 16:08:32 +01:00
Benjamin Kampmann cced512ad4 Keep the raw notification event around for further processing 2024-02-21 12:48:29 +01:00
Ivan Enderlin 06359b1166 fix(sdk): Race condition, doc, and Wasm in EventCache
fix(sdk): Race condition, doc, and Wasm in `EventCache`
2024-02-21 12:14:41 +01:00
Ivan Enderlin 10098d20c5 test(common): Add tests for spawn and JoinHandle::abort. 2024-02-21 12:01:08 +01:00
Ivan Enderlin e4c8d6b708 chore(test): Remove a useless import. 2024-02-21 12:00:50 +01:00
Ivan Enderlin 6c6a8e2e77 chore(common): Remove useless import. 2024-02-21 10:54:31 +01:00
Andy Balaam dcf0069753 export: Provide a streamed way to export keys
Signed-off-by: Andy Balaam <andy.balaam@matrix.org>
2024-02-20 16:06:24 +01:00
Andy Balaam f0354d1fc5 export: Move existing export_room_keys method to Store
Signed-off-by: Andy Balaam <andy.balaam@matrix.org>
2024-02-20 15:18:52 +01:00
Damir Jelić 6634735065 ffi: Let the auth service use a proxy as well
The ClientBuilder already exposes setting the proxy, but sadly the
AuthService doesn't let you configure the ClientBuilder directly (yet).

So logging in with a proxy wasn't supported until now.
2024-02-20 15:15:49 +01:00
Stefan Ceriu 59c468c758 Switch user ignoring/unignoring methods to full async 2024-02-20 13:51:18 +01:00
Stefan Ceriu c6e93b06a3 Log ignored user list event deserialization errors 2024-02-20 13:51:18 +01:00
Stefan Ceriu 89033cd13a Fixes #3141 - Expose ignored users on the FFI layer 2024-02-20 13:51:18 +01:00
Valere 88a70f472f Discard session API and bindings for Room (#2941)
Co-authored-by: Damir Jelić <poljar@termina.org.uk>
2024-02-20 13:36:55 +01:00
Doug fafd1a403c fix: Use from macro on wrapped error. 2024-02-20 13:32:46 +01:00
Doug 371cc24031 fix: Update Swift test, remove pub access on sanitize_server_name
Removed a test that was pinging matrix.org too.
2024-02-20 13:32:46 +01:00
Doug 2538ba68c5 ffi: Expose more server discovery errors. 2024-02-20 13:32:46 +01:00
Doug 14e93e8c0c ffi: Use server_name_or_homeserver_url directly. 2024-02-20 13:32:46 +01:00
Jorge Martín 54bdb7791c ffi: Add extra logs to Client::process_session_change
This should help us understand why 2 failed requests with invalid access token didn't pass a refreshed token to the client.
2024-02-20 11:44:02 +01:00
Ivan Enderlin 2f97bc2bae feat(sdk): Improve performance of EventCacheInner::for_room. 2024-02-19 20:08:28 +01:00
Ivan Enderlin 7e3e8fff55 feat(common): Implement JoinHandle::abort on wasm32-u-u.
This patch implements `JoinHandle::abort` when `cfg(target_arch =
"wasm32")`.

The idea is to combine `RemoteHandle` and `AbortHandle`.
2024-02-19 18:21:20 +01:00
Ivan Enderlin 8d878b6785 fix(sdk): Fix a race condition in EventCacheInner::for_room.
There is a race condition in `EventCacheInner::for_room`. Before this
patch, it was possible for 2 concurrent execution to do the following:

* Execution 1 takes the read lock; there is no room in `by_room`, so it
  creates the `RoomEventCache`, code is suspended while trying to get
  the write lock.
* Execution 2 takes the read lock; there is no room in `by_room`, so it
  creates the `RoomEventCache`, code is _not_ suspended because _insert
  reason_, the write lock is acquired, and the `RoomEventCache` is saved
  and a shallow clone is returned.
* Execution 1 resumes, the write lock is acquired, the `RoomEventCache`
  overwrites the one from Execution 2, and a shallow clone is returned.

Now Execution 2 holds a `RoomEventCache` that isn't saved in `by_room`.
It's a ghost! Worst, because the store is cloned in both
`RoomEventCache`, 2 versions will overwrite themselves in the store
constantly.

This patch uses a single write lock, and uses the `BTreeMap::entry`
API instead. Thus, the race condition disappears.

This patch also changes the return type of `for_room` to make it
infallible. It was already the case: only the `Ok` value was returned.
2024-02-19 16:40:11 +01:00
Ivan Enderlin add06bf897 doc(sdk): Add some documentation about the EventCache. 2024-02-19 16:40:11 +01:00
Ivan Enderlin e5b07aa827 chore(sdk): Move EventCache::drop_handles inside EventCacheInner.
This patch moves `EventCache::drop_handles` inside `EventCacheInner` for
the sake of simplicity.
2024-02-19 16:40:11 +01:00
Ivan Enderlin 814d78708e feat(sdk): EventCache uses matrix_sdk_common::executor::spawn.
This patch imports the `spawn` function from
`matrix_sdk_common::executor` instead of `tokio`.
`matrix_sdk_common::executor` adds support for WebAssembly.
2024-02-19 16:40:11 +01:00
Ivan Enderlin 88d7a2fe28 feat(ui,ffi): Add the favourite room list filter
feat(ui,ffi): Add the `favourite` room list filter
2024-02-19 13:45:37 +01:00
Benjamin Bouvier 5386e9e838 event cache: have a single EventCache instance per Client, at most (#3136)
* event cache: move it to the main SDK crate

* event cache: add requested Debug impl to `RoomEventCacheUpdate`

Somehow the compiler asked for it now...

* event cache: add missing copyright notice to store file

* event cache: use a weak reference to the client internally

This will make it possible to have the `Client` own an `EventCache` without a reference
cycle.

* event cache: move the spawned task to its own function

* event cache: move RwLock from EventCache::inner to the only mutable field inside EventCacheInner

* event cache: have the Client own *the* event cache

The goal is to have a unique EventCache instance overall, that's available from everywhere in
the SDK, notably when creating timelines for rooms.

Because the event cache only owns a weak reference to the client, it means the Client still
can be dropped, In turn, this will close its sender of `RoomUpdates`, which will gracefully
close the task spawned in `EventCache::new` after it's done handling the latest updates.

* event cache: process room updates one at a time

* timeline: use the client-wide event cache instead of spawning one per timeline

This now means that we're passing the "initial events" to the event cache just before initializing
the timeline. As a result, there might be previous events that the event cache saw (coming from
sync), but now we can't decide where to put them; drop previously known events in that case.

* event cache: hey, turns out we don't even need the weak back-link

Keeping it as a separate commit, to make it easier to revert later.

* event cache: remove unused errors

Keeping the error type and results, though, because we might have store errors soonish.

* fixup! event cache: move the spawned task to its own function

* event cache: manually subscribe to the event cache

It was a bad idea to have it enabled by default, since some users may not be interested in all
updates for all rooms (e.g. bots). Instead, we make it so that the event cache must be
explicitly subscribed to, and we do it in two cases:

- in the UI `TimelineBuilder::build` method, because we're interested in updates to the current
  room,
- in the `RoomListService`, because we *will* be interested in updates to room derived data (e.g.
  unread counts, read receipts, and so on).

This avoids a bit of fiddling when creating the event cache in the client.

This is resilient when a parent Client is forked into a child Client, because the child
`EventCache` share the same subscription as the parent's.
2024-02-19 12:39:31 +00:00
Ivan Enderlin 9e6252cb2d doc(ui): Add missing copyright headers. 2024-02-19 13:33:11 +01:00
Ivan Enderlin 12d5f51051 feat(ffi): Add the favourite room list filter.
This patch implements the `RoomListEntriesDynamicFilterKind::Favourite`
variant.
2024-02-19 13:29:56 +01:00
Ivan Enderlin c7d34bd65e doc(ui): Add documentation for matrix_sdk_ui::room_list_service::filters.
This patch adds missing documentation for the `filters` module.
2024-02-19 13:29:56 +01:00