Commit Graph

11296 Commits

Author SHA1 Message Date
Benjamin Bouvier
01bb8093d0 feat(ffi): add a function to setup a lightweight tokio runtime
Creating many threads may use a bit of memory: on a machine with N
devices, exactly N*2 MB of memory may be consumed.

That might be a lot for a NSE process on iOS, which can only have up to
16 MB of RAM allocated for it. For this case, we introduce a new FFI
method `setup_lightweight_tokio_runtime` which will spawn at most 4
worker threads and 1 blocking thread. This should be sufficient for most
use cases.
2025-03-11 16:05:52 +01:00
Ivan Enderlin
1565067cee doc(ffi): Update the CHANGELOG.md. 2025-03-11 15:39:50 +01:00
Ivan Enderlin
ecc603171b feat(ffi): Add RoomInfo::encryption_state.
This patch adds the `EncryptionState` onto the new
`RoomInfo::encryption_state` field.
2025-03-11 15:39:50 +01:00
Benjamin Bouvier
7f3308bd2b feat(sdk): don't trigger the ignored user list change if it hasn't changed since the previous time 2025-03-11 15:03:42 +01:00
Benjamin Bouvier
06d5fdb5ff fix(event cache): enable foreign keys on a connection basis
As opposed to WAL mode, foreign keys must be enabled for each database
connection, according to
https://www.sqlite.org/foreignkeys.html#fk_enable

Unfortunately, we can't track which connection objects have already
executed the pragma, so the safer we can do is enable it everytime we
try to acquire a connection from the pool.

Fixes #4785.
2025-03-11 15:03:42 +01:00
Benjamin Bouvier
6047d369a6 refactor(event cache): call clear() instead of doing it manually in clear_all_rooms 2025-03-11 15:03:42 +01:00
Benjamin Bouvier
961a893b8c test(event cache): double-check cascading happened in the clear linked chunk test 2025-03-11 15:03:42 +01:00
Benjamin Bouvier
2927974396 fix(event cache): don't try to remove a previous gap if it's the only chunk in memory
A linked chunk never wants to be empty. However, after a limited gap
that doesn't contain events, it may be shrunk to the latest chunk that's
a gap.

If later we decide to remove the gap (because it's been resolved with no
events), then we would try to remove the last chunk, which is not
correct.

Ideally, we'd keep an events chunk around; but if we have an events
chunk *before* a gap, that may look like missing events to the user, at
least until the gap has been resolved.

The fix to this problem is to *not* optimize / remove the gap, if it's
the only chunk kept in memory. This was only a memory optimization, but
it's not absolutely required per se.
2025-03-11 15:03:42 +01:00
Benjamin Bouvier
8c780fc5d5 chore(event cache): don't make use of .not() when it's not useful
`.not()` is useful in assertions, at best, but using it where `!` would
suffice is a bad code smell.
2025-03-11 15:03:42 +01:00
Benjamin Bouvier
8867d203e7 chore(event cache): add spans for RoomEventCache methods
So we know which room some logs messages correspond to.
2025-03-11 15:03:42 +01:00
Ivan Enderlin
cf5f14ef5d feat(base): Reduce memory usage of BaseClient::room_info_notable_update_sender.
This patch reduces the memory usage of the broadcast channel used by
`BaseClient::room_info_notable_update_sender`. So far, its size was
`u16::MAX`. Considering `RoomInfoNotableUpdate` is 24 bytes, the channel
was allocating 1.5Mb of memory, which is way too much. It is creating
problems on systems where the process has limited resources, like the
Notification Service Extension on iOS.

For a regular users with 200 rooms, the memory usage becomes 24Kb, which
is 65'536 times less.
2025-03-11 14:47:53 +01:00
Ivan Enderlin
132f063769 feat(base): Add ObservableMap::len.
This patch implements `ObservableMap::len`, which is useful to count of
values it contains.
2025-03-11 14:47:53 +01:00
Ivan Enderlin
915cb13d45 fix(ffi): Remove Room::is_encrypted.
This API is now deprecated.
2025-03-11 14:03:42 +01:00
Kévin Commaille
0089da10cc refactor(ffi): Use methods on OidcConfiguration to construct parts
Changing the `TryInto` implementation into a method makes the code easier to follow.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-03-11 13:55:12 +01:00
Kévin Commaille
28293d0f2b chore: Add changelog for url_for_oidc changes
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-03-11 13:55:12 +01:00
Kévin Commaille
d3e64295cf refactor(oidc): Add redirect URI as an argument of url_for_oidc
Being able to always use the first redirect URI in the client metadata
seems to be very specific to the FFI bindings.

