Commit Graph

11327 Commits

Author SHA1 Message Date
Kévin Commaille
abc4fbc2f7 refactor(oidc): Import code to discover OIDC provider configuration
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-03-14 18:03:34 +01:00
Kévin Commaille
9adff21f78 refactor(oidc): Import code for building the account management URL
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-03-14 18:03:34 +01:00
Kévin Commaille
91f9ef85ae refactor(oidc): Add type alias for oauth2 errors
To have less verbose and more predictable error types.
2025-03-14 18:03:34 +01:00
Ivan Enderlin
17c6ad6b70 test(ui): Ensure Timeline runs a redecryption for all UTD.
This patch adds two tests, ensuring UTD stored in the event cache are
decrypted, whether they come from the initial items or paginated items.
2025-03-14 14:18:21 +01:00
Ivan Enderlin
8f61bdb046 fix(ui): Events received from the event cache trigger a decryption.
This patch fixes a bug where events coming from the event cache might be
encrypted, see https://github.com/matrix-org/matrix-rust-sdk/issues/4762
to learn more.

This patch updates the `room_event_cache_updates_task` to call
`TimelineController::retry_event_decryption` if the origin is `Cache`.
2025-03-14 14:18:21 +01:00
Ivan Enderlin
53c36226cb refactor(ui): TimelineController::retry_event_decryption no longer needs a &Room.
This patch removes the room `&Room` argument of
`TimelineController::retry_event_decryption`. The `TimelineController`
already has the room with its `room(&self) -> &Room` method. This method
was always used to fetch the room, let's expect `retry_event_decryption`
to do that by itself.

It also prevents passing the “wrong” room. This is more robust this way.
2025-03-14 14:18:21 +01:00
Ivan Enderlin
5a22944f52 chore(ui): Move an inline comment.
This patch moves an inline comment in its correct place. Code
was inserted between the comment and the part of the code it was
documenting.
2025-03-14 10:51:49 +01:00
Ivan Enderlin
494f93d2a4 chore(ui): Move the RoomKeyInfo task inside its own function.
This patch moves the task responsibles to handle the `RoomKeyInfo`
updates into its own function.

The goal is to get simpler code.
2025-03-14 10:51:49 +01:00
Ivan Enderlin
d7849a1aa5 chore(ui): Move the BackupState task inside its own function.
This patch moves the task responsibles to handle the `BackupState`
updates into its own function.

The goal is to get simpler code.
2025-03-14 10:51:49 +01:00
Ivan Enderlin
bc9adaab06 chore(ui): Move the rooms keys from backups task inside its own function.
This patch moves the task responsibles to handle the room keys from
backups into its own function.

The goal is to get simpler code.
2025-03-14 10:51:49 +01:00
Ivan Enderlin
1ec47ca24f chore(ui): Move the RoomSendQueueUpdate task inside its own function.
This patch moves the task responsibles to handle the
`RoomSendQueueUpdate`s into its own function.

The goal is to get simpler code.
2025-03-14 10:51:49 +01:00
Ivan Enderlin
faa2fa2ef0 chore(ui): Move the pinned event IDs stream task inside its own function.
This patch moves the task responsibles to handle the pinned event IDs
stream into its own function.

The goal is to get simpler code.
2025-03-14 10:51:49 +01:00
Ivan Enderlin
33e8b453ee chore(ui): Move the RoomEventCacheUpdate task inside its own function.
This patch moves the task responsibles to handle the
`RoomEventCacheUpdate`s into its own function.

