Commit Graph

6992 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
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
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
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
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
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
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
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
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