For example clients that need to bind a port on localhost need to
provide a custom redirect URI each time.

 So we ask for the redirect URI, and keep the current behavior only for
the bindings.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-03-11 13:55:12 +01:00
Kévin Commaille
6cd3217c2e refactor(oidc): Don't take the client metadata as an argument of url_for_oidc
The OidcRegistrations already hold the metadata. We can just clone it lazily when we need it.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-03-11 13:55:12 +01:00
Ivan Enderlin
eba2a7a6e3 doc(ffi): Update the CHANGELOG.md. 2025-03-11 12:28:16 +01:00
Ivan Enderlin
a98b822eeb feat(ffi): Replace Room::is_encrypted by encryption_state and latest_encryption_state. 2025-03-11 12:28:16 +01:00
Ivan Enderlin
0a80021742 doc: Update the CHANGELOG.mds. 2025-03-11 12:28:16 +01:00
Ivan Enderlin
63e8fc84a3 test(sdk): Test encryption_state() vs latest_encryption_state(). 2025-03-11 12:28:16 +01:00
Ivan Enderlin
fe0fb641f3 test(base): Test EncryptionState helpers. 2025-03-11 12:28:16 +01:00
Ivan Enderlin
1c43bc7e29 test(base): Test EncryptionState::NotEncrypted. 2025-03-11 12:28:16 +01:00
Ivan Enderlin
d03ed3063c feat: Introduce EncryptionState.
This patch introduces the new `EncryptionState` to represent the 3
possible states: `Encrypted`, `NotEncrypted` or `Unknown`. All the
`is_encrypted` methods have been replaced by `encryption_state`.
The most noticable change is in `matrix_sdk::Room` where `async fn
is_encrypted(&self) -> Result<bool>` has been replaced by `fn fn
encryption_state(&self) -> EncryptionState`. However, a new `async
fn latest_encryption_state(&self) -> Result<EncryptionState>` method
“restores” the previous behaviour by calling `request_encryption_state`
if necessary.

The idea is that the caller is now responsible to call
`request_encryption_state` if desired, or use `latest_encryption_state`
to automate the call if necessary. `encryption_state` is now non-async
and infallible everywhere.

