Commit Graph

11131 Commits

Author SHA1 Message Date
Benjamin Bouvier
e5f6d026ff ci: use an hardcoded version of cargo-machete in CI (#4710)
Should resolve the CI issues around cargo-machete.

See also:
https://github.com/bnjbvr/cargo-machete/issues/156#issuecomment-2681308436
2025-02-25 11:35:18 +01:00
Benjamin Bouvier
5dd5710758 feat(event cache): auto-shrink a room event cache's chunk after all listeners are left matrix-sdk-ffi/20252502 2025-02-24 17:40:50 +01:00
Ivan Enderlin
37b62dfed1 test(sdk): Add a big test for a deduplication + event removals.
This patch adds a test for deduplication that covers unloaded and loaded
chunk with event removals in both, with a finaly backwards pagination.
Yummy.
2025-02-24 17:37:47 +01:00
Ivan Enderlin
d21a4152de chore(sdk): Code cleanup.
This patch puts the `Ok` outside the `match` for a better ergonomics.
2025-02-24 17:37:47 +01:00
Ivan Enderlin
8c2dcd7b5d task(sdk): Make the code more robust around event removals.
This patch makes the code more robust around event removals. Sorting
events by their position is no longer done in the `Deduplicator` but in
a new `RoomEventCacheState::remove_events` method, which removes events
in the store and in the `RoomEvents`. This method is responsible to sort
events, this stuff is less fragile like so.
2025-02-24 17:37:47 +01:00
Ivan Enderlin
019b4a20f6 chore(common): Rename EmptyChunk to EmptyChunkRule.
This patch renames `EmptyChunk` into `EmptyChunkRule`. Name suggested by
@stefanceriu, it makes a lot more sense, thanks!
2025-02-24 17:37:47 +01:00
Ivan Enderlin
30a9a972ce tes(sdk): Deduplicator dispatches duplicated events in memory vs in store.
This patch tests that `Deduplicator` dispatches duplicated events in the
correct field of `DeduplicationOutcome`.
2025-02-24 17:37:47 +01:00
Ivan Enderlin
22ba1684b2 chore(sdk): Rename a test helper and some variables.
Nothing fancy here. Just regular chore tasks.
2025-02-24 17:37:47 +01:00
Ivan Enderlin
0b12ec2b38 test(sdk): Deduplicator excludes invalid events.
This patch adds a test ensuring that `Deduplicator` excludes invalid
events, i.e. event with no ID.
2025-02-24 17:37:47 +01:00
Ivan Enderlin
a71f5bf21f test(sdk): Test Deduplicator filters events in the input.
This patch adds a test ensuring that `Deduplicator` is able to find
duplicates in its own inputs.
2025-02-24 17:37:47 +01:00
Ivan Enderlin
9bd7cfda5f test(sdk): Rename a test. 2025-02-24 17:37:47 +01:00
Ivan Enderlin
c1a13f7f98 test(sdk): Test sort_events_by_position_descending.
This patch adds a test for `sort_events_by_position_descending`. It
also updates this function so that events are sorted by their chunk
identifier from newest to oldest, it makes no difference but it matches
the order of the position indices too. Everything “dimension” is
descending.
2025-02-24 17:37:47 +01:00
Ivan Enderlin
a362584bb3 task(sdk): Use DeduplicationOutcome to remove events in their correct place.
This patch uses `DeduplicationOutcome` to remove events either in
memory, or in the store, when required. The `remove_events_by_id` method
has been renamed `remove_events_by_position`.
2025-02-24 17:37:47 +01:00
Ivan Enderlin
f9ce7628ff task(sdk): Redesign Deduplicator::filter_duplicate_events.
This patch redesigns `Deduplicator::filter_duplicate_events`.

First off, `filter_duplicate_events` does remove events with no valid
ID. At the same time, it removes duplicate events within the new events
(`events`). This check was done in the `BloomFilterDeduplicator` but
not in the `StoreDeduplicator`. Now it's done at the front of these
implementations, directly inside `Deduplicator`.

Second, this patch introduces `DeduplicationOutcome` to replace the
return type `(Vec<Event>, Vec<OwnedEventId>)`, especially because
now it would have become `(Vec<Event>, Vec<(OwnedEventId, Position)>,
Vec<(OwnedEventId, Position)>)`. Why?

1. Because the positions of the duplicated events are returned,
2. We differentiate between in-memory vs. in-store duplicated events.

Third, now there are positions associated to duplicated events, events
must be sorted. It's the role of `sort_events_by_position_descending`.

This way, `DeduplicatorOutcome` brings guarantees and less checks are
required.
2025-02-24 17:37:47 +01:00
Ivan Enderlin
43c066e837 task(base): EventCacheStore::filter_duplicated_events returns Position.
This patch changes `EventCacheStore::filter_duplicated_events` to return
the `Position` of the duplicated event.
2025-02-24 17:37:47 +01:00
Benjamin Bouvier
f3f37a33fd fix(event cache): override reached_start when there's a mismatch between network and disk
It could be that we have a mismatch between network and disk, after
running a back-pagination:

- network indicates start of the timeline, aka there's no previous-batch
token
- but in the persisted storage, we do have an initial empty events chunk

Because of this, we could have weird transitions from "I've reached the
start of the room" to "I haven't actually reached it", if calling the
`run_backwards()` method manually.

This patch rewrites the logic when returning `reached_start`, so that
it's more precise:

- when reloading an events chunk from disk, rely on the previous chunk
property to indicate whether we've reached the start of the timeline,
thus avoiding unnecessary calls to back-paginations.
- after resolving a gap via the network, override the result of
`reached_start` with a boolean that indicates 1. there are no more gaps
and 2. there's no previous chunk (actual previous or lazily-loaded).

In the future, we should consider NOT having empty events chunks, if we
can.
2025-02-24 14:47:21 +01:00
Benjamin Bouvier
39c6481f96 feat(event cache): include the lazy previous chunk in the debug string, if available 2025-02-24 14:47:21 +01:00
Benjamin Bouvier
66b9d334ef feat(event cache): shrink the linked chunk upon gappy syncs 2025-02-24 14:47:21 +01:00
Benjamin Bouvier
e64cb2c4f1 feat(event cache): implement RoomEventCacheState::shrink_to_last_chunk 2025-02-24 14:47:21 +01:00
Benjamin Bouvier
4f47868930 feat(linked chunk): allow replacing a linked chunk's content with a raw chunk 2025-02-24 14:47:21 +01:00
Benjamin Bouvier
4c115b6ad5 feat(event cache): don't store a gap if we've deduplicated all events during sync 2025-02-24 14:47:21 +01:00
Benjamin Bouvier
242a1047bd doc(event cache): clarify that RoomEvents::updates() is only for storage updates
And rename it accordingly to `RoomEvents::store_updates`.

Note: no changelog, because this is an internal API only.
2025-02-24 14:47:21 +01:00
Kévin Commaille
2f3cab431f chore: Add changelog for Oidc::logout
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-02-24 14:19:48 +01:00
Kévin Commaille
55f514897b refactor(oidc): Only revoke one token for logout
The server is supposed to revoke any token associated with the token that we revoke.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-02-24 14:19:48 +01:00
Kévin Commaille
d4b92de8e4 refactor(oidc): Remove support for OIDC RP-Initiated logout
Token revocation was split out from MSC2964 to MSC4254, and RP-Initiated
logout is now mentioned only as an alternative.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-02-24 14:19:48 +01:00
Kévin Commaille
25d39997a4 chore: Add changelog for moving qrcode module
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-02-24 13:39:23 +01:00
Kévin Commaille
254ce8923b refactor(oidc): Use OidcBackend with LoginWithQrCode
Will allow to share code when the backend is switched to the oauth2 crate too.

It will also allow to expose the device authorization grant directly in Oidc, if necessary.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-02-24 13:39:23 +01:00
Kévin Commaille
0a4db305b9 refactor(oidc): Move qrcode module inside oidc
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-02-24 13:39:23 +01:00
Benjamin Bouvier
90ac2181e9 test: rename some MatrixMockServer helpers functions to make it clear they're matchers
The `.from()`, `.with_delay()` and `.limit()` functions are not very
explicit about what they did, and the `with_delay` one in particular led
me to think that it would introduce a delay *in the response*, while it
indicated a delay was expected as part of the matched URL.

Instead, this patch proposes to prefix all matchers with `match_`, to
make it clearer that… they will match the incoming query: match_from,
match_delay, match_limit.

Thanks to this change, the `RoomMessagesResponseTemplate` can be renamed
from `delayed` to `with_delay`, which was my original intent, before I
noticed another `with_delay` with totally different semantics.
2025-02-24 11:09:25 +01:00
Ivan Enderlin
bdf5fad992 chore(common): Remove LinkedChunkBuilderTest.
This patch removes `LinkedChunkBuilderTest` and updates tests
accordingly.
2025-02-21 12:06:08 +01:00
Ivan Enderlin
05be62183a task: Remove all usages of LinkedChunkBuilderTest.
This patch replaces all usages of `LinkedChunkBuilderTest` by
`from_all_chunks`.
2025-02-21 12:06:08 +01:00
Ivan Enderlin
d545419684 test(common): Add lazy_loader::from_all_chunks.
This patch adds the new `from_all_chunks` function in the
`linked_chunk::lazy_loader` module. It is only used for testing
purposes. It aims at replacing `LinkedChunkBuilderTest` (see next
patches). Why? Because `from_all_chunks` uses `from_last_chunk` and
`insert_new_first_chunk`: if `from_all_chunks` is able to find all
errors that `LinkedChunkBuilderTest` finds, it's a bingo. Transitively,
it proves that `from_last_chunk` and `insert_new_first_chunk` are
correct!
2025-02-21 12:06:08 +01:00
Jonas Platte
f900db49dd feat(sdk): Re-export the base crate's store module
Fixes a broken intra-doc link.
2025-02-21 09:36:50 +01:00
Jonas Platte
1373f99288 refactor: Use NonZeroUsize::new + unwrap in const contexts
Make clippy happy.
2025-02-21 09:36:50 +01:00
Jonas Platte
f56bc4c0d6 chore: Bump nightly 2025-02-21 09:36:50 +01:00
Benjamin Bouvier
60efcbc55d refactor(event cache): use Option<&mut> in Chunk::insert_before 2025-02-20 16:28:22 +01:00
Benjamin Bouvier
30589ca899 refactor(event cache): use Option<&mut> in Chunk::unlink 2025-02-20 16:28:22 +01:00
Damir Jelić
61fa339163 refactor(crypto): Add a constructor to create an InboundGroupSession from a m.room_key event 2025-02-20 12:28:45 +01:00
Damir Jelić
3f5efc1ff6 docs(crypto): Update some docs for the InboundGroupSession 2025-02-20 12:28:45 +01:00
Ivan Enderlin
23f72ba15f test(common): Test ability for AsVector to generate several VectorDiff::Remove.
This patch adds a test ensuring that `AsVector` generates the correct
`VectorDiff::Remove` when a non-empty chunk is removed.
2025-02-20 10:52:59 +01:00
Ivan Enderlin
a25acf7e62 feat(common): Update::RemoveChunk emits VectorDiff::Remove.
This patch updates `Update::RemoveChunk` to emit `VectorDiff::Remove`.
Until now, `RemoveChunk` was expecting the chunk to be
empty, because it is how it is used so far. However, with
https://github.com/matrix-org/matrix-rust-sdk/pull/4694, it can change
rapidly.
2025-02-20 10:52:59 +01:00
Benjamin Bouvier
c3fc310f29 refactor(event cache): simplify back-pagination 2025-02-20 10:51:06 +01:00
Benjamin Bouvier
b9c7ffe7c3 doc(timeline): tweak comment in pagination to explain why it's correct 2025-02-20 10:51:06 +01:00
Benjamin Bouvier
017a947fc1 doc(timeline): fix a broken link to all_remote_events 2025-02-20 10:01:57 +01:00
Benjamin Bouvier
5c57631a6c refactor(event cache): simplify flow when deciding to resolve a gap
The code before this patch was doing this:

- look if there's any prev-batch token available right now, aka look if
there's a gap in the in-memory linked chunk
- look at the first chunk; if it's a gap, return to the caller so it
resolves it

The check is done twice at two different levels, which is confusing.
Instead, this patch rewrites it so that the chunk is done only in
`load_more_event_backwards()`.

Note this is also correct for the case storage is disabled; in this
case, we early return and always try to resolve the gap anyways.
2025-02-19 15:39:58 +01:00
Ivan Enderlin
3495cab7ad refactor(common): builder::LinkedChunkBuilder::* becomes lazy_loader::*.
This patch renames the `builder` module to `lazy_loader`.
The `LinkedChunkBuilder`'s methods are now functions.
The `LinkedChunkBuilder` struct is removed. Finally,
`LinkedChunkBuilderError` is renamed `LazyLoaderError`.

The `LinkedChunkBuilderTest` struct is kept for the moment. It's going
to be replaced soon.
2025-02-19 14:38:56 +01:00
bitfriend
7a06bdb695 Rename snapshots to reduce filename length (#4625) 2025-02-19 13:29:51 +00:00
Ivan Enderlin
6c57003d17 feat(sqlite) Add an index on events.event_id and .room_id.
This patch adds an index on `events.event_id` and on `events.room_id`
so that queries on this column are faster. It mostly happens for the
`Deduplicator`, which runs for every backwards pagination or sync.

This patch also updates the query in `filter_duplicated_events` to
sort event by their `chunk_id` and `position` so that the results are
constant, it helps when testing.
2025-02-19 11:50:23 +01:00
Kévin Commaille
2eb2ae7959 refactor(oidc): Use the GET /auth_metadata Matrix endpoint (#4673)
This is the method to get the server metadata in the latest draft of
[MSC2965](https://github.com/matrix-org/matrix-spec-proposals/pull/2965).

We still keep the old behavior with `GET /auth_issuer` as fallback for
now because it has wider server support.

There are some pre-main commit cleanups to simplify the main commit.
This can be reviewed commit by commit.

The changes were tested with the oidc_cli example on beta.matrix.org.

Closes #4550.

---------

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-02-18 17:41:48 +01:00
Ivan Enderlin
a055aa3e57 chore(sdk): Fix comments and rename variables. 2025-02-18 17:13:12 +01:00