Commit Graph

6925 Commits

Author SHA1 Message Date
Jonas Platte
a5a541ec98 ui: Improve comment in redaction code
(move it to a more logical place)
2023-08-21 15:54:25 +02:00
Jonas Platte
d395648165 ui: Remove outdated comment
The relevant decryption work is already done in a separate async task,
spawned in `TimelineInner::retry_event_decryption_inner`.
2023-08-21 15:00:00 +02:00
Benjamin Bouvier
f5ab1084eb fix: temporarily use the pip install method for the setup-matrix-synapse action
Until https://github.com/michaelkaye/setup-matrix-synapse/issues/95 is properly resolved.
2023-08-21 11:54:25 +02:00
Benjamin Bouvier
81daf5c90a test(sliding sync): add test that caused a deadlock before this PR 2023-08-21 11:48:51 +02:00
Benjamin Bouvier
c0b18c291d chore: make clippy happy 2023-08-21 11:48:51 +02:00
Benjamin Bouvier
6988bd1e6f feat(sliding sync): remove the response_handling_lock and extend the position's lock responsibilities
In the previous situation, we had two locks with similar responsibilities, the `response_handling_lock`
and the `position` lock. The latter *almost* covered the former's critical zone, albeit for a single
function call, which left room for a deadlock situation (latter taken, then former, then latter).

This removes the former, and extends the critical zone of the latter up to the end of the response handling,
removing the possibility of the deadlock entirely.
2023-08-21 11:48:51 +02:00
Ivan Enderlin
54771eadcf fix(ffi): Fix a keyword conflict with Swift
fix(ffi): Fix a keyword conflict with Swift
2023-08-21 11:35:09 +02:00
Ivan Enderlin
64f3bc674e feat(ui): Create a new normalized_match_room_name filter
feat(ui): Create a new `normalized_match_room_name` filter
2023-08-21 11:27:53 +02:00
Ivan Enderlin
b78372d4bb chore(cargo): Update UniFFI. 2023-08-21 11:07:32 +02:00
Ivan Enderlin
102482c6e3 fix(ffi): Fix a keyword conflict with Swift. 2023-08-21 10:32:33 +02:00
Ivan Enderlin
9973d30700 feat(ffi): Implement RoomListEntriesDynamicFilterKind::NormalizedMatchRoomName. 2023-08-21 10:22:06 +02:00
Ivan Enderlin
2821807e14 feat(ui): Create a new normalized_match_room_name filter.
This patch creates a new `normalized_match_room_name` filter for
`RoomListService`.
2023-08-21 10:19:20 +02:00
Ivan Enderlin
14f8b33136 Merge pull request #2425 from matrix-org/jonny/message-content-from-html
Add binding to create message events from HTML
2023-08-21 09:48:35 +02:00
Ivan Enderlin
e9a9382b2b RoomInfo: Remove is_encrypted use sliding sync room avatars
RoomInfo: Remove is_encrypted use sliding sync room avatars
2023-08-21 09:43:05 +02:00
jonnyandrew
5497a8de2c Add binding to create message event from HTML 2023-08-18 16:03:03 +01:00
Stefan Ceriu
531d1d9761 Read the room avatar URL from the RoomListService room instead of the SDK room so that DMs are populated correcty 2023-08-18 17:54:23 +03:00
Benjamin Bouvier
88018c259f Revert upgrade to uniffi since it broke generation of swift bindings 2023-08-18 12:07:36 +02:00
Stefan Ceriu
531d8d220d Remove is_encrypted from room info as it's not used and it might do network calls and slow down room list updates 2023-08-18 11:36:01 +03:00
Ivan Enderlin
d077892ad4 chore(uniffi): Update uniffi to another branch
chore(uniffi): Update `uniffi` to another branch
2023-08-17 18:29:05 +02:00
Ivan Enderlin
cc46417ec5 Merge branch 'main' into hywan/fix-android-uniffi-async-bis 2023-08-17 18:27:54 +02:00
Ivan Enderlin
4d7f951128 chore(cargo): Update UniFFI to main (specific commit). 2023-08-17 18:26:21 +02:00
Ivan Enderlin
92284a353e feat(sdk): SlidingSync is able to “ignore” some errors
feat(sdk): `SlidingSync` is able to “ignore” some errors
2023-08-17 16:50:12 +02:00
Ivan Enderlin
73bb46b5ea Revert "feat(sdk): SlidingSync makes timed out silent."
This reverts commit 9b811009e1.

We have realized that the server might not handle timeouts as expected.
Thus, it's hard to know the difference between network timeout and poll
timeout (resp. the server is unreachable vs. the server has nothing to
respond with). We will come back on this later.
2023-08-17 16:27:12 +02:00
Ivan Enderlin
9b811009e1 feat(sdk): SlidingSync makes timed out silent.
As a sequel of the previous commit (d4cbcd397d), this patch updates
`SlidingSync` to “ignore” timeouts, i.e. timeouts aren't reported to the
caller, and aren't stopping the sync-loop.
2023-08-17 15:37:25 +02:00
Ivan Enderlin
d4cbcd397d feat(sdk): SlidingSync is able to ignore some errors.
All errors inside `SlidingSync` are stopping the sync-loop, and errors
are returned to the caller. However, in some situation, some errors
should be ignored, i.e. they should not stop the sync-loop and they
should not be returned to the caller: the sync-loop just continues to
run. This patch does that for `Error::ResponseAlreadyReceived`. More
errors will come.