`matrix-sdk-ffi` has been updated but no methods have been added for
the moment.
2025-03-11 12:28:16 +01:00
Stefan Ceriu
ea8664c487 Merge pull request #4780 from matrix-org/stefan/invitesRoomSummaryFallback
Invites room summary fallback
2025-03-11 11:02:23 +02:00
Stefan Ceriu
ca025f8cca feat(ffi): forget the room when rejecting invites
- we're doing this as an extra layer of protection against spam attacks.
2025-03-11 10:16:27 +02:00
Stefan Ceriu
78e19fce32 chore(sdk): rewrite the room summary fallback test on top of the MatrixMockServer 2025-03-11 09:22:29 +02:00
Andy Balaam
c8536e9e46 fix(crypto): Redecrypt non-UTD messages to remove no-longer-relevant warning shields (#4644)
Fixes https://github.com/element-hq/element-meta/issues/2697
Fixes https://github.com/element-hq/crypto-internal/issues/398

I'm sorry it's a big change. I've tried to break it into decent commits,
and I did a couple of preparatory PRs to make it less painful, but it's
still a bit to get your head around.

The basic idea is that when a session is updated and we call
`retry_event_decryption`, we don't only look at UTDs any more - now we
also look at decrypted events, and re-request their `EncryptionInfo`, in
case it has improved.

---------

Signed-off-by: Andy Balaam <mail@artificialworlds.net>
Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
Co-authored-by: Benjamin Bouvier <benjamin@bouvier.cc>
2025-03-11 07:01:54 +00:00
Benjamin Bouvier
1caa6069db refactor(timeline): move is_utd() to TimelineItemContent
It's unusual to have the method on the parent type when the field type
could also hold the method. In fact, this was the only bool getter
inspecting the timeline's content, so let's move the method next to as
its siblings, for consistency, and let's spell it out fully for clarity.
2025-03-11 07:43:53 +01:00
Stefan Ceriu
abe8338e5c chore(ffi): expose a method for retrieving rooms based on their identifier 2025-03-10 19:11:59 +02:00
Stefan Ceriu
5373e39ce5 chore(ffi): remove now unnecessary invited_room and inviter methods as those should be retrieved through the room preview 2025-03-10 19:11:58 +02:00
Stefan Ceriu
5875973c13 feature(ffi): have previews for invited rooms fallback to cached client data if fetching the preview fails
- relates to element-hq/element-x-ios/issues/3713
- this will allow us to interact with them even if the given homeserver doesn't have MSC3266 enabled
2025-03-10 19:11:58 +02:00
dependabot[bot]
3fbf159d0e chore(deps): bump crate-ci/typos from 1.30.0 to 1.30.1
Bumps [crate-ci/typos](https://github.com/crate-ci/typos) from 1.30.0 to 1.30.1.
- [Release notes](https://github.com/crate-ci/typos/releases)
- [Changelog](https://github.com/crate-ci/typos/blob/master/CHANGELOG.md)
- [Commits](https://github.com/crate-ci/typos/compare/v1.30.0...v1.30.1)

---
updated-dependencies:
- dependency-name: crate-ci/typos
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-03-10 16:38:20 +01:00
Kévin Commaille
b5c4fe3f7d test(sdk): Allow any MockEndpoint to override the expected access token
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-03-10 10:52:53 +01:00
Kévin Commaille
516d066d4c test(sdk): Add a constructor for MockEndpoint on MatrixMockServer
Allows to reduce duplication and will allow to add common logic.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-03-10 10:52:53 +01:00
Kévin Commaille
fbcd5a71aa test(sdk): Always call MockEndpoint::respond_with
Instead of MockBuilder::respond_with. This reduces duplcation and will
allow to add some common logic when building the endpoints.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-03-10 10:52:53 +01:00
Ivan Enderlin
b5a23086fd test(sdk): Add test for maybe_apply_new_redaction.
This patch adds a test for `maybe_apply_new_redaction` when the redacted
event is not loaded in-memory, i.e. when it lives in the store only.
2025-03-10 09:45:41 +01:00
Kévin Commaille
a9ce3f6963 chore: Add changelog for merging SessionTokens
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-03-10 09:12:38 +01:00
Kévin Commaille
a27f8f79a4 refactor(sdk): Move the session tokens into the AuthCtx
To avoid duplicating the code between both authentication APIs.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-03-10 09:12:38 +01:00
Kévin Commaille
dd01479c6b refactor(sdk): Use a single SessionTokens type
Since MatrixSessionTokens and OidcSessionTokens are identical.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-03-10 09:12:38 +01:00
dependabot[bot]
e7f85ba545 chore(deps): bump ring from 0.17.8 to 0.17.13
Bumps [ring](https://github.com/briansmith/ring) from 0.17.8 to 0.17.13.
- [Changelog](https://github.com/briansmith/ring/blob/main/RELEASES.md)
- [Commits](https://github.com/briansmith/ring/commits)

---
updated-dependencies:
- dependency-name: ring
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-03-10 09:41:43 +02:00
Andy Balaam
48767da6cc refactor(test): Make use of is_utd method in integration test 2025-03-07 14:20:45 +00:00
Andy Balaam
73754399be feat(timeline): Provide is_utd on EventTimelineItem 2025-03-07 14:20:45 +00:00
Kévin Commaille
18f5668e3e Add assertion messages
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-03-07 13:10:52 +01:00
Kévin Commaille
bc92e55b53 Improve tests
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-03-07 13:10:52 +01:00
Kévin Commaille
230feff430 test(sdk): Add tests for handle_refresh_tokens and Oidc
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-03-07 13:10:52 +01:00
Kévin Commaille
8bb4387dc4 fix(oidc): Match the proper error type for invalid refresh token
Since we do not use mas-oidc-client anymore, the error to match has changed.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-03-07 13:10:52 +01:00
Kévin Commaille
2506ba8364 refactor(oidc): Use oauth2 for token revocation
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-03-07 12:50:58 +01:00
Damir Jelić
daad6d662f fix(multiverse): Don't wait for sync service state changes when shutting down
The SyncService::stop method guarantees that the sync service will be
stopped after it has completed so there's no need to wait for state
changes.

The state change might not even come, if you pressed `S` to stop the
sync service manually.
2025-03-06 16:16:11 +01:00
Damir Jelić
53853c2d9a refactor(multiverse): Put the login logic into a separate function 2025-03-06 15:46:07 +01:00