Commit Graph

9318 Commits

Author SHA1 Message Date
Benjamin Bouvier
61fb0aeafc timeline: move TimelineEventContext::encryption_info to the remote flow
Since it's only used for remote events, and a local echo couldn't figure
that out anyways (since it's not sent yet, and that information makes
sense after sending).
2024-07-10 17:41:00 +02:00
Benjamin Bouvier
9e9df163b9 timeline: remove duplicate set_fully_read_event that does the same as handle_fully_read_marker 2024-07-10 15:29:46 +02:00
Benjamin Bouvier
54c037ed03 timeline: add regression tests for adjusting day divider/read marker after cancelling a local echo 2024-07-10 15:29:46 +02:00
Benjamin Bouvier
7d16ca54f4 timeline: remove trailing read markers 2024-07-10 15:29:46 +02:00
Benjamin Bouvier
f96f55ccd9 timeline: move the handle_local_echo and handling of RoomSendQueueUpdate to TimelineInner
This will make testing easier.
2024-07-10 15:29:46 +02:00
Benjamin Bouvier
afa2e8063d timeline: adjust day divider and read marker items after a local echo has been edited or removed 2024-07-10 15:29:46 +02:00
Ivan Enderlin
25bb8e9d72 chore(base): Format doc. 2024-07-10 15:29:10 +02:00
Ivan Enderlin
c59ed5d877 feat(ui): RoomList is refreshed by RoomInfoNotableUpdateReasons::READ_RECEIPT.
This patch listens to `RoomInfoNotableUpdateReasons::READ_RECEIPT` to
update the `RoomLIst` stream.
2024-07-10 15:29:10 +02:00
Ivan Enderlin
396b7eff7d feat(base): New RoomInfoNotableUpdateReasons::READ_RECEIPT!
This patch adds the new `RoomInfoNotableUpdateReasons::READ_RECEIPT`
reason. It detects it and adds the test to ensure it's sent as expected.
2024-07-10 15:29:10 +02:00
Ivan Enderlin
a5702e92f1 test(base): Test RoomInfoNotableUpdateReason::RECENCY_TIMESTAMP is sent.
This patch adds a missing test to ensure that a
`RoomInfoNotableUpdateReason::RECENCY_TIMESTAMP` is correctly sent.
2024-07-10 15:29:10 +02:00
Ivan Enderlin
c4e45b5660 doc(base): Remove an outdated documentation information.
This patch removes the mention of a returned value whilst the function
returns nothing.
2024-07-10 15:29:10 +02:00
Andy Balaam
847bf5b974 Merge pull request #3677 from matrix-org/andybalaam/rename_msk_master_key
crypto: Rename msk to master_key for consistency with the wider codebase
2024-07-10 13:03:04 +01:00
Andy Balaam
0449ca89ce crypto: Rename msk to master_key for consistency with the wider codebase 2024-07-10 11:15:45 +01:00
Jorge Martin Espinosa
40343aa67e fix(sdk): force room member reload after inviting a user (#3672)
This is needed to prevent the race condition where the invite request finished, the `/sync` one didn't fetch the new membership event yet and we send a message in the room. This message won't be encrypted for the newly invited user and will result in an UTD.

I added a new integration test and I can confirm this [complement-crypto test](https://github.com/matrix-org/complement-crypto/pull/98) now passes instead of being skipped.

Fixes #3622.

---

* fix(sdk): force room member reload after inviting a user

This is needed to prevent the race condition where the invite request finished, the `/sync` one didn't fetch the new membership event yet and we send a message in the room. This message won't be encrypted for the newly invited user and will result in an UTD.

* Use `room.mark_members_missing()` instead, add integration test

* Abort syncing before the test ends

* Resolve nit: else after a return

* Fix race condition where bob may try to join the room before the invite is received

* Remove double sync
2024-07-10 10:01:50 +00:00
Benjamin Bouvier
625652e895 tests: get rid of the non_sync_events! macro 2024-07-10 12:00:17 +02:00
Ivan Enderlin
d78b6826b9 chore(sdk): Remove RoomListEntry and ops in Sliding Sync.
This patch removes everything related to the computation of `ops`
from a sliding sync response. With the recent `RoomList`'s client-side
sorting project, we no longer need to handle these `ops`. Moreover, the
simplified sliding sync specification that is coming removes the `ops`.

A `SlidingSyncList` was containing a `rooms` field. It's removed by
this patch. Consequently, all the `SlidingSyncList::room_list` and
`::room_list_stream` methods are also removed.

A `FrozenSlidingSyncList` was containing the `FrozenSlidingSyncRoom`.
This patch moves the `FrozenSlidingSyncRoom`s inside
`FrozenSlidingSync`. Why is it still correct? We only want to keep the
`SlidingSyncRoom::timeline_queue` in the cache for the moment (until
the `EventCache` has a persistent storage). Since a `SlidingSyncList`
no longer holds any information about the rooms, and since `SlidingSync`
itself has all the `SlidingSyncRoom`, this move is natural and still
valid.

Bye bye all this code :'-).
2024-07-10 11:44:07 +02:00
Benjamin Bouvier
e1fbfbe603 tests: get rid of EventBuilder::make_message_event_with_id 2024-07-10 11:39:16 +02:00
Benjamin Bouvier
a9a4d7b4c8 tests: get rid of EventBuilder::make_reaction_event and TestTimeline::handle_live_reaction 2024-07-10 11:39:16 +02:00
Benjamin Bouvier
8e90783f1f test(timeline): get rid of handle_live_message_event_with_id
The `EventFactory` can build events with a specific `event_id` already.
2024-07-10 11:39:16 +02:00
Benjamin Bouvier
a0a076a895 tests: get rid of EventBuilder::make_redaction_event and TestTimeline::handle_live_reaction
The `EventFactory` is improved to support creating those events too,
reducing the number of custom events creators everywhere.
2024-07-10 11:39:16 +02:00
Benjamin Bouvier
f7504b4ff2 test(timeline): remove "custom" in handle_back_paginated_custom_event 2024-07-10 11:39:16 +02:00
Benjamin Bouvier
d7cbd9d218 test(timeline): get rid of handle_back_paginated_message_event_with_id
Callers can make use of the `EventFactory` which is easier to understand
IMO, and that avoids a special testing function just for this.
2024-07-10 11:39:16 +02:00
Benjamin Bouvier
5a04f5b66a test(timeline): get rid of custom handle_live_event
This is `TimelineInner::add_events_at` with fixed parameters.
2024-07-10 11:39:16 +02:00
Benjamin Bouvier
3294a6c83a test(timeline): use handle_live_event instead of handle_live_custom_event
They're the same picture.</meme>
2024-07-10 11:39:16 +02:00
Richard van der Hoff
8d54bd92d1 crypto: Pass room id and session id to room_keys_withheld_received_stream (#3674) 2024-07-10 09:49:14 +01:00
Richard van der Hoff
2d3e2dab54 crypto: Expose new stream about room_key withheld messages (#3660)
Part of the fix to element-hq/element-web#27653.
2024-07-09 17:55:46 +00:00
Benjamin Bouvier
1bc044349e sdk: use a single field store both the server versions and the unstable features
The only thing is that our client builder allows setting only the server
versions, so this means the new field has to contain two `Option`al
fields. This causes a bit of churn, but isn't too bad in the end.
2024-07-09 12:37:33 +02:00
Benjamin Bouvier
2ca6a0e91e ffi: remove ability to set server versions in the ClientBuilder 👿 2024-07-09 12:37:33 +02:00
Benjamin Bouvier
19fcae4e0b sdk: add a way to reset the in-memory and on-disk caches for server capabilities
This required changing the OnceCell to RwLock<Option<>>, because a
OnceCell can't be reset to another value.
2024-07-09 12:37:33 +02:00
Benjamin Bouvier
a76b6faa9f sdk: cache after requesting server capabilities, and attempt to restore them from the cache later 2024-07-09 12:37:33 +02:00
Benjamin Bouvier
2785365b53 store: ServerCapabilities can decode to None if stale 2024-07-09 12:37:33 +02:00
Benjamin Bouvier
c7d1a7db4f store: save/restore server capabilities 2024-07-09 12:37:33 +02:00
Benjamin Bouvier
48fc80c643 sdk: fill both the server versions and unstable features when doing the /versions request 2024-07-09 12:37:33 +02:00
Benjamin Bouvier
96475b7f50 media: get rid of the TODO about ClientBuilder option to force use of auth endpoints
Fixes #3650.
2024-07-09 12:37:33 +02:00
Kegan Dougal
e5f92947e7 memory-store: release locks earlier to avoid deadlocks
I've been debugging a cause of flakey complement-crypto tests for
about a month now. I was pretty convinced it was deadlocking
somewhere in the memory store `save_changes` code. With additional
logging, it's now clear that the there is an ABBA style deadlock
when `save_changes` is called at the same time as `get_state_events`.

I've also adjusted code for `get_user_ids` as it has a very similar
pattern and also acquires locks in reverse order to `save_changes`,
so is potentially vulnerable to this.
2024-07-09 11:02:41 +02:00
Ivan Enderlin
02dddb47c9 fix(base) Move StateChanges::room_info_notable_changes into a standalone BTreeMap.
This patch extracts `StateChanges::room_info_notable_changes` as a
variable that is passed to `BaseClient::apply_changes`.
2024-07-08 18:47:55 +02:00
Ivan Enderlin
753606779b test(base): Update a test.
This patch updates a test to ensure calling
`Room::on_latest_event_decrypted` will emit a room info notable update
with the `LATEST_EVENT` reason.
2024-07-08 18:47:55 +02:00
Ivan Enderlin
4cf0d7a18b fix(ui): Emit a RoomInfoNotableUpdateReasons::RECENCY_TIMESTAMP ony for non-new rooms.
This patch avoids to emit a
`RoomInfoNotableUpdateReasons::RECENCY_TIMESTAMP` for rooms that are new.
Otherwise the entries in `matrix_sdk_ui::room_list_service::RoomList`
receive a `VectorDiff` because a new room is inserted, and then a
`VectorDiff` because the recency timestamp is updated. The second
`VectorDiff` is useless in this case.
2024-07-08 18:47:55 +02:00
Ivan Enderlin
ec7fa76240 feat(base): Revisit the roominfo_update API.
First off, this patch removes the
`RoomInfoNotableUpdate::trigger_room_list_update` field. It is replaced
by a `reasons: RoomInfoNotableUpdateReasons` 8-bit unsigned integer. It
addresses the following issues:

1. When a subscriber receives a `RoomInfoNotableUpdate`, they have no
   idea what has triggered this update.
2. In
   `matrix_sdk_base::sliding_sync::BaseClient::process_sliding_sync_e2ee`,
   we were triggering an update even if the latest event wasn't
   modified: it is a false-positive, it was a bug and a waste of
   resources. Now it's more refined, see the why below.

Second, this patch removes the second `trigger_room_list_update`
argument of `matrix_sdk_base::BaseClient::apply_changes`. This method
now knows where to find the reasons for the room info notable updates,
see next point.

Third, this patch adds a new
`matrix_sdk::StateChanges::room_info_notable_updates` field which is a
B-tree map between an `OwnedRoomId` and a
`RoomInfoNotableUpdateReasons`. The idea is that all places that receive
a `StateChanges` can also create a room info notable update with a
specific reason. This is a finer grained mechanism, and it avoids to
pass new arguments everywhere. It's cleaner.

Finally, it's easier than ever to add a new reason and to propagate it
to subscribers.
2024-07-08 18:47:55 +02:00
Ivan Enderlin
66e02f39ef chore(sdk): Rename RoomInfoUpdate into RoomInfoNotableUpdate.
The patch renames `RoomInfoUpdate` to `RoomInfoNotableUpdate`.
The functions, methods or variables whose names start with
`roominfo_update(.*)`` are renamed `room_info_notable_update$1`.
2024-07-08 18:47:55 +02:00
Ivan Enderlin
c8e05173e4 chore(base): Move imports under the correct feature flag.
Some imports are only required under `cfg(feature = "e2e-encryption")`.
Let's fix these warnings.
2024-07-08 18:47:55 +02:00
Johannes Marbach
8e0282ac4a ffi: expose methods for SSO login (#3558)
* ffi: expose methods for SSO login

Signed-off-by: Johannes Marbach <n0-0ne+github@mailbox.org>

* Update bindings/matrix-sdk-ffi/Cargo.toml

Co-authored-by: Ivan Enderlin <ivan@mnt.io>
Signed-off-by: Johannes Marbach <n0-0ne+github@mailbox.org>

* Refactor code to use a separate object to complete the SSO login

* Remove superfluous .workspace

* Remove superfluous field name

* Fix formatting with nightly toolchain

* Fix clippy errors using nightly toolchain

* Move SSO methods over into Client as AuthenticationService will go away very soon

* Add login tests

* Assign tokio runtime and url getter

* Reformat

* Relocate parts of the code as per review comments

* Add url to debugging representation of SsoHandler

* Add example for login_with_sso_callback

* Use unwrap_or_default to avoid creating empty string

* Remove leftover dependencies

---------

Signed-off-by: Johannes Marbach <n0-0ne+github@mailbox.org>
Co-authored-by: Ivan Enderlin <ivan@mnt.io>
2024-07-08 14:13:44 +02:00
Kegan Dougal
11cbf849cc base: adjust trace logging in memory store (#3659)
Now we have more information on which locks are implicated, refine the logs to identify the exact lock.
2024-07-05 11:48:49 +02:00
Richard van der Hoff
f9a19c5603 Merge pull request #3651 from matrix-org/rav/indexeddb_storage_efficiency_fix_bugs
indexeddb: fix bugs in serialization improvement
2024-07-05 10:43:53 +01:00
Richard van der Hoff
fac7221c7e Merge remote-tracking branch 'origin/main' into rav/indexeddb_storage_efficiency_fix_bugs 2024-07-05 10:29:24 +01:00
Benjamin Bouvier
d6300bbda7 http_client: log each attempt at sending a request, instead of a single one
When a request fails because of the exponential backoff, it won't be
re-logged again. It would be useful, for the purposes of the send queue
notably, to see when a request is re-attempted.
2024-07-04 18:32:44 +02:00
Benjamin Bouvier
b80c2f7197 timeline: use the previous content's membership info when it's missing from the current membership event
Synapse returns a bare `{ "membership": "leave" }` as the content of a
room membership event (for leave membership changes and likely others).
In this case, it'd still be nice to have some kind of display
name/avatar URL to show in UIs; it's possible to reuse information from
the previous member event, if available.
2024-07-04 17:09:34 +02:00
Jorge Martín
07b6425e10 ffi: Timeline::load_reply_details checks if the event exists locally
Before it would go fetch the event from the server using a network request.
2024-07-04 16:13:35 +02:00
Benjamin Kampmann
d49cb54b67 Allow to limit the number of concurrent requests made by the sdk (#3625)
Add a new `max_concurrent_requests` parameter in the `RequestConfig` limits the number of http(s) requests the internal sdk client issues concurrently (if > 0). The default behavior is the same as before: there is no limit on concurrent requests issued.

This is especially useful for resource constrained platforms (e.g. mobile platforms), and if your pattern might lead to issuing many requests at the same time (like downloading and caching all avatars at startup).

- [x] Public API changes documented in changelogs (optional)

Signed-off-by: Benjamin Kampmann <ben.kampmann@gmail.com>
2024-07-04 16:01:15 +02:00
Ivan Enderlin
aaccfdfea5 Merge pull request #3655 from matrix-org/jme/remove-is-encrypted-from-room-info
ffi: remove `is_encrypted` field from `RoomInfo`
2024-07-04 14:21:46 +02:00