The goal is to get simpler code.
2025-03-14 10:51:49 +01:00
Ivan Enderlin
b9fadd0a10 fix(base): Do not define the RoomInfoNotableUpdate's channel based on number of rooms.
When `BaseClient` is created, the rooms aren't loaded yet. Then,
calculating the size of the channel for `RoomInfoNotableUpdate` is
useless, as it will always be zero, and we will fallback to 500 every
time. By the way, 500 is a nice default. This patch uses this value as
the only channel's size.
2025-03-14 10:43:12 +01:00
Richard van der Hoff
294fd79947 multiverse: support passing a server URL
Allow use of a server url (eg `http://localhost:8008`), enabling connection to
a local server rather than one which supports well-known, TLS, and the rest.
2025-03-13 20:16:54 +01:00
Ivan Enderlin
8b6096729c fix(sdk): event_cache::Room::replace_all_events_by takes an EventsOrigin.
This patch updates `replace_all_events_by` to take an `EventsOrigin`.
It is called in two places: by `add_initial_events`, in which case it
is `EventsOrigin::Cache`, and by `handle_timeline`, in which case it is
`EventsOrigin::Sync`.
2025-03-13 09:23:24 +01:00
Ivan Enderlin
6f370daaed fix(sdk): Replace assert! by debug_assert!.
This patch replaces a call to `assert_eq` and `assert` by
`debug_assert_eq` and `debug_assert`. We don't want to panic in
production :-].
2025-03-13 09:23:24 +01:00
Ivan Enderlin
3c694e7909 fix(sdk): event_cache::Room::clear sends EventsOrigin::Cache.
This patch updates the `EventsOrigin` value sent by `Room::clear` to be
`Cache` instead of `Sync`. No events are added, but the `VectorDiff`s
are generated from the event cache itself, not from a sync.
2025-03-13 09:23:24 +01:00
Ivan Enderlin
c3245a4f22 fix(sdk): Events loaded from the cache have EventsOrigin::Cache.
This patch fixes the `EventsOrigin` value for events loaded from the
cache, it was `Pagination`, now it is `Cache`.
2025-03-13 09:23:24 +01:00
Ivan Enderlin
da89a53605 feat(ui): Add EventItemOrigin::Cache.
With more and more events coming from the event cache, it's nice to know
that an event actually from the cache instead of having `None`.
2025-03-13 09:23:24 +01:00
Ivan Enderlin
968582af01 chore(ui): Update a log message.
This patch changes the log message. A `TimelineItemPosition::UpdateAt`
can only happen for remote event, not local event. The log message
was talking about _decryption_ but an `UpdateAt` can also happen for
redaction. This was misleading.
2025-03-13 09:23:24 +01:00
Ivan Enderlin
07c7b6ab2a fix(ui): Pass the correct RemoteEventOrigin to replace_with_initial_remote_events.
This patch updates the `RemoteEventOrigin` value passed to
`TimelineController::replace_with_initial_remote_events` when there is
a lag with the event cache. The previous value was `Sync`, but it should
be `Cache` since these events come from the event _cache_ (it was in the
name, easy).
2025-03-13 09:23:24 +01:00
Ivan Enderlin
5aae0cbcd9 test: Fix a test in NotificationClient.
With the previous patch, `NotificationClient` with sliding sync now
knows immediately when the room is encrypted or not.
2025-03-12 16:53:59 +01:00
Ivan Enderlin
3ea842dae4 test(base): Test that room encryption is correctly computed. 2025-03-12 16:53:59 +01:00
Ivan Enderlin
31e0bfa400 feat: Install RequestedRequiredStates and add handle_encryption_state.
This patch updates the sync code to include the
`RequestedRequiredStates` type.

This patch also adds `RoomInfo::handle_encryption_state` which
is able to mark an encryption state as synced depending of
`RequestedRequiredStates` (read the comment in the code).

This patch also updates the documentation of
`RoomInfo::handle_state_event` to clarify the impact of a
`m.room.encryption` state event.
2025-03-12 16:53:59 +01:00
Ivan Enderlin
d32b10de80 feat: Introduce RequestedRequiredStates.
This patch introduces a new type: `RequestedRequiredStates`, which keeps
track of all `required_states` passed to a sync request. So far, there
is only a `From` implementation for MSC4186.
2025-03-12 16:53:59 +01:00
Kévin Commaille
215853cf67 chore: Upgrade ruma
To pull in`GrantType::DeviceCode` and a fix for the generated `DeviceId`
length.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-03-12 13:41:40 +01:00
Jorge Martín
a941cc824d fix(ffi): Restore some needed OIDC prompts in the FFI layer
These prompts were used in the Element X app, probably in some other clients too.

Since Ruma removed these cases, we're just passing them as `_Custom(value)` ones, which do work.
2025-03-12 13:12:09 +01:00
Benjamin Bouvier
d3daa18bf8 feat!(ffi): rename setup_tracing into init_platform (#4790)
And make it take a boolean indicating whether we want to set up a
lightweight tokio runtime or not, instead of having
`setup_lightweight_tokio_runtime` as a public function + another
function, both of which would have to be called anyways.

cc @stefanceriu @jmartinesp
2025-03-12 09:41:01 +00:00
Ivan Enderlin
2ac3b6e9a2 chore(ffi): Remove useless block_on.
This patch removes the last `block_on` calls in `matrix-sdk-ffi`. Those
are artifacts of the past.
2025-03-11 16:37:44 +01:00
Benjamin Bouvier
e81817c1b2 chore(ci): add new exceptions for cargo-deny 2025-03-11 16:05:52 +01:00
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