Why is it annoying? When `matrix_sdk_ui::SyncService` sees an error,
it stops all the sync-loops (`RoomListService`, `EncryptionSync`…) and
restarts them properly. In the case of `Error::ResponseAlreadyReceived`,
this is a waste of time and resources. This error is an error from the
`SlidingSync` point of view, but _not_ from the caller point of view.
2023-08-17 15:35:51 +02:00
Ivan Enderlin
932b9dee6b fix(base): Detect left room in SlidingSyncResponse
fix(base): Detect left room in `SlidingSyncResponse`
2023-08-17 15:32:58 +02:00
Ivan Enderlin
2c9981050a fix(sdk): Preventing starting a new request if the previous didn't finish
fix(sdk): Preventing starting a new request if the previous didn't finish
2023-08-17 15:29:58 +02:00
Ivan Enderlin
2a6fc16549 chore: Use serde::Raw without any feature flag. 2023-08-17 14:30:25 +02:00
Ivan Enderlin
1aef72d105 feat(base): Left room are stored in the leave list in SlidingSync.
This patch updates the `BaseClient::process_sliding_sync` method to put
the `LeftRoom` in the `SyncResponse::leave` list.

To achieve so, this patch updates
`BaseClient::process_sliding_sync_room` to returns `Option<JoinedRoom>`,
`Option<LeftRoom>` and `Option<InvitedRoom>` (previously, it was only
`JoinedRoom` and `Option<InvitedRoom>`).
2023-08-17 14:30:25 +02:00
Ivan Enderlin
acc2601c5b feat(base): Look for state events in timeline for SlidingSync.
SlidingSync emits state events inside `required_state`, but _also_
sometimes inside `timeline`! This patch looks for state events inside
both entries.

The rest of the patch is composed of tests.
2023-08-17 14:30:25 +02:00
Jonas Platte
47e7360b04 ffi: Add RoomInfo 2023-08-17 12:49:03 +02:00
Jonas Platte
9b803eda12 ffi: Merge impl blocks 2023-08-17 12:49:03 +02:00
Ivan Enderlin
d946664cf0 doc(sdk): Fix a typo. 2023-08-17 11:56:21 +02:00
Ivan Enderlin
f9f12c2b89 fix(sdk): Preventing starting a new request if the previous didn't finish.
Imagine the following scenario:

A request $R_1$ is sent. A response $S_1$ is received and is being
handled. In the meantime, the sync-loop is instructed to skip over any
remaining work in its iteration and to jump to the next iteration. As a
consequence, $S_1$ is detached, but continues to run. In the meantime, a
new request $R_2$ starts. Since $S_1$  has _not_ finished to be handled,
the `pos` isn't updated yet, and $R_2$ starts with the _same_ `pos`
as $R_1$.

The impacts are the following:

1. Since the `pos` is the same, even if some parameters are different,
   the server will reply with the same response. It's a waste of time
   and resources (incl. network).
2. Receiving the same response could have corrupt the state. It has been
   fixed in https://github.com/matrix-org/matrix-rust-sdk/pull/2395
   though.

Point 2 has been addressed, but point 1 remains to be addresed. This
patch fixes point 1.

How? It changes the `RwLock` around `SlidingSyncInner::position` to
a `Mutex`. An `OwnedMutexGuard` is fetched by locking the mutex when
the request is generated (i.e. when `pos` is read to be put in the new
request). This `OwnedMutexGuard` is kept during the entire lifetime
of the request extend to the response handling. It is dropped/released
when the response has been fully handled, or if any error happens along
the process.

It means that it's impossible for a new request to be generated and to
be sent if a request and response is running. It solves point 1 in case
of successful response, otherwise the `pos` isn't updated because of
an error.
2023-08-17 10:09:21 +02:00
Ivan Enderlin
2718176eab chore(sdk): Move response_handling_lock inside SlidingSyncInner.
This patch moves `SlidingSync::response_handling_lock` inside
`SlidingSyncInner`. There is no reason why it's stored inside
`SlidingSync`.
2023-08-17 09:16:25 +02:00
Ivan Enderlin
db9012a45e feat(base): Improve Client::deserialize_events.
This patch first off renames `Client::deserialize_events` as
`Client::deserialize_state_events`. Then, this patch initially updated
the return type of this method from `Vec<Option<_>>` to `Vec<_>` to
filter out events that failed to deserialize. The patch ultimately
updates the return type of this method to `Vec<(Raw<_>, _)>`, so that
the raw state events that map to the state event are collected too (this
is required for making `Client::handle_state` to work correctly if an
event failed to deserialized). Finally, the rest of the patch updates
the code accordingly.
2023-08-16 11:29:35 +02:00
Kévin Commaille
0dac5080c6 experimental: Expose an OpenID Connect API
Co-authored-by: Doug <6060466+pixlwave@users.noreply.github.com>
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-08-16 10:39:18 +02:00
Ivan Enderlin
6c2d596603 test(sdk): Test members count.
This patch improves some existing tests, and adds more test for members
count.
2023-08-14 18:04:41 +02:00
Ivan Enderlin
758c3f7901 chore(ui): Improve error description for Error::SlidingSync
chore(ui): Improve error description for `Error::SlidingSync`
2023-08-14 15:33:39 +02:00
Ivan Enderlin
bbe4df9cd6 chore(ui): Improve error description for Error::SlidingSync.
`matrix_sdk_ui::room_list_service::Error` has a `SlidingSync` variant to
report errors from `matrix_sdk::sliding_sync::Error` (to be more exact,
from `matrix_sdk::Error::SlidingSync`).

This patch updates the error message from `SlidingSync failed` to
`SlidingSync failed: <explanation>`, where `<explanation>` is the
`Display` representation of the inner error.

It will help to provide more details to the end-user when looking at
logs.
2023-08-14 15:03:38 +02:00
Ivan Enderlin
3b8f0c9a60 chore(ui): Raise a trace log into an error
chore(ui): Raise a `trace` log into an `error`
2023-08-14 14:42:25 +02:00
Ivan Enderlin
b9d74d3643 feat(ui): Room::latest_event returns the Timeline local event if any
feat(ui): `Room::latest_event` returns the `Timeline` local event if any
2023-08-14 13:56:51 +02:00
Ivan Enderlin
061f8534c8 doc(ui): Update the comment of Room::latest_event. 2023-08-14 13:36:08 +02:00
Ivan Enderlin
6a7caa7257 Revert "feat(ui): Room::latest_event uses Timeline if it exists."
This reverts commit 2290bae942.
2023-08-14 13:27:56 +02:00
Ivan Enderlin
f937920007 chore(ui): Raise a trace log into an warning.
The issue https://github.com/matrix-org/sliding-sync/issues/3 has been
fixed. It's safe to raise the `trace!` into an `warn!` now.
2023-08-14 13:24:28 +02:00
Ivan Enderlin
924033ed9c test(ui): Improve the remote_echo_full_trip test
test(ui): Improve the `remote_echo_full_trip` test
2023-08-14 13:23:02 +02:00
Ivan Enderlin
c192343495 test(ui): Improve the remote_echo_full_trip test.
This patch improves the `remote_echo_full_trip` `Timeline` test to
ensure that until the event reaches the `Sent` state, it is indeed a
local echo.
2023-08-14 12:54:45 +02:00
Damir Jelić
4643bae284 Eliminate a race condition in the Room::request_encryption_state method
The Room::request_encryption_state method employs a DashMap to uphold a
lock, facilitating the de-duplication of requests directed to the server.

The de-duplication logic involves creating a fresh Mutex and embedding
it into the DashMap through these stages:

    1. Generate a new de-duplication mutex.
    2. Insert a mutex copy into the DashMap.
    2. Acquire the mutex.

Due to DashMap's limitation of enabling map locking solely during
insertion (step 1), a race condition emerges. Consequently, multiple
invocations of the Room::request_encryption_state method might
concurrently endeavor to insert the de-duplication mutex.

This commit removes the chance of such a race. It substitutes the
DashMap with a combination of a mutex and a BTreeMap. This adaptation
permits us to lock the map throughout all three specified operations.
2023-08-11 13:58:12 +02:00
Damir Jelić
f3dd161b3a Resolve a bug causing incorrect results in Room::is_encrypted
This commit addresses a bug in the Room::is_encrypted functionality.
The issue stems from the Room::request_encryption_state method, which
Room::is_encrypted relies on. This method incorporates a de-duplication
mechanism to ensure that only a single request for the m.room.encryption
state event is made to the server.

Due to this de-duplication mechanism, Room::request_encryption_state
follows two code paths. One path receives the state event from the
server, while the other path merely waits for the first path to complete.

The primary goal of the Room::request_encryption_state method is to
furnish the requested state event. However, because the second code path
doesn't receive any content, it returns an Option.

The problem arises when Room::is_encrypted evaluates this Option. It
erroneously determines that if the Option is None, encryption remains
inactive for the room.

To rectify this, the commit proposes that Room::is_encrypted analyze the
information stored in the in-memory RoomInfo, which is maintained by the
Room::request_encryption_state method. This approach mirrors the existing
behavior of Room::is_encrypted when it processes the code path where the
m.room.encryption state event has already been retrieved.
2023-08-11 13:58:12 +02:00
Damir Jelić
bd1b6e7a27 Instrument the Room::send_raw method 2023-08-11 13:58:12 +02:00