Compare commits

...

2653 Commits

Author SHA1 Message Date
Damir Jelić bb573117e1 chore: Release matrix-sdk version 0.9.0 2024-12-18 15:12:23 +01:00
Andy Balaam ff7077b742 doc(crypto): Add changelog entry for #4424 2024-12-18 13:51:00 +00:00
Ivan Enderlin bb70229dd8 chore: Make Clippy happy. 2024-12-18 13:24:55 +01:00
Andy Balaam 03947618ff Merge branch 'release-for-crypto-wasm-11'
This brings in the fix for #4424 that we did on a release branch to
allow a quick release of crypto-wasm
2024-12-18 11:25:53 +00:00
Andy Balaam b18e7d71ed fix(crypto): Fix error when reading VerifiedStateOrBool with old PreviouslyVerifiedButNoLonger value 2024-12-18 11:22:53 +00:00
Andy Balaam 612ba6fa29 task(crypto): Accept old PreviouslyVerified value of ShieldStateCode when deserializing 2024-12-18 11:22:53 +00:00
Andy Balaam db39c6bea6 task(crypto): Accept old PreviouslyVerified value of VerificationLevel when deserializing 2024-12-18 11:22:53 +00:00
Andy Balaam 5f3b56a987 task(crypto): Accept old PreviouslyVerified value of SenderData when deserializing 2024-12-18 11:22:53 +00:00
Benjamin Bouvier 373709fb38 feat(event cache): don't replace a gap chunk by an empty items chunks 2024-12-17 18:30:57 +01:00
Benjamin Bouvier 5d8ad3a4a9 fix(linked chunk): in LinkedChunk::ritems_from, skip as long as we're on the right chunk
The previous code would skip based on the position's index, but not the
position's chunk. It could be that the position's chunk is different
from the first items chunk, as shown in the example, where the linked
chunk ends with a gap; in this case, the position's index would be 0,
while the first chunk found while iterating backwards had 3 items. As a
result, items 'd' and 'e' would be skipped incorrectly.

The fix is to take into account the chunk id when skipping over items.
2024-12-17 17:48:10 +01:00
Damir Jelić 0ca35d6c4a test: Test that room keys received by notification clients trigger redecryptions 2024-12-17 16:07:21 +01:00
Damir Jelić daeffc07b3 feat: Derive PartialEq and Eq for RoomListLoadingState 2024-12-17 16:07:21 +01:00
Damir Jelić bd15f4ecbe feat(timeline): Listen to the room keys stream to retry decryptions 2024-12-17 16:07:21 +01:00
Damir Jelić f17f4e2bf6 feat: Add a stream to listen to room keys being inserted to the store 2024-12-17 16:07:21 +01:00
Damir Jelić 177ec1216f feat(crypto)!: Don't ignore the error if the room_keys_received stream lags 2024-12-17 16:07:21 +01:00
Valere 512a2d2662 Merge pull request #4399 from matrix-org/valere/ffi_save_store_dehydration_pickle_key
feat(crypto-ffi-bindings): Save/Load dehydrated pickle key
2024-12-17 10:07:54 +01:00
Valere 95582a6c3c feat(crypto-bindings): Save/Load dehydrated pickle key
review: better tests
2024-12-17 09:51:28 +01:00
Jorge Martín 866b5fea40 feat(room): Separate RoomState::Banned from RoomState::Left.
This is needed to tell apart rooms in left and banned state in places like `RoomInfo` or `RoomPreview`.

The banned rooms will still count as left rooms in the sync processes.
2024-12-16 19:19:56 +01:00
Benjamin Bouvier 34ea42aec0 feat(ffi): expose the linked chunk debug string function at the FFI layer 2024-12-16 16:41:03 +01:00
Benjamin Bouvier cae7e43b91 feat(multiverse): add linked chunk debug screen in multiverse 2024-12-16 16:41:03 +01:00
Benjamin Bouvier 34d15a4d37 feat(event cache): propose a debug representation for the linked chunk in RoomEvents too 2024-12-16 16:41:03 +01:00
Benjamin Bouvier f6cb8186c6 task(event cache): limit the display of event ids to 8 chars in the raw chunk debug string 2024-12-16 16:41:03 +01:00
dependabot[bot] 47044b1a23 chore(deps): bump crate-ci/typos from 1.28.2 to 1.28.3
Bumps [crate-ci/typos](https://github.com/crate-ci/typos) from 1.28.2 to 1.28.3.
- [Release notes](https://github.com/crate-ci/typos/releases)
- [Changelog](https://github.com/crate-ci/typos/blob/master/CHANGELOG.md)
- [Commits](https://github.com/crate-ci/typos/compare/v1.28.2...v1.28.3)

---
updated-dependencies:
- dependency-name: crate-ci/typos
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-12-16 17:29:27 +02:00
Jorge Martín 05d46e6027 Rename JoinRequest in the SDK crates to KnockRequest, make Room::mark_knock_requests_as_seen thread safe and pass user_ids instead of event_ids: the user ids will be used to get the related member state events and they'll only be marked as seen if they're in a knock state.
Also, add extra checks to the integration tests.
2024-12-16 14:08:09 +01:00
Jorge Martín 338769508e feat(ffi): add bindings for subscribing to the join requests 2024-12-16 14:08:09 +01:00
Jorge Martín 93ebae6601 feat(room): allow subscribing to requests to join a room
This subscription will combine 3 streams: one notifying the members in the room have changed, another notifying the seen join requests have changed, and finally a third one notifying when the room members are no longer synced.

With this info we can track when we need to generate a new list of join requests to be emitted so the client can always have an up to date list.
2024-12-16 14:08:09 +01:00
Jorge Martín 780c264e59 feat(room): add JoinRequest abstraction
This struct is an abstraction over a room member or state event with knock membership.
2024-12-16 14:08:09 +01:00
Jorge Martín 9a899c1cb1 feat(room): add 'seen request to join ids' to the stores
This will allow us to keep track of which join room requests are marked as 'seen' by the current user and return them as such.

Also, add some methods to `Room` to mark new join requests as seen and to get the current ids for the seen join requests.
2024-12-16 14:08:09 +01:00
Richard van der Hoff 2703f7f7d4 crypto: extra logging in OtherUserIdentity
Add some extra logging in these two methids, to try to narrow down a bug report
we received.
2024-12-16 12:59:16 +00:00
Kévin Commaille 8d2e672996 feat!: Upgrade Ruma to 0.12.0
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-12-16 11:56:44 +01:00
Benjamin Bouvier 5a25e65da3 test(event cache): use the MatrixMockServer 2024-12-16 11:56:22 +01:00
Benjamin Bouvier c197808b42 task(event cache): get rid of one level of indent 2024-12-16 11:56:22 +01:00
Benjamin Bouvier ed34719295 task(event cache): simplify handling a back-pagination result 2024-12-16 11:56:22 +01:00
Benjamin Bouvier a052a79aaf fix(event cache): store the gap *before* events, after back-paginating
The conditions required to cause the bug might have been impossible to
reach in the real world, because it assumes a mix of:

- events present in the linked chunk
- no prev-batch token

However: now that we have storage, we could end up in this situation,
when reaching the start of the timeline (since there'll be no previous
gap in that case). We need to handle that better in the linked chunk
representation itself, but in the meanwhile, we should insert the gap
and the events in a relative correct order.
2024-12-16 11:56:22 +01:00
Benjamin Bouvier b6542477bb task(event cache): make the code more concise in back-pagination 2024-12-16 11:56:22 +01:00
Kévin Commaille a573b650c9 chore(sdk): Remove image-rayon cargo feature check from build.rs
The cargo feature was removed, but the build script was forgotten.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-12-15 18:07:42 +01:00
Valere 789bd317b3 Merge pull request #4383 from matrix-org/valere/cache_dehydration_pickle_key
feat(crypto): Support storing the dehydrated device pickle key
2024-12-13 14:42:44 +01:00
Valere 2b39476d9b feat(crypto): Support storing the dehydrated device pickle key 2024-12-13 13:05:19 +01:00
Andy Balaam 6dcefe49c2 feat(utds): Provide the reason why an event was an expected UTD 2024-12-13 10:46:10 +00:00
Benjamin Bouvier 150d9e4b05 fix(event cache store): always use immediate mode when handling linked chunk updates
If a linked chunk update starts with a RemoveChunk update, then the
transaction may start with a SELECT query and be considered a read
transaction. Soon enough, it will be upgraded into a write transaction,
because of the next UPDATE/DELETE operations that happen thereafter. If
there's another write transaction already happening, this may result in
a SQLITE_BUSY error, according to
https://www.sqlite.org/lang_transaction.html#deferred_immediate_and_exclusive_transactions

One solution is to always start the transaction in immediate mode. This
may also fail with SQLITE_BUSY according to the documentation, but it's
unclear whether it will happen in general, since we're using WAL mode
too. Let's try it out.
2024-12-12 17:59:42 +01:00
Damir Jelić 54bd1d7931 refactor(base): Move the joined member count logic into its respective sub-functions 2024-12-12 14:44:21 +01:00
Damir Jelić 7ae31d0cb1 fix(base): Subtract the number of service members from the number joined members
This patch fixes an edge case where the member is alone in the room with
a service member. We already subtracted the number of service members
in the case we calculated the room summary ourselves, but we did not do
so when the server provided the room summary.

This lead to the room, instead of being called `Empty`, being called
`Foo and N others`.
2024-12-12 14:44:21 +01:00
Damir Jelić f7f58dfd71 feat(ui): Add the MemberHints state event type to the required state
This state event allows us to correctly calculate the room display name
according to MSC4171.

MSC: https://github.com/matrix-org/matrix-spec-proposals/pull/4171
2024-12-12 14:44:21 +01:00
Richard van der Hoff 780a4630e4 chore(ffi): avoid hardcoding clang version
Update the workaround for https://github.com/rust-lang/rust/issues/109717 to
avoid hardcoding the clang version; instead, run `clang -dumpversion` to figure
it out.

While we're there, use the `CC_x86_64-linux-android` env var, which should
point to clang, rather than relying on `ANDROID_NDK_HOME` to be set.
2024-12-12 12:54:00 +00:00
Benjamin Bouvier 3356e0cc82 refactor(state store): use a single lock for all memory store accesses
The `MemoryStore` implementation of the `StateStore` has grown into a
monster, with one lock per field. It's probably overkill, as individual
fields don't need fine-grained locks like this; after all, accesses to
the store shouldn't be reentrant in general.

Fixes #3720.
2024-12-12 10:04:09 +01:00
Richard van der Hoff fda374ee81 feat(ffi): Add new properties to UnableToDecryptInfo
Followup to https://github.com/matrix-org/matrix-rust-sdk/pull/4360: expose
the new properties via FFI
2024-12-11 18:42:28 +00:00
Benjamin Bouvier 0264e49968 task(event cache): rename a few things
- rename RawLinkedChunk -> RawChunk
- rename RawChunk::id -> RawChunk::identifier
- precise that a `RawChunk` is mostly a `Chunk` with different
previous/next links.
2024-12-11 12:10:24 +01:00
Benjamin Bouvier d42c449612 refactor(event cache): only store a prev-batch token if the timeline was limited 2024-12-11 12:10:24 +01:00
Benjamin Bouvier 925d10f2ff task(event cache store): include the number of added items in one log 2024-12-11 12:10:24 +01:00
Benjamin Bouvier 4402f59e74 refactor(event cache): spawn a task to handle updates to the event cache store 2024-12-11 12:10:24 +01:00
Benjamin Bouvier 20184552a8 feat(event cache): start with an empty linked chunk if reloading failed 2024-12-11 12:10:24 +01:00
Benjamin Bouvier 832fedb05e feat(event cache): display raw linked chunks from storage when they fail to be rebuilt 2024-12-11 12:10:24 +01:00
Benjamin Bouvier eeb14f6cbe refactor!(event cache store): have the event cache store return raw linked chunks, not the full linked chunk
And let the caller rebuild the linked chunk. This is slightly nicer in
that it allows us to display the raw representation of a reloaded linked
chunk, before checking its internal state is consistent; this will allow
for better debug of issues related to the linked chunk internal state.

No functional changes.
2024-12-11 12:10:24 +01:00
Kévin Commaille a562f73b1e doc(timeline): Document media caching of send_attachment
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-12-11 10:45:39 +01:00
Kévin Commaille 7295f29055 doc(send_queue): Document media caching of send_attachment
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-12-11 10:45:39 +01:00
Kévin Commaille 723d7973d5 fix(send_queue): Use MediaFormat::File when caching attachment thumbnail
The `MediaFormat` reflects only the request that would be made to the homeserver.
There is no link between the format of the files stored in the media cache and their purpose in an event.

`MediaFormat::Tumbnail` means that we request a server-generated thumbnail of a file in the media repository.

Since the thumbnail is its own file in the media repository, it makes more sense to use `MediaFormat::File`.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-12-11 10:45:39 +01:00
Stefan Ceriu d5e7a9c949 chore(ui): rename date divider is_same_date_as to is_same_date_divider_group_as 2024-12-10 14:11:48 +02:00
Stefan Ceriu 8f064581d6 chore(ui): rename the day_dividers module to date_dividers 2024-12-10 14:11:48 +02:00
Stefan Ceriu 634edf2b65 chore(ui): rename all timeline "day dividers" to "date deviders" following the introduction of montly divider mode 2024-12-10 14:11:48 +02:00
Stefan Ceriu 935e4df927 feat(ui): make the timeline date separators configurable; have them appear either when the day changes or when the month changes. 2024-12-10 14:11:48 +02:00
Richard van der Hoff 1d72d2774f feat(ui): Add more properties to UnableToDecryptInfo 2024-12-10 11:36:04 +00:00
Richard van der Hoff 1e72131e7f feat(ui) Add UnableToDecryptInfo::user_trusts_own_identity 2024-12-10 11:36:04 +00:00
Richard van der Hoff e8b3949db3 feat(ui): Add UnableToDecryptInfo::event_local_age_millis 2024-12-10 11:36:04 +00:00
Richard van der Hoff c501a39ad4 refactor(sdk): Add Encryption::device_creation_timestamp
... so that we can use it in more places
2024-12-10 11:36:04 +00:00
Richard van der Hoff a04f9187f8 refactor(ui): store UTD info within PendingUtdReport
... making it easier to report late decryptions.
2024-12-10 11:36:04 +00:00
Benjamin Bouvier 32e2070f56 refactor(ffi): use a bool instead of an option to make the API less awkward
By default, the event cache store will be disabled. If disabled, it will
clean all the events in the cache store; most of the time this will do
nothing, since the store will not even be filled with any event data, so
it would be cheap to do. If some data was filled in the cache store
before, then it would be cleared after the cache store has been
disabled.

This makes a less awkward API than the previous one, where `None` and
`Some(false)` carried different semantics.
2024-12-10 12:05:29 +01:00
Benjamin Bouvier 4ee96aaffc feat(event cache): add a way to clear a single room's persistent storage 2024-12-10 12:05:29 +01:00
Benjamin Bouvier 0783cf89ba feat(ffi): add a feature flag to enable persistent storage for the event cache 2024-12-10 12:05:29 +01:00
Benjamin Bouvier cf02e694f2 feat(event cache store): add a method to clear all rooms' linked chunks 2024-12-10 12:05:29 +01:00
Ivan Enderlin cf178d603c doc(ui): Fix typos. 2024-12-10 11:36:05 +01:00
Ivan Enderlin ee94c86164 doc(ui): Fix a typo. 2024-12-10 11:36:05 +01:00
Ivan Enderlin 3526761580 doc(ui): Unfold a Self in the doc. 2024-12-10 11:36:05 +01:00
Ivan Enderlin 9a08975c8e doc(ui): Explain why ObservableItemsEntries does not implement Iterator. 2024-12-10 11:36:05 +01:00
Ivan Enderlin 6b56c9efd8 doc(ui): Explain why Deref is fine, but DerefMut is not. 2024-12-10 11:36:05 +01:00
Ivan Enderlin 0f2ada0958 refactor(ui): Rename ObservableItems::clone to clone_items. 2024-12-10 11:36:05 +01:00
Ivan Enderlin 0d17ea353f refactor(ui): Replace a panic by a sensible value + error!. 2024-12-10 11:36:05 +01:00
Ivan Enderlin 13e26b13e7 doc(ui): Rephrase the documentation of ObservableItems::all_remote_events. 2024-12-10 11:36:05 +01:00
Ivan Enderlin 72f1bd6180 doc(ui): Document ObservableItems::items more and TimelineItemKind. 2024-12-10 11:36:05 +01:00
Ivan Enderlin e32ea1627e doc(ui): Fix typos. 2024-12-10 11:36:05 +01:00
Ivan Enderlin ed1f2e29ed refactor(ui): ObservableItemsTransactionEntry::remove is no longer unsafe 2024-12-10 11:36:05 +01:00
Ivan Enderlin 92cb18207e test(ui): Write test suite for ObservableItems. 2024-12-10 11:36:05 +01:00
Ivan Enderlin 80f6b8d2cd test(ui): Write test suite for AllRemoteEvents.
This patch adds test suite for `AllRemoteEvents`.
2024-12-10 11:36:05 +01:00
Ivan Enderlin 05969fefde chore: Make Clippy happy. 2024-12-10 11:36:05 +01:00
Ivan Enderlin 81c962238a doc(ui): Add more documentation for AllRemoteEvents. 2024-12-10 11:36:05 +01:00
Ivan Enderlin 56218ee5d7 refactor(ui): Create ObservableItemsTransactionEntry.
This patch creates `ObservableItemsTransactionEntry` that mimics
`ObservableVectorTransactionEntry`. The differences are `set` is
renamed `replace`, and `remove` is unsafe (because I failed to update
`AllRemoteEvents` in this method due to the borrow checker).
2024-12-10 11:36:05 +01:00
Ivan Enderlin aa9138b281 doc(ui): Add more documentation for ObservableItemsTransaction. 2024-12-10 11:36:05 +01:00
Ivan Enderlin 6f231523b3 refactor(ui): Create ObservableItemsEntries and ObservableItemsEntry.
This patch creates `ObservableItemsEntries` and particularly
`ObservableItemsEntry` that wraps the equivalent
`ObservableVectorEntries` and `ObservableVectorEntry` with the
noticeable difference that `ObservableItemsEntry` does **not** expose
the `remove` method. It only exposes `replace` (which is a renaming
of `set`).
2024-12-10 11:36:05 +01:00
Ivan Enderlin 943b3fbd91 refactor(ui): Rename ObservableItems::set to replace.
This patch renames `ObservableItems(Transaction)::set` to `replace`, it
conveys the semantics a bit better for new comers.
2024-12-10 11:36:05 +01:00
Ivan Enderlin 40ff880597 doc(ui): Add more documentation. 2024-12-10 11:36:05 +01:00
Ivan Enderlin 0647be1bc3 refactor(ui): Move AllRemoteEvents inside observable_items.
This patch moves `AllRemoteEvents` inside `observable_items` so that
more methods can be made private, which reduces the risk of misuses
of this API. In particular,  the following methods are now strictly
private:

- `clear`
- `push_front`
- `push_back`
- `remove`
- `timeline_item_has_been_inserted_at`
- `timeline_item_has_been_removed_at`

In fact, now, all `&mut self` method (except `get_by_event_id_mut`) are
now strictly private!
2024-12-10 11:36:05 +01:00
Ivan Enderlin b069b20e18 refactor(ui): Create ObservableItems(Transaction). 2024-12-10 11:36:05 +01:00
Ivan Enderlin 91b73a2b16 refactor(ui): Maintain timeline_item_index when timeline items are inserted or removed.
This patch maintains the `timeline_item_index` when timeline items are
inserted or removed.
2024-12-10 11:36:05 +01:00
Ivan Enderlin 14d0f6877a refactor(ui): Maintain timeline_item_index when remote events are manipulated.
This patch maintains the `timeline_item_index` when a new remote events
is added or removed.
2024-12-10 11:36:05 +01:00
Ivan Enderlin a2210bce48 refactor(ui): Add EventMeta::timeline_item_index.
This is the foundation for the mapping between remote events and
timeline items.
2024-12-10 11:36:05 +01:00
Benjamin Bouvier 68cb85a2b2 refactor(event cache store): use a single transaction to handle all linked chunk updates at once
Instead of one transaction per update. This ensures that if a single
update fails, then none is taken into account.
2024-12-10 11:32:30 +01:00
Jonas Richard Richter 72fcc50f80 feat(ffi): Expose the method to send custom events with JSON content (#4390)
This patch adds the Room::send_raw method to the bindings, making it usable from
e.g. Swift.

Signed-off-by: Jonas Richard Richter <jonas-richard.richter@telekom.de>
2024-12-10 11:03:31 +01:00
Andy Balaam 5721c3622d refactor(key_backups): Rename fast_exists_on_server to exists_on_server 2024-12-09 16:33:56 +00:00
Andy Balaam 50eb46dc82 refactor(key_backups): Rename exists_on_server to fetch_exists_on_server 2024-12-09 16:33:56 +00:00
Andy Balaam 8aae16ffd7 feat(crypto) Provide a method to check whether server backup exists without hitting the server every time 2024-12-09 16:33:56 +00:00
Benjamin Bouvier e402ed4ce8 refactor(event cache): get the *most recent* pagination token, not the *oldest* one
Whenever it needs to back-paginate, the event cache should start with
the *most recent* backpagination token, not the oldest one.

This isn't a functional change, until the persistent storage is enabled.
The reason is that, currently, there is one previous-batch token alive;
after it's used, it's replaced with another gap and the events it served
to request from the server.

When persistent storage will be enabled, we'll have situations like the
one shown in the test code, where we can have multiple previous-batch
token alive at the same time. In that case, we'll need to back-paginate
from the most recent events to the least recent events, and not the
other way around, or we'll have holes in the timeline that won't be
filled until we got to the start of the timeline.
2024-12-09 15:57:14 +01:00
Kévin Commaille a1a04ee513 chore: Remove MSRV from READMEs
It can be found in Cargo.toml.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-12-09 16:22:00 +02:00
Benjamin Bouvier affdc25256 refactor(linked chunk): rename len() to num_items()
This makes it clearer that it's only concerned about the number of
items, not the number of chunks.
2024-12-09 14:46:21 +01:00
Benjamin Bouvier 8db78efbbc fix(event cache): use a correcter heuristic to decide whether to add initial events or not
Thanks Hywan for spotting the issue.
2024-12-09 14:46:21 +01:00
Kévin Commaille d8184e72eb fix(media): Make sure that local MXC URIs only try to get media from the cache and ignore requested dimensions (#4387)
Extracted from #4329. This does not change the `MediaFormat` of the
request used in the media cache by the send queue.

---------

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-12-09 13:43:49 +01:00
torrybr 3bd57d4307 feat(sdk): support for observing m.beacon events 2024-12-09 10:33:37 +01:00
Kévin Commaille 42193f1b06 chore(xtask): Remove unnecessary lifetime
`const` variables are always `'static`. Detected by clippy.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-12-08 16:57:22 +01:00
Kévin Commaille a277e6d37f chore(xtask): Disable unexpected_cfgs lint
It is triggered by the `xshell::cmd!` macro, and is fixed in xshell 0.2.7, which we cannot upgrade to.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-12-08 16:57:22 +01:00
Benjamin Bouvier bf6fa4cd55 fix(event cache): don't fill initial items if the room already had events (#4381)
The test requires subtle conditions to trigger:

- initialize a timeline from a room-list-service's room
- start a backpagination with that timeline (so the room event cache's
paginator is busy)
- try to initialize another timeline with the same room-list-service's
room (e.g. because the first room has been closed, and the app using it
doesn't have a room cache)

This would fail, because initializing a timeline calls
`EventCache::add_initial_events()` all the time, which tries to reset
the paginator's state, which assumes the paginator's not paginating at
this point. In a soon future, we'll get rid of the
`add_initial_events()` function because the event cache will handle its
own persistent storage; in the meantime, a correct fix is to skip
`add_initial_events()` if there was already something in the linked
chunk. After all, we're likely to fill the initial events with the same
events all the time, or a subset of more recent events. By doing that,
we're likely keeping *more* events in the linked chunk, instead.

Thanks to @stefanceriu for reporting the issue and confirming the fix
works!
2024-12-06 12:37:34 +01:00
Damir Jelić 6501a44e6a feat: Add support for MSC4171
Introduce support for MSC4171, enabling the designation of certain users
as service members. These flagged users are excluded from the room
display name calculation.

MSC: https://github.com/matrix-org/matrix-spec-proposals/pull/4171
2024-12-05 14:23:36 +01:00
Mathieu Velten ee30008f38 feat: Accept any string as a key for m.direct account data (#4228)
This is the follow up of this [Ruma
PR](https://github.com/ruma/ruma/pull/1946) for the SDK.

---------

Signed-off-by: Mathieu Velten <mathieu@velten.xyz>
Co-authored-by: Benjamin Bouvier <benjamin@bouvier.cc>
2024-12-05 12:37:16 +00:00
Damir Jelić 22cb8a1878 chore: Bump the pprof version to fix a security issue 2024-12-05 12:08:25 +01:00
Timo 111f916a78 feat(WidgetDriver): Pass Matrix API errors to the widget (#4241)
Currently the WidgetDriver just returns unspecified error strings to the
widget that can be used to display an issue description to the user. It
is not helpful to run code like a retry or other error mitigation logic.

Here it is proposed to add standardized errors for issues that every
widget driver implementation can run into (all matrix cs api errors):
https://github.com/matrix-org/matrix-spec-proposals/pull/2762#discussion_r1838804895

This PR forwards the errors that occur during the widget processing to
the widget in the correct format.

NOTE:
It does not include request Url and http Headers. See also:
https://github.com/matrix-org/matrix-spec-proposals/pull/2762#discussion_r1839802292

Co-authored-by: Benjamin Bouvier <benjamin@bouvier.cc>
2024-12-04 16:52:02 +00:00
Benjamin Bouvier a6e1f05957 test(event cache): use the MatrixMockServer for integration testing 2024-12-04 17:18:45 +01:00
Benjamin Bouvier 0b64c68191 test(event cache): make use of macros to avoid manual timeouts 2024-12-04 17:18:45 +01:00
Benjamin Bouvier 713039279c Enable persistent storage in multiverse
And fix an issue that would cause a crash because a timeline wasn't
initialized and we tried to unwrap it later.
2024-12-04 17:18:45 +01:00
Benjamin Bouvier d317e5d73c feat(event cache): don't react specifically to limited timelines, when storage's enabled 2024-12-04 17:18:45 +01:00
Damir Jelić ee93c278df chore: Update the hashbrown version we're using 2024-12-04 16:31:15 +01:00
Valere 1009ea86ae Merge pull request #4305 from matrix-org/valere/support_for_withheld_reason
feat(crypto): Add optional withheld reason to `UnableToDecryptReason`
2024-12-04 15:57:22 +01:00
Damir Jelić 7d8e7af308 Revert "chore(ui): Unify the logic for timeline item insertions"
This reverts commit d2ecd745f6.
2024-12-04 15:55:49 +01:00
Damir Jelić 136522c694 Revert "doc(timeline): tweak comments when inserting a new item"
This reverts commit 197da2c585.
2024-12-04 15:55:49 +01:00
Valere 6801811226 feat(crypto): Supports new UtdCause variants for withheld keys
Adds new UtdCause variants for withheld keys, enabling applications to display customised messages when an Unable-To-Decrypt message is expected.

refactor(crypto): Move WithheldCode from crypto to common crate
2024-12-04 15:33:23 +01:00
Benjamin Bouvier a4434d79c9 feat(event cache): strip bundled relations before persisting events 2024-12-04 12:35:58 +01:00
Benjamin Bouvier e0b1b5dc05 test: don't use the event cache storage but regular syncs instead 2024-12-04 12:35:46 +01:00
Benjamin Bouvier 1a63d8f0b7 task(event cache): ignore add_initial_events() when the event cache storage has been enabled
Not worth testing IMO, since this is about the "temporary" API we're
going to remove in subsequent patches.
2024-12-04 12:35:46 +01:00
Benjamin Bouvier 5bf3b11edf test: rewrite test_send_edit_when_timeline_is_clear to not use add_initial_items
Moar MatrixMockServer \o/
2024-12-04 12:35:46 +01:00
Benjamin Bouvier 8f1722f2a8 test: have the PendingEdit test helper use the matrix mock server and event cache storage 2024-12-04 12:35:46 +01:00
Benjamin Bouvier 5d95387935 test: remove unused adding of initial events in sliding sync test helper 2024-12-04 12:35:46 +01:00
Benjamin Bouvier bd93a9a40e test: remvoe use of add_initial_events in test_add_initial_events
And make it a smoke test that the event cache correctly gets events it
retrieves from sync.
2024-12-04 12:35:46 +01:00
Benjamin Bouvier 5cde4a6630 test: remove use of add_initial_events in test_ignored_unignored 2024-12-04 12:35:46 +01:00
Benjamin Bouvier de5511f009 test: rewrite test_ignored_unignored so it makes use of the MatrixMockServer 2024-12-04 12:35:46 +01:00
Damir Jelić 9bdd9fa831 chore: Update the RELEASING file so it doesn't mention git-cliff anymore 2024-12-04 11:25:00 +01:00
Damir Jelić 48bb3dbbe7 chore: Update our contributing guide for the manual changelog entries 2024-12-04 11:25:00 +01:00
Damir Jelić b8bf847fc1 chore: Set up cargo-release to update the versions in the changelog 2024-12-04 11:25:00 +01:00
Damir Jelić 17812b6949 chore: Remove our cliff config and don't use cliff to generate changelogs 2024-12-04 11:25:00 +01:00
Damir Jelić bab979aaf4 chore: Update our changelogs 2024-12-04 11:25:00 +01:00
Damir Jelić 42778dc79d chore: Replace git-cliff in the weekly-report command 2024-12-04 11:25:00 +01:00
Damir Jelić a948be9c85 chore: Downgrade xshell due to broken stdin interactions
Since xshell 0.2.3 the behavior of the run() function has changed in a
incompatible manner. Namely the stdin for the run() function no longer
inherits stdin from the shell. This makes it impossible for commands
that are executed by the run() function to accept input from the shell.

We don't use this functionality in many places but the `xtask release
prepare` command is now broken.

Let's just pin xshell to a working version while we wait for this to be
resolved upstream.

Upstream-issue: https://github.com/matklad/xshell/issues/63
2024-12-04 11:22:43 +01:00
Stefan Ceriu 9c381c1022 feat(ffi): expose a generic message_filtered_timeline that can be configured to only include RoomMessage type events and filter those further based on their message type.
Virtual timeline items will still be provided and the `default_event_filter` will be applied before everything else.
Instances of these timelines will be used to power the 2 different tabs shown on the new media browser. The client will be responsible for interacting with it similar to a normal timeline and transforming its data into something renderable e.g. section by date separators (which will be made configurable in a follow up PR)
2024-12-04 11:41:25 +02:00
Andy Balaam 9002f82659 task(backup_tests): Move mock helpers into MatrixMockServer 2024-12-03 14:55:41 +00:00
Andy Balaam 5f7fb4699a task(backup_tests): Split exists_on_server test into separate tests 2024-12-03 14:55:41 +00:00
Andy Balaam 5907104e0e task(backup_tests): Use helper functions to shorten exists_on_server tests 2024-12-03 14:55:41 +00:00
Ivan Enderlin d7dff5b026 refactor(ui): Add AllRemoteEvents::get_by_event_id_mut.
Having a mutable iterator can be dangerous and is probably too generic
regarding the safety we want to add around the `AllRemoteEvents` type.

This patch removes `iter_mut` and replaces it by its only use case:
`get_by_event_id_mut`.
2024-12-03 13:52:42 +01:00
Ivan Enderlin cabde8ed11 refactor(ui): AllRemoteEvents::back becomes last to add semantics.
This patch renames `AllRemoteEvents::back` to `last` so that it now gets
a specific semantics instead of being generic.
2024-12-03 13:52:42 +01:00
Ivan Enderlin b02fd92ad0 refactor(ui): Introduce the AllRemoteEvents type.
This patch replaces `VecDeque<EventMeta>` by `AllRemoteEvents` which
is a wrapper type around `VecDeque<EventMeta>`, but this new type aims
at adding semantics API rather than a generic API. It also helps to
isolate the use of these values and to know precisely when and how they
are used.

As a first step, `AllRemoteEvents` implements a generic API to not break
the existing code. Next patches will revisit that a little bit step
by step.
2024-12-03 13:52:42 +01:00
Ivan Enderlin 9be8578aff doc(ui): Explain why all_remote_events is necessary. 2024-12-03 13:26:26 +01:00
Ivan Enderlin 4f28dd85bf refactor: TimelineStateTransaction::add_or_update_remote_event always return true.
The `add_or_update_remote_event` method always returns `true`. This
patch updates the method to return nothing, and cleans up the call sites
accordingly. This patch also adds comments to clarify the code flow.

The bool value returned by `add_or_update_remote_event` was supposed
to be `false` if the event was duplicated. First off, as soon as the
`Timeline` receives its events from the `EventCache` via `VectorDiff`,
the `event_cache::Deduplicator` will take care of deduplication,
so the `Timeline` won't have to handle that itself. Second,
`add_or_update_remote_event` was sometimes removing an event, but it
was re-inserting a new one immediately without returning `false`: it was
never returning `false` because a new event was always added.
2024-12-03 13:26:26 +01:00
Damir Jelić 74119e8861 Revert "chore: Remove Ruma from the cargo-deny git dep allow list"
This reverts commit f256fe4b24.

As discussed, we want to prioritize the testing of new Ruma features
over stability.
2024-12-03 12:58:37 +01:00
Timo e76b8f7e15 tests: Refactor the widget tests to use MockMatrixServer (#4236)
This is a follow up PR on https://github.com/matrix-org/matrix-rust-sdk/pull/3987.

And tries to use the `MockMatrixServer` wherever reasonable in the
widget integration tests.

---------

Co-authored-by: Benjamin Bouvier <benjamin@bouvier.cc>
2024-12-03 08:36:24 +00:00
Integral 31bd5c6790 refactor: replace static with const for global constants
Signed-off-by: Integral <integral@member.fsf.org>
2024-12-03 09:13:57 +01:00
Andy Balaam 50f036d283 task(crypto_tests): Fix test that will fail when we handle backups correctly
This test was checking that a new device which has access to backups
returned an unknown UTD when it was given empty JSON for the event. It
was only passing because we currently have incorrect behaviour when
backups are enabled.

The fix is to make the device old and without access to backups, so that
we still consider this UTD unexpected.
2024-12-02 17:34:44 +00:00
Andy Balaam 8c73f0c655 task(crypto_tests): Remove duplicate test 2024-12-02 17:34:44 +00:00
Andy Balaam 8de76deb1b task(crypto_tests): Re-arrange and reword utd_cause tests 2024-12-02 17:34:44 +00:00
Andy Balaam b65728d46f task(crypto_tests): Shorten utd_cause tests with helper functions for devices 2024-12-02 17:34:44 +00:00
Andy Balaam 0b4b4ea791 task(crypto_tests): Shorten utd_cause tests with utility functions for UnableToDecryptInfos 2024-12-02 17:34:44 +00:00
Andy Balaam 552ab81739 task(crypto_tests): Add comments and clarify tests for determining UTD causes 2024-12-02 17:34:44 +00:00
dependabot[bot] d49d12249a build(deps): bump crate-ci/typos from 1.27.3 to 1.28.2
Bumps [crate-ci/typos](https://github.com/crate-ci/typos) from 1.27.3 to 1.28.2.
- [Release notes](https://github.com/crate-ci/typos/releases)
- [Changelog](https://github.com/crate-ci/typos/blob/master/CHANGELOG.md)
- [Commits](https://github.com/crate-ci/typos/compare/v1.27.3...v1.28.2)

---
updated-dependencies:
- dependency-name: crate-ci/typos
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-12-02 17:19:21 +01:00
Gabriel Féron ed1d406b72 fix(store): fix indexing issue in ObservableMap (#4346)
Any `.remove` operation called on a `ObservableMap` did not re-index
`values` _after_ the removed position, which means any later operation
on elements inserted after the previously removed key would either be
fetched wrongly, or panic when using `.get_or_create`.

This PR fixes these two related bugs and adds extra test cases.

---------

Signed-off-by: g@leirbag.net
Co-authored-by: Benjamin Bouvier <benjamin@bouvier.cc>
2024-12-02 16:00:19 +00:00
Ivan Enderlin 80a48f53ad refactor: Rename add_or_update_event to add_or_update_remote_event. 2024-12-02 16:45:35 +01:00
Ivan Enderlin 51cfaaacee refactor: Rename TimelineMetadata::all_events to all_remote_events.
This patch renames the `all_events` field to `all_remote_events` in
`TimelineMetada` for the sake of clarity.
2024-12-02 16:45:35 +01:00
Benjamin Bouvier 2f9866cf04 test(event cache): test that the event cache correctly reads updates 2024-12-02 16:27:05 +01:00
Benjamin Bouvier 7de74e2c04 feat(event cache): reload the linked chunk from the store, if storage's enabled 2024-12-02 16:27:05 +01:00
Benjamin Bouvier 019de4ffa0 test(event cache): add a test that the event cache correctly stores updates 2024-12-02 16:27:05 +01:00
Benjamin Bouvier 9f1e3c179b feat(event cache): propagate linked chunk in-memory updates to storage (conditionally) 2024-12-02 16:27:05 +01:00
Damir Jelić 17e17f0b9c ci: Build the Mac framework using the reldbg profile 2024-12-02 15:54:47 +01:00
Benjamin Bouvier 5da36d13c8 fix(event cache): consider empty items chunks in the memory store 2024-12-02 14:09:42 +01:00
Benjamin Bouvier cce322f9c8 test(event cache): add integration test for handling updates and reloading a linked chunk 2024-12-02 14:09:42 +01:00
Benjamin Bouvier ed3b03f454 feat(event cache): implement reloading a linked chunk from the memory store too 2024-12-02 14:09:42 +01:00
Benjamin Bouvier 27e1cded2e feat(event cache): reload a linked chunk from a sqlite store 2024-12-02 14:09:42 +01:00
Ivan Enderlin ad3d1fb6b3 refactor(ui): Use an iterator instead of Vec to represent events.
This patch changes `TimelineStateTransaction::add_remote_events_at`
to take an `IntoIterator<Item = Into<SyncTimelineEvent>>`
for `events`. In the current code, it saves one
`iter().map(Into::into).collect::<Vec<_>>()`, but it will save another
one when we will support `VectorDiff`s coming from the `EventCache`.

It also avoids to allocate a vector to pass new events (this mostly
happens in the test, but it can happen in real life).
2024-12-02 13:09:07 +01:00
Jorge Martín d2fecb6701 fix(room_preview): When requesting a room summary, use fallback server names
If no server names are provided for the room summary request and the
room's server name doesn't match the current user's server name, add the
room alias/id server name as a fallback value. This seems to fix room
preview through federation.

Also, when getting a summary for a room list item, if it's an invite
one, add the server name of the inviter's user id as another possible
fallback.

Changelog: Use the inviter's server name and the server name from the
room alias as fallback values for the via parameter when requesting the
room summary from the homeserver.
2024-12-02 12:11:47 +01:00
Kévin Commaille 685386df13 chore(xtask): Fix scope of push_dir
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-11-30 18:03:54 +01:00
Kévin Commaille f94b202341 chore(xtask): Upgrade xshell
Gets rid of an unexpected_cfgs warning.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-11-30 18:03:54 +01:00
Kévin Commaille d1a6956e77 chore(sdk): Disable unused_async clippy lint for unimplemented method
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-11-30 09:21:23 +01:00
Damir Jelić 2d2215edbe chore: Make use of the member event builder in the EventFactory 2024-11-30 09:20:49 +01:00
Damir Jelić bcd0d20e2f test: Add a method to build m.room.member events in the EventFactory 2024-11-30 09:20:49 +01:00
Kévin Commaille ba5881355d chore(test): Upgrade ctor
Fixes the `unexpected_cfgs` warning so it doesn't need to be disabled anymore.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-11-29 19:59:24 +01:00
Andy Balaam 1072d0a019 chore(js_tracing): Elide explicit lifetime to satisfy clippy 2024-11-29 18:45:45 +01:00
Damir Jelić 783c86aa78 ci: Build the Mac framework in release mode
The dev profile fails with a linker issue about not finding the
__chkstk_darwin symbol.
2024-11-29 18:45:45 +01:00
Damir Jelić 5564fe8852 ci: Bump the mac OS runner to 15 2024-11-29 18:45:45 +01:00
Damir Jelić e1f0037fd5 chore: Define the lifetime of some const strings explicitly 2024-11-28 11:53:35 +01:00
Benjamin Bouvier daa984f7de feat(event cache store): enable foreign keys pragma \o/ 2024-11-28 11:48:46 +01:00
Benjamin Bouvier aa0eb760de test(event cache): add a test for reading events from multiple rooms
This was to make sure that we can search by blob.
2024-11-28 11:48:46 +01:00
Benjamin Bouvier 9ed65bc321 task(event cache): address review points 2024-11-28 11:48:46 +01:00
Benjamin Bouvier ce95b6089f doc(event cache): add the copyright notice and basic module doc comment 2024-11-28 11:48:46 +01:00
Benjamin Bouvier c6ba71ae33 feat(event cache): allow reloading from the store, and test functionalities
This required adding support for *reading* out of the event cache, for
the sqlite backend. This paves the way for the next PR (reload from the
cache), and it should also help with testing at the `EventCacheStore`
trait layer some day.
2024-11-28 11:48:46 +01:00
Benjamin Bouvier e57d38cf57 doc(common): add a note that a decrypted raw event always has a room id 2024-11-28 11:48:46 +01:00
Benjamin Bouvier 9bea0cff24 feat(event cache): implement the sqlite backend for events 2024-11-28 11:48:46 +01:00
Benjamin Bouvier 197da2c585 doc(timeline): tweak comments when inserting a new item
A comment was duplicating (the first trace! that's removed here), and
the second block comment only applied to new items, and was not as
concise as it could be.
2024-11-28 10:09:50 +01:00
Ivan Enderlin d2ecd745f6 chore(ui): Unify the logic for timeline item insertions
This patch unifies the logic for inserting timeline items at `Start`
and `End` positions. Both `TimelineItemPositions` can share the same
implementation, making separate logic unnecessary. Previously, `End`
included a duplicated events check as well, while `Start` did not, leading
to inconsistency.

The changes strictly involve moving and refactoring, with no functional
modifications.
2024-11-28 08:25:16 +01:00
Damir Jelić e99939db85 refactor(crypto): Rename the IncomingResponse enum to AnyIncomingResponse 2024-11-27 19:55:27 +01:00
Damir Jelić 600a708e7b refactor!(crypto): Rename the OutgoingRequests enum to AnyOutgoingRequest 2024-11-27 19:55:27 +01:00
Damir Jelić a94a5f1716 chore(crypto): Split out the requests module 2024-11-27 19:55:27 +01:00
Damir Jelić 46064680ce refactor!(crypto): Don't re-export the request types from the request module 2024-11-27 19:55:27 +01:00
Damir Jelić 6fe5acfc97 refactor(crypto): Move the requests module under the types module 2024-11-27 19:55:27 +01:00
Valere 3369903766 Merge pull request #4275 from matrix-org/valere/utd_hook_historical_message
feat(utd_hook): Report device-historical expected UTD with new reason
2024-11-27 18:23:53 +01:00
Valere a0c86d9645 feat(utd_hook): Report historical expected UTD with new reason
This PR introduces a new variant to `UtdCause` specifically for device-historical messages (`HistoricalMessage`). These messages cannot be decrypted if key storage is inaccessible. Applications can leverage this new variant to provide more informative error messages to users.
2024-11-27 18:09:06 +01:00
Damir Jelić 7a454888a3 chore: Bump the deps and move some of them to the workspace 2024-11-27 17:03:50 +01:00
Ivan Enderlin 37f52e1c6c fix(common): LinkedChunk emits an Update::NewItemsChunk when constructed.
This patch updates `LinkedChunk::new_with_update_history` to emit an
`Update::NewItemsChunk` because the first chunk is created and it must
emit an update accordingly.
2024-11-27 14:40:26 +01:00
Ivan Enderlin 185423539e test(ui): Fix the test_echo test.
This patch fixes the `test_echo` test. It was doing the following:

* client sends an event to the server,
* servers acknowledges with the ID `$wWgymRfo7ri1uQx0NXO40vLJ`,
* client syncs and the server returns one event with ID `$7at8sd:localhost`,
* the test expects those 2 events to be the same!, which is incorrect.

The test was working because the transaction IDs are the same, but
that's an abuse of the existing code (the code will change soon, another
patch is coming). Whatever the code does: the connection must be based
on the event ID, not the transaction ID.
2024-11-27 14:29:24 +01:00
Stefan Ceriu 9e20659d5d chore: bring back MediaSource JSON serialization methods 2024-11-27 15:13:24 +02:00
Damir Jelić 7783188769 chore: Box the OidcSession so the AuthSession enum isn't unnecessarily big 2024-11-27 13:23:34 +01:00
Damir Jelić 514af54c4c chore: Fix some clippy warnings about our docs 2024-11-27 13:23:34 +01:00
Damir Jelić ad615b7612 chore: Fix some clippy lint warnings around the usage of map_or 2024-11-27 13:23:34 +01:00
Damir Jelić a1b7906a7d chore: Fix some clippy lints around lifetimes 2024-11-27 13:23:34 +01:00
Damir Jelić 79c8d2c345 chore: Don't build the docs for xtask
Building the docs for xtask spews a bunch of unexpected cfg warnings. As
these warnings come from a macro in a dependency and the docs for xtask
don't exist nor will, let's just not build them with the rest of the
docs.
2024-11-27 13:23:34 +01:00
Damir Jelić dcf6af405d chore: Silence unexpected cfg warnings
These are all coming from macro invocations of macros that are defined
in other crates. It's likely a clippy issue. We should try to revert
this the next time we bump the nightly version we're using.
2024-11-27 13:23:34 +01:00
Damir Jelić bb598b61a5 chore: Bump the nightly version we use for the CI 2024-11-27 13:23:34 +01:00
Ivan Enderlin 1c554c4912 chore(ui): Clarifies what TimelineItemPosition::UpdateDecrypted holds.
This patch tries to clear confusion around
`TimelineItemPosition::UpdateDecrypted(usize)`: it does contains
a timeline item index. This patch changes to
`TimelineItemPosition::UpdateDecrypted { timeline_item_index: usize }`
2024-11-27 12:04:59 +01:00
Benjamin Bouvier 21f8b7ed31 refactor(linked chunk): simplify further impl of the LinkedChunkRebuilder 2024-11-27 11:01:44 +01:00
Benjamin Bouvier 23ee8e25dd feat(linked chunk): add a way to reconstruct a linked chunk from its raw representation 2024-11-27 11:01:44 +01:00
Benjamin Bouvier 1098095846 refactor(linked chunk): replace LinkedChunk::len() with a simpler implementation
It's unused so it's mostly cosmetic, and it's trivial to reimplement
using `linked_chunk.items().count()`; let's do that instead of keeping
the perfect exact count synchronized with the chunks, which pollutes the
code in a few places.
2024-11-27 10:16:12 +01:00
Ivan Enderlin 3e7d7e8a31 chore(ui): Rename TimelineEnd to TimelineNewItemPosition.
This patch renames `TimelineEnd` into `TimelineNewItemPosition` for
2 reasons:

1. In the following patches, we will introduce a new variant to insert
   at a specific index, so the suffix `End` would no longer make sense.

2. It's exactly like `TimelineItemPosition` except that it's used
   only and strictly only to add **new** items, which is why we can't use
   `TimelineItemPosition` because it contains the `UpdateDecrypted`
   variant. This renaming reflects it's only about **new** items.

This patch takes the opportunity to move the `RemoteEventOrigin` inside
`TimelineNewItemPosition` to simplify method signatures. They always
go together.
2024-11-26 20:29:31 +01:00
Benjamin Bouvier 2c45316bcb fixup! fix(room): make Room::history_visibility() return an Option 2024-11-26 19:02:46 +01:00
Benjamin Bouvier 8dc7c1f876 fix(ui): have the room list service require the create and history visibility events
These two are required to properly compute the room preview of a joined
room:

- m.room.create ends up filling the `room_type` (space or not)
- m.room.history_visibility ends up filling the `is_world_readable`
  field.
2024-11-26 19:02:46 +01:00
Benjamin Bouvier db84936dcd fix(room): make Room::history_visibility() return an Option
And introduce `Room::history_visibility_or_default()` to return a better
sensible default, according to the spec.
2024-11-26 19:02:46 +01:00
Kévin Commaille 75d7d07013 chore(ffi): Fix thumbnail size info
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-11-26 15:45:54 +01:00
Kévin Commaille d4d5f45edc feat(media)!: Make all fields of Thumbnail required
It seems sensible to assume that if a client is able to generate a thumbnail,
it should be able to get all this information for it too.
A thumbnail with no information is not really useful, as we don't know when it could be used instead of the original image.

Removes `BaseThumbnailInfo`.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-11-26 15:20:07 +01:00
Kévin Commaille d0257d1cb2 refactor(media): Add method to split Thumbnail into parts
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-11-26 15:20:07 +01:00
Kévin Commaille ecf44348cf fix(client): Do not use the encrypted original file's content type as the encrypted thumbnail's content type
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-11-26 15:20:07 +01:00
Ivan Enderlin cc8bc05537 refactor: RoomEvents::reset really clear the linked chunk.
This patch updates `RoomEvents::reset` to not drop the `LinkedChunk` to
clear it.
2024-11-26 15:19:24 +01:00
Ivan Enderlin 728d646ce2 fix(common): AsVector clears its internal state on Update::Clear.
This patch fixes a bug in `AsVector`: when an `Update::Clear` value
is received, `AsVector`'s internal state must be cleared too, i.e. the
`UpdateToVectorDiff::chunks` field should be reset to an initial value!

This patch adds a test to ensure this works as expected.
2024-11-26 15:19:24 +01:00
Stefan Ceriu ca397dca0f feat(ffi): wrap Ruma MediaSources and run validations before passing them over FFI
Ruma doesn't currently validate mxuri's and as such `MediaSource`s passed over FFI can contain invalid/empty URLs. This change introduces a wrapper type around Ruma's and failable transformations so that appropiate actions can be taken beforehand e.g. returning a `TimelineItemContent::FailedToParseMessageLike` or nil-ing out the thumbnail info.
2024-11-26 15:40:24 +02:00
Benjamin Bouvier 1fbe6815c3 task(event cache): log whenever we receive an ignore user list change 2024-11-26 12:29:34 +01:00
Ivan Enderlin c61f70727f fix: RelationalLinkedChunk handles Update::Clear.
What the title says.
2024-11-25 17:45:01 +01:00
Ivan Enderlin 2abbf58825 feat(common): Implement LinkedChunk::clear.
This patch implements `LinkedChunk::clear`. The code from `impl Drop
for LinkedChunk` has been moved inside `Ends::clear`, and replaced by
a simple `self.links.clear()`. In addition, `LinkedChunk::clear` indeed
calls `self.links.clear()` but also resets all fields.

This patch adds the `Clear` variant to `Update`.

This patch updates `AsVector` to emit a `VectorDiff::Clear` on
`Update::Clear`.

Finally, this patch adds the necessary tests.
2024-11-25 17:08:43 +01:00
Ivan Enderlin b979b2ea1e doc(common): Fix typos. 2024-11-25 17:08:27 +01:00
Ivan Enderlin 24b968ad39 refactor: EventCacheStore::handle_linked_chunk_updates takes a Vec<Update>.
This patch updates `EventCacheStore::handle_linked_chunk_updates` to
take a `Vec<Update<Item, Gap>>` instead of `&[Update<Item, Gap>]`.
In fact, `linked_chunk::ObservableUpdates::take()` already returns a
`Vec<Update<Item, Gap>>`; we can simply forward this `Vec` up to here
without any further clones.
2024-11-25 17:08:27 +01:00
Ivan Enderlin faa8aa2b9c fix(base): Move all fields of MemoryStore inside a StdRwLock<_>.
This patch creates a new `MemoryStoreInner` and moves all fields from
`MemoryStore` into this new type. All locks are removed, but a new lock
is added around `MemoryStoreInner`. That way we have a single lock.
2024-11-25 17:08:27 +01:00
Ivan Enderlin db9ee9d87b refactor: Add constructors for Position and ChunkIdentifier.
This patch adds constructors for `Position` and `ChunkIdentifier` so
that we keep their inner values private.
2024-11-25 17:08:27 +01:00
Ivan Enderlin 1dbb494b94 feat(common): RelationalLinkedChunk stores the RoomId. 2024-11-25 17:08:27 +01:00
Ivan Enderlin fe52b4cb78 feat(common): EventCacheStore::handle_linked_chunk_updates takes a &RoomId. 2024-11-25 17:08:27 +01:00
Ivan Enderlin 5519442ad8 doc(common): Fix a typo. 2024-11-25 17:08:27 +01:00
Ivan Enderlin 88363d8033 feat(base): MemoryStore uses RelationalLinkedChunk to store events.
That's it.
2024-11-25 17:08:27 +01:00
Ivan Enderlin fb5d8f29ac feat(common): Implement RelationalLinkedChunk.
A `RelationalLinkedChunk` is like a `LinkedChunk` but with a relational
layout, similar to what we would have in a database.

This is used by memory stores. The idea is to have a data layout that
is similar for memory stores and for relational database stores, to
represent a `LinkedChunk`.

This type is also designed to receive `Update`. Applying `Update`s
directly on a `LinkedChunk` is not ideal and particularly not trivial
as the `Update`s do _not_ match the internal data layout of the
`LinkedChunk`, they have been designed for storages, like a relational
database for example.

This type is not as performant as `LinkedChunk` (in terms of memory
layout, CPU caches etc.). It is only designed to be used in memory
stores, which are mostly used for test purposes or light usages of the
SDK.
2024-11-25 17:08:27 +01:00
Benjamin Bouvier 912b121d27 feat(timeline): make more errors transparent 2024-11-25 15:11:02 +01:00
Benjamin Bouvier 2e975d9b19 fix(base): all EventCacheStoreLock must refer to the same underlying cross-process lock
And not duplicate it once per `EventCacheStoreLock`.
2024-11-25 15:11:02 +01:00
Benjamin Bouvier edc93e62b4 task(sdk): expose the SqliteEventCacheStore from the SDK crate
And use it in multiverse.
2024-11-25 15:11:02 +01:00
Ivan Enderlin 9d6ffa951f doc(sdk): Specify how the Client::observe_events works. 2024-11-25 11:49:36 +01:00
Benjamin Bouvier 079ec023b7 task(oidc): add logs when refreshing an OIDC token 2024-11-25 10:58:50 +01:00
Damir Jelić e55a1c7e00 chore: Rework the crypto crate README 2024-11-22 18:20:38 +01:00
Damir Jelić ddd737e4d8 docs: Add a tutorial to the crypto crate
Changelog: Add a tutorial describing how to add end-to-end encryption
support to an existing library.
2024-11-22 18:20:38 +01:00
Mauro Romito 38a15afc9c build (apple): add dynamic type to debug package 2024-11-22 18:44:48 +02:00
Jorge Martín fa93daabd2 feat(ffi): Add RoomInfo::join_rule field to bindings
Breaking-Change: Add `RoomInfo::join_rule` field, remove `RoomInfo::is_public` in the FFI crate, as they contain the same info.
2024-11-22 16:09:55 +01:00
Jorge Martín 6b0987385e refactor(room_preview): make RoomPreview use the local known data only for joined rooms
When instantiating a room preview, previously it would try to just check if the room exists locally either as joined, invited, knocked, left, etc., and then retrieve the info we cached about it.

While this seems fine for most cases, it turns out for non-joined rooms, the info we have locally will **always** be the one we received when the invite/knock/leave action took place and it'll never be updated,
so we may have the case where we knock into a room, never receive a response, someone changes the join rule of the room to something else and we'll think about this room as a 'request to join' room until we clear the local cache.

To prevent that, we can only use the local data for joined rooms, which are constantly updated, and try to use the room summary API and other fallbacks for the rest, even if they're rooms known to us.
2024-11-22 14:20:50 +01:00
Benjamin Bouvier 48fbda844f fix(oidc): make sure we keep track of an ongoing OIDC refresh up to the end
There's a lock making sure we're not doing multiple refreshes of an OIDC
token at the same time. Unfortunately, this lock could be dropped, if
the task spawned by the inner function was detached.

The lock must be held throughout the entire detached task's lifetime,
which this refactoring ensures, by setting the lock's result after
calling the inner function.
2024-11-21 18:36:11 +01:00
Damir Jelić bc70f3c051 refactor: Clean up the Room::compute_display_name() method 2024-11-21 14:34:38 +01:00
Benjamin Bouvier d2f255d613 feat(ffi): add a new function helper to create a caption edit
It has the same semantics used when creating a caption (if no formatted
caption is provided, assume a provided caption is markdown and use that
as the formatted caption).
2024-11-21 10:40:39 +01:00
Doug bf86b168d7 feat(timeline): mark media events as editable in the timeline (#4303)
This PR makes audio, file, image and video messages be editable so that
the timeline signals when it is possible to use #4277/#4300 for editing
captions.
2024-11-21 10:25:32 +01:00
Ivan Enderlin e5ca44bb04 feat(base): Add EventCacheStore::handle_linked_chunk_updates.
This patch adds the `handle_linked_chunk_updates` method on the
`EventCacheStore` trait. Part of
https://github.com/matrix-org/matrix-rust-sdk/issues/3280.
2024-11-20 16:39:49 +01:00
Benjamin Bouvier 1f563c964c task: add manual Sync impl for VerificationCache to avoid overflowing evaluation requirements 2024-11-20 16:33:39 +01:00
Benjamin Bouvier 9a9730d59e task: move the EventFactory to the matrix-sdk-test crate
This makes it available to the crypto crate, by lowering it into the
local dependency tree.
2024-11-20 16:33:39 +01:00
Benjamin Bouvier af3ce4b32b task: remove the dependency from common to test
The (matrix-sdk-)common crate used the (matrix-sdk-)test crate only to
benefit from the `async_test` proc macro, which is conveniently defined
in another crate.

My goal is to make `EventFactory`, at this point in the commit history,
defined in the main SDK crate, available in the test crate.
`EventFactory` makes use of some types defined in common, so there's a
circular dependency at the moment.

To split this circular dependency, I've changed the common crate to
depend on the test-macro crate directly; now the test crate can depend
on the common crate, and everybody's happy.
2024-11-20 16:33:39 +01:00
Benjamin Bouvier 03f0c3a001 task: move the MockClientBuilder to its own mock file 2024-11-20 16:33:39 +01:00
Benjamin Bouvier 639833acf1 task: move test_utils.rs to test_utils/mod.rs
This is more in line with what we're doing in the SDK in general.
2024-11-20 16:33:39 +01:00
Benjamin Bouvier 60893d2797 test(send_queue): add tests for editing a caption while media not sent yet
test(timeline): add an integration test for sending an attachment

test(timeline): add tests for multiple caption edits and local reaction to a media upload
2024-11-20 10:11:56 +01:00
Benjamin Bouvier 9e45111d8b feat(send queue): allow updating caption while the media is being sent 2024-11-20 10:11:56 +01:00
Benjamin Bouvier 0080f17c1f feat(base): add a way to update a dependent send queue request 2024-11-20 10:11:56 +01:00
Benjamin Bouvier fa47af3dd6 refactor!(base): rename StateStore::update_dependent_queued_request to mark_dependent_queued_requests_as_ready 2024-11-20 10:11:56 +01:00
Benjamin Bouvier c4ff07124b feat(ffi): allow editing a media caption from the FFI layer 2024-11-20 10:11:56 +01:00
Benjamin Bouvier 900cf5d071 room: create edits to add a caption to a media event 2024-11-20 10:11:56 +01:00
Benjamin Bouvier 8a6ced0e8f fix(send queue): when adding a local reaction, look for media events in dependent requests too 2024-11-19 17:22:06 +01:00
Benjamin Bouvier f20401c657 test(timeline): add an integration test for sending an attachment in the timeline
Also includes a caption for a file media event, which acts as a
regression test for the previous commit.
2024-11-19 16:59:31 +01:00
Benjamin Bouvier b987fc1de2 fix(media): include the formatted caption and filename for audio and file attachments too 2024-11-19 16:59:31 +01:00
Benjamin Bouvier efeac2ef39 fix(base): clear a room's send queue and dependent event queue after removing it from the state store 2024-11-19 16:50:35 +01:00
Valere 6b80055bd2 fix(utd_hook): Fix regression causing retry to report false late decrypt (#4252)
There has been a recent change on `Decryptor::decrypt_event_impl` causing
the function to return an TimelineEvent of kind unable to decrypt
instead of failing with an error.

The `late_decrypt` detection code was not changed, causing any retry to
mark UTDs as late decrypt.
2024-11-19 16:40:18 +01:00
Jorge Martín 0af53e99ee feat(room_preview): Compute display name for RoomPreview when possible 2024-11-19 16:11:09 +01:00
Jorge Martín bc0c2a6be2 feat(room_preview): Add RoomPreview::heroes field for known rooms 2024-11-19 16:11:09 +01:00
Damir Jelić 0b16d488ad chore: Release matrix-sdk version 0.8.0 (#4291)
Co-authored-by: Ivan Enderlin <ivan@mnt.io>
2024-11-19 14:11:19 +01:00
Damir Jelić d40aac89cb fix: Use the DisplayName struct to protect against homoglyph attacks 2024-11-19 11:54:01 +01:00
Damir Jelić e4ebeb8a42 feat(base): Introduce a DisplayName struct
This patch introduces a struct that normalizes and sanitizes display
names. Display names can be a source of abuse and can contain characters
which might make it hard to distinguish one display name from the other.

This struct attempts to make it easier to protect against such abuse.

Changelog: Introduce a DisplayName struct which normalizes and sanitizes
display names.

Co-authored-by: Denis Kasak <dkasak@termina.org.uk>
2024-11-19 11:54:01 +01:00
Erik Johnston 22bbe0c32e Add 'conn_id' field to sync_once span
This is to make it easier to see which sync requests are for which
connection when debugging.
2024-11-19 11:45:32 +01:00
dependabot[bot] 05505a5a48 chore(deps): bump codecov/codecov-action from 4 to 5
Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from 4 to 5.
- [Release notes](https://github.com/codecov/codecov-action/releases)
- [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/codecov/codecov-action/compare/v4...v5)

---
updated-dependencies:
- dependency-name: codecov/codecov-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-11-19 08:32:34 +01:00
Timo 21bb85ac21 feat(Room): Check if the user is allowed to do a room mention before trying to send a call notify event. (#4271) 2024-11-18 16:15:28 +02:00
Benjamin Bouvier f1a442bad0 refactor(send queue): use a specialized mutex for locking access to the state store and being_sent
There was an implicit relationship that the `being_sent` lock needed to
be taken in order to do non-atomic state store operations. With the
change from this commit, the relationship is now more explicit: to get a
handle to the state store, or being_sent, you have to obtain a
`StoreLockGuard` by locking against the store itself. The `WeakClient`
isn't stored in the QueueStorage data structure itself, so it's the only
way to get a `dyn StateStore` from the `QueueStorage`.
2024-11-18 14:55:31 +01:00
Jorge Martín a8a83c3b45 feat(room_preview): Use room directory search as another data source 2024-11-18 13:22:41 +01:00
Tobias Fella 47246483fa doc(crypto): Fix typo
Signed-off-by: Tobias Fella <fella@posteo.de>
2024-11-16 17:24:17 +01:00
Hubert Chathi 31006ab3bf feat(crypto): pin identity when we withdraw verification 2024-11-16 10:26:58 +01:00
Doug 3ed5d34f49 feat(ffi): Add support for including captions with file uploads. 2024-11-15 20:10:50 +01:00
Benjamin Bouvier 232391c6b2 task(send queue): move some assertions back to logged errors
Better safe than panicky.
2024-11-15 10:35:31 +01:00
Jorge Martín cefd5a27f5 feat(ffi): make RoomPreviewInfo::room_type an enum, not an optional String 2024-11-14 16:41:55 +01:00
Jorge Martín 97952902a3 feat(ffi): add RoomPreviewInfo::num_active_members 2024-11-14 16:41:55 +01:00
Jorge Martín bf4a2ed297 feat(ffi): add is_direct and fn inviter to RoomPreview 2024-11-14 16:41:55 +01:00
Benjamin Bouvier a499988621 task(CI): rename the upload code coverage task to make its name clearer 2024-11-14 16:39:28 +01:00
Benjamin Bouvier 0d01cabb8d refactor(widget): get rid of unused limits parameter when constructing a WidgetMachine 2024-11-14 16:23:52 +01:00
Benjamin Bouvier f3c0309fbc refactor(widget): get rid of ProcessingContext and inline it in its callers 2024-11-14 16:23:52 +01:00
Benjamin Bouvier 8070e3c165 refactor(widget): tidy up and start commenting the widget code 2024-11-14 16:23:52 +01:00
Benjamin Bouvier 02c7c2cdfc test(send queue): caching a thumbnail of unknown dimensions removes it from cache after upload 2024-11-14 16:22:07 +01:00
Benjamin Bouvier 9b6de4e436 test(send queue): add more tests for cancellation 2024-11-14 15:33:59 +01:00
Benjamin Bouvier b7d4be9b65 test(send queue): add a test for cancelling an upload while the thumbnail upload is active 2024-11-14 15:33:59 +01:00
Benjamin Bouvier bc86027853 test(send queue): add a test for cancelling a media upload before it's active 2024-11-14 15:33:59 +01:00
Benjamin Bouvier 50db563363 feat(send queue): allow aborting media uploads 2024-11-14 15:33:59 +01:00
Benjamin Bouvier 8fa07ec22d task(send queue): being_sent is an Option, not a set anymore
There can be at most one thing being sent by the send queue, so make
this super explicit.
2024-11-14 15:33:59 +01:00
Timo 7aa930b81c feat(WidgetDriver): Send state from state sync and not from timeline to widget (#4254) 2024-11-14 15:55:25 +02:00
Benjamin Bouvier c02d8cee77 feat!(send queue): add a priority field to maintain ordering of sending
Prior to this patch, the send queue would not maintain the ordering of
sending a media *then* a text, because it would push back a dependent
request graduating into a queued request.

The solution implemented here consists in adding a new priority column
to the send queue, defaulting to 0 for existing events, and use higher
priorities for the media uploads, so they're considered before other
requests.

A high priority is also used for aggregation events that are sent late,
so they're sent as soon as possible, before other subsequent events.
2024-11-14 12:00:08 +01:00
Benjamin Bouvier 2872af234b test(send queue): add a test for the ordering of media vs other events 2024-11-14 12:00:08 +01:00
Jorge Martín d614878436 refactor(sdk): move formatted_caption_from to the SDK, rename it
Add the `markdown` feature to the SDK crate, otherwise we can't use `FormattedBody::markdown`.

Refactor the pattern matching into an if, add tests to check its behaviour.
2024-11-14 10:38:44 +01:00
Jorge Martín afaecdc457 feat(ffi): generate formatted captions for send_* media fns
Changelog: For `Timeline::send_*` fns, treat the passed `caption` parameter as markdown and use the HTML generated from it as the `formatted_caption` if there is none.
2024-11-14 10:38:44 +01:00
Ivan Enderlin aca83fb4ed refactor: Move Event and Gap into matrix_sdk_base::event_cache. 2024-11-13 15:25:58 +01:00
Ivan Enderlin c3e28f7e33 refactor: Move linked_chunk from matrix-sdk to matrix-sdk-common. 2024-11-13 15:25:58 +01:00
Ivan Enderlin 949cd78d94 refactor: Move event_cache_store/ to event_cache/store/ in matrix-sdk-base. 2024-11-13 15:25:58 +01:00
Benjamin Bouvier 99b9c50548 feat(send queue): implement unwedging for media uploads 2024-11-13 14:32:53 +01:00
Benjamin Bouvier 371e7bc052 task(tests): move error_too_large to the generic endpoint
So it can be reused in more contexts than just the sending of an event,
but also for uploads.
2024-11-13 14:32:53 +01:00
Benjamin Bouvier 0541ec7e3f refactor(send queue): use SendHandle for media uploads too 2024-11-13 14:32:53 +01:00
Ivan Enderlin 0509236cf8 doc(sdk): Improve documentation of Client::observe_events. 2024-11-13 11:24:08 +01:00
Ivan Enderlin 6cef7f20c5 feat(sdk): Implement Client::observe_events and Client::observe_room_events.
Changelog: This patch introduces a mechanism similar to
 `Client::add_event_handler` and `Client::add_room_event_handler`
 but with a reactive programming pattern. This patch adds
 `Client::observe_events` and `Client::observe_room_events`.

 ```rust
 // Get an observer.
 let observer =
     client.observe_events::<SyncRoomMessageEvent, (Room, Vec<Action>)>();

 // Subscribe to the observer.
 let mut subscriber = observer.subscribe();

 // Use the subscriber as a `Stream`.
 let (message_event, (room, push_actions)) = subscriber.next().await.unwrap();
 ```

 When calling `observe_events`, one has to specify the type of event
 (in the example, `SyncRoomMessageEvent`) and a context (in the example,
 `(Room, Vec<Action>)`, respectively for the room and the push actions).
2024-11-13 11:24:08 +01:00
Ivan Enderlin e798a51709 feat(sdk): Implement EventHandlerContext for tuples.
This patch implements `EventHandlerContext` for tuples where each part
implements `EventHandlerContext` itself.
2024-11-13 11:24:08 +01:00
Ivan Enderlin 8f8aad6f4d chore(cargo): Update eyeball-im-util to 0.7.0. 2024-11-13 11:16:30 +01:00
Ivan Enderlin af84c79e69 feat(base): Make ObservableMap::stream works on wasm32-unknown-unknown.
This patch updates `eyeball-im` and `eyeball-im-util` to integrate
https://github.com/jplatte/eyeball/pull/63/. With this new feature, we
can have a single implementation of `ObservableMap` (instead of 2: one
for all targets, one for `wasm32-u-u`). It makes it possible to get
`Client::rooms_stream` available on all targets now.
2024-11-13 11:16:30 +01:00
Ivan Enderlin a920c3fdec fix(ui): Disable share_pos() inside RoomListService.
This patch disables the call to `share_pos()` inside the
`RoomListService` because it creates slowness we need to investigate.
2024-11-13 09:33:04 +01:00
Benjamin Bouvier 9dd2d5ee3c task(architecture): address typo in architecture.md file about EncryptionSyncService 2024-11-12 16:24:07 +01:00
Benjamin Bouvier f341dc4131 refactor(ffi): remove duplicated fields in media event contents
The caption and filenames were weirdly duplicated in each media content,
when the expected behavior is well defined:

- if there's both a caption and a filename, body := caption, filename is
its own field.
- if there's only a filename, body := filename.

We can remove all duplicated fields, knowing this, and reconstruct the
body based on that information. This should make it clearer to FFI users
which is what, and provide a clearer API when creating the caption and
so on.
2024-11-12 16:22:09 +01:00
Damir Jelić d446eb933e test: Add a bunch examples to the MatrixMockServer docs 2024-11-12 14:51:31 +01:00
Damir Jelić 8f0f0fa4d4 chore(test): Don't require two room IDs in the mock_sync_room method 2024-11-12 14:51:31 +01:00
Benjamin Bouvier 36b96ccef2 task(tests): have the test clients use Matrix v1.12 2024-11-12 12:01:18 +01:00
Benjamin Bouvier 5957232e54 task(tests): add a MockClientBuilder to help with creating Clients connected to a MatrixMockServer 2024-11-12 12:01:18 +01:00
Benjamin Bouvier 6f60eea9ce task(tests): refactor mock system to use generic endpoints and avoid code duplication 2024-11-12 12:01:18 +01:00
Benjamin Bouvier 982c6eab54 feat(send queue): retry uploads if they've failed with transient errors 2024-11-12 11:19:05 +01:00
Benjamin Bouvier cfd0c5ce0c feat(media): allow passing a custom RequestConfig to an upload request 2024-11-12 11:19:05 +01:00
Benjamin Bouvier 8e2939bd91 refactor!(send queue): move RoomSendQueue::unwedge to the SendHandle type 2024-11-12 11:06:19 +01:00
Ivan Enderlin 66a79729ed test(ci): Re-enable Complement Crypto. 2024-11-12 10:46:59 +01:00
dependabot[bot] bd5f5f3fe0 chore(deps): bump crate-ci/typos from 1.27.0 to 1.27.3
Bumps [crate-ci/typos](https://github.com/crate-ci/typos) from 1.27.0 to 1.27.3.
- [Release notes](https://github.com/crate-ci/typos/releases)
- [Changelog](https://github.com/crate-ci/typos/blob/master/CHANGELOG.md)
- [Commits](https://github.com/crate-ci/typos/compare/v1.27.0...v1.27.3)

---
updated-dependencies:
- dependency-name: crate-ci/typos
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-11-11 15:43:34 +01:00
Ivan Enderlin 403be3dea0 test(ci): Disable Complement Crypto for a short period of time. 2024-11-11 13:28:39 +01:00
Ivan Enderlin 4d39d176d9 fix(ffi): Simplify Client::new constructor.
This patch continues to simplification of the `matrix_sdk_ffi::Client`.
The constructor can receive a `enable_oidc_refresh_lock: bool` instead
of `cross_process_refresh_lock_id: Option<String>`, which was a copy of
`matrix_sdk::Client::cross_process_store_locks_holder_name`.

Now there is a single boolean to indicate whether
`Oidc::enable_cross_process_refresh_lock` should be called
or not. If it has to be called, it is possible to re-use
`matrix_sdk::Client::cross_process_store_locks_holder_name`. Once
again, there is a single place to read this data, it's not copied over
different semantics.
2024-11-11 13:28:39 +01:00
Ivan Enderlin d3a232607a fix(ffi): Replace enable_cross_process_refresh_lock by enable_oidc_refresh_crypto_lock.
This patch simplifies a little the `ClientBuilder` API:

* `enable_cross_process_refresh_lock` is removed
* `enable_oidc_refresh_crypto_lock` + `set_session_delegate` must be
  used instead.
2024-11-11 13:28:39 +01:00
Ivan Enderlin 3070154a57 feat(ffi): Add ClientBuilder::cross_process_store_locks_holder_name. 2024-11-11 13:28:39 +01:00
Ivan Enderlin 563c3aae31 feat(ui): EncryptionSyncService and Notification are using Client::cross_process_store_locks_holder_name.
This patch removes the `process_id` argument from
`EncryptionSyncService::new()` and replaces it by
`Client::cross_process_store_locks_holder_name`. The “process ID” is
set when the `Client` is converted into another `Client` tailore for
notification in `NotificationClient` with `Client::notification_client`
which now has a new `cross_process_store_locks_holder_name` argument.
2024-11-11 13:28:39 +01:00
Ivan Enderlin 90b8ba3c2e feat: Client::cross_process_store_locks_holder_name is used everywhere.
See the Changelog Section to get the details.

Changelog: `Client::cross_process_store_locks_holder_name` is used everywhere:
 - `StoreConfig::new()` now takes a
   `cross_process_store_locks_holder_name` argument.
 - `StoreConfig` no longer implements `Default`.
 - `BaseClient::new()` has been removed.
 - `BaseClient::clone_with_in_memory_state_store()` now takes a
   `cross_process_store_locks_holder_name` argument.
 - `BaseClient` no longer implements `Default`.
 - `EventCacheStoreLock::new()` no longer takes a `key` argument.
 - `BuilderStoreConfig` no longer has
   `cross_process_store_locks_holder_name` field for `Sqlite` and
   `IndexedDb`.
2024-11-11 13:28:39 +01:00
Ivan Enderlin 031a96200b feat(sdk): Add Client::cross_proces_store_locks_holder_name().
This patch adds `ClientInner::cross_process_store_locks_holder_name` and
its public method `Client::cross_process_store_locks_holder_name`. This
patch also adds `ClientBuilder::cross_process_store_locks_holider_name`
to configure this value.
2024-11-11 13:28:39 +01:00
Jorge Martín 57e78dd22b feat(ffi): Add Client::create_room_alias function 2024-11-11 13:26:15 +01:00
Jorge Martín 53900294d0 feat(room_alias): Add create_room_alias function
This associates a room alias with an existing room through its room id.
2024-11-11 13:26:15 +01:00
Damir Jelić f483f35573 chore: Allow backoff to be used in the cargo-deny config
Backoff seems to be unmaintained, there's no drop-in replacement so
let's silence the warning for now.
2024-11-11 13:16:02 +01:00
Jorge Martín 204e6e4ca0 feat(sliding_sync): Add m.room.join_rules to the required state
We need the join rules state event to prevent the SDK from assuming a room with an unknown (as in, not loaded) join rule is public.
2024-11-08 17:05:37 +01:00
Jorge Martín ca8c635f62 feat(ffi): add reason field to TimelineItemContent::RoomMembership 2024-11-08 16:40:50 +01:00
Timo b8a61cfc17 feat(WidgetDriver): Support widget redacts (#3987)
Changelog: Implement proper redact handling in the widget driver.
 This allows the Rust SDK widget driver to support widgets that
 rely on redacting.
Co-authored-by: Damir Jelić <poljar@termina.org.uk>
2024-11-08 14:21:35 +01:00
Jorge Martín ab61077a8b fix(ffi): match the right status code in Client::is_room_alias_available 2024-11-08 12:36:51 +01:00
Benjamin Bouvier 26bee1cc38 doc: start an architecture document with a high-level description of the crates 2024-11-08 13:11:19 +02:00
Jorge Martín 46232ee2c1 fix(sdk): add more invalid characters for room aliases 2024-11-08 11:55:26 +01:00
Jorge Martín 7c600fddf0 refactor(ffi): Improve is_room_alias_format_valid so it's more strict.
Previously this only used the Ruma checks, which only handled the initial `#` char and the domain part. With these changes, the name part is also validated, checking it's lowercase, with no whitespaces and containing only allowed chars, similar to what `DisplayName::to_room_alias_name` does.

Moved the code to the SDK crate so it can be properly tested.
2024-11-08 11:55:26 +01:00
Benjamin Bouvier 965a59d5b8 task(tests): create the client with MatrixMockServer::make_client() instead of embedding one into the struct 2024-11-07 17:37:58 +01:00
Benjamin Bouvier f032d16d20 task(tests): mock upload too 2024-11-07 17:37:58 +01:00
Benjamin Bouvier 57137cdd5b task(tests): introduce prebuilt mocks and mocking helpers 2024-11-07 17:37:58 +01:00
Damir Jelić 5d83808143 feat(base): Consider knocked members to be part of the room for display name disambiguation 2024-11-07 16:41:16 +01:00
Damir Jelić df465a0420 chore(base): Improve the docs for the AmbiguityCache 2024-11-07 16:41:16 +01:00
Damir Jelić 4ca69da93c chore(base): Improve the docs for the DisplayNameUsers struct 2024-11-07 16:41:16 +01:00
Damir Jelić 4039359512 chore(base): Clean up the display name ambiguity calculation logic 2024-11-07 16:41:16 +01:00
Damir Jelić 1304902cb4 refactor(base): Rename AmbiguityMap to DisplayNameUsers
The ambiguity map tracks the users which are using a single display
name, so let's reflect that in the name.
2024-11-07 16:41:16 +01:00
Damir Jelić 219be9b731 refactor(base)!: Rename DisplayName to RoomDisplayName 2024-11-07 16:41:16 +01:00
Benjamin Bouvier 237419c740 feat(media): introduce a stripped down MediaThumbnailSettings::new only taking a width and height
This one is used when caching a thumbnail everywhere, and when
attempting to retrieve it; it gives us a single place where to
coordinate the default `MediaThumbnailSettings` parameters.
2024-11-07 13:04:10 +01:00
Benjamin Bouvier 1658397139 refactor!(media): rename MediaThumbnailsSetting::new to with_method() 2024-11-07 13:04:10 +01:00
Benjamin Bouvier bab6761388 fix(event cache): give looser parameters for the deduplicator's bloom filters
The previous values would lead to super large memory allocations, as
observed with `valgrind --tool=massive` on the tiny test added in this
commit:

- for 400 rooms each having 100 events, this led to 540MB of
allocations.
- for 1000 rooms each having 100 events, this led to 1.5GB of
allocations.

This is not acceptable for any kind of devices, especially for mobile
devices which may be more constrained on memory. The bloom filter is an
optimisation to avoid going through events in the room's event list, so
it shouldn't cause a big toll like that; instead, we can reduce the
parameters values given when creating the filters.

With the given parameters, 1000 rooms each having 100 events leads to
1.2MB of allocations.
2024-11-07 12:59:16 +01:00
Timo 5193c2033f feat(ffi): Auto approve the required widget capabilities for element call raise hand and reaction feature. 2024-11-07 12:42:17 +01:00
Jorge Martín 0f9bc20bb8 fix(ffi): use subscribe_reset for verification_state instead, add a regression test 2024-11-07 12:36:07 +01:00
Jorge Martín d54f2a8b04 fix(encryption): emit an updated current verification state before any network request happens
This way we don't get stuck with an outdated value if there is no network connection.
2024-11-07 12:36:07 +01:00
Jorge Martín 00c4071fe1 feat(ffi): allow VerificationStateListener to emit the current state
With this, we get notified of the current verification state almost immediately.

Without it, you may either call it too soon and receive an `Unknown` state or you might have to call `Encryption::wait_for_e2ee_initialization_tasks()` and wait until it's finished to request a valid state value.
2024-11-07 12:36:07 +01:00
Damir Jelić 65287178d1 chore: Bump futures-util in the lock file
We were locked onto a yanked version of futures-util.
2024-11-07 11:10:56 +01:00
Damir Jelić 90b8015d71 chore: Don't ignore the aquamarine RUST-SEC issue, we bumped aquamarine 2024-11-07 11:10:56 +01:00
Damir Jelić f256fe4b24 chore: Remove Ruma from the cargo-deny git dep allow list 2024-11-07 11:10:56 +01:00
Benjamin Bouvier 8d07f36247 chore(send queue): adapt to new locks around the event cache store 😎 2024-11-06 15:33:51 +01:00
Benjamin Bouvier 77ee02f529 refactor!(media): rename MediaRequest to MediaRequestParameters
Because it's not a request we send to the server; it's some of the
request parameters.
2024-11-06 15:33:51 +01:00
Benjamin Bouvier 566a13b16e refactor!(media): inline MediaThumbnailSize into MediaThumbnailSettings
Changelog: all the fields of `MediaThumbnailSize` have been inlined into
 `MediaThumbnailSettings`, and the former type has been removed.
2024-11-06 15:33:51 +01:00
Benjamin Bouvier 4bbe620d0f feat(timeline): use the send queue for media uploads behind a feature toggle 2024-11-06 15:33:51 +01:00
Benjamin Bouvier 9178e4ce33 chore(send queue): review 2024-11-06 15:33:51 +01:00
Benjamin Bouvier c04a73c28d chore(send queue): move code for media upload to its own file 2024-11-06 15:33:51 +01:00
Benjamin Bouvier 13244d808b chore(send queue): move more code around to split work into smaller functions 2024-11-06 15:33:51 +01:00
Benjamin Bouvier e9d5aa1221 chore(send queue): move code around to avoid an enormous send_attachment method 2024-11-06 15:33:51 +01:00
Benjamin Bouvier 57ad256fe1 doc(send queue): beef up the send queue module comment and describe uploads 2024-11-06 15:33:51 +01:00
Benjamin Bouvier c196a9754b feat(timeline): send medias via the send queue 2024-11-06 15:33:51 +01:00
Benjamin Bouvier a8992f37d7 test(send queue): add a smoke test for sending an attachment with the send queue 2024-11-06 15:33:51 +01:00
Benjamin Bouvier 9483703e35 feat(send queue): allow sending attachments with the send queue 2024-11-06 15:33:51 +01:00
Ivan Enderlin 0942dab2fd doc(base): Document Client::event_cache_store a bit more. 2024-11-06 15:03:50 +01:00
Ivan Enderlin 94bd421a8d refactor: Use a common code for try_take_leased_lock.
This code is shared by all `MemoryStore` implementations.
2024-11-06 15:03:50 +01:00
Ivan Enderlin 7b3eb0b6f1 feat(base,sdk): Client now uses EventCacheStoreLock. 2024-11-06 15:03:50 +01:00
Ivan Enderlin 8b85ff2434 feat(base): Create EventCacheStoreLock. 2024-11-06 15:03:50 +01:00
Ivan Enderlin 94c507dd38 test: Testing the cross-process event cache store. 2024-11-06 15:03:50 +01:00
Ivan Enderlin 37304c8cdc refactor: Implement try_take_leased_lock on SqliteEventCacheStore 2024-11-06 15:03:50 +01:00
Ivan Enderlin 16a86587ea refactor: Implement try_take_leased_lock on MemoryStore. 2024-11-06 15:03:50 +01:00
Ivan Enderlin e24d9b3ce3 feat(base): Create LockableEventCacheStore. 2024-11-06 15:03:50 +01:00
Ivan Enderlin 9f11bced10 chore: Rename BackingStore::Error to BackingStore::LockingError.
The idea is to avoid name conflicts when implementing other traits
that use the `Error` associated type.
2024-11-06 15:03:50 +01:00
Ivan Enderlin e5d4ea5964 chore(base): Simplify &* with .as_ref() or .deref().
This patch replaces a `&*` by a `.as_ref()` and a `.deref()`. The result
is the same but it's just simpler for newcomers to understand what
happens.
2024-11-06 15:03:50 +01:00
Jorge Martín fbc914f586 feat(ffi): add room display name to room alias transformation 2024-11-06 09:22:50 +01:00
Jorge Martín bb2d19a1d8 feat(ffi): add room alias format validation 2024-11-06 09:22:50 +01:00
Ivan Enderlin 933033cc25 fix(sdk): Do not always remove empty chunks from LinkedChunk.
This patch introduces `EmptyChunk`, a new enum used to represent whether
empty chunks must be removed/unlink or kept from the `LinkedChunk`. It
is used by `LinkedChunk::remove_item_at`.

Why is it important? For example, imagine the following situation:

- one inserts a single event in a new chunk (possible if a (sliding)
  sync is done with `timeline_limit=1`),
- one inserts many events at the position of the previous event,
  with one of the new events being a duplicate of the first event
  (possible if a (sliding) sync is done with `timeline_limit=10` this
  time),
- prior to this patch, the older event was removed, resulting in an
  empty chunk, which was removed from the `LinkedChunk`, invalidating
  the insertion position!

So, with this patch:

- `RoomEvents::remove_events` does remove empty chunks, but
- `RoomEvents::remove_events_and_update_insert_position` does NOT remove
  empty chunks, they are kept in case the position wants to insert in this
  same chunk.
2024-11-05 16:56:42 +01:00
Benjamin Bouvier b233aa64d2 chore(timeline): rename TimelineItemPosition::Update to UpdateDecrypted 2024-11-05 16:38:13 +01:00
Damir Jelić ace96e372f chore: Fix a warning from an invalid Cargo.toml config for the OIDC example 2024-11-05 16:30:25 +01:00
Mathieu Velten 8865e2ff74 RoomListLoadingState now yields immediately with current value
This fixes a problem when doing an incremental sync at launch,
where `NotLoaded` event	would not be dispatched	until data became
available or timeout is	reached, leading to app waiting for it.
2024-11-05 12:15:16 +01:00
Mathieu Velten 2fa54e5cfa Activate share_pos on the room-list sliding sync instance 2024-11-05 12:15:16 +01:00
Benjamin Bouvier 04275d7c27 refactor!(room list): remove unneeded argument from RoomList::entries_with_dynamic_adapters
Changelog: the parameter `room_info_notable_update_receiver` was removed
 from `RoomList::entries_with_dynamic_adapters`, since it could be
 inferred internally instead.
2024-11-05 10:02:49 +01:00
Benjamin Bouvier 90d6a37b31 refactor(timeline): factor out in-reply-to updates 2024-11-04 17:50:55 +01:00
Benjamin Bouvier 590c2dd9fd fix(timeline): update responses after a successful decryption
Fixes #4196.
2024-11-04 17:50:55 +01:00
Benjamin Bouvier 478dc0ea90 chore(base): refactor internal helpers related to media
Notably, make it super clear what parameters are required to create the
attachment type, since the function doesn't consume the whole
`AttachmentConfig` for realz.
2024-11-04 17:44:30 +01:00
Benjamin Bouvier 7a422fe126 chore(send queue): rename de to dependent_request 2024-11-04 17:42:47 +01:00
Benjamin Bouvier a739ddfc84 chore(event cache store): update test to reflect that previous events and dependent events are cleared
Because the latest migration would clear events to-be-sent from the send
queue, we need to reflect this in this test.
2024-11-04 17:42:47 +01:00
Benjamin Bouvier 1f2e8c5007 refactor!(event cache store): store the serialized QueuedRequestKind, not a raw event
Changelog: The send queue will now store a serialized
 `QueuedRequestKind` instead of a raw event, which breaks the format.
 As a result, all send queues have been emptied.
2024-11-04 17:42:47 +01:00
Benjamin Bouvier c2a921cb58 chore(send queue): move sending of an event to an helper function 2024-11-04 17:42:47 +01:00
Benjamin Bouvier 06e6cba156 chore(event cache store): Support multiple parent key types for dependent requests
This makes it possible to have different kinds of *parent key*, to
update a dependent request. A dependent request waits for the parent key
to be set, before it can be acted upon; before, it could only be an
event id, because a dependent request would only wait for an event to be
sent. In a soon future, we're going to support uploading medias as
requests, and some subsequent requests will depend on this, but won't be
able to rely on an event id (since an upload doesn't return an
event/event id).

Since this changes the format of `DependentQueuedRequest`, which is
directly serialized into the state stores, I've also cleared the table,
to not have to migrate the data in there. Dependent requests are
supposed to be transient anyways, so it would be a bug if they were many
of them in the queue.

Since a migration was needed anyways, I've also removed the `rename`
annotations (that supported a previous format) for the
`DependentQueuedRequestKind` enum.
2024-11-04 17:42:47 +01:00
Jorge Martín 6828f93720 feat(ffi): add Client::is_room_alias_available function 2024-11-04 16:38:44 +01:00
Jorge Martín 7f7b996d24 refactor(ffi): modify Client::resolve_room_alias function
Breaking: `ffi::Client::resolve_room_alias` now returns `Result<Option<ResolvedRoomAlias>, ClientError>` instead of `Result<ResolvedRoomAlias, ClientError>`. This allows the client to match the 3 possible cases:

- The room alias exists.
- The room alias does not exist.
- The function failed internally.
2024-11-04 16:38:44 +01:00
Jorge Martín ee252437d1 fix(pinned_events): get pinned event ids from the HS if the sync doesn't contain it
This should take care of a bug that caused pinned events to be incorrectly removed when the new pinned event ids list was based on an empty one if the required state of the room didn't contain any pinned events info
2024-11-04 16:36:31 +01:00
dependabot[bot] 494532d579 chore(deps): bump crate-ci/typos from 1.26.8 to 1.27.0
Bumps [crate-ci/typos](https://github.com/crate-ci/typos) from 1.26.8 to 1.27.0.
- [Release notes](https://github.com/crate-ci/typos/releases)
- [Changelog](https://github.com/crate-ci/typos/blob/master/CHANGELOG.md)
- [Commits](https://github.com/crate-ci/typos/compare/v1.26.8...v1.27.0)

---
updated-dependencies:
- dependency-name: crate-ci/typos
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-11-04 15:56:26 +01:00
Ivan Enderlin 4002136cfb feat(ui): Remove RoomListService::new_with_encryption.
This patch removes `RoomListService::new_with_encryption`. This feature
is not used, not useful since it's best to use `EncryptionSyncService`,
and it can be racy depending on how it's used. To avoid potential errors
and bugs, it's preferable to remove this code.
2024-11-04 15:17:19 +01:00
Ivan Enderlin 5717eb1722 chore(ui): Display the real error of Error::EventCache (#4207)
This patch displays the wrapped error.
2024-11-04 14:12:18 +00:00
Benjamin Bouvier c08194aa44 chore(ffi): introduce AsyncRuntimeDropped helper
This avoids proliferation of `ManuallyDrop` in the code base, by having
a single type that's used for dropping under an async runtime.
2024-11-04 14:37:50 +01:00
Jorge Martín 5d141fce13 task(room_directory_search): add 'server' parameter to the room directory search
Changelog: a new optional `via_server` parameter was added to `sdk::RoomDirectorySearch::search`, to specify which homeserver to use for searching rooms. In the FFI layer, this parameter is called `via_server_name`.
2024-11-04 09:55:11 +01:00
Richard van der Hoff 70bcddfba5 fix(crypto): Fix spelling error in a warning message. 2024-11-01 12:17:13 +00:00
Kévin Commaille 3c48459768 fix: Upgrade Ruma to 0.11.1
Brings in a fix for KeyId::key_name.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-11-01 12:37:11 +01:00
Benjamin Bouvier 5107f5f23a chore(ffi): in Client::account_url return early when we're not an oidc session
This avoids one spammy log for sessions not using oidc.
2024-11-01 12:07:40 +01:00
Valere d4b9145bc2 Merge pull request #4105 from matrix-org/valere/crypto_ffi_expose_verification_violation
crypto-ffi: Expose `has_verification_violation` for `UserIdentity`
2024-10-31 11:32:46 +01:00
Valere 49f7fe90a9 crypto-ffi: Expose has_verification_violation for UserIdentity 2024-10-31 11:04:42 +01:00
Kévin Commaille 75683d268f refactor(crypto)!: Remove unused OneTimeKey::Key and SessionCreationError::OneTimeKeyUnknown variants
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-10-30 17:13:47 +01:00
Ivan Enderlin 71abbeb1f1 test(sdk): Use EventFactory to simplify the test cases. 2024-10-30 15:28:38 +01:00
Ivan Enderlin fe79826c7a feat(sdk): Find and remove duplicated events in RoomEvents.
This patch uses the new `Deduplicator` type, along with
`LinkeChunk::remove_item_at` to remove duplicated events. When a new
event is received, the older one is removed.
2024-10-30 15:28:38 +01:00
Ivan Enderlin 7d64ea1bbc feat(sdk): Introduce event_cache::Deduplicator.
This patch introduces `Deduplicator`, an efficient type to detect
duplicated events in the event cache. It uses a bloom filter, and
decorates a collection of events with `Decoration`, which an enum that
marks whether an event is unique, duplicated or invalid.
2024-10-30 15:28:38 +01:00
Kévin Commaille 5158b39277 refactor!: Upgrade Ruma to 0.11.0
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-10-30 09:42:19 +01:00
Benjamin Bouvier be88e0ad69 feat(event cache store): Implement renaming media keys 2024-10-29 18:15:28 +01:00
Benjamin Bouvier 50473ba1a8 chore(ring buffer): prefix all tests with test_ in this file 2024-10-29 18:15:28 +01:00
Benjamin Bouvier 5d828d234e feat(ring buffer): implement RingBuffer::iter_mut() 2024-10-29 18:15:28 +01:00
Benjamin Bouvier 9c858c1208 refactor(base): rename all send-queue related "events" to "requests"
Changelog: Renamed all the send-queue related "events" to "requests", so
  as to generalize usage of the send queue to not-events (e.g. medias,
  redactions, etc.).
2024-10-29 18:15:10 +01:00
Benjamin Bouvier 58d46f015b refactor(base): add a QueuedRequestKind enum
In a next commit, the `QueuedEvent` will be renamed to `QueuedRequest`.
This specifies which kind of request we want to send with the send
queue; for now, it can only be an event.
2024-10-29 18:15:10 +01:00
Benjamin Bouvier 4cbd18cb37 refactor(base): move all send-queue related types to a new store::send_queue module
No changes in functionality, only code motion.
2024-10-29 18:15:10 +01:00
Benjamin Bouvier 888f992df0 refactor(base): Renamed StateStore::list_dependend_send_queue_events to load_dependent_send_queue_events 2024-10-29 18:15:10 +01:00
Kévin Commaille ee80291c41 chore: Never skip breaking changes with git-cliff
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-10-29 17:33:01 +01:00
Ivan Enderlin de3a667eb9 chore: Add an empty line between struct fields. 2024-10-29 17:21:34 +01:00
Andy Balaam ce9dc73376 doc(crypto) Crypto changelog documenting VerificationRequestState::Transitioned interface change 2024-10-29 12:08:46 +00:00
Jorge Martín 03535832ec refactor(room): remove sdk::Room::room_power_levels function
This has been replaced by `sdk_base::Room::power_levels`, which can also be used from `sdk::Room`
2024-10-29 12:55:39 +01:00
Jorge Martín c143f981bd refactor(room_list): only display the knock state events if the current user can act on them
That is, if their power level allows them to either invite or kick users.
2024-10-29 12:55:39 +01:00
Jorge Martín f4a18989fb feat(room_list): allow knock state event as latest_event
This allows clients to display pending knocking requests in the room list items.
2024-10-29 12:55:39 +01:00
Ivan Enderlin 6752cf73df test(sdk): Move tests into their correct module. 2024-10-29 10:52:14 +01:00
Ivan Enderlin e87bed8ef4 chore(sdk): Move all RoomEventCache types from mod.rs to room/mod.rs. 2024-10-29 10:52:14 +01:00
Ivan Enderlin 2f19e2b762 chore(sdk): Rename event_cache/store.rs to event_cache/room/events.rs.
This patch renames the `store.rs` file to `room/events.rs`.
2024-10-29 10:52:14 +01:00
Ivan Enderlin b66024c386 test: Update Synapse from 1.115 to 1.117.
This patch updates Synapse in our CI infrastructure and in the
`matrix-sdk-integration-testing` crate.
2024-10-29 10:50:26 +01:00
Ivan Enderlin c48bb13159 doc: Deal with paragraphes in trailers (#4179)
Git trailers have a funny format.

---------

Signed-off-by: Ivan Enderlin <ivan@mnt.io>
Co-authored-by: Benjamin Bouvier <public@benj.me>
2024-10-29 09:39:42 +00:00
Andy Balaam 5f0ba1e7df refactor(crypto) Avoid msk and ssk abbreviations in test data 2024-10-28 16:35:39 +00:00
Andy Balaam 91fa1669be refactor(crypto) Rename device methods in IdentityChangeDataSet to match identity names 2024-10-28 16:35:39 +00:00
Andy Balaam a1a4ce0a95 refactor(crypto) Tidy IdentityChangeDataSet test data 2024-10-28 16:35:39 +00:00
Andy Balaam 131921c045 fix(tests) Increase a test timeout to fix occasional flakes I saw locally 2024-10-28 16:35:39 +00:00
Ivan Enderlin b62661bc70 feat(sdk): Map Update::RemoveItem into VectorDiff::Remove in UpdateToVectorDiff.
This patch implements the support of `Update::RemoveItem` inside
`UpdateToVectorDiff` to emit a `VectorDiff::Remove`.
2024-10-28 17:17:01 +01:00
Ivan Enderlin e0be1e8e32 fix(sdk): Fix a bug in an optimisation of UpdatetoVectorDiff.
This patch fixes a bug in an optimisation inside `UpdateToVectorDiff`
when an `Update::PushItems` is handled. It can sometimes create
`VectorDiff::Append` instead of a `VectorDiff::Insert`. The tests will
be part of the next patch.
2024-10-28 17:17:01 +01:00
Ivan Enderlin c23c3b9558 chore(sdk): Rename a couple of variables.
This is another clean up patch.
2024-10-28 17:17:01 +01:00
Ivan Enderlin ca3d5693b4 chore(sdk): Rename a couple of variables.
This is a clean up patch, nothing fancy.
2024-10-28 17:17:01 +01:00
Ivan Enderlin 135c448f2d chore(sdk): Extract code into a map_to_offset method.
This is only code move, nothing has changed.
2024-10-28 17:17:01 +01:00
Ivan Enderlin 01cbce907c feat(sdk): Add LinkedChunk::remove_item_at.
This patch adds the `LinkedChunk::remove_item_at` method, along with
`Update::RemoveItem` variant.
2024-10-28 17:17:01 +01:00
Stefan Ceriu df4a5c36fc Pass the DeviceData in between the Ready and Transitioned states instead of fetching it from the store. 2024-10-28 17:04:50 +02:00
Stefan Ceriu 8492968792 Pass a copy of the other DeviceData in between the (Requested, Ready) and (Created, Ready) states 2024-10-28 17:04:50 +02:00
Stefan Ceriu d31f5b2a72 chore(tests): fix verification integration tests following changes to the data associated with VerificationRequestState::Requested 2024-10-28 17:04:50 +02:00
Stefan Ceriu 8469cb1146 fix(crypto): fix incorrect VerificationMachine tests
- the tests used to incorrectly wrap the to-device content into an event as if it was sent by alice instead of bob
2024-10-28 17:04:50 +02:00
Stefan Ceriu bb8b0cf6b9 Expose requesting device details to the final client 2024-10-28 17:04:50 +02:00
Stefan Ceriu 35dabf7346 feat(crypto): store a copy of the requesting DeviceData within VerificationRequestStates 2024-10-28 17:04:50 +02:00
Stefan Ceriu f771eec3c5 Fix a clippy warning re single matching 2024-10-28 17:04:50 +02:00
Stefan Ceriu 6455585f1e Documentation + cleanup 2024-10-28 17:04:50 +02:00
Stefan Ceriu 3a34b03726 Expose mechanism for registering to verification updates before actually accepting one
- allows handling remote cancellations on verification requests that have not yet been accepted
2024-10-28 17:04:50 +02:00
Stefan Ceriu 8cf0716db2 refactor(ffi): switch to using VerificationRequest::changes instead of direct to_device events. 2024-10-28 17:04:50 +02:00
Stefan Ceriu 660a305cfa feat(ffi): add support for receiving and working with session verification requests
fixup! feat(ffi): add support for receiving and working with session verification requests
2024-10-28 17:04:50 +02:00
dependabot[bot] b2af1eeb20 chore(deps): bump crate-ci/typos from 1.26.0 to 1.26.8
Bumps [crate-ci/typos](https://github.com/crate-ci/typos) from 1.26.0 to 1.26.8.
- [Release notes](https://github.com/crate-ci/typos/releases)
- [Changelog](https://github.com/crate-ci/typos/blob/master/CHANGELOG.md)
- [Commits](https://github.com/crate-ci/typos/compare/v1.26.0...v1.26.8)

---
updated-dependencies:
- dependency-name: crate-ci/typos
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-10-28 15:36:15 +01:00
Ivan Enderlin 77b3aa8124 test(sdk): Test the RoomEvents' methods.
This patch adds unit tests for the `RoomEvents`' methods.
2024-10-28 13:30:35 +01:00
Ivan Enderlin cf7cb5c350 doc(sdk): Add more documentation for RoomEvents. 2024-10-28 13:30:35 +01:00
Ivan Enderlin ac7bc6461f chore(sdk): Add an Event type alias for the sake of convenience.
This patch adds an `Event` type alias to `SyncTimelineEvent` to (i) make
the code shorter, (ii) remove some cognitive effort, (iii) make things
more convenient.
2024-10-28 13:30:35 +01:00
Doug 7c39fd6ae5 chore(ffi): Expose supported OIDC prompts in the login details. 2024-10-28 13:26:14 +01:00
Jorge Martin Espinosa 40f4fc138b chore(room_preview): add RoomListItem::preview_room (#4152)
This method will return a `RoomPreview` for the provided room id. 

Also added `fn RoomPreview::leave()` action to be able to decline
invites or cancel knocks, since there wasn't a
`Client::leave_room_by_id` counterpart as there is for join.

The PR also deprecates `RoomListItem::invited_room`, since we have a
better alternative now.

Co-authored-by: Benjamin Bouvier <benjamin@bouvier.cc>
2024-10-25 14:33:16 +02:00
Andy Balaam d3d7c03892 doc(crypto) Update a doc comment on update_user_state_to 2024-10-25 14:27:06 +02:00
Andy Balaam 3558886b98 feat(crypto) Support Verified and VerificationViolation updates in IdentityStatusChanges streams 2024-10-25 10:32:14 +01:00
Andy Balaam 47361b93e9 refactor(crypto) Test RoomIdentityState by hard-coding identity states 2024-10-25 10:32:14 +01:00
Andy Balaam f5cdbd8e41 refactor(crypto) Rename test functions to reflect wider name change
and simplify them slightly by combining the wrapper with the main
function. The separation used to be needed, but is not any more.
2024-10-25 10:32:14 +01:00
Benjamin Bouvier f8c23d8aa0 feat(media): add support for async uploads
Changelog: Support for preallocated media content URI has been added in
`Media::create_content_uri()`, and uploading the content for such a
preallocated URI is possible with `Media::upload_preallocated()`.
2024-10-24 16:49:05 +02:00
Benjamin Bouvier 1a3c5045dd chore(room): add copyright notice to sdk/room/mod 2024-10-24 16:49:05 +02:00
Stefan Ceriu ca1d829788 sliding_sync(state): use * for m.call.member when requesting state through sliding sync
- introduced in https://github.com/matrix-org/matrix-rust-sdk/pull/4159 with an empty string
- call members use custom `state_key`s and as such not specifying the sentinel won't match them and state won't be returned
2024-10-24 11:35:41 +03:00
Valere 31e9600078 feat(send_queue): Persist failed to send errors (#4137)
Modify the SendQueue in order to persist the error that cause the event
to fail to send as a `QueueWedgeError`. The `QueueWedgeError` is not a
1:1 mapping for all kinds of errors, but holds variant and information
that the client can react to in order to propose "quick fixes"/solution
before retrying to send.

Fixes https://github.com/matrix-org/matrix-rust-sdk/issues/3973 
Also fixes https://github.com/element-hq/element-x-ios/issues/3287
because when a timeline reset occurs the fail to send reason is also
lost.

This PR starts with a refactoring commit
https://github.com/matrix-org/matrix-rust-sdk/commit/e7696003e846b64c41761109f326fd37c4506040
to introduce the new `QueueWedgedError` and move the logic that was in
the ffi layer to convert api errors to SendState error variant. This
`QueueWedgedError` can be directly use in the `SendingFailed` variant
and expose to ffi.

Second commit
https://github.com/matrix-org/matrix-rust-sdk/commit/109c1337465ba7965825fec858fd2a4b8b954611
adds the persistence, `QueuedEvent` now have an optional error field
instead of a `is_weged` boolean. Same for LocalEchoContent::Event.
Adds also Migration for sqlite and indexeddb

Co-authored-by: Benjamin Bouvier <benjamin@bouvier.cc>

Changelog:  We now persist the error that caused an event to fail to send. The error `QueueWedgeError` contains info that client can use to try to resolve the problem when the error is not automatically retry-able. Some breaking changes occurred in the FFI layer for `timeline::EventSendState`, `SendingFailed` now directly contains the wedge reason enum; use it in place of the removed variant of `EventSendState`.
2024-10-23 12:48:55 +02:00
Richard van der Hoff 3291a426d8 test(crypto): rename UtdCause tests with test_ prefix 2024-10-23 09:44:07 +01:00
Richard van der Hoff 1368a8534c feat(crypto): Add more reason codes to UtdCause 2024-10-23 09:44:07 +01:00
Richard van der Hoff 7cfcc8ecc1 refactor(crypto): pass utd info into UtdCause::determine
We'll need this for future changes
2024-10-23 09:44:07 +01:00
Richard van der Hoff c4f9c20115 feat(crypto): rename UtdCause::Membership
Before we do any more work here, give this variant a better name

Breaking-Change: `matrix_sdk_crypto::type::events::UtdCause::Membership` has
been renamed to `...::SentBeforeWeJoined`.
2024-10-23 09:44:07 +01:00
Richard van der Hoff 0c81206653 refactor(timeline): retry_event_decryption: re-use utd cause
Rather than calling `UtdCause::determine` again when an event is successfully
decrypted on retry, re-use the cause we already determined.
2024-10-23 09:44:07 +01:00
Richard van der Hoff a61bc3cbbd refactor(ui): add UTD info to TimelineEventKind::UnableToDecrypt
Stash the reason for the decryption failure in
`matrix-sdk-ui::event_handler::TimelineEventKind::UnableToDecrypt`.

It's not yet used.
2024-10-23 09:44:07 +01:00
Richard van der Hoff 74de617d76 refactor(ui): add TimelineEventKind::UnableToDecrypt
Give `matrix-sdk-ui::event_handler::TimelineEventKind` a new variant which
specifically represents events that could not be decrypted.
2024-10-23 09:44:07 +01:00
Jorge Martín 3f5d54c494 chore(knocking): Add optional reason and server_names parameters to Client::knock 2024-10-22 18:33:18 +02:00
Stefan Ceriu f2f99fb207 chore(ffi): move the store_in_cache timeline media upload parameter before the progress_watcher closure for aesthetic reasons 2024-10-22 18:18:32 +03:00
Benjamin Bouvier 6196ebaba6 chore(media): use the same media method when caching a thumbnail as the default one used in the FFI
The FFI will request a scaled version of the thumbnail by default; let's
use the same cache key when caching the thumbnail after an upload.

Thanks @zecakeh for flagging the issue.
2024-10-22 15:47:58 +02:00
Ivan Enderlin 65bb373379 chore(ui): Add the DEFAULT_ROOM_SUBSCRIPTION_EXTRA_REQUIRED_STATE constant.
This patch refactors 2 `chain(once(…))` with a 1 `chain`. It
also clarifies the extra `required_state` that are added for room
subscriptions.
2024-10-22 14:55:10 +02:00
Ivan Enderlin e62c47132e feat(ui): RoomListService::subscribe_to_rooms no longer has a settings argument.
This patch removes the `settings` argument of
`RoomListService::subscribe_to_rooms`. The settings were mostly composed
of:

* `required_state`: now shared with `all_rooms`, so that we are
  sure they are synced; except that `m.room.create` is added for
  subscriptions.
* `timeline_limit`: now defaults to 20.

This patch thus creates the `DEFAULT_REQUIRED_STATE` and
`DEFAULT_ROOM_SUBSCRIPTION_TIMELINE_LIMIT` constants.

Finally, this patch updates the tests, and updates all usages of
`subscribe_to_rooms`.
2024-10-22 14:55:10 +02:00
Ivan Enderlin 996b391506 feat(ui): Add m.room.topic and m.room.pinned_events in all_rooms.
This patch adds the `m.room.topic` and `m.room.pinned_events` state
events in the `required_state` of the `all_rooms` sliding sync list of
`RoomListService`.
2024-10-22 14:55:10 +02:00
Ivan Enderlin 74722f48aa fix(ui): Add the m.call.member state event in the required state.
This patch adds the `m.call.member` state event in the `required_state`
for `all_rooms` of the `RoomListService`.
2024-10-22 14:55:10 +02:00
Andy Balaam e3180cdbc5 fix(crypto): Don't warn about verified users when subscribing to identity updates 2024-10-22 12:40:31 +01:00
Benjamin Bouvier 9c03c5dd7e feat(media): cache thumbnails too with a sensible media request key
We can't know which key is going to be used precisely for the thumbnail,
so assume non-animated cropped same-size thumbnail media request.

Changelog: when `SendAttachment::store_in_cache()` is set, the thumbnail
is also cached with a sensible default media request (not animated,
cropped, same dimensions as the uploaded thumbnail).
2024-10-22 12:06:15 +02:00
Benjamin Bouvier b46ebbf34e feat(media): don't clone the data when uploading an encrypted media 2024-10-22 12:06:15 +02:00
Benjamin Bouvier d3bfdb9563 feat(media)!: optionally cache a media after upload
Changelog: Uploaded medias can now be cached in multiple
attachment-related methods like `Room::send_attachment`.
2024-10-22 12:06:15 +02:00
Richard van der Hoff 3887c10444 test: Update tests to use new UTD TimelineEventKind variant
Make the tests behave the same way as the network code, by returning UTDs
as `TimelineEventKind::UnableToDecrypt` instead of `TimelineEventKind::PlainText`.
2024-10-21 17:26:34 +01:00
Richard van der Hoff b69575d5ff refactor(timeline): store UTDs in decrypt_room_event
When `decrypt_room_event` fails to decrypt an event, return the UTD as a
`TimelineEvent` instead of an Error.
2024-10-21 17:26:34 +01:00
Richard van der Hoff 543152d914 refactor(timeline): store UTDs in decrypt_sync_room_event
When `decrypt_sync_room_event` fails to decrypt an event, return the UTD as a
`SyncTimelineEvent` instead of an Error.
2024-10-21 17:26:34 +01:00
Richard van der Hoff c8b38257f1 refactor(common): add TimelineEventKind::UnableToDecrypt 2024-10-21 17:26:34 +01:00
Andy Balaam 2df359d316 fix(experimental-algorithms) Add missing argument to handle_supported_key_request 2024-10-21 16:56:31 +01:00
Benjamin Bouvier 951a4354c6 refactor(timeline): get rid of local_item_by_transaction_id
There's no need for this API anymore.

Changelog: `Timeline::get_event_timeline_item_by_transaction_id` has
been removed. There's no API that makes use of an `EventTimelineItem`
now, those APIs are using a `TimelineEventItemId` instead.
2024-10-21 17:25:23 +02:00
Doug befcd069c3 FFI: Expose UserIdentity::is_verified and add a new Encryption::user_identity method. (#4142) 2024-10-21 13:36:34 +00:00
Richard van der Hoff 0c26988cf5 refactor(base): Remove impl From for SyncTimelineEvent
I feel like the ability to convert straight from a `Raw<AnySyncTimelineEvent>>`
into a `SyncTimelineEvent` is somewhat over-simplified: the two are only
occasionally equivalent, and it's better to be explicit.

Changelog: `SyncTimelineEvent` no longer implements `From<Raw<AnySyncTimelineEvent>>`.
2024-10-21 12:48:14 +01:00
Ivan Enderlin a7f69973c2 feat(sdk): Dropping a UpdatesSubscriber release the reader token for the GC.
The event cache stores its events in a linked chunk. The linked chunk
supports updates (`ObservableUpdates`) via `LinkedChunk::updates()`.
This `ObservableUpdates` receives all updates that are happening inside
the `LinkedChunk`. An `ObservableUpdates` wraps `UpdatesInner`, which
is the real logic to handle multiple update readers. Each reader has a
unique `ReaderToken`. `UpdatesInner` has a garbage collector that drops
all updates that are read by all readers. And here comes the problem.

A category of readers are `UpdatesSubscriber`, returned by
`ObservableUpdates::subscribe()`. When an `UpdatesSubscriber` is
dropped, its reader token was still alive, thus preventing the garbage
collector to clear all its pending updates: they were kept in memory
for the eternity.

This patch implements `Drop` for `UpdatesSubscriber` to correctly remove
its `ReaderToken` from `UpdatesInner`. This patch also adds a test that
runs multiple subscribers, and when one is dropped, its pending updates
are collected by the garbage collector.
2024-10-21 11:17:09 +02:00
Ivan Enderlin 1750bf597f test(sdk): Fix a comment. 2024-10-21 11:17:09 +02:00
Jorge Martín ad677cb6f2 chore(ffi): Add optional canonical_alias field to CreateRoomParameters 2024-10-18 13:21:04 +02:00
Andy Balaam 350a26cee9 refactor(crypto): Extract a test helper function for simulating verification 2024-10-18 11:37:37 +01:00
Benjamin Bouvier 08152bd9fc refactor(sdk)!: rename PrepareEncryptedFile et al. to UploadEncryptedFile
Changelog: Renamed `PrepareEncryptedFile` and
`Client::prepare_encrypted_file` to `UploadEncryptedFile` and
`Client::upload_encrypted_file`.
2024-10-17 16:54:50 +02:00
Benjamin Bouvier 89183a3d4b doc(timeline): rejigger a doc comment around sending attachments 2024-10-17 16:54:50 +02:00
Benjamin Bouvier 65ed4f3f22 refactor(ffi): push further and inline parse_mime into the same caller 2024-10-17 16:54:50 +02:00
Benjamin Bouvier 41d392f899 refactor(ffi): commonize creation of the attachment with a thumbnail 2024-10-17 16:54:50 +02:00
Benjamin Bouvier 1ce5160846 refactor(ffi): introduce a parse_mime function to avoid code repetition 2024-10-17 16:54:50 +02:00
Benjamin Bouvier dc4c6b4d73 refactor(media): inline update_audio_message_event into its unique caller
The name wasn't very descriptive, and it's tweaking the content, so
let's do that in place, instead of deferring to another method somewhere
else in the codebase.
2024-10-17 16:54:50 +02:00
Benjamin Bouvier 3b33f3779f chore(media): rename upload methods to make their intents clearer 2024-10-17 16:54:50 +02:00
Benjamin Bouvier 7089ff51c4 refactor(room): take the transaction id by ownership in with_transaction_id
This allows letting the caller whether they need to clone it or not, and
avoids a spurious clone in one call site.
2024-10-17 16:54:50 +02:00
Benjamin Bouvier d8de12561b refactor(media): regroup preparation of the media message after uploading the content
The tails of the prepare_attachment_message and
prepare_encrypted_attachment_message were almost the same, with the one
different that they were using different ctors for the `EventContent`
types. In fact, all these `EventContent` types also expose a plain `new`
function that can take in either an encrypted or a plain media source,
so we can commonize the code there.
2024-10-17 16:54:50 +02:00
Benjamin Bouvier 56edc9d00f chore(media): rename all event content values to content 2024-10-17 16:54:50 +02:00
Benjamin Bouvier 2ea114d988 chore(media): reduce indent level of upload_thumbnail by one with let-else 2024-10-17 16:54:50 +02:00
Jorge Martín c7708d6154 feature(ffi): Add optional CreateRoomParameters::join_rule_override
This allows clients to set custom join rules for a room, as would be needed for the knock-only rooms, or restricted rooms (those that can only be joined if the user is part of some other room or space).
2024-10-17 16:05:07 +02:00
Benjamin Bouvier bdfe64179b feat(ffi): support custom membership state value in MembershipState 2024-10-17 15:30:34 +02:00
Benjamin Bouvier 59c47fb22d fix(ffi): don't panic when running into an unknown membership state
Fixes #1254.
2024-10-17 15:30:34 +02:00
Benjamin Bouvier 821fa8fa99 refactor(timeline): don't return a bool in Timeline::edit
See previous commit for explanations. This makes for a simpler API
anyways.

Changelog: `Timeline::edit` doesn't return a bool anymore to indicate it
couldn't manage the edit in some cases, but will return errors
indicating what the cause of the error is.
2024-10-17 14:55:17 +02:00
Benjamin Bouvier a5f1769e28 refactor(timeline): return an invalid local echo state error if a local echo disappeared
I think this can't happen, but the send queue can return an error if a
local echo identified by a transaction id doesn't exist anymore in the
database. The only reason the latter could happen is because the local
echo has been sent, in which case an update to the timeline would be
dispatched, and the timeline item would have morphed into a remote echo
in the meantime. So it's really rare that this would happen, and the
`Timeline::redact()` method doesn't have to return a boolean to indicate
success in general.

Changelog: `Timeline::redact()` doesn't return a boolean; previously, it
would only return false if the internal state was invalid, so a new
error `RedactError::InvalidLocalEchoState` has been introduced to
represent that.
2024-10-17 14:55:17 +02:00
Benjamin Bouvier 59fce90943 chore(ffi): revert to using a room method to edit if a remote event couldn't be found in the timeline
This maintains functionality we had prior to the previous commit: if an
event's missing from the timeline (e.g. timeline's been cleared after a
gappy sync response), then still allow editing it.
2024-10-17 14:55:17 +02:00
Benjamin Bouvier 81bebcf692 refactor(timeline): fuse edit_by_id() within edit()
In particular, this means that trying to edit an event that's not
present anymore in a timeline (e.g. after a timeline reset) will fail,
while it worked before.

Changelog: `Timeline::edit_by_id` has been fused into `Timeline::edit`,
which now takes a `TimelineEventItemId` as the identifier for the local
or remote item to edit. This also means that editing an event that's not
in the timeline anymore will now fail. Callers should manually create
the edit event's content, and then send it via the send queue; which the
FFI function `Room::edit` does.
2024-10-17 14:55:17 +02:00
Benjamin Bouvier c4dd2d192e refactor(timeline): fuse redact_by_id() within redact()
Changelog: `Timeline::redact_by_id` has been fused into
`Timeline::redact`, which now takes a `TimelineEventItemId` as an
identifier of the item (local or remote) to redact.
2024-10-17 14:55:17 +02:00
Benjamin Bouvier a901506a53 fix(ffi): don't panic when joining after having cancelled a media upload
Fixes #3573.
2024-10-16 18:52:06 +02:00
Richard van der Hoff 87f89ec561 crypto: update changelog 2024-10-16 16:44:48 +01:00
Richard van der Hoff 2820f5f3b4 crypto: new method OlmMachine::try_decrypt_room_event 2024-10-16 16:44:48 +01:00
Richard van der Hoff 427c59e266 crypto: add UnableToDecryptReason to UnableToDecryptInfo
Add a field to store the reason that the decryption failed
2024-10-16 16:44:48 +01:00
Richard van der Hoff 4a7f924161 timeline: tests for deserializing SyncTimelineEvent with unsigned events 2024-10-16 16:44:48 +01:00
Richard van der Hoff 2829b07305 doc: fix typo in contributing guide
The convention is for changelog entries to be in the imperative, not the past
tense.
2024-10-16 17:06:10 +02:00
Benjamin Bouvier 4f49b23751 refactor(timeline): introduce TimelineUniqueId as an opaque type for the unique identifier
We can now use this type instead of passing a string, which means
there's no way to confuse oneself in methods like
`toggle_reaction_local`.

Changelog: Introduced `TimelineUniqueId`, returned by
`TimelineItem::unique_id()` and serving as an opaque identifier to use
in other methods modifying the timeline item (e.g. `toggle_reaction`).
2024-10-16 16:21:34 +02:00
Benjamin Bouvier 962a78ab13 chore(timeline): always increment the unique id to avoid issues with stall IDs across timeline clears 2024-10-16 16:21:34 +02:00
Jorge Martín 664f6d5f5a feat(knocking): add code to process knocked rooms separately during sync 2024-10-16 16:12:39 +02:00
Benjamin Bouvier 30f3a3c2e4 chore(timeline): fix instrumentation of update_event_send_state
This would not report the `txn_id` field because of the `skip_all`. It's
actually interesting to also get the error, so I'm only skipping self
from now on.
2024-10-16 15:03:36 +02:00
Benjamin Bouvier 8df5d655c0 feat(multiverse): add support to toggle a reaction on the last message of a room 2024-10-16 15:03:36 +02:00
Benjamin Bouvier 1552426961 timeline: get rid of conversions from string to TimelineEventItemId
I suppose these were useful at the FFI layer at some point, but they
aren't anymore, so they could be removed.

Changelog: Got rid of `From<String/&str>` for `TimelineEventItemId`.
2024-10-16 15:03:36 +02:00
Benjamin Bouvier 8b7494d17b timeline: use a TimelineItemId to react to a timeline item
Changelog: `Timeline::toggle_reaction` now identifies the item that's
reacted to with a `TimelineEventItemId`.
2024-10-16 15:03:36 +02:00
Benjamin Bouvier 77e5281781 chore(timeline): instrument timeline tasks with their focus and internal prefix
This would have avoided a few hours of debugging where we thought there
was an issue with multiple timelines spawned at the same time, and then
realized it was expected because of the existence of the pinned timeline
in EX apps.
2024-10-16 14:38:21 +02:00
Andy Balaam efc2e2c4c8 doc(contributing): Recommend --interactive for git rebase --autosquash
Older versions of Git require --interactive when we supply --autosquash,
and it's also probably a good idea generally.

See https://stackoverflow.com/a/77663575/22610 for more info.
2024-10-16 10:47:15 +01:00
Jorge Martín 79798a9de9 refactor(oidc): allow passing a Prompt to get an OIDC url
Changelog: `Client::url_for_oidc_login` is now `Client::url_for_oidc` with an additional `OidcPrompt` parameter. `abort_oidc_login` has been renamed to `abort_oidc_auth`.

This allows clients to directly open the web page they want: the login one, the registration one, consent, etc. It should improve the UX in the registration flow since we can now skip the login one.
2024-10-16 11:28:34 +02:00
Kévin Commaille 3d0423447c fix(qrcode): Do not enable default features of image crate
Gets rid of dependencies for the different image formats.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-10-16 10:55:11 +02:00
Kévin Commaille 9999d3ba96 chore(sdk)!: Remove image-proc feature and functions to generate a thumbnail
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-10-16 10:55:11 +02:00
Kévin Commaille ee4ef2eb53 sdk: Remove room from in-memory list when calling Room::forget
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-10-15 17:04:47 +02:00
Kévin Commaille 0b57ef4bf6 sdk: Remove room from m.direct account data in Room::forget
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-10-15 17:04:47 +02:00
Benjamin Bouvier 6dd2e3becf refactor(event cache): use a single mutex for the prev and next batch pagination tokens 2024-10-15 16:15:40 +02:00
Benjamin Bouvier 1018d71bb7 refactor(event cache): get rid of the RoomPaginationData data structure
It only contained two fields, and it avoids one extra level of cognitive
overhead and makes the type hierarchy flatter.
2024-10-15 16:15:40 +02:00
Benjamin Bouvier 87472e7679 refactor(event cache): introduce RoomEventCacheState for inner mutable state
This limits the possibility of race conditions in users of this API.
2024-10-15 16:15:40 +02:00
Benjamin Bouvier cdbfae2aee doc(event cache): simplify module comment, as a source file isn't a good todo list
All the items have their equivalent sub item in the issue anyways.
2024-10-15 16:15:40 +02:00
dependabot[bot] 2eca7271ea chore(deps): bump actions/checkout from 3 to 4
Bumps [actions/checkout](https://github.com/actions/checkout) from 3 to 4.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v3...v4)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-10-15 09:27:23 +02:00
dependabot[bot] 92a02a51c4 chore(deps): bump crate-ci/typos from 1.25.0 to 1.26.0
Bumps [crate-ci/typos](https://github.com/crate-ci/typos) from 1.25.0 to 1.26.0.
- [Release notes](https://github.com/crate-ci/typos/releases)
- [Changelog](https://github.com/crate-ci/typos/blob/master/CHANGELOG.md)
- [Commits](https://github.com/crate-ci/typos/compare/v1.25.0...v1.26.0)

---
updated-dependencies:
- dependency-name: crate-ci/typos
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-10-15 08:04:16 +02:00
Andy Balaam 019d198af8 crypto: Sort IdentityStatusChanges when providing them via subscribe_to_identity_status_changes
Fixes https://github.com/element-hq/element-meta/issues/2566
2024-10-14 10:46:58 +01:00
Damir Jelić e6db85b7d4 chore: Enable the default features for futures-util (#4120)
We depend on the `futures_util::steam_select` macro since 9b36a04b. This
macro requires the async-await-macros and std feature of futures-util.

These features are the default features so let's just stop disabling the
default features for futures-util.

Signed-off-by: Damir Jelić <poljar@termina.org.uk>
Co-authored-by: Jonas Platte <jplatte@matrix.org>
2024-10-13 19:41:11 +00:00
Jonas Platte a4bda1ac66 chore: Move lint configuration out of .cargo/config.toml
This allows removing a lot of hacks to avoid spurious rebuilds.
2024-10-11 12:40:18 +02:00
Jonas Platte e46e63771b chore(ffi): Merge export and export_async attribute macros 2024-10-11 09:57:48 +02:00
Damir Jelić 41a2ad09cf chore: Move the ffi macros into the bindings folder 2024-10-10 19:58:50 +02:00
Benjamin Bouvier 32919405d6 refactor(ffi): use a single provider for lazily computed info 2024-10-10 15:39:55 +02:00
Benjamin Bouvier b002a8da52 refactor(ffi): Don't repeat information in EventTimelineItem about local vs remote echoes 2024-10-10 15:39:55 +02:00
Benjamin Bouvier 85682ac37f chore(timeline): add extra logs to investigate edit issues 2024-10-10 15:17:18 +02:00
Ivan Enderlin 22c765b9ab fix(ui): all_rooms in RoomListService requires the m.room.avatar state.
This patch updates the `required_state` of `all_rooms` inside the
`RoomListService` to add `m.room.name`. Apparently, Synapse doesn't
always update the `response.rooms.*.avatar` field when the avatar is
updated. It's being investigated, but it doesn't hurt to ensure we get
it from the state events.
2024-10-10 15:07:57 +02:00
Ivan Enderlin 3ad8f1d607 test(integration): Fix one test by adding required_state.
To fix the `test_room_avatar_group_conversation`, we need to ask for the
`m.room.avatar` state event from `required_state`. The rest of the patch
rewrites the test a little bit to make it more Rust idiomatic.

The `response.rooms.*.avatar` field from sliding sync should contain the
new avatar, but for the moment, it doesn't. It seems to be a bug.
2024-10-10 15:07:57 +02:00
Ivan Enderlin a4782939b3 test(integration): Fix one test by adding required_state.
To fix the `test_left_room`, we need to ask for the `m.room.member`
state event from `required_state`. The rest of the patch rewrites the
test a little bit to make it more Rust idiomatic.
2024-10-10 15:07:57 +02:00
Ivan Enderlin 72dc307400 fix(base): Add a way for handle_timeline to ignore state events.
Sliding sync expects all state events to be in `required_state`. State
events in `timeline` **must be ignored**. However, in sync v2, state
events in `timeline` **must be handled**.

In the sync response flow, both sliding sync and sync v2 uses the same
`handle_timeline` method. This patch adds an argument to ignore state
events. This is not ideal, but it's a temporary solution as a first
step. The next step is to refactor this code, but let's start easy.

The rest of the patch updates the tests accordingly.
2024-10-10 15:07:57 +02:00
Ivan Enderlin 248cf55272 fix(base): Don't use state events from timeline with sliding sync.
With sliding sync, we must handle state events from `required_state`
only, not from `timeline`, this is a mistake as they might be incomplete
or _staled_.
2024-10-10 15:07:57 +02:00
Damir Jelić 1260e740ba Update the contributing guide with our new git-cliff setup
Co-authored-by: Ivan Enderlin <ivan@mnt.io>
2024-10-10 14:32:46 +02:00
Damir Jelić 9a4a67d488 Document the new release process 2024-10-10 14:32:46 +02:00
Damir Jelić ab0871f299 Call git-cliff as a pre-release hook 2024-10-10 14:32:46 +02:00
Damir Jelić 86d9fe59d2 Create an xtask for the release handling 2024-10-10 14:32:46 +02:00
Damir Jelić 1945b508c3 Create some missing changelog files 2024-10-10 14:32:46 +02:00
Damir Jelić 4c7461357c Add a git-cliff configuration file 2024-10-10 14:32:46 +02:00
Damir Jelić ca7f2ad3d0 Add a cargo-release config 2024-10-10 14:32:46 +02:00
Benjamin Bouvier 711f4cb868 ci: detect unused dependencies with cargo-machete 2024-10-10 14:18:36 +02:00
Benjamin Bouvier cb51a3155a chore: get rid of unused dependencies 2024-10-10 14:18:36 +02:00
Damir Jelić 81119a66d8 ci: Install libsqlite, it does not seem to be part of the latest ubuntu image (#4108) 2024-10-10 13:43:58 +02:00
Richard van der Hoff 9c6413551c Inline SyncTimelineEvent::set_raw
This is only used in one place, and is much better inlined anyway.
2024-10-09 15:19:26 +01:00
Richard van der Hoff 42f0d83b53 timeline: remove redundant Debug implementations
These are no longer required now that the event itself lives in an inner class.
2024-10-09 15:19:26 +01:00
Richard van der Hoff d9167f208a timeline: Extract inner parts of [Sync]TimelineEvent
Pull out the bits of these classes which are dependent on success or otherwise
of decrypting an event to a new enum.
2024-10-09 15:19:26 +01:00
Richard van der Hoff 7f0a3f0e47 timeline: make TimelineEvent::into_raw return a Raw<AnySyncTimelineEvent>
Give `Timeline::into_raw()` the same treatmeant we just gave `Timeline::ra()`.
2024-10-09 15:19:26 +01:00
Richard van der Hoff 8fe61e1fb3 timeline: make TimelineEvent::raw return a Raw<AnySyncTimelineEvent>
I'm going to be replacing the inner structure of `TimelineEvent` with an
implementation that holds a `Raw<AnySyncTimelineEvent>`, rather than a
`Raw<AnyTimelineEvent>`. Prepare for that by changing the accessors to return
`Raw<AnySyncTimelineEvent>`.
2024-10-09 15:19:26 +01:00
Richard van der Hoff 07cfe3da94 timeline: make TimelineEvent fields private
... and add accessors instead.

Give `TimelineEvent` the same treatment we just gave `SyncTimelineEvent`: make
the fields private, and use accessors where we previously used direct access.
2024-10-09 15:19:26 +01:00
Richard van der Hoff 4d472f6aed timeline: make SyncTimelineEvent fields private
... and add accessors instead.

I'm going to change the inner structure of `SyncTimelineEvent`, meaning that
access will have to be via an accessor in future. Let's start by making the
fields private, and use accessors where we previously used direct access.
2024-10-09 15:19:26 +01:00
Richard van der Hoff ce231e6c2b timeline: test for SyncTimelineEvent serialization
I'm going to change the internal structure of `SyncTimelineEvent`, and since
it implements `Deserialize`, we need to not break it. Let's add a test for the
current format.
2024-10-09 15:19:26 +01:00
Richard van der Hoff b36a9ad781 timeline: Add documentation to [Sync]TimelineEvent
I found it hard to understand what these two structs were for, so let's start
by giving them some documentation.
2024-10-09 15:19:26 +01:00
Doug 95ae5d1938 ffi: Rename get_media_file body parameter to filename. 2024-10-09 10:52:35 +02:00
Doug 9d976d0bcf sdk: Update get_media_file to take a filename instead of the body. 2024-10-09 10:52:35 +02:00
Kévin Commaille 17370a5702 sdk: Upgrade aquamarine
Finally get rid of syn 1!

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-10-08 19:05:35 +02:00
Jorge Martín b793acd2b1 sdk-ui: allow already sent local events to be redacted using redact_by_id
Test this use case.
2024-10-08 17:50:05 +02:00
Mathieu Velten 752706c51d Get back to Recovering syncing when we haven't sync for a while 2024-10-08 17:17:42 +02:00
Benjamin Bouvier 736aa0351c ffi: add our own macro for processing exports
Including one that will always warn if used with async functions, and
the other one always setting the tokio runtime if used for async stuff.
2024-10-08 17:11:39 +02:00
boxdot 4bcb9b7d9f fix: Fix a deadlock between bootstrap_cross_signing and sync (#4060)
`bootstrap_cross_signing` holds a lock on the private identity. In case
a new identity is created, it will try to acquire a lock on `account`.
The latter is locked by `sync`, which tries to acquire a lock on the private identity.

Note that the `bootstrap_cross_signing` call is executed in a separate
task e.g. in `restore_session`. In particular, this task and `sync` both
race to acquire locks described above.

Signed-off-by: boxdot <d@zerovolt.org>
2024-10-08 15:12:40 +02:00
Jorge Martín 867d9c71fd sdk-base: add prev_room_state to RoomInfo
This is useful for the knocking feature since we'll be able to differentiate between rooms that you were just invited from rooms that you knocked and then were granted access, or rooms that you left and rooms where your knocking attempt was rejected.

The `mark_room_as_*` functions have been updated so they reuse the same `set_state` function underneath, which only updates the previous state if the new one doesn't match.
2024-10-08 13:16:40 +02:00
Kévin Commaille 2dcf06fad2 sdk: Add support for authenticated media stable feature
Was added post-merge to the MSC for servers that support
authenticated media but do not support all of Matrix 1.11 yet.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-10-08 12:21:32 +02:00
Jorge Martín 1fc3450eac ffi & sdk: add room knocking to Client 2024-10-08 12:07:01 +02:00
Benjamin Bouvier 19b9a73ecc ffi: add async_runtime annotation for impl block with async fun 2024-10-08 11:12:01 +02:00
Ivan Enderlin 4d45b02e91 fix(ui): Consider timeline_limit in sliding sync as non-sticky.
This patch changes the behaviour of `timeline_limit` in sliding sync
requests. It previously was sticky, but since it's now mandatory
with MSC4186, it's preferable it to be non-sticky, otherwise in
some scenarios it might default to 0 (its default value). How?
If the server doesn't reply with our `txn_id` (because it doesn't
support sticky parameters or because it misses a `txn_id`), the
next request will be built with a default `timeline_limit` value,
which is zero, and won't get updated to the `timeline_limit` value
from `SlidingSyncListStickyParameters`. This is not good. Instead,
we must consider `timeline_limit` as non-sticky, and moves it from
`SlidingSyncListStickyParameters` to `SlidingSyncListInner`. This is
what this patch does.
2024-10-07 16:38:07 +02:00
Ivan Enderlin a9cfba2c03 chore(cargo): Update ruma. 2024-10-07 16:38:07 +02:00
Benjamin Bouvier ff7e8c75ee ci: try using macos-14 runners for swift-related tasks 2024-10-07 16:14:18 +02:00
Stefan Ceriu 2967b73aff ci: speed up iOS bindings tests by building them on the dev profile
- speed regression introduced when switching the default bindings profile to `reldbg` in #4020
2024-10-07 16:07:38 +02:00
Ivan Enderlin 6f0fbf92e4 Revert "Revert "chore(ui,ffi): Remove the RoomList::entries method.""
This reverts commit af390328b5.
2024-10-07 15:58:38 +02:00
Benjamin Bouvier 4cbc162964 timeline: update replies when a message has been edited 2024-10-07 15:11:09 +02:00
Andy Balaam 6c7acf6faa ffi: Expose the master_key method on UserIdentity 2024-10-07 13:31:38 +01:00
Andy Balaam 181ee643b1 crypto: Expose a way to pin a user's identity 2024-10-07 13:31:38 +01:00
Doug a12a46b777 ffi: Add caption/formatted_caption to media timeline items.
Also includes the computed filename too.
2024-10-07 14:11:19 +02:00
Doug 93fce02606 chore: Update Ruma to add media caption methods.
fixup

fixup
2024-10-07 14:11:19 +02:00
Benjamin Bouvier 351fbf60c1 tests: serialize Unsigned with serde 2024-10-07 07:47:05 +02:00
Benjamin Bouvier 5c353923cd timeline: add test for poll edit in relations overriding pending poll edit 2024-10-07 07:47:05 +02:00
Benjamin Bouvier dc4cc02926 timeline: add helpers for Flow to avoid redundant code 2024-10-07 07:47:05 +02:00
Benjamin Bouvier 6b543d105f timeline: avoid passing the raw event in two places 2024-10-07 07:47:05 +02:00
Benjamin Bouvier 5a1728a468 timeline: rename find_and_remove_pending to maybe_unstash_pending_edit 2024-10-07 07:47:05 +02:00
Benjamin Bouvier 5c8d1d816e timeline: move adding a new msg to its own function 2024-10-07 07:47:05 +02:00
Benjamin Bouvier bd7f0d695b timeline: add TimelineItemContent::as_poll
That's more aligned with `as_message()`, and allows getting rid of one
custom test helper.
2024-10-07 07:47:05 +02:00
Benjamin Bouvier ccf8bf8652 timeline(test): add test for latest poll with a bundled edit 2024-10-07 07:47:05 +02:00
Benjamin Bouvier f21de25da0 timeline: apply bundled edits for polls too 2024-10-07 07:47:05 +02:00
Benjamin Bouvier d789983eff timeline: rename extract_edit_content to extract_room_msg_edit_content 2024-10-07 07:47:05 +02:00
Benjamin Bouvier f8e65f53cd timeline: provide the edit JSON for edits either pending or bundled 2024-10-07 07:47:05 +02:00
Benjamin Bouvier 05cbb9e290 timeline(refactor): get rid of the stored event id in the pending_edits array
Since it's implied from the `Replacement` data structure.

Also reuse `find_and_remove_pending` in more places.
2024-10-07 07:47:05 +02:00
Benjamin Bouvier d403bf3431 timeline(code motion): move the poll code to other files
The content of a poll timeline item goes to the content directory. The
data structure handling pending poll events goes into state.

No functional changes, only code motion.
2024-10-07 07:47:05 +02:00
Benjamin Bouvier 56ccda4ded timeline: apply Message edits in a single place 2024-10-07 07:47:05 +02:00
Benjamin Bouvier 157499955a tests: allow passing an u64 to EventBuilder::server_ts 2024-10-07 07:47:05 +02:00
Benjamin Bouvier 8a71ac622d tests: allow bundled relations in EventBuidler 2024-10-07 07:47:05 +02:00
Benjamin Bouvier 45968b2a2b timeline: prefer a bundled edit to a pending edit when adding a new message 2024-10-07 07:47:05 +02:00
Benjamin Bouvier efbf9472f2 latest event: consider bundled edits when constructing an event item from a latest event 2024-10-07 07:47:05 +02:00
Benjamin Bouvier 1434285a1b timeline: extract edits from bundled relations and pass an optional edited content to Message::from_event
No changes in functionality.
2024-10-07 07:47:05 +02:00
Benjamin Bouvier 46856f54af timeline: get rid of one indent level thanks to a let else 2024-10-07 07:47:05 +02:00
Kévin Commaille 3ce2f16d55 base: Do not warn when room in m.direct account data is missing
It can occur that the data contains rooms that were forgotten.
Knowing that we now update that data after every sync, that creates
a lot of noise in the logs.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-10-07 06:51:19 +02:00
Kévin Commaille abf3c6e7b7 ui: Do not warn when no reaction to redact was found
The `handle_reaction_redaction` method is called by `handle_redaction`
for every single redaction event that we receive as a first step to
check if the redaction matches a reaction.
It means that not finding a reaction to redact is perfectly fine and is not worthy of a warning.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-10-04 18:00:30 +03:00
Damir Jelić a3a0125421 chore: Set up cargo-deny 2024-10-04 16:53:17 +02:00
Damir Jelić 657c72904a chore: Define our license in every crate we have 2024-10-04 16:53:17 +02:00
Damir Jelić de752eb089 chore: Use a released version of the qrcode crate for the qr-login example 2024-10-04 16:53:17 +02:00
Damir Jelić a4415c9fa5 chore: Use a released version of vodozemac 2024-10-04 16:53:17 +02:00
Andy Balaam 5d46b35d95 crypto: Rename some straggling 'Identities' to 'Identity'
The main enum was renamed to `UserIdentity` and some aliases and
comments had not kept up.
2024-10-04 14:37:12 +01:00
Kévin Commaille 65b422312c chore: Enable the proper feature of tower
We only use `service_fn` which is behind the `util` feature.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-10-04 12:51:38 +02:00
Kévin Commaille 7bac0340d6 base: Apply RoomInfo migrations for notable_tags and pinned_events
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-10-04 11:58:10 +02:00
Richard van der Hoff 1d1863d323 crypto: Give decrypt_room_event a new return type
I want to do a bit of a refactoring on `TimelineEvent`, so let's start by
giving `decrypt_room_event` its own return type.
2024-10-03 16:23:45 +01:00
Andy Balaam a695e291fa crypto: Rename PreviouslyVerified to VerificationViolation
For consistency with other places, we have now settled on
`VerificationViolation` as the best way to express this situation.
2024-10-03 15:41:55 +01:00
Andy Balaam c5f5bc8496 crypto: FFI bindings for subscribe_to_identity_status_changes 2024-10-03 13:24:24 +01:00
Andy Balaam cd072e6dff crypto: Provide a way to subscribe to identity status changes 2024-10-03 13:24:24 +01:00
Andy Balaam 9b36a04bb9 crypto: Provide the core logic about how identities change in a room when changes occur 2024-10-03 13:24:24 +01:00
Andy Balaam 6b357de947 crypto: Allow accessing the underlying identity on a UserIdentity 2024-10-03 13:24:24 +01:00
Andy Balaam e85e50b185 crypto: Provide DerefMut on OwnUserIdentity and UserIdentity 2024-10-03 13:24:24 +01:00
Erik Johnston c9fd5a0787 Do not log full keys query response which can be very large (#4065)
Signed-off-by: Erik Johnston <erikj@jki.re>
Co-authored-by: Damir Jelić <poljar@termina.org.uk>
2024-10-03 10:42:43 +00:00
Valere 6de676f491 Merge pull request #4046 from matrix-org/valere/trust_decoration_decryption_trust_req
crypto: Expose with_decryption_trust_requirement for ClientBuilder
2024-10-02 12:13:15 +02:00
Benjamin Bouvier 06f60e3b62 base: rename account_data to account_data_processor and other review comments 2024-10-02 11:58:09 +02:00
Benjamin Bouvier 96765cad28 base: add helper to process data on a room info from state changes or store 2024-10-02 11:58:09 +02:00
Benjamin Bouvier 4f265ccd22 base: move processing of the direct room inside the AccountDataProcessor 2024-10-02 11:58:09 +02:00
Benjamin Bouvier 759a9b0e18 base: make the dependency to push rules explicit when processing a room's subpart of a response 2024-10-02 11:58:09 +02:00
Benjamin Bouvier 0a854cdbf7 base: get rid of StateChanges::add_account_data 2024-10-02 11:58:09 +02:00
Benjamin Bouvier 40e6e9f028 base: avoid double-contains check in apply_changes
Calling `contains_key` and then doing `if let Some() = .get` have the
same effect.
2024-10-02 11:58:09 +02:00
Benjamin Bouvier 8f4fcf6299 base: experiment with handling global account data as a separate processor 2024-10-02 11:58:09 +02:00
Benjamin Bouvier 2283c28503 base: tidy up sliding sync code around e2ee 2024-10-02 11:58:09 +02:00
dependabot[bot] 59d3608c32 chore(deps): bump actions/checkout from 2.0.0 to 4.2.0
Bumps [actions/checkout](https://github.com/actions/checkout) from 2.0.0 to 4.2.0.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v2...v4.2.0)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-10-01 14:37:36 +02:00
Benjamin Bouvier 06e9f01a4a chore: fix new typos 2024-10-01 14:07:14 +02:00
dependabot[bot] 0ff63d3008 chore(deps): bump crate-ci/typos from 1.20.10 to 1.25.0
Bumps [crate-ci/typos](https://github.com/crate-ci/typos) from 1.20.10 to 1.25.0.
- [Release notes](https://github.com/crate-ci/typos/releases)
- [Changelog](https://github.com/crate-ci/typos/blob/master/CHANGELOG.md)
- [Commits](https://github.com/crate-ci/typos/compare/v1.20.10...v1.25.0)

---
updated-dependencies:
- dependency-name: crate-ci/typos
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-10-01 14:07:14 +02:00
Damir Jelić 5cc7730dd9 chore: Configure dependabot to notify us about outdated github actions 2024-10-01 13:23:08 +02:00
Damir Jelić e5bd7602e4 refactor: Use a match arm when evaluating session comparison results 2024-10-01 13:00:51 +02:00
Damir Jelić 2fc4aacdd0 feat: Prefer room keys with better SenderData when comparing duplicate room keys 2024-10-01 13:00:51 +02:00
Pratik Deshpande f7d99cc506 Added a binding for custom login using JWT 2024-10-01 12:33:06 +03:00
Valere 60319914e1 code review | quick doc and test cleaning 2024-10-01 10:19:25 +02:00
Valere 740356a350 test: ClientBuilder test for decryption trust requirement 2024-10-01 10:19:25 +02:00
Valere 806ee13aa0 ffi: Expose room_decryption_trust_requirement for ClientBuilder 2024-10-01 10:19:25 +02:00
Valere 3fd2f5794e crypto: Expose with_decryption_trust_requirement for ClientBuilder 2024-10-01 10:15:17 +02:00
Damir Jelić dc055c632c chore: Update the changelog to mention the UserIdentity renames 2024-09-30 18:04:04 +02:00
Damir Jelić c2ab795122 doc: Fix some doc links for the user identities 2024-09-30 18:04:04 +02:00
Damir Jelić e7bc510313 refactor: Rename the UserIdentities enum into UserIdentity 2024-09-30 18:04:04 +02:00
Damir Jelić 7efee5a5af refactor: Rename UserIdentity to OtherUserIdentity in the crypto crate 2024-09-30 18:04:04 +02:00
reivilibre 866b6e5f2d client builder: return a ClientBuildError when failing to build, instead of filtering out unexpected errors (#4016)
This old method was checking invariants that were
spooky-action-at-a-distance: these invariants have changed since then,
so this would panic instead of returning a proper error to the caller.

Signed-off-by: oliverw@element.io

---------

Co-authored-by: Benjamin Bouvier <benjamin@bouvier.cc>
2024-09-30 13:43:25 +02:00
Kévin Commaille 1e0e815fab base: Remove deprecated StateStore APIs
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-09-30 12:18:10 +02:00
Kévin Commaille 99fe49bbac sdk: Remove deprecated Room APIs
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-09-30 12:18:10 +02:00
Kévin Commaille 68bc14e567 base: Expose room avatar info from RoomInfo
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-09-30 12:55:39 +03:00
Benjamin Bouvier fe648d9cb5 event cache(refactoring): don't have related event rely on ordering
This was because we used a `BTreeSet`, which doesn't make sense anymore
since the data part of the key got mangled with some value unrelated to
the key itself.
2024-09-30 11:50:43 +02:00
Jorge Martín 743799fbd2 ffi: move the dependency override from ffi/Cargo.toml to the root one
This seems to be the only way to make the log rotation fix work and avoid build warnings like:

```
warning: patch for the non root package will be ignored, specify patch at the workspace root:
package:   matrix-rust-sdk/bindings/matrix-sdk-ffi/Cargo.toml
workspace: = matrix-rust-sdk/Cargo.toml
    Finished `dev` profile [unoptimized] target(s) in 0.30s
```
2024-09-30 10:22:41 +02:00
Jorge Martín ac61fc8830 ffi: create EventShieldsProvider to load shields on demand in the clients 2024-09-27 17:22:55 +02:00
Jorge Martín 52898fa526 ffi: create EventOrTransactionId enum for functions that can receive both 2024-09-27 17:22:55 +02:00
Jorge Martín 263386ea53 ffi: use event_or_transaction_id parameter name for Timeline functions that can take both 2024-09-27 17:22:55 +02:00
Jorge Martín 0082fbc0b4 ffi: add EventTimelineItemDebugInfoProvider to lazily retrieve an event's debug info 2024-09-27 17:22:55 +02:00
Jorge Martín 281a79ffc6 ffi: make From implementations for some event types use values, not references 2024-09-27 17:22:55 +02:00
Jorge Martín bdf303aa57 ffi: remove unused unwrap_or_clone_arc_into_variant macro 2024-09-27 17:22:55 +02:00
Jorge Martín 7dcf45562c ffi: fix bindings not using Arc wrappers 2024-09-27 17:22:55 +02:00
Jorge Martín 548c66750f sdk-ui: Move the event-fetching logic for edit and redact functions to the sdk-ui crate where they can be tested, to the edit_by_id and redact_by_id functions.
Added some tests for those, based on the existing ones.
2024-09-27 17:22:55 +02:00
Jorge Martín 67df36f733 ffi: Turn EventTimelineItem into a record type
This improves parsing times in mobile Clients. On Android, this means a 5-10x faster parsing of timeline events.

To do that I had to:

- Make functions like `edit/redact/forward` take an identifier (EventId/TransactionId) instead of the actual event. This id will be used to look for the actual SDK timeline event in the timeline. This change will make these functions a bit less performant.
- Make `InReplyToDetails` an object instead since a record can't recursively contain itself.
- Turn `EventTimelineItem` into a record type. Do the same with `Message`, which is now `MessageContent`.
2024-09-27 17:22:55 +02:00
Damir Jelić e61fb45504 ffi: Allow recovery to be enabled using a passphrase 2024-09-27 17:04:00 +02:00
Jorge Martín 9b7f89c183 ffi: use fork of tracing crate with a fix for Android logs rotation 2024-09-27 10:37:21 +02:00
Damir Jelić 322c5b3f83 refactor: Fold the private UserIdentities struct into UserIdentity
It doesn't serve any purpose and only confuses people since we have many
similarly named types.
2024-09-26 12:20:36 +02:00
Valere 14ec35e67f Merge pull request #3985 from matrix-org/valere/invisible_crypto/identity_based_withheld_code
crypto: change withheld code for IdentityBased share strategy
2024-09-25 17:24:43 +02:00
Valere 2bb0c50266 crypto: change withheld code for IdentityBased share strategy 2024-09-25 16:57:52 +02:00
Ivan Enderlin d254217217 test(integration): Enable test_room_preview and test_room_avatar_group_conversation.
These tests were failing since the migration from the sliding sync proxy
to Synapse.

Since the previous fixes to re-enable other tests, these 2 passes for
free.
2024-09-25 16:40:49 +02:00
Ivan Enderlin 83ce4c7ca2 test(integration): Fix test_room_notification_count.
This test was failing since the migration from the sliding sync proxy
to Synapse.

This patch fixes the test. The failing parts were:

1. The `timeline_limit` wasn't set, so Synapse was returning an error,
2. The `unread_notifications` was set to 0 and could not be set to 1
   because that's an encrypted room.

The fact `timeline_limit` is now mandatory has been mentioned in the MSC:
https://github.com/matrix-org/matrix-spec-proposals/pull/4186/files#r1775138458
A patch in Ruma has been created. The previous patch in this repository
also contains the fix for the SDK side.

The assertions around `unread_notifications` have been removed. We no
longer use this API anymore (and it should be deprecated by the way).
2024-09-25 16:13:08 +02:00
Ivan Enderlin 2562aa3fee chore(test): Clean a test by rewriting the code a little bit. 2024-09-25 16:13:08 +02:00
Ivan Enderlin fcb1c96869 feat(sdk): Sliding Sync has a required timeline_limit now.
Since MSC4186, the `timeline_limit` value is required.

This patch uses 1 as the default value for `timeline_limit`, and forces
the `timeline_limit` to be defined everywhere.
2024-09-25 16:13:08 +02:00
Ivan Enderlin 88ceeb3513 testing again 2024-09-25 16:12:57 +02:00
Ivan Enderlin a5dc8ff871 test(integration): Remove what seems to be a bug but it's not.
When Bob receives the invite, the room has the correct name. Bob to sync
more to receive the new name. This is not a bug.

This patch updates the `CreateRoomRequest` to set the correct name
immediately.
2024-09-25 16:12:57 +02:00
Ivan Enderlin c3caf6cbca test(integration): Enable test_notification.
This test was failing since the migration from the sliding sync proxy
to Synapse.

This patch fixes the test. The failing part was:

```rust
assert_eq!(notification.joined_members_count, 1);
```

This patch changes the value from 1 to 0. Indeed, Synapse doesn't share
this data for the sake of privacy because the room is not joined.

A comment has been made on MSC4186 to precise this behaviour:
https://github.com/matrix-org/matrix-spec-proposals/pull/4186#discussion_r1774775560.

Moreover, this test was asserting a bug (which is alright), but now
a bug report has been made. The patch contains the link to this bug
report.

The code has been a bit rewritten to make it simpler, and more comments
have been added.
2024-09-25 16:12:57 +02:00
Ivan Enderlin 8469c6465e test(integration): Update Synapse to 1.115. 2024-09-25 14:55:16 +02:00
Jorge Martín 03f7806000 sdk-ui & sdk: add a relationship type filter to load_event_with_relations
We need this for pinned events, where we want reactions, edits and redactions, but we don't want replies or threaded replies.
2024-09-25 12:09:14 +02:00
Kévin Commaille 5ba90611b4 ui: Allow to subscribe to read receipt changes in timeline metadata
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-09-24 15:48:07 +02:00
Benjamin Bouvier bda2acf5f6 use precise Dockerfile version 2024-09-24 15:09:05 +02:00
Ivan Enderlin 40f1ce80ea test: Bye bye SS proxy, hello Synapse \o/.
This patch removes the sliding sync proxy, and makes the
`matrix-sdk-integration-testing` tests to run against Synapse with
MSC4186 enabled.
2024-09-24 15:09:05 +02:00
Andy Balaam 3492bd6929 doc: Fix a typo in an error message 2024-09-24 13:13:39 +01:00
Jorge Martín 5e9f629edb sdk-ui: make room encryption optional to create a timeline
Instead of forcing the room encryption to be known when the timeline is created and failing if it's not known, take the latest room encryption info as a base value and update it when processing timeline events.

At the time of writing this commit, the encryption info is only used to decide whether shields should be calculated for timeline items or not.
2024-09-24 08:22:51 +02:00
Richard van der Hoff 794dbb36dc crypto: minor fixes to documentation on UserIdentity 2024-09-23 11:25:26 +01:00
Johannes Marbach 2a03de3bd5 Reformat again... 2024-09-19 08:03:36 +02:00
Johannes Marbach 79d8738ff5 Reformat 2024-09-19 08:03:36 +02:00
Johannes Marbach e16ca9d8ba ffi: default to reldbg when building iOS bindings
Relates to: #4009
Signed-off-by: Johannes Marbach <n0-0ne+github@mailbox.org>
2024-09-19 08:03:36 +02:00
Benjamin Bouvier 746d7e13ab tests: change strategy for test_ensure_max_concurrency_is_observed 2024-09-18 17:34:24 +02:00
Benjamin Bouvier 1b4f665d99 integration tests: update instructions (#4017)
- explain what these tests are
- mention that it's sometimes needed to rebuild the synapse image

---------

Signed-off-by: Benjamin Bouvier <benjamin@bouvier.cc>
Co-authored-by: Ivan Enderlin <ivan@mnt.io>
2024-09-18 14:45:33 +00:00
Jorge Martín 7d1bbfaa32 sdk-base: split handle_account_data and process_direct_rooms
This removes a couple of TODOs in the codebase.
2024-09-18 08:16:56 +02:00
Timo 8119697ef0 MatrixRTC: Fix different devices from the same user overwriting the room info state event. 2024-09-17 17:02:06 +02:00
Jorge Martín decdd6f47e crypto-ffi: update the x86-64 Android workaround to match matrix-sdk-ffi
This workaround was applied to `matrix-sdk-ffi` and it should be used here too
2024-09-17 16:44:52 +02:00
Ivan Enderlin 72febaee57 feat(base): Increase the room_info_notable_update_sender capacity.
This broadcast channel can easily be overflowed if more than 100 updates
arrive at the time. This patch extends the capacity to 2^16 - 1.
2024-09-17 16:37:23 +02:00
Ivan Enderlin 7a2728f8b5 feat(ui): Add logs when RoomList entries receive a lag.
This patch updates `merge_stream_and_receiver` to display an `error!`
when the room info receiver reads an error, like `Closed` or `Lagged`.
This is helpful when debugging.
2024-09-17 16:37:23 +02:00
Damir Jelić f576c72ef8 crypto: Avoid deep copying the OlmMachine when creating a NotificationClient
The NotificationClient, responsible for handling, fetching, and
potentially decrypting events received via push notifications, creates a
copy of the main Client object.

During this process, the Client object is adjusted to use an in-memory
state store to prevent concurrency issues from multiple sync loops
attempting to write to the same database.

This copying unintentionally recreated the OlmMachine with fresh data
loaded from the database. If both Client instances were used for syncing
without proper cross-process locking, forks of the vodozemac Account and
Olm Sessions could be created and later persisted to the database.

This behavior can lead to the duplication of one-time keys, cause
sessions to lose their ability to decrypt messages, and result in the
generation of undecryptable messages on the recipient’s side.
2024-09-16 18:27:31 +02:00
Damir Jelić 1429c1a06a test: Confirm that the notification client doesn't create duplicate one-time keys 2024-09-16 18:27:31 +02:00
Damir Jelić b7ce2dc7e6 chore: Fix a clippy warning 2024-09-16 17:58:29 +02:00
Benjamin Bouvier ea9da3bdad tests: increase timeout duration when awaiting a timeline update 2024-09-16 17:35:42 +02:00
Stefan Ceriu a1bb7c0acc sdk: add account deactivation tests 2024-09-16 17:52:39 +03:00
Stefan Ceriu ea4b9635c9 ffi: add another method that tells the client if account deactivation is supported
- i.e. only works for `m.login.password`
2024-09-16 17:52:39 +03:00
Stefan Ceriu 5b79a9843e ffi: expose method to allow user account deactivate for m.login.password based accounts 2024-09-16 17:52:39 +03:00
Benjamin Bouvier abbe2ec523 tests: increase timeout duration for await_room_remote_echo
Fixes #4003, or so I suspect. The integration tests run in code coverage
can be quite slow, so we can't put timeouts this low.
2024-09-16 14:29:57 +02:00
Benjamin Bouvier 965390cbdc notification client: use the membership state to match an invite 2024-09-16 14:02:07 +02:00
Ivan Enderlin 119bee66ce feat(sdk,ui): SlidingSync::subscribe_to_rooms has a new cancel_in_flight_request argument.
This patch adds a new `cancel_in_flight_request` argument to
`SlidingSync::subscribe_to_rooms`, which tells the method cancel the
in-flight request if any.

This patch also updates `RoomListService::subscribe_to_rooms` to turn
this new argument to `true` if the state machine isn't in a “starting”
state.

The problem it's solving is the following:

* some apps starts the room list service
* a first request is sent with `pos = None`
* the server calculates a new session (which can be expensive)
* the app subscribes to a set of rooms
* a second request is immediately sent with `pos = None` again
* the server does possibly NOT cancel its previous calculations, but
  starts a new session and its calculations

This is pretty expensive for the server. This patch makes so that the
immediate room subscriptions will be part of the second request, with
the first request not being cancelled.
2024-09-16 12:18:07 +02:00
Ivan Enderlin 4fd4410f4a chore: Update to ruma/ruma. 2024-09-16 12:08:15 +02:00
Ivan Enderlin af390328b5 Revert "chore(ui,ffi): Remove the RoomList::entries method."
This reverts commit 98a3a0b3c4.
2024-09-16 12:02:03 +02:00
Ivan Enderlin 98a3a0b3c4 chore(ui,ffi): Remove the RoomList::entries method.
This method is now private inside `matrix_sdk_ui` and removed
from `matrix_sdk_ffi`. This method is returning a stream of rooms,
but updates on rooms won't update the stream (only new rooms
will be seen on the stream). Nobody uses it as far as I know, and
`entries_with_dynamic_adapters` is the real only API we want people
to use.
2024-09-16 11:50:11 +02:00
Jorge Martín aa92e26342 sdk-base: fix handle_account_data behaviour
Handle the account data in the response if not empty, otherwise use the cached one.
2024-09-16 11:20:47 +02:00
Jorge Martín dd13fe6b4e sdk-base: use updated account data for processing direct rooms 2024-09-16 11:20:47 +02:00
Doug a9ed62284e ffi: Expose the server URL to the app too. 2024-09-13 19:32:08 +03:00
Doug 2532c5227f ffi: Add the registration helper URL to the ElementWellKnown file. 2024-09-13 18:37:45 +03:00
Richard van der Hoff 72cc2bd60c crypto: Include megolm ratchet index in logging span fields
This field is helpful as it tells us the sequence number of the message in the
megolm session, which gives us a clue about how long it will have been since
the session should have been shared with us.
2024-09-13 12:18:52 +01:00
Benjamin Bouvier 2408df8bf5 multiverse: highlight which rooms are DMs in the list 2024-09-12 14:58:59 +02:00
Jorge Martín 5827bb7ab3 sdk-ui: fix typo in TimelineState::replace_with_remove_events 2024-09-12 13:21:39 +02:00
Jorge Martín 25111ac9eb sdk-ui: make SlidingSyncRoom not needed in RoomListItem::default_room_timeline_builder.
Having initial items shouldn't be mandatory to create a timeline, the timeline can also be empty.
2024-09-12 13:21:39 +02:00
Jorge Martín 6ae7d3c017 ffi: add FFI fn for Client::await_room_remote_echo(&room_id) 2024-09-12 13:21:39 +02:00
Jorge Martín bbe16db94c sdk: add Client::await_room_remote_echo(&room_id)
This fn will loop until it finds an at least partially synced room with the given id. It uses the `ClientInner::sync_beat` listener to wait until the next check is needed.
2024-09-12 13:21:39 +02:00
Jorge Martín f8961a4382 sdk-base: add Room::is_state_partially_or_fully_synced()
This new fn is used to check when a room is at least partially synced, which seems to be the case with SSS.
2024-09-12 13:21:39 +02:00
Damir Jelić 9e7ab635c6 bindings: Expose the PkEncryption stuff in the crypto crate bindings (#3971) 2024-09-12 09:54:46 +00:00
Damir Jelić a024c010ce chore: Remove the olm-rs dep now that PkEncryption stuff has moved to vodozemac 2024-09-12 10:35:28 +02:00
Damir Jelić 3555474cad crypto: Bump the vodozemac version and remove the PkEncryption compat module
The PkEncryption support now lives inside of vodozemac so no need to
keep our own copy around.
2024-09-11 17:03:50 +02:00
Ivan Enderlin 2b3ad86869 feat(ui): all_rooms in RoomListService requires m.room.canonical_name.
This patch adds `m.room.canonical_name` in the `required_state` of the
`all_rooms` list defined by `RoomListService`.

This is useful to better compute the room name in a more robust way.
2024-09-11 16:06:03 +02:00
Ivan Enderlin 075f3fa9d2 feat(ffi): Add RoomInfo::creator.
This patch adds the `matrix_sdk_ffi::RoomInfo::creator` field that
simply copies the value from `matrix_sdk_base::Room::creator()`.
2024-09-11 15:19:41 +02:00
Ivan Enderlin 47c7d05499 feat(base): Add Room::creator().
This patch adds `Room::creator()` to expose the value from
`RoomInfo::creator()`.
2024-09-11 15:19:41 +02:00
Jorge Martín 4b970e879f sdk: ensure sync_beat is only notified with a successful sync response 2024-09-11 12:46:32 +02:00
Jorge Martín cc0dfd62e7 sdk: notify when a sync response is received by SlidingSync
Previously this was only done in `Client::sync_once`, which made `ClientInner::sync_beat` not that useful.
2024-09-11 12:46:32 +02:00
Jorge Martin Espinosa 31e6df7234 timeline: unify edit and edit_poll functions (#3951)
## Changes

Takes care of [this
TODO](https://github.com/matrix-org/matrix-rust-sdk/blob/9df1c480795c42afcee39e4c7e553d5a927a2680/crates/matrix-sdk-ui/src/timeline/mod.rs#L520).

- sdk & sdk-ui: unify `Timeline::edit` and `Timeline::edit_polls`, the
new fn takes an `EditedContent` parameter now, which includes a
`PollStart` case too.
- ffi: also unify the FFI fns there, using `PollStart` and a new
`EditContent` enum that must be passed from the clients like:

```kotlin
val messageContent = MessageEventContent.from(...)
timeline.edit(event, EditedContent.RoomMessage(messageContent))
```

Since the is mainly about changing the fns signatures I've reused the
existing tests, including one that used `edit_poll` that now uses the
new fn.

---------

Co-authored-by: Benjamin Bouvier <benjamin@bouvier.cc>
2024-09-11 08:50:51 +00:00
Ivan Enderlin 2576042194 chore(sdk): Add an info log in sliding sync. 2024-09-11 10:40:59 +02:00
Ivan Enderlin a3ae9dca75 doc(crypto): Improve documentation. 2024-09-11 10:40:59 +02:00
Ivan Enderlin 6e36111462 fix(sdk): Mark tracked users as dirty when the SS connection is reset.
There is a non-negligible difference MSC3575 and MSC4186 in how the
`e2ee` extension works. When the client sends a request with no `pos`:

* MSC3575 returns all device lists updates since the last request
  from the device that asked for device lists (this works similarly to
  to-device message handling),

* MSC4186 returns no device lists updates, as it only returns changes
  since the provided `pos` (which is `null` in this case); this is in
  line with sync v2.

Therefore, with MSC4186, the device list cache must be marked as to be
re-downloaded if the `since` token is `None`, otherwise it's easy to
miss device lists updates that happened between the previous request and
the new “initial” request.
2024-09-11 10:40:59 +02:00
Ivan Enderlin b7bde3cabe feat(crypto): Implement OldMachine::mark_all_tracked_users_as_dirty.
This patch adds the `OldMachine::mark_all_tracked_users_as_dirty`.

This patch rewrites a bit `OlmMachine::new_helper` by extracting some
piece of it inside `OlmMachine::new_helper_prelude`. With that, we
can rewrite `OlmMachine::migration_post_verified_latch_support` to use
`IdentityManager::mark_all_tracked_users_as_dirty`.
This latter is the shared implementation with
`OlmMachine::mark_all_tracked_users_as_dirty`.

This patch adds a test for `OlmMachine:mark_all_tracked_users_as_dirty`.
2024-09-11 10:40:59 +02:00
Benjamin Bouvier cb825864b9 event cache: reset paginator state when receiving a limited timeline 2024-09-11 09:40:30 +02:00
Jorge Martín 08df153ed9 sdk-ui: create TimelineState::replace_all which combines clear and add_remote_events_at in the same transaction 2024-09-10 17:23:15 +02:00
Ivan Enderlin a6f84d8513 feat(sdk): Use the user ID to discover the sliding sync proxy.
This patch improves `Client::available_sliding_sync_versions` when
trying to detect the sliding sync proxy. Previously, we were relying
on the `Client::server` to send the `discover_homeserver::Request`.
Sadly, this value is an `Option<_>`, meaning it's not always defined
(it depends how the `Client` has been built with `HomeserverConfig`:
sometimes the homeserver URL is passed directly, so the server cannot
be known).

This patch tries to find to discover the homeserver by using
`Client::server` if it exists, like before, but it also tries by using
`Client::user_id`. Another problem arises then: the user ID indeed
contains a server name, but we don't know whether it's behind HTTPS or
HTTP. Thus, this patch tries both: it starts by testing with `https://`
and then fallbacks to `http://`.

A test has been added accordingly.
2024-09-10 14:09:50 +02:00
Benjamin Bouvier 729ba3e22b ffi: rename RustShieldState to SdkShieldState
This is all Rust code, after all :)
2024-09-10 11:20:52 +02:00
Doug 83cc0acf7b ffi: Expose RoomSendQueue::unwedge to allow resending. 2024-09-09 17:47:06 +02:00
Benjamin Bouvier ef6237045e timeline: use a RingBuffer instead of a hashmap to put an upper bound on the number of pending edits 2024-09-09 17:13:11 +02:00
Benjamin Bouvier d005311235 timeline: add comments for each item in TimelineMetadata 2024-09-09 17:13:11 +02:00
Benjamin Bouvier c66ea8162c timeline: use fewer early returns in code around pending edits
😥
2024-09-09 17:13:11 +02:00
Benjamin Bouvier 40c1e8a2da timeline: add more tests for pending edits 2024-09-09 17:13:11 +02:00
Benjamin Bouvier d2709c0679 timeline: handle pending poll edits too 2024-09-09 17:13:11 +02:00
Benjamin Bouvier c9a46173b9 timeline: some renamings around poll edits 2024-09-09 17:13:11 +02:00
Benjamin Bouvier 8a2929fb51 timeline: apply pending edits when adding the new item, not as a separate update 2024-09-09 17:13:11 +02:00
Benjamin Bouvier 79f412790f timeline: stash edits around in case they arrive before the related event 2024-09-09 17:13:11 +02:00
Benjamin Bouvier 5abff2970c room: mark encryption state as missing if a room thinks it's not encrypted after requesting it 2024-09-09 17:04:01 +02:00
Damir Jelić dcc20b6c96 backups: Rename the term session to room key
The term session is usually only used in the crypto crate to reference a
Megolm session, the rest of the SDK uses the name from the event and the
Matrix spec, this should lower the amount of confusion since the main
crate has already a session concept and its unrelated to end-to-end
encryption.
2024-09-09 16:51:15 +02:00
Damir Jelić 4e541ad825 backups: Expire downloaded room keys so they get retried if a better one is found 2024-09-09 16:51:15 +02:00
Damir Jelić 67a4a322f5 backups: Don't queue up room keys to be downloaded if backups aren't enabled 2024-09-09 16:51:15 +02:00
Damir Jelić 26e6a038a1 backups: Don't mark a room key as downloaded if we did not attempt to download it 2024-09-09 16:51:15 +02:00
Damir Jelić e8a920118f timeline: Retry decryption if a room key backup gets enabled 2024-09-09 16:51:15 +02:00
Damir Jelić 626b3d152c test: Check that we don't mark keys as downloaded before backups were enabled 2024-09-09 16:51:15 +02:00
Damir Jelić 38ed66c1b1 test: Test that a timeline decrypts an event if a backup got enabled 2024-09-09 16:51:15 +02:00
Benjamin Bouvier 19e89bbd6a tests: make test_incremental_upload_of_keys_sliding_sync less dependent on timing 2024-09-09 14:21:51 +02:00
Benjamin Bouvier a07be884b7 tests: try to address intermittent failure of test_incremental_upload_of_keys
My theory is that the intermittent failure depends on the ordering of
the requests, and if the /keys/upload request happened before the key
backup request, then after failing the next key backup request wouldn't
run.

This is likely a small typo that the key upload returns a 404 error
instead of a 200, let's see if this improves the situation.
2024-09-09 14:21:51 +02:00
Valere 24d4e60c2b crypto: Bugfix - UTD messages showing unexpected red padlock warning 2024-09-09 14:59:20 +03:00
Benjamin Bouvier 7d7142add3 timeline: check that unique IDs are indeed unique
And log an error in production builds if that's not the case.
2024-09-09 12:10:41 +02:00
Ivan Enderlin 57352f0154 chore(sdk): Rename a variable from_… to with_….
This patch renames the variable `from_msc4186` to `with_msc4186` for
better clarity.
2024-09-09 12:01:33 +02:00
Ivan Enderlin 7eea5628d3 chore: Update Ruma feat-sss to its latest commit.
The new commits from `feat-sss` are about migrating
`unstable-simplified-msc3575` to `unstable-msc4186`.
2024-09-09 12:01:33 +02:00
Ivan Enderlin ea794bb9f2 chore(sdk): Replace “simplified sliding sync” by “MSC4186”.
Simplified sliding sync finally has an MSC number: 4186. Let's use this
name when possible to clarify the code.
2024-09-09 12:01:33 +02:00
Jorge Martín 10a0d59012 sdk-ui: fix max concurrent requests for pinned events timeline. 2024-09-09 09:37:50 +02:00
Ivan Enderlin 16fd88c419 chore(sdk): Improve a doc and format code. 2024-09-09 09:20:01 +02:00
Damir Jelić 1eecb2d603 ui: Remove the e2e-encryption feature from the matrix-sdk-ui crate
It does not make much sense to create an UI client that does not support
end-to-end encryption, besides disabling the feature was broken for
quite some time.
2024-09-06 15:37:18 +02:00
Damir Jelić 98ba714b20 sdk: Fix a clippy warning 2024-09-06 13:51:04 +02:00
Andy Balaam 07aa6d7bc7 doc: Fix missing 'o' in the doc comment for the recovery module 2024-09-05 17:12:15 +01:00
Benjamin Bouvier 9df1c48079 timeline(tests): ASCII art 2024-09-05 16:46:25 +02:00
Benjamin Bouvier 977a9995fe timeline(tests): simplify matching a day divider or a read marker using public APIs 2024-09-05 16:46:25 +02:00
Benjamin Bouvier f978960d30 timeline: don't insert a read marker when all subsequent events have been inserted by ourselves 2024-09-05 16:46:25 +02:00
Benjamin Bouvier 3f93324a85 timeline(style): gather common code under the same arm branches 2024-09-05 16:46:25 +02:00
Richard van der Hoff 3204953738 crypto: update changelog 2024-09-05 13:22:10 +01:00
Richard van der Hoff 88b005ace3 crypto: clarify logging on conclusion of verification requests
* Not verifying the remote device/user is normal: log it at debug rather than
  info.
* On the other hand, if we do verify something, let's log that at info rather
  than trace.

Also fix a comment, while we're here.
2024-09-05 13:22:10 +01:00
Richard van der Hoff c761a84acd crypto: logging during QR code verifications
* Upgrade the log when we get the "reciprocate" message (which tells us the
   other side has scanned our QR code) to debug, instead of trace.
 * Warn if we get a reciprocate we don't understand
 * Log when the user confirms that the other side has scanned successfully.
2024-09-05 13:22:10 +01:00
Richard van der Hoff a2bfc07ecc crypto: log the method on an m.verification.start message
This is the message that tells us whether the other side wants to do QR code or
SAS (emoji) verification. Knowing which they have chosen is really helpful for
following the flow!
2024-09-05 13:22:10 +01:00
Richard van der Hoff b1a533a071 crypto: log flow_id when processing verification requests
Attach the flow_id (the transaction ID or message ID from the `request`
message) to the span, so that it is displayed alongside loglines that happen
when processing the request.
2024-09-05 13:22:10 +01:00
Richard van der Hoff fed418d9a8 crypto: log when we show a QR code
Take the logging that happens when a QR code verification is added to the
`verification cache`, and push it down to the `VerificationCache` itself. Doing
so means that we will log when we *show* a QR code as well as when we scan it.

I would have found this helpful when trying to debug a verification flow this
week.
2024-09-05 13:22:10 +01:00
Richard van der Hoff 2c2d8e9ff0 crypto: log details of our public identity when we update it
For debugging, it's useful to have a record of what we believe our own public
cross-signing keys to be. Currently, we log the keys at startup if we restore
them from the database, but if we subsequently create, or download, a set of
keys, they aren't logged.
2024-09-05 13:22:10 +01:00
Andy Balaam b9b8de7ff1 crypto: Mark all new SenderData info as non-legacy
Since we now have a clear idea of the structure, and anything we create
now should be usable in future.
2024-09-05 13:54:01 +02:00
Benjamin Bouvier 552df0e4c6 timeline(tests): use the event factory in a few more places 2024-09-05 10:01:37 +02:00
Benjamin Bouvier 12f36d5972 timeline: document and rename some concepts around pending poll events 2024-09-05 10:01:37 +02:00
Richard van der Hoff f7ee643475 crypto: update changelog 2024-09-04 16:07:03 +01:00
Richard van der Hoff 73486b2b7b crypto: update senderdata integration tests
Extend the integration tests for megolm sender data to check that we update
existing inbound group sessions when we get a `/keys/query` response.
2024-09-04 16:07:03 +01:00
Richard van der Hoff 3c27f83857 crypto: update sender data on /keys/query responses
When we receive an `/keys/query` response, look for existing
inboundgroupsessions created by updated devices, and see if we can update any
of their senderdata settings.
2024-09-04 16:07:03 +01:00
Richard van der Hoff 385c2b8e71 crypto: Expose sender_data_finder module as pub(crate)
This module has a number of useful types (in particular, error types). Rather
than addding even more types to the top level module, let's export the
`sender_data_finder` module as a whole.
2024-09-04 16:07:03 +01:00
Richard van der Hoff 6bc9887314 crypto: fix memorystore groupsession batch query
If the previous session is removed from the list, we should still be able to
continue iterating through the *rest* of the list.
2024-09-04 16:07:03 +01:00
Richard van der Hoff 30d3d9d26c crypto: expose InboundGroupSession.sender_data
We need write access to this in the integration tests
2024-09-04 16:07:03 +01:00
Hubert Chathi dfb67c88e6 crypto: add changelog 2024-09-04 14:59:21 +01:00
Hubert Chathi 98a79de811 crypto: check trust requirement when decrypting 2024-09-04 14:59:21 +01:00
Hubert Chathi 62d4abd454 crypto: add DecryptionSettings parameter to functions 2024-09-04 14:59:21 +01:00
Hubert Chathi 7b71d3ca1b crypto: add error code for sender device not sufficiently trusted on decryption 2024-09-04 14:59:21 +01:00
Hubert Chathi 31b4d0a2d1 crypto: add setting for checking sender device trust on decryption 2024-09-04 14:59:21 +01:00
Stefan Ceriu 14ee78c54d ffi: expose methods for manually withdrawing certain users' verification or trusting their devices and resending failed messages 2024-09-04 15:39:35 +03:00
Stefan Ceriu f3d3924bb6 send_queue: publish retry updates when unwedging an event; have the timeline update the corresponding item in response. 2024-09-04 15:39:35 +03:00
Stefan Ceriu 6c704352a9 send_queue: add mechanism for unwedging and resending a request based on its transaction identifier 2024-09-04 15:39:35 +03:00
Damir Jelić 0db0ea0977 docs: Add PR review guidelines. 2024-09-04 13:42:16 +02:00
Benjamin Bouvier 3f7909641f client builder(nit): avoid unnecessary clone 2024-09-04 12:41:17 +02:00
Benjamin Bouvier 5b0ad01bab event cache: don't return a useless Option 2024-09-04 12:41:17 +02:00
Kévin Commaille b0e8121347 sqlite: Bump sqlite crates
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-09-04 10:55:38 +02:00
dependabot[bot] aa94ad846b build(deps): bump quinn-proto from 0.11.3 to 0.11.8
Bumps [quinn-proto](https://github.com/quinn-rs/quinn) from 0.11.3 to 0.11.8.
- [Release notes](https://github.com/quinn-rs/quinn/releases)
- [Commits](https://github.com/quinn-rs/quinn/compare/quinn-proto-0.11.3...quinn-proto-0.11.8)

---
updated-dependencies:
- dependency-name: quinn-proto
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-09-04 10:50:34 +02:00
Hubert Chathi 1dd8c908c5 crypto: Error when sending keys to previously-verified users with identity-based strategy (#3896) 2024-09-03 18:06:32 +01:00
Stefan Ceriu 5b14fe6f34 crypto: fix OIDC cross-signing reset flows after backend authorization failure response change (#3933) 2024-09-03 14:43:46 +00:00
Ivan Enderlin a737421875 chore(ui): Rename variables.
This is not a timestamp but a regular stamp. Make it clear with the
variable names.
2024-09-03 15:52:05 +02:00
Ivan Enderlin 49252b5342 test: Restore Complement Crypto. 2024-09-03 11:52:32 +02:00
Richard van der Hoff d8b0f9f3d7 crypto: add cryptostore integ test
Add a new integration test for
`CryptoStore::get_inbound_group_sessions_for_device_batch`
2024-09-02 18:07:38 +01:00
Richard van der Hoff 1de99161e2 indexeddb: implement get_inbound_group_sessions_for_device_batch 2024-09-02 18:07:38 +01:00
Richard van der Hoff 675f576343 indexeddb: add new index on inbound_group_sessions
Add an index on `(sender_key, sender_data_type, session_id)`.
2024-09-02 18:07:38 +01:00
Richard van der Hoff 7cf8e9eb9b indexeddb: add new fields to InboundGroupSessionIndexedDbObject
Add new `session_id`, `sender_key` and `sender_data_type` properties to stored
inbound group session objects.
2024-09-02 18:07:38 +01:00
Richard van der Hoff 7bcc920514 sqlite: add get_inbound_group_sessions_for_device_batch 2024-09-02 18:07:38 +01:00
Richard van der Hoff 12653fb2b6 sqlite: add new curve_key and sender_data_type columns 2024-09-02 18:07:38 +01:00
Richard van der Hoff eeaf31ce53 crypto: implement MemoryStore::get_inbound_group_sessions_for_device_batch 2024-09-02 18:07:38 +01:00
Richard van der Hoff 228a117ccb crypto: add get_inbound_group_sessions_for_device_batch to CryptoStore 2024-09-02 18:07:38 +01:00
Andy Balaam 3f408a9a36 crypto: Create a SenderDataType enum 2024-09-02 18:07:38 +01:00
Kévin Commaille 7f4e79e2a3 Add link to SQLite docs
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-09-02 17:44:30 +02:00
Kévin Commaille 7807ed8bda sqlite: Update last access time first to force write transaction
Avoids errors when the read transaction tries to upgrade to a write transaction.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-09-02 17:44:30 +02:00
Richard van der Hoff f8dd5c76d2 crypto: Add tests for sender_data after receiving megolm sessions 2024-09-02 15:36:45 +01:00
Richard van der Hoff 6068d3e870 crypto: Pull out Session::build_encrypted_event
Break up `encrypt` a bit, so that we can write tests that do something slightly
different.
2024-09-02 15:36:45 +01:00
Richard van der Hoff 76d161ac9a crypto: expose SenderDataFinder::find_using_device_data
Turns out that most of the places we call `find_using_device_keys`, we already
have a DeviceData. So we might as well pass that in directly, rather than
extracting the device keys and then rebuilding a DeviceData.
2024-09-02 15:30:29 +01:00
Richard van der Hoff ca42657abb crypto: Log the received device keys on an encrypted olm message
Attempt to summarise the received keys.
2024-09-02 15:14:46 +01:00
Ivan Enderlin 4636a9177e chore(sdk): Rename HomeserverConfig variants.
This patch renames `HomeserverConfig::Url` to `HomeserverUrl`, and
`HomeserverConfig::ServerNameOrUrl` to `ServerNameOrHomeserverUrl`.
Funnily, the methods on `ClientBuilder` doesn't need to be renamed to
match the new naming since they already use this naming!
2024-09-02 15:51:41 +02:00
Ivan Enderlin 5e662e855d fix(sdk): Don't subscribe to already subscribed rooms.
When subscribing to an already subscribed room, the subscription state
was reset, the subscription was resent by cancelling the in-flight
request. All this is useless and can create a feeling of lag.

This patch checks if a room is subscribed first. If it is, nothing
happens. If it is not, the room subscription is created, and the
in-flight request is cancelled.

Tests are updated to reflect this new change.

Note: room subscription settings are not taken into account in this
“presence” pattern. It means that if we subscribe to an already
subscribed room but with different settings, nothing will happen. The
server will ignore the new settings anywhere for the moment.
2024-09-02 14:52:42 +02:00
Benjamin Bouvier 513c80df5e timeline: add comment to TimelineFocus::PinnedEvents 2024-09-02 14:29:08 +02:00
Benjamin Bouvier 956dda1073 timeline: rename TimelineInner to TimelineController 2024-09-02 14:29:08 +02:00
Benjamin Bouvier de6016de1e timeline: remove Inner in TimelineInnerStateTransaction 2024-09-02 14:29:08 +02:00
Benjamin Bouvier 72f42a46d8 timeline: remove Inner in TimelineInnerState 2024-09-02 14:29:08 +02:00
Benjamin Bouvier 03a4cc46ad timeline: remove Inner in TimelineInnerSettings 2024-09-02 14:29:08 +02:00
Benjamin Bouvier 63ca064f93 timeline: remove Inner in TimelineInnerMetadata 2024-09-02 14:29:08 +02:00
Ivan Enderlin a19cb24567 fix(sdk): Sliding sync discovers the proxy on the server, not the homserver.
The `.well-known` file is located on the server, not the homeserver.
This patch fixes that along with the associated tests.
2024-09-02 14:18:45 +02:00
Ivan Enderlin 99c44ee883 fix(sdk): Don't confuse server and homeserver.
This patch fixes an error where the `homeserver` is used for the
`server` value.
2024-09-02 14:00:10 +02:00
Ivan Enderlin d0c5d87a96 doc(sdk): Improve documentation of HomeserverConfig. 2024-09-02 14:00:10 +02:00
Ivan Enderlin 222be6983c test(sdk): Test HomeserverConfig::discover.
This API is tested via `Client` and `ClientBuilder` but it's preferable
to unit testing it too, it makes things clearer and cleaner.
2024-09-02 14:00:10 +02:00
Ivan Enderlin f3bc24e98f chore(sdk): Extract HomeserverConfig & co. in its own module.
This patch moves `client/builder.rs` into `client/builder/mod.rs`.
This patch also moves the `HomeserverConfig` type and its siblings
(`discover_homeserver`, `UrlScheme` etc.) into its own module `client/
builder/homeserver_config.rs`.

This is purely for cleaning up.
2024-09-02 14:00:10 +02:00
Ivan Enderlin 22a19e26d3 feat(sdk): Add Client::server.
This patch adds `Client::server`: the URL of the server.

Not to be confused with the `Client::homeserver`. The `server`
holds some information, like the `.well-known` file, to discover the
homeserver. The homeserver is the client-server Matrix API.

`server` is usually the server part in a user ID, e.g. with
`@mnt_io:matrix.org`, here `matrix.org` is the server, whilst
`matrix-client.matrix.org` is the homeserver.

This patch also moves the code about homeserver discovery in the
`HomeserverConfig::discover` new method. A new struct is introduced to
hold the result, to replace a 4-tuples.

`Client::server` is also now a `Option<_>` because in the case of
`HomeserverConfig::Url`, the server cannot be known.

This patch also removes several clones here and there.

Finally, this patch updates a test to quickly test the new behaviour. A
next patch will introduce proper tests.
2024-09-02 14:00:10 +02:00
Benjamin Bouvier b9628301ec timeline: beef up comment around TimelineEventContext::should_add_new_items 2024-09-02 13:45:12 +02:00
Benjamin Bouvier b4683c0ff5 timeline: reinterpret LiveTimelineUpdatesAllowed as TimelineFocusKind
It makes the code simpler to understand, in my opinion.
2024-09-02 13:45:12 +02:00
Benjamin Bouvier cb3c5ab1ce timeline: move the decision to add a timeline item upwards
Especially for remote items, it should be in sync with `should_add` as
it's used in this method, otherwise read receipt tracking will not work
correctly.
2024-09-02 13:45:12 +02:00
Benjamin Bouvier 8c5ffc9a96 timeline: don't clear the internal counter in presence of local echoes 2024-09-02 13:21:36 +02:00
Benjamin Bouvier 9ec46ddf2c timeline(tests): use the EventFactory in more tests 2024-09-02 13:21:36 +02:00
Benjamin Bouvier bfb04f2ddd event factory: allow having unsigned data too
And use the event factory in more timeline tests.
2024-09-02 13:21:36 +02:00
Andy Balaam eecd00cd98 indexeddb: Pass the db transaction into do_schema_upgrade closures
For some operations (notably: adding an index to an existing object store), we
need access to the database transation during the upgrade operation.
2024-09-02 11:22:43 +01:00
Benjamin Bouvier b8d90286aa testing: enforce a test_ prefix for tests
This will only apply to `async_test` functions, but I think this is a
win:

1. for consistency within the codebase, since I've started doing so in
many places,
2. because these function names will clearly identify these functions as
tests, in the call tree interfaces, when rendered using the LSP
show-callers/show-callees functionality.
2024-09-02 12:02:43 +02:00
Kévin Commaille 424d01d964 Revert "doc(sdk): Update CHANGELOG.md."
This reverts commit 711a753533.
2024-09-02 11:32:04 +02:00
Kévin Commaille 84e4552da7 Revert "feat(sdk): Remove NotificationSettings::subscribe_to_changes."
This reverts commit 4e291205d5.
2024-09-02 11:32:04 +02:00
Benjamin Bouvier c4624cc863 timeline: add local echo handling for *all* timelines
Including non-live timelines (pinned event timelines and permalinked
timelines). This makes it possible to see that you're adding a reaction
etc. in real time, while it wasn't the case anymore.

Fixes #3906.
2024-09-02 11:08:25 +02:00
Benjamin Bouvier c3973589c8 timeline(test): add an integration test for non-live timelines not handling local echoes 2024-09-02 11:08:25 +02:00
Benjamin Bouvier 224292ab3e testing: remove EventBuilder::make_sync_reaction which is unused 2024-08-29 16:21:56 +02:00
Benjamin Bouvier 0311f30182 timeline: get rid of one use of sync_timeline_event 2024-08-29 16:21:56 +02:00
Benjamin Bouvier 0877445273 timeline: add assert_let_timeout for testing purposes 2024-08-29 16:21:56 +02:00
Richard van der Hoff 7f02447c78 indexeddb: remove InboundGroupSessionIndexedDbObject::new
We're going to add some more fields soon, so a `new` method is increasingly
unhelpful.

Replace it with a helper for the tests.
2024-08-29 11:11:07 +01:00
Richard van der Hoff 308d658224 indexeddb: add InboundGroupSessionIndexedDbObject::from_session
factor out the two copies of this code into a common function, and inline the
call to `new` while we're there
2024-08-29 11:11:07 +01:00
Richard van der Hoff 9808ad7d16 indexeddb: fix a typo in a comment 2024-08-29 11:11:07 +01:00
Benjamin Bouvier 06fc220268 ffi: use the send queue when sending an edit with Room::edit
This will make it possible to send updates to observers, update local
echoes, and so on, making it closer to the edit functions from the
timeline.
2024-08-29 09:34:31 +03:00
Benjamin Bouvier f399f229ae send queue: remove outdated comment
The future is now, and has been for quite a while, in fact.
2024-08-29 09:34:31 +03:00
Kévin Commaille a8b38d271e sqlite: Merge init and run_migrations for SqliteEventCacheStore
This was copied from SqliteStateStore, but the reason
that they are separated there is because some migrations
require the store cipher.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-08-29 09:31:40 +03:00
Kévin Commaille 66e901bb9b sqlite: Make migrations atomic
Setting the version number only when all migrations are done
means that the version will be wrong if a migration fails.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-08-29 09:31:40 +03:00
Benjamin Bouvier 9edca06d3b http client: don't infinitely retry network failures if there's no retry limit
Otherwise, this would mean that logged out clients would infinitely
repeat network requests failing in the background.

Without this fix, the added test will time out, endlessly reattempting
network requests.
2024-08-28 17:26:16 +02:00
Benjamin Bouvier 47444cc671 sdk-base: hack to avoid over-recursion when evaluating Send/Sync bounds in rustc
See
https://github.com/matrix-org/matrix-rust-sdk/pull/3749#issuecomment-2312939823
for the gory details.
2024-08-28 16:49:46 +02:00
Benjamin Bouvier e1fe1ca129 timeline: add support for local reactions to local echoes 2024-08-28 16:49:46 +02:00
Benjamin Bouvier 6181387776 timeline: allow reactions in local|remote event timeline items 2024-08-28 16:49:46 +02:00
Benjamin Bouvier 81a75508dc send queue: early return if there are no dependent events to handle 2024-08-28 16:49:46 +02:00
Benjamin Bouvier f6faf6267e send queue: add integration test for sending and aborting reactions 2024-08-28 16:49:46 +02:00
Benjamin Bouvier 25db0b2cc0 send queue: handle reactions in the send queue 2024-08-28 16:49:46 +02:00
Benjamin Bouvier 2d6aec7319 send queue: put a LocalEcho's event content into a new enum 2024-08-28 16:49:46 +02:00
Kévin Commaille d17a49e827 sqlite: Add more methods to SqliteKeyValueStoreAsyncConnExt
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-08-28 15:45:12 +02:00
Kévin Commaille 1321e92b30 sqlite: Rename SqliteObjectStoreExt to SqliteKeyValueStoreAsyncConnExt
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-08-28 15:45:12 +02:00
Kévin Commaille 6e62f8b269 sqlite: Rename utils::ConnectionExt to SqliteKeyValueStoreConnExt
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-08-28 15:45:12 +02:00
Kévin Commaille 6e369aecc9 sqlite: Rename SqliteConn to SqliteAsyncConn and SqliteObjectExt to SqliteAsyncConnExt
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-08-28 15:45:12 +02:00
Richard van der Hoff ece33059e1 indexeddb: Reinstate crypto store integration tests
We are no longer running the cryptostore integration tests for indexeddb
without encryption. I think this was accidentally removed in 96b615ba.
2024-08-28 11:49:22 +02:00
Benjamin Bouvier 468ee53644 sliding sync version(chore): address review comments 2024-08-27 17:25:12 +02:00
Ivan Enderlin 067b1e0020 feat(ffi): Add Client::available_sliding_sync_versions.
This patch adds bindings to `Client::available_sliding_sync_versions`
to `matrix-sdk-ffi`.

This patch also moves `Client::sliding_sync_version` from “private” to
“public” FFI API, in thee sense that this method is now exported with
UniFFI.
2024-08-27 17:25:12 +02:00
Ivan Enderlin 96c7f36d75 feat(sdk): Add Client::available_sliding_sync_versions.
Previous patches have unified all sliding sync versions behind a
single type: `Version`. More recent previous patches have introduced
`VersionBuilder` so that a `ClientBuilder` can use them to coerce or
find the best `Version` possible. This patch implements a last missing
piece: `Client::available_sliding_sync_versions` will report all
available `Version`s at a given time. This is useful when a `Client`
is already built, and a session has been opened/a user is logged,
but someone has to take the decision whether it's useful to switch to
another sliding sync version or not.
2024-08-27 17:25:12 +02:00
Ivan Enderlin 01f88f1c4b test: Disable Complement Crypto for a short period. 2024-08-27 17:25:12 +02:00
Ivan Enderlin 9e5b06902d test(sdk): Add 2 more tests for auto-discovery of sliding sync. 2024-08-27 17:25:12 +02:00
Ivan Enderlin 245f011fb6 test(sdk): Restore disabled tests. 2024-08-27 17:25:12 +02:00
Ivan Enderlin e1f623cf56 feat: Use the new sliding_sync::VersionBuilder. 2024-08-27 17:25:12 +02:00
Ivan Enderlin 01fd365f67 feat(sdk): Add sliding_sync::VersionBuilder.
This patch adds a builder for `sliding_sync::Version`. It is a similar
enum except that it has `DiscoverProxy` and `DiscoverNative` to
automatically configure `Version::Proxy` or `Version::Native`.
2024-08-27 17:25:12 +02:00
Ivan Enderlin 875f59133b feat(sdk): ClientBuilder extracts get_supported_versions.
This patch changes the type of
`discover_homeserver_from_server_name_or_url`. It now returns a `Url`
instead of a `String` for the homeserver URL. It also returns an
`Option<get_supported_versions::Response>` in addition to the other
values.

The change from `String` to `Url` is necessary to avoid a
double-parsing. It was parsed in `build()` but previously in
`discover_homeserver_from_server_name_or_url` in the last branch.

The addition of `get_supported_versions::Response` is necessary for the
next patch. It's going to be helpful to auto-discover sliding sync in
Synapse. The change happens here because
`get_supported_versions::Response` is already received in
`discover_homeserver_from_server_name_or_url`. This patch makes it easy
to re-use it so that the request is sent only once.

This patch therefore changes `check_is_homeserver` a little bit to
become `get_supported_versions`, and inlines its previous call inside
`discover_homeserver_from_server_name_or_url`.
2024-08-27 17:25:12 +02:00
Ivan Enderlin de8537f8b0 feat: Use sliding_sync::Version everywhere.
This patch replaces all the API using simplified sliding sync, or
sliding sync proxy, by a unified `sliding_sync::Version` type!

This patch disables auto-discovery for the moment. It will be re-enable
with the next patches.
2024-08-27 17:25:12 +02:00
Ivan Enderlin d9ffe2867f feat(sdk): Add sliding_sync::Version. 2024-08-27 17:25:12 +02:00
Daniel Salinas b908fa78b9 The length param from Truncate was not being exposed 2024-08-27 15:17:37 +02:00
Kévin Commaille f568e8c4d3 sdk: Handle a clippy warning
On my version of clippy nightly, these lines triggered the
`filter_map_bool_then` lint.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-08-27 14:10:20 +03:00
Richard van der Hoff 8005515ec5 common: generate wasm bindings for ShieldStateCode on wasm architectures (#3888)
If we're building for the wasm architecture, jump through the hoops to
tell wasm_bindgen about `ShieldStateCode`. This solves the need to 
declare an identical copy of `ShieldStateCode` in the wasm bindings.
2024-08-27 11:02:37 +00:00
Hubert Chathi 758171931d refactor collect_session_recipients in advance of some behavioural changes (#3884)
This is part of https://github.com/matrix-org/matrix-rust-sdk/pull/3662,
pulled out to into a separate PR. Recent changes in `main` made it
pretty much impossible to merge this section of code from `main` into
that PR, and Rich wanted to see the refactoring bits separate from the
behavioural changes. So I've re-written the refactoring.

Pulls the `match` on `sharing_strategy` outside of the `for` loop, and
moves any code that is specific to one strategy into the appropriate
branch.
2024-08-27 11:59:38 +01:00
Daniel Salinas 47671a182d Expose login with email + password on the client 2024-08-26 18:23:25 +02:00
Kévin Commaille b9d49b85c3 sqlite: Use transaction for chunked queries
Allows the operation to be atomic.
Also allows to chunk part of a transaction.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-08-26 18:20:41 +02:00
Benjamin Bouvier 5753c53ea7 test utils: use a macro for assert_next_with_timeout
This makes for better error locations, and avoids monomorphizing on the
stream type in every call site with a different type.
2024-08-26 17:52:43 +02:00
Kévin Commaille fe143ffbed sqlite: Remove SqliteObjectEventCacheStoreExt trait
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-08-26 10:40:12 +02:00
Kévin Commaille 25e406f669 sqlite: Remove unused path field
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-08-26 10:40:12 +02:00
Kévin Commaille 154f86aa20 sqlite: Rename deadpool_sqlite::Object to SqliteConn consistently
So we know that its always the same type when reading the code.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-08-26 10:40:12 +02:00
Doug c769e32b41 ffi: Expose the new cache store path to the bindings. 2024-08-23 15:15:03 +02:00
Jorge Martín c78639d880 sdk-ui: fix pinned events benchmark 2024-08-23 14:12:32 +02:00
Jorge Martín af5107f529 sdk: add RequestConfig to Room::event_with_context to match Room::event, save its results to the event cache too. 2024-08-23 14:12:32 +02:00
Jorge Martín d6d9cd129a sdk: add fn RoomEventCache::save_events to save several events using the same RwLock for the cache, which should be faster 2024-08-23 14:12:32 +02:00
Jorge Martín d1d4c6417c sdk-ui: fix and add new pinned events tests.
This commit contains a new `assert_next_matches_with_timeout!` macro that will take a `Stream` and wait for a little while until its next item is ready, then match it to a pattern.
2024-08-23 14:12:32 +02:00
Jorge Martín d5630bc5cd sdk-ui: load pinned events with their related events
This way any reactions/redactions/edits, etc. will be taken into account when building the timeline event.
2024-08-23 14:12:32 +02:00
Jorge Martín 8a6ac05519 sdk-ui: enable handling new synced timeline events for TimelineFocus::PinnedEvents 2024-08-23 14:12:32 +02:00
Jorge Martín a3262740ac sdk-ui: handle events related to a pinned event in TimelineEventHandler 2024-08-23 14:12:32 +02:00
Andy Balaam fb63c8dfbc crypto: Move should_recalculate_sender_data to OlmMachine 2024-08-23 11:19:42 +01:00
Hubert Chathi e01c1aecbb crypto: Add variants to SenderData to represent different verification states 2024-08-23 11:19:42 +01:00
Kévin Commaille 6e5601db1f Enable web-sys features for tests
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-08-23 10:59:27 +01:00
Kévin Commaille 5586a81703 chore: Use ruma::time instead of instant
This is a reexport of web-time.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-08-23 10:59:27 +01:00
Benjamin Bouvier be133886b7 sdk-ui: remove dependency to async_trait \o/ 2024-08-23 09:43:00 +02:00
Benjamin Bouvier 6fb38179a4 room edit: don't use async_trait for EventSource either 2024-08-23 09:43:00 +02:00
Benjamin Bouvier 912cb233f5 paginator: don't use async_trait for PaginableRoom
This divides compile times for matrix-sdk by 2, on my machine (33
seconds -> 16).
2024-08-23 09:43:00 +02:00
Benjamin Bouvier 4042db7d50 paginator: use a generic type instead of a boxed trait
Who has two thumbs and wants to make a trait not use async_trait, and
thus get rid of trait object safety?
2024-08-23 09:43:00 +02:00
Benjamin Bouvier 4273dff33e timeline: get rid of async_trait for our own traits 2024-08-23 09:43:00 +02:00
Benjamin Bouvier 5f27f487e6 pinned events: get rid of async_trait for PinnedEventsRoom too 2024-08-23 09:43:00 +02:00
Benjamin Bouvier 6cbd197514 timeline: don't use async_trait for RoomExt
It's one fewer pathologically slow type query during type-checking, and
a build time for matrix-sdk-ui 5 seconds lower.
2024-08-23 09:43:00 +02:00
Benjamin Bouvier c10894bed6 timeline: inline update_timeline_item in all callers
It was found that it's making the whole build slower because it's
hitting a pathologically slow path in type-checking. Considering that it
doesn't do much, let's get rid of it and inline it instead.

After this, compiles times are reduced from 30 seconds to 22 seconds on
my machine
2024-08-23 09:43:00 +02:00
Benjamin Bouvier 2291268679 timeline: get rid of Clone for Flow and TimelineEventContext
These are function parameters, they shouldn't be cloned for no good
reason.
2024-08-23 09:43:00 +02:00
Benjamin Bouvier 94e9005132 room list service: get rid of the abstract action system and replace it with functions
After this, compiles times for matrix-sdk-ui are reduced from 44 seconds
to 30 seconds on my machine.
2024-08-23 09:43:00 +02:00
Ivan Enderlin 3a1c374a13 chore(sdk): Rename StickyData::commit to ::on_commit. 2024-08-23 09:18:14 +02:00
Ivan Enderlin 2ac71fc89c test(ui): Fix a test, finally.
This patch fixes a test. It now fails, for my own personal joy. The new
behaviour is much better.
2024-08-23 09:18:14 +02:00
Ivan Enderlin a484964d4d feat(sdk): Do not send a room subscription that has already been sent.
This patch uses the new `RoomSubscriptionState` enum to filter
room subscriptions that have already been sent, when building a
`http::Request` with the sticky parameters.

By default, to start, a `http::request::RoomSubscription` is in the
state `Pending`, i.e. it's not sent yet. Once the sticky parameters are
committed, the state is updated to `Applied`. When the sticky parameters
are applied, only the `Pending` room subscriptions are added.

This patch contains one test to specifically assert this behaviour.
2024-08-23 09:18:14 +02:00
Ivan Enderlin 5f159d4418 feat(sdk): Add RoomSubscriptionState.
This patch introduces the `RoomSubscriptionState` type, to represent
whether a room subscription has already been correctly sent to the
server.
2024-08-23 09:18:14 +02:00
Ivan Enderlin aeaedf7e5b feat(sdk): Add StickyData::commit.
This patch adds the `commit` method on the `StickyData` trait. It is
called by `SlidingSyncStickyManager::maybe_commit` when we are sure the
data can be validated because of a valid response to the sent request.
2024-08-23 09:18:14 +02:00
Benjamin Bouvier 2db031cec5 timeline: rename ReactionStatus::Remote to ReactionStatus::RemoteToRemote 2024-08-22 17:46:11 +02:00
Benjamin Bouvier 3329e75708 test: add a test that if a redaction request fails, we add the annotation back 2024-08-22 17:46:11 +02:00
Benjamin Bouvier cdd6c23e15 test: add a test for redacting a reaction that was being sent 2024-08-22 17:46:11 +02:00
Benjamin Bouvier 6dc8d3980e timeline: only use the send queue to send reactions, and nothing else 2024-08-22 17:46:11 +02:00
Benjamin Bouvier a9c0dc3da4 timeline: introduce new methods send/redact in the RoomDataProvider 2024-08-22 17:46:11 +02:00
Timo c04dd18440 MatrixRTC: Update ruma revision.
This revision includes renaming `focus_select` (wrong) to `focus_selection` (correct).
2024-08-22 15:59:46 +02:00
Jorge Martin Espinosa 794bf98a1b sdk: add relationships cache to EventCache (#3870)
## Changes

- Creates a separate `AllEventsCache` struct holding both the actual all
events cache map and the relationship one. This new cache wrapper also
holds a single `RwLock` to both inner caches, as they are independent
from each other.
- When a new event is saved either from `/sync` or another HS request,
it'll be saved to both the 'all events' cache and the relationship map.
- Add tests for the relationship cache.
2024-08-22 14:24:19 +02:00
Richard van der Hoff e88f14a1f9 ffi: expose new SessionRecipientCollectionErrors to application
Fixes https://github.com/matrix-org/matrix-rust-sdk/issues/3842
2024-08-22 12:47:16 +01:00
Benjamin Bouvier b95c189a18 test mocks: deduplicate mock_encryption_state 2024-08-22 10:45:50 +02:00
Benjamin Bouvier 92fe72f83a test: add a mocks mod in matrix-sdk-test to reuse across different integration tests 2024-08-22 10:45:50 +02:00
Kévin Commaille 01e2db1f52 base: Move media cache to new EventCacheStore trait (#3858)
Allows to save media in a different path than the state store.

This adds a "last_access" field to the SQLite implementation, to prepare
for future work on a media retention policy.

This removes the IndexedDB media cache implementation, because as far as
I know it is currently unused, and I have no idea how to implement
efficiently the planned media retention policy with a key-value store.

Closes #1810.

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

---------

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-08-22 10:36:43 +02:00
Ivan Enderlin 40d447dc69 fix(sdk): Clear all sliding sync room subscriptions when session expires.
This patch clears all sliding sync room subscriptions when a session
expires. Indeed, we might not want to request all room subscriptions
when the session restarts. Imagine if the client has subscribed to 400
rooms and the session expires: once the session restarts, it will ask
for 400 room subscriptions, which is a lot and will result in a quite
slow response.
2024-08-21 18:34:11 +02:00
Stefan Ceriu 4cc5790c64 ffi: expose room membership through the RoomListItem and allow invited rooms to be build differently than "full" ones (#3869)
We're finding ourselves in the situation in which we can't interact with
invites through normal Room APIs as `full_room`s can't be build from the
RoomListItem. Full rooms require the timeline to be configured before
use and the timeline can't be configured because encryption cannot be
fetched for invited rooms on homeservers that have previews disabled
(see #3848 and #3850)

In response we now expose the room's membership directly from the
`RoomListItem` so that the final client can chose which of the 2 rooms
types (invited or full) to ask for before using aforementioned APIs.

Powers https://github.com/element-hq/element-x-ios/pull/3189
2024-08-21 16:55:03 +03:00
Jorge Martín fbc9db9b15 ffi: add info to FFI room redaction event 2024-08-21 13:29:36 +02:00
Ivan Enderlin f6b21e6ce9 chore(sdk): Clean documentation and remove a useless pub(super).
This patch is a small cleanup.
2024-08-21 13:11:09 +02:00
Ivan Enderlin 05542f7ba8 feat(sdk): Sliding sync has a timeout if all lists require a timeout.
This patch updates when sliding sync requests have a `timeout`.

Prior to this patch, all requests had a `timeout` query, set to the
`poll_timeout` duration value. However it means: if there is no data
to return, wait `timeout` milliseconds for new data before returning.
This definition is correct. Problem: if the current range of a list
has no data, the server will wait! It means that, in a situation where
there is no update at all, but the client is fetching all rooms batch by
batch, it will wait `poll_timeout` for each batch!

The behaviour described above is absolutely correct. Some server
implementations are less strict though, and we didn't realise our code
was doing that, because the server had some optimisations to ignore the
timeout if the range wasn't covering all the rooms. Nonetheless, a new
server implementation (namely Synapse) is strict, and it confirms we
have a bug here.

This patch then configures a `timeout` if all lists require a timeout,
otherwise there is no `timeout`, which is equivalent to `timeout=0`.
2024-08-21 13:11:09 +02:00
Ivan Enderlin b06bb42d3e feat(sdk): Add SlidingSyncList::requires_timeout.
This patchs adds the `SlidingSyncList::requires_timeout` method to know
exactly when a list should trigger a `timeout` on the request.
2024-08-21 13:11:09 +02:00
Ivan Enderlin e4d0f2291f feat(sdk): Add SlidingSyncListRequestGenerator::is_selective.
This patch adds a small helper:
`SlidingSyncListRequestGenerator::is_selective`.
2024-08-21 13:11:09 +02:00
Ivan Enderlin 31f84d7534 feat(sdk): Implement SlidingSyncListLoadingState::is_fully_loaded.
This patch implements and tests
`SlidingSyncListLoadingState::is_fully_loaded` for more convenience.
2024-08-21 13:11:09 +02:00
Ivan Enderlin 4c5b537825 test(sdk): Rename tests.
This patch renames tests.
2024-08-21 13:11:09 +02:00
Richard van der Hoff d9e6bfa678 Add a tip about using RustRover 2024-08-21 09:41:54 +01:00
Stefan Ceriu f0d98602a9 timeline: use the EncryptionInfo provided by the replacement event when processing edits
- this prevents issues where spoofing the sender field is enough to spoof and edit and display wrong decorations in the app
- fixes matrix-org/internal-config/issues/1549
2024-08-21 10:31:33 +02:00
Richard van der Hoff a27ebaabae ffi: add ClientBuilder::room_key_recipient_strategy
... and pass it through to the underlying ClientBuilder.
2024-08-20 18:22:56 +01:00
Richard van der Hoff 9b78903705 crypto: add ClientBuilder::with_room_key_recipient_strategy
... and pass it into the constructed BaseClient.
2024-08-20 18:22:56 +01:00
Richard van der Hoff 0151f32425 crypto: add BaseClient::room_key_recipient_strategy field
... and use it when sharing a room key.
2024-08-20 18:22:56 +01:00
Andy Balaam ca09917d84 crypto: Update the comment about source of truth for in sqlite 2024-08-20 15:36:34 +01:00
Andy Balaam 78924ed877 crypto: In sqlite, use the SQL column value for backed_up everywhere
Most times we pulled an InboundGroupSession from the sqlite DB, we were
overriding whatever value for `backed_up` was stored inside the pickled
value, and using the value stored in the SQL column.

But when we pulled a single InboundGroupSession from the DB by ID, we
did not override it.

I am fairly sure this was an accidental oversight, so this change
corrects it, and unifies the code with other places we create these
objects.
2024-08-20 15:36:34 +01:00
Andy Balaam 668a267c9b crypto: Merge deserialize_pickled_inbound_group_session into unpickle_inbound_group_session 2024-08-20 13:16:17 +01:00
Andy Balaam fed08fad76 crypto: Utility deserialize_and_unpickle_inbound_group_session for sqlite store 2024-08-20 13:16:17 +01:00
Richard van der Hoff 651b61414e crypto: add a note about libolm only being used in tests
It seems that the fact that matrix-rust-sdk contains `olm-rs` in its
`Cargo.lock` sparked panic, so let's attempt to fend off future concerns by
adding a comment.
2024-08-20 12:16:33 +01:00
Benjamin Bouvier bbefad34bc test: reuse the internal EventFactory of the TestTimeline in more places
Also rename a few `factory` to `f`, for consistency with the rest of the
testing code.
2024-08-20 12:11:11 +02:00
Benjamin Bouvier b00f58a28d test: get rid of TestTimeline::handle_live_message_event in favor of TestTimeline::handle_live_event
By using the `EventFactory` a bit more.

Part of #3716.
2024-08-20 12:11:11 +02:00
Kévin Commaille 3b3474688b sdk: Upgrade mas-oidc-client
Gets rid of the old version of the http crate.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-08-19 23:14:27 +02:00
Ivan Enderlin ed19bf7bc5 fix(ffi): New fields formatter to remove duplicated span fields.
This patch fixes a bug in the tracing system. It introduces one
fields formatter _per layer_ to force the fields to be recorded in
different span extensions, and thus to remove the duplicated fields in
`FormattedFields`.

The patch contains links to the bug report in `tokio-rs/tracing`. This
patch is a workaround.
2024-08-19 14:44:04 +02:00
Ivan Enderlin eeb325abb7 chore(ffi): Format code. 2024-08-19 14:44:04 +02:00
Richard van der Hoff 9d7dd1a6d6 crypto: update changelog 2024-08-19 13:13:58 +01:00
Richard van der Hoff 820f4ee711 crypto: tests for errors on verification violation 2024-08-19 13:13:58 +01:00
Richard van der Hoff 271ba98ba9 crypto: test: factor out EncryptionSettings helper 2024-08-19 13:13:58 +01:00
Richard van der Hoff 7575c256d4 crypto: test: move unsigned_of_verified_setup helper function
I want to use this in more tests, so move it out of the middle of the test
module.
2024-08-19 13:13:58 +01:00
Richard van der Hoff cd0d79dd88 crypto: Key sharing option to error for verification violation 2024-08-19 13:13:58 +01:00
Richard van der Hoff d35e3405ab crypto: Add UserIdentityData::was_previously_verified
Since `was_preivously_verified` is implemented for both variants, we can add a
helper here.
2024-08-19 13:13:58 +01:00
Ivan Enderlin 711a753533 doc(sdk): Update CHANGELOG.md. 2024-08-19 07:22:29 +02:00
Ivan Enderlin 4e291205d5 feat(sdk): Remove NotificationSettings::subscribe_to_changes.
This patch removes `NotificationSettings::subscribe_to_changes` because
it's not used anywhere in our code except in tests. It is indeed part of
the public API but I'm not aware of anyone using it for the moment. It
only adds complexity in the code.
2024-08-19 07:22:29 +02:00
Richard van der Hoff b497577717 crypto: use UserIdentities utility functions
... instead of lots of `match` and `own()` and `other()`.
2024-08-16 16:58:27 +01:00
Richard van der Hoff 9077310eb2 crypto: Add utility wrappers to UserIdentities
We have a bunch of methods which are the same in both `OtherUserIdentity` and
`OwnUserIdentity`, so add some convenience methods to access them.
2024-08-16 16:58:27 +01:00
Richard van der Hoff b4d265e997 crypto: update changelog 2024-08-16 15:07:36 +01:00
Richard van der Hoff dd810f4803 crypto: Track if our own identity was previously verified
... and expose new methods to access it.
2024-08-16 15:07:36 +01:00
Richard van der Hoff a6b78d8d53 crypto: replace OwnUserIdentityData::verified with enum
I want to make this a tri-state, so let's start by making it an enum.
2024-08-16 15:07:36 +01:00
Richard van der Hoff 96c4e4c49e crypto: update OtherUserIdentityData::is_device_signed to return bool
Once again: since all the callers end up calling `.is_ok()` on the result, and
the name implies it should return a bool, let's just return a bool.
2024-08-16 12:34:10 +01:00
Richard van der Hoff 5f9a4fc6d1 crypto: update OwnUserIdentityData::is_device_signed to return bool
As before: since all the callers end up calling `.is_ok()` on the result, and
the name implies it should return a bool, let's just return a bool.
2024-08-16 12:34:10 +01:00
Richard van der Hoff 31b25b8754 crypto: update OwnUserIdentityData::is_identity_signed to return bool
Since all the callers end up calling `.is_ok()` on the result, and the name
implies it should return a bool, let's just return a bool.
2024-08-16 12:34:10 +01:00
Ivan Enderlin fa6066b810 test(sdk): Test Room::cached_user_defined_notification_mode.
This patch adds a test for `Room::cached_user_defined_notification_mode`.
2024-08-15 14:51:16 +03:00
Ivan Enderlin 102da7cb9a feat(ffi): Add RoomInfo::cached_user_defined_notification_mode.
This patch replaces `RoomInfo::user_defined_notification_mode` by
its cached variant: `cached_user_defined_notification_mode`, and
call `Room::cached_user_defined_notification_mode` which will boost
performance when computing a new `RoomInfo`.
2024-08-15 14:51:16 +03:00
Ivan Enderlin 1c39086b5a feat(sdk): Cache the user-defined notification mode on each sync.
This patch caches the user-defined notification mode on each sync for
the sake of performance.
2024-08-15 14:51:16 +03:00
Ivan Enderlin 651e8fcd48 test(base): Split test_room_info_deserialization_without_optional_items.
This patch splits/copies the
`test_room_info_deserialization_without_optional_items` test into the
same test + `test_room_info_deserialization`.

It appears that the _without optional items_ part has been forgotten.
In the past, the test has been updated to test optional items. The
initial idea (based on my understanding of the comments) is to test
potentially old `RoomInfo` can still be deserialized today. So this test
must never be changed, except if a non-optional field is added.

For this reason, this patch removes from this test the assertions about
optional fields. A new test, named `test_room_info_deserialization` is
created, and tests all the fields, including the optional ones.

One important thing:
`test_room_info_deserialization_without_optional_items` now runs
even if the `experimental-sliding-sync` feature is absent. It was
required only because of `latest_event`, but that's an optional
field! However, the `test_room_info_deserialization` requires the
`experimental-sliding-sync` feature, as it tests `latest_event` but
also `recency_stamp`.

Finally, `test_room_info_deserialization` tests
`cached_user_defined_notification_mode`.
2024-08-15 14:51:16 +03:00
Ivan Enderlin ad947132ed feat(sdk): Room::user_defined_notification_mode caches its result.
This patch updates `matrix_sdk::Room::user_defined_notification_mode`
to cache its result if some mode has been found. The cached result can
be retrieve with
`matrix_sdk_base::Room::cached_user_defined_notification_mode`.
2024-08-15 14:51:16 +03:00
Ivan Enderlin 2a3525f7be chore(sdk): Add missing copyright. 2024-08-15 14:51:16 +03:00
Ivan Enderlin 7e2c773d21 chore(base): Move RoomNotificationMode into matrix-sdk-base.
This patch moves the `RoomNotificationMode` type from `matrix-sdk`
to `matrix-sdk-base` because it's going to be shared across multiple
crates.
2024-08-15 14:51:16 +03:00
Jorge Martín 6becbf61c9 fixup! Fixes after rebase 2024-08-14 17:38:24 +02:00
Jorge Martín 1155f75612 fixup! fix review comments 2024-08-14 17:38:24 +02:00
Jorge Martín 5cd29830a3 fixup! Fix clippy after merge 2024-08-14 17:38:24 +02:00
Jorge Martín 34370b1525 fixup! Fix test 2024-08-14 17:38:24 +02:00
Jorge Martín 1132074ae0 sdk-base: Make sure we only send a notable membership update when membership does change 2024-08-14 17:38:24 +02:00
Jorge Martín e5af5a32fa sdk-base: Add RoomInfoNotableUpdateReasons::MEMBERSHIP
This fixes joined rooms not being bumped to the top of the timeline and left rooms not disappearing from the room list.
2024-08-14 17:38:24 +02:00
Richard van der Hoff 1e8dd5dd41 crypto: Update changelog 2024-08-14 14:57:42 +01:00
Richard van der Hoff 5431c0fdd6 crypto: test: add tests for error_on_verified_user_problem 2024-08-14 14:57:42 +01:00
Richard van der Hoff a240b87ba6 crypto: test: factor out redundant variable
This thing was confusing. What is "legacy" about it?
2024-08-14 14:57:42 +01:00
Richard van der Hoff 324cf2e007 crypto: test: factor out create_test_outbound_group_session helper 2024-08-14 14:57:42 +01:00
Valere 66142317d4 crypto: key sharing error for verified user with unverified devices 2024-08-14 14:57:42 +01:00
Richard van der Hoff f66c74e878 crypto: extend CollectionStrategy::DeviceBasedStrategy
Add (as yet unimplemented) `error_on_verified_user_problem` option
2024-08-14 14:57:42 +01:00
Richard van der Hoff 1862a3e254 crypto: change EncryptionSettings::new to take a CollectStrategy
Again, the list of boolean arguments is confusing.
2024-08-14 14:57:42 +01:00
Richard van der Hoff dadc85c4fc crypto: remove CollectStrategy::new_device_based
The list of boolean arguments is confusing. We may as well just construct the
`DeviceBasedStrategy` directly.
2024-08-14 14:57:42 +01:00
Richard van der Hoff d8c1094939 crypto: add OwnUserIdentityData::is_identity_verified
... and use it to remove a bit of duplicated code.
2024-08-14 14:57:42 +01:00
Richard van der Hoff ace937fcee crypto: rafactor split_recipients_withhelds_for_user
Use a for loop rather than `partition_map`. We're about to add a third list, so
partition_map won't work.

(partition_map ends up using Vec::push under the hood, so this is pretty much
equivalent.)
2024-08-14 14:57:42 +01:00
Richard van der Hoff 1e58c0382c crypto: minor cleanups in is_session_overshared_for_user 2024-08-14 14:57:42 +01:00
Valere ce95cc06e0 crypto: extract function that checks if session is shared too much 2024-08-14 14:57:42 +01:00
Andrew Ferrazzutti 3803792518 rtc: Handle non-MXID call member event state keys (#3836)
Update Ruma dependency to expect call membership state events with state
keys that are arbitrary strings, not just pure MXIDs.

When a call membership state key does not exactly match the format of an
MXID, treat it as a valid state key if it starts with an MXID followed
by an underscore, with that MXID designating the owner of the event.

(The state key may also be optionally prefixed with an underscore, which
is permitted as a way to bypass pre-MSC3757 authorization rules against
sending state events with state keys that do not exactly match the
sender's MXID.)

---------

Signed-off-by: Andrew Ferrazzutti <andrewf@element.io>
Co-authored-by: Benjamin Bouvier <public@benj.me>
Co-authored-by: Benjamin Bouvier <benjamin@bouvier.cc>
2024-08-14 08:43:02 +00:00
Richard van der Hoff 4ece38af4f test: document methods in PreviouslyVerifiedTestData 2024-08-13 16:38:58 +01:00
Richard van der Hoff 4baa82d3a6 test: add new methods for device IDs 2024-08-13 16:38:58 +01:00
Richard van der Hoff 8b01e3e209 test: make internal functions private 2024-08-13 16:38:58 +01:00
Richard van der Hoff 4a69cc9110 test: inline device_keys_payload_bob_unsigned_device
This is only used in one place, so is a bit pointless.
2024-08-13 16:38:58 +01:00
Benjamin Bouvier 766786e2f1 pinned events(refactor): get rid of the PinnedEventCache
This commit makes use of the `RoomEventCache` instead of the
`PinnedEventCache` for a room, so the latter can be removed.
2024-08-13 17:17:16 +02:00
Benjamin Bouvier e67e2289e2 event cache(refactor): use a map keyed by event id for retrieving events
And add unit tests.
2024-08-13 17:17:16 +02:00
Benjamin Bouvier 5954ee18b7 pinned events(refactor): rename event_with_config to fetch_event
The `with_config` is now redundant, and `fetch` makes it clear it's
hitting network.
2024-08-12 16:01:39 +02:00
Benjamin Bouvier e15ddf6ad9 pinned events(refactor): simplify handling of AddTimelineEvents
The timeline already listens to changes to the pinned events list (via a
stream), so there's no need to fully reload all the pinned events every
time we receive a new event that's pinned. Technically it may avoid one
or a few lookups, but this is cheap and a subsequent commit/PR will
merge the pinned event cache into the event cache.
2024-08-12 16:01:39 +02:00
Benjamin Bouvier 19b6495f2b pinned events(refactor) misc tiny refactorings and renamings 2024-08-12 16:01:39 +02:00
Benjamin Bouvier 0ba6adbf34 pinned events(chore): add doc comments 2024-08-12 16:01:39 +02:00
Benjamin Bouvier 3886a55ad8 pinned events(chore): add licence header to pinned_events_loader.rs 2024-08-12 16:01:39 +02:00
Benjamin Bouvier 8f59f45183 pinned events(refactor): don't store max_concurrent_requests as a field
since it's used only once
2024-08-12 16:01:39 +02:00
Benjamin Bouvier a12a244a89 pinned events(refactor): lower logs from info to debug 2024-08-12 16:01:39 +02:00
Benjamin Bouvier f3587a44dc pinned events(refactor): fetch all the pinned events concurrently
Also log the reason why one couldn't be fetched, instead of discarding
silently.
2024-08-12 16:01:39 +02:00
Benjamin Bouvier c76ea95f65 pinned events(refactor): sort loaded pinned events in place
Instead of creating a collection, then using itertools to sort it, then
allocating a new vector from that.
2024-08-12 16:01:39 +02:00
Ivan Enderlin bdfc300e4c feat(sdk): compute_limited is only useful for the SS proxy.
This patch restricts the call to `compute_limited` to the sliding sync
proxy implementation (aka MCS3575). It is not necessary for the sliding
sync native implementation (aka Simplified MSC3575). The proxy doesn't
implement the `limited` flag, contrary to Synapse. Let's not run
workarounds when we don't need them.
2024-08-12 15:06:01 +02:00
Ivan Enderlin d143c6198c fix(sdk): Remove SlidingSyncInner::past_positions.
The patch https://github.com/matrix-org/matrix-rust-sdk/pull/2395 has
introduced `SlidingSyncInner::past_positions` as a mechanism to filter
duplicated responses. It was a problem because the sliding sync `ops`
could easily create corrupted states if they were applied more than
once.

Since https://github.com/matrix-org/matrix-rust-sdk/pull/3664/, `ops`
are ignored.

Now, `past_positions` create a problem with the sliding sync native
implementation inside Synapse because `pos` can stay the same between
multiple responses.

While `past_positions` was helpful to fix bugs in the past, it's no
longer necessary today. Moreover, it breaks an invariant about `pos`: we
must consider it as a blackbox. It means we must ignore if a `pos` value
has been received in the past or not. This invariant has been broken for
good reasons, but it now creates new issues.

This patch removes `past_positions`, along with the associated code
(like `Error::ResponseAlreadyReceived` for example).
2024-08-12 14:26:31 +02:00
Ivan Enderlin 35b62a1a4a doc(sdk): Fix a markup.
Even if the visual output is the same, it's semantically better to have
`<a><code>…</code></a>` rather than `<code><a>…</a></code>` I believe.
2024-08-12 13:47:28 +02:00
Ivan Enderlin 704fe6719f feat(sdk): Add a log for must_process_rooms_response.
This patch adds a `trace` log for `must_process_rooms_response`. That's
useful for debugging weird bugs.
2024-08-12 13:47:28 +02:00
Ivan Enderlin 0b9e07a386 chore(sdk): Change visibility of SlidingSyncList::invalidate_sticky_data.
This patch changes the visibility of
`SlidingSyncList::invalidate_sticky_data` from `pub` to `pub(super)`.
This is the only place where it must be accessible from.
2024-08-12 13:47:28 +02:00
Ivan Enderlin 0a28c222f5 test(ui): Improve test_room_subscription.
This patch asserts that when subscribing to a new room, the old room
subscriptions are still present. Is it the behaviour we want? Probably
not, but this is the standard behaviour right now, and we need to assert
it.
2024-08-12 13:47:28 +02:00
Richard van der Hoff 31dbca6c28 testing: create ruma_response_from_json
We had *two* copies of `response_from_file`, and all calls to them were always
immediately followed by an operation to parse the response as a Ruma response
object.

We can save a whole lot of boilerplate with a generic function that wraps the
json into an HTTP response *and* parses it into a Ruma object.
2024-08-12 12:39:02 +01:00
Richard van der Hoff f96e82f833 indexeddb: Future-proofing: accept any db schema version up to 99
... so that next time we make a non-breaking change to the schema, it doesn't
break rollback
2024-08-12 12:37:56 +01:00
Richard van der Hoff f2792801c3 indexeddb: Add missing do_schema_upgrade call from v11 migration
We weren't updating the database schema version immediately after the v10 -> v11
migration. This was fine in practice, because (a) for now, there is no v12
migration so we ended up setting the schema version immediately anyway; (b) the
migration is idempotent.

However, it's inconsistent with the other migrations and confusing, and is
about to make my test fail, so let's clean it up.
2024-08-12 12:37:56 +01:00
Benjamin Bouvier a0c8b71236 refactor(sdk): merge Room::event and Room::event_with_config
It's better to have fewer public APIs, especially when there's little
annoyance to have it. We could use a request builder that converts into
a Future, too, but considering there's only a single optional parameter,
it's fine to include it in the function's signature.
2024-08-12 11:51:54 +02:00
Erik Johnston 101f6bd57b Sync: Don't spuriously show spinner
We should only show the spinner if the *first* sliding sync request is
taking a while. If we have received some data and the second request
takes a while, that is OK.

For the state transition of `Init -> SettingUp` this is handled
correctly, however for `Terminated -> Recovering -> Running` we waited
until the second request returned before hiding the sync spinner. This
meant that if the first request returned quickly the app would show new
data and *then* the sync spinner would show (if the second request took
time).

This situation occurs frequently with the new SSS API, where if all the
new data was returned in the first sync then the second sync would
block waiting for new data, triggering the sync spinner.
2024-08-12 11:47:18 +02:00
Benjamin Bouvier fa394fc45b test: remove unused TestClientBuilder::http_proxy method 2024-08-12 11:44:34 +02:00
Ivan Enderlin 16ca282ae4 chore(ui): Add logs inside RoomListService::sync.
This patch adds logs inside the `RoomListService::sync` method to know
what are the current states.
2024-08-12 10:03:22 +02:00
Ivan Enderlin be404f6666 feat(sdk): Subscribe to many rooms only via Sliding Sync.
This patch changes the `SlidingSync::subscribe_to_room` method to
`subscribe_to_rooms`. Note the plural form. It's now mandatory to
subscribe to a set of rooms. The idea is to avoid calling this method
repeatedly. Why? Because each time the method is called, it sends a
`SlidingSyncInternalMessage` of kind `SyncLoopSkipOverCurrentIteration`,
i.e. it cancels the in-flight sliding sync request, to start over with
a new one (with the new room subscription). A problem arises when the
async runtime (here, Tokio) is busy: in this case, the internal message
channel can be filled pretty easily because its size is 8. Messages
are not consumed as fast as they are inserted. By changing this API:
subscribing to multiple rooms will result in a single internal message,
instead of one per room.

Consequently, the rest of the patch moves the `subscribe` method of
`room_list_service::Room` to `room_list_service::RoomListService`
because it now concerns multiple rooms instead of a single one.
2024-08-09 11:58:59 +03:00
Stefan Ceriu 89ce8870a9 ffi: provide manual cancellation mechanism for identity/cross-signing reset handles
- works around swift issue where nil-ing the handle is not enough for it to get cancelled
2024-08-09 10:27:56 +03:00
Ivan Enderlin 70f46d48af chore(ffi): More idiomatic format!. 2024-08-08 17:54:49 +02:00
Timo 58f4e2b1ad FFI Element Call: Fix the permission list returned by the get_element_call_required_permissions ffi function. 2024-08-08 17:54:49 +02:00
Damir Jelić 58c35ee507 Add the rust-crypto-reviewers to the code owners for the crypto crate 2024-08-08 14:51:30 +02:00
Damir Jelić 40c347846e docs: Mention that the custom types in the crypto crate implement zeroize 2024-08-08 14:04:11 +02:00
Richard van der Hoff 9c809b900d Merge pull request #3813 from matrix-org/rav/split_machine_tests
crypto: split up the `machine.rs` behemoth
2024-08-08 12:00:39 +01:00
Damir Jelić a03893ee3f ci: Enable CI for draft PRs (#3815)
Our CI used to be quite slow and used up a lot of CI time, so as an
optimization we disabled CI for draft PRs.

This is a bit annoying since people want to open draft PRs to check if
CI passes, but without triggering any review requests.

Since our CI is nowadays a bit more efficient let's see if we can enable
it for draft PRs.
2024-08-08 12:58:51 +02:00
Richard van der Hoff 045374c604 Merge remote-tracking branch 'origin/main' into rav/split_machine_tests 2024-08-08 11:44:12 +01:00
Richard van der Hoff f3fe06be7d Merge pull request #3795 from matrix-org/valere/invisible_crypto/verification_pin
Crypto | Add support for verified identities change detection.
2024-08-08 11:10:47 +01:00
Richard van der Hoff 2220973adc crypto: move room_settings tests to their own file 2024-08-07 17:20:02 +01:00
Richard van der Hoff d8b0b2e097 crypto: move encrypted to-device tests to new file 2024-08-07 17:18:52 +01:00
Richard van der Hoff 93f6bdecb3 crypto: move decryption verification state tests to a new file 2024-08-07 17:17:51 +01:00
Richard van der Hoff 85b74edf80 crypto: move interactive verification tests to a new file 2024-08-07 17:17:02 +01:00
Richard van der Hoff 6f5442c5ce crypto: Move some olm-related tests to a separate file 2024-08-07 17:15:45 +01:00
Richard van der Hoff 18e27f3090 crypto: move OlmMachine tests to a separate file 2024-08-07 17:05:47 +01:00
Richard van der Hoff 066fdf99c3 crypto: Move create_session test helper to test_helpers 2024-08-07 17:02:47 +01:00
Richard van der Hoff 2c0d858833 crypto: Pull out OlmMachine test helpers to a new module 2024-08-07 16:10:26 +01:00
Richard van der Hoff 0b5f9aec5e crypto: promote machine module to directory 2024-08-07 16:08:56 +01:00
Valere 1b05380b60 Crypto: Verified identity changes - Add API at UserIdentity level + test 2024-08-07 15:06:19 +02:00
Valere 072b5d5605 Fix typo in method name 2024-08-07 13:36:20 +02:00
Valere 7e9f4fc5a0 CodeReview: Clarify comment 2024-08-07 13:34:12 +02:00
Valere 2e410e5d94 CodeReview: rename verification_latch to previously verified 2024-08-07 13:34:12 +02:00
Valere d81b12f389 Review: Fix false postitive typo in b64 string 2024-08-07 13:34:12 +02:00
Valere 58c4075ff5 Review: CI fix identity serialization test 2024-08-07 13:34:12 +02:00
Valere 3c9ae33be1 crypto: Verified identity changes - Migration of existing data 2024-08-07 13:34:12 +02:00
Valere c171c518c6 crypto: Verified identity changes Fix test with memory store
Clone of identities prevent detect changes due shared Arc. Force serializing/deserializing
2024-08-07 13:32:55 +02:00
Valere 20f717ec31 crypto: Verified Identity changes - Update latch on own trust change 2024-08-07 13:32:55 +02:00
Valere 0e01b1d93c crypto: Verified identity changes - Update latch on identity update 2024-08-07 13:29:58 +02:00
Valere 3d3f93a33d crypto: Verified identity changes TDD 2024-08-07 13:29:57 +02:00
Valere b4fe3059c3 crypto: Remember and detect verified identity changes for #1129 2024-08-07 13:29:57 +02:00
Jorge Martín 57963dcf36 ffi: add method for the ClientBuilder to provide a RequestConfig for the client 2024-08-07 11:48:34 +02:00
Jorge Martín 7d9fdc4f05 sdk-ui: add fn Room::event_with_config
This method works the same as `Room::event` but you can provide a custom `RequestConfig` to it.

It's especially useful for the pinned events timeline, since we need a max number of retries and a max number of concurrent requests. With this we can remove some unnecessary complexity.
2024-08-07 11:48:15 +02:00
Jorge Martín 1c4f035c99 sdk-ui: reverse (again) the order in the pinned events timeline
This way it matches the rest of timelines in the SDK, I reversed it here because I didn't realise most clients just do this reversal of ordering themselves. As they do, they need the same order for this timeline too to be able to reuse their existing logic.
2024-08-06 19:33:00 +02:00
Doug 71e4f60fa5 chore: Update the human readable description for the SentInClear shield. 2024-08-06 17:22:38 +03:00
Damir Jelić c3848ca016 crypto: Update the changelog 2024-08-06 15:10:13 +02:00
Damir Jelić a74f6bcc3f Add the Olm Session cache back in the CryptoStoreWrapper 2024-08-06 15:10:13 +02:00
Damir Jelić ba7fb7fc36 Convert all SessionStore locks to be async locks 2024-08-06 15:10:13 +02:00
Damir Jelić 96b615ba8e Remove Olm Session cache from the individual crypto store implementations 2024-08-06 15:10:13 +02:00
Jorge Martín c83fa3a532 sdk-ui: move conversion between Content::RoomPinnedEvents from ffi to sdk-ui 2024-08-06 10:37:18 +02:00
Jorge Martín d509d79472 ffi: add RoomPinnedEventsChange and a diffing step to know what happened in the last pinning/unpinning events action 2024-08-06 10:37:18 +02:00
Andy Balaam ffba842919 crypto: Don't recalculate SenderData if the sender is known but not verified 2024-08-06 09:34:21 +01:00
Jorge Martín 91c10ae213 sdk-ui: add PinnedEventsLoaderError::TimelineReloadFailed.
This error will be returned when the room has pinned event ids but the timeline couldn't load any of them.

Also fix tests.
2024-08-05 16:56:49 +02:00
Andy Balaam efdd6d2693 crypto: Use most-trusted SenderData available when decrypting 2024-08-05 15:46:08 +01:00
Andy Balaam 08bc563e9e crypto: Methods on SenderData for comparing trust level 2024-08-05 15:46:08 +01:00
Jorge Martín 71b5ab4d07 sdk-ui: fix pinned_events tests 2024-08-05 14:31:03 +02:00
Jorge Martín 4569b25d98 bench: fix benchmark by adding encryption event and clearing the cache in each iteration 2024-08-05 14:31:03 +02:00
Jorge Martín 9f7f1a98fb ffi: base the ffi::Room::clear_pinned_events method in sdk::Room::clear_pinned_events 2024-08-05 14:31:03 +02:00
Jorge Martín 4432b332fa sdk: add Room::clear_pinned_events 2024-08-05 14:31:03 +02:00
Jorge Martín d846563df3 sdk-ui: use reversed chronological order for TimelineFocus::PinnedEvents 2024-08-05 14:31:03 +02:00
Doug b453a0204e sdk-ui: Make the SentInClear shield red. 2024-08-05 10:48:06 +02:00
Doug 4c220ed030 shields: Put the Code inside the Colour instead of the Colour inside the Code. 2024-08-05 10:48:06 +02:00
Doug 037badf7a4 chore: Strongly typed ShieldStates. 2024-08-05 10:48:06 +02:00
Jorge Martín fba61751d5 sdk-ui: extract MAX_CONCURRENT_REQUESTS const for PinnedEventsLoader 2024-08-02 18:54:28 +02:00
Jorge Martín 2bd4db8a23 sdk-ui: use PinnedEventsLoader::update_if_needed when new timeline events are received. Using PinnedEventsLoader::load_events here was a mistake. 2024-08-02 18:54:28 +02:00
Jorge Martín 4de1375a76 ffi: add bindings for Room::clear_pinned_events_cache 2024-08-02 18:54:28 +02:00
Jorge Martín 1353406b80 sdk-ui: add Room::clear_pinned_events_cache to remove any cached pinned events from a room 2024-08-02 18:54:28 +02:00
Jorge Martín e1bffaee21 sdk: add PinnedEventCache::remove_bulk to be able to remove events from the cache 2024-08-02 18:54:28 +02:00
Jorge Martín 0496ef4313 sdk-ui: add test checking the pinned event cache is kept for different room instances 2024-08-02 18:54:28 +02:00
Jorge Martín 674605aeab sdk-ui: use the moved PinnedEventCache instead of the one encapsulated in PinnedEventsLoader 2024-08-02 18:54:28 +02:00
Jorge Martín f1b20a8ea5 sdk: add PinnedEventCache to Client.
This ensures the cache keeps the events even when the associated `Room` is dropped, which is what we want when using it to cache the pinned events for rooms in the client.

Add `fn Client::pinned_event_cached()` to get a reference to it.
2024-08-02 18:54:28 +02:00
Jorge Martín d1fe27c969 sdk: move PinnedEventCache from sdk-ui 2024-08-02 18:54:28 +02:00
Jorge Martín 769a627496 ci: try fixing the kotlin bindings tests by using NDK 27 2024-08-02 17:28:36 +02:00
Timo aff7aefd28 WidgetDriver: don't specify the length of the serializer. Its not needed for the json serializer. 2024-08-02 15:14:09 +01:00
Timo d60b9d3da2 Changelog: Add delayed event to the widget driver.
Also mention the breaking change in the public widget capabilities interface.
2024-08-02 15:14:09 +01:00
Timo 8d5dc18dd3 IntegrationTests: Add integration tests for the WidgetDriver delayed events. 2024-08-02 15:14:09 +01:00
Timo 49790c9f91 WidgetDriver: wire up everything in the widget process action handler. 2024-08-02 15:14:09 +01:00
Timo 2e8b135859 WidgetDriver: Add interacting with delayed event to the matrix driver.
In `matrix.rs` we add methods to interact with the matrix homeserver. And in `machine/mod.rs` we implement the widgetMachine cases for handling (checking capabilities and using the matrixDriver) delayed events.
2024-08-02 15:14:09 +01:00
Timo 7614bfb716 WidgetDriver: Introduce new capabilities for sending and updating delayed events.
Those capabilities are also exposed to the FFI.
+ related tests
2024-08-02 15:14:09 +01:00
Timo 0407dd7eb1 WidgetDriver: Introduce new Delay Event update widget action types.
Also update the naming from `future` to `delay` in existing types.
2024-08-02 15:14:09 +01:00
Timo 16a638400c chore: Update ruma to a version supporting authenticated delayed events. 2024-08-02 15:14:09 +01:00
torrybr be6bc444f8 chore: fix formatting 2024-08-02 15:42:54 +03:00
torrybr 36091a9ef3 sdk: refactor beacon_info tests into their own folder 2024-08-02 15:42:54 +03:00
Stefan Ceriu 1160383d71 sdk: fix identity reset not actually disabling backups when not enabled locally, resulting in conflicts and failing to correctly setup the newly reset session 2024-08-02 15:25:42 +03:00
Stefan Ceriu d7f3914673 sdk: throw an error instead of silently failing when disabling backups if they weren't previously enabled locally
- also change back the state from `disabling` to `unknown`
2024-08-02 15:25:42 +03:00
Jorge Martín 1ca4377baf ffi: add FFI bindings for creating the new pinned events focused timeline 2024-08-02 13:11:24 +02:00
Jorge Martín ab12f2f7ca sdk-ui: add and fix tests 2024-08-02 13:11:24 +02:00
Jorge Martín 6889430474 benchmark: add a benchmark to measure how loading pinned events performs 2024-08-02 13:11:24 +02:00
Jorge Martín 382c573973 sdk-ui: add TimelineFocus::PinnedEvents and TimelineFocusData::PinnedEvents to load the live pinned events for a room.
Add `PinnedEventsLoader` to encapsulate this logic, being able to provide a max number of events to load and how many can be loaded at the same time. Also implement an event cache for it.

 Add `PinnedEventsRoom` trait to use it in the same way as `PaginableRoom`, only for pinned events.
2024-08-02 13:11:24 +02:00
Jorge Martín 643c9a0b8e sdb-base: add methods for getting the pinned event ids of a Room as a stream and checking whether an event is pinned in the room or not 2024-08-02 13:11:24 +02:00
Kévin Commaille 689bf9b4dc base-sdk: Properly update direct targets of rooms with m.direct event
The code used to only add new targets to rooms
but never remove the ones that are not in the event anymore.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-08-02 12:46:37 +02:00
Richard van der Hoff 21efd60dba crypto: clarify/expand comments in Device::is_owner_of_session
I found some of this comment a bit hard to grok, so I've expanded it a
bit. Hope it's clear to others.
2024-08-02 10:04:08 +02:00
Valere 0850c0c1c9 feat(crypto): Add support for master key local pinning (#3639)
This patch ensures that we retain the master key for a given UserIdentityData object, even when a new and different identity arrives via the `/keys/query` endpoint. This concept, called pinning, is similar to certificate pinning in web browsers.

Retaining the master key allows us to detect changes and notify the user accordingly.
2024-08-02 09:13:14 +02:00
Doug aee8728418 sdk-ui: Fix a bug where local echoes were showing unencrypted shields. 2024-08-01 14:28:33 +03:00
Kevin Boos 7c5c5a8f30 timeline: re-export ReactionsByKeyBySender and ReactionInfo types (#3787)
This tiny change allows one to easily name the return type of
`EventTimelineItem::reactions()` such that you can use it in a function
signature. Same goes for the `ReactionInfo` type.

I think this was likely just a small oversight in recent changes to the
reactions API, so hopefully it's not controversial.

Without this, it's impossible to write a function that uses
`ReactionsByKeyBySender` or `ReactionInfo` in the signature.

Signed-off-by: Kevin Boos <kevinaboos@gmail.com>
2024-08-01 11:37:16 +01:00
Stefan Ceriu bfa069d6c0 Merge pull request #3783 from matrix-org/doug/sent-in-clear
UI Timeline: Build a ShieldState for an unencrypted event in an encrypted room.
2024-08-01 11:47:52 +03:00
Doug de502f42c6 chore: Add docs & todo on EventTimelineItem::from_latest_event 2024-07-31 19:08:31 +01:00
Doug dc1a34cd56 chore: Fix tests. 2024-07-31 15:51:40 +01:00
Doug 11a26d7fc4 chore: Make the room encryption state optional on timeline items. 2024-07-31 14:45:00 +01:00
Doug 1abbaa8607 ui: Add tests for Sent In Clear shield. 2024-07-31 13:06:36 +01:00
Doug bae0f304f7 ui: Add a ShieldState for "Sent in clear". 2024-07-31 13:06:36 +01:00
Andy Balaam 25df9a11c5 crypto: Rename OlmMachine::get_or_update_verification_state 2024-07-31 12:27:30 +01:00
Andy Balaam 1f937278b2 crypto: Store the updated SenderData in the store when we calculate it 2024-07-31 12:27:30 +01:00
Andy Balaam e2ff2daf5d crypto: Extract a function to convert SenderData->VerificationState 2024-07-31 12:27:30 +01:00
Damir Jelić 8760ea8440 chore: Update the bytemuck crate 2024-07-31 10:40:23 +02:00
Andy Balaam d03d3cff17 crypto: Remove unused retry_details from SenderData 2024-07-30 14:34:23 +01:00
Andy Balaam f88c6dff4d crypto: Use SenderDataFinder to implement get_verification_state
This avoids repeating equivalent code.
2024-07-30 13:50:58 +01:00
Andy Balaam d3835bb992 crypto: Return an error if is_owner_of_session fails 2024-07-30 13:50:58 +01:00
Andy Balaam 93a0fe500b crypto: Provide specific error types for SenderDataFinder 2024-07-30 13:50:58 +01:00
Andy Balaam 1f369c5912 crypto: Support a mismatched identity variant in session creation errors 2024-07-30 13:50:58 +01:00
Andy Balaam 2289c813f1 crypto: Allow testing SenderDataFinder with imported sessions 2024-07-30 13:50:58 +01:00
Andy Balaam 0a9431d01d crypto: Do not provide device ID to EncryptionInfo when device is not the owner 2024-07-30 13:50:58 +01:00
Stefan Ceriu f51eebb55f Merge pull request #3759 from matrix-org/stefan/crypto-identity-reset
ffi: add high level method for resetting the user's identity and deleting all associated secrets
2024-07-30 13:29:01 +03:00
Stefan Ceriu 8895e532bb Handle the situation where the backend skips user interactive authentication
- disable backups and recovery before requesting the reset handle
- attempt device key upload
- re-enable backups both when UIAA is required and when not
2024-07-30 13:13:26 +03:00
Richard van der Hoff 40e3a96ae3 Make message-ids feature the default (#3776)
The feature is now a no-op.

Will fix (I hope)
https://github.com/element-hq/element-android/issues/8872
2024-07-30 10:49:21 +01:00
Stefan Ceriu 8fe2b37354 ffi: Expose identity reset mechanism 2024-07-29 16:52:03 +03:00
Stefan Ceriu db064626fa sdk: Add high level method for resetting the user's identity and deleting all associated secrets 2024-07-29 16:52:03 +03:00
Andy Balaam 0b46a7e29c crypto: Make the return type of is_owner_of_session more specific 2024-07-29 14:50:22 +01:00
Andy Balaam 449e8b40b8 crypto: Extract a new error type: MismatchedIdentityKeysError 2024-07-29 14:50:22 +01:00
Andy Balaam d7224a7ede crypto: Store device_id in SenderData
This means we have all the information inside SenderData to populate
VerificationStatus and DeviceId for EncryptionInfo, so we can share the
code between SenderDataFinder and get_verification_state.
2024-07-29 11:11:44 +01:00
Jorge Martin Espinosa e0833110f2 Merge pull request #3771 from torrybr/feat/send-beacon
sdk: basic support for sending location beacons
2024-07-29 09:47:55 +02:00
torrybr 3756eeb385 test: move beacon tests into own file 2024-07-26 23:55:19 -04:00
torrybr dd252937c1 test: verify test_send_location_beacon_with_expired_live_share 2024-07-26 23:18:12 -04:00
torrybr ab6d039369 sdk: basic support for sending live location beacons 2024-07-26 22:57:16 -04:00
Jorge Martín 6fca1e81ed ffi: expose pin_event and unpin_event, also the currently pinned event ids in RoomInfo 2024-07-26 14:20:53 +01:00
Jorge Martín ab0494549e sdk-ui: add Timeline::pin_event and Timeline::unpin_event 2024-07-26 14:20:53 +01:00
Jorge Martín 15bf675e5e sdk-base: add Member::can_pin_or_unpin_event 2024-07-26 14:20:53 +01:00
Jorge Martín 95637c57da ffi: expose Room::can_user_pin_unpin check 2024-07-26 14:20:53 +01:00
Jorge Martín 8f90a76cb4 sdk: Add Room::can_user_pin_unpin check 2024-07-26 14:20:53 +01:00
Andy Balaam 844923dd44 crypto: Make TestOptions a builder 2024-07-26 12:47:41 +01:00
Andy Balaam 9efc6494d1 crypto: Check the device owns the session in SenderDataFinder
and add a flag to the SenderData struct to store the fact that this
check failed if it did.
2024-07-26 12:47:41 +01:00
Andy Balaam 5191737389 crypto: Require passing a session when we find SenderData 2024-07-26 12:47:41 +01:00
Damir Jelić 4fdc78f565 doc: Shorten one of our doc examples 2024-07-26 13:29:37 +02:00
torrybr 5bbe022e97 sdk: basic support for sending and stopping live location shares 2024-07-26 10:17:50 +01:00
Stefan Ceriu 6faf3f75e0 Merge pull request #3766 from matrix-org/update-dco
update DCO
2024-07-26 08:39:21 +03:00
Josh Simmons 38e842fc0f update DCO 2024-07-25 14:31:32 -07:00
Benjamin Bouvier 73759fc361 sdk-base: enable the "rand" feature on ruma there too 2024-07-25 15:20:34 +02:00
Benjamin Bouvier c1fda3a601 send queue: use the transaction id generated and saved in the db for network queries
Intense facepalm energy here.
2024-07-25 15:20:34 +02:00
Benjamin Bouvier 689f006c07 send queue: get rid of all the non-canonical events after canonicalization 2024-07-25 15:20:34 +02:00
Benjamin Bouvier 6f0da7e91b send queue: canonicalize dependent events keyed by parent transaction id 2024-07-25 15:20:34 +02:00
Benjamin Bouvier ce68ad4968 state store: add a transparent newtype ChildTransactionId to help distinguish the parent from the child transaction id 2024-07-25 15:20:34 +02:00
Benjamin Bouvier 02a929c614 timeline: flatten ReactionSenderData into PendingReaction 2024-07-25 15:13:23 +02:00
Benjamin Bouvier 7a660749ed timeline: map from the reaction local-or-remote id to the item it's reacting to 2024-07-25 15:13:23 +02:00
Benjamin Bouvier 6e82e4f14f timeline: store pending reactions without the indirection to Reactions::map 2024-07-25 15:13:23 +02:00
Benjamin Bouvier f0015bb10d timeline: store reaction by key by sender, instead of by key by local or remote id
This makes it impossible to represent states like "there's a local *and*
a remote echo for the same sender for a given reaction", or multiple
reactions from the same sender to the same event, and so on.
2024-07-25 15:13:23 +02:00
Benjamin Bouvier aa4f606171 timeline: reorganize handle_reaction 2024-07-25 15:13:23 +02:00
Benjamin Bouvier 3a386121a1 timeline: remove Deref for ReactionGroup 2024-07-25 15:13:23 +02:00
Benjamin Bouvier 3d40a5c30c ffi: remove the Reaction::count field
It's exactly the same as `Reaction::senders`'s length.
2024-07-25 15:13:23 +02:00
Benjamin Bouvier 4c76255689 timeline: move reaction-related structs to the reaction module, move meta's reaction fields to the Reactions object
No changes in functionality, pure code motion.
2024-07-25 15:13:23 +02:00
Benjamin Bouvier 37d9fa784a timeline: clear more things in TimelineInnerMetadata when clearing the timeline 2024-07-25 15:13:23 +02:00
Benjamin Bouvier fa1cf32883 timeline: move the clearing of TimelineInnerMetadata to its own function 2024-07-25 15:13:23 +02:00
Benjamin Bouvier 002767a146 timeline: move the removal of reactions to pending_reactions 2024-07-25 15:13:23 +02:00
Benjamin Bouvier 5cd4462d27 dependencies: get rid of custom fork of openidconnect-rs
There's a published 4.0.0-alpha.2 version that compiles and doesn't
require the custom changes we needed.

Part of #3742.
2024-07-25 13:14:26 +02:00
Benjamin Bouvier 2eb6930988 send queue: add an own transaction id for dependent events
The previously named `transaction_id` is also renamed to
`parent_transaction_id` to make it clearer.
2024-07-24 17:54:25 +02:00
Benjamin Bouvier 0246863af3 send queue: make use of dependent events to remember an intent to edit/redact an event
This should get rid of most of the race conditions while
editing/redacting an event, and this paves the way for sending reactions
via the send queue.
2024-07-24 17:54:25 +02:00
Benjamin Bouvier d973fef280 send queue: add QueueStorage::client() helper method 2024-07-24 17:54:25 +02:00
Benjamin Bouvier 54c6f0517f send queue: canonicalize multiple dependent events into a more restricted list 2024-07-24 17:54:25 +02:00
Benjamin Bouvier 9a7f18c62c state store: add dependent queued events tables and operations 2024-07-24 17:54:25 +02:00
Damir Jelić f0ef37efae tests: Add tests for the cross-signing reset 2024-07-24 11:03:54 +02:00
Damir Jelić d9e91344aa examples: Update the cross-signing bootstrap example to use the new method 2024-07-24 11:03:54 +02:00
Damir Jelić 4883f3fa77 examples: Add a reset-cross-signing command to the oidc example 2024-07-24 11:03:54 +02:00
Damir Jelić 0d00bda0c6 encryption: Add a method to reset cross-signing keys 2024-07-24 11:03:54 +02:00
Damir Jelić 947a1b1aeb sdk: Refactor the way we determine which HTTP error is permannent 2024-07-24 11:03:54 +02:00
Andy Balaam ece0c6d703 crypto: Simplify error types in SenderDataFinder
Remove `Result` where it is not needed, and switch to `CryptoStoreError`
instead of `OlmError` where possible. Soon, this will allow us to call
some of these methods from places that don't know about `OlmError`.
2024-07-24 07:52:46 +01:00
Jorge Martín 79010af9e2 sdk-base: add pinned events to BaseRoomInfo to keep track of them.
Also add `Room::pinned_events(&self)` to get the current pinned events at any time.
2024-07-23 17:19:53 +02:00
Andy Balaam 99da0ff18d crypto: Simplify the interface of search_for_device 2024-07-23 15:03:19 +01:00
Andy Balaam 2045b326b9 crypto: Re-use existing get_device_from_curve_key method
These calls are equivalent because the old code called
`self.get_user_devices` with a `timeout` of `None`, which meant the call
to `wait_if_user_pending` inside was a no-op.
2024-07-23 14:56:47 +01:00
Doug dfdea0cb2e sdk: Ignore the sliding sync proxy value when using SSS.
Update crates/matrix-sdk/src/client/builder.rs

Co-authored-by: Benjamin Bouvier <public@benj.me>
Signed-off-by: Doug <6060466+pixlwave@users.noreply.github.com>
2024-07-23 11:34:49 +02:00
Doug 56e3780808 ffi: Use the SDK's (tested) logic for overriding the sliding sync proxy. 2024-07-23 11:34:49 +02:00
Benjamin Kampmann 96763aec42 sdk: Add a set_account_data method to the Room struct (#3740)
As it says on the tin. Needed the functions but they were missing. They are analogous to the GlobalAccountData setters.

Signed-off-by: Benjamin Kampmann <ben@acter.global>
2024-07-23 10:34:49 +02:00
Benjamin Bouvier 925c5b2233 workspace: update dependencies
Fixes #3744.
2024-07-22 15:01:06 +02:00
Benjamin Bouvier 5242f647f3 make_reply_event: don't require the event cache to be enabled for the API to work 2024-07-22 12:50:37 +02:00
Benjamin Bouvier ed2ab3ffe6 timeline: rename any_timeline_item_by_txn_id to item_by_transaction_id 2024-07-22 11:32:09 +02:00
Benjamin Bouvier 30c401ac75 timeline: rename item_by_transaction_id to local_item_by_transaction_id 2024-07-22 11:32:09 +02:00
Benjamin Bouvier bbae5364b3 timeline: update comments and error types for Timeline::redact
Yay, one fewer error type for the timeline.
2024-07-22 11:32:09 +02:00
Benjamin Bouvier ec057cf354 timeline: update comments around Timeline::edit 2024-07-22 11:32:09 +02:00
Benjamin Bouvier d4ad2b26cd timeline: remove unused error variants 2024-07-22 11:32:09 +02:00
Benjamin Bouvier 9b1b67fa09 timeline: rationalize edit/abort 2024-07-22 11:32:09 +02:00
Benjamin Bouvier 07f5289e7e release: Update Cargo.lock file 2024-07-22 10:57:25 +02:00
Damir Jelić d65e33ca6a Merge branch '0.7-release' into main 2024-07-19 12:02:40 +02:00
Ivan Enderlin 730d5a3803 fix(base): Fix a bug when an invite has no timestamp.
The sliding sync proxy has a bug: despite the presence of
`m.room.create` in `bump_event_types`, an invite with an `m.room.create`
event will not have a `timestamp`. Thus, such a room cannot be sorted
reliably.

This patch fixes this problem with a terrible hack, where it tries to
find an `origin_server_ts` value from within the `invite_state` state
events.

Please read the comment to learn more.
2024-07-19 11:39:14 +02:00
Ivan Enderlin 23a232e99f fix(base): Add the from_simplified_sliding_sync argument to BaseClien::process_sliding_sync. 2024-07-19 11:39:14 +02:00
Damir Jelić 4f79a15fa9 qrcode: Bump the version 2024-07-19 11:05:14 +02:00
Damir Jelić 11d5e56892 chore: Fix a formatting issue that snuck in while doing a security release 2024-07-18 17:31:55 +02:00
Damir Jelić 8b0d6afe4b Merge branch '0.7-release' into main 2024-07-18 17:26:18 +02:00
Ivan Enderlin 5679a45f75 fix(ui): RoomList reacts to all RoomInfoNotableUpdate.
The `RoomList` provides a `Stream<Item = Vec<VectorDiff<Room>>>`.
This `Stream` receives updates from 2 sources: `RoomList::entries`,
and `Receiver<RoomInfoNotableUpdate>`. When a `RoomInfo` is
updated, a notable update is emitted and broadcasted. The
`RoomList` was filtering these notable updates by _reasons_ (namely
`RoomInfoNotableUpdateReasons`).

This is great and it's a good idea since we can filter which
`RoomInfoNotableUpdate` will trigger a `RoomList` update. However, too
many _reasons_ were hidden/implicit, and it creates several regressions
because (i) these _reasons_ were implicit, (ii) since the business rules
are not defined, there is no tests for that (not in this SDK, not in
apps like ElementX). It means we discover missing _reasons_ bug after
bug. It's not pleasant.

The reality is: we are in the middle of big changes, mostly with room
list client-side sorting and simplified sliding sync. We want to relax
a little bit. This patch then disable the feature _filter updates by
reasons_. The `RoomList` will update to all `RoomInfoNotableUpdate` for
the moment. We will get back to this optimisation later.
2024-07-18 16:29:45 +02:00
Damir Jelić 76a7052149 crypto: Fix UserIdentity::is_verified to take into account our own identity
The `UserIdentity::is_verified()` method in the matrix-sdk-crypto crate
before version 0.7.2 doesn't take into account the verification status
of the user's own identity while performing the check and may as a result
return a value contrary to what is implied by its name and documentation.

This patch fixes this and adds a regression test.

The method itself is not used internally and as such has not a larger
impact.

Co-authored-by: Denis Kasak <dkasak@termina.org.uk>
Signed-off-by: Damir Jelić <poljar@termina.org.uk>
2024-07-18 16:20:47 +02:00
Ivan Enderlin 2aecf2950d fix(sdk): Add m.room.create to bump_event_types for sliding sync.
This patch updates the `rev` of our `ruma`'s fork to match the latest
commit of our `feat-sss` branch, see
https://github.com/ruma/ruma/commit/f25b3220d0c3ece7720020ed180af4955a855402.
It adds `m.room.create` in the `bump_event_types` of a
`v4::SyncRequestList` (equivalent of a `v5::request::List`).
2024-07-18 10:43:55 +02:00
Doug 4bbb6bd60c ffi: Don't add a custom SS proxy in ClientBuilder when using SSS. 2024-07-18 09:48:53 +02:00
Doug e37f65c46b ffi: Allow restoring an existing session with SSS enabled. 2024-07-18 09:48:53 +02:00
Doug 92b4c2a469 ffi: Expose client builder method to disable built in CAs. 2024-07-18 09:10:42 +02:00
Doug 20eb1db0f9 sdk: Allow building a Client with the built in CAs disabled. 2024-07-18 09:10:42 +02:00
Damir Jelić 30e95bf992 chore: Use a released version of vodozemac (#3721) 2024-07-17 18:07:39 +02:00
Ivan Enderlin dd20c37f35 doc(sdk): Fix some typos in the documentation. 2024-07-17 16:33:37 +02:00
Ivan Enderlin ea2a27075a feat(ffi,base,ui,sdk): Migrate from sliding sync to simplified sliding sync.
This patch migrates the entire SDK to sliding sync to simplified sliding
sync.
2024-07-17 16:33:37 +02:00
Ivan Enderlin c22de4c035 feat(sdk) Remove delta_token from sliding sync.
Simplified sliding sync doesn't have `delta_token`. This patch removes
it. Note: even the current sliding sync proxy doesn't use it.
2024-07-17 16:33:37 +02:00
Ivan Enderlin f84ce6a34f feat(sdk): Remove sort and bump_event_types from sliding sync.
Simplified sliding sync no longer has `sort` or `bump_event_types`
because they are static values on the implementation/server side. This
patch removes them here.
2024-07-17 16:33:37 +02:00
Ivan Enderlin 508176a2c7 feat(ui): Remove is_tombstoned filter from sliding sync.
Simplified sliding sync no longer has the `is_tombstoned` filter. This
patch removes it.
2024-07-17 16:33:37 +02:00
Ivan Enderlin dc9b975fc0 feat(base): Rename recency_timestamp to recency_stamp.
This patch renames “recency timestamp” to “recency stamp”. It prepares
the fact that simplified sliding sync has a `bump_stamp` instead of a
`timestamp`. The notion of _timestamp_ must be removed.
2024-07-17 16:33:37 +02:00
Ivan Enderlin ea9f79a006 feat(sdk): Remove SlidingSync::unsubscribe_from_room.
Simplified sliding sync no longer has the concept of unsubscribing from
a room. This patch removes this API.
2024-07-17 16:33:37 +02:00
Ivan Enderlin 1b92a034fd feat(sdk) Transform Simplified MSC3575 to MSC3575 in SlidingSync::sync_once.
This patch extracts most of `SlidingSync::sync_once` into a
method named `SlidingSync::send_sync_request`. The name mimics
the `SlidingSync::generate_sync_request` similar method: first we
_generate_, then we _send_.

The `SlidingSync::send_sync_request` is generic over the `Request` and
`::sync_once` passes the correct type depending of whether Simplified
MSC3575 is enabled.
2024-07-17 16:33:37 +02:00
Ivan Enderlin 5a4bf780fb feat(base): Create an http module for sliding_sync.
This patch creates an `http` module containing all the sliding sync types
types (from Simplified MSC3575 or simply MSC3575).
2024-07-17 16:33:37 +02:00
Ivan Enderlin c1a92bb3a9 chore(base): Move sliding_sync into its own module.
This patch moves the `sliding_sync` file into its own module.
2024-07-17 16:33:37 +02:00
Ivan Enderlin e3b950a9f0 feat(client): Add the Client::is_simplified_sliding_sync_enabled field.
This patch is the first over two patches to change the support
of Simplified MSC3575 from a compiler feature flag to a runtime
configuration. This configuration is held by the `Client`.
By default, it's turned off inside `matrix-sdk-ffi` and
`matrix-sdk-integration-testing`, otherwise it's turned on.
2024-07-17 16:33:37 +02:00
Kévin Commaille b79fdefbfd sdk-base: Split code into compute_summary and make less db requests
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-07-17 14:19:53 +02:00
Kévin Commaille e3ad875293 sdk-base: Use left and banned members as heroes as a last resort
As suggested in the spec.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-07-17 14:19:53 +02:00
Kévin Commaille 3f6df64386 sdk-base: Use invited members too when computing heroes locally
The spec is clear that heroes are joined and invited members.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-07-17 14:19:53 +02:00
Kévin Commaille 3bab1c3584 sdk-base: Do not treat left rooms differently than joined rooms
Otherwise they always show up as "Empty" when we don't have a room summary.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-07-17 14:19:53 +02:00
Marco Antonio Alvarez 897f1cfef1 matrix_sdk_base: make sticker events suitable as latest_event (#3715)
Currently on Element X if you receive a sticker in a room, the room list
will show the room as updated but it will show the latest event that is
not a sticker. This change fixes that.

Signed-off-by: 
Marco Antonio Alvarez <surakin@gmail.com>

---------

Signed-off-by: Marco Antonio Alvarez <surakin@gmail.com>
Signed-off-by: Benjamin Bouvier <public@benj.me>
Co-authored-by: Benjamin Bouvier <public@benj.me>
2024-07-17 13:09:48 +02:00
Kévin Commaille 1cc8292034 sdk: Allow to request animated thumbnails (#3710)
New feature from Matrix 1.11.

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

---------

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-07-17 10:18:53 +00:00
Benjamin Bouvier d2c6a83175 sliding sync: only emit the recency_timestamp notable update if it's changed value 2024-07-17 10:32:49 +02:00
Benjamin Bouvier 91f8cfb48c integration tests: handle possibly limited timelines in test_stale_local_echo_time_abort_edit 2024-07-17 10:32:49 +02:00
Benjamin Bouvier 2fde15da79 integration tests: raise test_left_room join timeout a bit 2024-07-17 10:32:49 +02:00
Benjamin Bouvier 9d3fcb9290 room list: add logging explaining why we received an update 2024-07-17 10:32:49 +02:00
Benjamin Bouvier 171e4ef8f8 integration tests: make test_stale_local_echo_time_abort_edit resilient to more races 2024-07-17 10:32:49 +02:00
Benjamin Bouvier 55d0a3cdb8 integration tests: make test_event_with_context wait for as long as it claims
The previous linear backoff would retry overall 10 times the value, and
10x30 == 300ms, not 3 seconds.
2024-07-17 10:32:49 +02:00
Benjamin Bouvier 1f1310c797 integration tests: add a small helper for getting a room with a linear backoff 2024-07-17 10:32:49 +02:00
Benjamin Bouvier c9e2db1fe5 test(sdk): make test_room_info_notable_update_deduplication better 2024-07-17 10:32:49 +02:00
Benjamin Bouvier af469f6bbd Revert "test(integration-testing): Remove a flaky and useless test."
This reverts commit 03e1fd78a6.
2024-07-17 10:32:49 +02:00
Benjamin Bouvier 8a52d6f2a3 notable room updates: have a change to the unread-marker event cause a notable update
Also log out why an account data event couldn't be deserialized.
2024-07-17 10:14:23 +02:00
Andy Balaam 8ebf3c02c6 doc: Remove extra word from a doc comment 2024-07-17 08:11:05 +01:00
Damir Jelić 8fab34cc8c chore: Fix some typos 2024-07-16 20:13:59 +02:00
Damir Jelić 99010ed83b crypto: Get rid of all the read-only mentions
There were some leftovers from the rename of the ReadOnlyDevice and
identity structs. The store still referenced them.

This gets rid of all the mentions and improves the documentation of the
store methods for devices and identities.
2024-07-16 20:13:59 +02:00
Doug 5428339b27 xtask(swift): Put the headers in a module subdirectory.
Fixes a conflict with any other UniFFI library built the same way.
2024-07-16 17:25:15 +02:00
Andy Balaam 942b2f937c logging: Extract debug log code into a separate function.
This reduces the work we do to calculate changed devices etc. when DEBUG
logging is not enabled, but more importantly (to me) it makes clear
that this code is only used for logging.
2024-07-16 16:00:53 +01:00
Andy Balaam 8845550e72 crypto: Calculate sender data for incoming sessions
Part of https://github.com/matrix-org/matrix-rust-sdk/issues/3543.
Builds on top of https://github.com/matrix-org/matrix-rust-sdk/pull/3556

Implements the "fast lane" as described in
https://github.com/matrix-org/matrix-rust-sdk/issues/3544

This will begin to populate `InboundGroupSession`s with the new
`SenderData` struct introduced in
https://github.com/matrix-org/matrix-rust-sdk/pull/3556 but it will only
do it when the information is already available in the store. Future PRs
for this issue will query Matrix APIs using spawned async tasks.

Future issues will do retries and migration of old sessions.

---------

Signed-off-by: Andy Balaam <mail@artificialworlds.net>
Co-authored-by: Damir Jelić <poljar@termina.org.uk>
2024-07-16 13:04:32 +01:00
Damir Jelić 84c9280349 docs: Fix the OIDC QR code login example in the docs 2024-07-16 13:56:45 +02:00
Timo 5dbd5f1adf element call(ffi): add widget permissions for room create and call member state keys with device id (#3706)
It is possible to remove the m.call capability because we now have
merged and released a version that does not request it anymore on
call.element.io

---------

Signed-off-by: Benjamin Bouvier <public@benj.me>
Co-authored-by: Benjamin Bouvier <public@benj.me>
2024-07-16 11:38:48 +00:00
Benjamin Bouvier 1730ec5155 test(sdk): make the test_delayed_decryption_latest_event faster and more robust 2024-07-16 11:30:12 +02:00
Ivan Enderlin 8e65099f3d test(sdk): Rewrite test_delayed_decryption_latest_event.
This patch rewrites the `test_delayed_decryption_latest_event` test a
little bit. It does exactly the same things, but in a simpler way: it
removes multiple `sleep` and remove 2 sliding sync loops.

First off, the `SyncService` already starts the `RoomListService and the
 `EncryptionSync` service. Both of them have their own sliding sync
loop. The test doesn't need other sliding sync loops in their own tasks,
this is not necessary at all: it's just pretty confusing and doesn't
reflect the reality, i.e. how these API are supposed to be used.

Second, it also tests the room for Bob is seen as encrypted.

Third, the `VectorDiff::Reset` is tested before the event from Bob
is sent. It's not only for clarity: it makes the test more robust for
future modifications.

Fourth, instead of waiting with a `sleep` for the event from Bob to be
received by Alice, we instead wait on the room list's stream of Alice to
receive an update. It's more robust this way and reflects the real usage
of this API. It also helps to remove an intermediate `assert_pending!`
that is no longer necessary because we are waiting on the stream just
after.

Finally, just like for the previous modification, this patch removes
another `sleep` for the to-device event from Bob to be received by
Alice, and instead wait on the room list's stream to receive an update.
It's again more robust and reflects the real usage of this API. Plus, it
makes the last `assert_pending!` macro to not be flaky.
2024-07-16 11:30:12 +02:00
Ivan Enderlin 62137e5a3e fix(sdk): SlidingSyncBuilder restores the rooms from the cache.
This patch fixes a bug where rooms stored in the sliding sync cache
aren't restored by the `SlidingSyncBuilder`.

This patch also removes `SlidingSyncBuilder::rooms` fields which was
used but never modified. It's dead code.
2024-07-16 10:34:45 +02:00
Ivan Enderlin 84dfb78e1d test(sdk): Test rooms are restored in the sliding sync cache.
This patch updates a test to ensure that rooms are restored correctly by
the sliding sync cache.

This test fails :-].
2024-07-16 10:34:45 +02:00
Benjamin Bouvier 81d388a55b errors: allow EventCacheError to be a subset of matrix_sdk::Error
This required breaking a type reference cycle, by introducing a box.
2024-07-15 13:49:23 +02:00
Benjamin Bouvier 7b4f480b2a timeline: use Room::make_edit_event instead of doing adhoc edition 2024-07-15 13:49:23 +02:00
Benjamin Bouvier 034bd64e2c sdk: add a Room::make_edit_event() method to create an edit event for a m.room.message 2024-07-15 13:49:23 +02:00
Benjamin Bouvier 328c4767a0 event cache: add RoomEventCache::event() to get an event by id in a single room 2024-07-15 13:49:23 +02:00
Benjamin Bouvier 7a85b7abdc timeline: and yet another red herring warn is removed
Same reason as two commits ago; presence of a transaction id doesn't
mean it's related to the current session.
2024-07-15 10:21:16 +02:00
Benjamin Bouvier 851784c8c0 nit(timeline): remove else after return 2024-07-15 10:21:16 +02:00
Benjamin Bouvier faa961eb7a timeline: remove another red herring
Again, a transaction id received from the remote flow doesn't mean it
corresponds to a local echo sent *this particular session*, so no need
to warn about it.
2024-07-15 10:21:16 +02:00
Benjamin Bouvier a7011d8ac0 ffi: remove lag about timeline reset
We do reset a timeline the first time, to fill the initial items, so
this is a red herring.
2024-07-15 10:21:16 +02:00
Benjamin Bouvier e6525c093f timeline: remove red herring log
This log can happen when an event is received, has a transaction id (in
the data received from sync), and doesn't have a corresponding timeline
item (be it local or remote). There's no reason to warn about this,
because this would happen in most cases, for new incoming events coming
from sync, and this pollutes the logs of rageshakes.
2024-07-15 10:21:16 +02:00
Damir Jelić 57eb225506 chore: Bump our bytes dependency
The version we were using was yanked.
2024-07-15 09:38:31 +02:00
Ivan Enderlin e1a607b6cf Merge pull request #3669 from matrix-org/misc/update-uniffi-to-0.28.0
chore: update UniFFI to `v0.28.0`
2024-07-15 09:11:28 +02:00
Ivan Enderlin 03e1fd78a6 test(integration-testing): Remove a flaky and useless test.
This patch removes the `test_room_info_notable_update_deduplication`
test. First off, it's flaky because sometimes Synapse lags, or sends
another events, which makes the test to fail. Second, the same feature
is tested inside the `matrix_sdk_ui::room_list_service` test suite,
with `test_room_sorting` and `test_room_latest_event`, and inside the
`matrix_sdk_base::sliding_sync` test suite, with a better granularity.
And lastly, this test doesn't test what it says: there is no room info
notable update deduplication whatsoever. I personally don't believe it
has ever existed. This test isn't necessary.
2024-07-12 18:55:34 +02:00
Damir Jelić a5dbfa66a7 encryption: Rename the ReadOnly user identity types 2024-07-12 18:06:34 +02:00
Damir Jelić 6f0d3b663b encryption: Rename ReadOnlyDevice to DeviceData
ReadOnlyDevice is not particularly useful as a description of why we
have two device types. This commit renames it into DeviceData, as this
struct is used to hold the device keys and additional local device data.

I'm not quite sure why it took me so long to come up with a better name.

Please forgive me past readers.
2024-07-12 18:06:34 +02:00
Damir Jelić 9d464eb908 tests: Add a snapshot of a SQLite database to perform regression tests
The test database was created using a slightly modified `oidc-cli`
example, to turn of the database encryption, on commit
d6dca91df86413b0cbf193a4be191835dd81862e
2024-07-12 18:06:34 +02:00
Alexis Métaireau 48f11ea025 Enforce the redundant_clone Clippy lint rule.
Fixes #3683
2024-07-11 15:28:33 +02:00
Valere d9b2b53f83 feat(timeline): Expose shield state for EventTimelineItem (#3679) 2024-07-11 13:18:19 +02:00
Jorge Martin Espinosa 6bcd07fd7b Merge branch 'main' into misc/update-uniffi-to-0.28.0
Signed-off-by: Jorge Martin Espinosa <jorgem@element.io>
2024-07-11 11:27:44 +02:00
Ivan Enderlin bacf85d807 chore: Use anyhow from the workspace. 2024-07-11 11:16:17 +02:00
Ivan Enderlin b163368be0 chore: Use futures-util from the workspace. 2024-07-11 11:16:17 +02:00
Ivan Enderlin 5ebfd7bc55 chore: Use tokio from the workspace. 2024-07-11 11:16:17 +02:00
Ivan Enderlin 0d264d209f chore: Use tracing-subscriber from the workspace. 2024-07-11 11:16:17 +02:00
Ivan Enderlin ea8628e210 chore(labs): multiverse uses tokio from the workspace. 2024-07-11 11:16:17 +02:00
Timo f4078fdf68 widget-driver: rename all mentions of future in the context of future events.
We need to disambigute future events and rust futures.
2024-07-10 18:27:53 +02:00
Timo c366bae428 widget_driver: doc and test changes (review) 2024-07-10 18:27:53 +02:00
Timo cf1ec862c2 changelog: add future events to the widget-driver/api. 2024-07-10 18:27:53 +02:00
Timo 10db61575f widget-driver: add integration test for future events. 2024-07-10 18:27:53 +02:00
Timo 2e936702c8 widget-driver: Fix widget action format and add test. 2024-07-10 18:27:53 +02:00
Timo 5922fb8ff3 widget-driver: add tests for future events in widget send action. 2024-07-10 18:27:53 +02:00
Timo f6c2a28682 widget-driver: Support for sending futures events through the widget api. 2024-07-10 18:27:53 +02:00
Benjamin Bouvier 6ee2919576 event cache: add EventCache::event() to get an event by id 2024-07-10 17:43:11 +02:00
Benjamin Bouvier b0f60d2bf7 event cache: remove allow(dead_code) and remove dead code 2024-07-10 17:43:11 +02:00
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
Jorge Martín 3d9bdd2bb4 chore: update UniFFI to v0.28.0 2024-07-09 11:23:20 +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
Jorge Martín ad4d24f7d0 ffi: remove is_encrypted field from RoomInfo
It turns out this will cause a network request if the encryption info hasn't been loaded before, which is the case for opening a client in offline mode. It will slow down displaying the room list or loading the room info in general.
2024-07-04 13:52:27 +02:00
Ivan Enderlin 66743f5e57 Merge pull request #3654 from Hywan/fix-complement-crypto
test(crypto): Restore Complement crypto since it's been updated
2024-07-04 13:34:59 +02:00
Andy Balaam 03d4a30eb4 crypto: Move device_keys to DecryptedOlmV1Event as per MSC4147 2024-07-04 11:22:38 +01:00
Ivan Enderlin a82a1f505e test(crypto): Restore Complement crypto since it's been updated.
This patch restores Complement crypto since it's been updated to the
latest version of the Rust SDK.
2024-07-04 12:00:12 +02:00
Richard van der Hoff 98e9abd6c9 indexeddb: tests for new schema migration 2024-07-04 09:10:21 +01:00
Richard van der Hoff 2a8e8c1fff indexeddb: improve docs and tests 2024-07-04 09:10:21 +01:00
Ivan Enderlin 9aa277405d Merge pull request #3653 from matrix-org/jme/verify-android-bindings-build-fine
ci: Verify Android bindings build fine
2024-07-04 10:02:06 +02:00
Jorge Martín 3be5311113 ci: Verify Android bindings build fine 2024-07-04 09:40:26 +02:00
Ivan Enderlin a957e70698 Merge pull request #3646 from Hywan/feat-ui-room-list-roominfo-update
feat(ui): Trigger room list update only when necessary
2024-07-03 21:16:06 +02:00
Ivan Enderlin 77feed2447 test: Fix flakyness. 2024-07-03 20:56:23 +02:00
Richard van der Hoff 7b25a1c2f0 indexeddb: update changelog 2024-07-03 19:43:44 +01:00
Richard van der Hoff bb0e50ce02 indexeddb: migrate name and format of backup_version
The name was stupid, and this was the only string that was stored in the legacy
format; we can fix both problems with a cheeky migration.
2024-07-03 19:41:49 +01:00
Richard van der Hoff ab3ea8c467 indexeddb: Improve handling of legacy values in deserialize_value
Turns out legacy unencrypted objects can take many forms, and we need to be
tolerant of them.

Also expose `deserialize_legacy_value` as a separate function, because we're
going to need to special-case it.
2024-07-03 19:05:33 +01:00
Benjamin Bouvier 6679caecf9 ffi: add doc comments to TracingFileConfiguration and TracingConfiguration 2024-07-03 19:14:44 +02:00
Richard van der Hoff 885b2b22bd indexeddb: Revert change from into_serde to serde_wasm_bindgen::from_value
Turns out that `serde_wasm_bindgen` isn't happy with some input. Haven't
figured out why, yet.
2024-07-03 17:59:37 +01:00
Valere d8b2b74a2d feat(sdk-crypto): Add Identity based room key sharing strategy (#3607)
This sharing strategy is defined as part of MSC4153[1].

[1]: https://github.com/matrix-org/matrix-spec-proposals/pull/4153
2024-07-03 16:18:10 +02:00
Ivan Enderlin 76caf7ed05 feat(ui): Trigger room list update only when necessary.
This patch revisits the need to trigger a room list update for
all changes of `RoomInfo`. For the moment, it reduces the scope to
`recency_timestamp` update.

This patch comes with a test to ensure things work as expected.
2024-07-03 16:07:27 +02:00
Benjamin Bouvier cdc3743888 timeline: when aborting fails on a local echo, retry on the matching remote echo 2024-07-03 16:03:13 +02:00
Benjamin Bouvier 9b97a2ed26 timeline: when an edit fails on a stale local echo, retry on the matching remote echo 2024-07-03 16:03:13 +02:00
Benjamin Bouvier aff07c13fc timeline: add integration test showing the issue with editing or aborting with a stale local echo 2024-07-03 16:03:13 +02:00
Benjamin Bouvier 9260942c5d integration testing: rename reactions.rs to timeline.rs 2024-07-03 16:03:13 +02:00
Richard van der Hoff c4413c6ac3 Merge pull request #3645 from matrix-org/rav/indexeddb_storage_efficiency
Indexeddb: more efficient serialization format
2024-07-03 14:37:05 +01:00
Richard van der Hoff 4d12a78341 indexeddb: remove redundant ? operators
Now that `deserialize_value` returns an `IndexeddbCryptoStoreError`, we don't
need these any more.
2024-07-03 14:10:57 +01:00
Richard van der Hoff a6dce1c0d7 Merge remote-tracking branch 'origin/main' into rav/indexeddb_storage_efficiency 2024-07-03 14:10:56 +01:00
Richard van der Hoff 09d53a52ad indexeddb: changelog 2024-07-03 14:10:35 +01:00
Richard van der Hoff 6d46e35d50 indexeddb: Make serialize_value a wrapper for maybe_encrypt_value
... and make `deserialize_value` handle both the old and new formats.

`maybe_encrypt_value` uses a much more efficient representation, so let's
migrate to that.
2024-07-03 14:10:29 +01:00
Richard van der Hoff 87653da2e3 indexeddb: Inline a call to IndexeddbSerializer::serialize_value
I'm going to change the behaviour of `serialize_value`, and we want to preserve
the behaviour of this test.
2024-07-03 14:10:29 +01:00
Richard van der Hoff a38eaf08be indexeddb: Add some tests for IndexeddbSerializer 2024-07-03 14:10:16 +01:00
Richard van der Hoff 786015f18c indexeddb: Make maybe_en/decrypt_value generic 2024-07-03 14:10:10 +01:00
Richard van der Hoff d60ec55e30 Crypto store: clear db before integ tests (#3644)
It's currently possible for integ test results to leak from one test run to the
next (for example, the indexeddb stores hang around in the browser), causing
bad test results.

Extend the test setup routine to clear out the store before the test starts.
2024-07-03 13:39:54 +01:00
Ivan Enderlin 99e284d8b0 Merge pull request #3585 from Hywan/feat-roomlist-sorting-2
feat(ui): Client-side sorting in `RoomList`
2024-07-03 13:07:00 +02:00
Ivan Enderlin 3588b88303 chore(base): Remove LatestEvent::cached_event_origin_ts.
This patch removes the `LatestEvent::cached_event_origin_ts`.
It's no longer necessary to cache this value as the
`matrix_sdk_ui::room_list_service::sorter::recency` sorter no longer
uses it.
2024-07-03 12:23:11 +02:00
Ivan Enderlin b4bbb10ba5 feat(ui): The recency sorter now uses recency_timestamp.
This patch changes the `recency` sorter to use `Room::recency_timestamp`
instead of `LatestEvent::event_origin_server_ts` to sort rooms.
2024-07-03 12:23:11 +02:00
Ivan Enderlin 9a02d6877f feat(base): Store the timestamp from SS in RoomInfo::recency_timestamp.
This patch adds a new field in `RoomInfo`: `recency_timestamp:
Option<MilliSecondsSinceUnixEpoch>>`. Its value comes from a Sliding
Sync Room response, that's why all this API is behind `cfg(feature =
"experimental-sliding-sync")`.
2024-07-03 12:06:08 +02:00
Benjamin Bouvier 10fd5d0ff6 sdk: don't clobber the DM list if we failed to deserialize the previous m.direct event
Report a deserialization failure and do not mark the room as a DM,
instead of incorrectly restarting from an empty DM list.

Fixes #3410.
2024-07-03 12:00:54 +02:00
Benjamin Bouvier 2be846669e multiverse: add Events view
This allows seeing the events directly from the room event cache. I'm
hoping this will give us some interesting insights about duplicates,
among other things.
2024-07-03 11:30:52 +02:00
Benjamin Bouvier 02b095491d integration tests: simplify maintaining temp directories alive 2024-07-03 11:30:42 +02:00
Benjamin Bouvier 68670baa30 integration test: common out the first bits of ClientBuilder creation in TestClientBuilder
DRY.
2024-07-03 11:30:42 +02:00
Benjamin Bouvier 664c71b822 integration tests: make randomize_username() the default
Most tests would randomize the username when creating a
`TestClientBuilder`; make it the default, since it's a sensible choice,
and avoids interference between different tests / test runs.

A single test required an actual non-randomized username, so a specific
way to opt out from this new default behavior has been introduced.
2024-07-03 11:30:42 +02:00
Richard van der Hoff 5d716f969d Stores: Remove StoreCipher::{en,de}crypt_value_[base64_]typed (#3638)
* Use `IndexeddbSerializer` more widely in test code

reuse `IndexeddbSerializer::maybe_encrypt_value` instead of re-inventing it.

* Rewrite `StoreCipher::decrypt_value_base64_typed`

Instead of un-base64-ing and calling `decrypt_value_typed` (which deserializes
the result`), call `decrypt_value_base64_data` (which un-base64s before
decrypting but does not deserialize the result), then deserialize.

This makes it more symmetrical with `encrypt_value_base64_typed`, and helps me
get rid of `decrypt_value_typed` (which is barely used.)

* Fix docs on `StoreCipher::encrypt_value_base64_typed`

looks like they got C&Ped from `encrypt_value_typed`.

* Inline `StoreCipher::{encrypt,decrypt}_value_typed`

Each of these are quite simple, are only used in two places, and their
existence melts my brain.

* Rewrite `IndexeddbSerializer::maybe_{encrypt,decrypt}_value`

... to use `en/decrypt_value_base64_data` instead of
`en/decrypt_value_base64_typed`.

We have to have the de/serialization code for the unencrypted case anyway, so
using the higher-level method isn't helping us much.

* Remove unused `StoreCipher::{en,de}crypt_value_base64_typed`

Outside of tests, these things are totally unused.
2024-07-03 09:42:45 +01:00
Ivan Enderlin 765b95468a !fixup Remove useless comment. 2024-07-03 09:54:13 +02:00
Ivan Enderlin 813ce6a14d test(ui): Assert the roominfo updates. 2024-07-03 09:54:12 +02:00
Ivan Enderlin 5d68f89372 chore(ui): Remove the RoomListService::rooms cache.
This patch removes the `RoomListService::rooms` cache, since now a
`Room` is pretty cheap to build.

This cache was also used to keep the `Timeline` alive, but it's now
recommended that the consumer of the `Room` keeps its own clone of the
`Timeline` somewhere. We may introduce a cache inside `RoomListService`
for the `Timeline` later.
2024-07-03 09:54:12 +02:00
Ivan Enderlin b525002828 fix(ui): merge_stream_and_receiver gives priority to raw_stream.
This patch rewrites `merge_stream_and_receiver` to switch the order
of `roominfo_update_recv` and `raw_stream`. The idea is to give the
priority to `raw_stream` since it will necessarily trigger the room
items recomputation.

This patch also remove the `for` loop with `Iterator::enumerate`, to
simply use `Iterator::position`: it's more compact and it removes a
`break` (it makes the code simpler to understand).

Finally, this patch renames `merged_stream` into `merged_streams`.
2024-07-03 09:54:12 +02:00
Ivan Enderlin ab190ad29c test: Disable Complement.
Complement uses the FFI `RoomList` API. Since the patch set modifies
this API, Complement is broken. We disable it and will re-enable it once
we have updated Complement.
2024-07-03 09:20:25 +02:00
Ivan Enderlin 76477281c2 chore(labs): multiverse uses RoomList::entries_with_dynamic_controllers. 2024-07-03 09:20:25 +02:00
Ivan Enderlin 2c25103226 chore(labs): Update multiverse to the latest RoomList version. 2024-07-03 09:20:24 +02:00
Ivan Enderlin 606a1510cf feat(ffi) Update RoomList API to the recent changes.
This patch adapts the `RoomList` FFI API to the recent changes to
suport a `Stream<Item = RoomListItem>` instead of a `Stream<Item =
RoomListEntry>`. Behind the scene, it supports client side sorting for
the rooms but this is transparent for this API.

This patch also removes the `RoomListInput` enum as no input is
supporter anymore.

The `entries` method no long returns a `RoomListEntriesResult` but
directly a `TaskHandle`. The given listener will receive the initial
entries as a `VectorDiff::Append`, which first is simpler but also fixe
a potential race condition bug.
2024-07-03 09:20:07 +02:00
Ivan Enderlin ed086afe83 test(ui): Update tests of the RoomList with sorters.
This patch mostly tests that sorting the rooms in the room list by
recency and by name works as expected.
2024-07-03 09:20:07 +02:00
Ivan Enderlin 51ca5a7113 feat(ui) Rename RoomList' sorter or to lexicographic.
This patch renames the `or` sorter to `lexicographic` as it describes
better what it does.
2024-07-03 09:20:07 +02:00
Ivan Enderlin ff4af894e4 feat(ui): The RoomList uses sorters!
This patch “installs” the sorters API for the `RoomList`.
2024-07-03 09:19:27 +02:00
Ivan Enderlin ec80c6ff7b feat(ui): Add the recency, name and or sorters for the RoomList.
This patch adds 3 sorters for the `RoomList`: `recency`, `name` and
`or`.
2024-07-03 09:18:23 +02:00
Ivan Enderlin daf878fa7f feat(base): Add LatestEvent::cached_event_origin_server_ts.
This patch adds a new `cached_event_origin_server_ts` field on
`LatestEvent`, which is a copy of the `origin_server_ts` of the inner
`SyncTimelineEvent`.
2024-07-03 09:17:49 +02:00
Ivan Enderlin 7aa7d1ca53 feat(ui): Remove visible_rooms from RoomListService.
This patch removes the `visible_rooms` sliding sync list from
`RoomListService`. As we are taking the path of doing client-side
sorting, the ordering of the server-side will most likely always
mismatch the ordering of the client-side, thus using `visible_rooms`
with room indices make no sense (indices from server-side won't map
indices on the client-side, so room ranges from client-side won't map
what the server knows).

We used to use `visible_rooms` to “preload” the timeline of rooms in
the user app viewport, with a `timeline_limit` of 20. This should be
replaced by room subscriptions starting from now. For the moment, the
user of `RoomListService` is responsible to do that manually. Maybe
`RoomListService` will handle that automatically in the future.
2024-07-03 09:17:28 +02:00
Kegan Dougal 09dc9b913d base: Add trace logging to memory store (#3642)
* Add trace logging to memory store

To help debug https://github.com/matrix-org/complement-crypto/issues/77

* Missing import
* Review comments
2024-07-02 16:20:53 +00:00
Kévin Commaille 0a7184e594 ui: Implement Clone for RepliedToInfo
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-07-02 16:58:48 +02:00
Kévin Commaille 14c8a96f55 ui: Expose identifier or RepliedToInfo and EditInfo
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-07-02 16:58:48 +02:00
Benjamin Bouvier fbeb77ae3e sdk-store-encryption: use ZeroizeOnDrop instead of [zeroize(drop)]
One item of https://github.com/matrix-org/matrix-rust-sdk/issues/3272.
2024-07-02 14:33:19 +02:00
Benjamin Bouvier a1b557b20a ffi(client builder): reduce indent in build_with_qr_code using a let else statement
No functional changes.
2024-07-02 14:05:09 +02:00
Benjamin Bouvier b8fc5f4764 ffi(client builder): inline build_inner into its one caller
No functional changes.
2024-07-02 14:05:09 +02:00
Benjamin Bouvier d531a7cc01 ffi(client builder): inline enable_cross_process_refresh_lock_inner into its one caller
No functional changes.
2024-07-02 14:05:09 +02:00
Benjamin Bouvier 84a57ce690 ffi(client builder): remove unused inner field from the builder 2024-07-02 14:05:09 +02:00
Benjamin Bouvier 263c86b508 send queue: use being_sent as a lock for touching storage
There were two disconnected sources of truth for the state of event to
be sent:

- it can or cannot be in the in-memory `being_sent` map
- it can or cannot be in the database

Unfortunately, this led to subtle race conditions when it comes to
editing/aborting. The following sequence of operations was possible:

- try to send an event: a local echo is added to storage, but it's not
marked as being sent yet
- the task wakes up, finds the local echo in the storage,...
- try to edit/abort the event: the event is not marked as being sent
yet, so we think we can edit/abort it
- ... having found the local echo, it is marked as being sent.

This would result in the event misleadlingly not being aborted/edited,
while it should have been.

Now, there's already a lock on the `being_sent` map, so we can hold onto
it while we're touching storage, making sure that there aren't two
callers trying to manipulate storage *and* `being_sent` at the same
time.

This is pretty tricky to test properly, since this requires super
precise timing control over the state store, so there's no test for
this. I can confirm this avoids some weirdness I observed with
`multiverse` though.
2024-07-01 16:19:48 +02:00
Benjamin Bouvier 2f125e97ee send queue: make SendHandle::abort/update more precise
Using `SendHandle::abort()` after the event has been sent would look
like a successful abort of the event, while it's not the case; this
fixes this by having the state store backends return whether they've
touched an entry in the database.
2024-07-01 16:19:48 +02:00
Benjamin Bouvier 16aa6df0b8 timeline: update test expectation after previous bugfix 2024-07-01 15:44:09 +02:00
Benjamin Bouvier 96422b3c32 send queue: wake up the sending task after editing an event
It could be that the last event in a room's send queue has been marked
as wedged. In that case, the task will sleep until it's notified again.
If the event is being edited, then nothing would wake up the task; a
manual wakeup might be required in that case.

The new integration test shows the issue; the last `assert_update` would
fail with a timeout before this patch.
2024-07-01 15:44:09 +02:00
Damir Jelić eac20766bd fixup! fix(crypto): Rename the device keys property for Olm messages 2024-07-01 15:19:04 +02:00
Damir Jelić 53cdac9661 fix(crypto): Rename the device keys property for Olm messages
Commit d41af396c implemented MSC4147, which puts the device keys into a
Olm message. It failed to adhere to the unstable prefix proposed in the
MSC:

> Until this MSC is accepted, the new property should be named
> org.matrix.msc4147.device_keys.

This patch fixes this.
2024-07-01 15:19:04 +02:00
Andy Balaam 1de3d16d25 Merge pull request #3629 from matrix-org/andybalaam/typos-specific-exceptions
typos: Exclude specific words from typo checking instead of whole files
2024-07-01 14:00:55 +01:00
Andy Balaam 858150b6b6 typos: Exclude specific words from typo checking instead of whole files 2024-07-01 13:40:52 +01:00
Damir Jelić a34e19617a recovery: Ensure that we don't miss updates to the backup state
This patch switches the way we update the recovery state upon changes in
the backup state. Previously two places updated the recovery state after
the backup state changed:

    1. A method living in the recovery subsystem that the backup
       subsystem itself calls.
    2. An event handler which is called when we receive a m.secret.send
       event.

The first method is a hack because it introduces a circular dependency
between the recovery and backup subsystems.

More importantly, the second method can miss updates, because the backup
subsystem has a similar event handler which then processes the secret we
received and if the secret was a backup recovery key, enables backups.

Depending on the order these event handlers are called, the recovery
subsystem might update the recovery state before the secret has been
handled.

The backup subsystem provides an async stream which broadcasts updates
to the backup state, letting the recovery subsystem listen to this
stream and update its state if we notice such updates fixes both
problems we listed above. The method in the first bullet point was
completely removed, the event handler is kept for other secret types but
we don't rely on it for the backup state anymore.
2024-07-01 14:38:26 +02:00
Damir Jelić 9e4164f6f7 encryption: Log when the backup and recovery state changes 2024-07-01 14:38:26 +02:00
Damir Jelić a819dd568d utils: Return the old value in the set method of ChannelObservable 2024-07-01 14:38:26 +02:00
Kévin Commaille 7fee66da11 ui: Rename EventItemIdentifier to TimelineEventItemId
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-07-01 14:32:16 +02:00
Kévin Commaille 9f929f7670 ui: Docs fixes
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-07-01 14:32:16 +02:00
Kévin Commaille b9d0aa9b54 ui: Expose content of RepliedToInfo and EditInfo
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-07-01 14:32:16 +02:00
Kévin Commaille f0867262c7 ui: Get rid of TimelineEventItemId
There is EventItemIdentifier for the same purpose.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-07-01 14:32:16 +02:00
Benjamin Bouvier 2507a450df send queue: add useful logs when aborting/editing a local echo 2024-07-01 14:12:44 +02:00
Kévin Commaille a7e4849f25 sdk: Use strongly-typed strings where it makes sense
Where a string is clearly documented as a room ID, event ID or mxc URI,
use OwnedRoomId, OwnedEventId and OwnedMxcURI, respectively.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-07-01 12:55:15 +02:00
Damir Jelić 769fe8bb7d ci: Add a github workflow to fail when fixup commits exist
We tend to use fixup commits quite a bit, and in the heat of the moment
we sometimes forget to squash them before the final merge.

This should prevent us from doing so.
2024-07-01 12:30:02 +02:00
Benjamin Bouvier 52fa00e474 sdk: remove Error::InconsistentState as it was unused 2024-07-01 08:57:09 +02:00
Benjamin Bouvier 17d18321f2 send queue: mark ConcurrentRequestFailed as recoverable
This will still disable the room's send queue, but the embedder may then
decide whether to re-enable the queue or not, based on network
connectivity. Ideally, we'd implement some retry mechanism here too, but
since we're at a different layer than the HTTP one, we can't get that
"for free", so let the embedder decide what to do here.
2024-07-01 08:56:55 +02:00
Kévin Commaille 374da7674e crypto: Remove assert_matches2 from regular dependencies
It was added as a regular dependency in #3517
but it is only used in tests.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-07-01 08:36:32 +02:00
Ivan Enderlin 1270cdad1a feat(ui): RoomList::entries* manipulates a Room.
This patch is quite big… `RoomList::entries*` now returns `Room`s
instead of `RoomListEntry`s. This patch consequently updates all the
filters to manipulate `Room` instead of `RoomListEntry`. No more
`Client` is needed in the filters.

This patch also disables the `RoomList` integration test suite in order
to keep this patch “small”.
2024-06-30 21:19:27 +02:00
Ivan Enderlin 73b481a8fc chore(cargo): Update eyeball-im and eyeball-im-util.
The idea is to get the `SortBy` stream adapter.
2024-06-30 21:19:25 +02:00
Stefan Ceriu 38a18c3c8e feat(ffi): add Element specific well known struct and a way to deserialize it from external clients 2024-06-28 16:58:55 +02:00
Stefan Ceriu 70fddc0e1b feat(ffi): expose method for reading the server name part of the current user's identifier. 2024-06-28 16:58:55 +02:00
Stefan Ceriu 84796ab32a feat(ffi): expose method for sending generic GET requests through the SDK's inner HTTP client. 2024-06-28 16:58:55 +02:00
Andy Balaam 6464d21813 crypto: Storage changes for keeping sender data with InboundGroupSessions (#3556)
Signed-off-by: Andy Balaam <mail@artificialworlds.net>
Co-authored-by: Damir Jelić <poljar@termina.org.uk>
2024-06-28 14:14:55 +02:00
Hubert Chathi cb4c575234 Reshare Megolm session after the other party unwedges (#3604)
For each recipient device, we keep an "Olm wedging index" that indicates (approximately) how many times they tried to unwedge the Olm session. When we share a Megolm session, we store the Olm wedging index. This allows us to tell whether the Olm session was unwedged since we shared the Megolm session, so that we know if we should re-share it.

We detect an attempt to unwedge the Olm session by checking if the Olm message that we decrypted is from a brand new Olm session. This is not entirely accurate, since this could happen, for example, if Alice and Bob create Olm sessions at the same time. This may result in some Megolm sessions being re-shared unnecessarily, but should not make a huge difference.
2024-06-28 10:08:58 +02:00
Benjamin Bouvier 1c92633a23 ffi: add new error conversions into ClientError
*sigh*
2024-06-27 18:53:00 +02:00
Benjamin Bouvier c3cdc4526e ffi: rename Timeline::edit to Timeline::edit_by_event_id, and introduce a more general Timeline::edit 2024-06-27 18:53:00 +02:00
Benjamin Bouvier 58e2b618b7 timeline: allow editing a local echo too 2024-06-27 18:53:00 +02:00
Benjamin Bouvier e808153473 timeline: react to send queue local echo updates (for room-message events) 2024-06-27 18:53:00 +02:00
Benjamin Bouvier d49190ade4 send queue: allow editing a local echo 2024-06-27 18:53:00 +02:00
Benjamin Bouvier 45c6efcc65 state store: add method to update the content of a send queue event
It also resets the wedged state, so that the queue will retry to send
this event later. This will show useful in the following case: when an
event is too big, we can now retry to send it, even if it was blocked,
by splitting the event instead of copy/abort/recreate it.
2024-06-27 18:53:00 +02:00
Benjamin Bouvier 43d9abae73 base: tweak SerializableEventContent::new signature
The first parameter doesn't need to be taken by ownership, reference is
sufficient.
2024-06-27 18:53:00 +02:00
Benjamin Bouvier 394effbc72 send queue: rename AbortSendHandle to SendHandle 2024-06-27 18:53:00 +02:00
Hubert Chathi d41af396cc Embed device keys in Olm-encrypted messages (#3517)
This patch implements MSC4147[1].

Signed-off-by: Hubert Chathi <hubertc@matrix.org>

[1]: https://github.com/matrix-org/matrix-spec-proposals/pull/4147
2024-06-27 12:18:52 +02:00
Ivan Enderlin 37c125c306 Merge pull request #3615 from Hywan/feat-base-synctimelinevent-constructor
chore(base): Use constructors of `SyncTimelineEvent` to simplify code
2024-06-27 11:11:16 +02:00
Benjamin Bouvier 8e8d793f0d fixup! state store: change schema for send_queue_events table 2024-06-26 19:42:14 +02:00
Benjamin Bouvier 29ac3e0dda fixup! state store: change schema for send_queue_events table 2024-06-26 19:42:14 +02:00
Benjamin Bouvier 7f0b035e86 ffi: respawn send queue tasks just before subscribing to the client-wide send q errors 2024-06-26 19:42:14 +02:00
Benjamin Bouvier 7daf493313 send queue: improve the module doc comment 2024-06-26 19:42:14 +02:00
Benjamin Bouvier 419dd57116 tracing timers: drive-by fix recursive macro usage 2024-06-26 19:42:14 +02:00
Benjamin Bouvier a4098291af send queue: add a way to spawn tasks for all the rooms which had unsent events 2024-06-26 19:42:14 +02:00
Benjamin Bouvier 62801f1a6c state store: change schema for send_queue_events table
It turns out that so as to be able to read the room ids, they need to be
*values*, not only *keys* (since keys are one-way hashed). This means we
need to duplicate the room_id field in indexeddb/sqlite, so each entry
contains both the room_id as a key (for queries) and as a value (to
return it).

Since there's no meaningful migration we can apply, the way to go is to
drop the pending events table and recreate it from the ground up. It is
assumed that no one has used the store on indexeddb; otherwise the
workaround would be to drop and recreate it.
2024-06-26 19:42:14 +02:00
Benjamin Bouvier 24f62a5912 indexeddb: rename (de)serialize_event to (de)serialize_value 2024-06-26 19:42:14 +02:00
Ivan Enderlin d59b28e121 chore(base): Use constructors of SyncTimelineEvent to simplify code. 2024-06-26 16:59:22 +02:00
Andy Balaam ed9ab879c9 Merge pull request #3614 from zecakeh/reexport-eyeball-im
ui: Reexport eyeball-im
2024-06-26 15:22:10 +01:00
Kévin Commaille 28d6401c4f ui: Make public all timeline module errors
A few were missing in the public API like SendEventError and RedactEventError and their dependencies.
This uses a wildcard because it should be rare to not want to expose an error type.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-06-26 15:58:33 +02:00
Kévin Commaille b8c2005422 ui: Reexport eyeball-im
A user of the library needs to add this crate as a dependency just to be able to match on `VectorDiff`.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-06-26 15:46:43 +02:00
Damir Jelić fefdfd2e4b test: Add a test to verify that interactive self-verification works
This also checks that secrets are gossiped from one device to the
other and that the recovery and backup states are correctly updated.
2024-06-26 14:31:31 +02:00
Damir Jelić d4bbdfd106 test(integration): Allow the creation of multiple clients for the same user 2024-06-26 14:31:31 +02:00
Kévin Commaille 973df115f8 ci: Bump the version of Rust nightly again
Should get rid of the `rewriting_static` noise when running rustfmt

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-06-26 14:10:36 +02:00
Kévin Commaille eaf7a9e350 chore: rustfmt fixes
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-06-26 14:10:36 +02:00
Kévin Commaille dad2e6eafd ci: Bump the version of Rust nightly
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-06-26 14:10:36 +02:00
Kévin Commaille 56739202cf sdk: Disable new rustc warnings
The issue here seems to be that
the `panic!` and `unreachable!()` macros used in the tests return `!`.
In the future, `!` will not fallback to `()`, which is what `dependency_on_unit_never_type_fallback` checks.
`add_event_handler` expects a function that returns an `EventHandlerResult`, but it is only implemented for `()`, not for `!`.

A solution could be to implement that trait for `!` but it is an unstable feature right now.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-06-26 14:10:36 +02:00
Kévin Commaille a31d362137 crypto: Disable clippy false positives
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-06-26 14:10:36 +02:00
Kévin Commaille 0cc7103fd9 docs: Fix indentation of list items paragraphs
Thanks to the new doc_lazy_continuation clippy lint in nightly.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-06-26 14:10:36 +02:00
Kévin Commaille 22171d58de sdk: Mark openidconnect crate as optional
It is only needed with the experimental-oidc and e2e-encryption features.
The former is less likely to be enabled so use it to enable the dependency.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-06-26 14:09:40 +02:00
Damir Jelić 3be84a5a30 refactor(sdk-crypto): Room key sharing, introduce extensible strategy
This patch set does two things:

1. Extracted the logic to collect the devices that should receive a room key.
2. Introduce a new CollectStrategy enum which defines which rules are
   used to collect recipient devices for a room key. Currently only the
   existing rules have beenmoved under this enum.
2024-06-25 16:54:25 +02:00
Valere ca6537badc Fix: post rename fix, update test relative paths for json inputs 2024-06-25 16:35:11 +02:00
Kévin Commaille 1221d151df sdk: Add support for authenticated media requests (#3598)
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-06-25 14:16:58 +00:00
Valere 90f92ac950 Refactor: Move file to match project module naming conventions 2024-06-25 16:01:54 +02:00
Benjamin Bouvier 4d6ee63760 sdk: retry all requests which previous response was a plain 429 without an errcode
This can happen if there's a load-balancer or any modification of the
response by a reverse proxy (e.g. rewrite 5XX errors into 429, to not
let a reverse proxy mark the upstream server as being down, as
Cloudflare seems to do).

As a result, such requests will be retried in multiple places, including
when sending something with the send queue. Also, the send queue will
mark these errors as recoverable instead of unrecoverable.

No test, because the change really is trivial and a regression test
didn't seem worth it, for once.
2024-06-25 13:47:01 +02:00
Benjamin Bouvier 58c687b71b send queue: mark reloaded local echoes as wedged or not
Part of #3361.
2024-06-25 13:30:24 +02:00
Damir Jelić 0ab0678be3 fix(sdk): when an encryption event is received, mark the room encryption as set #3602
RoomInfo::handle_state_event(...) will check this condition so we don't have to later ask the HS whether the room is encrypted or not through room::is_encrypted().

Also, as we need some way to get this info in the room list in our clients, two ways of doing this were added the FFI crate, one through RoomInfo and another one through RoomListItem.
2024-06-25 13:00:03 +02:00
Jorge Martín 0162f6ba49 Add doc clarification for ffi::room_list_item.is_encrypted() 2024-06-25 12:42:59 +02:00
Benjamin Bouvier 0701c7d652 send queue: allow sending raw events from the send queue
This requires a bit of API rejiggering, but turns out not so bad
actually.
2024-06-25 11:31:34 +02:00
Benjamin Bouvier 2855b0f6a8 sdk: bump ruma to get the bug-fix for the serialization issue related to thread replies 2024-06-25 11:31:34 +02:00
Valere 5c93372e8a refactor(sdk-crypto) - RoomKey Sharing | More test 2024-06-25 11:17:54 +02:00
Valere d6e523c1d1 refactor(sdk-crypto) - RoomKey Sharing | add settings for strategy 2024-06-25 11:16:24 +02:00
Valere 9cb068da25 refactor(sdk-crypto) - RoomKey Sharing | extract function 2024-06-25 10:30:36 +02:00
Valere 944972c27a refactor(sdk-crypto) - RoomKey Sharing | extract share module 2024-06-25 09:21:28 +02:00
Jorge Martín d8900bd6d7 Fix clippy 2024-06-24 16:18:18 +02:00
Jorge Martín 912e75c1f8 ffi: add RoomListItem::is_encrypted() function. 2024-06-24 16:01:19 +02:00
Jorge Martín 004941b6b4 ffi: add encryption info to RoomInfo 2024-06-24 16:00:29 +02:00
Jorge Martín 0bc40eadc3 sdk-base: when a m.room.encryption event is received, mark the room encryption as set.
`RoomInfo::handle_state_event` will check this condition so we don't have to later ask the HS whether the room is encrypted or not through `room::is_encrypted()`.
2024-06-24 16:00:07 +02:00
Benjamin Bouvier 74b770f4d6 send queue: use state-store backed storage for remembering events to be sent 2024-06-24 13:56:10 +02:00
Benjamin Bouvier e1e4422670 sdk: update ruma to custom fork with proper event content deserialization 2024-06-24 13:56:10 +02:00
Benjamin Bouvier 90f73195b1 send queue: introduce fallible fake state store in the send queue code 2024-06-24 13:56:10 +02:00
Richard van der Hoff 1b48bf7dc6 crypto: Log content of received m.room_key_withheld messages (#3591) 2024-06-24 11:47:53 +01:00
Doug e89659b69d ffi: Tidy up authentication.rs file.
(Nothing changed, just moving things around)
2024-06-24 10:56:04 +02:00
Doug 6d728be32d ffi: Split up AuthenticationError between ClientBuildError and a new OidcError. 2024-06-24 10:56:04 +02:00
Doug 5cbc803347 ffi: Refactor authentication_service.rs to authentication.rs 2024-06-24 10:56:04 +02:00
Doug 2d479e0177 ffi: Remove the AuthenticationService 2024-06-24 10:56:04 +02:00
Kévin Commaille 730c287201 chore: Fix new clippy nightly lints
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-06-23 20:20:09 +02:00
Johannes Marbach 3f1b9fe524 fix(ffi): Downgrade security-framework to 2.10.0
Fixes: #3596
Signed-off-by: Johannes Marbach <n0-0ne+github@mailbox.org>
2024-06-21 22:59:08 +02:00
Andy Balaam 2b1bddb2f0 Merge pull request #3587 from matrix-org/doug/client-oidc-helpers
sdk: Move the OIDC helper methods from the FFI's `AuthenticationService` into `Client`
2024-06-21 10:14:35 +01:00
Doug 837cfaed48 sdk: Clarify InvalidState OIDC check and prepare abort method for the FFI. 2024-06-20 15:54:06 +01:00
Doug 655ced2c81 docs: Clarify some of the OIDC helper methods more. 2024-06-20 15:54:06 +01:00
Doug 748f40c250 sdk: Add ClientBuilder::requires_sliding_sync method. 2024-06-20 14:27:55 +02:00
Doug 8bf104c55e ffi: Add ClientBuilder::requires_sliding_sync method. 2024-06-20 14:27:55 +02:00
Doug db38d25b5b sdk: Test the OIDC helper methods. 2024-06-20 13:23:04 +01:00
Damir Jelić af141575c9 chore: Update the changelog 2024-06-20 14:06:01 +02:00
Ivan Enderlin 6701fd0685 Merge pull request #3586 from Hywan/feat-ui-room-list-new-is-infallible 2024-06-20 13:47:28 +02:00
Damir Jelić 6dde95c865 examples: Add a recovery command to the oidc-cli example
This adds support to input your recovery key to the OIDC example which
will allow the OIDC example client to be verified and have access to all
the secrets (cross-signing keys and the backup recovery key).

Not particularly useful right now, but once the OIDC example is able to
log in other devices via a QR code it becomes necessary to have access
to all the secrets.
2024-06-20 13:43:14 +02:00
Doug 082dda0b24 sdk: Add the OIDC helper methods from the FFI. 2024-06-20 12:05:23 +01:00
Benjamin Bouvier 4ee56fa62e room: rename the encrypted log field to is_room_encrypted (#3572) 2024-06-20 12:18:00 +02:00
Benjamin Bouvier c06b6d91c3 timeline: get rid of the indirection for the Unsupported* errors
No idea why we had these wrappers, and IMO they just add unnecessary
noise, so let's get rid of them.
2024-06-20 10:11:47 +02:00
Benjamin Bouvier fd9d3bd3a1 timeline: refactor edit_info/replied_to_info 2024-06-20 10:11:47 +02:00
Doug 735ae1ce75 ffi: Move OIDC logic into Client. 2024-06-19 18:17:27 +01:00
Kévin Commaille a2235d50c1 crypto: Decrypt events bundled in unsigned object of another event
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-06-19 17:40:49 +02:00
Ivan Enderlin 96f4a1f085 feat(sdk): room_list_service::Room::new is now infallible.
This patch makes `Room::new` infallible, i.e. it no longer returns a
`Result<Self, _>` but `Self` directly.
2024-06-19 17:14:56 +02:00
Ivan Enderlin 0cd93a2f06 Merge pull request #3578 from Hywan/fix-sdk-linked-chunk-substract-overflow
fix(sdk): Fix a substract with overflow in `LinkedChunk`
2024-06-19 14:05:08 +02:00
Ivan Enderlin edcd573b6f fix(sdk): Fix a substract with overflow in LinkedChunk. 2024-06-19 12:17:23 +02:00
Damir Jelić a6c962b9b0 chore: Fix the compilation of the benchmarks outside of the workspace root
The workspace root enables some features which are required to compile
the benchmarks, but if you decide to just compile the benchmarks these
features won't be enabled since they aren't specified in the Cargo.toml
file of the benchmarks.

Let's define all the required features so compilation works in both
cases.
2024-06-19 12:06:53 +02:00
Mauro 306a9f7d3b Allow edit and reply to work also for events that have not yet been paginated (#3553)
Fixes #3538 

The current implementation for send_reply and edit only work with timeline items that have already been paginated.
However given the fact that by restoring drafts, we may restore a reply to an event for timeline where such event has not been paginated, sending such reply would fail (same for the edit event).

So I reworked a bit the code here to use. only the event id, and reuse the existing timeline if available, otherwise we can fetch the event and synthethise the content and still be able to successfully send the event.

This is the third part of the breakdown of the following PR: https://github.com/matrix-org/matrix-rust-sdk/pull/3439
2024-06-19 11:58:57 +02:00
dependabot[bot] 2834fa135a build(deps): bump curve25519-dalek from 4.1.2 to 4.1.3
Bumps [curve25519-dalek](https://github.com/dalek-cryptography/curve25519-dalek) from 4.1.2 to 4.1.3.
- [Release notes](https://github.com/dalek-cryptography/curve25519-dalek/releases)
- [Commits](https://github.com/dalek-cryptography/curve25519-dalek/compare/curve25519-4.1.2...curve25519-4.1.3)

---
updated-dependencies:
- dependency-name: curve25519-dalek
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-06-19 11:41:05 +02:00
Richard van der Hoff 4822057163 sdk: Fix key backup download for ratcheted sessions (#3568)
Fixes https://github.com/matrix-org/matrix-rust-sdk/issues/3446 by checking
that we have the key for the event in question, not just the key for the
session.
2024-06-19 09:40:19 +01:00
Ivan Enderlin 6340eeac0b Merge pull request #3068 from Hywan/feat-roomlist-sorting
feat(base): Implement `Client::rooms_stream`
2024-06-19 08:27:37 +02:00
Ivan Enderlin 717c68d9b4 test(sdk): Test Client::rooms_stream.
This patch adds an integration test for `Client::rooms_stream`.
2024-06-18 17:37:08 +02:00
Ivan Enderlin 1e639c431f doc(base): Improve documentation. 2024-06-18 17:37:07 +02:00
Ivan Enderlin dd2ef57d37 feat(base): Extract ObservableMap into its own module. 2024-06-18 17:37:07 +02:00
Richard van der Hoff 565f97409e sdk: Rewrite BackupDownloadTask
Change this so that it fires off a task for each UTD event, rather than each
megolm session. This is a step towards considering the message index when
deciding whether to carry on with the download.
2024-06-18 14:17:36 +01:00
Richard van der Hoff 792402eca2 sdk: Expose WeakClient::strong_count
... allowing you to see if the client is alive without the overhead of
constructng a ref to the client.
2024-06-18 14:17:36 +01:00
Richard van der Hoff 53e3a7c242 sdk: BackupDownloadTask: use a new struct for the mpsc queue
We'll need to add more data here soon.
2024-06-18 14:17:36 +01:00
Richard van der Hoff dc2111f156 sdk: Push deserialization of UTD events down to BackupDownloadTask
This means the higher-level classes can be agnostic about the encryption
algorithm; we don't actually care about that until BackupDownloadTask.
2024-06-18 14:17:36 +01:00
Richard van der Hoff f1802d9bbe sdk: update Backups::utd_event_handler api
Make it take a `Raw<OriginalSyncRoomEncryptedEvent>`, to be consistent with
`Room::decrypt_event`.
2024-06-18 14:17:36 +01:00
Richard van der Hoff 2b5d2e97c0 sdk: add documentation on Backups::utd_event_handler 2024-06-18 14:17:36 +01:00
Benjamin Bouvier 0b9daa2702 timeline: when deduplicating event meta, keep the most recent instead of the oldest
Not doing this leads to an invalid ordering of events, as shown in the
test: if we increase the timeline limit of a room using sliding sync,
we'll receive a duplicate event, and if we ignore it, it'll be in an
invalid position. The solution is to keep the most recent event (and
remove the old one from event_meta).
2024-06-18 14:39:27 +02:00
Doug 304350ffd4 ffi: Expose room heroes (adding support for avatars). (#3503)
This PR makes 2 changes:
- Updates the storage of room heroes to be a single array containing the user's complete profile.
- Exposes these to the FFI so that client apps can use these for avatar colours/clusters.

Closes #2702 (again, now with avatars 🖼️)

---

* rooms: Store heroes as a complete user profile.

* ffi: Expose room heroes on Room and RoomInfo.

* chore: Remove TODO comment.

* Update crates/matrix-sdk-base/src/rooms/normal.rs

Signed-off-by: Benjamin Bouvier <public@benj.me>

---------

Signed-off-by: Benjamin Bouvier <public@benj.me>
Co-authored-by: Benjamin Bouvier <public@benj.me>
2024-06-18 10:10:09 +00:00
Benjamin Bouvier 8988094df5 sdk: introduce RetryKind next to the HttpError to determine errors that should be retried
retry kind: make `characterize_retry_kind` a method of `HttpError`

---

retry kind: mark all network errors as transient

This should cause more backoff in general, if the client is disconnected
of the grid, or the remote server is, which is good behavior to have in
general.

---

http error: introduce another rustfmt-formated impl block for HttpError

The previous `impl` block was marked as skipping rustfmt, which led to
weird formatting behavior.

Changes are formatting only.
2024-06-17 17:15:07 +02:00
Benjamin Bouvier f93df8cb9e send queue: improve testing with a lil macro 2024-06-17 17:15:07 +02:00
Benjamin Bouvier ced8c4c821 send queue: add a test that simulates unreachable network/server 2024-06-17 17:15:07 +02:00
Benjamin Bouvier f45098a61d send queue: flag unrecoverable errors, and don't block the queue on those 2024-06-17 17:15:07 +02:00
Richard van der Hoff d146ba869a sdk: Refactor key-backup integration tests (#3560)
* sdk: Integ tests: factor out some helper methods

A few common methods for logic shared between the tests. This serves two
purposes:

 * It reduces duplication, this making it easier to maintain the tests by
   reducing the number of places that we have to change things.

 * It makes the tests easier to read. By factoring out discrete steps, it's
   much easier to get an overview of what a test is doing than when it's all in
   one big function.

* sdk: Integ tests: timeout if nothing happens

If the test is going to fail, let's have it do so properly rather than
mysteriously getting stuck.
2024-06-17 15:42:48 +01:00
Ivan Enderlin 01d6a9e7b7 chore(base): Make Clippy happy. 2024-06-17 15:16:09 +02:00
Ivan Enderlin e9121ab1ff feat(base): Create an ObservableMap for wasm32-unknown-unknown.
This patch creates an `ObservableMap` for `wasm32-unknown-unknown` which
simply wraps a `BTreeMap`, and without the `stream` method. Indeed, the
first implementation uses `eyeball_im::ObservableVector` which requires
`Send` and `Sync` on its values, which cannot compile to Wasm.
2024-06-17 15:16:07 +02:00
Ivan Enderlin 6e7f53dc19 feat(sdk): Implement Client::rooms_stream.
This patch implements `Client::rooms_stream` by forwarding the
result of `matrix_sdk_base::Client::rooms_stream`, and mapping the
`matrix_sdk_base::Room` to `matrix_sdk::Room`.
2024-06-17 15:15:43 +02:00
Ivan Enderlin e028710cf9 test: Fix a compiler warning if e2e-encryption and experimental-sliding-sync aren't enabled. 2024-06-17 14:46:45 +02:00
Ivan Enderlin f9e8f1178b feat(base): Implement Client::rooms_stream.
This patch implements `Client::rooms_stream`, which forwards the result
of the recently added `Store::rooms_stream` method.
2024-06-17 14:46:45 +02:00
Ivan Enderlin fd4505b026 fix(base): Define matrix_sdk_base::latest_event also if e2e-encryption is enabled.
Running `cargo test -p matrix-sdk-base --features e2e-encryption`
makes the code to fail to compile because `crate::latest_event` isn't
defined. And indeed, it must be defined if `experimental-sliding-sync`
is enabled, but also if `e2e-encryption` is enabled.
2024-06-17 14:46:45 +02:00
Ivan Enderlin 11bced4876 feat(base): Implement Store::rooms_stream.
This patch implements a new `Store::rooms_stream` method that forwards
the result of `ObservableMap::stream`.
2024-06-17 14:46:44 +02:00
Ivan Enderlin 6dac77fd5e feat(base): Implement ObservableMap::stream.
This patch basically implements `ObservableMap::stream` which returns a
batched stream of the values.
2024-06-17 14:46:44 +02:00
Ivan Enderlin a67e7f2795 feat(base): Rename Rooms to generic ObservableMap + add tests.
This patch rewrites `Rooms` to a generic `ObservableMap` struct. It also
adds documentation and tests for this type.
2024-06-17 14:46:44 +02:00
Ivan Enderlin 5870dafe2e feat(base): Make Store::rooms observable.
This patch updates `Store::rooms` from a
`Arc<StdRwLock<BTreeMap<OwnedRoomId, Room>>>` to a
`Arc<StdRwLock<Rooms>>` where `Rooms` is a new type that mimics a
`BTreeMap` but that is observable. It uses an `ObservableVector`
for saving us the costs of writing a new `ObservableMap` type in
`eyeball-im`. It would have too much implications that are clearly
not necessary. The major one being that an `ObservableMap` must emit
`MapDiff`, but we expect `VectorDiff` everywhere in the SDK where rooms
are observable. It would break too many API and too many projects.

The benchmark is coming, but here are the results (for 10'000 rooms,
extreme case):

* `get_rooms` and `get_rooms_filtered` are twice faster (in practise, it
  means 650µs is saved per call),
* `get_room` and `get_or_create_room` are 10% slower (in practise, it
  means 8-10ns is lost per call).

Overall, I believe these results are acceptable, and even an improvement
for the first one.
2024-06-17 14:46:44 +02:00
Ivan Enderlin 3ffeef55a6 Merge pull request #3561 from Hywan/fix-base-box-stream
chore(base): Remove `BoxStream` as it's never used
2024-06-17 14:46:09 +02:00
Timo cb7814b362 MatrixRTC: bump ruma to be compatible with MSC4143.
Adapt types for the new ruma version.
2024-06-17 14:21:22 +02:00
Ivan Enderlin 2ecd54a3b2 chore(base): Remove BoxStream as it's never used.
This patch removes the public type alias `BoxedStream` which is never
used in our code.
2024-06-17 13:08:59 +02:00
Ivan Enderlin b34a2cdfc9 Merge pull request #3559 from matrix-org/feat-sdk-sliding-sync-get-room-id
chore(sdk): Remove the useless `SlidingSyncList::get_room_id` method
2024-06-17 13:02:28 +02:00
Ivan Enderlin 304c225c8f chore(sdk): Remove the useless SlidingSyncList::get_room_id method.
This patch removes the useless `SlidingSyncList::get_room_id` method as
I don't see how it can be useful for anybody. It's mostly dead public
code, let's clean that up.
2024-06-17 12:13:26 +02:00
Benjamin Bouvier 72adaf4119 sdk: slightly better doc for HttpError 2024-06-17 10:50:06 +02:00
Benjamin Bouvier c656ad4068 sdk: prefer direct use of IntoHttp ctor instead of implicit #[from] conversions 2024-06-17 10:50:06 +02:00
Benjamin Bouvier c33a7b77e1 sdk: prefer direct use of RefreshToken ctor instead of implicit #[from] conversions
This might be controversial, but I do strongly prefer explicit over
implicit, in this case: it helps looking at the use cases, when using
the LSP's goto_references().
2024-06-17 10:50:06 +02:00
Benjamin Bouvier 7f64580ce2 sdk: use Error::AuthenticationRequired instead of HttpError::AuthenticationRequired
The HttpError variant was misplaced, as it was always used when the
`user_id()` is missing, which is causing `Error::AuthenticationRequired`
errors everywhere else in the code base. This patch streamlines usage of
`Error::AuthenticationRequired`, and gets rid of the `HttpError`
variant.
2024-06-17 10:50:06 +02:00
Benjamin Bouvier 08d7bd0cee sdk: get rid of the UnableToCloneRequest error which is absolutely unused 2024-06-17 10:50:06 +02:00
Ivan Enderlin 6ecefd6bc7 Merge pull request #3554 from Hywan/chore-sdk-remove-get-prefix 2024-06-13 23:59:52 +02:00
Ivan Enderlin b21b8c4a53 doc(base): Update the CHANGELOG.md file. 2024-06-13 16:52:37 +02:00
Ivan Enderlin 771ddcb91e chore(base): Remove the get_ of some Client's methods.
This patch renames `Client::get_rooms`, `::get_rooms_filtered` and
`::get_room` to respectively `::rooms`, `::rooms_filtered` and `::room`.
This `get_` prefix isn't really Rust idiomatic.
2024-06-13 16:51:20 +02:00
Ivan Enderlin 408c12fc66 doc(base): Update the CHANGELOG.md file. 2024-06-13 16:44:54 +02:00
Ivan Enderlin adff893835 feat(base): Faster Store::rooms_filtered.
Just like in https://github.com/matrix-org/matrix-rust-sdk/pull/3552,
this patch updates `Store::rooms_filtered` to not call `Store::room` so
that it doesn't lock `rooms` for each item, thus making it way faster.
2024-06-13 16:44:54 +02:00
Ivan Enderlin 81e328d090 chore: Remove the get_ of some Store's methods.
This patch renames `Store::get_rooms`, `::get_rooms_filtered` and
`::get_room` to respectively `::rooms`, `::rooms_filtered` and `::room`.
This `get_` prefix isn't really Rust idiomatic.
2024-06-13 16:40:32 +02:00
Benjamin Bouvier b1c09ed61b ffi: get rid of Timeline::latest_event()
It's unlikely to be useful as per the `Timeline` object: rather, callers
should make use of `Room::latest_event()`.
2024-06-13 16:28:40 +02:00
Ivan Enderlin 9ccf94dc3c Merge pull request #3552 from Hywan/fix-base-store-get-rooms-fast
feat(base): Make `Store::get_rooms` wayyy faster
2024-06-13 16:21:46 +02:00
Ivan Enderlin 15ab77629f feat(base): Make Store::get_rooms wayyy faster.
`Store::get_rooms` worked as follows: For each room ID, call

* Take the read lock for `rooms`,
* For each entry in `rooms`, take the room ID (the key), then call `Store::get_room`, which…
* Take the read lock for `rooms`,
* Based on the room ID (the key), read the room (the value) from `rooms`.

So calling `get_rooms` calls `get_room` for each room, which takes the lock every time.

This patch modifies that by fetching the values (the rooms) directly
from `rooms`, without calling `get_room`.

In my benchmark, it took 1.2ms to read 10'000 rooms. Now it takes 542µs.
Performance time has improved by -55.8%.
2024-06-13 16:03:25 +02:00
Ivan Enderlin 5178cbbfc7 Merge pull request #3551 from Hywan/fix-ui-roomlist-slidingsyncroom
feat(ui): `RoomListService::room` is no longer async!
2024-06-13 15:20:47 +02:00
Ivan Enderlin a7ff0587a6 fix(ui): Replace the RwLock by a Mutex in RoomListService::rooms.
This patch replaces the `RwLock` by a `Mutex` in
`RoomListService::rooms` because:

1. it removes a race condition,
2. `RwLock` was used because the lock could have been taken for a long
   time due to the previous `.await` point. It's no longer the case, so we
   can blindly use a `Mutex` here.
2024-06-13 15:03:59 +02:00
Ivan Enderlin edec6e7558 feat(ui): RoomListService::room is no longer async.
This patch makes `RoomListService::room` synchronous. It no longer reads
a `SlidingSyncRoom` from `SlidingSync`, then it not needs to be async
anymore. This patch replaces the `RwLock` of `RoomListService::rooms`
from `tokio::sync` to `std::sync`.

The patch updates all calls to `RoomListService::room` to remove the
`.await` point.
2024-06-13 14:47:43 +02:00
Ivan Enderlin 868e821427 Merge pull request #3550 from Hywan/fix-ui-timeline-duplicated-events
fix(ui): Change the behaviour when a duplicated event is received by the `Timeline`
2024-06-13 14:43:44 +02:00
Ivan Enderlin de5d80547b Merge pull request #3541 from Hywan/chore-ffi-roominfo-latest-event
chore(ffi): Remove `RoomInfo::latest_event`
2024-06-13 14:40:38 +02:00
Ivan Enderlin 5e755c5d51 fix(ui): room_list_service::Room::new no longer receives a SlidingSyncRoom.
This patch updates `room_list_service::Room::new` to take a `&Client`
and a `&RoomId` instead of a `SlidingSyncRoom`. The `SlidingSyncRoom` is
only used in `Room::default_room_timeline_builder` and is fetched there
from the `SlidingSync` instance lazily. It confines the
`SlidingSyncRoom` to one single method for `Room` now.
2024-06-13 14:39:39 +02:00
Ivan Enderlin d46e65805a chore(ui): Rename TimelineInnerState::add_event to add_or_update_event.
This patch renames `add_event` to `add_or_update_event` because it is
what it does.
2024-06-13 14:21:17 +02:00
Damir Jelić 9b05d0d822 crypto: Use the server name in the QR code login data (#3537)
Using the resolved homeserver URL causes problems if we need to inspect
the well-known configuration of the homeserver, for example, if the
server name is matrix.org, but the homeserver URL is server.matrix.org,
the well-known might be only available for the former.

This is why we also need to receive the former, i.e. the server name in
the QR code data.
2024-06-13 14:16:48 +02:00
Ivan Enderlin 01a36c90c3 chore(ffi): Remove RoomInfo::latest_event.
This patch removes `RoomInfo::latest_event`. To get the latest event,
one has to use `RoomListItem::latest_event` because it supports
local events and remote events. It was supposed to be the case of
`Room::room_info` too, but only when the method was called: Once the
`RoomInfo` was created, the latest event inside `RoomInfo`
was static, not dynamic. Also, this code wasn't tested
contrary to `RoomListItem::latest_event` which uses
`matrix_sdk_ui::room_list_service::Room::latest_event` which is itself
tested.
2024-06-13 14:13:48 +02:00
Ivan Enderlin 6da17b3f02 Merge pull request #3540 from Hywan/fix-ui-roomlist-latest-event
chore(ui): `room_list_service::Room::latest_event` no longer uses `SlidingSyncRoom` (+ drop `SlidingSyncRoomExt`)
2024-06-13 14:08:27 +02:00
Ivan Enderlin 15ed91e047 fix(ui): Change the behaviour when a duplicated event is received by Timeline.
This patch changes the behaviour of the `Timeline` when a duplicated
event is received. Prior to this patch, the old event was removed, and
the one was added. With this patch, the old event is kept, and the new
one is skipped.

This is important for https://github.com/matrix-org/matrix-rust-sdk/pull/3512
where events are mapped to the timeline item indices. When an event is
removed, it becomes difficult to keep the mapping correct.

This patch also adds duplication detection for pagination (with
`TimelineItemPosition::Start`).
2024-06-13 14:05:22 +02:00
Ivan Enderlin 6d1289482a chore(ui): Remove SlidingSyncRoomExt.
This patch removes the `matrix_sdk_ui::timeline::SlidingSyncRoomExt`
trait as it's no longer necessary since `room_list::Room::latest_event`
no longer uses `SlidingSyncRoom` to fetch the latest event.
2024-06-13 13:47:42 +02:00
Ivan Enderlin 8021d72389 feat(ui): Fetch the latest event from Room instead of SlidingSyncRoom in room_list::Room.
This patch updates `matrix_sdk_ui::room_list::Room::latest_event`
to fetch the latest event from `matrix_sdk::Room` instead of
`matrix_sdk::sliding_sync::SlidingSyncRoom`. It removes one dependency
to `SlidingSyncRoom` and it simplifies the code.
2024-06-13 12:00:22 +02:00
Johannes Marbach f770248b24 fix(bindings): use the same library name for all platforms in the xcframework
Fixes: #3528
Signed-off-by: Johannes Marbach <n0-0ne+github@mailbox.org>
2024-06-12 17:17:36 +02:00
Benjamin Bouvier 2a79956caa ffi: call the initial events in the same task that listens to updates
This avoids a race condition where the caller hasn't set up the initial
items or the listener, and the listener is called *before* the initial
items have been used.
2024-06-12 16:16:41 +02:00
Mauro 871116eee9 feat (bindings): added an API to retrieve a loaded reply (#3534)
second part of the #3439 breakdown

The context for this API, is for the composer preview an reply without the need of it being actively in the timeline.
2024-06-12 14:00:50 +00:00
Benjamin Bouvier 03c16cb9f6 deduplicating handler: rename NotFinishedYet to Cancelled and add a few comments around the code future 2024-06-12 15:39:21 +02:00
Benjamin Bouvier 34a9289978 deduplicating handler: add a regression test for cancellation of a deduplicated query 2024-06-12 15:39:21 +02:00
Benjamin Bouvier ad63d28cfa deduplicating handler: use a new QueryState data structure 2024-06-12 15:39:21 +02:00
Benjamin Bouvier ac0992953e deduplicating handler: repeat request until it's performed at least once 2024-06-12 15:39:21 +02:00
Mauro d035eb1d90 feat (bindings): added APIs to save and load composer drafts (#3531)
This PR is the first piece of the breakdown of the following PR: https://github.com/matrix-org/matrix-rust-sdk/pull/3439 where only the core functionalities of the feature are implemented, without addressing the issue of editing and replying to events that have not yet been paginated.
2024-06-11 15:32:07 +00:00
Benjamin Bouvier 0ec90c23da base: move the initial filling of the display name cache into the sync methods
It's not perfect, but it's honest work.
2024-06-11 15:44:53 +02:00
Benjamin Bouvier c72384f7d4 base: don't regenerate the display name when creating a room, store the cached display name in RoomInfo
So revert a few changes to make some functions async, etc.
2024-06-11 15:44:53 +02:00
Benjamin Bouvier 5a5a5797e9 ci: fix flakeyness of test_room_notification_count in an innovative way
The test looks at updates of `RoomInfo`s, but these depends on external
factors like the server sending them in one part or multiple ones.

Instead of trying to figure out which partial updates the server sent,
wait for the stream of `RoomInfo`s to stabilize by trying to get the
latest item from the stream, then wait up to N seconds for another item
to show up, and continue as long as items come in.

This should allow us to get rid of some code that was required to
prevent flakey updates.
2024-06-11 15:44:53 +02:00
Benjamin Bouvier e22162a23a base: rename computed_display_name to compute_display_name and remove computed_ in the cached one 2024-06-11 15:44:53 +02:00
Benjamin Bouvier 73f977986e sdk: use the cached computed display name in more places 2024-06-11 15:44:53 +02:00
Benjamin Bouvier 2d444284cc base: rename calculate_room_name to compute_display_name_from_heroes 2024-06-11 15:44:53 +02:00
Benjamin Bouvier c0c9d16412 ui: make use of the cached computed display name in the room name matchers 2024-06-11 15:44:53 +02:00
Benjamin Bouvier 78a1634341 base: add a cache to the computed display name 2024-06-11 15:44:53 +02:00
Benjamin Bouvier 78e2ab9d99 base: make get_or_create_room async
Since this is a good place where to recompute the cached display name at
start.
2024-06-11 15:44:53 +02:00
Benjamin Bouvier f1553ae7f8 sliding sync: add some simple positive tests for room names too 2024-06-11 15:44:53 +02:00
Benjamin Bouvier 9a1a3e67c3 base(code motion): move calculate_room_name into the one file where it's used 2024-06-11 15:44:53 +02:00
Benjamin Bouvier 82ae74fee9 base: get rid of intermediate calculate_name() function 2024-06-11 15:44:53 +02:00
Benjamin Bouvier 8d66d1bab0 base: fix guessed number of members as it should relate to joined users, not joined+invited
The previous code would use `ACTIVE` which means "either joined or
invited" members, but the code thereafter considered this to be the
number of joined members.

Also replaced a call to `self.members()` (which does a lot of work under
the hood) with a call to `self.joined_user_ids()`, since we only
retrieve the `.len()` of the resulting vector.
2024-06-11 15:44:53 +02:00
Benjamin Bouvier 66d43c1088 base: directly call calculate_room_name since it's a free-function
Instead of calling it through `BaseRoomInfo::calculate_room_name`.
2024-06-11 15:44:53 +02:00
Denis Kasak ad79f9c0ac docs: Update message key forwarding algorithm model.
- Change incorrect "key sharing" references to "key forwarding".
- Explain that this is a feature that needs to be enabled.
- Regenerate the key forwarding algorithm diagram.
- Provide a spec link and mention alternative names.
2024-06-11 14:51:32 +02:00
Richard van der Hoff 1510f87fa0 UTD hook: stop re-reporting of UTDs on app relaunch (#3519)
Use a Bloom filter to keep track of which events we have already reported to the parent UTD hook.
We load the data from database on startup, and flush it out immediately on every update.
2024-06-10 18:56:35 +01:00
Ivan Enderlin a2f868d1a7 Merge pull request #3527 from Hywan/chore-ui-timeline-event-handler-add
chore(ui): Rewrite a bit `TimelineEventHandler::add`
2024-06-10 18:31:51 +02:00
Ivan Enderlin 17befab414 chore(ui): Rewrite a bit TimelineEventHandler::add.
This patch renames `TimelineEventHandler::add` to `add_item`.

This patch also removes the `should_add` argument. The `add_item`
is called conditionally everytime. I believe this is much cleaner.
Otherwise the method should have been called `maybe_add_item` with a
return type or something that indicates whether the item is added. This
patch makes it clear and remove one possible state in `add_item`.
2024-06-10 18:18:05 +02:00
Ivan Enderlin abda959796 chore(ui): Make TimelineInnerMetadata::next_internal_id private
chore(ui): Make `TimelineInnerMetadata::next_internal_id` private
2024-06-10 10:21:54 +02:00
Ivan Enderlin 1a343d93e7 chore(ui): Remove a useless clone
chore(ui): Remove a useless clone
2024-06-10 10:19:45 +02:00
Ivan Enderlin 2a70587dda chore(ui): Make TimelineInnerMetadata::next_internal_id private.
This patch updates `TimelineEventHandler` to re-use the public API and
avoid using `TimelineInnerMeta::next_internal_id`. The consequence is
that `next_internal_id` can now be private instead of public. It's
better to have isolated API in this code.
2024-06-10 10:06:08 +02:00
Ivan Enderlin d403c12464 chore(ui): Remove a useless clone.
This patch removes a useless clone of `TimelineInner::items`. This clone
was technically cheap because it's a `Vector` behind the scene, which is
cheap to clone, but still, it's not necessary at all to clone it.
2024-06-10 10:03:49 +02:00
Benjamin Bouvier e5487da160 send queue: control enabled on a per-room basis in addition to globally 2024-06-10 09:44:44 +02:00
Benjamin Bouvier 9c1d62a039 sdk: finish renaming "sending queue" to "send queue" 2024-06-10 09:21:35 +02:00
Ivan Enderlin 1c9171d917 Merge pull request #3515 from Hywan/doc-sdk-sliding-sync-mode-typo 2024-06-10 07:13:27 +02:00
Timo 931c564942 widget API(ffi): Add StateEventType::RoomEncryption to capabilities (#3506)
also add TODO comment to remove `org.matrix.msc3401.call` once possible.
2024-06-06 19:31:56 +02:00
Benjamin Bouvier 632de475a1 send queue: try to avoid a race when disabling then aborting a send 2024-06-06 18:30:15 +02:00
Benjamin Bouvier a21ea06bed day dividers: demote an assert to an error message
Because of the task cancellation that can happen at any place in the
code base, it's really hard to predict in which situation a
day-divider-adjuster should have run or not, so just demote the assert
to an error. The intent is that, if we see errors with day dividers in
the future, they'll be reported along rageshakes and we'll notice this
in the logs.
2024-06-06 18:05:21 +02:00
Benjamin Bouvier 66330a20b3 sdk: rename "sending queue" to "send queue" 2024-06-06 17:56:17 +02:00
Doug 3f272a72c4 chore: Update some docs on the authentication service. 2024-06-06 17:01:46 +02:00
Doug 81b55a4ca8 ffi: Use a single client in the authentication service.
We no longer need the in-memory store as we provide a path for the new session.
2024-06-06 17:01:46 +02:00
Doug d43812ac04 ffi: Replace the Client's base_path with a session_path.
The SDK no longer handles subdirectories for the user, this becomes the app's responsibility.
2024-06-06 17:01:46 +02:00
Doug 2c87333106 oidc: Supply a direct path to the registrations file instead of a base path. 2024-06-06 17:01:46 +02:00
Ivan Enderlin 1aacbaf681 doc(sdk): Fix a formatting typo. 2024-06-06 11:34:38 +02:00
Benjamin Bouvier 5093af87b1 clippy: disallow useless asyncs (#3513)
Using async when not required will increase compile times, and propagate async-ness to the callers, transitively.

See also the [lint description](https://rust-lang.github.io/rust-clippy/master/#/unused_async).

Since we only had a few false positives, I've enabled it by default.
2024-06-05 17:13:10 +02:00
Benjamin Bouvier 23cc1e31c1 ffi: make more methods async, rename a few variables/functions, etc. 2024-06-05 14:58:41 +02:00
Benjamin Bouvier 96824055f8 ffi: add new method to retrieve a timeline item by transaction id 2024-06-05 14:58:41 +02:00
Benjamin Bouvier cb9e2bda92 timeline: mark local echoes as not editable
Also reunify two methods that did the same thing, with slightly
different semantics, and test the one that wasn't tested at all.

Note that `is_editable()` was already exposed to the FFI and used in EX
apps.
2024-06-05 14:58:41 +02:00
Benjamin Bouvier 04befa3ab5 timeline: get rid of the Cancelled state
It was used after a previous local echo couldn't be sent (i.e. the
sending queue failed to send it). However, it was slightly incorrect to
mark those as cancelled, since those local echoes would still have
corresponding items in the sending queue, and would be retried as soon
as the sending queue was reenabled and could send events.

Instead, this is removed: it means that previously cancelled events
would be in the NotSentYet state, which is correct. (At the limit, we
could even get rid of the SendingFailed variant, since the sending queue
will automatically retry as soon as possible.)
2024-06-05 14:58:41 +02:00
Benjamin Bouvier fd15333ba2 timeline: add a redact method to get rid of local or remote events 2024-06-05 14:58:41 +02:00
Benjamin Bouvier 68c61ef8e1 send queue: add an abort handle to all local echoes 2024-06-05 14:58:41 +02:00
Benjamin Bouvier fd9266e960 ffi: expose the abort handle after sending an event 2024-06-05 14:58:41 +02:00
Benjamin Bouvier 5ea7ef01e5 ffi: expose the global sending queue primitives 2024-06-05 14:58:41 +02:00
Benjamin Bouvier 3693c582c3 integration tests: update reactions test to check if an event is a local echo
The test relied on the fact that sending an event from a given timeline
is not observable from another timeline. Indeed, it sent a message using
a first timeline object, then constructed a second timeline object and
expected only the remote event to be in there.

Now, the sending queue is shared across all instances of a Room, thus
all instances of a Timeline, and the second timeline can see the local
echo for the message sent by the first timeline.

The "fix" is thus in the test structure itself: when waiting for the
remote echo to be there, check that the timeline item doesn't pertain to
a local echo, i.e. is a remote echo.
2024-06-05 14:58:41 +02:00
Benjamin Bouvier 8101879799 timeline: clarify in some names that events are remote 2024-06-05 14:58:41 +02:00
Benjamin Bouvier ec95ca6ed1 timeline: only spawn the local echo listener if we're a live timeline
Technically, the test already passed before the change in the builder,
because `TimelineEventHandler::handle_event` already filters out local
events on non-live timelines, but it's a waste of resources to even
spawn the local echo listener task in that case, so let's not do it.
2024-06-05 14:58:41 +02:00
Benjamin Bouvier b88381a289 timeline: use the new sending queue mechanism to send and receive local echoes 2024-06-05 14:58:41 +02:00
Benjamin Bouvier 3917ba67c9 ffi: add a reference to the FFI Client to the Encryption API object
By keeping a reference to the FFI Client, we make sure that the SDK
Client is dropped while in a tokio runtime context. This makes it
possible for an `Encryption` (FFI) object to outlive the `Client` (FFI)
object without crashing (because deadpool requires to be in a tokio
runtime context when dropping).
2024-06-05 13:48:39 +02:00
Benjamin Bouvier c1030562c3 authentication service: inline details_from_client() 2024-06-05 13:48:39 +02:00
Benjamin Bouvier e6185b3827 authentication service(ffi): don't set the base_path for the temporary discovery client
Following https://github.com/matrix-org/matrix-rust-sdk/pull/3473, we
made it so that if there's a base-path but no username, then we'll
create a sqlite database.

Unfortunately, this introduced a bad side-effect: for the temporary
client used during homeserver resolution, this would create a temporary
sqlite database.

The "fix" is to not set the base path for the temporary client, and only
for the other caller of `new_client_builder()`, manually. The long term
fix is to get rid of the `AuthenticationService` so we can test it
properly.
2024-06-05 13:48:39 +02:00
Benjamin Bouvier 13df762dc1 ffi: add more logs related to the path in the client builder 2024-06-05 13:48:39 +02:00
Ivan Enderlin ec5f94f0b4 feat(base): Update Ruma to get RoomSummary::heroes as Vec<OwnedUserId>
feat(base): Update Ruma to get `RoomSummary::heroes` as `Vec<OwnedUserId>`
2024-06-05 10:51:38 +02:00
Ivan Enderlin 420a69f9de feat(base): Update Ruma to get RoomSummary::heroes as Vec<OwnedUserId>.
This patch updates Ruma to 75e8829 so that `RoomSummary::heroes` is now
a `Vec<OwnedUserId>` instead of a `Vec<String>`. This patch updates our
code accordingly by removing the parsing of heroes as `OwnedUserId`.
2024-06-05 10:38:03 +02:00
Benjamin Bouvier ec5f5bc104 room preview integration test: explicitly request some state events to sync
Another attempt at fixing #3483.
2024-06-05 10:08:52 +02:00
Benjamin Bouvier 9d46da9f11 clippy: fix additional errors
We should investigate why some errors were not found in CI tasks,
though.
2024-06-05 09:34:31 +02:00
Benjamin Bouvier 13f2c89e06 xtask: force --target-applies-to-host when running Clippy check
Without this, the configs from `.cargo/config.toml` were not read in CI
tasks, causing false positives when running Clippy on CI (i.e. there
were issues observed when compiling locally that were not found when
compiling remotely).

Not entirely sure why it's needed, because I'm seeing the issues when
I'm using `cargo xtask ci clippy` locally, with nothing changed.
2024-06-05 09:34:31 +02:00
Ivan Enderlin d4df2624ff Merge pull request #3444 from surakin/encrypted-stickers
Expose new sticker source field (and drop url field)
2024-06-05 09:04:40 +02:00
Ivan Enderlin 37098bbb43 Merge pull request #3510 from maan2003/push-zluyyrrmtqpz
fix: bump deadpool-sync
2024-06-05 08:52:59 +02:00
Ivan Enderlin 1913d012ee Merge pull request #3509 from matrix-org/jplatte/unexpected-cfgs
Configure unexpected-cfgs via Cargo.toml instead of build scripts
2024-06-05 08:50:21 +02:00
maan2003 80ccbd045f fix: bump deadpool-sync 2024-06-05 03:18:53 +05:30
Jonas Platte b73dbb4a55 Bump nightly version 2024-06-04 23:45:33 +02:00
Jonas Platte 02185f7034 Configure unexpected-cfgs via Cargo.toml instead of build scripts 2024-06-04 23:34:38 +02:00
Marco Antonio Alvarez dadca42776 expose sticker source field
Signed-off-by: Marco Antonio Alvarez <surakin@gmail.com>

go back to old ruma rev
2024-06-04 15:18:04 +02:00
Benjamin Bouvier 5d549f1714 integration test: raise the sync time before considering it as stable
It turns out that the failure came when using the known room path in the
room preview: Alice knows about the room, but for some reason the client
didn't retrieve all the state events from the sliding sync proxy yet.

Before, the sync would be considered stable after 2 seconds. This is too
little, considering that events come from the proxy that listens to
events from synapse. Raising this threshold to 15 seconds should help
getting all the room information from the proxy, and thus get all the
information we expected in the client.
2024-06-04 14:57:26 +02:00
Benjamin Bouvier 77f0b6a4e2 pagination: don't hold onto the waited_for_initial_prev_token lock for too long
While this mutex is taken, in `oldest_token()` we can get a hold of the
RoomEvent mutex, making it so that the `waited_...` token covers the
critical region of room events.

Unfortunately, in `clear()`, we're taking these two locks in the
opposite order, implying that the room events critical region now
overlaps that of the `waited_...` lock.

The way to break the cycle is to keep the `waited_` token for as short
as possible.
2024-06-04 11:46:37 +02:00
Benjamin Bouvier bffcb26e7d multiverse: add support for sending messages and {en|dis}abling the sending queue 2024-06-03 17:42:30 +02:00
Benjamin Bouvier 78608a1b9d sending queue: do a few renamings after the live review
Thanks @Hywan for the review comments!
2024-06-03 15:30:56 +02:00
Benjamin Bouvier 75aba1d17f clippy: declare victory over clippy
So as to not use sync mutexes across await points, we have to use an
async mutex, BUT it can't be immediately called in a wiremock responder,
so we need to shoe-horn a bit: create a new tokio runtime, which can
only be called from another running thread, etc. It's a bit ugly, but I
couldn't find another mechanism to block the responder from returning a
Response immediately; happy to change that anytime if there's a simpler
way.
2024-06-03 15:30:56 +02:00
Benjamin Bouvier c5e8cb71b5 sending queue: add better logging for debug purposes 2024-06-03 15:30:56 +02:00
Benjamin Bouvier a49b3a1b61 sending queue: remove spurious async 2024-06-03 15:30:56 +02:00
Benjamin Bouvier 0e8a707311 sending queue: add a global way to observe the enablement state
A client would require this to know that the sending queue has been
globally disabled, across all the rooms, otherwise they couldn't know
that it needs to be re-enabled later on.
2024-06-03 15:30:56 +02:00
Benjamin Bouvier 2cf36c7a5e sdk: add a sending queue for handling sending room events in the background
This implements the following features:

- enabling/disabling the sending queue at a client-wide granularity,
- one sending queue per room, that lives until the client is shutting
down,
- retrying sending an event three times, if it failed in the past, with
some exponential backoff to attempt to re-send,
- allowing to cancel sending an event we haven't sent yet.

fixup sdk
2024-06-03 15:30:56 +02:00
Benjamin Bouvier 001e88a60d sdk: add an optional RequestConfig to the SendMessageLikeEvent futures 2024-06-03 15:30:56 +02:00
Benjamin Bouvier 4ec34ad25d ffi: get rid of get_timeline_event_content_by_event_id
This can be equivalently retrieved using:

`get_timeline_event_by_event_id(event_id).content().as_message()?.content()`

As per the commit date, this is used in one place in both EXA and EXI,
so it seems fine to change the caller's call sites.

And this avoids one explicit call site of
`Timeline::item_by_event_id()`.
2024-06-03 15:28:17 +02:00
Ivan Enderlin 03b58ea1df Merge pull request #3491 from Hywan/feat-sdk-event-cache-pagination-through-update-2
feat(sdk): Add `RoomPagination::run_backwards(…, until)`, take 2
2024-06-03 10:28:49 +02:00
Ivan Enderlin 59924ea03e doc(sdk): Fix Control to ControlFlow. 2024-06-03 09:11:47 +02:00
Ivan Enderlin b85c819414 Reapply "feat(sdk): Add RoomPagination::run_backwards(…, until)"
This reverts commit 392fd004d9.
2024-06-03 09:09:57 +02:00
Benjamin Bouvier 6012c7d98b chore: remove unused dependencies
Thanks cargo-machete.
2024-05-31 17:26:57 +02:00
Richard van der Hoff b029519248 utd hook: fix re-reporting of late-decrypted events (#3480)
If an event cannot be decrypted after a grace period, it is reported to the application (and thence Posthog) as a UTD event. Currently, if it is then successfully decrypted, the event is then re-reported as a "late decryption".

This does not match the expected behaviour in Posthog - an event is *either* a UTD, or a late decryption; it makes no sense for it to be both. This PR fixes the problem.

I've attempted to make the commits sensible, but I'm not entirely sure I've succeeded. The tests do pass after each commit, though. The interesting change itself is somewhere in the middle; there is non-functional groundwork before and cleanup afterwards.

---

* ui: Factor out UTD report code to a closure

For now, this doesn't help much, but in future there will be more logic here,
and it helps reduce the repetition between the delay and no-delay cases.

* ui: Convert UtdHookManager::pending_delayed to a HashMap

* ui: Store decryption time in `UtdHookManager::pending_delayed`

This is a step on getting rid of `known_utds`

* ui: Fix re-reporting of late decryptions

This fixes the problem where a message that was previously reported as a UTD,
and was then subsequently successfully decrypted, is then re-reported as a late
decryption. This artificially inflated the UTD metrics.

We do this by checking the `pending_delayed` list in `on_late_decrypt`, instead
of the `known_utds` list. There is some associated reordering of code to get
the locking right.

* ui: Remove unused "utd report time" from `UtdHookManager::known_utds`

* ui: Replace `UtdHookManager::known_utds` with `reported_utds`

Keep a list of the UTDs we've actually reported, rather than the union of those
we've reported together with those we might report in a while.

I find this much easier to reason about.

* Address minor review comments

* Reinstate assertion in UTD hook tests

* Reinstate `known_utds`
2024-05-31 14:24:38 +02:00
Stefan Ceriu 61440c3561 ffi: enable panic logging for all supported platforms not only android 2024-05-31 09:06:24 +02:00
Jonas Platte 9c4e547f5a ci: Error if coverage report files are not found 2024-05-30 20:22:47 +02:00
Jonas Platte fa3db13cec ci: Update coverage workflows to use the right file 2024-05-30 20:22:47 +02:00
Jonas Platte eff57ad483 ci: Use one artifact for all coverage files
Instead of three separate artifacts.
2024-05-30 20:22:47 +02:00
Jonas Platte 2c964b07ab ci: Fix bash syntax in last code_coverage job step
It was trying to execute `upload_coverage.yml` before.
2024-05-30 20:22:47 +02:00
Jonas Platte 8c5d60e539 ci: Normalize indentation in upload_coverage.yml 2024-05-30 20:22:47 +02:00
Jonas Platte 63d4b758f8 ci: Only run upload_coverage if coverage workflow succeeded 2024-05-30 20:22:47 +02:00
Jonas Platte 7876c37715 Fix trigger condition for new upload_coverage workflow 2024-05-30 15:25:41 +02:00
Damir Jelić 29f29e981e chore: Go back to depending on Ruma from the Ruma repo 2024-05-30 15:12:45 +02:00
Kévin Commaille 2163b282b5 sdk: Add method to request user identity from homeserver (#3469)
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-05-30 14:40:21 +02:00
Jonas Platte 40dc706270 Split codecov uploads into a separate workflow
… which runs in the context of the main repo even for PRs, and can be
retried individually without rerunning coverage collection.
2024-05-30 13:53:49 +02:00
Hubert Chathi 0c97c85aea add tests for unknown properties in device keys 2024-05-30 12:16:07 +02:00
Kévin Commaille 0db486b511 crypto: Add SasState::Created variant
To differentiate the SAS state between the party
that sent the verification start and the party that received it.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-05-30 12:09:46 +02:00
Stefan Ceriu 7551d87384 feat: add support for m.call.notify events in the timeline and as a last room message 2024-05-30 11:27:30 +02:00
Damir Jelić 3ac598666a bindings: Remove the InvalidQrCode error variant for the QR login error type. (#3481)
We have a separate error for the QR code decoding method.
2024-05-29 14:40:22 +02:00
Damir Jelić 1380af4f00 bindings: Even more precise errors for the QR code login 2024-05-29 13:45:55 +02:00
Damir Jelić ab08f5e095 bindings(qr): Add an error variant for when the other device is not signed in 2024-05-29 13:45:55 +02:00
Damir Jelić 59d1f349b5 bindings: Expose the method to log in the client using a QR code
Co-authored-by: Benjamin Bouvier <public@benj.me>
2024-05-29 08:59:23 +02:00
Damir Jelić 3dbf8a07bd bindings: Move the OIDC metadata validation method into a TryInto method 2024-05-29 08:59:23 +02:00
Benjamin Bouvier 392fd004d9 Revert "feat(sdk): Add RoomPagination::run_backwards(…, until)" 2024-05-28 18:30:43 +02:00
Ivan Enderlin 72314f1014 feat(sdk): Add RoomPagination::run_backwards(…, until)
feat(sdk): Add `RoomPagination::run_backwards(…, until)`
2024-05-28 16:03:17 +02:00
Ivan Enderlin 9a1de1d9e8 test(sdk): Improve tests around RoomPagination::run_backwards. 2024-05-28 15:43:01 +02:00
Damir Jelić 7dd08c3b81 Add an example for the QR code login 2024-05-28 12:43:49 +02:00
Damir Jelić e6dc24a914 feat: Add support to log in using a QR code
This implements one part of MSC4108[1], it implements the case where the
new device scans the QR code.

[1]: https://github.com/matrix-org/matrix-spec-proposals/pull/4108
2024-05-28 12:43:49 +02:00
Damir Jelić 05f9f85d2d Make errors public 2024-05-28 12:43:49 +02:00
Damir Jelić 96c5515b04 Add a method to ensure device keys are uploaded 2024-05-28 12:43:49 +02:00
Damir Jelić e94b40a75f chore: Add the import secrets bundle method 2024-05-28 12:43:49 +02:00
Damir Jelić dc60c1ee10 chore: Allow setting a custom vodozemac account 2024-05-28 12:43:49 +02:00
Damir Jelić 3e6347cd48 chore: Create a subdirectory for authentication 2024-05-28 12:43:49 +02:00
Ivan Enderlin 7377971da8 test(sdk): Ensure that until can trigger multiple iterations.
This patch adds a test for `until` when it returns
`ControlFlow::Continue` multiple times instead of `ControlFlow::Break`
immediately.
2024-05-28 11:34:05 +02:00
Ivan Enderlin 13df5d9db8 feat(sdk): Add TimelineHasBeenResetWhilePaginating.
This patch adds a new argument to the `until` argument closure of
`RoomPagination::run_backwards`: `timeline_has_been_reset`, which
designates when the timeline has been reset.

A test has been updated accordingly.
2024-05-28 11:32:24 +02:00
Ivan Enderlin 664a64b3f3 feat(sdk): Improve RoomEventCacheUpdate (#3471)
* chore(sdk): Rename `RoomEventCacheUpdate::UpdateReadMarker`.

This patch renames `RoomEventCacheUpdate::UpdateReadMarker` to
`ReadMarker`. The `Update` prefix is already part of the enum name.

* feat(sdk): Rename `RoomEventCacheUpdate::ReadMarker::event_id` to `move_to`.

This patch renames `RoomEventCacheUpdate::ReadMarker::event_id` to
`ReadMarker::move_to` as I feel like it conveys a better semantics.

* feat(sdk): Extract `RoomEventCacheUpdate::Append::ambiguity_changes`.

This patch extracts `RoomEventCacheUpdate::Append::ambiguity_changes`
into a new variant `RoomEventCacheUpdate::Members { ambiguity_changes }
`.

This patch also creates a new private
`RoomEventCacheInner::send_grouped_updates_for_events` method to ensure
the updates are sent in a particular order.

* feat(sdk): Rename `RoomEventCacheUpdate::Append`.

This patch renames `RoomEventCacheUpdate::Append` to `SyncEvents`. The
field `events` is renamed `timeline`.

This patch also renames some variables to clarify the code and to match
the renamings in `RoomEventCacheUpdate`.

* feat(sdk): Rename `RoomEventCacheUpdate::ReadMarker` and `Members`.

This patch renames `ReadMarker { move_to: … }` to `MoveReaderMarkerTo
{ event_id: … }`.

This patch also renames `Members` to `UpdateMembers`.

Finally, this patch renames some other variables to avoid clashes with
terminology in `matrix_sdk_ui`.

* feat(sdk): Split `RoomEventCacheUpdate::SyncEvents`.

This patch splits `RoomEventCacheUpdate::SyncEvents` into 2 new variants:
`AddTimelineEvents` and `AddEphemeralEvents`.

This patch takes this opportunity to update `matrix_sdk_ui::timeline`
a little bit too. `handle_sync_events` is renamed
`handle_ephemeral_events`, and the `SyncTimelineEvent` argument is
removed: it's possible to use `add_events_at` directly to handle the
`SyncTimelineEvent`s.

* fix(sdk): Do not send `RoomEventCacheUpdate` if values are empty.

This patch prevents sending useless `RoomEventCacheUdpate` if their
respective values are empty.

* chore(ui): Update a log message.

* Apply suggestions from code review

Signed-off-by: Benjamin Bouvier <public@benj.me>

---------

Signed-off-by: Benjamin Bouvier <public@benj.me>
Co-authored-by: Benjamin Bouvier <public@benj.me>
2024-05-28 09:26:38 +00:00
Ivan Enderlin 6c90f7aaff feat(sdk): Add RoomPagination::run_backwards(…, until).
This patch adds a new argument to `RoomPagination::run_backwards`:
`until`. It becomes:

    pub async fn run_backwards<F, B, Fut>(&self,
        batch_size: u16,
        mut until: F
    ) -> Result<B>
    where
        F: FnMut(BackPaginationOutcome) -> Fut,
        Fut: Future<Output = ControlFlow<B, ()>>,

The idea behind `until` is to run pagination _until_ `until` returns
`ControlFlow::Break`, otherwise it continues paginating.

This is useful is many scenearii (cf. the documentation). This is
also and primarily the first step to stop adding events directly from
the pagination, and starts adding events only and strictly only from
`event_cache::RoomEventCacheUpdate` (again, see the `TODO` in the
documentation). This is not done in this patch for the sake of ease
of review.
2024-05-28 10:55:13 +02:00
Ivan Enderlin eddaf961a1 Merge pull request #3462 from matrix-org/valere/binding_ffi_crypto_expose_clear_caches
FFI Bindings: Expose CryptoStore clear caches
2024-05-28 10:50:27 +02:00
Valere 0e456cded2 review: cargo fmt 2024-05-27 16:14:49 +02:00
Valere a042b3d409 FFI Bindings: Review, remove runtime block_on, use await
Co-authored-by: Ivan Enderlin <ivan@mnt.io>
Signed-off-by: Valere <bill.carson@valrsoft.com>
2024-05-27 12:49:59 +02:00
Ivan Enderlin 16891ff937 feat(sdk): Mutation-based testing and property-based testing for LinkedChunk
feat(sdk): Mutation-based testing and property-based testing for `LinkedChunk`
2024-05-27 11:35:49 +02:00
Benjamin Bouvier 70403b5d9a nit: address typo
Signed-off-by: Benjamin Bouvier <public@benj.me>
2024-05-27 10:32:19 +02:00
Benjamin Bouvier 6a8dd30f26 fixup! rooms: use the heroes names if provided to compute the display name 2024-05-27 10:32:19 +02:00
Benjamin Bouvier 75d6a048b9 room names: better handle the unfortunate case where there are no heroes 2024-05-27 10:32:19 +02:00
Benjamin Bouvier d186e735d3 rooms: use the heroes names if provided to compute the display name 2024-05-27 10:32:19 +02:00
Benjamin Bouvier 75c4cebdb6 sliding sync: also save the heroes' names from sync 2024-05-27 10:32:19 +02:00
Benjamin Bouvier 56be9d5461 sdk-base: store heroes as OwnedUserIds in our own RoomSummary
This is the right goal, and Ruma will be updated to reflect that the
`heroes` field should contain `OwnedUserId` too in [1].

This simplifies the code a bit, and avoids a round-trip encoding
user-ids into a string then decoding them from a string later, in the
case of sliding sync and room name computation.

[1] https://github.com/ruma/ruma/pull/1822
2024-05-27 10:32:19 +02:00
Benjamin Bouvier 2851a42fed sliding sync: save UserIds in the room_summary.heroes field 2024-05-27 10:32:19 +02:00
Benjamin Bouvier 58cbc0ffaa multiverse: add support for room names
Since rendering is sync, and I want the computed display name (which
retrieval is async), I have to fetch the display name early, just after
getting the room. Oh well :)
2024-05-27 10:32:19 +02:00
Ivan Enderlin 93fa01f7f5 feat(ui): Enable include_heroes for all_rooms and visible_rooms. 2024-05-27 10:32:19 +02:00
Ivan Enderlin 4892fce37c feat(sdk): Add include_heroes as a sticky parameter for SlidingSyncList. 2024-05-27 10:32:19 +02:00
Ivan Enderlin cedcda5372 feat(base+ffi): SlidingSync consumes heroes from a response.
This patch does 3 things:

1. It updates Ruma to the latest revision at the time of writing,
2. It updates `matrix-sdk-ffi` to provide the
   `RoomSubscription::include_heroes` field,
3. It updates `matrix-sdk-base` so that SlidingSync consumes `heroes`
   from the response and update the `RoomSummary` accordingly.

A test has been added to ensure the `RoomSummary` is updated as expected.
2024-05-27 10:32:19 +02:00
Ivan Enderlin 78433d3dc7 test(sdk): Do not run proptest on wasm32. 2024-05-27 10:05:43 +02:00
Ivan Enderlin db9e6518ed Merge pull request #3463 from matrix-org/valere/fix_up_crypto_0.7.1_release_branch_not_merged
chore(crypto): Fixup version and changelog from patch release
2024-05-27 09:44:01 +02:00
Ivan Enderlin 4c9398f6bd test(sdk): Use property-based testing to test AsVector.
This patch adds property-based testing to test `AsVector`. In this case
it works pretty well.
2024-05-27 09:21:43 +02:00
Ivan Enderlin 3ef8cb2f92 chore(sdk): Add missing derive(Debug). 2024-05-27 09:21:43 +02:00
Ivan Enderlin bbe9d75bd6 fix(sdk): Drain Updates when building AsVector.
This patch fixes a bug found with the `as_vector` fuzz test where the
`Updates` weren't drained when building `AsVector`.
2024-05-27 09:21:43 +02:00
Ivan Enderlin 8d6f88f612 test(sdk) Add a test for Chunk::is_first_chunk and Chunk::is_last_chunk.
This patch is testing two more methods on `Chunk`: `is_first_chunk` and
`is_last_chunk`. It's been detected by a mutant with `cargo-mutants`.
2024-05-27 09:21:40 +02:00
Valere 8cf52972bb ffi-crypto-bindings: Improve comments 2024-05-24 16:13:31 +02:00
Valere e99b67c281 chore(crypto): Fixup version and changelog from patch release 2024-05-24 16:03:03 +02:00
Valere 1985eede8f Changelog: Update crypto crate changelog 2024-05-24 15:09:31 +02:00
Valere 0f5f71f07a FFI Bindings: Expose CryptoStore clear caches 2024-05-24 14:59:35 +02:00
Richard van der Hoff 1dc370942b Merge pull request #3456 from matrix-org/rav/fix_fix_backup_import
crypto: Wire up `save_inbound_group_sessions` to `room_keys_received` stream
2024-05-24 10:32:49 +01:00
Benjamin Bouvier e0d7f4d9c6 timeline: make live_back_pagination_status available only on live timelines
It doesn't make sense to expose it for a focused timeline.

Note there's no way for timeline to change focus, at the moment; this
would require special handling here, because one could subscribe to the
back pagination status on a live timeline first, then switch the
timeline to the focus mode. The stream wrapper could then observe other
states that aren't expected by the converter method.
2024-05-24 11:21:34 +02:00
Benjamin Bouvier aebfaf58a3 timeline: reintroduce a custom pagination status that indicates if we've hit the timeline start
This is actually required for one use case: if the event cache triggers
back-pagination in the background *before* a timeline is opened, it's
possible the timeline observes pagination is running at the beginning,
and doesn't know if more back-pagination is required or not.

This wraps the `Paginator::status` stream by reading the
hit_timeline_start() from the room pagination and adding it to the
`Idle` state.
2024-05-24 11:21:34 +02:00
Benjamin Bouvier 0d4c5c7f49 paginator: add a method to retrieve the current pagination status
i.e. did we hit the timeline start/end, after paginating sufficiently?
2024-05-24 11:21:34 +02:00
Damir Jelić 2de2bc658c feat(sdk): Return the Curve25519Public key type instead of a string (#3450) 2024-05-24 11:17:56 +02:00
Damir Jelić 15c4ba2fb9 feat(crypto): Allow the explicit upload of the device keys (#3457) 2024-05-24 11:15:33 +02:00
Damir Jelić bb05b904cf feat(crypto): Allow the creation of an OlmMachine using a custom Account (#3451) 2024-05-24 10:54:21 +02:00
Damir Jelić 110d67cc62 feat(crypto): If available, sign the new device keys using the cross-signing keys (#3453) 2024-05-24 10:38:43 +02:00
Stefan Ceriu 03069f7acf fix: fix what permissions get_element_call_required_permissions returns and have them match what Element Call actually expects 2024-05-24 10:25:04 +02:00
Johannes Marbach f7aee0ee36 Update JS bindings link
Signed-off-by: Johannes Marbach <johannesm@element.io>
2024-05-23 19:54:47 +02:00
Ivan Enderlin e9dc02ae17 Merge pull request #3392 from Hywan/feat-sdk-linked-chunk-subscribe-as-vector 2024-05-23 19:02:45 +02:00
Benjamin Bouvier 11d66979d6 crypto(nit): remove unnecessary path qualifier in a test
The compiler has been pestering me with this, so here's a fix.
2024-05-23 18:52:14 +02:00
Richard van der Hoff 7e44fbca79 crypto: Wire up save_inbound_group_sessions to room_keys_received stream
https://github.com/matrix-org/matrix-rust-sdk/pull/3448 added a new method
`save_inbound_group_sessions` to `CrytoStore`, but forgot to wire it up to the
`room_keys_received` stream.
2024-05-23 17:08:58 +01:00
Richard van der Hoff dcc32da55a Merge pull request #3448 from matrix-org/rav/fix_backup_import
Crypto: fix backed-up keys being re-backed-up
2024-05-23 16:20:32 +01:00
Ivan Enderlin 52c0614199 doc(sdk): Fix tiny typos. 2024-05-23 16:54:23 +02:00
Richard van der Hoff 0777aa6ece crypto: Remove Olm::import_room_keys altogether 2024-05-23 15:53:21 +01:00
Richard van der Hoff 3945071446 crypto: Update changelog 2024-05-23 15:53:16 +01:00
Richard van der Hoff 05e4d7a502 ffi: Deprecate import_decrypted_room_keys
... and expose a new method `import_room_keys_from_backup` which does the right
thing.
2024-05-23 15:52:22 +01:00
Richard van der Hoff ba38d0c1de sdk: avoid deprecated BackupMachine::import_backed_up_room_keys
... and use its replacement, `Store::import_room_keys`
2024-05-23 15:52:22 +01:00
Richard van der Hoff f7cc17e1e0 crypto: Deprecate BackupMachine::import_backed_up_room_keys
This whole method is a bit broken. It assumes that, when we did an import from
backup, the backup that they came from is the same as the "current" version.

We *could* add another argument, but to be honest I find the whole method a bit
pointless. It's not particularly tied to the `BackupMachine` abstraction. Let's
instead expose `Store::import_room_keys` and
`ExportedRooomKey::from_backed_up_room_key` publicly, and tell callers to use
that directly.
2024-05-23 15:52:22 +01:00
Richard van der Hoff f77d2cd83f crypto: Use new CryptoStore::save_inbound_group_sessions method
When we are importing a batch of room keys, use the newly-added
`CryptoStore::save_inbound_group_sessions` method instead of
`CryptoStore::save_changes`.

To do this, we need to pass the backup version into `Store::import_room_keys`
instead of just `from_backup` flag.
2024-05-23 15:52:22 +01:00
Richard van der Hoff 4cd619ccdd crypto: New method CryptoStore::save_inbound_group_sessions
When we add a batch of inbound group sessions to the store, if they came from a
backup, we need to record which backup version they came from.
`CryptoStore::save_changes` doesn't give us an easy way to set the backup
version (we could add it to the `Changes` struct, but ugh).

So, we add a new method `save_inbound_group_sessions` which takes the backup
version as a separate param. This works fine, because whenever we import
sessions there are no other changes to store.

The new method isn't used outside of tests yet -- that comes in a follow-up
commit.
2024-05-23 15:52:22 +01:00
Richard van der Hoff 66aae2a0b5 crypto: Add a failing test demonstrating our problem 2024-05-23 15:52:22 +01:00
Damir Jelić 7fb57ea271 chore: Move the cross-process lock enabling into a separate method 2024-05-23 15:31:25 +02:00
Damir Jelić 4d9e41871e chore: The e2ee initialization tasks method doesn't need to return an error 2024-05-23 15:31:25 +02:00
Stefan Ceriu f672f17fcf feat(calls): add support for sending Matrix RTC call notifications 2024-05-23 15:07:13 +02:00
Ivan Enderlin 39a6a2eb8c chore(sdk): Rename Update::PushItems::position_hint to …::at. 2024-05-23 13:40:08 +02:00
Benjamin Bouvier 13ceb3e745 sdk: make use of the WeakClient in the encryption/ directory too 2024-05-23 12:20:17 +02:00
Benjamin Bouvier 6250677493 sdk: move the WeakRoom into room/mod.rs
This moves code around, and tweaks the behavior:

- `WeakRoom::get()` returns an `Option`, that will be None if the client
is missing or the room is missing.
- `PaginableRoom` for `WeakRoom` will now return a default response if
the room could not be reconstructed from the weak room. It's fine to do
so because we're in a shutdown context.
2024-05-23 12:20:17 +02:00
Benjamin Bouvier f1dcfd6332 event cache: keep a weak link to the room when paginating 2024-05-23 12:20:17 +02:00
Benjamin Bouvier c40b3e768e sdk: add failing test for the strong Client <-> EventCache cycle 2024-05-23 12:20:17 +02:00
Benjamin Bouvier 3eaac27789 sdk: introduce a WeakClient data structure 2024-05-23 12:20:17 +02:00
Benjamin Bouvier affb5d195e day dividers: remove all the trailing day dividers if needs be
multipletrailing
2024-05-23 12:19:07 +02:00
Benjamin Bouvier 7995c046b4 day dividers: tweak invariant
It's possible the timeline starts with a read marker, in which case the
first item won't be a day divider; in that case, check for the next
item, if present.

test_start_with_read_marker
2024-05-23 12:19:07 +02:00
Benjamin Bouvier 612ed3b603 day dividers: don't remove the final entry if it was already scheduled for removal 2024-05-23 12:19:07 +02:00
Ivan Enderlin ba1c797db4 chore(sdk): Rename Updates to ObservableUpdates. 2024-05-23 11:45:34 +02:00
Ivan Enderlin e3fdf19843 doc(sdk): Improve the documentation of AsVector. 2024-05-23 10:43:13 +02:00
Ivan Enderlin c1061150a9 chore(sdk): derive(Clone) is implemented if all parameters are Clone. 2024-05-23 10:06:18 +02:00
Ivan Enderlin c5f4168dd6 Merge pull request #3442 from matrix-org/rav/no_device_update_on_unchanged
crypto: emit no `identities_stream` items on no-op changes
2024-05-23 09:31:15 +02:00
Ivan Enderlin 7ea804bd2a Merge pull request #3443 from matrix-org/valere/apple_binding_update_podspec
Apple Bindings | Update SDKCrypto podspec files
2024-05-23 09:23:55 +02:00
Valere 748c3d514a Apple Bindings | Update SDKCrypto podspec files 2024-05-22 19:50:37 +02:00
Richard van der Hoff 818778cdf3 Add a test for invalid responses
This was untested before, and it seems the coverage gate is now sad.
2024-05-22 17:23:11 +01:00
Richard van der Hoff 2a605deaa5 changelog 2024-05-22 13:42:57 +01:00
Richard van der Hoff a154cd4640 crypto: emit no stream update for unchanged devices
There is no need to emit a notification from `identities_stream` when all
devices are unchanged since last time.
2024-05-22 13:42:57 +01:00
Richard van der Hoff eee0dc4e87 crypto: indicate when a device was updated
update `ReadOnlyDevice::update_device` to return a bool indicating whether
anything is changing.
2024-05-22 13:42:57 +01:00
Ivan Enderlin 28a8ce1732 chore(sdk): Make explicit a hidden lifetime. 2024-05-22 13:59:39 +02:00
Ivan Enderlin 3d3639a923 chore(sdk): Replace into_iter by iter. 2024-05-22 13:55:03 +02:00
Ivan Enderlin 57d454c557 chore(sdk): pin-project-lite is no longer required. 2024-05-22 13:54:00 +02:00
Ivan Enderlin 94fe6a9876 test(sdk): More tests for AsVector.
This patch adds another check to ensure `AsVector` generates
`VectorDiff`s that, once combined, produce an expected `Vector`. It
avoids errors when unit testing `VectorDiff` alone.
2024-05-22 13:28:29 +02:00
Ivan Enderlin c9086a436b fix(sdk): Ensure an underflow is not possible.
This patch ensures that an underflow is not possible when the length
of `chunks` is 0. In practise, it's not possible because there is
_always_ one chunk inside `LinkedChunk`, but it's better to have good
code habits.
2024-05-22 12:15:48 +02:00
Ivan Enderlin 87370abea4 chore(sdk): Remove a useless Option. 2024-05-22 12:15:00 +02:00
Ivan Enderlin fa554455b7 Merge pull request #3334 from matrix-org/valere/fix_crypto_binding_apple_script
crypto: Apple Crypto Bindings | Fix crypto xcframework script
2024-05-22 11:43:47 +02:00
Valere b430d95c0a Workflow | only add the needed target for script 2024-05-22 11:29:01 +02:00
Ivan Enderlin b4b2ee4716 chore(sdk): Move code inside the same module. 2024-05-22 10:24:36 +02:00
Ivan Enderlin ea6e15086e feat(sdk): as_vectors are no longer unsafe.
This patch removes the `unsafe` part of `as_vector`. The idea is to
pass `Iter` (the forward iterator of `Chunk`) to `AsVector` so that it
internally computes `initial_chunk_lengths`. The shape of this data must
no longer be guaranteed by the caller.

This patch goes a bit further: `UpdateToVectorDiff` has
a new constructor which consumes this `Iter` and builds
`initial_chunk_lengths` itself. Even better!

Finally, `Updates::as_vector` is removed. It's clearly no longer
necessary and it was creating borrowing issues anyway with the new code
structure.
2024-05-22 10:16:02 +02:00
Richard van der Hoff d7a887766c indexeddb: expose new method IndexeddbCryptoStore::open_with_key (#3423)
Allow applications to skip the PBKDF2 operation if they already have a cryptographically secure key,
instead using a simple HKDF to derive a key.

In order to maintain compatibility for existing element-web sessions, if we discover that we have an
existing store that was encrypted with a key derived from PBKDF2, then we reconstruct what
element-web used to do: specifically, we base64-encode the key to obtain the "passphrase" that
was previously passed in. If that matches, we know we've got the right key, and can update the
meta store accordingly.

Part of a resolution to element-hq/element-web#26821.

Signed-off-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
Co-authored-by: Damir Jelić <poljar@termina.org.uk>
2024-05-22 09:07:45 +01:00
Valere ee040aba60 split for do in several lines 2024-05-22 09:55:25 +02:00
Valere f7e06d0c20 Generate ffi files only using aarch64-apple-ios 2024-05-22 09:55:25 +02:00
Valere d2ecf461d0 fix script 2024-05-22 09:55:25 +02:00
Valere a1bbe9d810 reduce build time of CI check 2024-05-22 09:55:25 +02:00
Valere 20ada4014d fix target name 2024-05-22 09:55:24 +02:00
Valere 604190d3ca CI: Test CrypoFFI XCFramework generation 2024-05-22 09:55:24 +02:00
Valere 6ad26fff5c remove unneeded \ at end of script 2024-05-22 09:54:43 +02:00
Valere de989b2c51 fmt 2024-05-22 09:54:43 +02:00
Valere ea4737269f Fix crypto xcframework apple bindings 2024-05-22 09:54:43 +02:00
Ivan Enderlin bf39976d21 doc(sdk): Add a useful inline documentation. 2024-05-22 09:36:15 +02:00
Ivan Enderlin ad9c2acef1 chore(sdk): Rename ReattachItems and ReattachItemsDone.
This patch renames `ReattachItems` to `StartReattachItems` and
`ReattachItemsDone` to `EndReattachItems`. This naming conveys better
the idea of a _state transition_.
2024-05-22 09:33:36 +02:00
Ivan Enderlin 5ac5e04fb8 doc(sdk): Fix or add missing documentation. 2024-05-22 09:23:42 +02:00
Kegan Dougal 794b11a0ce ci: Add a step running complement crypto (#3400)
Add a CI step running complement crypto, automatically matching the complement-crypto branch name based on the current branch name, if needs be.

Signed-off-by: Kegan Dougal <7190048+kegsay@users.noreply.github.com>
2024-05-21 16:34:39 +02:00
Benjamin Bouvier dba7cf39e6 day dividers: record the insert position when applying an operation based on the previous item
We could end up, like in the regression test, with a sequence of
operations like that:

- remove day divider @ i+1 (because it's redundant with one @ i)
- remove day divider @ i (because it's useless, since the event before
the day divider and after the day divider use the same date).

In that case, it would break the non-decreasing invariant: we'd apply an
operation on the array @ i+1, then @ i, which troubles the offset
computation.

Instead, when doing an operation based on the "prev_item" (now with a
small helper struct, to facilitate understanding of each field), we also
record the insertion order for the operation itself: it's always "at the
end of the operation order, at the time we're looking at it", so
equivalent to a "push_back" if there's no operation in between; but that
ensures that we'll do the operation in a non-decreasing order. For
instance in the above test case, the Remove(i) is now inserted before
the Remove(i+1), instead of after.
2024-05-21 12:45:59 +02:00
Benjamin Bouvier 1a872ac383 day dividers: only run the poisoning check for DayDividerAdjuster::drop if we're not already panicking 2024-05-21 12:45:59 +02:00
Andy Balaam 7bce12ca70 Merge pull request #3320 from matrix-org/andybalaam/fast-backup-reset-in-memorystore2
crypto: MemoryStore uses backup versions to track which sessions are backed up
2024-05-21 09:57:26 +01:00
Andy Balaam 2652b77a1b crypto: MemoryStore uses backup versions to track which sessions are backed up 2024-05-21 09:44:39 +01:00
Andy Balaam f310db44a3 crypto: Test for resetting backups by asking for new version 2024-05-21 09:43:40 +01:00
Benjamin Bouvier 5df53d7338 timeline queue refactoring: address review comments 2024-05-20 11:18:43 +02:00
Benjamin Bouvier 9575ee92d4 timeline queue: unify updating event send state into a single place 2024-05-20 11:18:43 +02:00
Benjamin Bouvier e49d62988b timeline queue: tiny refactorings
A few renamings here and there, making use of `as_variant!` a bit more,
adding a few comments,…
2024-05-20 11:18:43 +02:00
Benjamin Bouvier 8867a03c07 memory state store: correctly save user avatar url
With a regression test.

Fixes #3432.
2024-05-20 11:03:07 +02:00
Kévin Commaille 6c18bcf748 sdk: Improvements around generate_image_thumbnail (#3415)
* sdk: Return a Thumbnail from generate_image_thumbnail

We have already all the data for it.
Also fixes an error where the thumbnail format was assumed to always be
JPEG.

* sdk: Allow to select the format of the generated thumbnail

Sending an attachment could often fail if the image crate
cannot encode the thumbnail to the same format as the original.
This allows to select a known supported format to always
be able to generate a thumbnail.

* sdk: Do not return error of thumbnail generation for SendAttachment

Since the thumbnail is optional, failing to generate it should not
stop us from sending the attachment.

* Apply code review fixes
* sdk: Split attachment tests in separate file
* sdk: Add integration tests for generating thumbnails
* Revert wiremock debug log level

---------

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-05-17 16:48:59 +02:00
Benjamin Bouvier 4cc67e9002 room list/notification services: don't request the room avatar since it's always provided
It's always provided in the `avatar` response in the field, which
sliding sync's using by default, so there's no need to request the
`m.room.avatar` event too.
2024-05-17 15:14:47 +02:00
Benjamin Bouvier bac0654a63 sliding sync: don't store the server-computed name in place of the raw name event
If we want to be able to note the absence of a room name, we shouldn't
take the name returned by the server (which may be computed, and thus
always be non-null). This way, we can expose both the name contained in
the m.room.name event as well as the computed name everywhere.

A consequence of this is that the room list service must now ask for the
m.room.name event as part of the required state for every room.
2024-05-17 15:14:47 +02:00
Valere 6111beded7 ffi: Expose ed25519/curve25519 keys in bindings (#3420) 2024-05-17 13:55:18 +02:00
Benjamin Bouvier b0558a002b day divider: don't recall a previous item if it's scheduled for deletion
With a regression test that didn't pass on main, and would incorrectly
remove the read marker, because it tried to replace the day divider at
(4), that was just scheduled for deletion in the previous loop
iteration.
2024-05-17 11:59:40 +02:00
Benjamin Bouvier c6f4ca09f5 day divider: simplify control flow in handle_event 2024-05-17 11:59:40 +02:00
Benjamin Bouvier 532f3a3ee8 day divider: add new invariant, a read marker should not disappear 2024-05-17 11:59:40 +02:00
Jorge Martín 3914e31461 ffi: Add the user's display name to RoomMembership timeline content
This is useful to properly format membership state events.
2024-05-17 10:45:48 +02:00
Damir Jelić a48d604b3f chore: Downgrade prost-derive, since the latest version was yanked 2024-05-17 10:40:31 +02:00
Benjamin Bouvier e486da4b08 cross-process lock: add a log line when aborting the previous renew task 2024-05-16 17:16:15 +02:00
Ivan Enderlin 67e5820643 feat(sdk): AsVectorSubscriber becomes AsVector.
This patch removes the possibility to have `LinkedChunk` as an
`ObservableVector` via a `Stream`, which was initially the goal of
`AsVectorSubscriber`. Having a `Stream` was more complex than required
for the integration inside `EventCache`. This patch keeps the same code
but renames `AsVectorSubscriber` into `AsVector`. A new internal type,
`UpdateToVectorDiff`, applies the algorithm itself and maintains its
own state, making it possible to re-introduce a `Stream` later if we
want to.
2024-05-16 16:57:01 +02:00
Benjamin Bouvier 7ae0bcecfd room preview: rejigger public API to pass a RoomOrAliasId in place of a RoomId to get_room_preview 2024-05-16 10:58:41 +02:00
Benjamin Bouvier 1fd29f7b6d room preview: allow passing through a list of servers to discover a room with MSC3266
Fixes #3395.`
2024-05-16 10:58:41 +02:00
Benjamin Bouvier c8f6fe4f6d event cache/timeline: reuse the Paginator when running back-paginations (#3373)
* event cache: reuse the paginator internally

Fixes #3355.

* event cache: move the `pagination_token_notifier` into the `RoomPaginationData` as well

* event cache: introduce a `RoomPagination` API object and move code around

Only code motion. No changes in functionality.

* event cache: remove "paginate" (et al.) in `RoomPagination` method names

No changes in functionality, just renamings.

* event_cache/timeline: have the event cache handle restarting a back-pagination that failed under our feet

When a timeline reset happens while we're back-paginating, the event
cache method to run back pagination would return an success result
indicating that the pagination token disappeared. After thinking about
it, it's not the best API in the world; ideally, the backpagination
mechanism would restart automatically.

Now, this was handled in the timeline before, and the reason it was
handled there was because it was possible to back-paginate and ask for a
certain number of events. I've removed that feature, so that
back-pagination on a live timeline matches the capabilities of a
focused-timeline back-pagination: one can only ask for a given number of
*events*, not timeline items.

As a matter of fact, this simplifies the code a lot by removing many
data structures, that were also exposed (and unused, since recent
changes) in the FFI layer.

* Address review comments
2024-05-16 10:22:05 +02:00
Damir Jelić 21804ab313 chore(crypto): Add a missing changelog entry 2024-05-16 09:33:12 +02:00
Ivan Enderlin 14252807a2 Merge pull request #3418 from zecakeh/attachment-mentions
sdk: Allow to send mentions with attachments
2024-05-16 09:06:01 +02:00
Ivan Enderlin d1fad85c5f chore(sdk): Make Clippy happy. 2024-05-16 08:47:42 +02:00
Ivan Enderlin 38932e7e03 doc(sdk): Add moooooar documentation.
This patch adds documentation that explains how `AsVectorSubscriber`
works.
2024-05-15 22:16:18 +02:00
Ivan Enderlin 397a970636 doc+test(sdk): Add documentation for AsVectorSubscriber + improve tests.
This patch add more documentation for `AsVectorSubscriber` and improve
the tests.
2024-05-15 22:16:18 +02:00
Ivan Enderlin 8d2db9d35a chore(sdk): assert_items_eq is shared amongst several test modules.
This patch moves the `assert_items_eq` macro in a place where it's
accessible to several test modules. This is going to be useful for next
patches.
2024-05-15 22:16:18 +02:00
Ivan Enderlin 8ee0bbb22e feat(sdk): Add Update::ReattachItems and Update::ReattachItemsDone.
This patch adds 2 new updates: `ReattachItems` and `ReattachItemsDone`.
It's useful to optimise insertion, esp. in `AsVectorSubscriber` but
almost maybe in database.
2024-05-15 22:16:18 +02:00
Ivan Enderlin 672bb0229b feat(sdk): Rename Update::TruncateItems to Update::DetachLastItems.
This patch renames `TruncateItems` to `DetachLastItems`. It's
technically the same things, but the fields are different: `chunk:
ChunkIdentifier` and `length: usize` become a unique `at: Position`. The
spirit is the same but the semantics is a bit different.

This patch, with this renaming, also prepares the next commits.
2024-05-15 22:09:01 +02:00
Ivan Enderlin b894b700c7 feat(sdk): Rename Update::InsertItems to Update::PushItems.
First off, this patch renames `Update::InsertItems` to
`Update::PushItems` because all items insertions happen at the end of
a chunk. Let's reflect that. `InsertItems` would have meant that it's
possible to insert at any position, but it's not what happens by design.

Second, this patch renames `Update::PushItems::at` to
`Update::PushItems::position_hint`. Indeed, the `at` field would have
meant that the position is specific whilst it's not. It's just a hint to
make the life of update readers simpler. It's also a good way to improve
performance in some cases: since items are pushed, to know the new
position of the items, one has to read the position of the previous last
item and compute the new position from there. Having `position_hint`
help to prevent this dance and save the cost of a reading. That's also
why the field has been renamed to `position_hint`, it's a hint.
2024-05-15 22:08:54 +02:00
Ivan Enderlin 9af57c7a60 feat(sdk) AsVectorSubscriber::new now receives the initial chunk lengths.
This patch updates the constructor of `AsVectorSubscriber` to receive
the initial chunk lengths so that this type doesn't have to guess what
to do when receiving an unknown chunk identifier. `AsVectorSubscriber`
is de facto synchronized with its source `LinkedChunk` when created.
2024-05-15 22:08:27 +02:00
Ivan Enderlin 725d7bbc97 !tmp First draft of the subscribe_as_vector API. 2024-05-15 22:05:52 +02:00
Ivan Enderlin 2d10ea4dc9 chore(sdk): Use pin-project-lite in matrix-sdk.
This patch moves the `pin-project-lite` dependency from `matrix-sdk-ui`
to the workspace, and uses it in `matrix-sdk`.
2024-05-15 22:05:52 +02:00
Kévin Commaille e50b574f12 sdk: Allow to send mentions with attachments
Particularly useful for captions

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-05-15 16:40:06 +02:00
Damir Jelić 35173347fd chore: Bump the vodozemac version
This gives us the necessary primitives for the QR code login feature.
2024-05-15 15:01:53 +02:00
Ivan Enderlin 64c5a83e33 Merge pull request #3413 from zecakeh/send-attachment-path
ui: Take a `PathBuf` to send an attachment
2024-05-15 13:24:09 +02:00
Kévin Commaille 8da3922ff0 sdk: Rename SendAttachment's url field to filename
It is name filename before and after, and it is not a url.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-05-15 13:00:49 +02:00
Kévin Commaille eba5efc829 Merge branch 'main' into send-attachment-path
Signed-off-by: Kévin Commaille <76261501+zecakeh@users.noreply.github.com>
2024-05-15 10:57:08 +02:00
Ivan Enderlin 7ed6db9758 Merge pull request #3406 from zecakeh/edit-without-relation
ui: Make Timeline::edit take a RoomMessageEventContentWithoutRelation
2024-05-15 10:55:21 +02:00
Kévin Commaille 32c7a1ab78 ui: Take a PathBuf to send an attachment
I found the previous API confusing. Firstly, the parameter name was "filename" when we want a file path.
Secondly, we take a `String` when we want a `Path`.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-05-15 10:50:26 +02:00
Damir Jelić cbb92cacce feat(crypto): Add support to import/export the newly added secrets bundle 2024-05-14 11:46:56 +02:00
Damir Jelić 402d620608 feat(crypto): Add a SecretsBundle type 2024-05-14 11:46:56 +02:00
Doug b57dbd8d1a xtask: Allow passing multiple targets to Swift's build-framework.
* Fix CI
2024-05-14 11:33:13 +02:00
Damir Jelić aa6bbc1a0f feat(crypto): Add data types to parse QR codes from MSC4108 2024-05-14 10:47:22 +02:00
Damir Jelić 6672302684 chore: Make the url crate a workspace dependency 2024-05-14 10:47:22 +02:00
Kévin Commaille 9e4125bb39 ui: Make Timeline::edit take a RoomMessageEventContentWithoutRelation
Like send_reply.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-05-13 20:25:44 +02:00
Kévin Commaille cb452802bb chore: Upgrade ruma
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-05-13 20:25:43 +02:00
Benjamin Bouvier da249bbc51 crypto: remove the fake crypto store test for olm session wedging
Two reviewers were suspicious the test wasn't very useful, so I propose
to hereby remove it.
2024-05-13 18:30:25 +02:00
Benjamin Bouvier c16bfd3234 timeline: reuse internal id when adding pending replied-to details to an item
Fixes #3379.
2024-05-13 18:29:34 +02:00
Benjamin Bouvier 83427b325c ci: use the latest synapse-service image with msc3266
And re-enable the room preview test there.
2024-05-13 18:11:07 +02:00
Andy Balaam b99e103704 Merge pull request #3409 from matrix-org/andybalaam/disable-flaking-nse-test
Ignore a flaking test
2024-05-13 16:55:17 +01:00
Andy Balaam 6d6f470e11 Ignore a flaking test 2024-05-13 16:42:22 +01:00
Benjamin Bouvier 94d3758a0d base: sort the heroes in the computed display name alphabetically 2024-05-13 15:11:57 +02:00
Andy Balaam 4b1d03f229 Merge pull request #3343 from matrix-org/andybalaam/test-store-cache-drop
crypto: Add a standalone integration test for the NSE race
2024-05-13 14:09:40 +01:00
Andy Balaam 06825c6385 crypto: Test for the NSE race bug #3110
Adds a test for https://github.com/matrix-org/matrix-rust-sdk/issues/3110
that fails before the fix and passes afterwards.
2024-05-13 13:55:04 +01:00
Ivan Enderlin 2987bd1f6d chore(cargo) Update dependencies
chore(cargo) Update dependencies
2024-05-13 14:32:05 +02:00
Ivan Enderlin 099cd8d6a0 chore(sdk): Remove the need for cfg_vis.
It introduces more dependencies for —apparently— no useful need here.
2024-05-13 14:17:45 +02:00
Ivan Enderlin f669b3a530 chore(test): Use workspace dependencies. 2024-05-13 14:16:36 +02:00
Ivan Enderlin da8588787f chore(cargo): Declare reqwest as a workspace dependency. 2024-05-13 14:15:35 +02:00
Ivan Enderlin e21e412aae chore(cargo): Update dependencies. 2024-05-13 14:12:32 +02:00
Andy Balaam 749ed2c3e0 crypto: Allow duplicating a Client in tests 2024-05-13 12:17:11 +01:00
Benjamin Bouvier e709cca2f5 test utils: prefer From impl to Into impl
Thanks clippy, i guess?
2024-05-13 12:36:44 +02:00
Benjamin Bouvier f661b0d728 event cache: add a regression test for ignoring/unignoring at the event cache level 2024-05-13 12:36:44 +02:00
Benjamin Bouvier cef4409dda timeline: make use of the EventFactory in more tests 2024-05-13 12:36:44 +02:00
Benjamin Bouvier ac6fa7abb1 event cache: move reacting to (un)blocks in the event cache 2024-05-13 12:36:44 +02:00
Damir Jelić 9ef465fdf4 chore: Fix the formatting 2024-05-13 12:22:35 +02:00
Denis Kasak 11de0449fa Merge pull request from GHSA-9ggc-845v-gcgv
Avoid incorrect usage of private backup key
2024-05-13 10:07:10 +00:00
Ivan Enderlin 964553952d Merge pull request #3399 from matrix-org/stefan/invitesListCleanup
feat(ui): enable `room-list-with-unified-invites` by default, remove …
2024-05-13 11:51:10 +02:00
Ivan Enderlin 5c52014c4b Merge pull request #3386 from matrix-org/stefan/joinedRoomListFilter
feat(ui): add room list filter for excluding non-joined rooms
2024-05-13 11:24:13 +02:00
Stefan Ceriu 85d09c3c56 feat(ui): enable room-list-with-unified-invites by default, remove old invites sliding sync list. 2024-05-13 11:55:38 +03:00
Ivan Enderlin c0924c87af feat(sdk): Introduce linked_chunk::Updates
feat(sdk): Introduce `linked_chunk::Updates`
2024-05-12 17:42:29 +02:00
Kévin Commaille 733665ddcc ui: Expose message mentions
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-05-11 10:53:52 +02:00
Andy Balaam 2c57557a3a ci: Quieten hyper logs 2024-05-10 17:24:30 +01:00
Andy Balaam d5df58496b Merge pull request #3396 from zecakeh/ci-nightly
ci: Bump version of rust nightly
2024-05-10 16:27:14 +01:00
Valere df5e8e724e Review: better comments
Co-authored-by: Denis Kasak <dkasak@termina.org.uk>
Signed-off-by: Valere <bill.carson@valrsoft.com>
2024-05-10 15:49:20 +02:00
Valere a7cc3777d1 Review: better comment
Co-authored-by: Denis Kasak <dkasak@termina.org.uk>
Signed-off-by: Valere <bill.carson@valrsoft.com>
2024-05-10 15:49:02 +02:00
Kévin Commaille 4724115e8d chore: Fix docs warning
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-05-10 12:16:42 +02:00
Kévin Commaille e355a6aa39 ci: Bump version of rust nightly
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-05-10 11:35:19 +02:00
Kévin Commaille 99ae06be68 chore: Fix cfg options
Cargo nightly now checks whether a cfg option exists.
We need to declare the custom
options we use
and fix those that are wrong.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-05-10 11:34:59 +02:00
Kévin Commaille 787b2d31cd chore: Fix warnings during compilation
cargo says that default_features will not be supported anymore in 2024 edition

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-05-10 11:32:05 +02:00
Doug 23f17614e5 ffi: Allow joining a room ID with server names. 2024-05-09 19:32:16 +02:00
Doug eebbb74be7 ffi: Include servers when resolving a room alias.
Rename result.
2024-05-09 19:32:16 +02:00
Damir Jelić fac5ba5bae chore(crypto): Refactor the PK signing subkey constructors
This makes the public key fields private to ensure that we don't
accidentally swap them out. It also moves the construction of the
subkeys into the master key type.
2024-05-09 18:03:55 +02:00
Damir Jelić c57d2c68a1 fixup! chore(crypto): Refactor the cross-signing key wrappers 2024-05-09 17:41:32 +02:00
Damir Jelić 6b1ef484f2 chore(crypto): Refactor the cross-signing key wrappers
Since the master/self-signing/user-signing public key types are used for
public user identities as well as for the private key type we have, and
we'd like to sign the public key types it makes sense that the types
itself aren't using an Arc.

Let's instead put the Arc inside the user identity structs.

This will allow us later on to more easily sign the public key types.
2024-05-09 17:41:32 +02:00
Damir Jelić aeb85ba836 chore: Add a better debug implementation for the backup recover/decryption key 2024-05-09 17:40:51 +02:00
Damir Jelić afa3808752 chore: Use the released version of Ruma 2024-05-09 17:34:16 +02:00
Ivan Enderlin 1f26822a64 chore(sdk): Split linked_chunk into 2 modules. 2024-05-08 14:47:45 +02:00
Ivan Enderlin 44a78ba9f6 chore(sdk): Thanks Clippy. 2024-05-08 13:58:49 +02:00
Ivan Enderlin 1493dc2c6a chore(sdk): Remove the LinkedChunk prefix from type names. 2024-05-08 13:45:45 +02:00
Ivan Enderlin 9531a4041e feat(sdk): Allow LinkedChunkUpdatesInner to have multiple readers.
This patch removes the notion of `take` vs. `peek` from
`LinkedChunkUpdatesInner` and widens the problem to a more general
approach: `LinkedChunkUpdatesInner` must support multiple readers, not
only two (`take` was the first reader, `peek` was the second reader,
kind of).

Why do we need multiple readers? `LinkedChunkUpdates::take` is
clearly the first reader, it's part of the public API. But the private
API needs to read the updates too, without consuming them, like
`LinkedChunkUpdatesSubscriber`. `peek` was nice for that, but it's
possible to have multiple `LinkedChunkUpdatesSubscriber` at the same
time! Hence the need to widen the approach from 2 readers to many
readers.

This patch introduces a `ReaderToken` to identify readers. The last
indexes are now all stored in a `HashMap<ReaderToken, usize>`. The rest
of the modifications are the consequence of that.

The test `test_updates_take_and_peek` has been entirely rewritten to be
`test_updates_take_and_garbage_collector` where it tests 2 readers and
see how the garbage collector reacts to that.
2024-05-08 13:45:45 +02:00
Stefan Ceriu 1ce27d6eec feat(ui): add room list filter for excluding non-joined rooms 2024-05-08 12:48:14 +03:00
Ivan Enderlin 73ae1cc6da feat(sdk): Add LinkedChunkUpdatesSubscriber.
This patch implements `LinkedChunkUpdates::subscribe` and
`LinkedChunkUpdateSubscriber`, which itself implements `Stream`.

This patch splits `LinkedChunkUpdates` into `LinkedChunkUpdatesInner`,
so that the latter can be shared with `LinkedChunkUpdatesSubscriber`.
2024-05-08 09:23:20 +02:00
Michael Hollister 74b79d8212 ffi: Added dehydrated flag to Device
Signed-off-by: Michael Hollister <michael@futo.org>
2024-05-07 22:28:18 +02:00
Valere d0776819c7 Review: Add assert error message
Co-authored-by: Damir Jelić <poljar@termina.org.uk>
Signed-off-by: Valere <bill.carson@valrsoft.com>
2024-05-07 14:43:15 +02:00
Valere 4e9edcb0db Review: better comment
Co-authored-by: Damir Jelić <poljar@termina.org.uk>
Signed-off-by: Valere <bill.carson@valrsoft.com>
2024-05-07 14:42:52 +02:00
Valere e3dc094be4 Add minimal reproducing test 2024-05-07 10:20:19 +02:00
Valere f4772c9b0e Add FIXME comment 2024-05-07 10:20:08 +02:00
Ivan Enderlin 76210686c4 feat(sdk): Implement Clone on LinkedChunkUpdate.
`LinkedChunkUpdate` implements `Clone` if and only if `Item` and `Gap`
both implement `Clone`.
2024-05-06 22:22:32 +02:00
Ivan Enderlin 3a00271af0 chore(sdk): Hmmmm. 2024-05-06 20:15:35 +02:00
Ivan Enderlin d6915793c1 feat(sdk) Add the LinkedChunkUpdates::peek.
This patch adds the `LinkedChunkUpdates::peek` method. This is
a new channel to read the updates without consuming them, like
`LinkedChunkUpdates::take` does.

The complexity is: when do we clear/drop the updates then? We don't
want to keep them in memory forever. Initially `take` was clearing
the updates, but now that we can read them with `peek` too, who's
responsible to clear them? Enter `garbage_collect`. First off,
we already need to maintain 2 index, resp. `last_taken_index` and
`last_peeked_index` so that `take` and `peek` don't return already
returned updates. They respectively know the index of the last update
that has been read. We can use this information to know which updates
must be garbage collected: that's all updates below the two index.
Tadaa. Simple. The only _drawback_ (if it can be considered as such)
is that the garbage collection happens on the next call to `take` or
`peek` (because of the borrow checker). That's not really a big deal in
practise. We could make it happens immediately when calling `take` or
`peek` but it needs more pointer arithmetic and a less straighforward
code.
2024-05-06 20:13:42 +02:00
Damir Jelić 121dedee4e chore: Use a released version of vodozemac 2024-05-06 15:24:21 +02:00
Damir Jelić 8eebb9bb39 chore: Use a released version of uniffi (#3382)
The commit we were using has been part of the 0.27.1 release, so let's
use it:

https://github.com/mozilla/uniffi-rs/commit/789a9023b522562a95618443cee5a0d4f111c4c7
2024-05-06 14:32:47 +02:00
Ivan Enderlin 9e2e28d57a feat(sdk) Change the update history from a Vec<T> to a new LinkedChunkUpdates type.
This patch updates the `LinkedChunk::update_history` field from
a simple `Vec<LinkedChunkUpdate<Item, Gap>>` type to the new
`LinkedChunkUpdates<Item, Gap>` type (note the plural).

This is going to be helpul for the next patches.
2024-05-06 14:22:51 +02:00
Ivan Enderlin 2255cd5a43 chore(ffi): Remove support for opentelemetry
chore(ffi): Remove support for opentelemetry
2024-05-03 20:17:50 +02:00
Ivan Enderlin 12a231675c chore(ffi): Remove support for opentelemetry.
This patch removes support for OpenTelemetry because it's not used
anymore by anybody. It also adds multiple duplicated dependencies (like
`reqwest`). Anyway. Farewell.
2024-05-03 19:52:17 +02:00
Denis Kasak 60017241b2 Tweak log messages when rejecting devices (DeviceKeys structs) received from the server.
Preferring to use "reject" wording rather than "failed to
create/update". The latter can be easily misinterpreted as a failure of
the local client to create an entirely new device from scratch, rather
than refusal to instantiate a new local device representation of an
(invalid) device definition received from the server.
2024-05-03 14:08:36 +02:00
Denis Kasak 03fe9feb69 docs: Expand docs for the DeviceKeys struct. 2024-05-03 14:08:36 +02:00
Damir Jelić 6f2d8e0e50 chore: Fix some clippy warnings 2024-05-02 17:12:19 +02:00
Damir Jelić 56aa86da8b chore: Depend on a released version of mas-oidc-client 2024-05-02 17:12:19 +02:00
Ivan Enderlin 67e2842f84 feat(sdk): Introduce LinkedChunkUpdate
feat(sdk): Introduce `LinkedChunkUpdate`
2024-05-02 14:46:19 +02:00
Ivan Enderlin 443647a1ba feat(sdk): Make update history of LinkedChunk optional.
This patch makes the `LinkedChunk::update_history` field optional,
so that it doesn't require the user to drain it to avoid eating the
universe.

The `new` constructor disabled the update history, the
`new_with_update_history` enables it.
2024-05-02 14:30:19 +02:00
Ivan Enderlin b9ea6ff300 chore(sdk): Rename LinkedChunkLinks to LinkedChunkEnds. 2024-05-02 14:30:19 +02:00
Ivan Enderlin c219c727bb feat(sdk) Remove LinkedChunkListener.
This patch is a turn around about the `LinkedChunkListener`. Many
patches have been removed because `LinkedChunkListener` needed to
support I/O, so errors and async code. The whole code was affected by
that, resulting in a complex API. The idea of this patch is to decoupled
this. Here is how.

First off, `LinkedChunkListener` is removed. So it's one less generic
parameter on `LinkedChunk`. It's also one less trait, so less
implementations.

Second, now `LinkedChunk` accumulates/collects all “updates” under the
form of a new enum `LinkedChunkUpdate`. These updates can be read with
`LinkedChunk::updates(&mut self) -> &Vec<LinkedChunkUpdate>`. The reader
can simply read them, or even drain them. The reader is responsible
to handle these updates and to dispatch them in a storage or whatever.
`LinkedChunk` is no longer responsible to do that, removing the need to
support errors and to be async.

Third, the simplification has led to an optimisation by introducing a
new type `LinkedChunkLinks`. The documentation explains what it does
and why it was needed. The benefit of this type is: it doesn't increase
the size of `LinkedChunk`, but it simplifies the code: no more `Arc`,
no more `Mutex` (it was required because with I/O and async), no more
borrow checker trick, and the code stays as safe as before.
2024-05-02 14:30:19 +02:00
Ivan Enderlin db0f9b19be feat(sdk) LinkedChunkError is a real error now. 2024-05-02 14:30:19 +02:00
Ivan Enderlin 343416653d feat(sdk): Create LinkedChunkListener.
This patch creates the `LinkedChunkListener` trait.

This patch also updates `LinkedChunk` to be able to use a
`LinkedChunkListener`.
2024-05-02 14:30:19 +02:00
Ivan Enderlin 17b3cb6b31 fix(store-encryption): Remove the displaydoc dependency
fix(store-encryption): Remove the `displaydoc` dependency
2024-05-02 09:41:43 +02:00
Ivan Enderlin f8a6f90664 Merge pull request #3371 from matrix-org/bnjbvr/ansi-pedantic-sync-builder
tests: rename ev_builder to sync_builder + add test_ prefix to test functions
2024-05-02 09:36:00 +02:00
Ivan Enderlin 8ac51c19f5 Merge pull request #3369 from matrix-org/bnjbvr/get-rid-of-notificationclientbuilder
notification client: get rid of builder
2024-05-02 09:34:32 +02:00
Ivan Enderlin ad2e8336f6 fix(store-encryption): Remove the displaydoc dep.
This patch removes the `displaydoc` dependency. Why?

1. It creates a warning in rustc nightly:

```
warning: non-local `impl` definition, they should be avoided as they go against expectation
  --> crates/matrix-sdk-store-encryption/src/lib.rs:49:17
   |
49 | #[derive(Debug, Display, thiserror::Error)]
   |                 ^^^^^^^
   |
   = help: move this `impl` block outside the of the current constant `_DERIVE_Display_FOR_Error`
   = note: an `impl` definition is non-local if it is nested inside an item and may impact type checking outside of that item. This can be the case if neither the trait or the self type are at the same nesting level as the `impl`
   = note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type
   = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue <https://github.com/rust-lang/rust/issues/120363>
   = note: the derive macro `Display` may come from an old version of the `displaydoc` crate, try updating your dependency with `cargo update -p displaydoc`
   = note: `#[warn(non_local_definitions)]` on by default
   = note: this warning originates in the derive macro `Display` (in Nightly builds, run with -Z macro-backtrace for more info)
```

2. `thiserror` is already used, which seems to provide a similar issue.
3. That's less dependency, and less proc-macro, which will improve the
   compilation time in general.
2024-05-02 09:27:17 +02:00
Benjamin Bouvier a3f6e0fb5a ffi: add back a raw_name() Room method and RoomInfo field for the name defined in the raw state event
And rename "name" to "display_name" everywhere, duh.
2024-05-01 14:32:38 +02:00
Benjamin Bouvier f997256c73 ffi: revert a few methods back to sync
And sprinkle useful comments here and there.
2024-05-01 14:32:38 +02:00
Benjamin Bouvier e56d092b4a ffi: simplify RoomInfo::new() by getting the room avatar url internally
Before, it was computed externally and passed as a parameter.
2024-05-01 14:32:38 +02:00
Benjamin Bouvier dedfc2649a ffi: get rid of name(), and use the computed_display_name() everywhere
This should make it more regular, in all the places, to use the same
string:
- Room
- RoomListItem
- RoomInfo
2024-05-01 14:32:38 +02:00
Benjamin Bouvier 90bed18415 ffi: make the name method sync again
Also:

- rename `display_name` to `computed_display_name` in several places,
and reflect that change into a few callers
- simplify slightly the `computed_display_name()` method
2024-05-01 14:32:38 +02:00
Benjamin Bouvier a3061eb39a ffi: make RoomListItem::is_direct sync again
And comment why some methods it's calling are async under the hood.
2024-05-01 14:32:38 +02:00
Benjamin Bouvier f69db1d169 notification client(bugfix): don't filter out the notification if we couldn't compute push actions with /context
This is in line with what the other method using sliding sync does. This
wasn't tested before, because this required `filter_by_push_rules()` to
be enabled in the notification client; now that it's the default, the
test revealed the bug, and so it could be fixed.
2024-05-01 13:13:14 +02:00
Benjamin Bouvier 0ba4e42161 notification client: get rid of builder
The builder had only one meaningful method, `filter_by_push_rules`,
which was always called by the applications — and in fact should always
be true. It was designed as an extra method because it was experimental
at the time, but it's stabilized sufficiently that we can enable this
behavior by default now, considering that a notification that is not
wanted by the user shouldn't be kept, to respect their intent. (This is
in the UI crate, which is opinionated, so it's fine to assume such
intents by design.)
2024-05-01 13:13:14 +02:00
Benjamin Bouvier 7cf36ee9f6 tests: rename ev_builder to sync_builder + add test_ prefix to test functions 2024-05-01 12:37:55 +02:00
Benjamin Bouvier ff40ef0176 ffi: replace some block_on asyncs by async() functions 2024-05-01 11:11:04 +02:00
Benjamin Bouvier d02125ba21 ffi: simplify notification settings locks
This gets rid of a few calls to `RUNTIME.block_on`.
2024-05-01 11:11:04 +02:00
Ivan Enderlin 76200c1007 Merge pull request #3367 from zecakeh/upgrade-crates
chore: Upgrade dependencies
2024-05-01 09:39:28 +02:00
Kévin Commaille b4c3ab38b8 chore: Upgrade more crates
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-04-30 20:05:34 +02:00
Kévin Commaille f4b0ebdb95 ui: Do not enable matrix_sdk experimental-oidc feature
The feature should have been removed when the authentication
module was moved.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-04-30 19:01:00 +02:00
Kévin Commaille 6488be671e Fix check of nonce length
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-04-30 18:44:47 +02:00
Kévin Commaille 5eaf10e9f8 chore: Upgrade base64 crate
This matches the version used in ruma and vodozemac

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-04-30 17:46:59 +02:00
Benjamin Bouvier 177e31cf9a timeline: reset pagination status if a live back-pagination is aborted 2024-04-30 16:10:30 +02:00
Kévin Commaille dc2b9ed89c ci: Upgrade most actions (#3364)
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-04-30 15:04:54 +02:00
Damir Jelić fb9982fb48 oidc: Use the correct types to compare the status codes in the oidc example (#3363) 2024-04-30 13:02:29 +00:00
Kévin Commaille 856dd01009 Upgrade http, ruma, reqwest and wiremock dependencies (#3362)
They need to be updated together
because the latters depend on the former.

matrix-authentication-service is still using http 0.2
so we need to add a conversion layer between both major versions
for OIDC requests.

We need to update vodozemac too because of a dependency resolution issue.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-04-30 14:04:56 +02:00
Kévin Commaille ea1a01000f sdk: Use the GET /auth_issuer endpoint for OIDC
The well-known method is deprecated.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-04-30 12:33:31 +02:00
Benjamin Bouvier 0ebedfe286 clippy: disable the box_default lint, take 2 2024-04-30 12:04:29 +02:00
Benjamin Bouvier e0b4e2c35d fixup! paginator: reset the paginator's state if the task is cancelled 2024-04-30 12:04:29 +02:00
Benjamin Bouvier 1f2459478f paginator: reset the paginator's state if the task is cancelled
This makes all the requests (/context and /messages) cancellation-safe
by making two changes:

- first, use sync locks instead of async locks for the prev/next batch
tokens. This ensures that we can't get cancelled after receiving a
response and managing internal state, i.e. we keep run-to-completion
semantics until the end of the function, once we got a response.
- second, introduce a RAII guard that will reset the state to a given
value when dropped. Then use this to reset the state to Initial (resp.
Idle) in /context (resp. /messages) when the async call is aborted. We
use `mem::forget` once the response has been returned, so as to not call
the `Drop` implementation of the guard later on.

A regression test has also been introduced.
2024-04-30 12:04:29 +02:00
Ivan Enderlin 0c0342b994 doc(sdk): Add doc for assert_items_eq!. 2024-04-29 15:08:34 +02:00
Ivan Enderlin 3e261188d3 chore(sdk): Move CHUNK_CAPACITY as first generics of LinkedChunk.
This patch changes the signature of `LinkedChunk<Item, Gap, const
CHUNK_CAPACITY = usize>` to `LinkedChunk<const CHUNK_CAPACITY = usize,
Item, Gap>`. It allows to add more generic parameters if needed, without
conflicting with generic constants.
2024-04-29 15:08:34 +02:00
Benjamin Bouvier 16eb449c6b clippy: disable the box_default lint
The clippy website explains that `Box::new(Default::default())` can be
shortened to `Box::default()` and that it's more readable. That's true…
when you don't have a generic parameter in the mix (which may be
required if rustc can't infer the type of the boxee), in which case it
just looks bad, e.g. `Box::<MyType>::default()` instead of
`Box::new(MyType::default())`.

I do strongly prefer the latter, and propose to get rid of the lint, as
a result.
2024-04-29 14:32:08 +02:00
Doug 4618d7ca7d ffi: Allow creation of a matrix.to link for any room alias. 2024-04-29 12:00:36 +02:00
Ivan Enderlin 5e2a2465c9 Merge pull request #3357 from zecakeh/use-axum
sdk: Replace hyper with axum for local servers
2024-04-29 09:35:33 +02:00
Kévin Commaille 0e0a406cb1 Replace hyper with axum for oidc_cli example
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-04-27 19:37:46 +02:00
Kévin Commaille 04e5643422 Lock axum to 0.7.4
Version 0.7.5 triggers a warning in
our version of rust nightly in CI,
but we can't update it to a recent
version because it triggers a warning
caused by displaydoc

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-04-27 18:34:37 +02:00
Kévin Commaille d2bb17acd5 sdk: Replace hyper with axum for SSO login
hyper::Server was dropped in hyper 1, without a replacement.
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-04-27 17:12:10 +02:00
Ivan Enderlin dddc607e07 timeline: add event focus mode for permalinks
timeline: add event focus mode for permalinks
2024-04-25 16:23:28 +02:00
Ivan Enderlin 25f893b0bb Merge branch 'main' into bnjbvr/permalink-mvp 2024-04-25 16:02:23 +02:00
Andy Balaam 415617080a Merge pull request #3337 from matrix-org/andybalaam/utd-type-info
crypto: UtdCause enum in reporting hooks and encryption event
2024-04-25 08:55:50 +01:00
Andy Balaam 2c7afc201f Merge pull request #3326 from matrix-org/andybalaam/allow-setting-encryption-settings
ffi: Expose encryption settings via FFI
2024-04-25 08:55:43 +01:00
Andy Balaam 89abb75d4d crypto: Include UTD cause in FFI EncryptedMessage 2024-04-24 12:16:17 +01:00
Andy Balaam fd5666f55f crypto: Support unstable prefix for MSC4115 2024-04-24 08:31:31 +01:00
Benjamin Bouvier 397a26e00b ffi: add bindings for the timeline focus mode and associated functions 2024-04-23 19:02:59 +02:00
Benjamin Bouvier a6c42404a6 tests: add integration tests for the new timeline focus mode 2024-04-23 19:02:45 +02:00
Benjamin Bouvier 7856dab56d timeline: add support for a focus mode in the timeline
This introduces the `TimelineFocus`, a new enum to declare if the
timeline is "live" aka looking at events from sync and displaying them
as they come in, or focused on an event (e.g. after clicking a
permalink).

When in the second mode, the timeline can paginate forwards and
backwards, without interacting with the event cache (as this would
require some complicated reconciliation of known events with events
received from pagination, with no guarantee that those events are event
connected in whatever way).

An event-focused timeline will also show edits/reactions/redactions in
real-time (as the events are received from the sync), but will not show
new timeline items, be they for local echoes or events received from the
sync.
2024-04-23 19:02:27 +02:00
Valere 149606e148 Avoid incorrect usage of private backup key
This fixes instances of key backup corruption and prevents inadvertently logging the private backup key to the logs.
2024-04-23 17:46:53 +02:00
Andy Balaam ebcf1c434c ffi: Expose encryption_settings via FFI 2024-04-23 15:45:29 +01:00
Andy Balaam b5e2eb6831 crypto: Add a UtdCause and code to determine it for membership 2024-04-23 15:44:39 +01:00
Andy Balaam 9d20a02a12 build: Ensure uniffi feature is properly passed on where needed 2024-04-23 15:26:51 +01:00
Benjamin Bouvier 8f5e1f3dfc timeline: include the remote event's origin in the timeline position/end
and don't assume inserting to the end means it's coming from sync — as
it won't be true for forward pagination anymore.
2024-04-23 13:45:01 +02:00
Benjamin Bouvier d9864373f3 timeline: add the ability to set a prefix for internal IDs 2024-04-23 13:19:32 +02:00
Benjamin Bouvier e4331ac9b8 timeline: use a string instead of a u64 to identify timeline items
This will allow to define a prefix later, to distinguish detached
timelines from live timelines.
2024-04-23 13:19:32 +02:00
Benjamin Bouvier 9547e3cee6 timeline: move populate_initial_user_receipt to TimelineInnerState
This makes the API less weird, and is more consistent with other read
receipts methods.
2024-04-23 13:19:14 +02:00
Benjamin Bouvier ec45ce3aa6 timeline: prevent deadlock in populate_initial_user_receipt
Follow-up to 13cc7962.
2024-04-23 13:19:14 +02:00
Benjamin Bouvier 5916192fb6 ffi: don't abort RoomInfo creation if the room member invite event is missing
`Room::invite_details()` can return an error if the room member event
(the invite) is missing from the store. Usually that would be a sign
that the state is semi-broken, since there should always be such an
event for an invited room. But if it's missing, it shouldn't break the
creation of a `RoomInfo`, and just be missing from the struct.
2024-04-23 11:05:44 +02:00
Ivan Enderlin 5e347ce135 fix(ui): Timeline::send_reply correctly sets up m.mentions
fix(ui): `Timeline::send_reply` correctly sets up `m.mentions`
2024-04-23 09:43:05 +02:00
Ivan Enderlin 97ce5742e1 fix(ui): Timeline::send_reply correctly sets up m.mentions.
In https://github.com/matrix-org/matrix-rust-sdk/pull/2691, I suppose
the way `add_mentions` is computed is… wrong. `AddMentions` is used to
automatically infer the `m.mentions` of the reply event based on the
replied event. The way it was computed was based on the reply event
`mentions`, which seems wrong: if the reply contains mentions, then the
sender should be part of it? Nah. That's a bug. We want the reply event
to automatically mention the sender of the replied event if and only
if it's not the same as the current user, i.e. the sender of the reply
event.

This patch fixes the `add_mentions` calculation. This patch also updates
a test and adds another test to ensure that `m.mentions` is correctly
defined when replying to an event.
2024-04-23 09:30:21 +02:00
Benjamin Bouvier 13cc7962e7 timeline: prevent deadlock in replace_with_initial_events
The `state` lock was taken at the top level of this function, and
indirectly implicitly in the `set_fully_read_event` function. This fixes
it, and adds a regression test.
2024-04-22 20:49:12 +02:00
Benjamin Bouvier c471ee42ab paginator: select how many events to retrieve from the /messages query 2024-04-22 16:58:37 +02:00
Benjamin Bouvier 8e2fdd9200 paginator: select how many events to retrieve from the initial /context query 2024-04-22 16:58:37 +02:00
Benjamin Bouvier 289e2ac92b test: silently skip the room summary test on CI, if the server doesn't support it 2024-04-22 14:55:47 +02:00
Benjamin Bouvier 90c35b6b34 room preview: add support for MSC3266, room summary 2024-04-22 14:55:47 +02:00
Benjamin Bouvier fd96360228 dependencies: bump ruma
Honestly, I'm not sure how the retry-after that's a fixed point in time
in the future should be handled, open to suggestions here…
2024-04-22 14:55:47 +02:00
Benjamin Bouvier bd65c77534 dependencies: use a fork of Ruma for the time being 2024-04-22 14:55:47 +02:00
Benjamin Bouvier 4398052d94 timeline: after an event cache update lag, fetch previous events back from the cache
Fixes #3311.

When the timeline is lagging behind the event cache, it should not only
clear what it contains (because it may be lagging some information
coming from the event cache), it should also retrieve the events the
cache knows about, and adds them as if they were "initial" events.

This makes sure that the event cache's events and the timeline's events
are always the same, and that, in the case of a lag, there won't be any
missing chunks (caused by the event cache back-pagination being further
away in the past, than what's displayed in the timeline).

The lag behind a bit too hard to reproduce, I've not included a test
here; but I think this should be the right move.
2024-04-22 11:18:19 +02:00
Ivan Enderlin b03ae97580 Merge pull request #3346 from matrix-org/dependabot/cargo/rustls-0.21.11
chore(deps): bump rustls from 0.21.10 to 0.21.11
2024-04-22 10:48:02 +02:00
dependabot[bot] a157f2eb97 chore(deps): bump rustls from 0.21.10 to 0.21.11
Bumps [rustls](https://github.com/rustls/rustls) from 0.21.10 to 0.21.11.
- [Release notes](https://github.com/rustls/rustls/releases)
- [Changelog](https://github.com/rustls/rustls/blob/main/CHANGELOG.md)
- [Commits](https://github.com/rustls/rustls/compare/v/0.21.10...v/0.21.11)

---
updated-dependencies:
- dependency-name: rustls
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-04-19 19:53:20 +00:00
Benjamin Bouvier db5151d612 timeline: rename variables around reaction redaction 2024-04-19 15:15:11 +02:00
Benjamin Bouvier 621b47d763 timeline: refactor handling of local redactions too 2024-04-19 15:15:11 +02:00
Benjamin Bouvier 650281b534 timeline: refactor handling of local events to use a single method 2024-04-19 15:15:11 +02:00
Benjamin Bouvier 25ee247fe9 timeline: simplify redaction
Redaction was requiring the `RoomRedactionEventContent`, which was
eventually unused in all the code paths; this removes it.

Also adds lots of documentation for the different types of reaction that
can happen in the timeline.
2024-04-19 15:15:11 +02:00
Andy Balaam 1f524f2dec Merge pull request #3327 from matrix-org/andybalaam/expose-wait-e2ee
ffi: Expose Encryption::wait_for_e2ee_initialization_tasks
2024-04-19 11:26:06 +01:00
Andy Balaam a3e6a070d5 Merge pull request #3338 from matrix-org/kegan/drop-store
bugfix: ensure the SessionStore is cleared when regenerating the OlmMachine
2024-04-19 09:05:01 +01:00
Andy Balaam 381c02d21e crypto: Test that the sqlite store empties its session cache when asked 2024-04-18 13:47:36 +01:00
Andy Balaam 558d133e14 crypto: Test that regenerate_olm clears the store cache 2024-04-18 11:50:22 +01:00
Kegan Dougal 3a99d52e84 Apply suggestions from code review
Co-authored-by: Ivan Enderlin <ivan@mnt.io>
Signed-off-by: Kegan Dougal <7190048+kegsay@users.noreply.github.com>
2024-04-18 10:34:54 +01:00
Benjamin Bouvier 4325812b05 test: try a different strategy for waiting for the sync to stabilize 2024-04-18 11:29:24 +02:00
Benjamin Bouvier 845f65400a test: add integration test for a room preview 2024-04-18 11:29:24 +02:00
Benjamin Bouvier d5cbf77b84 tests: prefix some more tests with test_ 2024-04-18 11:29:24 +02:00
Benjamin Bouvier f322dcd200 sdk: give the ability to get a room's preview 2024-04-18 11:29:24 +02:00
Kegan Dougal 8cb778e9d9 CHANGELOG 2024-04-18 10:11:52 +01:00
Kegan Dougal 09955cf0db bugfix: ensure the SessionStore is cleared when regenerating the OlmMachine
This fixes https://github.com/matrix-org/matrix-rust-sdk/issues/3110
2024-04-18 10:08:15 +01:00
Benjamin Bouvier f7329c71bb test: test that getting kicked/banned marks the room as left in sliding sync 2024-04-15 11:41:37 +02:00
Benjamin Bouvier b977a239c3 tests: prefix more tests with test_ 2024-04-15 11:41:37 +02:00
Benjamin Bouvier 3aa62a265d sliding sync: also mark kicked/banned users as leaving a room 2024-04-15 11:41:37 +02:00
Benjamin Bouvier fc4cd530fb event cache: introduce the Paginator API (#3309)
This introduces a new helper object to run arbitrary pagination requests, backwards- or forward-. At the moment they're disconnected from the event cache, although I've put the files there for future convenience, since at some point we'll want to merge the retrieved events with the cache (? maybe).

This little state machine makes it possible to retrieve the initial data, given an initial event id, using the /context endpoint; then allow stateful pagination using a paginator kind of API. Paginating in the timeline indicates whether we've reached the start/end of the timeline.

The test for the state subscription is quite extensive and makes sure the basic functionality works as intended.

Some testing helpers have been (re)introduced in the SDK crate, simplifying the code, and introducing a better `EventFactory` / `EventBuilder` pattern than the existing one in the `matrix-sdk-test` crate. In particular, this can make use of some types in `matrix-sdk`, notably `SyncTimelineEvent` and `TimelineEvent`, and I've found the API to be simpler to use as well.

Part of #3234.
2024-04-12 17:57:10 +02:00
Andy Balaam 8a313df6a4 ffi: Expose Encryption::wait_for_e2ee_initialization_tasks 2024-04-12 14:20:17 +01:00
Benjamin Bouvier 7c68096237 multiverse: allow setting a proxy
This is handy when running mitmproxy on multiverse.
2024-04-11 16:45:05 +02:00
Stefan Ceriu e12f917559 ffi: expose method for parsing Matrix URIs and converting them into actual Matrix entities 2024-04-11 16:27:20 +02:00
Stefan Ceriu 20f0346733 ffi: expose method for genering user matrix.to permalinks 2024-04-11 16:27:20 +02:00
Benjamin Bouvier 8e98252be3 event cache: only forward a read marker update once per JoinedRoomUpdates
This protects against the sliding sync proxy (or synapse) sending lots
of duplicate fully read marker events for the same room in case of
reset. This would lead to forwarding lots and lots of
`RoomEventCacheUpdate`s to the timeline, cluttering the channel, and
resulting in a lag. This lag would then clear the timeline, seemingly
cause missing chunks from history.

https://github.com/matrix-org/matrix-rust-sdk/pull/3312 is likely the
long term fix (after a clear(), the timeline should retrieve all the
memoized events from the event cache), but this should prevent the root
cause of the spamming in the first place, getting us back to a safe
state.
2024-04-11 14:02:57 +02:00
Benjamin Bouvier 1053bc9148 sync service: only log sliding sync errors when it's not a sliding sync expiration 2024-04-11 12:12:31 +02:00
Benjamin Bouvier 1dd497e9de sync service(refactor): let start task methods be self-less functions
This removes one (1) level of indent in both tasks and makes the code a
bit simpler to read.
2024-04-11 12:12:31 +02:00
Benjamin Bouvier 81f1292660 sync service: show the termination report debug info in the error logs
We do see lots of "broken channel" log lines for these two log
statements, and since I'm unclear why they happened, I'd like to add a
bit more logging to those.

Also makes the log level consistent, both are set to "warn" instead of
one warn and one error. Usually it's not a big deal because the only
error that may happen is that the channel is broken, indicating the task
died before, so there's no need to stop it manually.
2024-04-11 12:12:31 +02:00
Benjamin Bouvier 5671121b21 timeline: add comments about insertion order to the front of the timeline 2024-04-11 12:11:54 +02:00
Kévin Commaille 88c4dec35f sdk: Upgrade image crate
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-04-11 11:40:32 +02:00
Kévin Commaille 6d9aa14ccd qrcode: Upgrade qrcode crate
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-04-11 11:40:32 +02:00
Benjamin Bouvier 16551feea3 timeline: lower log severity of read receipts issues
Those two issues really aren't errors we should be too scared of:

- on the one hand, they don't prevent correct usage of the timeline, but
slightly decrease the UX's quality
- on the other hand, they may indicate that read receipts haven't been
received yet, OR some events are unknown (can be happening if the
previous read receipt refers to an event the timeline doesn't know
about).

So I lowered their severity to debug instead of error, since only
outstanding issues should errors or warnings in my opinion.
2024-04-11 11:26:16 +02:00
Andy Balaam 1e7182e820 Merge pull request #3253 from matrix-org/andybalaam/add-backup_version-arg
crypto: Add a backup_version argument to group session backup methods
2024-04-09 16:44:50 +01:00
Andy Balaam a843125fa4 crypto: Share code to get backup_version in tests 2024-04-09 16:31:13 +01:00
Benjamin Bouvier fcfdaadb25 room(refactor): reuse code to decrypt an event instead of duplicating it 2024-04-08 16:16:44 +02:00
Benjamin Bouvier 222f969e2f integration tests: add tests for /context
Update testing/matrix-sdk-integration-testing/src/tests/room.rs

Co-authored-by: Damir Jelić <poljar@termina.org.uk>
Signed-off-by: Benjamin Bouvier <public@benj.me>
2024-04-08 16:16:44 +02:00
Benjamin Bouvier 406fd011ff room: extend event_with_context so it returns a fully decrypted /context response 2024-04-08 16:16:44 +02:00
Benjamin Bouvier b903ee4b42 room(style): remove one level of indent with an early let/else statement
Classic Benji.
2024-04-08 16:16:44 +02:00
Stefan Ceriu b9b5286f8a ffi: fix the experimental-room-list-with-unified-invites feature, the sliding sync is_invite field should be None when they are allowed in the room list 2024-04-08 15:37:28 +02:00
dependabot[bot] 2f5d8c212a chore(deps): bump h2 from 0.3.24 to 0.3.26
Bumps [h2](https://github.com/hyperium/h2) from 0.3.24 to 0.3.26.
- [Release notes](https://github.com/hyperium/h2/releases)
- [Changelog](https://github.com/hyperium/h2/blob/v0.3.26/CHANGELOG.md)
- [Commits](https://github.com/hyperium/h2/compare/v0.3.24...v0.3.26)

---
updated-dependencies:
- dependency-name: h2
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-04-08 15:20:10 +02:00
Benjamin Bouvier 797532815a room: warn at most once per room if the room version is missing
This should avoid spamming the logs about missing room versions.
2024-04-08 09:41:56 +02:00
Andy Balaam f11aeafd58 crypto: Add an optional backup_version param to inbound_group_session_counts 2024-04-05 16:24:55 +01:00
Kévin Commaille 327e0aef99 sdk: Enable matrix-sdk-base feature conditionally
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-04-05 13:00:04 +02:00
Benjamin Bouvier 742700b7fa event cache: increase the number of pending updates for a sender
And also log the number of skipped updates, when lagging behind in the
event cache or the timeline.
2024-04-05 10:59:28 +02:00
Benjamin Bouvier 03f4a56bff timeline(optimization): don't call force_update_sender_profiles when there are no member_ambiguity_changes
`force_update_sender_profiles` goes through all the timeline items, even
though the `ambiguity_changes` map should be empty, leading to wasted
work. It might not be a big deal, but it's nice to avoid awaiting locks
when we don't have to.
2024-04-05 10:59:28 +02:00
Benjamin Bouvier d8b0b9e2f4 event cache: better handle room updates lag
First, add a log line, since this is a pretty big deal if we start
lagging behind, and we should understand this clearly in rageshakes.

Second: don't remove existing `RoomEventCache`s, but instead clear them:
we shouldn't re-create new `RoomEventCache`s for the same room id,
otherwise a previous subscriber to updates to `RoomEventCache` would not
get newer updates coming later on.

Third: let consumers know that we cleared the events from the
`RoomEventCaches`.
2024-04-05 10:59:28 +02:00
Benjamin Bouvier dbb9c60d09 linked chunks: cosmetic changes
This tweaks assert and error messages, avoids indent by returning early,
etc.
2024-04-05 10:59:12 +02:00
Benjamin Bouvier b6db3af882 room list service: always include the m.room.create state event in a room subscription 2024-04-05 10:58:55 +02:00
Kévin Commaille 8a8ad22961 ffi: Use async functions in AuthenticationService (#3294)
* ffi: Use async functions in AuthenticationService
* Fix swift tests
* Set async_runtime for uniffi::export attribute
* Rename RwLocks
* Get rid of unnecessary map_err

---------

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-04-04 15:54:20 +00:00
Benjamin Bouvier b78bbc01a0 timeline: pin all the local echoes to the bottom
Before this patch, only local echoes that were messages not sent or
messages succesfully sent (but not ack'd yet by sync) would be pinned to
the bottom.

This fixes it by also pinning events that failed to send.

Fixes #3287.
2024-04-04 15:02:13 +02:00
Andy Balaam f51865e1ae crypto: Add a backup_version argument to group session backup methods 2024-04-04 11:00:59 +01:00
Stefan Ceriu 682c17c9d8 feat: add support for storing breacrumbs in the state store 2024-04-04 11:23:55 +02:00
Damir Jelić 4da1c01963 chore: Fix some typos 2024-04-04 11:17:18 +02:00
Benjamin Bouvier 96a4b06ca6 timeline: use the day divider adjuster when updating the send state of a message 2024-04-02 16:16:45 +02:00
Benjamin Bouvier ef5b12035d day dividers: explicitly chase trailing day dividers
The algorithm works on the basis that we remove a previous day divider
if it was spurious. But we'd never do this, for a final item that would
be a day divider! So chase these explicitly, also ignore read markers
that would be in the way.
2024-04-02 16:16:45 +02:00
Kévin Commaille 38978dacd7 crypto: Define both bounds in the same place
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-04-02 15:05:41 +02:00
Kévin Commaille 74ea661438 chore: Use only extern attributes for test modules
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-04-02 15:05:41 +02:00
Kévin Commaille da2abccc0d chore: Disable clippy::assigning_clones lint
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-04-02 15:05:41 +02:00
Benjamin Bouvier 6731c52b12 base: extract changes to profile into a small function helper
and detail the comment about why we need to remove a previous profile
first.
2024-04-02 14:30:19 +02:00
Benjamin Bouvier a3ca28f1a5 test: add regression test for #3278 2024-04-02 14:30:19 +02:00
Benjamin Bouvier 450ceaa241 base: remove previous profiles of member when they're invited 2024-04-02 14:30:19 +02:00
Benjamin Bouvier 6cd655ba7c state store: add Changes::profile_to_delete field
So as to remove existing profiles from the storage.
2024-04-02 14:30:19 +02:00
Kévin Commaille f9ab073adf chore: Avoid redundant imports
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-04-02 13:27:58 +02:00
Kévin Commaille b5d7c40029 tests: Use .contains_key() instead of .get().is_some()/.is_none()
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-04-02 13:27:58 +02:00
Stefan Ceriu 29f7f88a2c ffi: expose room and event matrix.to permalink builder methods 2024-04-02 10:35:23 +02:00
Benjamin Bouvier db37a1feb5 base: fix typo in comment 2024-03-29 13:04:39 +01:00
Benjamin Bouvier 901024bccc base: remove cognitive overload when passing parameters
The `MemberInfo` struct only existed to regroup parameters, so let's
pass individual parameters instead. One less data structure is good for
the cognitive load.
2024-03-29 13:04:39 +01:00
Benjamin Bouvier 5d1fa986f3 base(logs): remove spammy trace statements in BaseRoom::get_member
and in BaseRoom::member_room_info.
2024-03-29 13:04:39 +01:00
Benjamin Bouvier aa99c7bd38 base(style): avoid repetitions of and_then
Option::and_then(f).and_then(g) is equivalent to Option::and_then(g(f?)).
2024-03-29 13:04:39 +01:00
Benjamin Bouvier 76d484541f test: add test for #3278 2024-03-29 13:04:39 +01:00
Benjamin Bouvier 8482d181b5 base: ensure test_ prefix for all the tests 2024-03-29 13:04:39 +01:00
Benjamin Bouvier 650f210da7 base: copy comment in receive_all_members explaining why it's not fine to set the profile of another user 2024-03-29 11:56:29 +01:00
Benjamin Bouvier 191350a290 Revert "fix: Process profiles for all room members not only state event senders (#3278)"
This reverts commit 99e47ed5d7.
2024-03-29 11:56:29 +01:00
Ivan Enderlin 95baf17c36 fix(sdk): Fix LinkedChunk::insert_items_at.
This patch fixes a bug when inserting items at the end of the
current items of a chunk. The condition was: `if item_index >=
current_items_length`, which is too restrictive. The bug was “hidden”
so far because it's not possible to get the position of “after an item”
with the current API. However, the bug arises if the items are empty and
new items are inserted the position index 0 (index = 0, length = 0).

The fix consists of relaxing the condition, and introducing an
optimisation. If we insert at the end, we do a simple push (like an
append). If we insert at another position, we split, then push the new
items, and finally push the detached items (as it was the case before).

The tests have been updated accordingly.
2024-03-29 11:43:25 +01:00
Benjamin Bouvier 1c1053afe6 event cache: internalize handling of the account data
(By moving handling of the fully read marker into the event cache
itself.)
2024-03-28 17:59:43 +01:00
Andy Balaam 7ac153fd67 Merge pull request #3282 from matrix-org/andybalaam/memorystore-tracked-users-map
memorystore: Fix bug where duplicate tracked users are stored
2024-03-28 16:33:49 +00:00
Andy Balaam 31131146a6 memorystore: Fix bug where duplicate tracked users are stored 2024-03-28 16:19:23 +00:00
Ivan Enderlin ac0bc95c25 feat(sdk): EventCache fully uses RoomEvents/LinkedChunk
feat(sdk): `EventCache` fully uses `RoomEvents`/`LinkedChunk`
2024-03-27 10:23:42 +01:00
Ivan Enderlin 11c3799fa2 doc(sdk): Improve doc of EventCache. 2024-03-27 09:39:22 +01:00
Ivan Enderlin f11cf87326 fix(sdk): Replace unwrap by expect and add SAFETY docs. 2024-03-27 09:35:45 +01:00
Ivan Enderlin 7b092fd174 doc(sdk): Improve documentation of EventCacheInner::multiple_room_updates_lock. 2024-03-27 09:32:33 +01:00
Ivan Enderlin 1fa4bb4cfa chore(sdk): Remove commented code. 2024-03-27 09:32:33 +01:00
Ivan Enderlin dabc7c512c !revert test changes 2024-03-27 09:32:33 +01:00
Ivan Enderlin 8fe27ab582 doc(sdk): Improve documentation of RoomEvents::replace_gap_at. 2024-03-27 09:32:33 +01:00
Ivan Enderlin 8c1d3f4f60 feat(sdk): RoomEventCacheInner::backpaginate always return Ok for unknown token.
Prior to this patch, in `RoomEventCacheInner::backpaginate`, when the
`token` validity was checked, and it was invalid:

* before calling `/messages`, `Err(EventCacheError::UnknownBackpaginationToken)` was returned,
* after calling `/messages`, `Ok(BackPaginationOutput::UnknownBackpaginationToken)` was returned.

This patch tries to uniformize this by only returning
`Ok(BackPaginationOutput::UnknownBackpaginationToken)`.

That's a tradeoff. It will probably be refactor later.

The idea is also to call `/messages` **before** taking the write-lock
of `RoomEvents`, otherwise it can keep the lock for up to 30secs in
this case. Also, checking the validity of the `token` **before** and
**after** `/messages` is not necessary: it can be done only after.
2024-03-27 09:32:33 +01:00
Ivan Enderlin a623215257 chore(sdk): Make Clippy happy. 2024-03-27 09:32:33 +01:00
Ivan Enderlin f61de718b8 fix(sdk): Fix a race-condition in EventCache.
This patch ensures that operations on `RoomEvents` happen in one block,
by sharing the same lock.

2 new methods are created: `replace_all_events_by` and
`append_new_events`.
2024-03-27 09:32:33 +01:00
Ivan Enderlin fa5bbadf57 doc(sdk): Just highlight how important this lock is. 2024-03-27 09:32:15 +01:00
Ivan Enderlin 9319f4fcff test(sdk): Fix test_reset_while_backpaginating.
The test `test_reset_while_backpaginating` was expecting a
race-condition, which no longer exists. It first initially tried to
assert a workaround about this race-condition. It doesn't hold anymore.
Rewrite the test to assert the (correct) new behaviour.
2024-03-27 09:32:15 +01:00
Ivan Enderlin 25fb9ee47d feat(sdk): Update RoomEvents::replace_gap_at to return a &Chunk. 2024-03-27 09:32:15 +01:00
Ivan Enderlin 85538dc3ed feat(sdk): Remove EventCacheStore, TimelineEntry, RoomInfo and MemoryStore. 2024-03-27 09:23:51 +01:00
Ivan Enderlin 5bb2511914 test(sdk): Tests of EventCache uses RoomEvents. 2024-03-27 09:23:25 +01:00
Ivan Enderlin 667ada88e6 feat(sdk): RoomEventCache::subscribe uses RoomEvents. 2024-03-27 09:23:05 +01:00
Ivan Enderlin 022b8a0f38 feat(sdk): EventCache::listen_task uses RoomEvents. 2024-03-27 09:22:43 +01:00
Ivan Enderlin 29caa02ef0 feat(sdk): EventCache::add_initial_events uses RoomEvents. 2024-03-27 09:22:13 +01:00
Ivan Enderlin 9102a9c841 feat(sdk): RoomEventCachecacherInner::oldest_backpagination_token uses RoomEvents. 2024-03-27 09:21:05 +01:00
Stefan Ceriu 99e47ed5d7 fix: Process profiles for all room members not only state event senders (#3278) 2024-03-27 09:13:18 +01:00
Ivan Enderlin 54729ce32b feat(sdk): Start disabling the global store in EventCache. 2024-03-27 09:11:15 +01:00
Ivan Enderlin 36e199c31e feat(sdk): Implement RoomEvents::reset, push_gap, replace_gap_at and events.
This patch implements the following wrapper methods (over
`LinkedChunk`): `push_gap`, `replace_gap_at` and `events`. This patch
also implements the `reset` method that clears/drops all chunks in the
`LinkedChunk`.
2024-03-27 09:07:52 +01:00
Richard van der Hoff ab9e4f73b1 crypto: Add OlmMachine::device_creation_time (#3275)
Turns out this is useful for https://github.com/element-hq/element-meta/issues/2313.
2024-03-26 15:13:55 +00:00
Benjamin Bouvier ce7143b833 integration tests: rewrite test_toggling_reaction so it syncs in the background 2024-03-25 18:03:18 +01:00
Benjamin Bouvier 9480450410 integration tests: attempt to fix test_toggling_reaction
There was a message sent, *then* an attempt to wait for the remote echo later. It's not ideal, because if the time setting up the waiting is high enough, and the server is fast
enough, the remote echo could come *before* we started waiting for it, resulting in timeouts. This fixes it by spawning the waiting task first, and then only sending the message.
Let's see how this helps with this test.
2024-03-25 18:03:18 +01:00
Benjamin Bouvier 4744a994b4 integration tests: enhance testing of test_room_notification_count
This adds additional checks for each room updates, and works around a few race conditions, notably one where the server would send a remote echo for a message, but not update the
computed unread_notification_counts immediately. This tends to make the test more stable, in that each response is well known and now properly tested.
2024-03-25 18:03:18 +01:00
Benjamin Bouvier 1fd5b34fd0 ci: add more logs for test_toggling_reaction 2024-03-25 18:03:18 +01:00
Benjamin Bouvier 1255027d6e git: ignore the code coverage report from the output 2024-03-25 18:03:18 +01:00
Benjamin Bouvier baac38fec5 day dividers: add test for redundant day divider before a read marker 2024-03-25 14:48:07 +01:00
Benjamin Bouvier 94c0322fbe day dividers: soften assertions
It's not worth panic'ing the whole timeline because we removed the wrong item; worst case, users will complain and can send a rageshake that contains all the information that's
needed to debug what went wrong.
2024-03-25 14:48:07 +01:00
Benjamin Bouvier e9a4389a12 day dividers: don't assume the previous item is at the immediate previous position
There could be situations where we have a day divider, then a read marker, then an event. In that case, when looking at the event, if the previous day divider is wrong and needs
to be removed, we would assume the "previous item" (= the day divider) was at position i-1, which could be that of the read marker, and we'd remove the read marker instead of the
day divider.
2024-03-25 14:48:07 +01:00
Andy Balaam 67615fec3a Merge pull request #3252 from matrix-org/andybalaam/run-integration-tests-for-memorystore
crypto: Run the crypto integration tests against MemoryStore
2024-03-25 12:23:52 +00:00
Thomas 95a471b0d2 ffi: Expose discovered sliding sync proxy URL (#3266)
Closes #3265.

There is currently no way to get the URL of a homeserver's sliding sync proxy before logging in on the homeserver.

I suggest exposing the URL via the `HomeserverLoginDetail` struct after configuring the homeserver (through `configure_homeserver`).

Since the homeserver may not declare a corresponding sliding sync proxy, this value is an `Optional`. It is used later in `configure_homeserver` to check if a sliding sync proxy exists and throws an error otherwise. Previously, this check was done against the client's `discovered_sliding_sync_proxy` function.

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

Signed-off-by: Thomas Völkl <thomas@vollkorntomate.de>
Signed-off-by: Benjamin Bouvier <public@benj.me>
Co-authored-by: Benjamin Bouvier <public@benj.me>
2024-03-22 17:21:24 +00:00
Benjamin Bouvier 56f4b3e70e day divider: don't assume events have event id
Local echoes (which haven't received a remote echo yet) can have no event id, so when computing the report, don't unwrap the event id but use a sensible
default instead.

Also tweaks comments from a previous version of another PR. And rename `DayDividerAdjuster::maybe_adjust_day_dividers` to `run`.
2024-03-22 17:00:33 +01:00
Benjamin Bouvier 6aee1f62bd day divider: make it impossible to handle an event without adjusting day dividers (#3267)
The previous API relied on the callers not forgetting about adjusting day dividers after handling an event.

This makes it statically impossible, by requiring that `TimelineEventHandler` takes a `&mut DayDividerAdjuster` when operating, that it marks as not "consumed". Later, the caller must call `DayDividerAdjuster::maybe_adjust_day_dividers()`, to mark it as consumed. When dropping, we check that it's been consumed, otherwise we panic — as it's a developer error to not call `maybe_adjust_day_dividers()`.
2024-03-22 12:14:28 +00:00
Hubert Chathi 8d968604e9 chore: Update Ruma to version that uses web-time crate (#3264) 2024-03-22 12:30:19 +01:00
Andy Balaam 3a7b8fc6a5 crypto: Run the crypto integration tests against MemoryStore 2024-03-22 09:58:13 +00:00
Andy Balaam 7de5d295b6 crypto: Enable testing module in test mode 2024-03-22 09:58:13 +00:00
Andy Balaam 6b394d96bd crypto: Formatting for integration_tests 2024-03-22 09:58:13 +00:00
Richard van der Hoff 97959bbcd0 crypto: Log details about olm session after encryption/decryption (#3242) 2024-03-22 09:43:35 +00:00
Benjamin Bouvier 2883685bcc day divider: adjust instrument macro
also fix two "date dividers" instances
2024-03-22 10:24:57 +01:00
Benjamin Bouvier eef61f87c1 day divider: move code to a new file
Only code motion, no changes in functionality.
2024-03-22 10:24:57 +01:00
Benjamin Bouvier 2c9a088a36 day divider: add test for duplicate date header after matching two local echoes
I checked that the test failed on main, by causing a final state of [DD First DD Second].

Fixes #2590.
2024-03-22 10:24:57 +01:00
Benjamin Bouvier 8912761eb7 day divider algorithm: address review comments
Notably, split the code into smaller functions, and revamp the high-level signatures so the individual handle_ functions don't take a bazillion arguments.
2024-03-22 10:24:57 +01:00
Benjamin Bouvier 3323f37efc day divider: beef up the reports
The reports now include the final state as well as the set of operations to run, so we can really debug all the steps just from looking at a rageshake.
2024-03-22 10:24:57 +01:00
Benjamin Bouvier 515aaf0a8a day divider: fix offset computation
When we're removing or inserting any day divider, we're also updating the offset, so that subsequent operations happen at the right positions.
The previous code made the error to clamp the offset when assigning it, instead of letting it be "out of bounds" and clamping the uses, which is
the correct way to implement this.
2024-03-22 10:24:57 +01:00
Benjamin Bouvier c172ad9191 day divider: only warn if some invariants are broken, in non-debug mode 2024-03-22 10:24:57 +01:00
Benjamin Bouvier 601dce76ef timeline: add instrumentation for the maybe_adjust_day_dividers function 2024-03-22 10:24:57 +01:00
Benjamin Bouvier f704066fbe timeline: group updates of the day dividers when multiple events are added at the same time 2024-03-22 10:24:57 +01:00
Benjamin Bouvier b8174c437f timeline: move the day divider adjusting code into its own data structure 2024-03-22 10:24:57 +01:00
Benjamin Bouvier a7cda30f6a timeline: use push_{front,back} semantics for both messages and day dividers 2024-03-22 10:24:57 +01:00
Benjamin Bouvier 88cd2557f3 timeline: rework the day divider separation as a post-processing algorithm 2024-03-22 10:24:57 +01:00
Benjamin Bouvier bd33c336e7 tests: try bumping the timeout duration in test_room_notification_count
The test has been failing with a timeout recently, several time. Let's see if it was a fluke caused by the low threshold (because the server might be
busy handling other requests from other tests), or an actual issue.
2024-03-21 20:15:05 +01:00
Richard van der Hoff 82bcf48c88 Enable debuginfo for tarpaulin builds
It appears that tarpaulin complains if the symbol information is stripped from
the binary, and as of Rust 1.77, `debug=0` causes Cargo to strip all debug
info.

To fix this, set `debug=1`.
2024-03-21 17:46:30 +01:00
Ivan Enderlin daaf17198c Merge pull request #3257 from Hywan/fix-issue-3213
doc(crypto-ffi): `Device::first_time_seen_ts` has an incorrect unit
2024-03-21 16:24:03 +01:00
Andy Balaam fe39ca47d6 Merge pull request #3223 from matrix-org/andybalaam/adjust-integration-tests
crypto: Refactor integration tests in preparation for them running against MemoryStore
2024-03-21 13:15:45 +00:00
Ivan Enderlin f42c8937da feat(sdk): Improve ChunkIdentifierGenerator
feat(sdk): Improve `ChunkIdentifierGenerator`
2024-03-21 12:56:16 +01:00
Ivan Enderlin 199275ff89 feat(sdk): Rename ChunkIdentifierGenerator::generate_next to next.
This patch renames `ChunkIdentifierGenerator::generate_next` to `next.

This patch also simplifies a `.saturating_add(1)` to a simple `+ 1`,
which is fine because we have checked for overflow just before.
2024-03-21 12:39:18 +01:00
Ivan Enderlin 7df31406dc feat(bindings): added join room by id to ffi
feat(bindings): added join room by id to ffi
2024-03-21 12:18:33 +01:00
Ivan Enderlin 1edfc6cb5e Merge pull request #3261 from matrix-org/kegan/arc-uniffi
uniffi: wrap TaskHandle up in an Arc<>
2024-03-21 12:10:36 +01:00
Ivan Enderlin d4c1b9b8ad chore: Avoid importing types redundantly
chore: Avoid importing types redundantly
2024-03-21 11:56:02 +01:00
Mauro Romito d447f63e33 fixed invalid parsing 2024-03-21 11:53:44 +01:00
Kegan Dougal c13fb7e19f uniffi: wrap TaskHandle up in an Arc<>
Up until uniffi 0.26 it was not possible to send objects
across the boundary unless they were wrapped in an `Arc<>`,
see https://github.com/mozilla/uniffi-rs/pull/1672

The bindings generator used in complement-crypto only supports
up to uniffi 0.25, meaning having a function which returns objects
ends up erroring with:
```
error[E0277]: the trait bound `TaskHandle: LowerReturn<UniFfiTag>` is not satisfied
   --> bindings/matrix-sdk-ffi/src/room_directory_search.rs:109:10
    |
109 |     ) -> TaskHandle {
    |          ^^^^^^^^^^ the trait `LowerReturn<UniFfiTag>` is not implemented for `TaskHandle`
    |
    = help: the following other types implement trait `LowerReturn<UT>`:
              <bool as LowerReturn<UT>>
              <i8 as LowerReturn<UT>>
              <i16 as LowerReturn<UT>>
              <i32 as LowerReturn<UT>>
              <i64 as LowerReturn<UT>>
              <u8 as LowerReturn<UT>>
              <u16 as LowerReturn<UT>>
              <u32 as LowerReturn<UT>>
            and 133 others

error[E0277]: the trait bound `TaskHandle: LowerReturn<_>` is not satisfied
   --> bindings/matrix-sdk-ffi/src/room_directory_search.rs:82:1
    |
82  | #[uniffi::export(async_runtime = "tokio")]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `LowerReturn<_>` is not implemented for `TaskHandle`
    |
    = help: the following other types implement trait `LowerReturn<UT>`:
              <bool as LowerReturn<UT>>
              <i8 as LowerReturn<UT>>
              <i16 as LowerReturn<UT>>
              <i32 as LowerReturn<UT>>
              <i64 as LowerReturn<UT>>
              <u8 as LowerReturn<UT>>
              <u16 as LowerReturn<UT>>
              <u32 as LowerReturn<UT>>
            and 133 others
```

This PR wraps the offending function in an `Arc<>` to make it uniffi 0.25 compatible,
which unbreaks complement crypto.
2024-03-21 10:40:37 +00:00
Mauro Romito 17805cbcd8 feat(bindings): added join room by id to ffi 2024-03-21 11:39:04 +01:00
hanadi92 d2c9ca455d docs: update copyright
Signed-off-by: hanadi92 <hanadi.tamimi@gmail.com>
2024-03-21 09:53:43 +01:00
hanadi92 36c39b837a refactor: create a pusher manager to set and delete
Signed-off-by: hanadi92 <hanadi.tamimi@gmail.com>
2024-03-21 09:53:43 +01:00
hanadi92 b83a644260 fix: use async instead of block on runtime
Signed-off-by: hanadi92 <hanadi.tamimi@gmail.com>
2024-03-21 09:53:43 +01:00
hanadi92 7c4d180297 ffi: add delete_pusher method
Signed-off-by: hanadi92 <hanadi.tamimi@gmail.com>
2024-03-21 09:53:43 +01:00
hanadi92 b2e7ae4310 sdk: add delete_pusher method
Signed-off-by: hanadi92 <hanadi.tamimi@gmail.com>
2024-03-21 09:53:43 +01:00
Ivan Enderlin 5d5a3044c8 chore: Avoid importing types redundantly.
`TryFrom` and `TryInto` are imported redundantly. They are already
defined in `core::prelude::rust_2021` which is automatically imported.
This is generating warnings on my side. This patch fixes that.
2024-03-21 09:14:56 +01:00
Ivan Enderlin ae170362a5 doc(crypto-ffi): Device::first_time_seen_ts has an incorrect unit.
This patch changes seconds to milliseconds for the description of
`Device::first_time_seen_ts`.
2024-03-21 09:05:30 +01:00
Ivan Enderlin 01c5412951 feat(sdk): ChunkIdentifierGenerator::generate_next panics.
This patch makes `ChunkIdentifierGenerator::generate_next` to panic
if there is no more identifiers available. It was previously returning
a `Result` but we were doing nothing with this `Result` except
`unwrap`ping it. To simplify the API: let's panic.
2024-03-20 21:14:51 +01:00
Ivan Enderlin ab2b5bfa23 feat(sdk): Remove AtomicU64::load in ChunkIdentifierGenerator.
As suggested in https://github.com/matrix-org/matrix-rust-sdk/
pull/3251#discussion_r1532103818 by Poljar, it is possible that the
value of the atomic changes between the `fetch_add` and the `load` (if
and only if it is used in a concurrency model, which is not the case
right now, but anyway… better being correct now!). The idea is not
`load` but repeat the addition manually to compute the “current” value.
2024-03-20 21:08:01 +01:00
Ivan Enderlin c120da79d1 feat(sdk): Optimise how LinkedChunk::insert_gap_at works when inserting at first position
feat(sdk): Optimise how `LinkedChunk::insert_gap_at` works when inserting at first position
2024-03-20 17:22:22 +01:00
Ivan Enderlin 962c0bf4fd doc(sdk): Improve SAFETY paragraphs, and replace unwraps by expects. 2024-03-20 15:57:04 +01:00
Ivan Enderlin 57b68614af doc(sdk): US vs UK strike again. 2024-03-20 15:50:51 +01:00
Ivan Enderlin 8eafaa58fb Merge pull request #3169 from matrix-org/mauroromito/directory_search
Room Directory Search
2024-03-20 15:43:18 +01:00
Ivan Enderlin 96c7b3fc52 doc(sdk): Add a warning.
Signed-off-by: Ivan Enderlin <ivan@mnt.io>
2024-03-20 15:28:24 +01:00
Ivan Enderlin 0a02a41a14 doc(sdk): Fix mark up.
Signed-off-by: Ivan Enderlin <ivan@mnt.io>
2024-03-20 15:28:03 +01:00
Ivan Enderlin a248ec75e2 feat(sdk): Optimise how insert_gap_at works when inserting at first position.
Imagine we have this linked chunk:

```rust
assert_items_eq!(linked_chunk, ['a'] [-] ['b', 'c'] ['d', 'e', 'f']);
```

Before the patch, when we were running:

```rust
let position_of_d = linked_chunk.item_position(|item| *item == 'd').unwrap();
linked_chunk.insert_gap_at((), position_of_d)?;
```

it was taking `['d', 'e', 'f']` to split it at index 0, so `[]` + `['d',
'e', 'f']`, and then was inserting a gap in between, thus resulting
into:

```rust
assert_items_eq!(linked_chunk, ['a'] [-] ['b', 'c'] [] [-] ['d', 'e', 'f']);
```

The problem is that it creates a useless empty chunk. It's a waste of
space, and rapidly, of computation. When used with `EventCache`, this
problem occurs every time a backpagination occurs (because it executes
a `replace_gap_at` to insert the new item, and then executes a
`insert_gap_at` if the backpagination contains another `prev_batch`
token).

With this patch, the result of the operation is now:

```rust
assert_items_eq!(linked_chunk, ['a'] [-] ['b', 'c'] [-] ['d', 'e', 'f']);
```

The `assert_items_eq!` macro has been updated to be able to assert
empty chunks. The `test_insert_gap_at` has been updated to test all
edge cases.
2024-03-20 13:47:53 +01:00
Ivan Enderlin 3aa0a905b2 feat(sdk): LinkedChunk::replace_gap_at returns &Chunk. 2024-03-20 13:47:53 +01:00
Damir Jelić 44443d3b46 crypto: Mac then decrypt in the PkDecryption compat module 2024-03-20 10:34:51 +01:00
Andy Balaam 40d96dbf27 crypto: Refactor integration tests in preparation for them running against MemoryStore
A couple of small changes that allow us to drop locks that would
otherwise persist when running the tests over the MemoryStore, and some
documentation comments for assertions to make it easier to spot which
assertion failed, even though we are inside a macro.
2024-03-20 09:10:02 +00:00
Andy Balaam b2dc21d7d0 Merge pull request #3222 from matrix-org/andybalaam/store-private-identity-in-memorystore
crypto: Save private identity in the MemoryStore
2024-03-20 09:09:22 +00:00
Ivan Enderlin fa5ce1d462 fix(sdk): Various tiny improvements for LinkedChunk
fix(sdk): Various tiny improvements for `LinkedChunk`
2024-03-19 20:41:23 +01:00
Ivan Enderlin e264482954 feat(sdk): Rename ItemPosition to Position.
The “position” can be placed inside a `Gap`, so naming it `Item…` is a
non-sense. This patch removes the `Item` prefix.
2024-03-19 20:22:08 +01:00
Matthias Grandl a1c1b0e157 timeline: make room() public (#3248) 2024-03-19 18:30:10 +01:00
Valere 3ac123db29 crypto: fix BackedUpRoomKey Serialization 2024-03-19 17:10:36 +01:00
Andy Balaam 9caec95c5e crypto: Save private identity in the MemoryStore 2024-03-19 15:36:08 +00:00
Andy Balaam 4bdcedbc66 Merge pull request #3221 from matrix-org/andybalaam/store-trackedusers-in-memorystore
crypto: Store TrackedUsers in MemoryStore
2024-03-19 15:29:13 +00:00
Damir Jelić 3ccd2e9f8f crypto: Remove the KeysBackup variant of the OutgoingRequest enum
Backing up room keys isn't part of the outgoing requests processing
loop, instead the user is supposed to have a separate loop calling
`BackupMachine::backup()`.
2024-03-19 16:23:13 +01:00
Andy Balaam 099c855049 crypto: Store TrackedUsers in MemoryStore 2024-03-19 15:16:53 +00:00
Hubert Chathi 1e35188aec Add a dehydrated flag to device_keys of dehydrated devices (#3164)
Signed-off-by: Hubert Chathi <hubert@uhoreg.ca>
Co-authored-by: Damir Jelić <poljar@termina.org.uk>
2024-03-19 14:33:13 +00:00
Benjamin Bouvier c6da40cf55 ffi: bump opentelemetry crates
This gets rid of multiple duplicate crates in the dependency tree.
2024-03-19 14:21:59 +01:00
Kévin Commaille 0ff9e066fb sdk: Don't enable default features of mas-oidc-client
We don't need the `hyper` feature as we use our own HTTP client,
and the `keystore` will not be used in most cases.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-03-19 14:01:53 +01:00
Damir Jelić c59465c54c crypto: Rotate fallback keys in a time-based manner (#3151)
Fallback keys until now have been rotated on the basis that the
homeserver tells us that a fallback key has been used.

Now this leads to various problems if the server tells us too often that
it has been used, i.e. if we receive the same sync response too often.
It leaves us also open to the homeserver being dishonest and never
telling us that the fallback key has been used.

Let's avoid all these problems by just rotating the fallback key in a
time-based manner.

Signed-off-by: Damir Jelić <poljar@termina.org.uk>
Co-authored-by: Andy Balaam <andy.balaam@matrix.org>
2024-03-19 13:16:37 +01:00
Jorge Martin Espinosa 0c4b62f664 sdk: move get_profile from Client to Account (#3238)
This also renames and streamlines the existing `Account::get_profile` function to `Account::fetch_profile` which now calls the more general function.
2024-03-19 12:03:32 +00:00
Andy Balaam 8c2831a5da Merge pull request #3220 from matrix-org/andybalaam/save-outbound-sessions-in-memorystore
crypto: Save outbound sessions in MemoryStore
2024-03-19 11:38:59 +00:00
依云 4e8cee162a sdk: make content of RawEvent public (#3239)
This way it can be moved out and converted to other types like ruma::Serde::Raw.

Signed-off-by: lilydjwg <lilydjwg@gmail.com>
2024-03-19 11:28:34 +00:00
Andy Balaam 1e11ac406f crypto: Use a BTreeMap for MemoryStores' OutboundGroupSessions 2024-03-19 11:26:20 +00:00
Marco Antonio Alvarez 10069fbead MSC2530: added the ability to send media with captions (#3226)
Now that there is some support for [MSC2530](https://github.com/matrix-org/matrix-spec-proposals/pull/2530), I gave adding sending captions a try. ( This is my first time with Rust 😄  )

I tried it on Element X with a hardcoded caption and it seems to work well
![image](https://github.com/matrix-org/matrix-rust-sdk/assets/683652/597e5ebf-f7f2-498f-97a4-ac98613c1134)

(It even got forwarded through mautrix-whatsapp and the caption was visible on the Whatsapp side)

---

* ffi: Expose filename and formatted body fields for media captions

In relevance to MSC2530

* MSC2530: added the ability to send media with captions

Signed-off-by: Marco Antonio Alvarez <surakin@gmail.com>

* signoff

Signed-off-by: Marco Antonio Alvarez <surakin@gmail.com>

* fixing the import messup

* fix missing parameters in documentation

* fix formatting

* move optional parameters to the end

* more formatting fixes

* more formatting fixes

* rename url parameter to filename in send_attachment and helpers

* fix send_attachment documentation example

* move caption and formatted_caption into attachmentconfig

* fix formatting

* fix formatting

* fix formatting (hopefully the last one)

* updated stale comments

* simplify attachment message comments

---------

Signed-off-by: Marco Antonio Alvarez <surakin@gmail.com>
Co-authored-by: SpiritCroc <dev@spiritcroc.de>
2024-03-19 11:08:47 +01:00
Andy Balaam 56da4a31a4 Merge pull request #3231 from matrix-org/andybalaam/wiremock-as-workspace-dep
build: Make wiremock a workspace dependency
2024-03-19 10:04:04 +00:00
Ivan Enderlin ffacbe8666 feat(sdk): Reverse the indices order of ItemPosition.
Previously, in a chunk with items `a`, `b` and `c`, their indices were
2, 1 and 0. It creates a problem when we push new items: all indices
must be shifted to the left inside the same chunk. That's not optimised.
This patch reverses the order, thus now `a` has index 0, `b` has index 1
and `c` has index 2.

It also removes a possible bug where we use `item_index` without
“reversing” it. This is now obvious that we don't need to re-compute the
`item_index`, we can use it directly.
2024-03-19 10:40:36 +01:00
Andy Balaam ca13be020c build: Make wiremock a workspace dependency 2024-03-19 09:39:31 +00:00
Samy Djemaï baf97c69b1 chore: upgrade uniffi-rs to latest commit
Signed-off-by: Samy Djemaï <53857555+SamyDjemai@users.noreply.github.com>
2024-03-19 10:37:26 +01:00
Ivan Enderlin 628374b8d8 feat(sdk): Optimise LinkedChunk iterators.
This patch optimises `LinkedChunk::rchunks` and `chunks` by _not_ using
`rchunks_from` and `chunks_from`. Indeed, it's faster to not call the
inner `chunk` method + `unwrap`ping the result and so on. Just a tiny
optimisation.

This patch also uses the new `Chunk::last_item_position` method for
`LinkedChunk::items`. Abstraction for the win!
2024-03-19 10:11:58 +01:00
Ivan Enderlin 454d49aa64 feat(sdk): Add Chunk::first_item_position and ::last_item_position.
This patch implements `Chunk::first_item_position` and
`Chunk::last_item_position` as a way to _position_ the
“cursor” (`ItemPosition`) in the correct way when we want to do some
particular insertion (at the beginning or at the end of a chunk).
2024-03-19 10:05:12 +01:00
Ivan Enderlin 06e212c11d !fix rebase issue 2024-03-19 09:48:28 +01:00
Ivan Enderlin 213dac2d30 feat(sdk): Rewrite LinkedChunk::replace_gap_at.
This patch rewrites `LinkedChunk::replace_gap_at`. Instead of inserting
new items on the _previous_ chunk of the gap and doing all the stuff
here, a new items chunk is created _after_ the gap (where items are
pushed), to finally unlink and remove the gap.

First off, it removes an `unwrap`. Second, if the previous chunk was
an items chunk, and had free space, the items would have been added in
there, which is not the intended behaviour. The tests have been updated
accordingly.
2024-03-19 09:48:28 +01:00
Ivan Enderlin 6b754acd81 feat(sdk): Add Chunk::as_ptr.
This patch adds the new `Chunk::as_ptr` method. It simplifies the code a
little bit.
2024-03-19 09:39:20 +01:00
Ivan Enderlin 88f75a85bb feat(sdk): Chunk::is_gap and ::is_items are now public. 2024-03-19 09:39:09 +01:00
Ivan Enderlin a8e522c164 feat(sdk): Implement LinkedChunk::chunks.
This patch implements the `LinkedChunk::chunks` method that returns a
forward iterator over the chunks.
2024-03-19 09:39:01 +01:00
Ivan Enderlin 9dcab4ed30 feat(sdk): ItemPosition has the copy semantics.
This patch implements `Copy` and `Clone` for `ItemPosition`.
2024-03-19 09:38:42 +01:00
Ivan Enderlin 4774cc8e65 feat(sdk): Implement Chunk::content.
This patch implements `Chunk::content` to get an immutable reference to
the content of a chunk.
2024-03-19 09:38:33 +01:00
Ivan Enderlin 9c4318d191 feat(sdk): Convert ChunkIdentifier to ItemPosition.
This patch implements `From<ChunkIdentifier>` for `ItemPosition`.
It's useful when we get a `ChunkIdentifier` and we need to `insert_…
_at(item_position)`.
2024-03-19 09:38:20 +01:00
Ivan Enderlin 2bb07d6a4e feat(sdk): Implement LinkedChunk::items.
This patch implements the new `LinkedChunk::items` method that returns
a forward iterator over items.
2024-03-19 09:38:06 +01:00
Ivan Enderlin 44029009e4 feat(sdk): Implement ChunkIdentifier::to_last_item_position.
This patch is about an internal thing, but it makes the code easier
to understand.
2024-03-19 09:37:52 +01:00
Andy Balaam b2c96b72b0 ci: Add a CI workflow to verify the minimum supported Rust version 2024-03-18 18:39:07 +01:00
Andy Balaam 9d281937d5 build: Add a missing dependency on wiremock even when testing feature is not enabled 2024-03-18 18:39:07 +01:00
Benjamin Bouvier 818a435f9e event cache: rename backpaginate_with_token to backpaginate 2024-03-18 17:02:05 +01:00
Andy Balaam 486b6d6e2b crypto: Save outbound sessions in MemoryStore 2024-03-18 15:21:41 +00:00
Andy Balaam 32edfb1a9f Merge pull request #3219 from matrix-org/andybalaam/fix-warnings-in-integration-tests
crypto: Fix warnings in integration_tests.rs (and a tiny bug)
2024-03-18 15:11:53 +00:00
Andy Balaam 9159a5983b crypto: Fix typo bug in integration tests 2024-03-18 14:54:59 +00:00
Andy Balaam 69ac7e07e6 crypto: Fix warnings in integration tests 2024-03-18 14:54:59 +00:00
Andy Balaam ee23839259 crypto: Remove unused imports from integration_tests.rs
The warnings were hidden because no-one within this crate used this macro.
2024-03-18 14:54:59 +00:00
Ivan Enderlin 555dfe0e77 feat(sdk): LinkedChunk can hold a value for Gaps
feat(sdk): `LinkedChunk` can hold a value for `Gap`s
2024-03-18 12:50:25 +01:00
Ivan Enderlin 7f7d9b8175 chore(sdk): Rename T and U in LinkedChunk.
This patch renames the generic parameters `T` and `U` to `Item` and
`Gap` for the `LinkedChunk` type and siblings.
2024-03-18 12:36:51 +01:00
Benjamin Bouvier 57f6715784 timeline: get rid of the update_timeline_item! macro and replace it with function calls 2024-03-18 12:36:35 +01:00
Benjamin Bouvier b587c064d7 timeline: prefix more tests with test_ 2024-03-18 12:36:35 +01:00
Benjamin Bouvier 52dc64e0db timeline: add doc comments here and there 2024-03-18 12:36:35 +01:00
Andy Balaam 7b7ee980e8 build: Update minimum supported Rust version to 1.76
This reflects the reality of the situation at the moment: we need 1.76.
to compile, and Ruma requires 1.75.
2024-03-18 11:45:02 +01:00
Ivan Enderlin 5591be9a8e feat(sdk): LinkedChunk can hold a value for Gaps.
This patch updates `ChunkContent::Gap` to hold a content `U`. Thus,
`Chunk` and LinkedChunk` both get a new generic parameter `U`. Some
methods like `new_gap` or `insert_gap_at` take a new `content: U`
parameter.

This type `RoomEvents` (that uses `LinkedChunk`) is also updated
accordingly.
2024-03-18 10:52:46 +01:00
Kévin Commaille 876d3237eb sdk: Check if server name points to homeserver during discovery (#3218)
The small first commit reintroduces `sanitize_server_name` in the public API. In Fractal, we use it to validate the string in the input before allowing the user to trigger the discovery.

The main commit changes a bit the discovery process: before, server names like `example.org` would only be checked for the presence of a well-known, and only URLs like `https://example.org` would be checked as a homeserver. Now, providing `example.org` will also check if `https://example.org` is the URL of a homeserver.

Sadly I don't think it's possible to add tests for it as it would require to have a homeserver accessible via HTTPS.

---

* sdk: Restore sanitize_server_name in the public API

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>

* sdk: Check if a provided server name points to a homeserver during discovery

Before, only URLs like `https://example.org` would be checked as a homeserver.
Providing `example.org` will check if `https://example.org` is the URL of a homeserver.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>

* Refactor to avoid duplication

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>

---------

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-03-15 19:18:33 +00:00
Mauro a308d34d09 Merge branch 'main' into mauroromito/directory_search 2024-03-15 15:08:16 +01:00
Benjamin Bouvier cabab289c9 timeline: get rid of ManuallyDrop in the TimelineInnerStateTransaction 2024-03-15 15:08:10 +01:00
Benjamin Bouvier a98779dfbb timeline: use u64 for all the fields of PaginationOutcome 2024-03-15 15:08:10 +01:00
Benjamin Bouvier 182e84cd3d timeline: get rid of deref/deref_mut from TimelineInnerState to TimelineInnerMetadata 2024-03-15 15:08:10 +01:00
Benjamin Bouvier 5c049d6e2e timeline: rename handle_joined_room_update to handle_sync_events 2024-03-15 15:08:10 +01:00
Benjamin Bouvier 057bca070c timeline: get rid of the synthetic Timeline and JoinedRoomUpdate when updating the timeline 2024-03-15 15:08:10 +01:00
Benjamin Bouvier 75871216d2 timeline: sanitize usage of meta in the TimelineInnerStateTransaction
Before this patch, the meta field would be mutated, even when the transaction would be aborted. This changes the update scheme to meta
with the following:

- when creating the transaction, clone the meta (but keep the pointer location to the previous one)
- all the transaction's methods operate on the WIP meta
- when committing, replace the previous meta with the current one
2024-03-15 15:08:10 +01:00
Benjamin Bouvier 4661ca810a timeline: get rid of deref/deref_mut from TimelineInnerStateTransaction to TimelineInnerMetadata 2024-03-15 15:08:10 +01:00
Benjamin Bouvier f3687dc4c7 timeline: don't return the unused event id in handle_remote_event 2024-03-15 15:08:10 +01:00
Benjamin Bouvier 694fb57c17 timeline: lower the number of methods to add events 2024-03-15 15:08:10 +01:00
Benjamin Bouvier e1b9fe266d timeline: prefix a few tests with test_ 2024-03-15 15:08:10 +01:00
Benjamin Bouvier 35a1596755 timeline: change number of added/updated items to u64 in `HandleManyEventsResult
u64 should be enough for everyone?
2024-03-15 15:08:10 +01:00
Benjamin Bouvier 117307eaff timeline: inline TimelineInnerStateTransaction::handle_live_event 2024-03-15 15:08:10 +01:00
Benjamin Bouvier 52a5a86cf9 event cache: important status update 2024-03-15 15:08:10 +01:00
Benjamin Bouvier 9faa839f56 event cache: don't return the prev_batch token anymore \o/
It's now the event cache's responsibility to handle back-pagination, so the timeline doesn't have to do it anymore.
2024-03-15 15:08:10 +01:00
bitfriend 5f960d889e Append the missed cancel codes 2024-03-15 11:52:08 +01:00
Mauro 655ac0725c Merge branch 'main' into mauroromito/directory_search 2024-03-14 17:56:23 +01:00
Mauro Romito 229105536b docs: updated docs 2024-03-14 17:55:54 +01:00
Mauro Romito 4b85a81347 docs: warning about NSFW content 2024-03-14 16:53:18 +01:00
Richard van der Hoff a328d8787a crypto: Log errors from Olm decryption (#3212)
When we fail to decrypt an olm message, it is useful to know *why* it
failed. Include the details of the failures in the warning message.
2024-03-14 15:22:46 +00:00
Benjamin Bouvier d1e92ece42 timeline: move the back-pagination code into the timeline/pagination.rs file
No changes in behavior, just pure code motion.
2024-03-14 15:47:53 +01:00
Benjamin Bouvier ff4a8f0ba5 timeline: integrate the event cache pagination into the UI timeline 2024-03-14 15:47:53 +01:00
Ivan Enderlin 0a7e28f681 Merge pull request #3166 from Hywan/feat-sdk-event-cache-store-experimental
feat(sdk): Event cache experimental store
2024-03-14 15:27:22 +01:00
Ivan Enderlin e8cf6dcde6 doc(sdk): Update the CHANGELOG.md. 2024-03-14 15:09:22 +01:00
Ivan Enderlin 505fb682af feat(sdk): Introduce the LinkedChunk type.
This patch is a work-in-progress. It explores an experimental data
structure to store events in an efficient way.

Note: in this comment, I will use the term _store_ to mean _database_
or _storage_.

The biggest constraint is the following: events can be ordered in
multiple ways, either topological order, or sync order. The problem is
that, when syncing events (with `/sync`), or when fetching events (with
`/messages`), we **don't know** how to order the newly received events
compared to the already downloaded events. A reconciliation algorithm
must be written (see #3058). However, from the “storage” point of view,
events must be read, written and re-ordered efficiently.

The simplest approach would be to use an `order_index` for example.
Every time a new event is inserted, it uses the position of the last
event, increments it by one, and done.

However, inserting a new event in _the middle_ of existing events would
shift all events on one side of the insertion point: given `a`, `b`,
`c`, `d`, `e`, `f` with `f` being the most recent event, if `g` needs
to be inserted between `b` and `c`, then `c`, `d`, `e`, `f`'s ordering
positions need to be shifted. That's not optimal at all as it would
imply a lot of updates in the store.

Example of a relational database:

| ordering_index | event |
|----------------|-------|
| 0              | `a`   |
| 1              | `b`   |
| 2              | `g`   |
| 3              | `c`   |
| …              | …     |

An insertion can be O(n), and it can happen more frequently than one
can think of. Let's imagine a permalink to an old message: the user
opens it, a couple of events are fetched (with `/messages`), and these
events must be inserted in the store, thus potentially shifting a lot of
existing events. Another example: Imagine the SDK has a search API for
events; as long as no search result is found, the SDK will back-paginate
until reaching the beginning of the room; every time there is a
back-pagination, a block of events will be inserted: there is more and
more events to shift at each back-pagination.

OK, let's forget the `order_index`. Let's use a linked list then? Each
event has a _link_ to the _previous_ and to the _next_ event.

Inserting an event would be at worst O(3) in this case: if the previous
event exists, it must be updated, if the next event exists, it must be
updated, finally, insert the new event.

Example with a relational database:

| previous | id      | event | next    |
|----------|---------|-------|---------|
| null     | `id(a)` | `a`   | `id(b)` |
| `id(a)`  | `id(b)` | `b`   | `id(c)` |
| `id(b)`  | `id(c)` | `c`   | null    |

This approach ensures a fast _writing_, but a terribly slow _reading_.
Indeed, reading N events require N queries in the store. Events aren't
contiguous in the store, and cannot be ordered by the database engine
(e.g. with `ORDER BY` for SQL-based database). So it really requires one
query per event. That's a no-go.

In the two scenarios above, another problem arises. How to represent
a gap? Indeed, when new events are synced (via `/sync`), sometimes the
response contains a `limited` flag, which means that the results are
_partial_.

Let's take the following example: the store contains `a`, `b`, `c`.
After a long offline period (during which the room has been pretty
active), a sync is started, which provides the following events: `x`,
`y`, `z` + the _limited_ flag. The app is killed and reopened later.
The event cache store will contain `a`, `b`, `c`, `x`, `y`, `z`. How
do we know that there is a hole/a gap between `c` and `x`? This is an
important information! When `z`, `y` and `x` are displayed, and the user
would like to scroll up, the SDK must know that it must back-paginate
before providing `c`, `b` and `a`.

So the data structure we use must also represent gaps. This information
is also crucial for the events reconciliation algorithm.

What about a mix between the two? Here is _Linked Chunk_.

A _linked chunk_ is like a linked list, except that each node is either
a _Gap_ or an _Items_. A _Gap_ contains nothing, it's just a gap. An
_Items_ contains _several_ events. A node is called a _Chunk_. A _chunk_
has a maximum size, which is called a _capacity_. When a chunk is full,
a new chunk is created and linked appropriately. Inside a chunk, an
ordering index is used to order events. At this point, it becomes a
trade-off the find the appropriate chunk size to balance the performance
between reading and writing. Nonetheless, if the chunk size is 50, then
reading events is 50 times more efficient with a linked chunk than with
a linked list, and writing events is at worst O(49), compare to the O(n
- 1) of the ordering index.

Example with a relational database. First table is `events`, second
table is `chunks`.

| chunk id | index | event |
|----------|-------|-------|
| `$0`     | 0     | `a`   |
| `$0`     | 1     | `b`   |
| `$0`     | 2     | `c`   |
| `$0`     | 3     | `d`   |
| `$2`     | 0     | `e`   |
| `$2`     | 1     | `f`   |
| `$2`     | 2     | `g`   |
| `$2`     | 3     | `h`   |

| chunk id | type  | previous | next |
|----------|-------|----------|------|
| `$0`     | items | null     | `$1` |
| `$1`     | gap   | `$0`     | `$2` |
| `$2`     | items | `$1`     | null |

Reading the last chunk consists of reading all events where the
`chunk_id` is `$2` for example, and contains events `e`, `f`, `g` and
`h`. We can sort them easily by using the `event_index` column. The
previous chunk is a gap. The previous chunk contains events `a`, `b`,
`c` and `d`.

Being able to read events by chunk clearly limit the amount of reading
and writing in the store. It is also close to what will be really done
in real life with this store. It also allows to represent gaps. We can
replace a gap by new chunk pretty easily with few writings.

A summary:

| Data structure | Reading           | Writing         |
|----------------|-------------------|-----------------|
| Ordering index | “O(1)”[^1] (fast) | O(n - 1) (slow) |
| Linked list    | O(n) (slow)       | O(3) (fast)     |
| Linked chunk   | O(n / capacity)   | O(capacity - 1) |

This patch contains a draft implementation of a linked chunk. It will
strictly only contain the required API for the `EventCache`, understand
it _is not_ designed as a generic data structure type.

[^1]: O(1) because it's simply one query to run; the database engine
does the sorting for us in a very efficient way, particularly if the
`ordering_index` is an unsigned integer.
2024-03-14 15:09:22 +01:00
SpiritCroc 2520804a60 ffi: Expose filename and formatted body fields for media captions
In relevance to MSC2530
2024-03-14 14:43:03 +01:00
Benjamin Bouvier 73684ab57c ui/timeline: allow subscribing to UTDs and late-decrypt events (#3206)
This adds a new mechanism in the UI crate (since re-attempts to decrypt happen in the timeline, as of today — later that'll happen in the event cache) to notify whenever we run into a UTD (an event couldn't be decrypted) or a late-decryption event (after some time, a UTD could be decrypted).

This new hook will deduplicate pings for the same event (identifying events on their event id), and also implements an optional grace period. If an event was a UTD:

- if it's still a UTD after the grace period, then it's reported with a `None` `time_to_decrypt`,
- if it's not a UTD anymore (i.e. it's been decrypted in the meanwhile), then it's reported with a `time_to_decrypt` set to the time it took to decrypt the event (approximate, since it starts counting from the time the timeline receives it, not the time the SDK fails to decrypt it at first).

It's configurable as an optional hook on timeline builders. For the FFI, it's configurable at the sync service's level with a "delegate", and then the sync service will forward the hook to the timelines it creates, and the hook will forward the UTD info to the delegate.

Part of https://github.com/element-hq/element-meta/issues/2300.

---

* ui: add a new module and trait for subscribing to unable-to-decrypt notifications

and late decryptions (i.e. the key came in after the event that required it for decryption).

* timeline: hook in (!) the unable-to-decrypt hook

* timeline: prefix some test names with test_

* utd hook: delay reporting a UTDs

* ffi: add support for configuring the utd hook

* utd hook: switch strategy, have a single hook

And have the data structure contain extra information about late-decryption events.

* utd hook: rename `SmartUtdHook` to `UtdHookManager`

* ffi: configure the UTD hook with a grace period of 60 seconds

And ignore UTDs that have been late-decrypted in less than 4 seconds.

* utd hook: update documentation and satisfy the clippy gods

* ffi: introduce another UnableToDecryptInfo FFI struct that exposes simplified fields from the SDK's version

* review: introduce type alias for pending utd reports

* review: address other review comments
2024-03-14 14:13:44 +01:00
Benjamin Bouvier 7718f90428 event cache: add support for running back-pagination (#3195)
This adds support for back-pagination into the event cache, supporting enough features for integrating with the timeline (which is going to happen in a separate PR).

The idea is to provide two new primitives:

- one to get (or wait, if we don't have any handy) the latest pagination token received by the sync,
- one to run a single back-pagination, given a token (or not — which will backpaginate from the end of the room's timeline)

The timeline code can then use those two primitives in a loop to replicate the current behavior it has (next PR to be open Soon™).

The representation of events in the store is changed, so that a timeline can have *entries*, which are one of two things:

- either an event, as before
- or a gap, identified by a backpagination token (at the moment)

This allows us to avoid a lot of complexity from the back-pagination code in the timeline, where we'd attach the backpagination token to an event that only had an event_id. We don't have to do this here, and I suppose we could even attach the backpagination token to the next event itself.

This doesn't do reconciliation yet; the plan is to add it as a next step.
2024-03-14 09:57:52 +00:00
Mauro 5e692931dd Apply suggestions from code review
Co-authored-by: Ivan Enderlin <ivan@mnt.io>
Signed-off-by: Mauro <34335419+Velin92@users.noreply.github.com>
2024-03-14 10:42:27 +01:00
Richard van der Hoff 5e10ccc248 Add more logging for crypto store generation counter (#3207)
It's a bit unclear whether the crypto-store generation counter is doing the right thing
in terms of causing us to reload the OlmMachine. There is a suspicion that things
 might be keeping hold of references to the old OlmMachine.

This PR attempts to add the generation number to the logging for any operations that 
hold the cross-process lock. It's obviously not bulletproof: for example, it is possible
for the OlmMachine to be replaced without holding the lock; but hopefully this will
at least help us understand what's going on.
2024-03-13 17:09:57 +00:00
Mauro Romito 73b01743a5 improved code spacing 2024-03-13 12:48:32 +01:00
Mauro Romito 2f9b9942c3 docs: removed useless comment 2024-03-13 12:45:50 +01:00
Mauro Romito a52a2329a1 pr suggestions
improved the conversion by using a try from and changed the nex_token to a search state to indicate the current state of the search
2024-03-13 12:43:26 +01:00
Ivan Enderlin 6f9147de86 Merge pull request #3205 from matrix-org/stefan/invites_main_room_list
feat: Expose a room list filter for Invites only
2024-03-13 11:43:10 +01:00
Stefan Ceriu 6a67ff9acf Update invite room list filter tests 2024-03-13 12:30:33 +02:00
Stefan Ceriu 4eb3da6be7 Update crates/matrix-sdk-ui/src/room_list_service/filters/invite.rs
Co-authored-by: Ivan Enderlin <ivan@mnt.io>
Signed-off-by: Stefan Ceriu <stefan.ceriu@gmail.com>
2024-03-13 12:15:16 +02:00
Ivan Enderlin 78889aec8c fix(ruma): Add the compat-tag-info feature
fix(ruma): Add the `compat-tag-info` feature
2024-03-13 11:10:38 +01:00
Ivan Enderlin b0880996fc fix(ruma): Add the compat-tag-info feature.
This patch enables the `compat-tag-info` feature on Ruma, so that
`TagInfo::order` can be deserialized from both a `f64` or a `string`
representing a `f64`[^1].

[^1]: https://github.com/ruma/ruma/blob/f24cae17f50d140a0ff112cb3dc74a2053aa1df4/crates/ruma-events/src/tag.rs#L180-L185
2024-03-13 10:24:18 +01:00
Andy Balaam 88a8a7007c Merge pull request #3200 from matrix-org/andybalaam/feature-flag-for-overriding-expiration-min
crypto: Add a feature flag to disable the minimum session rotation time
2024-03-12 14:45:45 +00:00
Andy Balaam ff1555ed40 crypto: Clarify Durations in outbound tests 2024-03-12 14:29:27 +00:00
Andy Balaam 5c29c08941 crypto: Document that _disable-minimum-rotation-period-ms should not be used 2024-03-12 14:17:31 +00:00
Damir Jelić 3fb8a46c95 test: Add a test for the verification state reset case 2024-03-12 14:36:05 +01:00
Damir Jelić 31d985813a test: Switch to scoped mocks for the /sync mocking
Wiremock doesn't allow overwriting of a mock, so if we want to mock
different sync response bodies for the same path we'll have to mount the
mock in a subscobe.

This also removes the need to access some internal OlmMachine state to
get us notified about changed devices.
2024-03-12 14:36:05 +01:00
Stefan Ceriu eea475854c feat: Expose a verification state listener directly from Encryption 2024-03-12 14:36:05 +01:00
Richard van der Hoff a6c2719976 Remove OlmError::Decryption (#3204)
I believe this is never used, so can be removed
2024-03-12 11:16:41 +00:00
Timo Kösters 2f58cb1620 members: Simplify disambiguation logic when loading member list (#3184)
When all room members are loaded, we do not need an incremental member update. We know that parsing the /members response will only lead to more ambiguous names, not less. And because /members returns the complete list, we can directly use that list as the disambiguation map.

This improves the performance in my emulator from 56s to 9s and on a less performant device from 11mins to 11s (Tested experimentally on Matrix HQ using log statements in element android. If I have time, I will write a proper benchmark tomorrow.

See also https://github.com/matrix-org/matrix-rust-sdk/pull/3184#issuecomment-1986170631 for a more detailed benchmark run.

---

* members: Simplify disambiguation logic

* members: Prevent api misuse for receive_members

* members: Benchmark receive_all_members performance

* sdk: remove unused import

* sdk-base: rename `ApiMisuse` error to `InvalidReceiveMembersParameters`

* benchmarks: extract the member loading benchmark to `room_bench.rs`

* benchmarks: remove wiremock

* sdk-base: fix format

* sdk-base: try fixing tests

* benchmark: Provide some data to the store so the search and disambiguation happen

* benchmark: fix clippy

* benchmark: use a constant for `MEMBERS_IN_ROOM`

* sdk(style): reduce indent in `receive_all_members`

---------

Co-authored-by: Jorge Martín <jorgem@element.io>
Co-authored-by: Benjamin Bouvier <public@benj.me>
2024-03-12 10:15:30 +00:00
Andy Balaam 0947349ae0 crypto: Add a feature flag to disable the minimum session rotation time
The feature flag is called "disable-minimum-rotation-period-ms" and
should not be used outside of tests, which is why it is largely
undocumented.
2024-03-12 09:40:19 +00:00
Andy Balaam 2f3b85d244 crypto: Split clamping of rotation_period into a separate function 2024-03-12 09:40:19 +00:00
Andy Balaam 919d58f94b crypto: Test that we enforce a minimum rotation_period_ms 2024-03-12 09:40:19 +00:00
Stefan Ceriu 16dcfb2e84 feat: Expose a room list filter for Invites only 2024-03-11 17:41:28 +02:00
Mauro 9ef78a484c Merge branch 'main' into mauroromito/directory_search 2024-03-11 16:30:55 +01:00
Ivan Enderlin 3edaff1364 Merge pull request #3178 from matrix-org/ex-tui
labs: turn `rrrepl` into a timeline client
2024-03-11 14:53:35 +01:00
Ivan Enderlin 45055d80cd Merge pull request #3203 from Hywan/feat-ui-room-list-invite-revisit
feat(ui,ffi): Add a new `experimental-room-list-with-unified-invites` feature
2024-03-11 13:28:09 +01:00
Richard van der Hoff 1ea163271b crypto: Include event timestamp in decryption failure logs
Co-authored-by: Benjamin Bouvier <public@benj.me>
Signed-off-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
2024-03-11 13:16:39 +01:00
Andy Balaam 899e4db8d0 crypto: Break up the expiration tests for clarity 2024-03-11 12:41:35 +01:00
Ivan Enderlin e9cca7f68d feat(ui,ffi): Add a new experimental-room-list-with-unified-invites feature.
The idea of this patch is to explore the possibility to unify the
`all_rooms` list with the `invites` list in `RoomListService`.
Since this is entirely experimental, it's behind a new feature
flag. The feature itself can be configured at runtime by using the
new `SyncServiceBuilder::with_unified_invites_in_room_list` builder
method, or directly with `RoomListService::new_with_unified_invites`
constructor.
2024-03-11 12:05:32 +01:00
Kévin Commaille fd709b9d52 workspace: Bump ruma crate
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-03-09 15:18:46 +01:00
Benjamin Bouvier 4ad79d6d44 multiverse: hide the password by using rpassword to prompt it 2024-03-08 17:44:55 +01:00
Benjamin Bouvier e57a02fd91 multiverse: add support for backpagination 2024-03-08 17:37:26 +01:00
Benjamin Bouvier c41f7975b3 labs: turn rrrepl into a timeline client 2024-03-08 16:08:29 +01:00
Jorge Martin Espinosa cb6b420ad0 ffi: add previous power levels to OtherState::RoomPowerLevels (#3199)
This is needed to be able to diff between increases and decreases of power levels ("user Alice was promoted Admin", etc.).

---

* ffi: add `previous` power levels to `OtherState::RoomPowerLevels`

This is needed to be able to diff between increases and decreases of power levels.

* ffi: please clippy

* ffi: inline initialization of `previous` and `users`
2024-03-08 15:03:02 +00:00
Hanadi 724d133cce sdk&ffi: server unstable features support for MSC4028 (#3192)
Fixes https://github.com/matrix-org/matrix-rust-sdk/issues/3191

Allows support for fetching the unstable_features from `/_matrix/clients/versions`.
Specifically, to be used for checking the state of org.matrix.msc4028 through ffi to the clients.

---

* sdk: fetch unstable_features supported by homeserver

Signed-off-by: hanadi92 <hanadi.tamimi@gmail.com>

* ffi: add can_homeserver_push_encrypted_event_to_device method

Signed-off-by: hanadi92 <hanadi.tamimi@gmail.com>

* fix: use copied instead of dereferencing

Co-authored-by: Benjamin Bouvier <public@benj.me>
Signed-off-by: Hanadi <hanadi.tamimi@gmail.com>

* fix: move can_homeserver_push_encrypted_event_to_device logic to sdk

Signed-off-by: hanadi92 <hanadi.tamimi@gmail.com>

* fix: remove unused unstable features param in client builder

Signed-off-by: hanadi92 <hanadi.tamimi@gmail.com>

* fix: use assert instead of asserteq for bool check

Signed-off-by: hanadi92 <hanadi.tamimi@gmail.com>

* fix: documentation

Signed-off-by: hanadi92 <hanadi.tamimi@gmail.com>

* Apply suggestions from code review

Signed-off-by: Benjamin Bouvier <public@benj.me>

---------

Signed-off-by: hanadi92 <hanadi.tamimi@gmail.com>
Signed-off-by: Hanadi <hanadi.tamimi@gmail.com>
Signed-off-by: Benjamin Bouvier <public@benj.me>
Co-authored-by: Benjamin Bouvier <public@benj.me>
2024-03-08 11:28:04 +01:00
Benjamin Bouvier b7d6fd08f1 event cache: enforce unique access on the EventCacheStore 2024-03-07 18:57:57 +01:00
Jorge Martin Espinosa 0469c27b91 ffi: Add methods to get and reset the power levels of a Room
- `Room::build_power_level_changes_from_current()` was replaced by `Room::get_power_levels()`, which now returns an SDK/Ruma `RoomPowerLevels` value containing all the data we need to display these values in UI and not only the customised values.
- `Room::reset_power_levels()` was added to the FFI layer.
2024-03-07 12:46:13 +01:00
Benjamin Kampmann f14c00db82 store: Add a method to set a custom value without reading and returning the old value
This is useful if we don't care about the old value, which lets us avoid unnecessary reads.
2024-03-07 12:02:32 +01:00
Johannes Marbach a204b2994d chore: improve create_room documentation
Signed-off-by: Johannes Marbach <n0-0ne+github@mailbox.org>
2024-03-06 09:52:23 +01:00
Mauro 3f627f4125 Merge branch 'main' into mauroromito/directory_search 2024-03-05 11:44:15 +01:00
dependabot[bot] 98a68632df chore(deps): bump mio from 0.8.10 to 0.8.11
Bumps [mio](https://github.com/tokio-rs/mio) from 0.8.10 to 0.8.11.
- [Release notes](https://github.com/tokio-rs/mio/releases)
- [Changelog](https://github.com/tokio-rs/mio/blob/master/CHANGELOG.md)
- [Commits](https://github.com/tokio-rs/mio/compare/v0.8.10...v0.8.11)

---
updated-dependencies:
- dependency-name: mio
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-03-05 10:42:26 +01:00
Jorge Martin Espinosa 0c98e26a05 sdk: create new users_with_power_levels fn (#3182)
It maps user ids to users' power levels.

Also, make sure it just returns an empty map if this info is not available, instead of crashing. 

Then use it in the FFI side to output updated data for the `RoomInfo`.

---

* sdk: create new `users_with_power_levels` fn which maps user ids to users' power levels

Also, make sure it just returns an empty map if this info is not available, instead of crashing.

* Update crates/matrix-sdk/src/room/mod.rs

Co-authored-by: Benjamin Bouvier <public@benj.me>
Signed-off-by: Jorge Martin Espinosa <angel.arasthel@gmail.com>

* Improve tests

---------

Signed-off-by: Jorge Martin Espinosa <angel.arasthel@gmail.com>
Co-authored-by: Benjamin Bouvier <public@benj.me>
2024-03-04 16:37:16 +01:00
Benjamin Bouvier 4b56ca1841 event cache: remove the RoomNotFound error
Having `EventCache::for_room` return an `Option` avoids the need for the error. One caller can
safely unwrap it, and others can log and ignore rooms that have disappeared (like we do in `call_sync_response_handlers`).
2024-03-04 15:11:14 +01:00
Benjamin Bouvier 8d2e790bca event cache: add a Room::event_cache() method
This keeps the `RoomNotFound` error, which could still happen in theory if the `EventCache` is
being misused internally.
2024-03-04 15:11:14 +01:00
Stefan Ceriu e4be216731 feat: add support for m.call.invite events in the timeline and as a last room message 2024-03-04 14:57:01 +01:00
Benjamin Bouvier 74727e5f84 ci: update codecov action to v4 2024-03-04 12:25:19 +01:00
Andy Balaam 4b711e4b37 Merge pull request #3177 from matrix-org/doug/multi-user-power-levels
FFI: Update the power levels of multiple users at once.
2024-03-04 10:10:28 +00:00
Mauro Romito 4db69647ce Merge branch 'mauroromito/directory_search' of github.com:matrix-org/matrix-rust-sdk into mauroromito/directory_search 2024-03-01 17:25:16 +01:00
Mauro Romito e922a58cc3 tests: fix fmt 2024-03-01 17:25:11 +01:00
Mauro eb0ddbc063 Merge branch 'main' into mauroromito/directory_search 2024-03-01 17:18:08 +01:00
Mauro Romito 9fbc2ab07c mocking library not supported on wasm 2024-03-01 17:17:24 +01:00
Mauro Romito 2f7b2f0451 fix: fmt 2024-03-01 17:07:52 +01:00
Mauro Romito ad1623da58 docs: fixed docs 2024-03-01 15:44:24 +01:00
Mauro Romito 2abe3aba4a improved docs 2024-03-01 15:21:57 +01:00
Andy Balaam 82684d64d4 Merge pull request #3180 from matrix-org/jme/bump-uniffi-referenced-commit-so-android-works-again
ffi: bump the UniFFi referenced commit again
2024-03-01 13:27:53 +00:00
Jorge Martín 7b40daa3cf ffi: bump the UniFFi referenced commit again
At the moment, the SDK can't be built for Android because of these 2 issues:

- https://github.com/mozilla/uniffi-rs/issues/1996
- https://github.com/mozilla/uniffi-rs/issues/1995

Those have been fixed in the new commit.
2024-03-01 13:59:12 +01:00
Timo Kösters 5ee3897f7e ffi: aggregate RoomMember fields early instead of requiring to call getters (#3172)
This does two things:

- raise the timeout value for the `/members` queries, because they can super slow in Synapse because of nasal demons,
- and aggregate all the fields of `RoomMember` early, so users don't have to call getters to read each field.

---

* room_members: Export plain old data for room members to avoid FFI calls

Signed-off-by: Timo Kösters <timo@koesters.xyz>

* room_member: Respond to review feedback

* room_member: Remove previous RoomMember struct

* ffi: rename ExportedRoomMember to RoomMember

---------

Signed-off-by: Timo Kösters <timo@koesters.xyz>
Co-authored-by: Benjamin Bouvier <public@benj.me>
2024-02-29 17:27:21 +01:00
Benjamin Bouvier 370f4735f7 ffi: simplify the declaration type 2024-02-29 15:03:45 +01:00
Mauro 77ba3010cc Merge branch 'main' into mauroromito/directory_search 2024-02-29 14:29:31 +01:00
Mauro Romito b2b9b5fa12 feat(bindings): reverted some code from ffi 2024-02-29 14:29:03 +01:00
Doug c251f16292 ffi: Update the power levels of multiple users as once. 2024-02-29 13:12:30 +00:00
Mauro Romito 8890bf3cee feat(bindings): improved and fixed ffi code 2024-02-29 14:10:45 +01:00
Mauro Romito 2e3ced1fb2 docs: more documentation 2024-02-29 12:58:34 +01:00
Mauro Romito 2163ab03ec tests: test improvements and added a new test 2024-02-29 12:48:49 +01:00
Mauro 4b1eefca80 Apply suggestions from code review
Co-authored-by: Ivan Enderlin <ivan@mnt.io>
Signed-off-by: Mauro <34335419+Velin92@users.noreply.github.com>
2024-02-29 11:52:31 +01:00
Mauro Romito 4dd7c3093c tests: improved the tests by adding the limit
into the check for the request
2024-02-28 19:41:31 +01:00
Mauro Romito 70466aafb4 docs: more documentation for types and the mod 2024-02-28 19:25:52 +01:00
Mauro Romito 3e35f163b7 docs: updated documentation
and removed code from ffi that will be changed soon
2024-02-28 19:17:58 +01:00
Mauro Romito 690ed4611d tests: unit tests have been completed 2024-02-28 19:01:42 +01:00
Stefan Ceriu 8392ef07cd ffi: bump uniffi to latest git rev to generate open swift classes 2024-02-28 18:46:26 +01:00
Mauro Romito 9c33540af8 tests: improved tests and added a unit test 2024-02-28 16:18:35 +01:00
Doug 0401b995b7 ffi: Expose getting a power level from a role. 2024-02-28 13:27:10 +01:00
Andy Balaam 0521d23e94 Merge pull request #3167 from matrix-org/andybalaam/doc-fixes-e2ee
docs: Punctuation and wording fixes in encryption docs
2024-02-28 09:56:19 +00:00
Mauro Romito 37d95571e9 test: fixed a test by a adding a small delay 2024-02-27 17:40:03 +01:00
Mauro Romito caa9a7d8be tests: code improvement for the filter integration test 2024-02-27 17:31:26 +01:00
Mauro Romito d9231be1ba feat(bindings): listener code 2024-02-27 17:08:55 +01:00
Jorge Martin Espinosa 2068e7f266 sdk & ffi: add user power levels and role getter to RoomInfo (#3170)
Changes:
- sdk: Add `get_user_power_level` and `get_suggested_user_role` functions so we don't need to load the whole room member list to know if a user has some power level/role.
- ffi: add an FFI fn for `get_suggested_user_role`.
- ffi: add `user_power_levels` to `RoomInfo`.

The goal of this PR is being able to fetch a user's power level or role almost immediately and avoid having to load and find the user in the room member list, which can be very slow to load (especially in EX Android).

---

* sdk: Add `get_user_power_level` and `get_suggested_user_role` functions to get the power level for a user without loading the room member list.

* ffi: add `suggested_role_for_user` fn, which calls the new `get_suggested_user_role` fn in Room

* sdk: add test

* ffi: add user power level info to `RoomInfo`

* Add changes to changelog

* sdk: Fix docs formatting

* sdk & ffi: use `&UserId` instead of `OwnedUserId`

Also, simplify error mapping.

* sdk: add extra test

* ffi: fix `OwnedUserId` -> `&UserId` conversion

* sdk: Replace `UserId::parse` with `user_id!` macro for literals in tests

* Update crates/matrix-sdk/tests/integration/room/joined.rs

Signed-off-by: Benjamin Bouvier <public@benj.me>

---------

Signed-off-by: Benjamin Bouvier <public@benj.me>
Co-authored-by: Benjamin Bouvier <public@benj.me>
2024-02-27 16:04:08 +01:00
Mauro Romito 26b0b32e55 feat(bindings): ffi layer started implementation
also improved the integration test for the filtered case
2024-02-27 14:37:22 +01:00
Andy Balaam c7f3e2ad1d docs: Punctuation and wording fixes in encryption docs
Signed-off-by: Andy Balaam <andy.balaam@matrix.org>
2024-02-27 10:16:03 +00:00
Mauro Romito a79c5286d7 improved the tests 2024-02-27 10:58:13 +01:00
Mauro Romito 8ac6845607 feat: paginated public room search 2024-02-26 17:32:52 +01:00
Benjamin Bouvier 9f75552c9b event cache: only emit an event update when there are, well, events to propagate
Mostly an optimization that was also revealed by the previous version of the test failing, because it would receive an initial update with empty
events.
2024-02-26 16:05:23 +01:00
Benjamin Bouvier 3ef5214587 event cache: add a few smoke tests
This adds a few basic tests for the event cache, notably one for the `add_initial_events`, for something I identified while working on the code, but
that could've caused bad issues:

The `test_add_initial_events` checks that even if we received updates with meaningful events for a room, the room's events are cleared before we add initial events (since
we have no ways to know where to insert the events, in this case). In the future, we can keep this test as a "smoke test" for basic functionality of
the event cache.
2024-02-26 16:05:23 +01:00
Valere 30640ebb65 sdk: Log the successful room message sending and record the received event ID 2024-02-26 11:40:38 +01:00
Doug 4f3cdfacaa docs: Clarify PR title guidelines. 2024-02-26 10:31:28 +01:00
Johannes Marbach b68bcf9cff fix(examples): Fix typos in getting started example
Signed-off-by: Johannes Marbach <n0-0ne+github@mailbox.org>
2024-02-25 11:35:59 +01:00
Doug 8e64341176 ffi: Use a custom RollingFileAppender.
The built in hourly preset doesn't let us specify a max file count. Plus this way we can add a file extension too.
2024-02-23 11:49:47 +01:00
Benjamin Bouvier 40ba98b95e test: fix one potential race in test_room_notification_count
We're subscribing to settings updates *after* sending a request to change a setting. In an unlucky scenario, the following sequence of events could happen:

- sending request to change the settings
- response is received
- we set up the receiver to settings updates, but it's too late

The fix would then be to subscribe to the changes *before* we even send the request to update settings.
2024-02-22 18:01:53 +01:00
Benjamin Bouvier 3541d205e0 test: timeout faster in test_room_notification_count 2024-02-22 18:01:53 +01:00
Benjamin Bouvier 2a201d4218 test: move the with_server methods in the sdk crate
It means the `wiremock` dependency is not a `dev-dependency` anymore, but an optional `dependency` enabled only if `testing` is enabled.
It seems like a fine tradeoff to me.
2024-02-22 18:01:29 +01:00
Benjamin Bouvier 43129441db test: rename another logged_in_client to logged_in_client_with_server 2024-02-22 18:01:29 +01:00
Benjamin Bouvier 5ae2d83457 test: rename one logged_in_client to logged_in_client_with_server 2024-02-22 18:01:29 +01:00
Benjamin Bouvier 193f3331e8 test: remove a few copies of logged_in_client
- in sdk-ui, reuse the same implementation everywhere
- in the sdk integration test, make use of the sdk logged_in_client to remove a few lines
2024-02-22 18:01:29 +01:00
Benjamin Bouvier 65fe3c8b5b test: commonize the logged_in_base_client methods in sdk-base 2024-02-22 18:01:29 +01:00
Benjamin Bouvier 85e8771b5a test: rename one logged_in_client to logged_in_base_client
As it returns a `BaseClient`, it should be distinguished from all the other `logged_in_client`s that return... a `Client`.
2024-02-22 18:01:29 +01:00
Benjamin Bouvier d27bfca5e4 test: rename no_retry_test_client to {{SAME}}_with_server as it also returns a mocking server
And use `no_retry_test_client` in there.
2024-02-22 18:01:29 +01:00
Benjamin Bouvier 77bf972b3f test: rename another test_client_builder to {{SAME}}_with_server as it also returns a mocking server
And use `test_client_builder` in there too.
2024-02-22 18:01:29 +01:00
Benjamin Bouvier 307063e571 test: deduplicate test_client_builder methods
And start deduplicating the other twos as well.
2024-02-22 18:01:29 +01:00
Mauro Romito 18c155beb5 feat: room_directory_sync basic sync loop 2024-02-22 17:50:07 +01:00
Stefan Ceriu 0c1b6e45d5 latest event: Remove edits/replacements from the latest room event (#3150) 2024-02-22 15:19:00 +01:00
Ivan Enderlin b5bda577dd chore(sdk): Remove useless imports or fix unused code. 2024-02-22 14:34:56 +01:00
Benjamin Bouvier 6593e32582 ffi: fix one clippy warning about ToOwned 2024-02-22 14:33:13 +01:00
Benjamin Bouvier d3612ce35b event cache: give each RoomEventCache a sdk::Room
To do so, we need to put the weak reference `EventCache -> Client` back into the `EventCache`.

Putting the `sdk::Room` in the `RoomEventCache` will be useful to run room queries like backpagination (aka call `Room::messages()`).
2024-02-22 14:33:13 +01:00
Damir Jelić bd6d0e959a backups: Better logs for decryption errors for backed up room keys 2024-02-21 16:08:32 +01:00
Benjamin Kampmann cced512ad4 Keep the raw notification event around for further processing 2024-02-21 12:48:29 +01:00
Ivan Enderlin 06359b1166 fix(sdk): Race condition, doc, and Wasm in EventCache
fix(sdk): Race condition, doc, and Wasm in `EventCache`
2024-02-21 12:14:41 +01:00
Ivan Enderlin 10098d20c5 test(common): Add tests for spawn and JoinHandle::abort. 2024-02-21 12:01:08 +01:00
Ivan Enderlin e4c8d6b708 chore(test): Remove a useless import. 2024-02-21 12:00:50 +01:00
Ivan Enderlin 6c6a8e2e77 chore(common): Remove useless import. 2024-02-21 10:54:31 +01:00
Andy Balaam dcf0069753 export: Provide a streamed way to export keys
Signed-off-by: Andy Balaam <andy.balaam@matrix.org>
2024-02-20 16:06:24 +01:00
Andy Balaam f0354d1fc5 export: Move existing export_room_keys method to Store
Signed-off-by: Andy Balaam <andy.balaam@matrix.org>
2024-02-20 15:18:52 +01:00
Damir Jelić 6634735065 ffi: Let the auth service use a proxy as well
The ClientBuilder already exposes setting the proxy, but sadly the
AuthService doesn't let you configure the ClientBuilder directly (yet).

So logging in with a proxy wasn't supported until now.
2024-02-20 15:15:49 +01:00
Stefan Ceriu 59c468c758 Switch user ignoring/unignoring methods to full async 2024-02-20 13:51:18 +01:00
Stefan Ceriu c6e93b06a3 Log ignored user list event deserialization errors 2024-02-20 13:51:18 +01:00
Stefan Ceriu 89033cd13a Fixes #3141 - Expose ignored users on the FFI layer 2024-02-20 13:51:18 +01:00
Valere 88a70f472f Discard session API and bindings for Room (#2941)
Co-authored-by: Damir Jelić <poljar@termina.org.uk>
2024-02-20 13:36:55 +01:00
Doug fafd1a403c fix: Use from macro on wrapped error. 2024-02-20 13:32:46 +01:00
Doug 371cc24031 fix: Update Swift test, remove pub access on sanitize_server_name
Removed a test that was pinging matrix.org too.
2024-02-20 13:32:46 +01:00
Doug 2538ba68c5 ffi: Expose more server discovery errors. 2024-02-20 13:32:46 +01:00
Doug 14e93e8c0c ffi: Use server_name_or_homeserver_url directly. 2024-02-20 13:32:46 +01:00
Jorge Martín 54bdb7791c ffi: Add extra logs to Client::process_session_change
This should help us understand why 2 failed requests with invalid access token didn't pass a refreshed token to the client.
2024-02-20 11:44:02 +01:00
Ivan Enderlin 2f97bc2bae feat(sdk): Improve performance of EventCacheInner::for_room. 2024-02-19 20:08:28 +01:00
Ivan Enderlin 7e3e8fff55 feat(common): Implement JoinHandle::abort on wasm32-u-u.
This patch implements `JoinHandle::abort` when `cfg(target_arch =
"wasm32")`.

The idea is to combine `RemoteHandle` and `AbortHandle`.
2024-02-19 18:21:20 +01:00
Ivan Enderlin 8d878b6785 fix(sdk): Fix a race condition in EventCacheInner::for_room.
There is a race condition in `EventCacheInner::for_room`. Before this
patch, it was possible for 2 concurrent execution to do the following:

* Execution 1 takes the read lock; there is no room in `by_room`, so it
  creates the `RoomEventCache`, code is suspended while trying to get
  the write lock.
* Execution 2 takes the read lock; there is no room in `by_room`, so it
  creates the `RoomEventCache`, code is _not_ suspended because _insert
  reason_, the write lock is acquired, and the `RoomEventCache` is saved
  and a shallow clone is returned.
* Execution 1 resumes, the write lock is acquired, the `RoomEventCache`
  overwrites the one from Execution 2, and a shallow clone is returned.

Now Execution 2 holds a `RoomEventCache` that isn't saved in `by_room`.
It's a ghost! Worst, because the store is cloned in both
`RoomEventCache`, 2 versions will overwrite themselves in the store
constantly.

This patch uses a single write lock, and uses the `BTreeMap::entry`
API instead. Thus, the race condition disappears.

This patch also changes the return type of `for_room` to make it
infallible. It was already the case: only the `Ok` value was returned.
2024-02-19 16:40:11 +01:00
Ivan Enderlin add06bf897 doc(sdk): Add some documentation about the EventCache. 2024-02-19 16:40:11 +01:00
Ivan Enderlin e5b07aa827 chore(sdk): Move EventCache::drop_handles inside EventCacheInner.
This patch moves `EventCache::drop_handles` inside `EventCacheInner` for
the sake of simplicity.
2024-02-19 16:40:11 +01:00
Ivan Enderlin 814d78708e feat(sdk): EventCache uses matrix_sdk_common::executor::spawn.
This patch imports the `spawn` function from
`matrix_sdk_common::executor` instead of `tokio`.
`matrix_sdk_common::executor` adds support for WebAssembly.
2024-02-19 16:40:11 +01:00
Ivan Enderlin 88d7a2fe28 feat(ui,ffi): Add the favourite room list filter
feat(ui,ffi): Add the `favourite` room list filter
2024-02-19 13:45:37 +01:00
Benjamin Bouvier 5386e9e838 event cache: have a single EventCache instance per Client, at most (#3136)
* event cache: move it to the main SDK crate

* event cache: add requested Debug impl to `RoomEventCacheUpdate`

Somehow the compiler asked for it now...

* event cache: add missing copyright notice to store file

* event cache: use a weak reference to the client internally

This will make it possible to have the `Client` own an `EventCache` without a reference
cycle.

* event cache: move the spawned task to its own function

* event cache: move RwLock from EventCache::inner to the only mutable field inside EventCacheInner

* event cache: have the Client own *the* event cache

The goal is to have a unique EventCache instance overall, that's available from everywhere in
the SDK, notably when creating timelines for rooms.

Because the event cache only owns a weak reference to the client, it means the Client still
can be dropped, In turn, this will close its sender of `RoomUpdates`, which will gracefully
close the task spawned in `EventCache::new` after it's done handling the latest updates.

* event cache: process room updates one at a time

* timeline: use the client-wide event cache instead of spawning one per timeline

This now means that we're passing the "initial events" to the event cache just before initializing
the timeline. As a result, there might be previous events that the event cache saw (coming from
sync), but now we can't decide where to put them; drop previously known events in that case.

* event cache: hey, turns out we don't even need the weak back-link

Keeping it as a separate commit, to make it easier to revert later.

* event cache: remove unused errors

Keeping the error type and results, though, because we might have store errors soonish.

* fixup! event cache: move the spawned task to its own function

* event cache: manually subscribe to the event cache

It was a bad idea to have it enabled by default, since some users may not be interested in all
updates for all rooms (e.g. bots). Instead, we make it so that the event cache must be
explicitly subscribed to, and we do it in two cases:

- in the UI `TimelineBuilder::build` method, because we're interested in updates to the current
  room,
- in the `RoomListService`, because we *will* be interested in updates to room derived data (e.g.
  unread counts, read receipts, and so on).

This avoids a bit of fiddling when creating the event cache in the client.

This is resilient when a parent Client is forked into a child Client, because the child
`EventCache` share the same subscription as the parent's.
2024-02-19 12:39:31 +00:00
Ivan Enderlin 9e6252cb2d doc(ui): Add missing copyright headers. 2024-02-19 13:33:11 +01:00
Ivan Enderlin 12d5f51051 feat(ffi): Add the favourite room list filter.
This patch implements the `RoomListEntriesDynamicFilterKind::Favourite`
variant.
2024-02-19 13:29:56 +01:00
Ivan Enderlin c7d34bd65e doc(ui): Add documentation for matrix_sdk_ui::room_list_service::filters.
This patch adds missing documentation for the `filters` module.
2024-02-19 13:29:56 +01:00
Ivan Enderlin 900a6d1382 feat(ui): Add the favourite filter.
This patch adds the `favourite` filter, to filter out rooms that are not
marked as favourite.
2024-02-19 13:29:56 +01:00
Doug 9228ad2f59 chore: Update changelog 2024-02-16 14:57:12 +01:00
Doug 7d9ee71245 More rusty 🦀 2024-02-16 14:57:12 +01:00
Doug c1c8bfda4e Fix: Feature flags on CI 2024-02-16 14:57:12 +01:00
Doug 1fb717968e fix: Store the details and the error separately. 2024-02-16 14:57:12 +01:00
Doug e69591dad3 fix: Address PR comments. 2024-02-16 14:57:12 +01:00
Doug ee8e9ef528 sdk: Add tests for server_name_or_homeserver_url 2024-02-16 14:57:12 +01:00
Doug 7cbc3e587d sdk: Add server_name_or_homeserver_url to ClientBuilder 2024-02-16 14:57:12 +01:00
maan2003 aeba46a0eb indexeddb: fix incorrect key used for next batch token
Signed-off-by: maan2003 <manmeetmann2003@gmail.com>
2024-02-16 14:45:21 +01:00
Benjamin Bouvier 11074d8f4d event cache: listen to all the room updates at once! 2024-02-15 18:22:11 +01:00
Benjamin Bouvier a6c133369f sdk: add a mechanism to get all room updates at once
(instead of having to subscribe to a single room in the event cache)
2024-02-15 18:22:11 +01:00
Benjamin Bouvier 6a81ceced0 event cache: move store trait and memory impl to a new store file 2024-02-15 18:22:11 +01:00
Benjamin Bouvier ffc7648ce6 ui: rename "event graph" to "event cache" 2024-02-15 18:22:11 +01:00
Benjamin Bouvier fd395a82c5 sdk: add docs for the DeduplicatingHandler data structure 2024-02-15 18:10:34 +01:00
Benjamin Bouvier 15afd1f690 sdk: deduplicate requests to send a read receipt 2024-02-15 18:10:34 +01:00
Benjamin Bouvier 1e24fbc72d rrrepl: use Timeline::mark_as_read there too 2024-02-15 18:09:57 +01:00
Damir Jelić 32afc56005 ffi: Expose the method to add additional certs in the bindings 2024-02-15 16:19:20 +01:00
Damir Jelić 7e61a6dd31 sdk: Re-expose the reqwest method to add certs through the ClientBuilder 2024-02-15 16:19:20 +01:00
Doug cae3b38c35 ffi: Expose the suggested role constructor. 2024-02-15 11:31:36 +01:00
Doug c36cb1b424 ffi: Include users in the RoomPowerLevels state 2024-02-15 11:31:36 +01:00
Damir Jelić 315a29f568 Reneable the correct backup download strategy for the bindings 2024-02-15 09:19:14 +01:00
ganfra 74931768e5 ffi : expose room_info is_favourite 2024-02-13 16:47:26 +01:00
Benjamin Bouvier 7eb3c30a3c timeline: remove the thread parameter from mark_as_read
It doesn't make sense to set a thread identifier for the receipt of the latest event: the event might not belong to that thread, and the SDK would need to check that,
since the latest event isn't reachable from the outside world (the reason why `mark_as_read` had been introduced). So let's remove it for now, and
add comments related to threaded receipts.
2024-02-13 16:03:49 +01:00
Benjamin Bouvier 7e99e812dd ffi/sdk: rename mark_read into set_unread_flag
This slightly changes the API when interacting from the FFI layer:

- instead of `mark_as_unread` and `mark_as_read`, there's now a single method `set_unread_flag(bool)`, which callers may call with true (i.e. unread) or false (i.e. not unread).
- there's a new method `mark_as_read` which sends a read receipt to the latest event in the timeline, using other commits from the same PR,
- forcing a room as read requires calling first `set_unread_flag(false)` then `mark_as_read()`
2024-02-13 16:03:49 +01:00
Benjamin Bouvier e97b7838c5 ffi: use the Timeline::mark_as_read function in mark_as_read_and_send_read_receipt 2024-02-13 16:03:49 +01:00
Benjamin Bouvier 8eb3fdc9e4 timeline: add a test that sending a reaction to the latest timeline event item isn't the same as marking as read 2024-02-13 16:03:49 +01:00
Benjamin Bouvier 8536e2b2a3 timeline: add a mark_as_read function to send a read receipt for the actual latest event 2024-02-13 16:03:49 +01:00
Benjamin Bouvier 060eaeffc0 key backup: test that the upload moves from the error state back to the idle state immediately 2024-02-12 19:38:03 +01:00
Benjamin Bouvier b177bd9783 sdk: put all the e2ee-related Client fields under a new EncryptionData struct 2024-02-12 19:38:03 +01:00
Benjamin Bouvier 6fa487fad8 sdk: comment each sub-field of ClientInner
and make the code breath a bit more
2024-02-12 19:38:03 +01:00
Denis Kasak 12444d3dc1 docs: Clarify some doc comments. 2024-02-12 17:32:37 +01:00
Denis Kasak ed5d97e052 docs: Fix doc comment for Account::signed_one_time_keys.
It talks about generating OTKs, but that is no longer true since
1c6d85935.
2024-02-12 17:32:37 +01:00
kegsay cff844ac74 Add debug logging when sessions get rotated (#3106)
Critically, explain why the session is being rotated.

Signed-off-by: kegsay <7190048+kegsay@users.noreply.github.com>
Co-authored-by: Damir Jelić <poljar@termina.org.uk>
2024-02-12 17:31:41 +01:00
Benjamin Bouvier 70e38755fa recovery: comment and simplify all_known_secrets_available 2024-02-12 17:28:40 +01:00
Benjamin Bouvier c20e6aeca7 ffi: configure encryption settings only when it's needed
It's wrong that the first client, used only to determine how to log in and find the user id, try to run the encryption initialization tasks.
In particular, it should not even try to bootstrap the account, as this may send OTKs to the server, which the client will forget about as soon
as it's respawned as a database-backed client.
2024-02-12 17:28:40 +01:00
Benjamin Bouvier 53d723d149 ffi: avoid having two clients alive at the same time 2024-02-12 17:28:40 +01:00
Timo Kösters 5cb587a60b sliding_sync: Use assert_next_eq for tests
Signed-off-by: Timo Kösters <timo@koesters.xyz>
2024-02-12 14:48:35 +01:00
Benjamin Bouvier 354f9de257 test: refactor integration test code to avoid Box::leak 2024-02-12 14:48:35 +01:00
Timo Kösters 9d04b23f45 sliding_sync: Refactor for code review
Signed-off-by: Timo Kösters <timo@koesters.xyz>
2024-02-12 14:48:35 +01:00
Timo Kösters 73edf6b734 sliding_sync: Documentation for RoomInfoUpdate and cargo fmt
Signed-off-by: Timo Kösters <timo@koesters.xyz>
2024-02-12 14:48:35 +01:00
Timo Kösters 5114474829 sliding_sync: Only emit manual room list update when late decryption happens
Previously, there were duplicate updates.

Signed-off-by: Timo Kösters <timo@koesters.xyz>
2024-02-12 14:48:35 +01:00
Timo Kösters 91331bea51 sliding_sync: More documentation for roominfo sender/receiver
Signed-off-by: Timo Kösters <timo@koesters.xyz>
2024-02-12 14:48:35 +01:00
Timo Kösters 79f97504f8 sliding_sync: Refactor delayed decryption test
Signed-off-by: Timo Kösters <timo@koesters.xyz>
2024-02-12 14:48:35 +01:00
Timo Kösters 50ed681a4e sliding_sync: Refactor roominfo sender/receiver code
Signed-off-by: Timo Kösters <timo@koesters.xyz>
2024-02-12 14:48:35 +01:00
Timo Kösters 910887fbc6 sliding_sync: Add test for delayed decryption roominfo updates
Signed-off-by: Timo Kösters <timo@koesters.xyz>
2024-02-12 14:48:35 +01:00
Timo Kösters 304bd910f0 sliding_sync: Add test to make sure stream updates are in correct order
I have also changed the priorities so that manual updates are preferred.
This means that duplicate updates do not happen if the room was previously unknown.

Signed-off-by: Timo Kösters <timo@koesters.xyz>
2024-02-12 14:48:35 +01:00
Timo Kösters e87a7954a0 sliding_sync: Refactor roominfo update receiver
Signed-off-by: Timo Kösters <timo@koesters.xyz>
2024-02-12 14:48:35 +01:00
Timo Kösters d2b02ec2e8 sliding_sync: Trigger room list update when room info changes
This fixes https://github.com/element-hq/element-x-ios/issues/1847

Signed-off-by: Timo Kösters <timo@koesters.xyz>
2024-02-12 14:48:35 +01:00
Andy Balaam d84387d12e Merge pull request #3118 from progval/shrink-decrypted-media
Preallocate vector storing decrypted files
2024-02-12 10:06:00 +00:00
Val Lorentz 368b585124 Preallocate vector storing decrypted files
Vectors grow in powers of two while reading, which is doubly wasteful:

* causes every byte to be copied in average once
* leaves the vector in average 25% larger than it needs to be, wasting memory.

For example, adding this test to
`crates/matrix-sdk-crypto/src/file_encryption/attachments.rs`:

```
fn encrypt_decrypt_minimize_memory() {
    let data = std::iter::repeat("abcdefg").take(10000).collect::<String>();
    let mut cursor = Cursor::new(data.clone());

    let mut encryptor = AttachmentEncryptor::new(&mut cursor);

    let mut encrypted = Vec::new();

    encryptor.read_to_end(&mut encrypted).unwrap();
    let key = encryptor.finish();
    assert_ne!(encrypted.as_slice(), data.as_bytes());

    let mut cursor = Cursor::new(encrypted);
    let mut decryptor = AttachmentDecryptor::new(&mut cursor, key).unwrap();
    let mut decrypted_data = Vec::new();

    decryptor.read_to_end(&mut decrypted_data).unwrap();

    assert_eq!(
        decrypted_data.len(),
        decrypted_data.capacity(),
        "{} bytes wasted by decrypted_data",
        decrypted_data.capacity() - decrypted_data.len()
    );
}
```

errors with:

```
assertion `left == right` failed: 61072 bytes wasted by decrypted_data
  left: 70000
 right: 131072
```

By initially setting this capacity, the vector should be slightly larger
than needed from the start, avoiding both copying and leftover capacity
after decryption is done.
2024-02-10 10:49:23 +01:00
Val Lorentz 7bbd07cc77 Allow references to MediaEventContent
`matrix_sdk_ui::timeline::Message::msgtype` returns `&MessageType`,
and variants of `MessageType` implement `MediaEventContent`, so it is
allowing references here avoids cloning message content.
2024-02-10 10:20:00 +01:00
Ivan Enderlin 008330a744 Merge pull request #3111 from Hywan/fix-base-notable-tags
fix(base): Rewrite `RoomNotableTags`
2024-02-09 17:37:14 +01:00
Ivan Enderlin 1052c8db15 Merge branch 'main' into fix-base-notable-tags
Signed-off-by: Ivan Enderlin <ivan@mnt.io>
2024-02-09 17:03:30 +01:00
Benjamin Bouvier 3e04590ded sdk: rename Client::handle_sync_response to call_sync_response_handlers
This indicates, in an hopefully clearer way, that it's only calling the handlers, after getting a sync response.
2024-02-09 11:39:46 +01:00
Benjamin Bouvier ce2d8212eb sdk: rename other {Joined,Invited,Left}Room to {0}Update
Since they're updates to rooms, and not the rooms in themselves.
2024-02-09 11:39:46 +01:00
Benjamin Bouvier 5ad9090dc8 sdk: rename sync::Rooms to RoomUpdates
This struct contains updates to rooms, not rooms per se. Make it clear from the name.
2024-02-09 11:39:46 +01:00
Benjamin Bouvier b15829a9fd sdk: add comment and make it clear that some functions are tests 2024-02-09 11:39:46 +01:00
Benjamin Bouvier bebb733607 nit: change favorite to favourite in a few places
Signed-off-by: Benjamin Bouvier <public@benj.me>
2024-02-09 11:37:50 +01:00
Benjamin Bouvier e872babd40 read receipts: add the room id in the instrumentation of send_single_receipt
This didn't show up, and it's quite useful to know for which room we're trying to send a receipt, without having to look up the room based on the
target event id.
2024-02-09 11:21:23 +01:00
Ivan Enderlin bcb125a09b test(sdk): Revisit the tests for notable tags.
This patch rewrites all the integration tests for the notable tags. The
tests were good, but we could merge some together. The names were too
long, they have been shortened.
2024-02-09 09:44:40 +01:00
Ivan Enderlin 65774aa90b chore(base): Remove warnings when e2e-encryption is disabled. 2024-02-09 09:31:47 +01:00
Ivan Enderlin 868bb9a8d9 fix(base) Client::receive_sync_response overwrites RoomInfo.
The workflow inside `Client::receive_sync_response` is a little
bit fragile. When `Client::handle_room_account_data` is called, it
modifies `RoomInfo`. The problem is that a current `RoomInfo` is being
computed before `handle_room_account_data` is called, and saved a
couple lines after, resulting in overwriting the modification made by
`handle_room_account_data`.

This patch ensures that the new `RoomInfo` is saved before
`handle_room_account_data` is called.
2024-02-09 09:29:57 +01:00
Ivan Enderlin 61c7a96e36 doc(base): Add missing documentation. 2024-02-09 09:29:34 +01:00
Ivan Enderlin e6dadf2b0d chore(base): Clean up tests. 2024-02-09 09:29:34 +01:00
Ivan Enderlin 75454de284 test(base): Test Room::is_favourite and ::is_low_priority.
This patch tests the `is_favourite` and `is_low_priority` methods.
2024-02-09 09:29:34 +01:00
Ivan Enderlin 8b298dfd2f chore(base): Rename NotableTags to RoomNotableTags.
Now that `NotableTags` has replaced `RoomNotableTags` entirely, this
patch can rename `NotableTags` to `RoomNotableTags` as it's a better
name for it.

Note that this type is private to `matrix_sdk_base`, so it's fine to
rename it.
2024-02-08 15:27:48 +01:00
Ivan Enderlin 31ba7b82d8 doc(sdk,base,ffi): Improve documentation and rename favorite to favourite.
The Matrix specification uses the `m.favourite` orthography. Let's use
the same in our code. So `set_is_favorite` becomes `set_is_favourite`.
This patch updates this in various places for the sake of consistency.
2024-02-08 15:25:41 +01:00
Ivan Enderlin 71f4af9cdd feat(base,sdk,ffi): Remove RoomNotableTags.
The previous patch has introduced the new `NotableTags` type to replace
the `RoomNotableTags`. This patch removes the latter.

This patch keeps the `Room::set_is_favorite` and `::set_is_low_priority`
methods. However, this patch adds the `Room::is_favourite` and
`::is_low_priority` methods, with the consequence of entirely hiding the
notable tags type from the public API.
2024-02-08 15:17:17 +01:00
Ivan Enderlin fd716bcd81 feat(base): Add the NotableTags type.
This patch is the first step to remove the [`RoomNotableTags`] API. The
idea is to compute the notable tags as a single 8-bit unsigned integer
(`u8`) and to store it inside `RoomInfo`. The benefits are numerous:

1. The type is smaller that `RoomNotableTags`,
2. It's part of `RoomInfo` so:
  - We don't need an async API to fetch the tags from the store and to
    compute the notable tags,
  - It can be put in the store,
  - The observable/subscribe mechanism is supported by `RoomInfo` behind
    observable instead of introducing a new subscribe mechanism.
2024-02-08 15:14:03 +01:00
Ivan Enderlin 385e6933d2 chore(base): Update bitflags. 2024-02-08 14:33:00 +01:00
Ivan Enderlin fab1c1c299 chore(base): Introduce a small helper to clarify the code.
I believe this small refactoring makes the code simpler to read, esp.
when more event type will be added.
2024-02-08 14:33:00 +01:00
Ivan Enderlin 9bf48ef041 feat(ui): Moaaar filters: add all, any, not, unread and category filters
feat(ui): Moaaar filters: add `all`, `any`, `not`, `unread` and `category` filters
2024-02-08 14:28:18 +01:00
Valere 2e9f362ae4 Add a method to the Device to encrypt an event directly for the device (#3091)
This patch exposes the 1-to-1 encryption method that is usually used to share a room key with a device. Users might want to send encrypted custom to-device events to a device directly, so let's expose this functionality. 

Co-authored-by: Damir Jelić <poljar@termina.org.uk>
2024-02-08 13:15:01 +00:00
Ivan Enderlin fce1140ad1 test(ui): Split tests and improve documentation. 2024-02-08 14:15:01 +01:00
ganfra 0c1d90d901 Tags : introduce set_is_favorite and set_is_low_priority (#3075)
* tags : introduce update_notable_tags method

* tags : replace update_notable_tags by set_is_favorite and set_is_low_priority methods. Also add more tests.

* tags : fix clippy issues

* tags : improve doc
2024-02-08 12:32:24 +01:00
Damir Jelić 717dc1184b Add a integration test that checks if backups get automatically created 2024-02-08 10:47:35 +01:00
Damir Jelić 99e0593f90 Catch the error if we fail to automatically enable backups
We don't want the rest of the method to abort executing because
automatic backup creation failed.

We also move the infallible event handler registration at the top of the
method.

The logic to automatically create a backup uses the following logic:

1. We check if we need to create a backup, this includes a check if a
   backup exists on the server.
2. We conclude that we should create a backup, no backup exists on the
   server.
3. The method to create the backup checks again if a backup exists, this
   was an API change because the method is public and users misused the
   method.
4. Finally, we create the backup.

A race exists between the first time we check if a backup exists and the
second time, i.e. step 1 and 3.

It seems that some users create two Client objects which then make this
race a common occurrence. Clients should not do that, but at least we
don't error out too soon anymore if the automatic creation of the backup
fails.
2024-02-08 10:47:35 +01:00
Valere f6f6cfd844 Indexeddb: Avoid long and suspendable calls for encryption/serialization during the indexeddb transaction (#2966)
Quick performance improvement on `save_change` for indexeddb.
All the serialization/encryption is now done outside the db transaction

---

* do serialization/encryption before db transaction

* clippy

* add changelog for indexeddb crate

* clean comments

* fix typo

* Review: Fix typo in changelog

* Review: refactor, rename DbOperation to PendingOperation

* Review: rename variant PutKeyVal to Put

* Review: fix doc typo

* Review: rename perfrom_operation to apply

* Review: remove unneeded isEmpty checks

* Review: refactor better API for PendingStoreChanges

* Review: Prefer BTreeMap to HashMap

* Refactor: rename IndexeddbChangesKeyValue

* Refactoring: get the list of affected store from PendingIndexeddbChanges

* cleaning

* Review: Better names and comments

* Review: use filter_map instead of filter then map
2024-02-08 09:22:28 +01:00
Ivan Enderlin d905dcc476 doc(sdk): Fix a typo
doc(sdk): Fix a typo
2024-02-08 09:00:41 +01:00
Ivan Enderlin 790fe5f6db doc(sdk): Fix a typo. 2024-02-08 08:36:00 +01:00
Ivan Enderlin f2652ee9f2 Merge pull request #3066 from matrix-org/doug/room-power-levels
Add RoomPowerLevelSettings.
2024-02-07 16:03:10 +01:00
Doug 099bf9c929 sdk: Add RoomPowerLevelSettings.
fix: Preserve the event of any settings that are changed back to the default level.

sdk: Rename get_room_power_levels (drop the get).

chore: Refactor with more sensible naming.

sdk: Clean up the RoomPowerLevelChanges API.
2024-02-07 14:49:03 +00:00
Damir Jelić 5957d9603b Move back to reqwest 0.11.20
The linking error[1] on Mac still isn't fixed.

[1]: https://github.com/seanmonstar/reqwest/issues/2006
2024-02-07 13:57:07 +01:00
Damir Jelić 3d60ac36d2 Replace the usage of IndexMap::remove with IndexMap::swap_remove
The IndexMap::remove method has been deprecated, the documentation[1] on
the method tells us that we can replace the usage of it with
IndexMap::swap_remove:

> NOTE: This is equivalent to .swap_remove(key), replacing this entry’s
> position with the last element, and it is deprecated in favor of
> calling that explicitly.

[1]: https://docs.rs/indexmap/2.2.2/indexmap/map/struct.IndexMap.html#method.remove
2024-02-07 13:57:07 +01:00
Damir Jelić 787d04190e Fix some more new clippy warnings 2024-02-07 13:57:07 +01:00
Damir Jelić e33c44266e Fix a new clippy warning in the crypto crate 2024-02-07 13:57:07 +01:00
Damir Jelić 17e8109ab6 Bump our nightly version for the CI and xtask 2024-02-07 13:57:07 +01:00
Damir Jelić 14246c7094 Update our lock file
The Dalek crates got a new release fixing some build issues on nightly.
This should get rid of those build issues.
2024-02-07 13:57:07 +01:00
Andy Balaam 6a34f54753 Merge pull request #3095 from matrix-org/andybalaam/indexeddb-tidy-migrations
indexeddb: Tidy the migrations code
2024-02-07 12:41:44 +00:00
Andy Balaam 78e3350b17 indexeddb: Use a type alias to clarify do_schema_upgrade
Signed-off-by: Andy Balaam <andy.balaam@matrix.org>
2024-02-07 12:27:36 +00:00
Andy Balaam e3c7e9db9b indexeddb: Fix incorrect link
Signed-off-by: Andy Balaam <andy.balaam@matrix.org>
2024-02-07 12:24:25 +00:00
Ivan Enderlin dc89c00a8c doc(sdk): Fix typos. 2024-02-07 13:22:10 +01:00
Ivan Enderlin 5baf078c4b feat(ui,ffi): Implement the category room list filter.
This patch implements the `category` room list filter. It introduces a
new type: `RoomCategory`, to ensure that “group” and “people” are
mutually exclusives.
2024-02-07 13:22:10 +01:00
Ivan Enderlin f950e67b39 feat(base): Implement Room::direct_targets_length.
This patch implements `Room::direct_targets_length`. It avoids to call
`Room::is_direct` if and only if we don't care about the room's state
and we don't want an async call, and if we don't want to pay the cost of
`Room::direct_targets` which clones the `HashSet` as an alternative way
to get a similar information than `Room::is_direct`.
2024-02-07 10:36:52 +01:00
Ivan Enderlin 2c688fd40f chore(ui): Remove the get_ prefix of an internal filter type.
This patch renames `NonLeftRoomMatcher::get_state` to `::state`. This is
more Rust idiomatic.
2024-02-07 10:36:52 +01:00
Ivan Enderlin e94fd2a7df feat(ui,ffi): Implement the unread room list filter.
This patch implements the `unread` room list filter.
2024-02-07 10:36:52 +01:00
Ivan Enderlin d699b2fa70 feat(ui,ffi): Implement the all and any filters on FFI.
This patch implements the `all` and `any` filters in `matrix-sdk-ffi`.
The `not` filter cannot be implemented because recursive enum isn't
supported by UniFFI (see https://github.com/mozilla/uniffi-rs/issues/396).
2024-02-07 10:23:23 +01:00
Ivan Enderlin 61d3f8d1d9 feat(ui): Rename logical_<name> filters to <name>.
This patch removes the `logical_` prefix of some filters.
2024-02-07 10:23:23 +01:00
Ivan Enderlin 435d74a67a chore(ui): Remove the all room list filter.
This patch removes the `all` room list filter. It's not used anymore
since we have `non_left` which is more correct.
2024-02-07 10:23:22 +01:00
Ivan Enderlin fe2ca34179 feat: Implement logical_all, _any and _not filters.
This patch implements 3 new filters: `logical_all`, `logical_any` and
`logical_not`.
2024-02-07 10:23:22 +01:00
Ivan Enderlin 3b068b592d chore: Rename all_non_left to non_left.
This patch renames the room list filter `all_non_left` to `non_left`.
2024-02-07 10:23:22 +01:00
Ivan Enderlin 344a96a80f feat: Introduce the Filter trait alias.
This patch introduces the
`matrix_sdk_ui::room_list_service::filters::Filter` trait alias.

This patch also cleans up a little bit the filters by renaming some
methods for the sake of consistency across all the existing filters.
2024-02-07 10:23:22 +01:00
Ivan Enderlin 4e8c63e4e0 Merge pull request #3059 from matrix-org/fga/room_typing_notifications
Room typing notifications
2024-02-07 09:52:22 +01:00
Damir Jelić 452cf0f269 Add a missing changelog entry for the Client::sync_token() method 2024-02-07 08:23:13 +01:00
ganfra e78c4b89b4 Merge branch 'main' into fga/room_typing_notifications 2024-02-06 16:54:54 +01:00
Damir Jelić bcf8cc1c57 Fix a clippy warning about a large error variant 2024-02-06 16:17:05 +01:00
Damir Jelić f47e7b3427 Ensure the Olm session state is recorded in both decryption paths 2024-02-06 16:17:05 +01:00
Damir Jelić 8252379f76 Record the Olm session before we try to decrypt
A decryption failure would have prevented the recording of the session
otherwise. We are mostly interested in the state of the session if a
decryption failure happens.
2024-02-06 16:17:05 +01:00
Damir Jelić 2ef1e32f9a Add the message to log lines when we decrypt a Olm message 2024-02-06 16:17:05 +01:00
Damir Jelić 47a4f473a6 Bump vodozemac
This adds more detailed logging for Olm messages
2024-02-06 16:17:05 +01:00
Andy Balaam 9d6d2c3b3c Merge pull request #3097 from matrix-org/doug/swift-task
Improve the handling of targets in the Swift xtask.
2024-02-06 09:22:12 +00:00
Doug bd38dc971b xtask: Tidy-up the swift task. 2024-02-05 16:27:02 +00:00
Andy Balaam 4712c318cc indexeddb: Fix compiler warnings
Signed-off-by: Andy Balaam <andy.balaam@matrix.org>
2024-02-05 16:05:52 +00:00
Andy Balaam a92140f3ac indexeddb: Use a MigrationDb object to ensure DB is closed
Signed-off-by: Andy Balaam <andy.balaam@matrix.org>
2024-02-05 15:57:07 +00:00
Andy Balaam 88d10210ad indexeddb: Regularise migration method names
Signed-off-by: Andy Balaam <andy.balaam@matrix.org>
2024-02-05 15:57:07 +00:00
Andy Balaam de9adc8d3d indexeddb: Use utility functions to create indices
Signed-off-by: Andy Balaam <andy.balaam@matrix.org>
2024-02-05 15:57:07 +00:00
Andy Balaam 51704fa093 indexeddb: Move add_nonunique_index method up to the main module
Signed-off-by: Andy Balaam <andy.balaam@matrix.org>
2024-02-05 15:57:07 +00:00
Andy Balaam 0e91c085f9 indexeddb: Clear the inbound_group_sessions2 store during migration
Signed-off-by: Andy Balaam <andy.balaam@matrix.org>
2024-02-05 15:57:07 +00:00
Andy Balaam 49630fdd9f indexeddb: Comments explaining the migration methods and modules
Signed-off-by: Andy Balaam <andy.balaam@matrix.org>
2024-02-05 15:57:07 +00:00
Andy Balaam a1f1992d7e indexeddb: Extract db_version function
Signed-off-by: Andy Balaam <andy.balaam@matrix.org>
2024-02-05 15:57:07 +00:00
Andy Balaam d64a5e4dcc indexeddb: Move v0 to c5 migration into own module
Signed-off-by: Andy Balaam <andy.balaam@matrix.org>
2024-02-05 15:57:07 +00:00
Andy Balaam f0c97d94b2 indexeddb: Re-use do_schema_upgrade for v0 to v5
Signed-off-by: Andy Balaam <andy.balaam@matrix.org>
2024-02-05 15:57:07 +00:00
Andy Balaam 5d0c6a608a indexeddb: Simplify v5 to v7 migration code
Signed-off-by: Andy Balaam <andy.balaam@matrix.org>
2024-02-05 15:57:07 +00:00
Andy Balaam 3dbfdcddf4 indexeddb: Move v7 to v8 migration into separate module
Signed-off-by: Andy Balaam <andy.balaam@matrix.org>
2024-02-05 15:57:07 +00:00
Andy Balaam e9b11408bb indexeddb: Move InboundGroupSessionIndexedDbObject2 into v7 module
Signed-off-by: Andy Balaam <andy.balaam@matrix.org>
2024-02-05 15:57:07 +00:00
Andy Balaam d26b8cca1c indexeddb: Move v5 to v7 code into a separate module
Signed-off-by: Andy Balaam <andy.balaam@matrix.org>
2024-02-05 15:57:07 +00:00
Andy Balaam 6c5400896a indexeddb: prepare_data_for_v7 creates its own DB
Signed-off-by: Andy Balaam <andy.balaam@matrix.org>
2024-02-05 15:57:07 +00:00
Andy Balaam 8b7ebece49 indexeddb: Use do_schema_upgrade for v8
Signed-off-by: Andy Balaam <andy.balaam@matrix.org>
2024-02-05 15:57:07 +00:00
Andy Balaam 4def306eb8 indexeddb: use do_schema_upgrade for v6 migration
Signed-off-by: Andy Balaam <andy.balaam@matrix.org>
2024-02-05 15:57:07 +00:00
Andy Balaam 3d4db7e220 indexeddb: Move do_schema_upgrade into migrations to be re-used
Signed-off-by: Andy Balaam <andy.balaam@matrix.org>
2024-02-05 15:57:07 +00:00
Andy Balaam 6fe98c3f43 indexeddb: Split v6 migration out because it is part of v5_to_v7
Signed-off-by: Andy Balaam <andy.balaam@matrix.org>
2024-02-05 15:57:07 +00:00
Andy Balaam 375c6c33c6 indexeddb: Move old_keys into its own file
Signed-off-by: Andy Balaam <andy.balaam@matrix.org>
2024-02-05 15:57:07 +00:00
Andy Balaam edf23dbd2e indexeddb: move v8_to_v10 migration into its own file
Signed-off-by: Andy Balaam <andy.balaam@matrix.org>
2024-02-05 15:57:07 +00:00
Andy Balaam 8d87e32f8b indexeddb: Create a migrations directory
Signed-off-by: Andy Balaam <andy.balaam@matrix.org>
2024-02-05 15:57:07 +00:00
Doug 2f6d0450a7 xtask: Simplify the code used to build targets for Swift. 2024-02-05 15:50:46 +00:00
Doug e07ed14d20 xtask: Add supported swift targets and iterate through them when building. 2024-02-05 15:30:35 +00:00
Ivan Enderlin ae97772909 feat(sdk,ui): Remove SlidingSyncRoom::latest_event
feat(sdk,ui): Remove `SlidingSyncRoom::latest_event`
2024-02-05 12:57:07 +01:00
Ivan Enderlin 8975e6ab5d Merge pull request #3076 from matrix-org/stefan/mark_unread
Add support for MSC2867 - Manually marking rooms as unread
2024-02-05 12:40:52 +01:00
Andy Balaam 32aa784c5f Merge pull request #3094 from matrix-org/andybalaam/fix-incorrect-url
doc: Fix an incorrect URL about Indexed DB
2024-02-05 11:30:51 +00:00
Andy Balaam 56e155300c doc: Fix an incorrect URL about Indexed DB
Signed-off-by: Andy Balaam <andy.balaam@matrix.org>
2024-02-05 11:07:08 +00:00
Ivan Enderlin df61037ac5 fix(base,sdk): Fix imports. 2024-02-05 11:59:31 +01:00
Stefan Ceriu 471b470c01 Change where unstable-msc2867 is enabled, try to fix CI tests 2024-02-05 11:59:31 +01:00
Stefan Ceriu 56d9f9d9a8 Add support for MSC2867 - Manually marking rooms as unread
- also fixes how room account data is processed and adds tests for both when rooms and extensions are present or just extensions
2024-02-05 11:59:29 +01:00
Ivan Enderlin 6e685e2e09 Merge pull request #3062 from zecakeh/ambiguity-changes
sdk: Allow to track ambiguity changes per-room
2024-02-05 11:53:10 +01:00
Ivan Enderlin ad5c1202b5 feat(sdk,ui): Remove SlidingSyncRoom::latest_event.
This patch inlines `SlidingSyncRoom::latest_event` into its unique call
site: `SlidingSyncRoomExt::latest_timeline_item`.

`SlidingSyncRoom::latest_event` is not using any data from
`SlidingSyncRoom`, except the `Client`. So it can easily live somewhere
else. Our goal is to clean up `SlidingSyncRoom` as much as possible, and
to remove any kind of logic from it.
2024-02-05 11:09:14 +01:00
Ivan Enderlin 87a07d9ee3 feat(sdk): Remove SlidingSyncRoomInner::inner
feat(sdk): Remove `SlidingSyncRoomInner::inner`
2024-02-05 09:27:44 +01:00
Kévin Commaille e0bda80e7b Merge branch 'main' into ambiguity-changes
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-02-04 11:55:41 +01:00
Andy Balaam b9ef5d6270 Merge pull request #3090 from matrix-org/andybalaam/indexeddb-clear-store-before-delete
indexeddb: Clear the object store before deleting it
2024-02-02 14:50:01 +00:00
Damir Jelić fa26499a39 Showcase how to use an event handler context in the custom events example 2024-02-02 15:30:26 +01:00
Andy Balaam 916e85f79e indexeddb: Clear the object store before deleting it
Since my investigation found that it significantly speeds up deletion of
a store on both Firefox and Chromium if you clear() it first, do that in
our migration code.
2024-02-02 14:06:07 +00:00
Ivan Enderlin f2b61eb5e2 chore: Remove ununsed imports. 2024-02-02 08:42:06 +01:00
Benjamin Bouvier 40e006658c ffi: add missing variants to ffi::event::MessageLikeEventType and use it in the timeline filter types 2024-02-01 19:02:12 +01:00
Benjamin Bouvier ac2fce8220 ffi: move two event type enums over to matrix-sdk-ffi/event.rs 2024-02-01 19:02:12 +01:00
Benjamin Bouvier 296d613138 ffi: sort event type enums in alphabetical order 2024-02-01 19:02:12 +01:00
Ivan Enderlin 43bed281b1 feat: Replace SlidingSyncRoom::inner by SlidingSyncRoom::prev_batch.
This patch removes the need to store and to update the
`SlidingSyncRoom::inner` field (of type `v4::SlidingSyncRoom`). Now,
we just need to handle the `prev_batch`, which is the only data we care
about.

Bonus: it reduces the size of the frozen sliding sync room quite much.
2024-02-01 17:45:30 +01:00
Ivan Enderlin b951d0d785 feat(sdk,base,ui,ffi): Continue to remove dead code in SlidingSyncRoom
feat(sdk,base,ui,ffi): Continue to remove dead code in `SlidingSyncRoom`
2024-02-01 17:20:36 +01:00
Ivan Enderlin a802b733f8 feat(sdk): Remove the SlidingSyncRoom::name method.
This patch removes the `SlidingSyncRoom::name` method. The name is
already synchronized with the `matrix_sdk_base::Room`. This code is
then useless.
2024-02-01 15:26:25 +01:00
Ivan Enderlin 6acd68cf00 feat(sdk): Remove the SlidingSyncRoom::is_dm method.
This patch removes the `SlidingSyncRoom::is_dm` method. It's not used
anywhere in the SDK, neither by the FFI bindings. Since this code is
still experimental, it's fine to remove public API.
2024-02-01 15:20:56 +01:00
Ivan Enderlin 75365a7774 feat(sdk): Remove the SlidingSyncRoom::is_initial_response method.
This patch removes the `SlidingSyncRoom::is_initial_response` method.
It's not used anywhere in the SDK, neither by the FFI bindings. Since
this code is still experimental, it's fine to remove public API.
2024-02-01 15:13:03 +01:00
Ivan Enderlin 61a5f1b3cf feat(sdk): Remove the SlidingSyncRoom::required_state method
feat(sdk): Remove the `SlidingSyncRoom::required_state` method
2024-02-01 14:47:48 +01:00
Ivan Enderlin 44e438b21b feat(sdk): Remove the SlidingSyncRoom::required_state method.
This patch removes a useless and not used (in the Matrix Rust SDK, along with the FFI bindings) method: `SlidingSyncRoom::required_state`.
2024-02-01 14:35:42 +01:00
Ivan Enderlin 7b49283394 feat(sdk,ui,ffi): Remove SlidingSyncRoom::has_unread_notifications and ::unread_notifications
feat(sdk,ui,ffi): Remove `SlidingSyncRoom::has_unread_notifications` and `::unread_notifications`
2024-02-01 14:07:22 +01:00
Benjamin Bouvier e0384494b6 sdk: use a Mutex instead of a RwLock for the sync lock
I think the reasoning behind using a RwLock for sync, and notably allowing multiple concurrent `.read()` lock taking was flawed: since there's no way
to identify which subpiece of the store we're reading and writing, there could be two concurrent requests to the write to the same thing at the same
time. To get rid of this possibility, this commit changes the lock to a single access only Mutex lock.
2024-02-01 14:07:04 +01:00
ganfra cc236e39d5 typing : filter the current user id 2024-02-01 12:54:10 +01:00
Ivan Enderlin c4d5657162 chore: Remove unused imports. 2024-02-01 12:26:44 +01:00
ganfra 59f9f43f15 Merge branch 'main' into fga/room_typing_notifications 2024-02-01 12:18:26 +01:00
Ivan Enderlin 261eb99614 feat(ffi): Remove room_list::Room::has_unread_notifications and ::unread_notifications.
In the previous commit, these methods have been removed from `matrix_sdk_ui`.
2024-02-01 11:57:11 +01:00
Ivan Enderlin 5ae638047e feat(ui): Remove room_list::Room::has_unread_notifications and ::unread_notifications.
This patch removes the `room_list::Room::has_unread_notifications` and
the `::unread_notifications` methods. Since the previous commits,
the respective `SlidingSyncRoom` methods have been removed too. It's
better to use the `Deref` implementation of `room_list::Room` to
`matrix_sdk::Room` to use the correct methods.
2024-02-01 11:54:48 +01:00
Ivan Enderlin 8ee0021641 feat(sdk): Remove SlidingSyncRoom::has_unread_notifications and ::unread_notifications.
This patch removes the `SlidingSyncRoom::has_unread_notifications`
and the `::unread_notifications` methods. It doesn't hold any relevant
information that `matrix_sdk::Room` can provide.
2024-02-01 11:53:26 +01:00
Ivan Enderlin 39241c5e18 fix(base,sdk,ui): Synchronize sliding sync room's avatar with regular Room
fix(base,sdk,ui): Synchronize sliding sync room's avatar with regular `Room`
2024-02-01 11:17:45 +01:00
Ivan Enderlin 9ef9251936 feat(ui): Remove the fallback mechanism for avatar in room_list_service::Room.
`SlidingSyncRoom` no longer has an `avatar_url` method.
`room_list::Room` no longer needs to check first in sliding sync then in
`Room` as a fallback.

This patch removes the `room_list::Room::avatar_url` method.

This patch also implements `Deref` for `room_list::Room` to
`matrix_sdk::Room`, to make our lifes easier.
2024-02-01 10:58:05 +01:00
Ivan Enderlin 90f1a34855 feat(sdk): Remove the avatar_url logic in SlidingSyncRoom.
With the previous commit, the avatar is properly synchronized with the
`Room`. The result is that `SlidingSyncRoom` no longer needs to hold
the `avatar_url`.
2024-02-01 10:58:05 +01:00
Ivan Enderlin e00532f5d2 feat(base): Update room's avatar from SlidingSyncRoom::avatar.
To update the avatar of a room, one has to look up in the state event.
That's the canonical way to do. For Sliding Sync, it means looking
inside the `required_state` field of the `v4::SlidingSyncRoom`. This
case already works and was tested.

However, a `v4::SlidingSyncRoom` comes with a direct `avatar` field.
It's another way to know the avatar URL of the room. This case was
handled and tested in `matrix_sdk::sliding_sync::SlidingSyncRoom`, but
it was never propagated into the proper sync mechanism. So when the
`avatar` field was set up, `matrix_sdk::sliding_sync::SlidingSyncRoom`
was holding this information, and the `avatar` wasn't defined in the
proper `Room`: `SlidingSyncRoom` has to look up inside the `Room` as
a fallback.

This patch is the first one to fix this “fallback” mechanism.

The `avatar` field of a `v4::SlidingSyncRoom` now triggers an update to
the new `RoomInfo::update_avatar` method (à la `update_name`), via
`process_room_properties`.
2024-02-01 10:58:05 +01:00
Kévin Commaille 8cef7a54d9 Update changelogs
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-01-31 18:49:07 +01:00
Andy Balaam f64af126f1 Merge pull request #3073 from matrix-org/andybalaam/shrink-inbound_group_sessions
indexeddb: Shrink values in inbound_group_sessions store, improving performance all around
2024-01-31 12:29:31 +00:00
Andy Balaam e3da325f29 doc: Add rust,no_run to examples in matrix-sdk-store-encryption 2024-01-31 12:15:43 +00:00
Andy Balaam 860fe4afe0 indexeddb: Measure performance of v8 and v10 inbound_group_session store 2024-01-31 12:15:43 +00:00
Andy Balaam e3ba3366f1 indexeddb: Shrink values in inbound_group_sessions store 2024-01-31 11:59:46 +00:00
Jorge Martin Espinosa e604277e4c ffi: add missing poll events to FilterMessageLikeEventType (#3077)
Added:

- PollEnd
- PollResponse
- PollStart
- UnstablePollStart
- UnstablePollResponse
- UnstablePollEnd
2024-01-31 11:04:26 +01:00
Benjamin Bouvier a356a20c3d fixup! event graph: make TimelineBuilder::build fallible 2024-01-30 23:27:22 +01:00
Benjamin Bouvier 1c1ecf0ab0 ui: inline SlidingSyncRoomExt::timeline into its own caller
It's only used in test code, so it's not worth exposing to the SlidingSyncRoom object (and the Room already has such a timeline function, if needs be).
2024-01-30 23:27:22 +01:00
Benjamin Bouvier fd26cbcfcb ffi: get rid of Room::poll_history as it's slow and likely unused
It's super slow (as it recreates and backpaginates from the start again) and unused in both EX apps, which are our main FFI embedders.
2024-01-30 23:27:22 +01:00
Benjamin Bouvier 3a543f188b event graph: make TimelineBuilder::build fallible 2024-01-30 23:27:22 +01:00
Benjamin Bouvier 06fe8a8f32 event graph: add an initial implementation of the event graph
This is mostly a demonstration of how to plug this with the timeline, and how little it changes as a result.

Remove read receipts
2024-01-30 23:27:22 +01:00
ganfra 6ef33619bf tags : improve code after pr review 2024-01-30 16:46:43 +01:00
ganfra cde6a559ad tags : exposes RoomNotableTags directly from the sdk-base crate 2024-01-30 16:46:43 +01:00
ganfra 3b20cc4444 tags: introduce a new RoomNotablesTags and methods to subscribe to changes on it. 2024-01-30 16:46:43 +01:00
Kévin Commaille 3599e578e2 base: Move ambiguity changes maps from SyncResponse to {Left/Joined}Room
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-01-30 16:33:34 +01:00
Kévin Commaille bc6c458371 ui: Update user profile when ambiguity changes
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-01-30 16:33:34 +01:00
Kévin Commaille f0d722099f sdk: Allow to receive ambiguity changes per-room.
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-01-30 16:33:34 +01:00
Kévin Commaille bcf1ee408b sdk: Add integration test for ambiguity changes
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-01-30 16:33:34 +01:00
Kévin Commaille ef322cc39b base: Add room member ID to AmbiguityChange
Makes AmbiguityChange easier to use, especially outside of SyncResponse,
where we might not have the m.room.member event.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-01-30 16:33:33 +01:00
Benjamin Bouvier f5f8f47667 integration test: fix racy behavior in the test_toggling_reaction
The room sync could be over, and then the timeline items would not contain the updated item yet, if the timeline didn't get a chance to finish its
internal update. Fix this by:

1. limiting the sync time to 10 seconds
2. giving up to one second for the timeline to update internally, by watching its stream of events (we're ignoring stream updates just after this loop)
2024-01-30 12:42:56 +01:00
Jorge Martin Espinosa c418f0e6ba timeline: Add TimelineEventTypeFilter (#3025)
Adds a `TimelineEventTypeFilter` enum that either returns only events whose event_type is included in a set of allowed event types, or all events but those whose event types are in a list of excluded event types.

Also adds `TimelineEventTypeFilter` so the clients can use it to define those lists of event types, which are then converted to ruma `TimelineEventType` and used for filtering.

---

* matrix-sdk-ui: add `TimelineEventTypeFilter` to filter timeline events by either including only those of some event types or all but the ones that match those event types.

* ffi: add bindings to `TimelineEventTypeFilter` and `FilterTimelineEventType` so we can provide these event types from the FFI clients

* Fix format

* Fix tests

* Fix format again (using nightly toolchain)

* Remove `all_filter_...` functions as there is no right way to support it at the moment and they're just helpers

* Improve tests

* Make `TimelineEventFilterFn` public so it can be used in several layers.

* Make `TimelineEventTypeFilter` a struct in the FFI layer

* Add fns for creating a timeline with cache and event type filters

* Remove dead code

* Fix some review comments

* ffi: create new timeline initialization APIs, modify existing ones.
ui: make `Room::timeline()` return `None` if no timeline exists instead of lazily creating one.

More details:

- Added `init_timeline_with_builder` to `matrix_sdk_ui::room_list_service::Room` so a timeline can be initialized at will given a `TimelineBuilder`.
- Create `is_timeline_initialized()` fns in both the ui and ffi layers to check the status of the timeline.
- Make `matrix_sdk_ui::room_list_service::Room::timeline()` only return a timeline if it's already been initialized.
- Create FFI functions to expose these UI ones.

* Fix tests

* Fix some review comments

* Update bindings/matrix-sdk-ffi/src/room_list.rs

Signed-off-by: Benjamin Bouvier <public@benj.me>

---------

Signed-off-by: Benjamin Bouvier <public@benj.me>
Co-authored-by: Benjamin Bouvier <public@benj.me>
2024-01-30 11:00:43 +00:00
Benjamin Bouvier cde7dd2ea8 integration test: make test_toggling_reaction fail fast (#3070)
It's started failing with timeouts in multiple PRs, so this PR should help spot where the issues specifically are, since codecov test failures are so hard to reproduce locally.
2024-01-30 09:52:53 +00:00
ganfra debc28fa47 typing : apply some changes after pr review 2024-01-29 18:18:29 +01:00
Kévin Commaille 6e3892528c intergation-testing: Fix syntax of docker-compose.yml
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-01-29 18:01:33 +01:00
Ivan Enderlin fca455c0bf Merge pull request #3063 from zecakeh/compose-v2
integration-testing: Improve docker-compose.yml compatibility with Podman
2024-01-29 13:52:25 +01:00
Kévin Commaille cd90265eab integration-testing: Update command to clean up docker compose data
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-01-29 11:50:33 +01:00
Kévin Commaille 25b2b191bb integration-testing: Make sliding-sync proxy depend on synapse in docker compose
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-01-29 11:48:58 +01:00
Kévin Commaille 3ade16a07d integration-testing: Add newline at end of docker-compose.yml
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-01-28 17:49:21 +01:00
Kévin Commaille 411dd29244 integration-testing: Use volumes in docker-compose.yml
Podman running unprivileged containers by default, using system folders
can result in permission issues inside the containers.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-01-28 12:20:43 +01:00
Kévin Commaille 1e74be2b2d integration-testing: Remove links in docker-compose.yml
It is not supported by podman and is not necessary by defaut

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-01-28 12:18:33 +01:00
Kévin Commaille a77b67eecd integration-testing: Migrate to Compose V2
Compose V1 was deprecated in January 2023 and is not
supported anymore since July 2023

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-01-28 12:16:50 +01:00
Jonas Platte 18eefcffdb Move matrix-sdk-crypto enum definitions out of UDL 2024-01-27 00:31:42 +01:00
ganfra 2a5dcd562c typing : fix ci 2024-01-26 17:29:05 +01:00
ganfra a3b8ec3640 typing : enable typing extension in room_list_service 2024-01-26 15:37:13 +01:00
ganfra 1fa488ec04 typing : add subscribe_to_typing_notifications and expose through ffi 2024-01-26 15:36:50 +01:00
ganfra 25ecf089aa sliding_sync : fix room account data not being processed when there is no other changes in the room (#3032)
This fixes an issue with the sliding sync processing where room account data are not processed when the associated room has no other changes.

---

* sliding_sync : fix room account data not being processed when there is no other changes in the room

* sliding_sync : properly handle room_account_data from extension

* sliding_sync : add test for processing rooms_account_data

* sliding_sync : fix formatting

* Apply suggestions from code review

Co-authored-by: Ivan Enderlin <ivan@mnt.io>
Signed-off-by: ganfra <francois.ganard@gmail.com>

* sliding_sync : avoid cloning room account data events

Co-authored-by: Benjamin Bouvier <public@benj.me>
Signed-off-by: ganfra <francois.ganard@gmail.com>

---------

Signed-off-by: ganfra <francois.ganard@gmail.com>
Co-authored-by: Ivan Enderlin <ivan@mnt.io>
Co-authored-by: Benjamin Bouvier <public@benj.me>
2024-01-26 13:34:10 +01:00
Valere 8573417537 indexeddb(perf): don't deserialize data while in an indexeddb transaction (#2969)
A quick performance improvement to not do the deserialization/decryption inside the transaction.

---

* quick perf inbound_group_sessions_for_backup

* log on deserialize error

* Review: Unneeded use of :? for an object with Display trait

Co-authored-by: Benjamin Bouvier <public@benj.me>
Signed-off-by: Valere <bill.carson@valrsoft.com>

* Doc: fix capitalization

Co-authored-by: Benjamin Bouvier <public@benj.me>
Signed-off-by: Valere <bill.carson@valrsoft.com>

* Review: better naming

---------

Signed-off-by: Valere <bill.carson@valrsoft.com>
Co-authored-by: Benjamin Bouvier <public@benj.me>
2024-01-26 11:55:04 +01:00
Doug f20c92a323 sdk: Support getting a room member's role. 2024-01-26 11:36:34 +01:00
Doug be8be9ef04 sdk: Add uniffi scaffolding. 2024-01-26 11:36:34 +01:00
Jorge Martín eccfab8b27 ffi: enable android_cleaner option in uniffi.toml
This allows us to use the native `SystemCleaner` in Android 13+ which is a bit safer regarding deadlocks than the JNA alternative we'd use otherwise.
Note this breaks compatibility with pure JVM environments, meaning the library can only be used in Android.
2024-01-26 11:20:55 +01:00
Benjamin Bouvier 25e4c8d722 read receipts: add lots of tracing logs for easier remote debugging 2024-01-26 10:45:02 +01:00
Benjamin Bouvier a9d6ab7313 read receipts: take implicit receipts into account when computing unread counts 2024-01-26 10:45:02 +01:00
Ivan Enderlin 4d2c3e33fc Merge pull request #3042 from matrix-org/rav/room_settings
crypto: Implement `OlmMachine::{set_,}room_settings`
2024-01-25 16:28:34 +01:00
Jonas Platte 0be2747ccf Use new crates.io release of UniFFI 2024-01-25 16:25:55 +01:00
Richard van der Hoff 0b01a2a53a Merge branch 'main' into rav/room_settings
Signed-off-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
2024-01-25 15:14:52 +00:00
Benjamin Bouvier d85c7b213f sliding sync: take the sync lock when processing the response 2024-01-25 13:29:55 +01:00
Benjamin Bouvier 52b10e776c read receipts: use comparison instead of manually reporting read receipts have changed
Before, to avoid saving a room info if the read receipts `RoomInfo` field hadn't changed, we used explicit reporting to the caller that a field
changed value. This way was error-prone, and there's been bugs twice in this area: one fixed in a previous PR,
and there was another one in the existing implementation (when the pending list shrinked, it wouldn't tell the caller).

This commit changes the implementation so that it we snapshot the previous read receipts, and after processing unread counts, we compare the
new version with the snapshot, relying on `PartialEq` to do the leg work here. This is more future proof and less error prone.

Also `compute_unread_counts` isn't fallible, so doesn't need to return a Result.
2024-01-25 13:29:55 +01:00
Benjamin Bouvier d88970155d read receipts: rename compute_notifications to compute_unread_counts 2024-01-25 13:29:55 +01:00
Benjamin Bouvier 1139538c76 comments: correct "inflight" to "in-flight" throughout the codebase 2024-01-25 11:58:13 +01:00
Benjamin Bouvier a1a93afbe2 matrix-sdk: add doc comment to Client::handle_sync_response 2024-01-25 11:58:13 +01:00
Benjamin Bouvier 7a107d8fa2 timeline: inline handle_room_encrypted into its one caller TimelineEventHandler::add
It's a one-liner, so not much worth it as a separate function.
2024-01-25 11:58:13 +01:00
Benjamin Bouvier 5117325ef4 comment: make it clear when some account data comes from storage 2024-01-25 11:58:13 +01:00
Benjamin Bouvier 1085b85dfc timeline: replace floating timeline_item function with a ctor on TimelineItem
And add comments here and there.
2024-01-25 11:58:13 +01:00
Benjamin Bouvier 7a7e624e7b timeline: rename and invert meaning of event_should_update_fully_read_marker
This is renamed to `has_up_to_date_read_marker_item`, and inverted in meaning, compared to its previous meaning.
It's simpler to think of it as the presence of the read marker item: if it's not there, then that's the only case where we'd need to worry about adding one.
2024-01-25 11:58:13 +01:00
Benjamin Bouvier 384d8b0e19 timeline: add comments around read marker handling 2024-01-25 11:58:13 +01:00
Benjamin Bouvier 68c9e5e98d timeline: inline find_read_marker that's used only once 2024-01-25 11:58:13 +01:00
Richard van der Hoff ff89315b6e crypto: add test for 4S keys with no mac or iv (#3048)
A regression test for https://github.com/matrix-org/matrix-rust-sdk/issues/2932

Also a changelog update.
2024-01-23 11:15:49 +00:00
Ivan Enderlin eec52d7977 chore: Update Ruma to 684ffc
chore: Update Ruma to 684ffc
2024-01-22 15:13:01 +01:00
Ivan Enderlin 8515def61b fix(crypto): It's OK to have iv and mac missing.
This patch updates `SecretStorageKey::check_zero_message` to assume
that a missing `iv` and/or `mac` is valid, instead of an error, as the
spec suggests.
2024-01-22 15:00:23 +01:00
Richard van der Hoff 75ea0ad283 Rename session_rotation_period_msgs 2024-01-22 13:36:09 +00:00
Richard van der Hoff ac24f62d8c Address review comments 2024-01-22 12:49:54 +00:00
Benjamin Bouvier 76cd7ab649 test: reenable the unread count test in code coverage (#3044)
The real reason why the test wasn't passing was the same root cause as #3031. The client's room member information was missing, meaning we couldn't compute a push context, so we couldn't compute notifications/mentions either. The fix is in the testing code itself, the sliding sync should request the `$ME` room member state event to work correctly and non-racily.
2024-01-22 12:49:28 +00:00
Ivan Enderlin eab35c1289 chore: Update Ruma to 684ffc.
This patch updates Ruma to the latest commit on its `main` branch.

This is useful for https://github.com/matrix-org/matrix-rust-sdk/issues/2932.
2024-01-22 13:42:00 +01:00
Benjamin Bouvier 1d6c01fb34 Bump matrix-sdk to 0.7.1 2024-01-22 11:56:58 +01:00
Benjamin Bouvier b680c50035 labs: introduce rrrrepl, a client specialized for showing and sending read receipts
This was quite handy during development of the client-side computation of read-receipts, to analyze some bugs.

It might be not useful to have it checked in for long, but I would love to make sure it keeps on compiling
until we have a more stable handling of read receipts in general.
2024-01-22 11:01:26 +01:00
Ivan Enderlin 20b8c41727 Merge pull request #3031 from matrix-org/sliding-sync-add-$me-to-required-state-for-all-rooms
room list service: add `$ME` as a required state for the `all_rooms` sliding sync list
2024-01-22 10:50:47 +01:00
Ivan Enderlin e9d2b1f27a feat: RingBuffer takes a NonZeroUsize
feat: `RingBuffer` takes a `NonZeroUsize`
2024-01-22 10:47:46 +01:00
Ivan Enderlin f90d1678e2 Merge pull request #3038 from matrix-org/cleanup-registrations-again
oidc: cleanup `read_registration_data()` again
2024-01-22 10:46:24 +01:00
Ivan Enderlin 92b7598e4b Merge pull request #3041 from matrix-org/rav/stfu_dead_code
crypto: Silence compiler warning
2024-01-22 10:35:56 +01:00
Ivan Enderlin 10779481b7 feat: RingBuffer takes a NonZeroUsize.
The default implementation of `RingBuffer` was setting a capacity of 0.
This was incorrect as it wasn't possible to insert any items. This patch
updates it to take a `NonZeroUsize` so that it's impossible to set a
negative or zero capacity.
2024-01-22 10:34:49 +01:00
Richard van der Hoff 2314a74cdb crypto: Implement OlmMachine::{get,set}_room_settings
We need to make sure we guard against servers downgrading the encryption
settings, or breaking them with unsupported algorithms. It's not *entirely*
clear what the expectation is here, but legacy crypto in matrix-js-sdk blocks
any changes to the settings at all, so we'll follow suit for now.
2024-01-19 19:15:44 +00:00
Richard van der Hoff 5e0e752fcd memorystore: implement room settings saving 2024-01-19 19:15:44 +00:00
Richard van der Hoff b4b460ad27 crypto: expand RoomSettings to cover session rotation settings. 2024-01-19 19:00:56 +00:00
Richard van der Hoff 6d5f617355 crypto: Silence compiler warning 2024-01-19 17:36:50 +00:00
dependabot[bot] 9f0a1e0ce7 build(deps): bump h2 from 0.3.22 to 0.3.24
---
updated-dependencies:
- dependency-name: h2
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-01-19 17:54:43 +01:00
Benjamin Bouvier d6484a012c oidc: cleanup read_registration_data() again 2024-01-19 17:03:00 +01:00
Benjamin Bouvier f7cb253b1c test: add test that after a first time sync with the room list service, we're able to compute notifications
trying to simplify test
2024-01-19 16:44:32 +01:00
Doug 2dbd4a28a1 oidc: Remove public registration errors that are only used internally. 2024-01-19 13:57:43 +01:00
Doug 5c3edfcf6a authentication: Merge the UI crate's authentication module into the SDK. 2024-01-19 13:57:43 +01:00
Benjamin Bouvier 20b97fc716 room list service: add $ME as a required state for the all_rooms sliding sync list
Without this, we wouldn't ever have the member information for the logged-in user, the first time they log in, if they don't happen to be the
last user sending a message in a room (a case covered by `$LAZY`).
2024-01-19 13:02:23 +01:00
Kévin Commaille b3f4e658c5 base-client: Support notifications in invited rooms (#2907)
Necessary for the `.m.rule.invite_for_me` rule that should only happen in invited rooms.

Requires to create a `Notification` type that accepts stripped state events. It is simpler than Ruma's type because it lacks fields with data that is made up or redundant.

Tested locally with Fractal.

Fixes #1912.

---

* Upgrade Ruma

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>

* base-client: Support notifications in invited rooms

Necessary for the .m.rule.invite_for_me rule that should
only happen in invited rooms.
Requires to create a Notification type that accepts stripped state
events.
It also removes fields with data that is made up or redundant.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>

* matrix-sdk-test: Add macros to construct raw sync or stripped state events

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>

* client: Add tests for register_notification_handler

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>

* Upgrade Ruma

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>

* Fix base changelog

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>

* Fix methods on Room

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>

* Fix FFI

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>

* Fix FFI RoomMember

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>

* Simplify and_then chain

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>

---------

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-01-19 10:30:35 +00:00
Benjamin Bouvier a3fe9c357b read receipts: address PR comments (renamings + comments) 2024-01-18 16:48:47 +01:00
Benjamin Bouvier 2fcd28ab0c read receipts: include implementation details in the module's doc comment 2024-01-18 16:48:47 +01:00
Benjamin Bouvier 5e029aa7a0 read receipts: slightly simplify the new active receipt case 2024-01-18 16:48:47 +01:00
Benjamin Bouvier 95edb9f864 read receipts: rename account_event to process_event
and address some other review comments.
2024-01-18 16:48:47 +01:00
Benjamin Bouvier 7116ed4848 ring buffer: show the behavior of a ring buffer with 0 capacity with a test 2024-01-18 16:48:47 +01:00
Benjamin Bouvier c00f9e9312 read receipts: use a ring buffer to limit the number of pending receipts 2024-01-18 16:48:47 +01:00
Benjamin Bouvier 26896599de ring buffer: Add retain() to the ring buffer implementation 2024-01-18 16:48:47 +01:00
Benjamin Bouvier 3b5238135d read receipts: tracing improvements to help debugging 2024-01-18 16:48:47 +01:00
Benjamin Bouvier 0e5cc44ffa read receipts: use a lax comparison when selecting better receipts
Before, restoring a timeline from the cache, for which we had a receipt for the last element, would not mark that receipt as "interesting", thus
considering that all the events are new. This is incorrect, and another way to fix that would be to set `best_receipt` to the initial read receipt;
but having the information that we had a change is more useful in general, so the comparison is changed from strict to lax here.
2024-01-18 16:48:47 +01:00
Benjamin Bouvier ca47e6d5f9 read receipts: dismiss old events when they contain common events with the new set
When restoring a timeline from the disk cache, or when we get a timeline from a limited sync, we can have events in common to the two sets, messing
up with the count. In that case, forget about previous events, since we don't try to stitch timelines yet.
2024-01-18 16:48:47 +01:00
Benjamin Bouvier 75f1aaced6 ui timeline: add a note about a proxy workaround for duplicate timeline items 2024-01-18 16:48:47 +01:00
Benjamin Bouvier de316acc11 read receipts: don't get confused when receiving multiple times the same event
This is a workaround because the proxy may send the same event multiple times in a sync timeline. When that happens and we had the read receipt
on the duplicated event, it may cause some events to be counted twice, resulting in invalid counts. This patch fixes it by resetting the count
*every* time we see the matching event.
2024-01-18 16:48:47 +01:00
Benjamin Bouvier 706e477e02 read receipts(chore): clippy/rustfmt/typos 2024-01-18 16:48:47 +01:00
Benjamin Bouvier 6716ad6374 read receipts: have compute_notifications return true when stashing pending receipts 2024-01-18 16:48:47 +01:00
Benjamin Bouvier 92df885474 read receipts: introduce ReceiptSelector helper and add many unit tests
The `ReceiptSelector` splits the tasks of computing a better new receipt into small parts, making it trivial to test in isolation.
2024-01-18 16:48:47 +01:00
Benjamin Bouvier ddb44d35cd read receipts: extract create_sync_index out of compute_notifications and unit-test it 2024-01-18 16:48:47 +01:00
Benjamin Bouvier 8de6345d0f test: add test for multiple receipts coming in the same sync 2024-01-18 16:48:47 +01:00
Benjamin Bouvier e6d33eaf90 test: use existing make_receipt_event_content test helper 2024-01-18 16:48:47 +01:00
Benjamin Bouvier fa74602c65 test: introduce test helper sync_timeline_message 2024-01-18 16:48:47 +01:00
Benjamin Bouvier 5cbc34811f read receipts: use sync order
No caching. Step 1 make it correct, etc.
2024-01-18 16:48:47 +01:00
Benjamin Bouvier 2d60611a44 read receipts: don't repeat iterating over older events if the server sent us the same receipt twice 2024-01-18 16:48:47 +01:00
Andy Balaam ff387609c3 Merge pull request #3012 from matrix-org/andybalaam/batch-indexeddb-fetch-for-get_inbound_group_sessions
indexeddb: Attempt to fix export crashes by batching DB operations in get_inbound_group_sessions
2024-01-18 13:40:20 +00:00
Andy Balaam b05a0ecb3b indexeddb: Batch DB access in get_inbound_group_sessions
Signed-off-by: Andy Balaam <andy.balaam@matrix.org>
2024-01-18 13:28:14 +00:00
Valere 784c7459fe refactor(bootstrap): init cross-signing with other e2e initial task (#3024)
In existing code the bootstraping is done in different places:
  - in `bootstrap_cross_signing_if_needed` 
  - or in `run_intialization_tasks`

And both are based on the same EncryptionSettings.
`bootstrap_cross_signing_if_needed` was done by `LoginBuilder` but `run_intialization_tasks` by `MatrixAuth`. 

I propose to move all that under `run_intialization_tasks` that has already support to do it in background, and to call it in one place only: `MatrixAuth`

Also Fixes https://github.com/matrix-org/matrix-rust-sdk/issues/2763

## Notes

- Some tests have been updated to properly `wait_for_e2ee_initialization_tasks`

- `bootstrap_cross_signing_if_needed` might require re-authentication. Which I suppose was the original reason to have that in a seperate place. But given that the need to re-auth will soon be deprecated for bootstrap (when this [MSC](https://github.com/matrix-org/matrix-spec-proposals/pull/3967) will land); so for now we pass the authentication info to `run_intialization_tasks` if any. 

---

* refactor(bootstrap): init cross-signing with other e2e initial task

* fix compilation warning for NoEncryption feature set

* Doc and Formatting: Improve doc and formatting

* Fix missing import with encryption feature flag
2024-01-18 14:25:50 +01:00
Benjamin Bouvier 18065cb42e ffi: remove unused RoomListItem::full_room_blocking() function
The Kotlin leaks have been fixed nowadays.
2024-01-18 12:30:47 +01:00
Richard van der Hoff 01d11888f4 RELEASE.md: remove spurious backticks
Signed-off-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
2024-01-18 10:31:36 +01:00
Richard van der Hoff 8aef687dcb Merge pull request #3026 from matrix-org/rav/remove_base_dep
indexeddb, sqlite: Avoid dependency on `matrix-sdk-base`
2024-01-17 09:19:15 +00:00
Richard van der Hoff 79bb716298 Inline matrix_sdk_sqlite::make_store_config
... mostly for parity with `matrix_sdk_indexeddb::make_store_config`, but
again, simplifying the dependency graph.
2024-01-16 18:13:51 +00:00
Richard van der Hoff 8ef09b4044 indexeddb: Replace make_store_config
Replace `make_store_config` with a pair of funtions `open_stores_with_name` and
`open_state_store`. This allows us to remove a dependency on
`matrix-sdk-base/e2e-encryption`, and generally simplifies things.
2024-01-16 18:13:51 +00:00
Richard van der Hoff 5f435a86ee Factor out build_store_config function 2024-01-16 12:57:18 +00:00
Andy Balaam 58be7b0f3d Merge pull request #3013 from matrix-org/andybalaam/retain-in-export_room_keys
crypto: Improve memory overhead of export_room_keys by using Vec::retain
2024-01-15 11:59:33 +00:00
Andy Balaam 7034104ef1 fixup! crypto: Improve memory overhead of export_room_keys by using Vec::retain 2024-01-15 10:05:42 +00:00
Denis Kasak c4113060b2 refactor: Simplify construction of main crate UserIdentity.
Instead of needing three methods, we now only need one: since we use the
crypto crate enum directly, we no longer need to convert between the
crypto crate and main crate enums.

Signed-off-by: Denis Kasak <dkasak@termina.org.uk>
2024-01-14 18:29:57 +01:00
Denis Kasak 3d1de1f583 refactor: Simplify main crate user identities types.
Specifically, this removes the following redundant types in the main
crate:

- enum UserIdentities
- struct OwnUserIdentity
- struct OtherUserIdentity

This is possible because `OwnUserIdentity` and `OtherUserIdentity` are
exactly the same as their crypto crate counterparts, except they also
wrap a `Client`.

As a consequence, the main crate enum `UserIdentities` is isomorphic to
a struct containing:

1. the crypto crate `UserIdentities`
2. a `Client`

So this commit performs that transformation.

Signed-off-by: Denis Kasak <dkasak@termina.org.uk>
2024-01-14 18:29:57 +01:00
Sami J. Mäkinen 147f1d3f6c Upgrade aquamarine dependency 2024-01-14 11:20:12 +00:00
Kévin Commaille e3af74739d ui: Improve logging of toggle reaction failures
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-01-13 21:19:55 +01:00
Kévin Commaille 8d0867a1a8 ui: Forward server failures to toggle reaction to user
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-01-13 21:19:55 +01:00
Benjamin Bouvier cfe3bb7cef sdk: expose SqliteStateStore for symmetry with the crypto store export 2024-01-13 09:25:05 +01:00
Benjamin Bouvier 95b95aae5f Apply suggestions from code review
Co-authored-by: Jonas Platte <jplatte@matrix.org>
Signed-off-by: Benjamin Bouvier <public@benj.me>
2024-01-12 17:20:10 +01:00
Benjamin Bouvier 83d7cd5430 docs: explain how to release the SDK in RELEASE.md 2024-01-12 17:20:10 +01:00
Benjamin Bouvier d0e5d84bff docs: add commit messages and PR titles guidelines 2024-01-12 17:20:10 +01:00
Mauro fb4b5ea48f ffi bindings: Expose members_no_sync (#3004)
As it is useful to allow fetching members from the store in offline contexts.
2024-01-12 17:01:05 +01:00
Andy Balaam 985f9f9b07 crypto: Improve memory overhead of export_room_keys by using Vec::retain
Signed-off-by: Andy Balaam <andy.balaam@matrix.org>
2024-01-12 15:05:13 +00:00
Mauro c7f7828368 ffi: Expose is_name_ambiguous for notification item 2024-01-12 10:28:48 +00:00
Benjamin Bouvier 3fea9ae51a crypto: rename Account::generate_one_time_keys_helper to generate_one_time_keys 2024-01-11 16:19:12 +01:00
Benjamin Bouvier 3c4b892129 crypto: rename Account::generate_one_time_keys to Account::generate_one_time_keys_if_needed 2024-01-11 16:19:12 +01:00
Benjamin Bouvier a7d2ff327d style: reduce indent in generate_one_time_keys 2024-01-11 16:19:12 +01:00
Benjamin Bouvier 90c1858389 style: don't use a large outer Ok with ? in it 2024-01-11 16:19:12 +01:00
Benjamin Bouvier 289268a60b crypto: make it clearer receive_to_device_event is infallible 2024-01-11 16:19:12 +01:00
Benjamin Bouvier 04d1fd4b8a test: rename create_session_for to create_session_for_test_helper
To make it easier to see it's a test function when looking up callers/callees.
2024-01-11 16:19:12 +01:00
Ivan Enderlin 97b2a20338 Merge pull request #3007 from matrix-org/revert-3006-revert-2995-rav/indexeddb_optional_base
Revert "Revert "matrix-sdk-indexeddb: make `matrix-sdk-base` an optional dependency""
2024-01-11 15:21:05 +01:00
Ivan Enderlin 62641adfeb Revert "Revert "matrix-sdk-indexeddb: make matrix-sdk-base an optional dependency"" 2024-01-11 15:20:38 +01:00
Ivan Enderlin 6e407989e8 Merge pull request #3006 from matrix-org/revert-2995-rav/indexeddb_optional_base
Revert "matrix-sdk-indexeddb: make `matrix-sdk-base` an optional dependency"
2024-01-11 15:18:27 +01:00
Ivan Enderlin 1521ec6cb2 Revert "matrix-sdk-indexeddb: make matrix-sdk-base an optional dependency" 2024-01-11 15:05:00 +01:00
Ivan Enderlin b3ada6cb37 Merge pull request #3003 from matrix-org/mauroromito/better_naming_for_msc4028
Improving documentation: Can push encrypted events to device
2024-01-11 14:13:28 +01:00
Mauro 21b7e54a59 Merge branch 'main' into mauroromito/better_naming_for_msc4028 2024-01-11 12:16:20 +01:00
Benjamin Bouvier 463b0dfb91 sliding sync: make the maximum number of room facultative when updating a room 2024-01-11 11:38:26 +01:00
Benjamin Bouvier f48695cc95 Test that an extension causing a room update will mark the room as updated 2024-01-11 11:38:26 +01:00
Benjamin Bouvier 395a39e039 sliding sync: mark room/list as updated whenever a room is updated by an extension
Some sliding sync responses may include extension data that will cause an update to the room, but the room itself may not be in the set of
rooms as returned in the top-level `rooms` fields of the response. This may cause missed updates for rooms, since notifiers won't be notified
about those.

This fixes that, by making sure that a `RoomInfo`-only update will cause the room (and the lists that contain it) to be marked as updated.
2024-01-11 11:38:26 +01:00
Mauro Romito e37f5e5ac3 ffi docs: renamed push encrypted event FFI API
and improved the documentation
2024-01-11 11:35:21 +01:00
Benjamin Bouvier 1bc921f373 integration tests: remove useless qualifications 2024-01-11 10:30:16 +01:00
Benjamin Bouvier 36e69f30ec crypto ffi: use a u64 for timestamps
Fixes https://github.com/matrix-org/matrix-rust-sdk/issues/2974
2024-01-11 10:30:16 +01:00
Ivan Enderlin 82c60116ef Merge pull request #2995 from matrix-org/rav/indexeddb_optional_base
matrix-sdk-indexeddb: make `matrix-sdk-base` an optional dependency
2024-01-10 10:52:29 +01:00
Ivan Enderlin 840cb97c21 Merge pull request #3001 from matrix-org/andybalaam/tests-for-inbound-group-session-serialization
Tests for serialization of InboundGroupSessionIndexedDbObject
2024-01-10 10:23:22 +01:00
Benjamin Bouvier ae15595af1 cleanup: move homeserver overriding to the SendRequest struct 2024-01-09 16:54:58 +01:00
Andy Balaam f89ed01182 Formatting 2024-01-09 15:38:29 +00:00
Andy Balaam 2e803c3a3d Improve name of variable in tests 2024-01-09 15:35:25 +00:00
Andy Balaam 7a3a3edc9d Tests for serialization of InboundGroupSessionIndexedDbObject
Signed-off-by: Andy Balaam <andy.balaam@matrix.org>
2024-01-09 15:31:24 +00:00
Mauro Romito 13718c6d49 fix 2024-01-08 17:44:52 +01:00
Benjamin Kampmann 767b45dcf7 Fix: Registration-login-pattern leads to double devices (#2888)
When using the same pattern of `client.register(); client.login_*` that is used by tests in [our Acter app, strangely showed that more than one device/session had been opened](https://github.com/acterglobal/a3/issues/938).

Turns out, if the server is set up for it, according [to the spec](https://spec.matrix.org/v1.8/client-server-api/#post_matrixclientv3register) registration _is_ already a login and both device id and access token will be returned ... which are then straight-up ignored by the matrix-sdk Client and without any way of setting it from the outside, one _must_ login again, creating a second unnecessary device/session.

This PR adds an integration test case that checks that upon the minimal registration-login-flow only one device/session is found (as is to be expected from the outside), surfacing the error. It also contains a "somewhat fix" (as we need this in the app right now), but as it a) changes the behavior of the current API and b) isn't fully implementing the encryption-bootstrapping-pattern (and thus fails a different test), I'd leave it open to discussion whether that was appropriate way to go.

---

* Test showing registration-login-pattern leads to too many devices

* Fix too-many-devices-bug

* Do not panic on failure to set session, refactor and add docs

* refactor bootstrap crosssinging

* Fixup

* Use new post_login_cross_signing feature from Oidc, too

* unwrap at construction for less verbose code

* remove comment from test

* make new fn pub(crate) to fix build
2024-01-08 15:24:56 +01:00
Richard van der Hoff b690db1e05 matrix-sdk-crypto: enable matrix-sdk-common/js 2024-01-08 13:31:31 +00:00
Richard van der Hoff 5ab397e8d9 Enable state-store on matrix-sdk-indexeddb 2024-01-08 11:56:03 +00:00
Richard van der Hoff 0d938d94aa matrix-sdk-indexeddb: make matrix-sdk-base an optional dependency
If we're not using the StateStore, then we don't need a dependency on
`matrix-sdk-base`. Let's make it turn-off-able.
2024-01-05 17:29:07 +00:00
598 changed files with 127118 additions and 35718 deletions
-46
View File
@@ -1,13 +1,3 @@
# Pass the rustflags specified to host dependencies (build scripts, proc-macros)
# when a `--target` is passed to Cargo. Historically this was not the case, and
# because of that, cross-compilation would not set the rustflags configured
# below in `target.'cfg(...)'` for them, resulting in cache invalidation.
#
# Since this is an unstable feature (enabled at the bottom of the file), this
# setting is unfortunately ignored on stable toolchains, but it's still better
# to have it apply on nightly than using the old behavior for all toolchains.
target-applies-to-host = false
[alias]
xtask = "run --package xtask --"
uniffi-bindgen = "run --package uniffi-bindgen --"
@@ -15,41 +5,5 @@ uniffi-bindgen = "run --package uniffi-bindgen --"
[doc.extern-map.registries]
crates-io = "https://docs.rs/"
# Exclude tarpaulin, android and ios from extra lints since on stable, without
# the nightly-only target-applies-to-host setting at the top, cross compilation
# and otherwise changing cfg's can be very bad for caching. These should never
# be the default either and don't have much target-specific code that would
# benefit from the extra lints.
[target.'cfg(not(any(tarpaulin, target_os = "android", target_os = "ios")))']
rustflags = [
"-Wrust_2018_idioms",
"-Wsemicolon_in_expressions_from_macros",
"-Wunused_extern_crates",
"-Wunused_import_braces",
"-Wunused_qualifications",
"-Wtrivial_casts",
"-Wtrivial_numeric_casts",
"-Wclippy::cloned_instead_of_copied",
"-Wclippy::dbg_macro",
"-Wclippy::inefficient_to_string",
"-Wclippy::macro_use_imports",
"-Wclippy::mut_mut",
"-Wclippy::needless_borrow",
"-Wclippy::nonstandard_macro_braces",
"-Wclippy::str_to_string",
"-Wclippy::todo",
]
[target.'cfg(target_arch = "wasm32")']
rustflags = [
# We have some types that are !Send and/or !Sync only on wasm, it would be
# slightly more efficient, but also pretty annoying, to wrap them in Rc
# where we would use Arc on other platforms.
"-Aclippy::arc_with_non_send_sync",
]
# activate the target-applies-to-host feature.
# Required for `target-applies-to-host` at the top to take effect.
[unstable]
rustdoc-map = true
target-applies-to-host = true
+64
View File
@@ -0,0 +1,64 @@
# https://embarkstudios.github.io/cargo-deny/checks/cfg.html
[graph]
all-features = true
exclude = [
# dev only dependency
"criterion"
]
[advisories]
version = 2
ignore = [
{ id = "RUSTSEC-2023-0071", reason = "We are not using RSA directly, nor do we depend on the RSA crate directly" },
{ id = "RUSTSEC-2024-0384", reason = "Unmaintained backoff crate, not critical. We'll migrate soon." },
]
[licenses]
version = 2
allow = [
"Apache-2.0",
"Apache-2.0 WITH LLVM-exception",
"BSD-2-Clause",
"BSD-3-Clause",
"BSL-1.0",
"ISC",
"MIT",
"MPL-2.0",
"Unicode-3.0",
"Zlib",
]
exceptions = [
{ allow = ["Unicode-DFS-2016"], crate = "unicode-ident" },
{ allow = ["CDDL-1.0"], crate = "inferno" },
{ allow = ["LicenseRef-ring"], crate = "ring" },
]
[[licenses.clarify]]
name = "ring"
expression = "LicenseRef-ring"
license-files = [
{ path = "LICENSE", hash = 0xbd0eed23 },
]
[bans]
# We should disallow this, but it's currently a PITA.
multiple-versions = "allow"
wildcards = "allow"
[sources]
unknown-registry = "deny"
unknown-git = "deny"
allow-git = [
# A patch override for the bindings fixing a bug for Android before upstream
# releases a new version.
"https://github.com/element-hq/tracing.git",
# Sam as for the tracing dependency.
"https://github.com/element-hq/paranoid-android.git",
# Well, it's Ruma.
"https://github.com/ruma/ruma",
# A patch override for the bindings: https://github.com/rodrimati1992/const_panic/pull/10
"https://github.com/jplatte/const_panic",
# A patch override for the bindings: https://github.com/smol-rs/async-compat/pull/22
"https://github.com/jplatte/async-compat",
]
+1
View File
@@ -1 +1,2 @@
* @matrix-org/rust
/crates/matrix-sdk-crypto @matrix-org/rust @matrix-org/rust-crypto-reviewers
+7
View File
@@ -0,0 +1,7 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
# Check for updates to GitHub Actions every week
interval: "weekly"
-13
View File
@@ -1,13 +0,0 @@
name: Security audit
on:
workflow_dispatch:
schedule:
- cron: '0 0 * * *'
jobs:
audit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/audit-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
+3 -3
View File
@@ -8,16 +8,16 @@ jobs:
name: Run Benchmarks
runs-on: ubuntu-latest
environment: matrix-rust-bot
if: github.event_name == 'push' || !github.event.pull_request.draft
if: github.event_name == 'push'
steps:
- name: Checkout the repo
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly-2023-11-08
toolchain: nightly-2024-11-26
components: rustfmt
- name: Run Benchmarks
+119 -6
View File
@@ -31,7 +31,7 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Install protoc
uses: taiki-e/install-action@v2
@@ -52,7 +52,7 @@ jobs:
save-if: ${{ github.ref == 'refs/heads/main' }}
- name: Get xtask
uses: actions/cache/restore@v3
uses: actions/cache/restore@v4
with:
path: target/debug/xtask
key: "${{ needs.xtask.outputs.cachekey-linux }}"
@@ -61,15 +61,82 @@ jobs:
- name: Build library & generate bindings
run: target/debug/xtask ci bindings
test-android:
name: matrix-rust-components-kotlin
needs: xtask
runs-on: ubuntu-latest
if: github.event_name == 'push' || !github.event.pull_request.draft
steps:
- name: Checkout Rust SDK
uses: actions/checkout@v4
- name: Checkout Kotlin Rust Components project
uses: actions/checkout@v4
with:
repository: matrix-org/matrix-rust-components-kotlin
path: rust-components-kotlin
ref: main
- name: Use JDK 17
uses: actions/setup-java@v4
with:
distribution: 'temurin' # See 'Supported distributions' for available options
java-version: '17'
- name: Install android sdk
uses: malinskiy/action-android/install-sdk@release/0.1.4
- name: Install android ndk
uses: nttld/setup-ndk@v1
id: install-ndk
with:
ndk-version: r27
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
# Cargo config can screw with caching and is only used for alias config
# and extra lints, which we don't care about here
- name: Delete cargo config
run: rm .cargo/config.toml
- name: Load cache
uses: Swatinem/rust-cache@v2
with:
save-if: ${{ github.ref == 'refs/heads/main' }}
- name: Get xtask
uses: actions/cache/restore@v4
with:
path: target/debug/xtask
key: "${{ needs.xtask.outputs.cachekey-linux }}"
fail-on-cache-miss: true
- name: Install Rust dependencies
run: |
rustup target add x86_64-linux-android
cargo install cargo-ndk
- name: Build SDK bindings for Android
# Building for x86_64-linux-android as it's the most prone to breaking and building for every arch is too much
run: |
echo "Building SDK for x86_64-linux-android and creating bindings"
target/debug/xtask kotlin build-android-library --package full-sdk --only-target x86_64-linux-android --src-dir rust-components-kotlin/sdk/sdk-android/src/main
echo "Copying the result binary to the Android project"
cd rust-components-kotlin
echo "Building the Kotlin bindings"
./gradlew :sdk:sdk-android:assembleDebug
test-apple:
name: matrix-rust-components-swift
needs: xtask
runs-on: macos-12
runs-on: macos-15
if: github.event_name == 'push' || !github.event.pull_request.draft
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
# install protoc in case we end up rebuilding opentelemetry-proto
- name: Install protoc
@@ -94,7 +161,7 @@ jobs:
save-if: ${{ github.ref == 'refs/heads/main' }}
- name: Get xtask
uses: actions/cache/restore@v3
uses: actions/cache/restore@v4
with:
path: target/debug/xtask
key: "${{ needs.xtask.outputs.cachekey-macos }}"
@@ -108,4 +175,50 @@ jobs:
run: swift test
- name: Build Framework
run: target/debug/xtask swift build-framework --only-target=aarch64-apple-ios
run: target/debug/xtask swift build-framework --target=aarch64-apple-ios --profile=reldbg
complement-crypto:
name: "Run Complement Crypto tests"
uses: matrix-org/complement-crypto/.github/workflows/single_sdk_tests.yml@main
with:
use_rust_sdk: "." # use local checkout
use_complement_crypto: "MATCHING_BRANCH"
test-crypto-apple-framework-generation:
name: Generate Crypto FFI Apple XCFramework
runs-on: macos-15
if: github.event_name == 'push' || !github.event.pull_request.draft
steps:
- name: Checkout
uses: actions/checkout@v4
# install protoc in case we end up rebuilding opentelemetry-proto
- name: Install protoc
uses: taiki-e/install-action@v2
with:
tool: protoc@3.20.3
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Add rust targets
run: |
rustup target add aarch64-apple-ios
# Cargo config can screw with caching and is only used for alias config
# and extra lints, which we don't care about here
- name: Delete cargo config
run: rm .cargo/config.toml
- name: Load cache
uses: Swatinem/rust-cache@v2
with:
save-if: ${{ github.ref == 'refs/heads/main' }}
- name: Run the Build Framework script
run: ./bindings/apple/build_crypto_xcframework.sh -i
- name: Is XCFramework generated?
if: ${{ hashFiles('generated/MatrixSDKCryptoFFI.zip') != '' }}
run: echo "XCFramework exists"
+44 -46
View File
@@ -26,7 +26,6 @@ jobs:
test-matrix-sdk-features:
name: 🐧 [m], ${{ matrix.name }}
needs: xtask
if: github.event_name == 'push' || !github.event.pull_request.draft
runs-on: ubuntu-latest
strategy:
@@ -44,11 +43,16 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Install libsqlite
run: |
sudo apt-get update
sudo apt-get install libsqlite3-dev
- name: Load cache
uses: Swatinem/rust-cache@v2
with:
@@ -64,7 +68,7 @@ jobs:
uses: taiki-e/install-action@nextest
- name: Get xtask
uses: actions/cache/restore@v3
uses: actions/cache/restore@v4
with:
path: target/debug/xtask
key: "${{ needs.xtask.outputs.cachekey-linux }}"
@@ -78,11 +82,10 @@ jobs:
name: 🐧 [m]-examples
needs: xtask
runs-on: ubuntu-latest
if: github.event_name == 'push' || !github.event.pull_request.draft
steps:
- name: Checkout the repo
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
@@ -96,7 +99,7 @@ jobs:
uses: taiki-e/install-action@nextest
- name: Get xtask
uses: actions/cache/restore@v3
uses: actions/cache/restore@v4
with:
path: target/debug/xtask
key: "${{ needs.xtask.outputs.cachekey-linux }}"
@@ -110,11 +113,15 @@ jobs:
name: 🐧 [m]-crypto
needs: xtask
runs-on: ubuntu-latest
if: github.event_name == 'push' || !github.event.pull_request.draft
steps:
- name: Checkout the repo
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Install libsqlite
run: |
sudo apt-get update
sudo apt-get install libsqlite3-dev
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
@@ -128,7 +135,7 @@ jobs:
uses: taiki-e/install-action@nextest
- name: Get xtask
uses: actions/cache/restore@v3
uses: actions/cache/restore@v4
with:
path: target/debug/xtask
key: "${{ needs.xtask.outputs.cachekey-linux }}"
@@ -140,7 +147,6 @@ jobs:
test-all-crates:
name: ${{ matrix.name }}
if: github.event_name == 'push' || !github.event.pull_request.draft
runs-on: ${{ matrix.os }}
strategy:
@@ -161,13 +167,19 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Install protoc
uses: taiki-e/install-action@v2
with:
tool: protoc@3.20.3
- name: Install libsqlite
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install libsqlite3-dev
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@master
with:
@@ -193,7 +205,6 @@ jobs:
test-wasm:
name: 🕸️ ${{ matrix.name }}
needs: xtask
if: github.event_name == 'push' || !github.event.pull_request.draft
runs-on: ubuntu-latest
@@ -210,11 +221,8 @@ jobs:
- name: '[m]-common'
cmd: matrix-sdk-common
- name: '[m]-indexeddb, no crypto'
cmd: indexeddb-no-crypto
- name: '[m]-indexeddb, with crypto'
cmd: indexeddb-with-crypto
- name: '[m]-indexeddb'
cmd: indexeddb
- name: '[m], no-default, wasm-flags'
cmd: matrix-sdk-no-default
@@ -227,7 +235,7 @@ jobs:
steps:
- name: Checkout the repo
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
@@ -236,7 +244,7 @@ jobs:
components: clippy
- name: Install wasm-pack
uses: jetli/wasm-pack-action@v0.4.0
uses: qmaru/wasm-pack-action@v0.5.0
with:
version: v0.10.3
@@ -255,7 +263,7 @@ jobs:
uses: taiki-e/install-action@nextest
- name: Get xtask
uses: actions/cache/restore@v3
uses: actions/cache/restore@v4
with:
path: target/debug/xtask
key: "${{ needs.xtask.outputs.cachekey-linux }}"
@@ -272,16 +280,15 @@ jobs:
formatting:
name: Check Formatting
runs-on: ubuntu-latest
if: github.event_name == 'push' || !github.event.pull_request.draft
steps:
- name: Checkout the repo
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly-2023-11-08
toolchain: nightly-2024-11-26
components: rustfmt
- name: Cargo fmt
@@ -291,24 +298,22 @@ jobs:
typos:
name: Spell Check with Typos
runs-on: ubuntu-latest
if: github.event_name == 'push' || !github.event.pull_request.draft
steps:
- name: Checkout Actions Repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Check the spelling of the files in our repo
uses: crate-ci/typos@v1.17.0
uses: crate-ci/typos@v1.28.3
clippy:
name: Run clippy
needs: xtask
runs-on: ubuntu-latest
if: github.event_name == 'push' || !github.event.pull_request.draft
steps:
- name: Checkout the repo
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Install protoc
uses: taiki-e/install-action@v2
@@ -318,7 +323,7 @@ jobs:
- name: Install Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly-2023-11-08
toolchain: nightly-2024-11-26
components: clippy
- name: Load cache
@@ -327,7 +332,7 @@ jobs:
save-if: ${{ github.ref == 'refs/heads/main' }}
- name: Get xtask
uses: actions/cache/restore@v3
uses: actions/cache/restore@v4
with:
path: target/debug/xtask
key: "${{ needs.xtask.outputs.cachekey-linux }}"
@@ -339,14 +344,13 @@ jobs:
integration-tests:
name: Integration test
if: github.event_name == 'push' || !github.event.pull_request.draft
runs-on: ubuntu-latest
# run several docker containers with the same networking stack so the hostname 'postgres'
# maps to the postgres container, etc.
services:
# sliding sync needs a postgres container
# synapse needs a postgres container
postgres:
# Docker Hub image
image: postgres
@@ -364,21 +368,10 @@ jobs:
ports:
# Maps tcp port 5432 on service container to the host
- 5432:5432
# run sliding sync and point it at the postgres container and synapse container.
# the postgres container needs to be above this to make sure it has started prior to this service.
slidingsync:
image: "ghcr.io/matrix-org/sliding-sync:v0.99.11" # keep in sync with ./coverage.yml
env:
SYNCV3_SERVER: "http://synapse:8008"
SYNCV3_SECRET: "SUPER_CI_SECRET"
SYNCV3_BINDADDR: ":8118"
SYNCV3_DB: "user=postgres password=postgres dbname=syncv3 sslmode=disable host=postgres"
ports:
- 8118:8118
# tests need a synapse: this is a service and not michaelkaye/setup-matrix-synapse@main as the
# latter does not provide networking for services to communicate with it.
synapse:
image: ghcr.io/matrix-org/synapse-service:v1.94.0 # keep in sync with ./coverage.yml
image: ghcr.io/matrix-org/synapse-service:v1.117.0 # keep in sync with ./coverage.yml
env:
SYNAPSE_COMPLEMENT_DATABASE: sqlite
SERVER_NAME: synapse
@@ -387,7 +380,12 @@ jobs:
steps:
- name: Checkout the repo
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Install libsqlite
run: |
sudo apt-get update
sudo apt-get install libsqlite3-dev
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
@@ -402,7 +400,7 @@ jobs:
- name: Test
env:
RUST_LOG: "hyper=trace"
RUST_LOG: "info,matrix_sdk=trace"
HOMESERVER_URL: "http://localhost:8008"
HOMESERVER_DOMAIN: "synapse"
SLIDING_SYNC_PROXY_URL: "http://localhost:8118"
+35 -26
View File
@@ -1,4 +1,4 @@
name: Code coverage
name: Code Coverage
on:
push:
@@ -25,12 +25,10 @@ jobs:
code_coverage:
name: Code Coverage
runs-on: "ubuntu-latest"
if: github.event_name == 'push' || !github.event.pull_request.draft
# run several docker containers with the same networking stack so the hostname 'postgres'
# maps to the postgres container, etc.
services:
# sliding sync needs a postgres container
postgres:
# Docker Hub image
image: postgres
@@ -48,21 +46,10 @@ jobs:
ports:
# Maps tcp port 5432 on service container to the host
- 5432:5432
# run sliding sync and point it at the postgres container and synapse container.
# the postgres container needs to be above this to make sure it has started prior to this service.
slidingsync:
image: "ghcr.io/matrix-org/sliding-sync:v0.99.11" # keep in sync with ./ci.yml
env:
SYNCV3_SERVER: "http://synapse:8008"
SYNCV3_SECRET: "SUPER_CI_SECRET"
SYNCV3_BINDADDR: ":8118"
SYNCV3_DB: "user=postgres password=postgres dbname=syncv3 sslmode=disable host=postgres"
ports:
- 8118:8118
# tests need a synapse: this is a service and not michaelkaye/setup-matrix-synapse@main as the
# latter does not provide networking for services to communicate with it.
synapse:
image: ghcr.io/matrix-org/synapse-service:v1.94.0 # keep in sync with ./ci.yml
image: ghcr.io/matrix-org/synapse-service:v1.117.0 # keep in sync with ./ci.yml
env:
SYNAPSE_COMPLEMENT_DATABASE: sqlite
SERVER_NAME: synapse
@@ -71,10 +58,15 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Install libsqlite
run: |
sudo apt-get update
sudo apt-get install libsqlite3-dev
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
@@ -94,7 +86,7 @@ jobs:
tool: cargo-tarpaulin
# set up backend for integration tests
- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: 3.8
@@ -105,17 +97,34 @@ jobs:
--features experimental-widgets,testing
env:
CARGO_PROFILE_COV_INHERITS: 'dev'
CARGO_PROFILE_COV_DEBUG: 'false'
CARGO_PROFILE_COV_DEBUG: 1
HOMESERVER_URL: "http://localhost:8008"
HOMESERVER_DOMAIN: "synapse"
SLIDING_SYNC_PROXY_URL: "http://localhost:8118"
- name: Upload to codecov.io
uses: codecov/codecov-action@v3
# Copied with minimal adjustments, source:
# https://github.com/google/mdbook-i18n-helpers/blob/2168b9cea1f4f76b55426591a9bcc308a620194f/.github/workflows/test.yml
- name: Get PR number and commit SHA
run: |
echo "Storing PR number ${{ github.event.number }}"
echo "${{ github.event.number }}" > pr_number.txt
echo "Storing commit SHA ${{ github.event.pull_request.head.sha }}"
echo "${{ github.event.pull_request.head.sha }}" > commit_sha.txt
# This stores the coverage report and metadata in artifacts.
# The actual upload to Codecov is executed by a different workflow `upload_coverage.yml`.
# The reason for this split is because `on.pull_request` workflows don't have access to secrets.
- name: Store coverage report in artifacts
uses: actions/upload-artifact@v4
with:
# Work around frequent upload errors, for runs inside the main repo (not PRs from forks).
# Otherwise not required for public repos.
token: ${{ secrets.CODECOV_UPLOAD_TOKEN }}
# The upload sometimes fails due to https://github.com/codecov/codecov-action/issues/837.
# To make sure that the failure gets flagged clearly in the UI, fail the action.
fail_ci_if_error: true
name: codecov_report
path: |
cobertura.xml
pr_number.txt
commit_sha.txt
if-no-files-found: error
- run: |
echo 'The coverage report was stored in Github artifacts.'
echo 'It will be uploaded to Codecov using `upload_coverage.yml` workflow shortly.'
+14
View File
@@ -0,0 +1,14 @@
name: Lint dependencies (for licences, allowed sources, banned dependencies, vulnerabilities)
on:
pull_request:
paths:
- '**/Cargo.toml'
workflow_dispatch:
schedule:
- cron: '0 0 * * *'
jobs:
cargo-deny:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: EmbarkStudios/cargo-deny-action@v2
@@ -0,0 +1,12 @@
name: Detects unused dependencies
on:
pull_request: { branches: "*" }
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Machete
uses: bnjbvr/cargo-machete@main
+6 -9
View File
@@ -23,11 +23,10 @@ jobs:
docs:
name: All crates
runs-on: ubuntu-latest
if: github.event_name == 'push' || !github.event.pull_request.draft
steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Install protoc
uses: taiki-e/install-action@v2
@@ -37,10 +36,10 @@ jobs:
- name: Install Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly-2023-11-08
toolchain: nightly-2024-11-26
- name: Install Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 20
@@ -52,19 +51,17 @@ jobs:
# Keep in sync with xtask docs
- name: Build documentation
env:
# Work around https://github.com/rust-lang/cargo/issues/10744
CARGO_TARGET_APPLIES_TO_HOST: "true"
RUSTDOCFLAGS: "--enable-index-page -Zunstable-options --cfg docsrs -Dwarnings"
run:
cargo doc --no-deps --workspace --features docsrs
cargo doc --no-deps --workspace --features docsrs --exclude=xtask
- name: Upload artifact
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
uses: actions/upload-pages-artifact@v1
uses: actions/upload-pages-artifact@v3
with:
path: './target/doc/'
- name: Deploy to GitHub Pages
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
id: deployment
uses: actions/deploy-pages@v2
uses: actions/deploy-pages@v4
+12
View File
@@ -0,0 +1,12 @@
name: Git Checks
on: [pull_request]
jobs:
block-fixup:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Block Fixup Commit Merge
uses: 13rac1/block-fixup-merge-action@v2.0.0
+21
View File
@@ -0,0 +1,21 @@
name: Rust version
on:
workflow_dispatch:
push:
branches: [main]
pull_request:
branches: [main]
types:
- opened
- reopened
- synchronize
- ready_for_review
jobs:
msrv:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: taiki-e/install-action@cargo-hack
- run: cargo hack check --rust-version --workspace --all-targets --ignore-private
+79
View File
@@ -0,0 +1,79 @@
# Copied with minimal adjustments, source:
# https://github.com/google/mdbook-i18n-helpers/blob/2168b9cea1f4f76b55426591a9bcc308a620194f/.github/workflows/coverage-report.yml
name: Upload code coverage
on:
# This workflow is triggered after every successful execution
# of `coverage` workflow.
workflow_run:
workflows: ["Code Coverage"]
types:
- completed
jobs:
coverage:
name: Upload coverage report
runs-on: ubuntu-latest
if: github.event.workflow_run.conclusion == 'success'
steps:
- name: 'Fetch coverage report from artifacts'
id: prepare_report
uses: actions/github-script@v7
with:
script: |
var fs = require('fs');
// List artifacts of the workflow run that triggered this workflow
var artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id,
});
let codecovReport = artifacts.data.artifacts.filter((artifact) => {
return artifact.name == "codecov_report";
});
if (codecovReport.length != 1) {
throw new Error("Unexpected number of {codecov_report} artifacts: " + codecovReport.length);
}
var download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: codecovReport[0].id,
archive_format: 'zip',
});
fs.writeFileSync('codecov_report.zip', Buffer.from(download.data));
- id: parse_previous_artifacts
run: |
unzip codecov_report.zip
echo "Detected PR is: $(<pr_number.txt)"
echo "Detected commit_sha is: $(<commit_sha.txt)"
# Make the params available as step output
echo "override_pr=$(<pr_number.txt)" >> "$GITHUB_OUTPUT"
echo "override_commit=$(<commit_sha.txt)" >> "$GITHUB_OUTPUT"
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ steps.parse_previous_artifacts.outputs.override_commit || '' }}
path: repo_root
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_UPLOAD_TOKEN }}
fail_ci_if_error: true
# Manual overrides for these parameters are needed because automatic detection
# in codecov-action does not work for non-`pull_request` workflows.
# In `main` branch push, these default to empty strings since we want to run
# the analysis on HEAD.
override_commit: ${{ steps.parse_previous_artifacts.outputs.override_commit || '' }}
override_pr: ${{ steps.parse_previous_artifacts.outputs.override_pr || '' }}
working-directory: ${{ github.workspace }}/repo_root
# Location where coverage report files are searched for
directory: ${{ github.workspace }}
+4 -4
View File
@@ -35,7 +35,7 @@ jobs:
os-name: 🐧
cachekey-id: linux
- os: macos-12
- os: macos-15
os-name: 🍏
cachekey-id: macos
@@ -43,7 +43,7 @@ jobs:
steps:
- name: Checkout repo
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Calculate cache key
id: cachekey
@@ -53,11 +53,11 @@ jobs:
echo "cachekey-${{ matrix.cachekey-id }}=xtask-${{ matrix.cachekey-id }}-${{ hashFiles('Cargo.toml', 'xtask/**') }}" >> $GITHUB_OUTPUT
- name: Check xtask cache
uses: actions/cache@v3
uses: actions/cache@v4
id: xtask-cache
with:
path: target/debug/xtask
# use the cache key calculated in the step above. Bit of an awkard
# use the cache key calculated in the step above. Bit of an awkward
# syntax
key: |
${{ steps.cachekey.outputs[format('cachekey-{0}', matrix.cachekey-id)] }}
+2
View File
@@ -7,6 +7,8 @@ emsdk-*
.build
.swiftpm
/Package.swift
# code coverage report
cobertura.xml
## User settings
xcuserdata/
Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

+9 -3
View File
@@ -21,13 +21,19 @@ WeeChat = "WeeChat"
sing = "sign"
singed = "signed"
singing = "signing"
ratatui = "ratatui"
# base64 false positives
Nd = "Nd"
Abl = "Abl"
Som = "Som"
Ba = "Ba"
Yur = "Yur" # as found in crates/matrix-sdk-indexeddb/src/crypto_store/migrations/mod.rs
TYE = "TYE" # as found in testing/matrix-sdk-test/src/test_json/keys_query_sets.rs
[files]
# Our json files contain a bunch of base64 encoded ed25519 keys which aren't
# automatically ignored, we ignore them here.
extend-exclude = [
# Our json files contain a bunch of base64 encoded ed25519 keys.
"*.json",
# We are using some fuzzy match patterns that can be understood as typos confusingly.
# Fuzzy match patterns that can be understood as typos confusingly.
"crates/matrix-sdk-ui/tests/integration/room_list_service.rs",
]
+119
View File
@@ -0,0 +1,119 @@
# Architecture
The SDK is split into multiple layers:
```
WASM (external crate matrix-rust-sdk-crypto-wasm)
/
/ uniffi
/ /
/ bindings (matrix-sdk-ffi)
crypto |
bindings |
| |
| UI (matrix-sdk-ui)
| \
| \
| main (matrix-sdk)
| / /
crypto /
\ /
store (matrix-sdk-base, + all the store impls)
|
common (matrix-sdk-common)
```
Where the store implementations are `matrix-sdk-sqlite` and `matrix-sdk-indexeddb` as well as
`MemoryStore` which is defined in `matrix-sdk-base`.
## `crates/matrix-sdk`
This is the main crate, and one that is expected to be used by most consumers. Notable data types
include:
- the `Client`, which can run room-independent requests: logging in/out, creating rooms, running
sync, etc.
- the `Room`, which represents a room and its state (notably via the observable `RoomInfo`), and
allows running queries that are room-specific, notably sending events.
## `crates/matrix-sdk-base`
A *sans I/O* crate to represent the base data types persisted in the SDK. No network or storage I/O
happens in this crate, although it defines traits (`StateStore` and `EventCacheStore`) representing
storage backends, as well as dummy in-memory implementations of these traits.
## `crates/matrix-sdk-common`
Common helpers used by most of the other crates; almost a leaf in the dependency tree of our own
crates (the only crate it's using is test helpers).
## `crates/matrix-sdk-crypto`
A *sans I/O* implementation of a state machine that handles end-to-end encryption for Matrix
clients. It defines a `CryptoStore` trait representing storage backends that will perform the
actual storage I/O later, as well as a dummy in-memory implementation of this trait.
## `crates/matrix-sdk-indexeddb`
Implementations of `EventCacheStore`, `StateStore` and `CryptoStore` for a
indexeddb backend (for use in Web browsers, via WebAssembly).
## `crates/matrix-sdk-qrcode`
Implementation of QR codes for interactive verifications, used in the crypto crate.
## `crates/matrix-sdk-sqlite`
Implementations of `EventCacheStore`, `StateStore` and `CryptoStore` for a
SQLite backend.
## `crates/matrix-sdk-store-encryption`
Low-level primitives for encrypting/decrypting/hashing values. Store implementations that
implement encryption at rest can use those primitives.
## `crates/matrix-sdk-ui`
Very high-level primitives implementing the best practices and cutting-edge Matrix tech:
- `EncryptionSyncService`: a specialized service running simplified sliding sync (MSC4186) for
everything related to crypto and E2EE for the current `Client`.
- `RoomListService`: a specialized service running simplified sliding sync (MSC4186) for
retrieving the list of current rooms, and exposing its entries.
- `SyncService`: a wrapper for the two previous services, coordinating their running and shutting
down.
- `Timeline`: a high-level view for a `Room`'s timeline of events, grouping related events
(aggregations) into single timeline items.
## `bindings/matrix-sdk-crypto-ffi/`
FFI bindings for the crypto crate, used in a Web browser context via WebAssembly. These use
`wasm-bindgen` to generate the bindings. These bindings are used in Element Web and the legacy
Element apps, as of 2024-11-07.
## `bindings/matrix-sdk-ffi/`
FFI bindings for important concepts in `matrix-sdk-ui` and `matrix-sdk`, generated with
[UniFFI](https://github.com/mozilla/uniffi-rs) and to be used from other languages like
Swift/Go/Kotlin. These bindings are used in the ElementX apps, as of 2024-11-07.
## `bindings/matrix-sdk-ffi-macros/`
Macros used in `bindings/matrix-sdk-ffi`.
## `testing/matrix-sdk-test/`
Common test helpers, used by all the other crates.
## `testing/matrix-sdk-test-macros/`
Implementation of the `#[async_test]` test macro.
## `testing/matrix-sdk-integration-testing/`
Fully-fledged integration tests that require spawning a Synapse instance to run. A docker-compose
setup is provided to ease running the tests, and it is compatible for running with Podman too.
# Inspiration
This document has been inspired by the reading of this [blog post](https://matklad.github.io/2021/02/06/ARCHITECTURE.md.html).
+196 -11
View File
@@ -29,16 +29,196 @@ integration tests that need a running synapse instance. These tests reside in
[README](./testing/matrix-sdk-integration-testing/README.md) to easily set up a
synapse for testing purposes.
## Pull requests
Ideally, a PR should have a *proper title*, with *atomic logical commits*, and
each commit should have a *good commit message*.
A *proper PR title* would be a one-liner summary of the changes in the PR,
following the same guidelines of a good commit message, including the
area/feature prefix. Something like `FFI: Allow logs files to be pruned.` would
be a good PR title.
(An additional bad example of a bad PR title would be `mynickname/branch name`,
that is, just the branch name.)
# Writing changelog entries
Our goal is to maintain clear, concise, and informative changelogs that
accurately document changes in the project. Changelog entries should be written
manually for each crate in the `/crates/$CRATE_NAME/Changelog.md` file.
Be sure to include a link to the pull request for additional context. A
well-written changelog entry should be understandable even to those who may not
be deeply familiar with the project. Provide enough context to ensure clarity
and ease of understanding.
A couple of examples of bad changelog entry would look like:
```markdown
- Fixed a panic.
```
```markdown
- Added the Bar function to Foo.
```
A good example of a changelog entry could look like the following:
```markdown
- Use the inviter's server name and the server name from the room alias as
fallback values for the via parameter when requesting the room summary from
the homeserver. This ensures requests succeed even when the room being
previewed is hosted on a federated server.
([#4357](https://github.com/matrix-org/matrix-rust-sdk/pull/4357))
```
For security-related changelog entries, please include the following additional
details alongside the pull request number:
* Impact: Clearly describe the issue's potential impact on users or systems.
* CVE Number: If available, include the CVE (Common Vulnerabilities and Exposures) identifier.
* GitHub Advisory Link: Provide a link to the corresponding GitHub security advisory for further context.
```markdown
- Use a constant-time Base64 encoder for secret key material to mitigate
side-channel attacks leaking secret key material ([#156](https://github.com/matrix-org/vodozemac/pull/156)) (Low, [CVE-2024-40640](https://www.cve.org/CVERecord?id=CVE-2024-40640), [GHSA-j8cm-g7r6-hfpq](https://github.com/matrix-org/vodozemac/security/advisories/GHSA-j8cm-g7r6-hfpq)).
```
## Commit message format
Commit messages should be formatted as Conventional Commits. In addition, some
git trailers are supported and have special meaning (see below).
### Conventional commits
Conventional Commits are structured as follows:
```
<type>(<scope>): <short summary>
```
The type of changes which will be included in changelogs is one of the following:
* `feat`: A new feature
* `fix`: A bug fix
* `doc`: Documentation changes
* `refactor`: Code refactoring
* `perf`: Performance improvements
* `ci`: Changes to CI configuration files and scripts
The scope is optional and can specify the area of the codebase affected (e.g.,
olm, cipher).
### Security fixes
Commits addressing security vulnerabilities must include specific trailers for
vulnerability metadata, which should also be reflected in the corresponding
changelog entry.
The metadata must be included in the following git-trailers:
* `Security-Impact`: The magnitude of harm that can be expected, i.e. low/moderate/high/critical.
* `CVE`: The CVE that was assigned to this issue.
* `GitHub-Advisory`: The GitHub advisory identifier.
Please include all of the fields that are available.
Example:
```
fix(crypto): Use a constant-time Base64 encoder for secret key material
This patch fixes a security issue around a side-channel vulnerability[1]
when decoding secret key material using Base64.
In some circumstances an attacker can obtain information about secret
secret key material via a controlled-channel and side-channel attack.
This patch avoids the side-channel by switching to the base64ct crate
for the encoding, and more importantly, the decoding of secret key
material.
Security-Impact: Low
CVE: CVE-2024-40640
GitHub-Advisory: GHSA-j8cm-g7r6-hfpq
```
## Review process
To streamline the review process and make it easier for maintainers to review
your contributions, follow these basic rules:
1. Do not force push after a review has started. This helps maintainers track
incremental changes without confusion and makes it easier to follow the
evolution of the code.
2. Do not mix moves and refactoring with functional changes. Keep these in
separate commits for clarity. This ensures that the purpose of each commit is
clear and easy to review.
3. Each commit must compile. If commits dont compile, git bisect becomes
unusable, which hampers the debugging process and makes it harder to identify
the source of issues.
4. Commits should only introduce test failures if they are proving that a bug
exists. New features should never introduce test failures. Test failures
should only be used to demonstrate existing bugs, not as part of adding new
functionality.
5. Keep PRs on topic and small. Large PRs are harder to review and more prone to
delays. Create small, focused commits that address a single topic. Use a
combination of [git add] -p or git checkout -p to split changes into logical
units. This makes your work easier to review and reduces the chance of
introducing unrelated changes.
[git add]: https://git-scm.com/docs/git-add#Documentation/git-add.txt---patch
[git checkout]: https://git-scm.com/docs/git-checkout#Documentation/git-checkout.txt---patch
### Addressing review comments using fixup commits
So you posted a PR and the maintainers aren't quite happy with it. Here are some
guidelines to make the maintainers life easier and increase the chances that
your PR will be reviewed swiftly.
1. Use [fixup] commits. When addressing reviewer feedback, you can create fixup
commits. These commits mark your changes as corrections of specific previous
commits in the PR.
Example:
```bash
git commit --fixup=<commit-hash>
```
This command creates a new commit that refers to an existing one, making it
easier to rebase and squash later while showing reviewers the history of fixes.
For extra points, link to the fixup commit in the thread where the change was
requested.
2. After all requested changes were addressed, feel free to re-request a review.
People might not notice that all changes were addressed.
3. Once the PR has been approved, rebase your PR to squash all the fixup
commits, the [autosquash] option can help with this.
```bash
git rebase main --interactive --autosquash
```
[fixup]: https://git-scm.com/docs/git-commit#Documentation/git-commit.txt---fixupamendrewordltcommitgt
[autosquash]: https://git-scm.com/docs/git-rebase#Documentation/git-rebase.txt---autosquash
## Sign off
In order to have a concrete record that your contribution is intentional
and you agree to license it under the same terms as the project's license, we've
adopted the same lightweight approach that the Linux Kernel
(https://www.kernel.org/doc/Documentation/SubmittingPatches), Docker
(https://github.com/docker/docker/blob/master/CONTRIBUTING.md), and many other
projects use: the DCO (Developer Certificate of Origin:
http://developercertificate.org/). This is a simple declaration that you wrote
the contribution or otherwise have the right to contribute it to Matrix:
adopted the same lightweight approach that the [Linux Kernel](https://www.kernel.org/doc/Documentation/SubmittingPatches),
[Docker](https://github.com/docker/docker/blob/master/CONTRIBUTING.md), and many other
projects use: the DCO ([Developer Certificate of Origin](http://developercertificate.org/)).
This is a simple declaration that you wrote the contribution or otherwise have the right
to contribute it to Matrix:
```
Developer Certificate of Origin
@@ -85,11 +265,6 @@ include the line in your commit or pull request comment:
Signed-off-by: Your Name <your@email.example.org>
```
We accept contributions under a legally identifiable name, such as your name on
government documentation or common-law names (names claimed by legitimate usage
or repute). Unfortunately, we cannot accept anonymous contributions at this
time.
Git allows you to add this signoff automatically when using the `-s` flag to
`git commit`, which uses the name and email set in your `user.name` and
`user.email` git configs.
@@ -100,3 +275,13 @@ on Git 2.17+ you can mass signoff using rebase:
```
git rebase --signoff origin/main
```
## Tips for working on the `matrix-rust-sdk` with specific IDEs
* [RustRover](https://www.jetbrains.com/rust/) will attempt to sync the project
with all features enabled, causing an error in `matrix-sdk` ("only one of the
features 'native-tls' or 'rustls-tls' can be enabled"). To work around this,
open `crates/matrix-sdk/Cargo.toml` in RustRover and uncheck one of the
`native-tls` or `rustls-tls` feature definitions:
![Screenshot of RustRover](.img/rustrover-disable-feature.png)
Generated
+1920 -1756
View File
File diff suppressed because it is too large Load Diff
+112 -34
View File
@@ -6,64 +6,108 @@ members = [
"crates/*",
"testing/*",
"examples/*",
"labs/*",
"uniffi-bindgen",
"xtask",
]
exclude = [
"testing/data",
]
# xtask, testing and the bindings should only be built when invoked explicitly.
default-members = ["benchmarks", "crates/*"]
default-members = ["benchmarks", "crates/*", "labs/*"]
resolver = "2"
[workspace.package]
rust-version = "1.70"
rust-version = "1.82"
[workspace.dependencies]
anyhow = "1.0.68"
assert-json-diff = "2"
anyhow = "1.0.93"
aquamarine = "0.6.0"
assert-json-diff = "2.0.2"
assert_matches = "1.5.0"
assert_matches2 = "0.1.1"
assert_matches2 = "0.1.2"
async-rx = "0.1.3"
async-stream = "0.3.3"
async-trait = "0.1.60"
async-stream = "0.3.5"
async-trait = "0.1.83"
as_variant = "1.2.0"
base64 = "0.21.0"
byteorder = "1.4.3"
eyeball = { version = "0.8.7", features = ["tracing"] }
eyeball-im = { version = "0.4.1", features = ["tracing"] }
eyeball-im-util = "0.5.1"
futures-core = "0.3.28"
base64 = "0.22.1"
byteorder = "1.5.0"
chrono = "0.4.38"
eyeball = { version = "0.8.8", features = ["tracing"] }
eyeball-im = { version = "0.5.1", features = ["tracing"] }
eyeball-im-util = "0.7.0"
futures-core = "0.3.31"
futures-executor = "0.3.21"
futures-util = { version = "0.3.26", default-features = false, features = ["alloc"] }
http = "0.2.6"
itertools = "0.12.0"
ruma = { version = "0.9.3", features = ["client-api-c", "compat-upload-signatures", "compat-user-id", "compat-arbitrary-length-ids", "unstable-msc3401"] }
ruma-common = "0.12.0"
once_cell = "1.16.0"
futures-util = "0.3.31"
gloo-timers = "0.3.0"
growable-bloom-filter = "2.1.1"
hkdf = "0.12.4"
hmac = "0.12.1"
http = "1.1.0"
imbl = "3.0.0"
indexmap = "2.6.0"
itertools = "0.13.0"
js-sys = "0.3.69"
mime = "0.3.17"
once_cell = "1.20.2"
pbkdf2 = { version = "0.12.2" }
pin-project-lite = "0.2.15"
proptest = { version = "1.5.0", default-features = false, features = ["std"] }
rand = "0.8.5"
reqwest = { version = "0.12.4", default-features = false }
rmp-serde = "1.3.0"
ruma = { version = "0.12.0", features = [
"client-api-c",
"compat-upload-signatures",
"compat-user-id",
"compat-arbitrary-length-ids",
"compat-tag-info",
"compat-encrypted-stickers",
"unstable-msc3401",
"unstable-msc3266",
"unstable-msc3488",
"unstable-msc3489",
"unstable-msc4075",
"unstable-msc4140",
"unstable-msc4171",
] }
ruma-common = "0.15.0"
serde = "1.0.151"
serde_html_form = "0.2.0"
serde_json = "1.0.91"
sha2 = "0.10.8"
similar-asserts = "1.6.0"
stream_assert = "0.1.1"
thiserror = "1.0.38"
tokio = { version = "1.30.0", default-features = false, features = ["sync"] }
tempfile = "3.9.0"
thiserror = "2.0.3"
tokio = { version = "1.41.1", default-features = false, features = ["sync"] }
tokio-stream = "0.1.14"
tracing = { version = "0.1.40", default-features = false, features = ["std"] }
tracing-core = "0.1.32"
uniffi = { version = "0.25.3", git = "https://github.com/mozilla/uniffi-rs", rev = "0d58c94cbd2ef63554f3388d03d55984be76bb1f" }
uniffi_bindgen = { version = "0.25.3", git = "https://github.com/mozilla/uniffi-rs", rev = "0d58c94cbd2ef63554f3388d03d55984be76bb1f" }
vodozemac = { version = "0.7.0" }
zeroize = "1.6.0"
tracing-subscriber = "0.3.18"
unicode-normalization = "0.1.24"
uniffi = { version = "0.28.0" }
uniffi_bindgen = { version = "0.28.0" }
url = "2.5.4"
uuid = "1.11.0"
vodozemac = { version = "0.8.1", features = ["insecure-pk-encryption"] }
wasm-bindgen = "0.2.84"
wasm-bindgen-test = "0.3.33"
web-sys = "0.3.69"
wiremock = "0.6.2"
zeroize = "1.8.1"
matrix-sdk = { path = "crates/matrix-sdk", version = "0.7.0", default-features = false }
matrix-sdk-base = { path = "crates/matrix-sdk-base", version = "0.7.0" }
matrix-sdk-common = { path = "crates/matrix-sdk-common", version = "0.7.0" }
matrix-sdk-crypto = { path = "crates/matrix-sdk-crypto", version = "0.7.0" }
matrix-sdk-indexeddb = { path = "crates/matrix-sdk-indexeddb", version = "0.7.0", default-features = false }
matrix-sdk-qrcode = { path = "crates/matrix-sdk-qrcode", version = "0.7.0" }
matrix-sdk-sqlite = { path = "crates/matrix-sdk-sqlite", version = "0.7.0", default-features = false }
matrix-sdk-store-encryption = { path = "crates/matrix-sdk-store-encryption", version = "0.7.0" }
matrix-sdk = { path = "crates/matrix-sdk", version = "0.9.0", default-features = false }
matrix-sdk-base = { path = "crates/matrix-sdk-base", version = "0.9.0" }
matrix-sdk-common = { path = "crates/matrix-sdk-common", version = "0.9.0" }
matrix-sdk-crypto = { path = "crates/matrix-sdk-crypto", version = "0.9.0" }
matrix-sdk-ffi-macros = { path = "bindings/matrix-sdk-ffi-macros", version = "0.7.0" }
matrix-sdk-indexeddb = { path = "crates/matrix-sdk-indexeddb", version = "0.9.0", default-features = false }
matrix-sdk-qrcode = { path = "crates/matrix-sdk-qrcode", version = "0.9.0" }
matrix-sdk-sqlite = { path = "crates/matrix-sdk-sqlite", version = "0.9.0", default-features = false }
matrix-sdk-store-encryption = { path = "crates/matrix-sdk-store-encryption", version = "0.9.0" }
matrix-sdk-test = { path = "testing/matrix-sdk-test", version = "0.7.0" }
matrix-sdk-ui = { path = "crates/matrix-sdk-ui", version = "0.7.0", default-features = false }
matrix-sdk-ui = { path = "crates/matrix-sdk-ui", version = "0.9.0", default-features = false }
# Default release profile, select with `--release`
[profile.release]
@@ -95,3 +139,37 @@ opt-level = 3
[patch.crates-io]
async-compat = { git = "https://github.com/jplatte/async-compat", rev = "16dc8597ec09a6102d58d4e7b67714a35dd0ecb8" }
const_panic = { git = "https://github.com/jplatte/const_panic", rev = "9024a4cb3eac45c1d2d980f17aaee287b17be498" }
# Needed to fix rotation log issue on Android (https://github.com/tokio-rs/tracing/issues/2937)
tracing = { git = "https://github.com/element-hq/tracing.git", rev = "ca9431f74d37c9d3b5e6a9f35b2c706711dab7dd" }
tracing-core = { git = "https://github.com/element-hq/tracing.git", rev = "ca9431f74d37c9d3b5e6a9f35b2c706711dab7dd" }
tracing-subscriber = { git = "https://github.com/element-hq/tracing.git", rev = "ca9431f74d37c9d3b5e6a9f35b2c706711dab7dd" }
tracing-appender = { git = "https://github.com/element-hq/tracing.git", rev = "ca9431f74d37c9d3b5e6a9f35b2c706711dab7dd" }
paranoid-android = { git = "https://github.com/element-hq/paranoid-android.git", rev = "69388ac5b4afeed7be4401c70ce17f6d9a2cf19b" }
[workspace.lints.rust]
rust_2018_idioms = "warn"
semicolon_in_expressions_from_macros = "warn"
unexpected_cfgs = { level = "warn", check-cfg = [
'cfg(tarpaulin_include)', # Used by tarpaulin (code coverage)
'cfg(ruma_unstable_exhaustive_types)', # Used by Ruma's EventContent derive macro
] }
unused_extern_crates = "warn"
unused_import_braces = "warn"
unused_qualifications = "warn"
trivial_casts = "warn"
trivial_numeric_casts = "warn"
[workspace.lints.clippy]
assigning_clones = "allow"
box_default = "allow"
cloned_instead_of_copied = "warn"
dbg_macro = "warn"
inefficient_to_string = "warn"
macro_use_imports = "warn"
mut_mut = "warn"
needless_borrow = "warn"
nonstandard_macro_braces = "warn"
str_to_string = "warn"
todo = "warn"
unused_async = "warn"
redundant_clone = "warn"
-4
View File
@@ -24,10 +24,6 @@ The rust-sdk consists of multiple crates that can be picked at your convenience:
- **matrix-sdk-crypto** - No (network) IO encryption state machine that can be
used to add Matrix E2EE support to your client or client library.
## Minimum Supported Rust Version (MSRV)
These crates are built with the Rust language version 2021 and require a minimum compiler version of `1.70`.
## Status
The library is in an alpha state, things that are implemented generally work but
+47
View File
@@ -0,0 +1,47 @@
# Releasing and publishing the SDK
While the release process can be handled manually, `cargo-release` has been
configured to make it more convenient.
By default, [`cargo-release`](https://github.com/crate-ci/cargo-release) assumes
that no pull request is required to cut a release. However, since the SDK
repo is set up so that each push requires a pull request, we need to slightly
deviate from the default workflow. A `cargo-xtask` has been created to make the
process as smooth as possible.
The procedure is as follows:
1. Switch to a release branch:
```bash
git switch -c release-x.y.z
  ```
2. Prepare the release. This will update the `README.md`, set the versions in
the `CHANGELOG.md` file, and bump the version in the `Cargo.toml` file.
```bash
cargo xtask release prepare --execute minor|patch|rc
```
3. Double-check and edit the `CHANGELOG.md` and `README.md` if necessary. Once you are
satisfied, push the branch and open a PR.
```bash
git push --set-upstream origin/release-x.y.z
```
4. Pass the review and merge the branch as you would with any other branch.
5. Create tags for your new release, publish the release on crates.io and push
the tags:
```bash
# Switch to main first.
git switch main
# Pull in the now-merged release commit(s).
git pull
# Create tags, publish the release on crates.io, and push the tags.
cargo xtask release publish --execute
```
For more information on cargo-release: https://github.com/crate-ci/cargo-release
+13 -3
View File
@@ -13,14 +13,17 @@ matrix-sdk-base = { workspace = true }
matrix-sdk-crypto = { workspace = true }
matrix-sdk-sqlite = { workspace = true, features = ["crypto-store"] }
matrix-sdk-test = { workspace = true }
matrix-sdk = { workspace = true }
matrix-sdk-ui = { workspace = true }
matrix-sdk = { workspace = true, features = ["native-tls", "e2e-encryption", "sqlite"] }
ruma = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
tempfile = "3.3.0"
tokio = { version = "1.24.2", default-features = false, features = ["rt-multi-thread"] }
tokio = { workspace = true, default-features = false, features = ["rt-multi-thread"] }
wiremock = { workspace = true }
[target.'cfg(target_os = "linux")'.dependencies]
pprof = { version = "0.13.0", features = ["flamegraph", "criterion"] }
pprof = { version = "0.14.0", features = ["flamegraph", "criterion"] }
[[bench]]
name = "crypto_bench"
@@ -29,3 +32,10 @@ harness = false
[[bench]]
name = "store_bench"
harness = false
[[bench]]
name = "room_bench"
harness = false
[package.metadata.release]
release = false
+19 -25
View File
@@ -3,14 +3,11 @@ use std::{ops::Deref, sync::Arc};
use criterion::{criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion, Throughput};
use matrix_sdk_crypto::{EncryptionSettings, OlmMachine};
use matrix_sdk_sqlite::SqliteCryptoStore;
use matrix_sdk_test::response_from_file;
use matrix_sdk_test::ruma_response_from_json;
use ruma::{
api::{
client::{
keys::{claim_keys, get_keys},
to_device::send_event_to_device::v3::Response as ToDeviceResponse,
},
IncomingResponse,
api::client::{
keys::{claim_keys, get_keys},
to_device::send_event_to_device::v3::Response as ToDeviceResponse,
},
device_id, room_id, user_id, DeviceId, OwnedUserId, TransactionId, UserId,
};
@@ -28,25 +25,19 @@ fn alice_device_id() -> &'static DeviceId {
fn keys_query_response() -> get_keys::v3::Response {
let data = include_bytes!("crypto_bench/keys_query.json");
let data: Value = serde_json::from_slice(data).unwrap();
let data = response_from_file(&data);
get_keys::v3::Response::try_from_http_response(data)
.expect("Can't parse the `/keys/upload` response")
ruma_response_from_json(&data)
}
fn keys_claim_response() -> claim_keys::v3::Response {
let data = include_bytes!("crypto_bench/keys_claim.json");
let data: Value = serde_json::from_slice(data).unwrap();
let data = response_from_file(&data);
claim_keys::v3::Response::try_from_http_response(data)
.expect("Can't parse the `/keys/upload` response")
ruma_response_from_json(&data)
}
fn huge_keys_query_response() -> get_keys::v3::Response {
let data = include_bytes!("crypto_bench/keys_query_2000_members.json");
let data: Value = serde_json::from_slice(data).unwrap();
let data = response_from_file(&data);
get_keys::v3::Response::try_from_http_response(data)
.expect("Can't parse the `/keys/query` response")
ruma_response_from_json(&data)
}
pub fn keys_query(c: &mut Criterion) {
@@ -76,8 +67,9 @@ pub fn keys_query(c: &mut Criterion) {
let dir = tempfile::tempdir().unwrap();
let store = Arc::new(runtime.block_on(SqliteCryptoStore::open(dir.path(), None)).unwrap());
let machine =
runtime.block_on(OlmMachine::with_store(alice_id(), alice_device_id(), store)).unwrap();
let machine = runtime
.block_on(OlmMachine::with_store(alice_id(), alice_device_id(), store, None))
.unwrap();
group.bench_with_input(BenchmarkId::new("sqlite store", &name), &response, |b, response| {
b.to_async(&runtime)
@@ -134,7 +126,7 @@ pub fn keys_claiming(c: &mut Criterion) {
Arc::new(runtime.block_on(SqliteCryptoStore::open(dir.path(), None)).unwrap());
let machine = runtime
.block_on(OlmMachine::with_store(alice_id(), alice_device_id(), store))
.block_on(OlmMachine::with_store(alice_id(), alice_device_id(), store, None))
.unwrap();
runtime
.block_on(machine.mark_request_as_sent(&txn_id, &keys_query_response))
@@ -194,7 +186,7 @@ pub fn room_key_sharing(c: &mut Criterion) {
machine.mark_request_as_sent(&request.txn_id, &to_device_response).await.unwrap();
}
machine.invalidate_group_session(room_id).await.unwrap();
machine.discard_room_key(room_id).await.unwrap();
})
});
@@ -203,8 +195,9 @@ pub fn room_key_sharing(c: &mut Criterion) {
let dir = tempfile::tempdir().unwrap();
let store = Arc::new(runtime.block_on(SqliteCryptoStore::open(dir.path(), None)).unwrap());
let machine =
runtime.block_on(OlmMachine::with_store(alice_id(), alice_device_id(), store)).unwrap();
let machine = runtime
.block_on(OlmMachine::with_store(alice_id(), alice_device_id(), store, None))
.unwrap();
runtime.block_on(machine.mark_request_as_sent(&txn_id, &keys_query_response)).unwrap();
runtime.block_on(machine.mark_request_as_sent(&txn_id, &response)).unwrap();
@@ -225,7 +218,7 @@ pub fn room_key_sharing(c: &mut Criterion) {
machine.mark_request_as_sent(&request.txn_id, &to_device_response).await.unwrap();
}
machine.invalidate_group_session(room_id).await.unwrap();
machine.discard_room_key(room_id).await.unwrap();
})
});
@@ -267,8 +260,9 @@ pub fn devices_missing_sessions_collecting(c: &mut Criterion) {
let dir = tempfile::tempdir().unwrap();
let store = Arc::new(runtime.block_on(SqliteCryptoStore::open(dir.path(), None)).unwrap());
let machine =
runtime.block_on(OlmMachine::with_store(alice_id(), alice_device_id(), store)).unwrap();
let machine = runtime
.block_on(OlmMachine::with_store(alice_id(), alice_device_id(), store, None))
.unwrap();
runtime.block_on(machine.mark_request_as_sent(&txn_id, &response)).unwrap();
+264
View File
@@ -0,0 +1,264 @@
use std::{sync::Arc, time::Duration};
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
use matrix_sdk::{
config::SyncSettings, test_utils::logged_in_client_with_server, utils::IntoRawStateEventContent,
};
use matrix_sdk_base::{
store::StoreConfig, BaseClient, RoomInfo, RoomState, SessionMeta, StateChanges, StateStore,
};
use matrix_sdk_sqlite::SqliteStateStore;
use matrix_sdk_test::{
event_factory::EventFactory, EventBuilder, JoinedRoomBuilder, StateTestEvent,
SyncResponseBuilder,
};
use matrix_sdk_ui::{timeline::TimelineFocus, Timeline};
use ruma::{
api::client::membership::get_member_events,
device_id,
events::room::member::{RoomMemberEvent, RoomMemberEventContent},
owned_room_id, owned_user_id,
serde::Raw,
user_id, EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedUserId,
};
use serde::Serialize;
use serde_json::json;
use tokio::runtime::Builder;
use wiremock::{
matchers::{header, method, path, path_regex, query_param, query_param_is_missing},
Mock, MockServer, Request, ResponseTemplate,
};
pub fn receive_all_members_benchmark(c: &mut Criterion) {
const MEMBERS_IN_ROOM: usize = 100000;
let runtime = Builder::new_multi_thread().build().expect("Can't create runtime");
let room_id = owned_room_id!("!room:example.com");
let ev_builder = EventBuilder::new();
let mut member_events: Vec<Raw<RoomMemberEvent>> = Vec::with_capacity(MEMBERS_IN_ROOM);
let member_content_json = json!({
"avatar_url": "mxc://example.org/SEsfnsuifSDFSSEF",
"displayname": "Alice Margatroid",
"membership": "join",
"reason": "Looking for support",
});
let member_content: Raw<RoomMemberEventContent> =
member_content_json.into_raw_state_event_content().cast();
for i in 0..MEMBERS_IN_ROOM {
let user_id = OwnedUserId::try_from(format!("@user_{}:matrix.org", i)).unwrap();
let state_key = user_id.to_string();
let event: Raw<RoomMemberEvent> = ev_builder
.make_state_event(
&user_id,
&room_id,
&state_key,
member_content.deserialize().unwrap(),
None,
)
.cast();
member_events.push(event);
}
// Create a fake list of changes, and a session to recover from.
let mut changes = StateChanges::default();
changes.add_room(RoomInfo::new(&room_id, RoomState::Joined));
for member_event in member_events.iter() {
let event = member_event.clone().cast();
changes.add_state_event(&room_id, event.deserialize().unwrap(), event);
}
// Sqlite
let sqlite_dir = tempfile::tempdir().unwrap();
let sqlite_store = runtime.block_on(SqliteStateStore::open(sqlite_dir.path(), None)).unwrap();
runtime
.block_on(sqlite_store.save_changes(&changes))
.expect("initial filling of sqlite failed");
let base_client = BaseClient::with_store_config(
StoreConfig::new("cross-process-store-locks-holder-name".to_owned())
.state_store(sqlite_store),
);
runtime
.block_on(base_client.set_session_meta(
SessionMeta {
user_id: user_id!("@somebody:example.com").to_owned(),
device_id: device_id!("DEVICE_ID").to_owned(),
},
None,
))
.expect("Could not set session meta");
base_client.get_or_create_room(&room_id, RoomState::Joined);
let request = get_member_events::v3::Request::new(room_id.clone());
let response = get_member_events::v3::Response::new(member_events);
let count = MEMBERS_IN_ROOM;
let name = format!("{count} members");
let mut group = c.benchmark_group("Test");
group.throughput(Throughput::Elements(count as u64));
group.sample_size(50);
group.bench_function(BenchmarkId::new("receive_members", name), |b| {
b.to_async(&runtime).iter(|| async {
base_client.receive_all_members(&room_id, &request, &response).await.unwrap();
});
});
{
let _guard = runtime.enter();
drop(base_client);
}
group.finish();
}
pub fn load_pinned_events_benchmark(c: &mut Criterion) {
const PINNED_EVENTS_COUNT: usize = 100;
let runtime = Builder::new_multi_thread().enable_all().build().expect("Can't create runtime");
let room_id = owned_room_id!("!room:example.com");
let sender_id = owned_user_id!("@sender:example.com");
let f = EventFactory::new().room(&room_id).sender(&sender_id);
let (client, server) = runtime.block_on(logged_in_client_with_server());
let mut sync_response_builder = SyncResponseBuilder::new();
let mut joined_room_builder =
JoinedRoomBuilder::new(&room_id).add_state_event(StateTestEvent::Encryption);
let pinned_event_ids: Vec<OwnedEventId> = (0..PINNED_EVENTS_COUNT)
.map(|i| EventId::parse(format!("${i}")).expect("Invalid event id"))
.collect();
joined_room_builder = joined_room_builder.add_state_event(StateTestEvent::Custom(json!(
{
"content": {
"pinned": pinned_event_ids
},
"event_id": "$15139375513VdeRF:localhost",
"origin_server_ts": 151393755,
"sender": "@example:localhost",
"state_key": "",
"type": "m.room.pinned_events",
"unsigned": {
"age": 703422
}
}
)));
let response_json =
sync_response_builder.add_joined_room(joined_room_builder).build_json_sync_response();
runtime.block_on(mock_sync(&server, response_json, None));
let sync_settings = SyncSettings::default();
runtime.block_on(client.sync_once(sync_settings)).expect("Could not sync");
runtime.block_on(server.reset());
runtime.block_on(
Mock::given(method("GET"))
.and(path_regex(r"/_matrix/client/r0/rooms/.*/event/.*"))
.respond_with(move |r: &Request| {
let segments: Vec<&str> = r.url.path_segments().expect("Invalid path").collect();
let event_id_str = segments[6];
let event_id = EventId::parse(event_id_str).expect("Invalid event id in response");
let event = f
.text_msg(format!("Message {event_id_str}"))
.event_id(&event_id)
.server_ts(MilliSecondsSinceUnixEpoch::now())
.into_raw_sync();
ResponseTemplate::new(200)
.set_delay(Duration::from_millis(50))
.set_body_json(event.json())
})
.mount(&server),
);
let room = client.get_room(&room_id).expect("Room not found");
let pinned_event_ids = room.pinned_event_ids().unwrap_or_default();
assert!(!pinned_event_ids.is_empty());
assert_eq!(pinned_event_ids.len(), PINNED_EVENTS_COUNT);
let count = PINNED_EVENTS_COUNT;
let name = format!("{count} pinned events");
let mut group = c.benchmark_group("Test");
group.throughput(Throughput::Elements(count as u64));
group.sample_size(10);
let client = Arc::new(client);
{
let client = client.clone();
runtime.spawn_blocking(move || {
client.event_cache().subscribe().unwrap();
});
}
group.bench_function(BenchmarkId::new("load_pinned_events", name), |b| {
b.to_async(&runtime).iter(|| async {
let pinned_event_ids = room.pinned_event_ids().unwrap_or_default();
assert!(!pinned_event_ids.is_empty());
assert_eq!(pinned_event_ids.len(), PINNED_EVENTS_COUNT);
// Reset cache so it always loads the events from the mocked endpoint
client.event_cache().empty_immutable_cache().await;
let timeline = Timeline::builder(&room)
.with_focus(TimelineFocus::PinnedEvents {
max_events_to_load: 100,
max_concurrent_requests: 10,
})
.build()
.await
.expect("Could not create timeline");
let (items, _) = timeline.subscribe().await;
assert_eq!(items.len(), PINNED_EVENTS_COUNT + 1);
timeline.clear().await;
});
});
{
let _guard = runtime.enter();
runtime.block_on(server.reset());
drop(server);
}
group.finish();
}
async fn mock_sync(server: &MockServer, response_body: impl Serialize, since: Option<String>) {
let mut mock_builder = Mock::given(method("GET"))
.and(path("/_matrix/client/r0/sync"))
.and(header("authorization", "Bearer 1234"));
if let Some(since) = since {
mock_builder = mock_builder.and(query_param("since", since));
} else {
mock_builder = mock_builder.and(query_param_is_missing("since"));
}
mock_builder
.respond_with(ResponseTemplate::new(200).set_body_json(response_body))
.mount(server)
.await;
}
fn criterion() -> Criterion {
#[cfg(target_os = "linux")]
let criterion = Criterion::default().with_profiler(pprof::criterion::PProfProfiler::new(
100,
pprof::criterion::Output::Flamegraph(None),
));
#[cfg(not(target_os = "linux"))]
let criterion = Criterion::default();
criterion
}
criterion_group! {
name = room;
config = criterion();
targets = receive_all_members_benchmark, load_pinned_events_benchmark,
}
criterion_main!(room);
+8 -2
View File
@@ -69,7 +69,10 @@ pub fn restore_session(c: &mut Criterion) {
b.to_async(&runtime).iter(|| async {
let client = Client::builder()
.homeserver_url("https://matrix.example.com")
.store_config(StoreConfig::new().state_store(store.clone()))
.store_config(
StoreConfig::new("cross-process-store-locks-holder-name".to_owned())
.state_store(store.clone()),
)
.build()
.await
.expect("Can't build client");
@@ -96,7 +99,10 @@ pub fn restore_session(c: &mut Criterion) {
b.to_async(&runtime).iter(|| async {
let client = Client::builder()
.homeserver_url("https://matrix.example.com")
.store_config(StoreConfig::new().state_store(store.clone()))
.store_config(
StoreConfig::new("cross-process-store-locks-holder-name".to_owned())
.state_store(store.clone()),
)
.build()
.await
.expect("Can't build client");
+2 -2
View File
@@ -11,7 +11,7 @@ maintained by the owners of the Matrix Rust SDK project.
There are also external bindings in other repositories:
* [`matrix-sdk-crypto-js`], JavaScript bindings of the
* [`matrix-sdk-crypto-wasm`], JavaScript / WebAssembly bindings of the
[`matrix-sdk-crypto`] crate,
* [`matrix-sdk-crypto-nodejs`], Node.js bindings of the
[`matrix-sdk-crypto`] crate
@@ -22,7 +22,7 @@ There are also external bindings in other repositories:
[`matrix-sdk-ffi`]: ./matrix-sdk-ffi
[`matrix-sdk`]: ../crates/matrix-sdk
[`matrix-sdk-crypto-js`]: https://github.com/matrix-org/matrix-rust-sdk-crypto-web
[`matrix-sdk-crypto-wasm`]: https://github.com/matrix-org/matrix-rust-sdk-crypto-wasm
[`matrix-sdk-crypto-nodejs`]: https://github.com/matrix-org/matrix-rust-sdk-crypto-nodejs
## Contributing
+1
View File
@@ -13,6 +13,7 @@ let package = Package(
],
products: [
.library(name: "MatrixRustSDK",
type: .dynamic,
targets: ["MatrixRustSDK"]),
],
targets: [
+4 -4
View File
@@ -3,14 +3,14 @@
Pod::Spec.new do |s|
s.name = "MatrixSDKCrypto"
s.version = "0.0.1"
s.version = "0.4.1"
s.summary = "Uniffi based bindings for the Rust SDK crypto crate."
s.homepage = "https://github.com/matrix-org/matrix-rust-sdk"
s.license = { :type => "Apache License, Version 2.0", :file => "LICENSE" }
s.author = { "matrix.org" => "support@matrix.org" }
s.ios.deployment_target = "11.0"
s.osx.deployment_target = "10.10"
s.ios.deployment_target = "13.0"
s.osx.deployment_target = "10.15"
s.swift_versions = ['5.1', '5.2']
+4 -4
View File
@@ -1,16 +1,16 @@
Pod::Spec.new do |s|
s.name = "MatrixSDKCrypto"
s.version = "0.0.1" # Version is only incremented manually and locally before pushing to CocoaPods
s.version = "0.4.1" # Version is only incremented manually and locally before pushing to CocoaPods
s.summary = "Uniffi based bindings for the Rust SDK crypto crate."
s.homepage = "https://github.com/matrix-org/matrix-rust-sdk"
s.license = { :type => "Apache License, Version 2.0", :file => "LICENSE" }
s.author = { "matrix.org" => "support@matrix.org" }
s.ios.deployment_target = "11.0"
s.osx.deployment_target = "10.10"
s.ios.deployment_target = "13.0"
s.osx.deployment_target = "10.15"
s.swift_versions = ['5.0']
s.swift_versions = ['5.1', '5.2']
s.source = { :http => "https://github.com/matrix-org/matrix-rust-sdk/releases/download/matrix-sdk-crypto-ffi-#{s.version}/MatrixSDKCryptoFFI.zip" }
s.vendored_frameworks = "MatrixSDKCryptoFFI.xcframework"
@@ -2,9 +2,9 @@ import XCTest
@testable import MatrixRustSDK
final class ClientTests: XCTestCase {
func testBuildingWithHomeserverURL() {
func testBuildingWithHomeserverURL() async {
do {
_ = try ClientBuilder()
_ = try await ClientBuilder()
.homeserverUrl(url: "https://localhost:8008")
.build()
} catch {
@@ -12,9 +12,9 @@ final class ClientTests: XCTestCase {
}
}
func testBuildingWithHomeserverURLAndUserAgent() {
func testBuildingWithHomeserverURLAndUserAgent() async {
do {
_ = try ClientBuilder()
_ = try await ClientBuilder()
.homeserverUrl(url: "https://localhost:8008")
.userAgent(userAgent: "golden-eye/007")
.build()
@@ -23,24 +23,14 @@ final class ClientTests: XCTestCase {
}
}
func testBuildingWithUsername() {
func testBuildingWithInvalidUsername() async {
do {
_ = try ClientBuilder()
.username(username: "@test:matrix.org")
.build()
} catch {
XCTFail("The client should build successfully when given a username.")
}
}
func testBuildingWithInvalidUsername() {
do {
_ = try ClientBuilder()
_ = try await ClientBuilder()
.username(username: "@test:invalid")
.build()
XCTFail("The client should not build when given an invalid username.")
} catch ClientError.Generic(let message) {
} catch ClientBuildError.ServerUnreachable(let message) {
XCTAssertTrue(message.contains(".well-known"), "The client should fail to do the well-known lookup.")
} catch {
XCTFail("Not expecting any other kind of exception")
+72 -39
View File
@@ -1,6 +1,22 @@
#!/usr/bin/env bash
set -eEu
helpFunction() {
echo ""
echo "Usage: $0 -only_ios"
echo -e "\t-i Option to build only for iOS. Default will build for all targets."
exit 1
}
only_ios='false'
while getopts ':i' 'opt'; do
case ${opt} in
'i') only_ios='true' ;;
?) helpFunction ;;
esac
done
cd "$(dirname "$0")"
# Path to the repo root
@@ -22,52 +38,63 @@ TARGET_CRATE=matrix-sdk-crypto-ffi
# Required by olm-sys crate
export IOS_SDK_PATH=`xcrun --show-sdk-path --sdk iphoneos`
# iOS
echo -e "Building for iOS [1/5]"
cargo build -p ${TARGET_CRATE} ${REL_FLAG} --target "aarch64-apple-ios"
if ${only_ios}; then
# iOS
echo -e "Building only for iOS"
cargo build -p ${TARGET_CRATE} ${REL_FLAG} --target "aarch64-apple-ios"
else
# iOS
echo -e "Building for iOS [1/5]"
cargo build -p ${TARGET_CRATE} ${REL_FLAG} --target "aarch64-apple-ios"
# MacOS
echo -e "\nBuilding for macOS (Apple Silicon) [2/5]"
cargo build -p ${TARGET_CRATE} ${REL_FLAG} --target "aarch64-apple-darwin"
echo -e "\nBuilding for macOS (Intel) [3/5]"
cargo build -p ${TARGET_CRATE} ${REL_FLAG} --target "x86_64-apple-darwin"
# MacOS
echo -e "\nBuilding for macOS (Apple Silicon) [2/5]"
cargo build -p ${TARGET_CRATE} ${REL_FLAG} --target "aarch64-apple-darwin"
echo -e "\nBuilding for macOS (Intel) [3/5]"
cargo build -p ${TARGET_CRATE} ${REL_FLAG} --target "x86_64-apple-darwin"
# iOS Simulator
echo -e "\nBuilding for iOS Simulator (Apple Silicon) [4/5]"
cargo build -p ${TARGET_CRATE} ${REL_FLAG} --target "aarch64-apple-ios-sim"
echo -e "\nBuilding for iOS Simulator (Intel) [5/5]"
cargo build -p ${TARGET_CRATE} ${REL_FLAG} --target "x86_64-apple-ios"
# iOS Simulator
echo -e "\nBuilding for iOS Simulator (Apple Silicon) [4/5]"
cargo build -p ${TARGET_CRATE} ${REL_FLAG} --target "aarch64-apple-ios-sim"
echo -e "\nBuilding for iOS Simulator (Intel) [5/5]"
cargo build -p ${TARGET_CRATE} ${REL_FLAG} --target "x86_64-apple-ios"
fi
echo -e "\nCreating XCFramework"
# Lipo together the libraries for the same platform
# MacOS
lipo -create \
"${TARGET_DIR}/x86_64-apple-darwin/${REL_TYPE_DIR}/libmatrix_sdk_crypto_ffi.a" \
"${TARGET_DIR}/aarch64-apple-darwin/${REL_TYPE_DIR}/libmatrix_sdk_crypto_ffi.a" \
-output "${GENERATED_DIR}/macos/libmatrix_sdk_crypto_ffi.a"
if ! ${only_ios}; then
echo "Lipo together the libraries for the same platform"
# MacOS
lipo -create \
"${TARGET_DIR}/x86_64-apple-darwin/${REL_TYPE_DIR}/libmatrix_sdk_crypto_ffi.a" \
"${TARGET_DIR}/aarch64-apple-darwin/${REL_TYPE_DIR}/libmatrix_sdk_crypto_ffi.a" \
-output "${GENERATED_DIR}/macos/libmatrix_sdk_crypto_ffi.a"
# iOS Simulator
lipo -create \
"${TARGET_DIR}/x86_64-apple-ios/${REL_TYPE_DIR}/libmatrix_sdk_crypto_ffi.a" \
"${TARGET_DIR}/aarch64-apple-ios-sim/${REL_TYPE_DIR}/libmatrix_sdk_crypto_ffi.a" \
-output "${GENERATED_DIR}/simulator/libmatrix_sdk_crypto_ffi.a"
# iOS Simulator
lipo -create \
"${TARGET_DIR}/x86_64-apple-ios/${REL_TYPE_DIR}/libmatrix_sdk_crypto_ffi.a" \
"${TARGET_DIR}/aarch64-apple-ios-sim/${REL_TYPE_DIR}/libmatrix_sdk_crypto_ffi.a" \
-output "${GENERATED_DIR}/simulator/libmatrix_sdk_crypto_ffi.a"
fi
# Generate uniffi files
cargo uniffi-bindgen generate \
cd ../matrix-sdk-crypto-ffi && cargo run --bin matrix_sdk_crypto_ffi generate \
--language swift \
--lib-file "${TARGET_DIR}/aarch64-apple-ios-sim/${REL_TYPE_DIR}/libmatrix_sdk_crypto_ffi.a" \
--config "${SRC_ROOT}/bindings/${TARGET_CRATE}/uniffi.toml" \
--out-dir ${GENERATED_DIR} \
"${SRC_ROOT}/bindings/${TARGET_CRATE}/src/olm.udl"
--library "${TARGET_DIR}/aarch64-apple-ios/${REL_TYPE_DIR}/libmatrix_sdk_crypto_ffi.a" \
--out-dir ${GENERATED_DIR}
# Move headers to the right place
HEADERS_DIR=${GENERATED_DIR}/headers
mkdir -p ${HEADERS_DIR}
mv ${GENERATED_DIR}/*.h ${HEADERS_DIR}
# Rename and move modulemap to the right place
mv ${GENERATED_DIR}/*.modulemap ${HEADERS_DIR}/module.modulemap
# Rename and merge the modulemap files into a single file to the right place
for f in ${GENERATED_DIR}/*.modulemap
do
cat $f; echo;
done > ${HEADERS_DIR}/module.modulemap
rm ${GENERATED_DIR}/*.modulemap
# Move source files to the right place
SWIFT_DIR="${GENERATED_DIR}/Sources"
@@ -77,15 +104,21 @@ mv ${GENERATED_DIR}/*.swift ${SWIFT_DIR}
# Build the xcframework
if [ -d "${GENERATED_DIR}/MatrixSDKCryptoFFI.xcframework" ]; then rm -rf "${GENERATED_DIR}/MatrixSDKCryptoFFI.xcframework"; fi
xcodebuild -create-xcframework \
-library "${TARGET_DIR}/aarch64-apple-ios/${REL_TYPE_DIR}/libmatrix_sdk_crypto_ffi.a" \
-headers ${HEADERS_DIR} \
-library "${GENERATED_DIR}/macos/libmatrix_sdk_crypto_ffi.a" \
-headers ${HEADERS_DIR} \
-library "${GENERATED_DIR}/simulator/libmatrix_sdk_crypto_ffi.a" \
-headers ${HEADERS_DIR} \
-output "${GENERATED_DIR}/MatrixSDKCryptoFFI.xcframework"
if ${only_ios}; then
xcodebuild -create-xcframework \
-library "${TARGET_DIR}/aarch64-apple-ios/${REL_TYPE_DIR}/libmatrix_sdk_crypto_ffi.a" \
-headers ${HEADERS_DIR} \
-output "${GENERATED_DIR}/MatrixSDKCryptoFFI.xcframework"
else
xcodebuild -create-xcframework \
-library "${TARGET_DIR}/aarch64-apple-ios/${REL_TYPE_DIR}/libmatrix_sdk_crypto_ffi.a" \
-headers ${HEADERS_DIR} \
-library "${GENERATED_DIR}/macos/libmatrix_sdk_crypto_ffi.a" \
-headers ${HEADERS_DIR} \
-library "${GENERATED_DIR}/simulator/libmatrix_sdk_crypto_ffi.a" \
-headers ${HEADERS_DIR} \
-output "${GENERATED_DIR}/MatrixSDKCryptoFFI.xcframework"
fi
# Cleanup
if [ -d "${GENERATED_DIR}/macos" ]; then rm -rf "${GENERATED_DIR}/macos"; fi
+18 -7
View File
@@ -12,16 +12,21 @@ publish = false
[lib]
crate-type = ["cdylib", "staticlib"]
[[bin]]
name = "matrix_sdk_crypto_ffi"
path = "uniffi-bindgen.rs"
[features]
default = ["bundled-sqlite"]
bundled-sqlite = ["matrix-sdk-sqlite/bundled"]
[dependencies]
anyhow = { workspace = true }
futures-util = "0.3.28"
futures-util = { workspace = true }
hmac = "0.12.1"
http = { workspace = true }
matrix-sdk-common = { workspace = true }
matrix-sdk-common = { workspace = true, features = ["uniffi"] }
matrix-sdk-ffi-macros = { workspace = true }
pbkdf2 = "0.12.2"
rand = { workspace = true }
ruma = { workspace = true }
@@ -29,9 +34,9 @@ serde = { workspace = true }
serde_json = { workspace = true }
sha2 = { workspace = true }
thiserror = { workspace = true }
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
tracing-subscriber = { workspace = true, features = ["env-filter"] }
# keep in sync with uniffi dependency in matrix-sdk-ffi, and uniffi_bindgen in ffi CI job
uniffi = { workspace = true }
uniffi = { workspace = true, features = ["cli"] }
vodozemac = { workspace = true }
zeroize = { workspace = true, features = ["zeroize_derive"] }
@@ -41,7 +46,7 @@ features = ["lax_deserialize"]
[dependencies.matrix-sdk-crypto]
workspace = true
features = ["qrcode", "automatic-room-key-forwarding"]
features = ["qrcode", "automatic-room-key-forwarding", "uniffi"]
[dependencies.matrix-sdk-sqlite]
workspace = true
@@ -49,13 +54,19 @@ features = ["crypto-store"]
[dependencies.tokio]
version = "1.33.0"
default_features = false
default-features = false
features = ["rt-multi-thread"]
[build-dependencies]
uniffi = { workspace = true, features = ["build"] }
vergen = { version = "8.2.5", features = ["build", "git", "gitcl"] }
uniffi = { workspace = true, features = ["build"] }
[dev-dependencies]
tempfile = "3.8.0"
assert_matches2 = { workspace = true }
[lints]
workspace = true
[package.metadata.release]
release = false
-4
View File
@@ -71,10 +71,6 @@ $ cp ../../target/aarch64-linux-android/debug/libmatrix_crypto.so \
/home/example/matrix-sdk-android/src/main/jniLibs/aarch64/libuniffi_olm.so
```
## Minimum Supported Rust Version (MSRV)
These crates are built with the Rust language version 2021 and require a minimum compiler version of `1.62`.
## License
[Apache-2.0](https://www.apache.org/licenses/LICENSE-2.0)
+39 -18
View File
@@ -1,37 +1,58 @@
use std::{env, error::Error};
use std::{env, error::Error, path::PathBuf, process::Command};
use vergen::EmitBuilder;
/// Adds a temporary workaround for an issue with the Rust compiler and Android
/// in x86_64 devices: https://github.com/rust-lang/rust/issues/109717.
/// The workaround comes from: https://github.com/mozilla/application-services/pull/5442
/// The workaround is based on: https://github.com/mozilla/application-services/pull/5442
///
/// IMPORTANT: if you modify this, make sure to modify
/// [../matrix-sdk-ffi/build.rs] too!
fn setup_x86_64_android_workaround() {
let target_os = env::var("CARGO_CFG_TARGET_OS").expect("CARGO_CFG_TARGET_OS not set");
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").expect("CARGO_CFG_TARGET_ARCH not set");
if target_arch == "x86_64" && target_os == "android" {
let android_ndk_home = env::var("ANDROID_NDK_HOME").expect("ANDROID_NDK_HOME not set");
let build_os = match env::consts::OS {
"linux" => "linux",
"macos" => "darwin",
"windows" => "windows",
_ => panic!(
"Unsupported OS. You must use either Linux, MacOS or Windows to build the crate."
),
};
const DEFAULT_CLANG_VERSION: &str = "14.0.7";
let clang_version =
env::var("NDK_CLANG_VERSION").unwrap_or_else(|_| DEFAULT_CLANG_VERSION.to_owned());
let linux_x86_64_lib_dir = format!(
"toolchains/llvm/prebuilt/{build_os}-x86_64/lib64/clang/{clang_version}/lib/linux/"
// Configure rust to statically link against the `libclang_rt.builtins` supplied
// with clang.
// cargo-ndk sets CC_x86_64-linux-android to the path to `clang`, within the
// Android NDK.
let clang_path = PathBuf::from(
env::var("CC_x86_64-linux-android").expect("CC_x86_64-linux-android not set"),
);
println!("cargo:rustc-link-search={android_ndk_home}/{linux_x86_64_lib_dir}");
// clang_path should now look something like
// `.../sdk/ndk/28.0.12674087/toolchains/llvm/prebuilt/linux-x86_64/bin/clang`.
// We strip `/bin/clang` from the end to get the toolchain path.
let toolchain_path = clang_path
.ancestors()
.nth(2)
.expect("could not find NDK toolchain path")
.to_str()
.expect("NDK toolchain path is not valid UTF-8");
let clang_version = get_clang_major_version(&clang_path);
println!("cargo:rustc-link-search={toolchain_path}/lib/clang/{clang_version}/lib/linux/");
println!("cargo:rustc-link-lib=static=clang_rt.builtins-x86_64-android");
}
}
/// Run the clang binary at `clang_path`, and return its major version number
fn get_clang_major_version(clang_path: &PathBuf) -> String {
let clang_output =
Command::new(clang_path).arg("-dumpversion").output().expect("failed to start clang");
if !clang_output.status.success() {
panic!("failed to run clang: {}", String::from_utf8_lossy(&clang_output.stderr));
}
let clang_version = String::from_utf8(clang_output.stdout).expect("clang output is not utf8");
clang_version.split('.').next().expect("could not parse clang output").to_owned()
}
fn main() -> Result<(), Box<dyn Error>> {
setup_x86_64_android_workaround();
uniffi::generate_scaffolding("./src/olm.udl")?;
EmitBuilder::builder().git_sha(true).git_describe(true, false, None).emit()?;
@@ -69,7 +69,7 @@ impl BackupRecoveryKey {
const PBKDF_ROUNDS: i32 = 500_000;
}
#[uniffi::export]
#[matrix_sdk_ffi_macros::export]
impl BackupRecoveryKey {
/// Create a new random [`BackupRecoveryKey`].
#[allow(clippy::new_without_default)]
@@ -1,13 +1,17 @@
use std::{mem::ManuallyDrop, sync::Arc};
use matrix_sdk_crypto::dehydrated_devices::{
DehydratedDevice as InnerDehydratedDevice, DehydratedDevices as InnerDehydratedDevices,
RehydratedDevice as InnerRehydratedDevice,
use matrix_sdk_crypto::{
dehydrated_devices::{
DehydratedDevice as InnerDehydratedDevice, DehydratedDevices as InnerDehydratedDevices,
RehydratedDevice as InnerRehydratedDevice,
},
store::DehydratedDeviceKey as InnerDehydratedDeviceKey,
};
use ruma::{api::client::dehydrated_device, events::AnyToDeviceEvent, serde::Raw, OwnedDeviceId};
use serde_json::json;
use tokio::runtime::Handle;
use zeroize::Zeroize;
use crate::{CryptoStoreError, DehydratedDeviceKey};
#[derive(Debug, thiserror::Error, uniffi::Error)]
#[uniffi(flat_error)]
@@ -22,6 +26,8 @@ pub enum DehydrationError {
Store(#[from] matrix_sdk_crypto::CryptoStoreError),
#[error("The pickle key has an invalid length, expected 32 bytes, got {0}")]
PickleKeyLength(usize),
#[error(transparent)]
Rand(#[from] rand::Error),
}
impl From<matrix_sdk_crypto::dehydrated_devices::DehydrationError> for DehydrationError {
@@ -33,6 +39,9 @@ impl From<matrix_sdk_crypto::dehydrated_devices::DehydrationError> for Dehydrati
Self::MissingSigningKey(e)
}
matrix_sdk_crypto::dehydrated_devices::DehydrationError::Store(e) => Self::Store(e),
matrix_sdk_crypto::dehydrated_devices::DehydrationError::PickleKeyLength(l) => {
Self::PickleKeyLength(l)
}
}
}
}
@@ -53,7 +62,7 @@ impl Drop for DehydratedDevices {
}
}
#[uniffi::export]
#[matrix_sdk_ffi_macros::export]
impl DehydratedDevices {
pub fn create(&self) -> Result<Arc<DehydratedDevice>, DehydrationError> {
let inner = self.runtime.block_on(self.inner.create())?;
@@ -66,14 +75,14 @@ impl DehydratedDevices {
pub fn rehydrate(
&self,
pickle_key: Vec<u8>,
pickle_key: &DehydratedDeviceKey,
device_id: String,
device_data: String,
) -> Result<Arc<RehydratedDevice>, DehydrationError> {
let device_data: Raw<_> = serde_json::from_str(&device_data)?;
let device_id: OwnedDeviceId = device_id.into();
let mut key = get_pickle_key(&pickle_key)?;
let key = InnerDehydratedDeviceKey::from_slice(&pickle_key.inner)?;
let ret = RehydratedDevice {
runtime: self.runtime.to_owned(),
@@ -85,10 +94,41 @@ impl DehydratedDevices {
}
.into();
key.zeroize();
Ok(ret)
}
/// Get the cached dehydrated device pickle key if any.
///
/// None if the key was not previously cached (via
/// [`Self::save_dehydrated_device_pickle_key`]).
///
/// Should be used to periodically rotate the dehydrated device to avoid
/// OTK exhaustion and accumulation of to_device messages.
pub fn get_dehydrated_device_key(
&self,
) -> Result<Option<crate::DehydratedDeviceKey>, CryptoStoreError> {
Ok(self
.runtime
.block_on(self.inner.get_dehydrated_device_pickle_key())?
.map(crate::DehydratedDeviceKey::from))
}
/// Store the dehydrated device pickle key in the crypto store.
///
/// This is useful if the client wants to periodically rotate dehydrated
/// devices to avoid OTK exhaustion and accumulated to_device problems.
pub fn save_dehydrated_device_key(
&self,
pickle_key: &crate::DehydratedDeviceKey,
) -> Result<(), CryptoStoreError> {
let pickle_key = InnerDehydratedDeviceKey::from_slice(&pickle_key.inner)?;
Ok(self.runtime.block_on(self.inner.save_dehydrated_device_pickle_key(&pickle_key))?)
}
/// Deletes the previously stored dehydrated device pickle key.
pub fn delete_dehydrated_device_key(&self) -> Result<(), CryptoStoreError> {
Ok(self.runtime.block_on(self.inner.delete_dehydrated_device_pickle_key())?)
}
}
#[derive(uniffi::Object)]
@@ -107,7 +147,7 @@ impl Drop for RehydratedDevice {
}
}
#[uniffi::export]
#[matrix_sdk_ffi_macros::export]
impl RehydratedDevice {
pub fn receive_events(&self, events: String) -> Result<(), crate::CryptoStoreError> {
let events: Vec<Raw<AnyToDeviceEvent>> = serde_json::from_str(&events)?;
@@ -133,20 +173,18 @@ impl Drop for DehydratedDevice {
}
}
#[uniffi::export]
#[matrix_sdk_ffi_macros::export]
impl DehydratedDevice {
pub fn keys_for_upload(
&self,
device_display_name: String,
pickle_key: Vec<u8>,
pickle_key: &DehydratedDeviceKey,
) -> Result<UploadDehydratedDeviceRequest, DehydrationError> {
let mut key = get_pickle_key(&pickle_key)?;
let key = InnerDehydratedDeviceKey::from_slice(&pickle_key.inner)?;
let request =
self.runtime.block_on(self.inner.keys_for_upload(device_display_name, &key))?;
key.zeroize();
Ok(request.into())
}
}
@@ -177,15 +215,36 @@ impl From<dehydrated_device::put_dehydrated_device::unstable::Request>
}
}
fn get_pickle_key(pickle_key: &[u8]) -> Result<Box<[u8; 32]>, DehydrationError> {
let pickle_key_length = pickle_key.len();
#[cfg(test)]
mod tests {
use crate::{dehydrated_devices::DehydrationError, DehydratedDeviceKey};
if pickle_key_length == 32 {
let mut key = Box::new([0u8; 32]);
key.copy_from_slice(pickle_key);
#[test]
fn test_creating_dehydrated_key() {
let result = DehydratedDeviceKey::new();
assert!(result.is_ok());
let dehydrated_device_key = result.unwrap();
let base_64 = dehydrated_device_key.to_base64();
let inner_bytes = dehydrated_device_key.inner;
Ok(key)
} else {
Err(DehydrationError::PickleKeyLength(pickle_key_length))
let copy = DehydratedDeviceKey::from_slice(&inner_bytes).unwrap();
assert_eq!(base_64, copy.to_base64());
}
#[test]
fn test_creating_dehydrated_key_failure() {
let bytes = [0u8; 24];
let pickle_key = DehydratedDeviceKey::from_slice(&bytes);
assert!(pickle_key.is_err());
match pickle_key {
Err(DehydrationError::PickleKeyLength(pickle_key_length)) => {
assert_eq!(bytes.len(), pickle_key_length);
}
_ => panic!("Should have failed!"),
}
}
}
+5 -2
View File
@@ -25,9 +25,11 @@ pub struct Device {
/// Is our cross signing identity trusted and does the identity trust the
/// device.
pub cross_signing_trusted: bool,
/// The first time this device was seen in local timestamp, seconds since
/// epoch.
/// The first time this device was seen in local timestamp, milliseconds
/// since epoch.
pub first_time_seen_ts: u64,
/// Whether or not the device is a dehydrated device.
pub dehydrated: bool,
}
impl From<InnerDevice> for Device {
@@ -42,6 +44,7 @@ impl From<InnerDevice> for Device {
locally_trusted: d.is_locally_trusted(),
cross_signing_trusted: d.is_cross_signing_trusted(),
first_time_seen_ts: d.first_time_seen_ts().0.into(),
dehydrated: d.is_dehydrated(),
}
}
}
+6 -3
View File
@@ -1,8 +1,9 @@
#![allow(missing_docs)]
use matrix_sdk_crypto::{
store::CryptoStoreError as InnerStoreError, KeyExportError, MegolmError, OlmError,
SecretImportError as RustSecretImportError, SignatureError as InnerSignatureError,
store::{CryptoStoreError as InnerStoreError, DehydrationError as InnerDehydrationError},
KeyExportError, MegolmError, OlmError, SecretImportError as RustSecretImportError,
SignatureError as InnerSignatureError,
};
use matrix_sdk_sqlite::OpenStoreError;
use ruma::{IdParseError, OwnedUserId};
@@ -57,6 +58,8 @@ pub enum CryptoStoreError {
InvalidUserId(String, IdParseError),
#[error(transparent)]
Identifier(#[from] IdParseError),
#[error(transparent)]
DehydrationError(#[from] InnerDehydrationError),
}
#[derive(Debug, thiserror::Error, uniffi::Error)]
@@ -112,7 +115,7 @@ mod tests {
#[test]
fn test_withheld_error_mapping() {
use matrix_sdk_crypto::types::events::room_key_withheld::WithheldCode;
use matrix_sdk_common::deserialized_responses::WithheldCode;
let inner_error = MegolmError::MissingRoomKey(Some(WithheldCode::Unverified));
+193 -54
View File
@@ -16,9 +16,13 @@ mod responses;
mod users;
mod verification;
use std::{collections::HashMap, str::FromStr, sync::Arc, time::Duration};
use std::{
collections::{BTreeMap, HashMap},
sync::Arc,
time::Duration,
};
use anyhow::Context;
use anyhow::Context as _;
pub use backup_recovery_key::{
BackupRecoveryKey, DecodeError, MegolmV1BackupKey, PassphraseInfo, PkDecryptionError,
};
@@ -29,13 +33,17 @@ pub use error::{
use js_int::UInt;
pub use logger::{set_logger, Logger};
pub use machine::{KeyRequestPair, OlmMachine, SignatureVerification};
use matrix_sdk_common::deserialized_responses::ShieldState as RustShieldState;
use matrix_sdk_common::deserialized_responses::{ShieldState as RustShieldState, ShieldStateCode};
use matrix_sdk_crypto::{
backups::SignatureState,
olm::{IdentityKeys, InboundGroupSession, Session},
store::{Changes, CryptoStore, PendingChanges, RoomSettings as RustRoomSettings},
types::{EventEncryptionAlgorithm as RustEventEncryptionAlgorithm, SigningKey},
EncryptionSettings as RustEncryptionSettings, LocalTrust,
olm::{IdentityKeys, InboundGroupSession, SenderData, Session},
store::{
Changes, CryptoStore, DehydratedDeviceKey as InnerDehydratedDeviceKey, PendingChanges,
RoomSettings as RustRoomSettings,
},
types::{
DeviceKey, DeviceKeys, EventEncryptionAlgorithm as RustEventEncryptionAlgorithm, SigningKey,
},
CollectStrategy, EncryptionSettings as RustEncryptionSettings,
};
use matrix_sdk_sqlite::SqliteCryptoStore;
pub use responses::{
@@ -44,8 +52,8 @@ pub use responses::{
};
use ruma::{
events::room::history_visibility::HistoryVisibility as RustHistoryVisibility,
DeviceKeyAlgorithm, MilliSecondsSinceUnixEpoch, OwnedDeviceId, OwnedUserId, RoomId,
SecondsSinceUnixEpoch, UserId,
DeviceKeyAlgorithm, DeviceKeyId, MilliSecondsSinceUnixEpoch, OwnedDeviceId, OwnedUserId,
RoomId, SecondsSinceUnixEpoch, UserId,
};
use serde::{Deserialize, Serialize};
use tokio::runtime::Runtime;
@@ -57,6 +65,8 @@ pub use verification::{
};
use vodozemac::{Curve25519PublicKey, Ed25519PublicKey};
use crate::dehydrated_devices::DehydrationError;
/// Struct collecting data that is important to migrate to the rust-sdk
#[derive(Deserialize, Serialize, uniffi::Record)]
pub struct MigrationData {
@@ -129,10 +139,10 @@ pub struct PickledSession {
pub sender_key: String,
/// Was the session created using a fallback key.
pub created_using_fallback_key: bool,
/// The Unix timestamp when the session was created.
pub creation_time: String,
/// The Unix timestamp when the session was last used.
pub last_use_time: String,
/// Unix timestamp (in seconds) when the session was created.
pub creation_time: u64,
/// Unix timestamp (in seconds) when the session was last used.
pub last_use_time: u64,
}
/// A pickled version of an `InboundGroupSession`.
@@ -186,12 +196,12 @@ impl From<anyhow::Error> for MigrationError {
/// * `path` - The path where the SQLite store should be created.
///
/// * `passphrase` - The passphrase that should be used to encrypt the data at
/// rest in the SQLite store. **Warning**, if no passphrase is given, the store
/// and all its data will remain unencrypted.
/// rest in the SQLite store. **Warning**, if no passphrase is given, the
/// store and all its data will remain unencrypted.
///
/// * `progress_listener` - A callback that can be used to introspect the
/// progress of the migration.
#[uniffi::export]
/// progress of the migration.
#[matrix_sdk_ffi_macros::export]
pub fn migrate(
data: MigrationData,
path: String,
@@ -244,9 +254,11 @@ async fn migrate_data(
user_id: parse_user_id(&data.account.user_id)?,
device_id: device_id.clone(),
pickle,
dehydrated: false, // dehydrated devices are never involved in migration
shared: data.account.shared,
uploaded_signed_key_count: data.account.uploaded_signed_key_count as u64,
creation_local_time: MilliSecondsSinceUnixEpoch(UInt::default()),
creation_local_time: MilliSecondsSinceUnixEpoch::now(),
fallback_key_creation_timestamp: Some(MilliSecondsSinceUnixEpoch::now()),
};
let account = matrix_sdk_crypto::olm::Account::from_pickle(pickled_account)?;
@@ -347,12 +359,12 @@ async fn save_changes(
/// * `path` - The path where the SQLite store should be created.
///
/// * `passphrase` - The passphrase that should be used to encrypt the data at
/// rest in the SQLite store. **Warning**, if no passphrase is given, the store
/// and all its data will remain unencrypted.
/// rest in the SQLite store. **Warning**, if no passphrase is given, the
/// store and all its data will remain unencrypted.
///
/// * `progress_listener` - A callback that can be used to introspect the
/// progress of the migration.
#[uniffi::export]
/// progress of the migration.
#[matrix_sdk_ffi_macros::export]
pub fn migrate_sessions(
data: SessionMigrationData,
path: String,
@@ -418,13 +430,38 @@ fn collect_sessions(
) -> anyhow::Result<(Vec<Session>, Vec<InboundGroupSession>)> {
let mut sessions = Vec::new();
// Create a DeviceKeys struct with enough information to get a working
// Session, but we will won't actually use the Sessions (and we'll clear
// the session cache after migration) so we don't need to worry about
// signatures.
let device_keys = DeviceKeys::new(
user_id,
device_id.clone(),
Default::default(),
BTreeMap::from([
(
DeviceKeyId::from_parts(DeviceKeyAlgorithm::Ed25519, &device_id),
DeviceKey::Ed25519(identity_keys.ed25519),
),
(
DeviceKeyId::from_parts(DeviceKeyAlgorithm::Curve25519, &device_id),
DeviceKey::Curve25519(identity_keys.curve25519),
),
]),
Default::default(),
);
for session_pickle in session_pickles {
let pickle =
vodozemac::olm::Session::from_libolm_pickle(&session_pickle.pickle, pickle_key)?
.pickle();
let creation_time = SecondsSinceUnixEpoch(UInt::from_str(&session_pickle.creation_time)?);
let last_use_time = SecondsSinceUnixEpoch(UInt::from_str(&session_pickle.last_use_time)?);
let creation_time = SecondsSinceUnixEpoch(
UInt::new(session_pickle.creation_time).context("invalid creation timestamp")?,
);
let last_use_time = SecondsSinceUnixEpoch(
UInt::new(session_pickle.last_use_time).context("invalid last use timestamp")?,
);
let pickle = matrix_sdk_crypto::olm::PickledSession {
pickle,
@@ -434,8 +471,7 @@ fn collect_sessions(
last_use_time,
};
let session =
Session::from_pickle(user_id.clone(), device_id.clone(), identity_keys.clone(), pickle);
let session = Session::from_pickle(device_keys.clone(), pickle)?;
sessions.push(session);
processed_steps += 1;
@@ -466,6 +502,7 @@ fn collect_sessions(
Ok((algorithm, key))
})
.collect::<anyhow::Result<_>>()?,
sender_data: SenderData::legacy(),
room_id: RoomId::parse(session.room_id)?,
imported: session.imported,
backed_up: session.backed_up,
@@ -498,9 +535,9 @@ fn collect_sessions(
/// * `path` - The path where the Sqlite store should be created.
///
/// * `passphrase` - The passphrase that should be used to encrypt the data at
/// rest in the Sqlite store. **Warning**, if no passphrase is given, the store
/// and all its data will remain unencrypted.
#[uniffi::export]
/// rest in the Sqlite store. **Warning**, if no passphrase is given, the
/// store and all its data will remain unencrypted.
#[matrix_sdk_ffi_macros::export]
pub fn migrate_room_settings(
room_settings: HashMap<String, RoomSettings>,
path: String,
@@ -526,7 +563,7 @@ pub fn migrate_room_settings(
}
/// Callback that will be passed over the FFI to report progress
#[uniffi::export(callback_interface)]
#[matrix_sdk_ffi_macros::export(callback_interface)]
pub trait ProgressListener {
/// The callback that should be called on the Rust side
///
@@ -636,6 +673,9 @@ pub struct EncryptionSettings {
/// Should untrusted devices receive the room key, or should they be
/// excluded from the conversation.
pub only_allow_trusted_devices: bool,
/// Should fail to send when a verified user has unverified devices, or when
/// a previously verified user replaces their identity.
pub error_on_verified_user_problem: bool,
}
impl From<EncryptionSettings> for RustEncryptionSettings {
@@ -645,7 +685,10 @@ impl From<EncryptionSettings> for RustEncryptionSettings {
rotation_period: Duration::from_secs(v.rotation_period),
rotation_period_msgs: v.rotation_period_msgs,
history_visibility: v.history_visibility.into(),
only_allow_trusted_devices: v.only_allow_trusted_devices,
sharing_strategy: CollectStrategy::DeviceBasedStrategy {
only_allow_trusted_devices: v.only_allow_trusted_devices,
error_on_verified_user_problem: v.error_on_verified_user_problem,
},
}
}
}
@@ -690,19 +733,24 @@ pub enum ShieldColor {
#[allow(missing_docs)]
pub struct ShieldState {
color: ShieldColor,
code: Option<ShieldStateCode>,
message: Option<String>,
}
impl From<RustShieldState> for ShieldState {
fn from(value: RustShieldState) -> Self {
match value {
RustShieldState::Red { message } => {
Self { color: ShieldColor::Red, message: Some(message.to_owned()) }
}
RustShieldState::Grey { message } => {
Self { color: ShieldColor::Grey, message: Some(message.to_owned()) }
}
RustShieldState::None => Self { color: ShieldColor::None, message: None },
RustShieldState::Red { code, message } => Self {
color: ShieldColor::Red,
code: Some(code),
message: Some(message.to_owned()),
},
RustShieldState::Grey { code, message } => Self {
color: ShieldColor::Grey,
code: Some(code),
message: Some(message.to_owned()),
},
RustShieldState::None => Self { color: ShieldColor::None, code: None, message: None },
}
}
}
@@ -751,7 +799,7 @@ pub struct BackupKeys {
backup_version: String,
}
#[uniffi::export]
#[matrix_sdk_ffi_macros::export]
impl BackupKeys {
/// Get the recovery key that we're holding on to.
pub fn recovery_key(&self) -> Arc<BackupRecoveryKey> {
@@ -779,6 +827,39 @@ impl TryFrom<matrix_sdk_crypto::store::BackupKeys> for BackupKeys {
}
}
/// Dehydrated device key
#[derive(uniffi::Record, Clone)]
pub struct DehydratedDeviceKey {
pub(crate) inner: Vec<u8>,
}
impl DehydratedDeviceKey {
/// Generates a new random pickle key.
pub fn new() -> Result<Self, DehydrationError> {
let inner = InnerDehydratedDeviceKey::new()?;
Ok(inner.into())
}
/// Creates a new dehydration pickle key from the given slice.
///
/// Fail if the slice length is not 32.
pub fn from_slice(slice: &[u8]) -> Result<Self, DehydrationError> {
let inner = InnerDehydratedDeviceKey::from_slice(slice)?;
Ok(inner.into())
}
/// Export the [`DehydratedDeviceKey`] as a base64 encoded string.
pub fn to_base64(&self) -> String {
let inner = InnerDehydratedDeviceKey::from_slice(&self.inner).unwrap();
inner.to_base64()
}
}
impl From<InnerDehydratedDeviceKey> for DehydratedDeviceKey {
fn from(pickle_key: InnerDehydratedDeviceKey) -> Self {
DehydratedDeviceKey { inner: pickle_key.into() }
}
}
impl From<matrix_sdk_crypto::store::RoomKeyCounts> for RoomKeyCounts {
fn from(count: matrix_sdk_crypto::store::RoomKeyCounts) -> Self {
Self { total: count.total as i64, backed_up: count.backed_up as i64 }
@@ -839,6 +920,7 @@ impl From<RoomSettings> for RustRoomSettings {
Self {
algorithm: value.algorithm.into(),
only_allow_trusted_devices: value.only_allow_trusted_devices,
..RustRoomSettings::default()
}
}
}
@@ -847,7 +929,7 @@ fn parse_user_id(user_id: &str) -> Result<OwnedUserId, CryptoStoreError> {
ruma::UserId::parse(user_id).map_err(|e| CryptoStoreError::InvalidUserId(user_id.to_owned(), e))
}
#[uniffi::export]
#[matrix_sdk_ffi_macros::export]
fn version_info() -> VersionInfo {
VersionInfo {
version: matrix_sdk_crypto::VERSION.to_owned(),
@@ -871,17 +953,74 @@ pub struct VersionInfo {
pub git_description: String,
}
#[uniffi::export]
#[matrix_sdk_ffi_macros::export]
fn version() -> String {
matrix_sdk_crypto::VERSION.to_owned()
}
#[uniffi::export]
#[matrix_sdk_ffi_macros::export]
fn vodozemac_version() -> String {
vodozemac::VERSION.to_owned()
}
uniffi::include_scaffolding!("olm");
/// The encryption component of PkEncryption support.
///
/// This struct can be created using a [`Curve25519PublicKey`] corresponding to
/// a `PkDecryption` object, allowing messages to be encrypted for the
/// associated decryption object.
#[derive(uniffi::Object)]
pub struct PkEncryption {
inner: matrix_sdk_crypto::vodozemac::pk_encryption::PkEncryption,
}
#[matrix_sdk_ffi_macros::export]
impl PkEncryption {
/// Create a new [`PkEncryption`] object from a `Curve25519PublicKey`
/// encoded as Base64.
///
/// The public key should come from an existing `PkDecryption` object.
/// Returns a `DecodeError` if the Curve25519 key could not be decoded
/// correctly.
#[uniffi::constructor]
pub fn from_base64(key: &str) -> Result<Arc<Self>, DecodeError> {
let key = vodozemac::Curve25519PublicKey::from_base64(key)
.map_err(matrix_sdk_crypto::backups::DecodeError::PublicKey)?;
let inner = vodozemac::pk_encryption::PkEncryption::from_key(key);
Ok(Self { inner }.into())
}
/// Encrypt a message using this [`PkEncryption`] object.
pub fn encrypt(&self, plaintext: &str) -> PkMessage {
use vodozemac::base64_encode;
let message = self.inner.encrypt(plaintext.as_ref());
let vodozemac::pk_encryption::Message { ciphertext, mac, ephemeral_key } = message;
PkMessage {
ciphertext: base64_encode(ciphertext),
mac: base64_encode(mac),
ephemeral_key: ephemeral_key.to_base64(),
}
}
}
/// A message that was encrypted using a [`PkEncryption`] object.
#[derive(uniffi::Record)]
pub struct PkMessage {
/// The ciphertext of the message.
pub ciphertext: String,
/// The message authentication code of the message.
///
/// *Warning*: This does not authenticate the ciphertext.
pub mac: String,
/// The ephemeral Curve25519 key of the message which was used to derive the
/// individual message key.
pub ephemeral_key: String,
}
uniffi::setup_scaffolding!();
#[cfg(test)]
mod tests {
@@ -901,36 +1040,35 @@ mod tests {
"pickle":"FFGTGho89T3Xgd56l+EedOPV37s09RR8aYnS9305qPKF66LG+ly29YpCibjJOvkwm0dZwN9A2bOH/z7WscriqwZn/p0GE6YSNwLzffCy5iROzYzpYzFe0HtiyJmCQWCezvLc5lHV8YsfD00C1pKGX2R9M1wwp3/n4/3VjtTyPsdnmtwAPu4WdcPSkisCaQ3a6JaSKqv8zYzUjnpzgcpXHvPUR5d5+TzXgrVz3BeCOe8NEOWIW6xYUxFtGteYP0BczOkkJ22t7Css0tSMSrYgCll4zZUGNrd6D9b/z7KwcDnb978epsZ16DcZ/aaTxPdM5uDIkHgF/qHWerfxcaqsqs4EQfJdSgOTeqhjHBw1k0uWF2bByJLK+n7sGkYXEAuTzc4+0XvSFvu3Qp+1bHZuT7QejngRZzyxznORyBxd8la3/JjeJlehSK80OL7zSmohoYZD59S6i3tFWfopjQThJ0/eIyVOhEN/c3tfIcVr3lFEQeokgpCRNOVldhPcQWq994NHaL7jtb6yhUqT1gShY4zYayFL/VRz6nBSXXYwzrC9jho67knqXSri3lIKYevP9aOi384IvzbkinQdumc804dYwiCbs5hZppfEnfhfgiDDm+kVrJ9WaPRF4SySCTlS8jdGmBeL2CfCQ5IcZ5nK6X7tZM3tmtYwva0RuQiTNltp3XTfbMa0EoaEBximv25165hFTpzrWgoszBTpZPfgsMuWENWBcIX4AcLSk0CJ0qzPDeUwvmRcFStstGYV4drs5u5HEqovFSI48CoHPSEZfwwERCI4c/0efZ0CVEfnm8VcMv3AbnAfedD7v3QNdVwWOEhz/fGR76BQi2WjZP4MWvYRJ/vsLO5hcVWUvaJGQs5kANUFZMWuJQeJv3DmkV9kKKXnyfFUerlQ4Uk/5tp2mXiG+adHjuRp/Eeh5V/biCcIaX3rNuIY6MJaPz6SOwlFe79MMBaNwaS3j4Kh/Aq9BRw0QXdjO4CqMI4p2xCE1N5QTPdeaRTHTZ3r7mLkHX3FpZMxitc8vDl9L2FRoSOMMh/sRD1boBCkjrsty9rvTUGYY3li05jBuTXnYMjA4zj79dC9TGo4g+/wi+h537EhtP5+170LwqnIzfHt8yfjbsMMC7iwLpC1C57sTwxpMkNo3nQEvZOfqCxjq+ihiGuL9iN5lSstu9/C4qP2tQll86ASXf1axxRZQlUB0hlLHbEW6/7O7xOU6FTs4yXAZC04souRkggmfhDzZ9kQmN/zRTbqlATFI7l9/0VGxwLOVnCMUhgiDX5yL8CYK9I4ENMLf5zOuO6P3GbYISjEoHC7fUOzQ6OwGgLyI0wCEVdSJzQcdKh+W15VV+eDjhE/qEJHQWx024hTQFTKYHlDn95+lMmRI9BJLP1HU2JW6onVWsTsE5zSYu9jLj739EKfV4gS/pWzoQDRa7a9ZG6+m+RrwyJhCso3gkUekDNobhFlDX6YeH+Btj91N0uS3F9qr8lbo491s/z2fNV42zT4NYObzgrAYDQAV/2WYF8tXtxLV/Jzk8AMmyr/cfNaT2dXxVJKWq+nN2BYHBmg9CCWPJ2aB/1WWIcHfcDOlngtH991gP6246f/DEaVC/Ayxz7bPtSH5tlZ4Xbpc2P4BYxaRp/yxhhQ2C9H2I/PTt3mnNNgky/t8PZrN3W5+eiSVE9sONF8G3mYsa4XFqM+KxfbPUqsrEnrRBmvmJ250hpTPkFcIF775RvvRRKALXdlTKs+S4HKDW7KoP0Dm9+r4RlO0UHpWND9w0WSMItvWQyo0VViXJgZfBjYtWDoO0Ud+Kc7PLWNX6RUKY7RlDjXadJTC4adH6CN3UBC/ouqqfTrYvPOkyd2oKf4RLjEVcFAUIftFbLy+WBcWv8072nnAFJIlm3CxGq++80TyjqFR45P+qfIJavxQNIt5zhHPfMgHjX27OA3+l7rHDxqfMLBPxhtARwlyF+qx1IJiSWbmlHkdz2ylD9unoLSpf+DmmFvvgTj+3EEP4bY2jA/t91XFeG3uaTQSy3ryDvhbX21U7G2HGOEl9rCkmz+hG0YRB/6KxZZ0eMIDr7OWfpPEuHV8oYwDNYbsT9zCGsR1hHxBJtdo60b36mjMemtf761DhJ/oQZ4eU738yzx1hvVS3aCJsfyp70H5u+pUjgrA565uG2lEMNLu4T4NFVw0UdrVudyrhmT8P7vF4v+mR4pp+OzRbLf8AtZrKmHlMqRst+/wOHUHug/Tpz6EwZPDWGiQyFyPUkjHWW7ACouegBFOWFabsk+zCDhyxoSNrSMCtdB1L+qK72jRPGOvXk8p/1kBOIJfAjaK1ZWz8hTc30hOSWYxkRP296zPHiQF0ibNYSPNZ9tNxgq9nV/cEQ68TsNr3SULfDr0TSjCPf4AfmJ0k1k5xphSYv/TtGIbjg/9yGVFqclg4Y/6rrfkApbx36PQEBNxLiRsZ4hGpCfVU6h0jOekk8TV6CAguXVX/G31UqsAEa4sOD2g10Ir+5JD7bdd3JE/999kHGdiCqc0DNcgSqWYbq2QYwrN/mb+mMUbiQSNMcc34kK1n+7dGxppnt7YN7UsJqBWJdH0Lw1Epxi11ViTeVma9bqioJYXi6N5exdpZTT7KmcGYFsoTqO958EX6AppgcML7N9oP3TO8qSgCpV3Bbbemq4bvjV43aM6Rdx17pC4GZo0jjU97p4K8jE4PvgoHlYkuPwSJDOSAdnYPh+Inq/vCk48UfIlup0ATJFVUXD7uf84v9roZSwZPXZ5j/88+MkHBIJwPv8cugmz5uN2EuBW5IScMuEqG7Cmk72SU3/QA39G79S0Gpw7iPhTos5LXxhfvohGcnSaNEvfNeecQf7fpVciTdHwuvcgqJizUKpSFg2P+LDBiO44mJD15RNAaT37Rrj5P06YITO4PDj+FMdc6gx+JQUFbcSRhScE/0gfsVm0P1BYIH5q0k/QDgEVoerf/n19lITTzPib1F2OHP4hyF3BEq1pd9NwuPhhsVVqTVTK5MzFwFIOH7cwJyY7aBykmsWBavdb2J7UA5wjKqMHl1auUGPlNL+lZjqG4tw05bchtFAF+PGWQXJhJCtRSkkzTOCrLRyYyyI9mWYEjoc23cGLanlIs7WA1Nd0Jz+5RSNlf9Gtnd65yQp/W1eqY6yzURPHUUa7FrynyORmjaR9adT9utSQkXy8++IeDNzhMtFr+SqQ/gKECLe0GeuyTs6E5bImUtqpN+xopBXnEeq8wp+bvLf76d98qPE5ibTRwlsSyCE4c1Y7vrJrlc15Yc2R9ciIuKUS8rUKLSdGBFe/TD4R3cPhCKAnnRLGWnJiPPgxoTVwHVZMISdsAjNaWblBmiAOzFcu7443d3PCLyXVcfR9xgvW51HTumo91t5Qyx4HIXGoZxayZYFm2hrhSlieUqLnDL2j2gYgGU5NGoQl4OnEY2QqobpRUF4xJ4HhLzYbLrBeXmTDPvj0MasC3kKsRlm/HrsRRWZ2iPSMw9601tLvDfyjG53ddPISiVNnkdXcaAN5np7dwipdBOC1s4a0sEmKakNbkkDb8LsGBNte/g6UYs5yYaKr0bnXlDjMCznHQa7pypBjE7S55T3UeRpwo3IvZ1tfIGdb+z9RIA/PDvUksxJ3Xq3lqtZzkZJF5aeedfIOekGS/G0LiCSYsELgRceH5veknHqoGoL6xi4Q6/VjmfpZVXT19bDcTNtaR9Dlaq4LDjpQl9rl5C3O/X1hgADvJUuINCiLrD114sLY1DG/TDXE0sp+TK7utnjLAoHuAuj+6anY5vN66CSbwyUNmvo+m8li/AMkRYdtSDoPWkV7Y1ixMBPcua0Llwn2HSKKwnCjvhDIDIIVwbWwb1s6b9cztH81WF5RWUgFujewPvTElM1Sy10y7BcZohKw28uLRFVsKunc9yX2PiQoTSB4PHBHRA4U5dEQV3GHQJ93nee7VT3oeQPMVebWhuhOhi34Z33LQajzpCF3OjIbJb0tOPP6L6N/ODqkNsYViI3kgCnkNhexadOuGFWIqen2Q8iv2uOZWbPirt0YEeKZIk2dpND07L8Q3OsoQCk2rjpnw9LuFrjgu7gN9gFyPq25HJRBn7PM/lS60DF+xVkJq94PwN+CiZWC43SVcBGx65DFZIs/N78MZCUzZbFlsS7FsIrDJt878cp9eZdq/Ai4LZhL8QYHpVUrQxRxZGSqooA755N6nOxw66JkA1VPnjECCMgoNNtWox0JzhMe8PBdh2ZliXf8yQ6/eTvsG6FD84F+49pc7m0L99pfWHb9ClyO3KRHscp/MOIC1MJmqoB4dNxV20U+z8/lSTIvcmM8DiaAZj/yxlst90drlGydlyPjQzYd/XtIYcO5gHoeD1KUCZRapE5dkyk5vh97WZJn/JkR8hsslU3D6x3rNGwJbQVRu0IiA3PpeAQNZBNAJHHfv8IzIYxPhMJdYq0YqLIGSUYu87D04cDOxJY7hgawYs+ExOWb7XkbpuRoITQd8zpwVDFlSCS+wFO+qah3Vn8RBTc6cXHO5xRWfUNj+NrEtPdVmax+9EXqXtHQyFpxaauvL96RH+mGwpKHOk3aisXbZ6gLE2mF4egGjjJOIJdHyb2ZR+kj+4GIvkoBwipDgUfr4UBXY8pvFxQOxRgtI4LgOY9Z1Aco7Mwp6qi1KoMFJW8d+gJwsgM3cMsyEeYH1n/mdpJW6VDbIWzOHkP5n+OKKNm2vJTkQFFwF9eOtGy9fNBtS4qo4jvOUJnnAPsrPbGMbBYd1dMC3daHLEwvIKCAVBn7q1Z2c4zAD5eEoY0EwZj/j8x8lGQ8TswFT81ZotW7ZBDai/YtV8mkGfuaWJRI5yHc/bV7GWLF+yrMji/jicBF5jy2UoqwxseqjgTut49FRgBH3h1qwnfYbXD3FvQljyAAgBCiZV726pFRG+sZv0FjDbq0iCKILVSEUDZgmQ",
"shared":true,
"uploaded_signed_key_count":50
},
"sessions":[
{
"pickle":"cryZlFaQv0hwWe6tTgv75RExFKGnC8tMHBXJYMHOw4s+SdrKUYAMUdGcYD7QukrPklEOy7fJho9YGK/jV04QdA8JABiOfD+ngJTR4V8eZdmDuG08+Q5EL79V81hQwU2fKndP0y/9nAXPUIADYq0Zrg4EsOnXz7aE+hAeBAm0IBog1s8RYUvynZ15uwjbd/OTLP+gpqpX33DwVg2leiBkQetiUSpOpZCuQ8CcZwIA0MoGCqvaT7h76VHX9JxJx+2fCMhsJMx1nhd99WJH1W9ge5CtdbC4KUP92OSxIrPOnMrNcOPJPp/paZP+HFNQ3PDL+z8pGKXmCnrXGSbd7iPHurPYESrVkBzr",
"sender_key":"WJ6Ce7U67a6jqkHYHd8o0+5H4bqdi9hInZdk0+swuXs",
"created_using_fallback_key":false,
"creation_time":"1649425011424",
"last_use_time":"1649425011424"
"creation_time": 1649425011424u64,
"last_use_time": 1649425011424u64
},
{
"pickle":"cryZlFaQv0hwWe6tTgv75RExFKGnC8tMHBXJYMHOw4t2W/lowyrV6SXVZp+uG59im0AAfNSKjhjZuiOpQlX7MS+AOJkCNvyujJ2g3KSjLZ94IkoHxkBDHLWSjwaLPu40rfOzJPDpm0XZsR6bQrsxKOmXLGEw2qw5jOTouzMVL2gvuuTix97nSYSU8j3XvTMRUoh0AF/tUpRLcvEFZeGrdUYmTMlyTv4na+FVUalUZ+jrk8t1/sM99JNq3SY1IBSjrBq/0rCOHieiippz0sw2fe2b87id4rqj1g3R9w2MWTWEdOz3ugjMGYF1YDBQZA1tJZ/hmgppk2AU2xKQXE2X3DgSC6fC66D4",
"sender_key":"RzRROfmHNlBfzxnNCUYBfn/5oZNQ11XYjDg59hS+mV0",
"created_using_fallback_key":false,
"creation_time":"1649425011503",
"last_use_time":"1649425011503"
"creation_time": 1649425011503u64,
"last_use_time": 1649425011503u64
},
{
"pickle":"cryZlFaQv0hwWe6tTgv75RExFKGnC8tMHBXJYMHOw4titbL3SS12PYHpcBPJc6hXnOnZXqrjtjYOD545fck+3utEo8cqqwWubc9tsvxGW3tOWPttLBdAW30Vn8V1M8ebqVCNVWEAb1GKjV4ni8xG7G9SlEcCjLjnF4lJpddSZkqVMFoN0ITr9aSz/eJwXpc3HLreUFXwc8LuQp7krQ4Vt1e5EE/klduqsdurZf5V14RHsmWz2lKjt7nVgtIz/dhtF5F/sGJdg8kCGaHIMSbGAPuPPpa4/Laicb/5otrYt4pg4W4KdFpSGJIcvUQNjXaOZMx3cu/RPJIOyNhx7whG1QiYAUBqAJvr",
"sender_key":"IXSZugAHig1v8MowE1jxi2wDDDfuZBeJynHlegJVwUc",
"created_using_fallback_key":false,
"creation_time":"1649425011566",
"last_use_time":"1649425011566"
"creation_time": 1649425011566u64,
"last_use_time": 1649425011566u64
},
{
"pickle":"SmkDiFZjNukiarQ7XHQo25FILHsuhNOnxy56cMSQU/Y71jaGbJes4YrvN4Dfy4RSONfejEDXDkbW2JudlHHRP/rWEmnfJiGbK6ArbrG2puqIZgOecPnOUgPfCisr49p1Gmf36dPaO5lm/ZSrngfSoxahoeJJE/CcJN98sYM15XytRk2LBwc+CyYDqr4V1qxfsBt6tzJ4+tsAZeRdD0UtipQgysgH56o8N7nKTCkaZz5lfpYCl3FEgwXpLJ0MGQvtQmbORFvOLqR1jZ/EbmNGKiqDDIYsqG0sf78ii1jqfpLDBXLuYDccsg",
"sender_key":"EB9SC4jVAydKhM6/GcwMc9biKwVNywqW3TerNTrtb1M",
"created_using_fallback_key":false,
"creation_time":"1649542063182",
"last_use_time":"1649542063182"
"creation_time": 1649542063182u64,
"last_use_time": 1649542063182u64
}
],
"inbound_group_sessions":[
@@ -1010,7 +1148,8 @@ mod tests {
"JGgPQRuYj3ScMdPS+A0P+k/1qS9Hr3qeKXLscI+hS78"
);
let room_keys = machine.runtime.block_on(machine.inner.export_room_keys(|_| true))?;
let room_keys =
machine.runtime.block_on(machine.inner.store().export_room_keys(|_| true))?;
assert_eq!(room_keys.len(), 2);
let cross_signing_status = machine.cross_signing_status();
+2 -2
View File
@@ -7,7 +7,7 @@ use tracing_subscriber::{fmt::MakeWriter, EnvFilter};
/// Trait that can be used to forward Rust logs over FFI to a language specific
/// logger.
#[uniffi::export(callback_interface)]
#[matrix_sdk_ffi_macros::export(callback_interface)]
pub trait Logger: Send {
/// Called every time the Rust side wants to post a log line.
fn log(&self, log_line: String);
@@ -42,7 +42,7 @@ pub struct LoggerWrapper {
}
/// Set the logger that should be used to forward Rust logs over FFI.
#[uniffi::export]
#[matrix_sdk_ffi_macros::export]
pub fn set_logger(logger: Box<dyn Logger>) {
let logger = LoggerWrapper { inner: Arc::new(Mutex::new(logger)) };
+162 -80
View File
@@ -17,7 +17,8 @@ use matrix_sdk_crypto::{
decrypt_room_key_export, encrypt_room_key_export,
olm::ExportedRoomKey,
store::{BackupDecryptionKey, Changes},
LocalTrust, OlmMachine as InnerMachine, UserIdentities,
types::requests::ToDeviceRequest,
DecryptionSettings, LocalTrust, OlmMachine as InnerMachine, UserIdentity as SdkUserIdentity,
};
use ruma::{
api::{
@@ -37,10 +38,12 @@ use ruma::{
},
events::{
key::verification::VerificationMethod, room::message::MessageType, AnyMessageLikeEvent,
AnySyncMessageLikeEvent, AnyTimelineEvent, MessageLikeEvent,
AnySyncMessageLikeEvent, MessageLikeEvent,
},
serde::Raw,
DeviceKeyAlgorithm, EventId, OwnedTransactionId, OwnedUserId, RoomId, UserId,
to_device::DeviceIdOrAllDevices,
DeviceKeyAlgorithm, EventId, OneTimeKeyAlgorithm, OwnedTransactionId, OwnedUserId, RoomId,
UserId,
};
use serde::{Deserialize, Serialize};
use serde_json::{value::RawValue, Value};
@@ -176,7 +179,7 @@ impl From<RustSignatureCheckResult> for SignatureVerification {
}
}
#[uniffi::export]
#[matrix_sdk_ffi_macros::export]
impl OlmMachine {
/// Create a new `OlmMachine`
///
@@ -207,8 +210,12 @@ impl OlmMachine {
passphrase.zeroize();
let inner =
runtime.block_on(InnerMachine::with_store(&user_id, device_id, Arc::new(store)))?;
let inner = runtime.block_on(InnerMachine::with_store(
&user_id,
device_id,
Arc::new(store),
None,
))?;
Ok(Arc::new(OlmMachine { inner: ManuallyDrop::new(inner), runtime }))
}
@@ -246,12 +253,12 @@ impl OlmMachine {
///
/// * `user_id` - The unique id of the user that the identity belongs to
///
/// * `timeout` - The time in seconds we should wait before returning if
/// the user's device list has been marked as stale. Passing a 0 as the
/// timeout means that we won't wait at all. **Note**, this assumes that
/// the requests from [`OlmMachine::outgoing_requests`] are being processed
/// and sent out. Namely, this waits for a `/keys/query` response to be
/// received.
/// * `timeout` - The time in seconds we should wait before returning if the
/// user's device list has been marked as stale. Passing a 0 as the
/// timeout means that we won't wait at all. **Note**, this assumes that
/// the requests from [`OlmMachine::outgoing_requests`] are being
/// processed and sent out. Namely, this waits for a `/keys/query`
/// response to be received.
pub fn get_identity(
&self,
user_id: String,
@@ -280,10 +287,7 @@ impl OlmMachine {
if let Some(identity) =
self.runtime.block_on(self.inner.get_identity(&user_id, None))?
{
match identity {
UserIdentities::Own(i) => i.is_verified(),
UserIdentities::Other(i) => i.is_verified(),
}
identity.is_verified()
} else {
false
},
@@ -311,8 +315,8 @@ impl OlmMachine {
if let Some(user_identity) = user_identity {
Ok(match user_identity {
UserIdentities::Own(i) => self.runtime.block_on(i.verify())?,
UserIdentities::Other(i) => self.runtime.block_on(i.verify())?,
SdkUserIdentity::Own(i) => self.runtime.block_on(i.verify())?,
SdkUserIdentity::Other(i) => self.runtime.block_on(i.verify())?,
}
.into())
} else {
@@ -328,12 +332,12 @@ impl OlmMachine {
///
/// * `device_id` - The id of the device itself.
///
/// * `timeout` - The time in seconds we should wait before returning if
/// the user's device list has been marked as stale. Passing a 0 as the
/// timeout means that we won't wait at all. **Note**, this assumes that
/// the requests from [`OlmMachine::outgoing_requests`] are being processed
/// and sent out. Namely, this waits for a `/keys/query` response to be
/// received.
/// * `timeout` - The time in seconds we should wait before returning if the
/// user's device list has been marked as stale. Passing a 0 as the
/// timeout means that we won't wait at all. **Note**, this assumes that
/// the requests from [`OlmMachine::outgoing_requests`] are being
/// processed and sent out. Namely, this waits for a `/keys/query`
/// response to be received.
pub fn get_device(
&self,
user_id: String,
@@ -411,12 +415,12 @@ impl OlmMachine {
///
/// * `user_id` - The id of the device owner.
///
/// * `timeout` - The time in seconds we should wait before returning if
/// the user's device list has been marked as stale. Passing a 0 as the
/// timeout means that we won't wait at all. **Note**, this assumes that
/// the requests from [`OlmMachine::outgoing_requests`] are being processed
/// and sent out. Namely, this waits for a `/keys/query` response to be
/// received.
/// * `timeout` - The time in seconds we should wait before returning if the
/// user's device list has been marked as stale. Passing a 0 as the
/// timeout means that we won't wait at all. **Note**, this assumes that
/// the requests from [`OlmMachine::outgoing_requests`] are being
/// processed and sent out. Namely, this waits for a `/keys/query`
/// response to be received.
pub fn get_user_devices(
&self,
user_id: String,
@@ -512,7 +516,7 @@ impl OlmMachine {
/// current sync response.
///
/// * `device_changes` - The list of devices that have changed in some way
/// since the previous sync.
/// since the previous sync.
///
/// * `key_counts` - The map of uploaded one-time key types and counts.
pub fn receive_sync_changes(
@@ -525,11 +529,11 @@ impl OlmMachine {
) -> Result<SyncChangesResult, CryptoStoreError> {
let to_device: ToDevice = serde_json::from_str(&events)?;
let device_changes: RumaDeviceLists = device_changes.into();
let key_counts: BTreeMap<DeviceKeyAlgorithm, UInt> = key_counts
let key_counts: BTreeMap<OneTimeKeyAlgorithm, UInt> = key_counts
.into_iter()
.map(|(k, v)| {
(
DeviceKeyAlgorithm::from(k),
OneTimeKeyAlgorithm::from(k),
v.clamp(0, i32::MAX)
.try_into()
.expect("Couldn't convert key counts into an UInt"),
@@ -537,8 +541,8 @@ impl OlmMachine {
})
.collect();
let unused_fallback_keys: Option<Vec<DeviceKeyAlgorithm>> =
unused_fallback_keys.map(|u| u.into_iter().map(DeviceKeyAlgorithm::from).collect());
let unused_fallback_keys: Option<Vec<OneTimeKeyAlgorithm>> =
unused_fallback_keys.map(|u| u.into_iter().map(OneTimeKeyAlgorithm::from).collect());
let (to_device_events, room_key_infos) = self.runtime.block_on(
self.inner.receive_sync_changes(matrix_sdk_crypto::EncryptionSyncChanges {
@@ -603,7 +607,7 @@ impl OlmMachine {
/// # Arguments
///
/// * `users` - The list of users for which we would like to establish 1:1
/// Olm sessions for.
/// Olm sessions for.
pub fn get_missing_sessions(
&self,
users: Vec<String>,
@@ -724,11 +728,11 @@ impl OlmMachine {
/// # Arguments
///
/// * `room_id` - The unique id of the room, note that this doesn't strictly
/// need to be a Matrix room, it just needs to be an unique identifier for
/// the group that will participate in the conversation.
/// need to be a Matrix room, it just needs to be an unique identifier for
/// the group that will participate in the conversation.
///
/// * `users` - The list of users which are considered to be members of the
/// room and should receive the room key.
/// room and should receive the room key.
///
/// * `settings` - The settings that should be used for the room key.
pub fn share_room_key(
@@ -800,6 +804,53 @@ impl OlmMachine {
Ok(serde_json::to_string(&encrypted_content)?)
}
/// Encrypt the given event with the given type and content for the given
/// device. This method is used to send an event to a specific device.
///
/// # Arguments
///
/// * `user_id` - The ID of the user who owns the target device.
/// * `device_id` - The ID of the device to which the message will be sent.
/// * `event_type` - The event type.
/// * `content` - The serialized content of the event.
///
/// # Returns
/// A `Result` containing the request to be sent out if the encryption was
/// successful. If the device is not found, the result will be `Ok(None)`.
///
/// The caller should ensure that there is an olm session (see
/// `get_missing_sessions`) with the target device before calling this
/// method.
pub fn create_encrypted_to_device_request(
&self,
user_id: String,
device_id: String,
event_type: String,
content: String,
) -> Result<Option<Request>, CryptoStoreError> {
let user_id = parse_user_id(&user_id)?;
let device_id = device_id.as_str().into();
let content = serde_json::from_str(&content)?;
let device = self.runtime.block_on(self.inner.get_device(&user_id, device_id, None))?;
if let Some(device) = device {
let encrypted_content =
self.runtime.block_on(device.encrypt_event_raw(&event_type, &content))?;
let request = ToDeviceRequest::new(
user_id.as_ref(),
DeviceIdOrAllDevices::DeviceId(device_id.to_owned()),
"m.room.encrypted",
encrypted_content.cast(),
);
Ok(Some(request.into()))
} else {
Ok(None)
}
}
/// Decrypt the given event that was sent in the given room.
///
/// # Arguments
@@ -811,12 +862,14 @@ impl OlmMachine {
/// * `strict_shields` - If `true`, messages will be decorated with strict
/// warnings (use `false` to match legacy behaviour where unsafe keys have
/// lower severity warnings and unverified identities are not decorated).
/// * `decryption_settings` - The setting for decrypting messages.
pub fn decrypt_room_event(
&self,
event: String,
room_id: String,
handle_verification_events: bool,
strict_shields: bool,
decryption_settings: DecryptionSettings,
) -> Result<DecryptedEvent, DecryptionError> {
// Element Android wants only the content and the type and will create a
// decrypted event with those two itself, this struct makes sure we
@@ -832,10 +885,14 @@ impl OlmMachine {
let event: Raw<_> = serde_json::from_str(&event)?;
let room_id = RoomId::parse(room_id)?;
let decrypted = self.runtime.block_on(self.inner.decrypt_room_event(&event, &room_id))?;
let decrypted = self.runtime.block_on(self.inner.decrypt_room_event(
&event,
&room_id,
&decryption_settings,
))?;
if handle_verification_events {
if let Ok(AnyTimelineEvent::MessageLike(e)) = decrypted.event.deserialize() {
if let Ok(e) = decrypted.event.deserialize() {
match &e {
AnyMessageLikeEvent::RoomMessage(MessageLikeEvent::Original(
original_event,
@@ -853,8 +910,7 @@ impl OlmMachine {
}
}
let encryption_info =
decrypted.encryption_info.expect("Decrypted event didn't contain any encryption info");
let encryption_info = decrypted.encryption_info;
let event_json: Event<'_> = serde_json::from_str(decrypted.event.json().get())?;
@@ -883,7 +939,7 @@ impl OlmMachine {
/// # Arguments
///
/// * `event` - The undecryptable event that we would wish to request a room
/// key for.
/// key for.
///
/// * `room_id` - The id of the room the event was sent to.
pub fn request_room_key(
@@ -908,16 +964,16 @@ impl OlmMachine {
/// # Arguments
///
/// * `passphrase` - The passphrase that should be used to encrypt the key
/// export.
/// export.
///
/// * `rounds` - The number of rounds that should be used when expanding the
/// passphrase into an key.
/// passphrase into an key.
pub fn export_room_keys(
&self,
passphrase: String,
rounds: i32,
) -> Result<String, CryptoStoreError> {
let keys = self.runtime.block_on(self.inner.export_room_keys(|_| true))?;
let keys = self.runtime.block_on(self.inner.store().export_room_keys(|_| true))?;
let encrypted = encrypt_room_key_export(&keys, &passphrase, rounds as u32)
.map_err(CryptoStoreError::Serialization)?;
@@ -934,7 +990,7 @@ impl OlmMachine {
/// * `passphrase` - The passphrase that was used to encrypt the key export.
///
/// * `progress_listener` - A callback that can be used to introspect the
/// progress of the key import.
/// progress of the key import.
pub fn import_room_keys(
&self,
keys: String,
@@ -943,7 +999,7 @@ impl OlmMachine {
) -> Result<KeysImportResult, KeyImportError> {
let keys = Cursor::new(keys);
let keys = decrypt_room_key_export(keys, &passphrase)?;
self.import_room_keys_helper(keys, false, progress_listener)
self.import_room_keys_helper(keys, None, progress_listener)
}
/// Import room keys from the given serialized unencrypted key export.
@@ -953,22 +1009,52 @@ impl OlmMachine {
/// should be used if the room keys are coming from the server-side backup,
/// the method will mark all imported room keys as backed up.
///
/// **Note**: This has been deprecated. Use
/// [`OlmMachine::import_room_keys_from_backup`] instead.
///
/// # Arguments
///
/// * `keys` - The serialized version of the unencrypted key export.
///
/// * `progress_listener` - A callback that can be used to introspect the
/// progress of the key import.
/// progress of the key import.
pub fn import_decrypted_room_keys(
&self,
keys: String,
progress_listener: Box<dyn ProgressListener>,
) -> Result<KeysImportResult, KeyImportError> {
// Assume that the keys came from the current backup version.
let backup_version = self.runtime.block_on(self.inner.backup_machine().backup_version());
let keys: Vec<Value> = serde_json::from_str(&keys)?;
let keys = keys.into_iter().map(serde_json::from_value).filter_map(|k| k.ok()).collect();
self.import_room_keys_helper(keys, backup_version.as_deref(), progress_listener)
}
self.import_room_keys_helper(keys, true, progress_listener)
/// Import room keys from the given serialized unencrypted key export.
///
/// This method is the same as [`OlmMachine::import_room_keys`] but the
/// decryption step is skipped and should be performed by the caller. This
/// should be used if the room keys are coming from the server-side backup.
/// The method will mark all imported room keys as backed up.
///
/// # Arguments
///
/// * `keys` - The serialized version of the unencrypted key export.
///
/// * `backup_version` - The version of the backup that these keys came
/// from.
///
/// * `progress_listener` - A callback that can be used to introspect the
/// progress of the key import.
pub fn import_room_keys_from_backup(
&self,
keys: String,
backup_version: String,
progress_listener: Box<dyn ProgressListener>,
) -> Result<KeysImportResult, KeyImportError> {
let keys: Vec<Value> = serde_json::from_str(&keys)?;
let keys = keys.into_iter().map(serde_json::from_value).filter_map(|k| k.ok()).collect();
self.import_room_keys_helper(keys, Some(&backup_version), progress_listener)
}
/// Discard the currently active room key for the given room if there is
@@ -976,7 +1062,7 @@ impl OlmMachine {
pub fn discard_room_key(&self, room_id: String) -> Result<(), CryptoStoreError> {
let room_id = RoomId::parse(room_id)?;
self.runtime.block_on(self.inner.invalidate_group_session(&room_id))?;
self.runtime.block_on(self.inner.discard_room_key(&room_id))?;
Ok(())
}
@@ -1019,7 +1105,7 @@ impl OlmMachine {
/// # Arguments
///
/// * `user_id` - The ID of the user for which we would like to fetch the
/// verification requests.
/// verification requests.
pub fn get_verification_requests(&self, user_id: String) -> Vec<Arc<VerificationRequest>> {
let Ok(user_id) = UserId::parse(user_id) else {
return vec![];
@@ -1040,7 +1126,7 @@ impl OlmMachine {
/// # Arguments
///
/// * `user_id` - The ID of the user for which we would like to fetch the
/// verification requests.
/// verification requests.
///
/// * `flow_id` - The ID that uniquely identifies the verification flow.
pub fn get_verification_request(
@@ -1060,10 +1146,10 @@ impl OlmMachine {
/// # Arguments
///
/// * `user_id` - The ID of the user which we would like to request to
/// verify.
/// verify.
///
/// * `methods` - The list of verification methods we want to advertise to
/// support.
/// support.
pub fn verification_request_content(
&self,
user_id: String,
@@ -1076,8 +1162,7 @@ impl OlmMachine {
let methods = methods.into_iter().map(VerificationMethod::from).collect();
Ok(if let Some(identity) = identity.and_then(|i| i.other()) {
let content =
self.runtime.block_on(identity.verification_request_content(Some(methods)));
let content = identity.verification_request_content(Some(methods));
Some(serde_json::to_string(&content)?)
} else {
None
@@ -1090,18 +1175,18 @@ impl OlmMachine {
/// # Arguments
///
/// * `user_id` - The ID of the user which we would like to request to
/// verify.
/// verify.
///
/// * `room_id` - The ID of the room that represents a DM with the given
/// user.
/// user.
///
/// * `event_id` - The event ID of the `m.key.verification.request` event
/// that we sent out to request the verification to begin. The content for
/// this request can be created using the [verification_request_content()]
/// method.
/// that we sent out to request the verification to begin. The content for
/// this request can be created using the [verification_request_content()]
/// method.
///
/// * `methods` - The list of verification methods we advertised as
/// supported in the `m.key.verification.request` event.
/// supported in the `m.key.verification.request` event.
///
/// [verification_request_content()]: Self::verification_request_content
pub fn request_verification(
@@ -1120,11 +1205,7 @@ impl OlmMachine {
let methods = methods.into_iter().map(VerificationMethod::from).collect();
Ok(if let Some(identity) = identity.and_then(|i| i.other()) {
let request = self.runtime.block_on(identity.request_verification(
&room_id,
&event_id,
Some(methods),
));
let request = identity.request_verification(&room_id, &event_id, Some(methods));
Some(
VerificationRequest { inner: request, runtime: self.runtime.handle().to_owned() }
@@ -1140,12 +1221,12 @@ impl OlmMachine {
/// # Arguments
///
/// * `user_id` - The ID of the user which we would like to request to
/// verify.
/// verify.
///
/// * `device_id` - The ID of the device that we wish to verify.
///
/// * `methods` - The list of verification methods we advertised as
/// supported in the `m.key.verification.request` event.
/// supported in the `m.key.verification.request` event.
pub fn request_verification_with_device(
&self,
user_id: String,
@@ -1161,8 +1242,7 @@ impl OlmMachine {
if let Some(device) =
self.runtime.block_on(self.inner.get_device(&user_id, device_id, None))?
{
let (verification, request) =
self.runtime.block_on(device.request_verification_with_methods(methods));
let (verification, request) = device.request_verification_with_methods(methods);
Some(RequestVerificationResult {
verification: VerificationRequest {
@@ -1215,7 +1295,7 @@ impl OlmMachine {
/// # Arguments
///
/// * `user_id` - The ID of the user for which we would like to fetch the
/// verification.
/// verification.
///
/// * `flow_id` - The ID that uniquely identifies the verification flow.
pub fn get_verification(&self, user_id: String, flow_id: String) -> Option<Arc<Verification>> {
@@ -1235,7 +1315,7 @@ impl OlmMachine {
/// # Arguments
///
/// * `user_id` - The ID of the user for which we would like to start the
/// SAS verification.
/// SAS verification.
///
/// * `device_id` - The ID of device we would like to verify.
///
@@ -1458,16 +1538,18 @@ impl OlmMachine {
fn import_room_keys_helper(
&self,
keys: Vec<ExportedRoomKey>,
from_backup: bool,
from_backup_version: Option<&str>,
progress_listener: Box<dyn ProgressListener>,
) -> Result<KeysImportResult, KeyImportError> {
let listener = |progress: usize, total: usize| {
progress_listener.on_progress(progress as i32, total as i32)
};
#[allow(deprecated)]
let result =
self.runtime.block_on(self.inner.import_room_keys(keys, from_backup, listener))?;
let result = self.runtime.block_on(self.inner.store().import_room_keys(
keys,
from_backup_version,
listener,
))?;
Ok(KeysImportResult {
imported: result.imported_count as i64,
@@ -1,15 +0,0 @@
namespace matrix_sdk_crypto_ffi {};
enum LocalTrust {
"Verified",
"BlackListed",
"Ignored",
"Unset",
};
enum SignatureState {
"Missing",
"Invalid",
"ValidButNotTrusted",
"ValidAndTrusted",
};
+15 -13
View File
@@ -4,9 +4,12 @@ use std::collections::HashMap;
use http::Response;
use matrix_sdk_crypto::{
CrossSigningBootstrapRequests, IncomingResponse, KeysBackupRequest, OutgoingRequest,
OutgoingVerificationRequest as SdkVerificationRequest, RoomMessageRequest, ToDeviceRequest,
UploadSigningKeysRequest as RustUploadSigningKeysRequest,
types::requests::{
AnyIncomingResponse, KeysBackupRequest, OutgoingRequest,
OutgoingVerificationRequest as SdkVerificationRequest, RoomMessageRequest, ToDeviceRequest,
UploadSigningKeysRequest as RustUploadSigningKeysRequest,
},
CrossSigningBootstrapRequests,
};
use ruma::{
api::client::{
@@ -136,7 +139,7 @@ pub enum Request {
impl From<OutgoingRequest> for Request {
fn from(r: OutgoingRequest) -> Self {
use matrix_sdk_crypto::OutgoingRequests::*;
use matrix_sdk_crypto::types::requests::AnyOutgoingRequest::*;
match r.request() {
KeysUpload(u) => {
@@ -164,7 +167,6 @@ impl From<OutgoingRequest> for Request {
},
RoomMessage(r) => Request::from(r),
KeysClaim(c) => (r.request_id().to_owned(), c.clone()).into(),
KeysBackup(b) => (r.request_id().to_owned(), b.clone()).into(),
}
}
}
@@ -339,16 +341,16 @@ impl From<RoomMessageResponse> for OwnedResponse {
}
}
impl<'a> From<&'a OwnedResponse> for IncomingResponse<'a> {
impl<'a> From<&'a OwnedResponse> for AnyIncomingResponse<'a> {
fn from(r: &'a OwnedResponse) -> Self {
match r {
OwnedResponse::KeysClaim(r) => IncomingResponse::KeysClaim(r),
OwnedResponse::KeysQuery(r) => IncomingResponse::KeysQuery(r),
OwnedResponse::KeysUpload(r) => IncomingResponse::KeysUpload(r),
OwnedResponse::ToDevice(r) => IncomingResponse::ToDevice(r),
OwnedResponse::SignatureUpload(r) => IncomingResponse::SignatureUpload(r),
OwnedResponse::KeysBackup(r) => IncomingResponse::KeysBackup(r),
OwnedResponse::RoomMessage(r) => IncomingResponse::RoomMessage(r),
OwnedResponse::KeysClaim(r) => AnyIncomingResponse::KeysClaim(r),
OwnedResponse::KeysQuery(r) => AnyIncomingResponse::KeysQuery(r),
OwnedResponse::KeysUpload(r) => AnyIncomingResponse::KeysUpload(r),
OwnedResponse::ToDevice(r) => AnyIncomingResponse::ToDevice(r),
OwnedResponse::SignatureUpload(r) => AnyIncomingResponse::SignatureUpload(r),
OwnedResponse::KeysBackup(r) => AnyIncomingResponse::KeysBackup(r),
OwnedResponse::RoomMessage(r) => AnyIncomingResponse::RoomMessage(r),
}
}
}
+11 -5
View File
@@ -1,8 +1,8 @@
use matrix_sdk_crypto::{types::CrossSigningKey, UserIdentities};
use matrix_sdk_crypto::{types::CrossSigningKey, UserIdentity as SdkUserIdentity};
use crate::CryptoStoreError;
/// Enum representing cross signing identities of our own user or some other
/// Enum representing cross signing identity of our own user or some other
/// user.
#[derive(uniffi::Enum)]
pub enum UserIdentity {
@@ -18,6 +18,8 @@ pub enum UserIdentity {
user_signing_key: String,
/// The public self-signing key of our identity.
self_signing_key: String,
/// True if this identity was verified at some point but is not anymore.
has_verification_violation: bool,
},
/// The user identity of other users.
Other {
@@ -27,13 +29,15 @@ pub enum UserIdentity {
master_key: String,
/// The public self-signing key of our identity.
self_signing_key: String,
/// True if this identity was verified at some point but is not anymore.
has_verification_violation: bool,
},
}
impl UserIdentity {
pub(crate) async fn from_rust(i: UserIdentities) -> Result<Self, CryptoStoreError> {
pub(crate) async fn from_rust(i: SdkUserIdentity) -> Result<Self, CryptoStoreError> {
Ok(match i {
UserIdentities::Own(i) => {
SdkUserIdentity::Own(i) => {
let master: CrossSigningKey = i.master_key().as_ref().to_owned();
let user_signing: CrossSigningKey = i.user_signing_key().as_ref().to_owned();
let self_signing: CrossSigningKey = i.self_signing_key().as_ref().to_owned();
@@ -44,9 +48,10 @@ impl UserIdentity {
master_key: serde_json::to_string(&master)?,
user_signing_key: serde_json::to_string(&user_signing)?,
self_signing_key: serde_json::to_string(&self_signing)?,
has_verification_violation: i.has_verification_violation(),
}
}
UserIdentities::Other(i) => {
SdkUserIdentity::Other(i) => {
let master: CrossSigningKey = i.master_key().as_ref().to_owned();
let self_signing: CrossSigningKey = i.self_signing_key().as_ref().to_owned();
@@ -54,6 +59,7 @@ impl UserIdentity {
user_id: i.user_id().to_string(),
master_key: serde_json::to_string(&master)?,
self_signing_key: serde_json::to_string(&self_signing)?,
has_verification_violation: i.has_verification_violation(),
}
}
})
@@ -15,7 +15,7 @@ use crate::{CryptoStoreError, OutgoingVerificationRequest, SignatureUploadReques
/// Listener that will be passed over the FFI to report changes to a SAS
/// verification.
#[uniffi::export(callback_interface)]
#[matrix_sdk_ffi_macros::export(callback_interface)]
pub trait SasListener: Send {
/// The callback that should be called on the Rust side
///
@@ -28,8 +28,11 @@ pub trait SasListener: Send {
/// An Enum describing the state the SAS verification is in.
#[derive(uniffi::Enum)]
pub enum SasState {
/// The verification has been started, the protocols that should be used
/// have been proposed and can be accepted.
/// The verification has been created, the protocols that should be used
/// have been proposed to the other party.
Created,
/// The verification has been started, the other party proposed the
/// protocols that should be used and that can be accepted.
Started,
/// The verification has been accepted and both sides agreed to a set of
/// protocols that will be used for the verification process.
@@ -58,6 +61,7 @@ pub enum SasState {
impl From<RustSasState> for SasState {
fn from(s: RustSasState) -> Self {
match s {
RustSasState::Created { .. } => Self::Created,
RustSasState::Started { .. } => Self::Started,
RustSasState::Accepted { .. } => Self::Accepted,
RustSasState::KeysExchanged { emojis, decimals } => Self::KeysExchanged {
@@ -78,7 +82,7 @@ pub struct Verification {
pub(crate) runtime: Handle,
}
#[uniffi::export]
#[matrix_sdk_ffi_macros::export]
impl Verification {
/// Try to represent the `Verification` as an `Sas` verification object,
/// returns `None` if the verification is not a `Sas` verification.
@@ -108,7 +112,7 @@ pub struct Sas {
pub(crate) runtime: Handle,
}
#[uniffi::export]
#[matrix_sdk_ffi_macros::export]
impl Sas {
/// Get the user id of the other side.
pub fn other_user_id(&self) -> String {
@@ -165,8 +169,8 @@ impl Sas {
/// # Arguments
///
/// * `cancel_code` - The error code for why the verification was cancelled,
/// manual cancellatio usually happens with `m.user` cancel code. The full
/// list of cancel codes can be found in the [spec]
/// manual cancellatio usually happens with `m.user` cancel code. The full
/// list of cancel codes can be found in the [spec]
///
/// [spec]: https://spec.matrix.org/unstable/client-server-api/#mkeyverificationcancel
pub fn cancel(&self, cancel_code: String) -> Option<OutgoingVerificationRequest> {
@@ -272,7 +276,7 @@ impl Sas {
/// Listener that will be passed over the FFI to report changes to a QrCode
/// verification.
#[uniffi::export(callback_interface)]
#[matrix_sdk_ffi_macros::export(callback_interface)]
pub trait QrCodeListener: Send {
/// The callback that should be called on the Rust side
///
@@ -324,7 +328,7 @@ pub struct QrCode {
pub(crate) runtime: Handle,
}
#[uniffi::export]
#[matrix_sdk_ffi_macros::export]
impl QrCode {
/// Get the user id of the other side.
pub fn other_user_id(&self) -> String {
@@ -387,8 +391,8 @@ impl QrCode {
/// # Arguments
///
/// * `cancel_code` - The error code for why the verification was cancelled,
/// manual cancellatio usually happens with `m.user` cancel code. The full
/// list of cancel codes can be found in the [spec]
/// manual cancellatio usually happens with `m.user` cancel code. The full
/// list of cancel codes can be found in the [spec]
///
/// [spec]: https://spec.matrix.org/unstable/client-server-api/#mkeyverificationcancel
pub fn cancel(&self, cancel_code: String) -> Option<OutgoingVerificationRequest> {
@@ -518,7 +522,7 @@ pub struct ConfirmVerificationResult {
/// Listener that will be passed over the FFI to report changes to a
/// verification request.
#[uniffi::export(callback_interface)]
#[matrix_sdk_ffi_macros::export(callback_interface)]
pub trait VerificationRequestListener: Send {
/// The callback that should be called on the Rust side
///
@@ -558,7 +562,7 @@ pub struct VerificationRequest {
pub(crate) runtime: Handle,
}
#[uniffi::export]
#[matrix_sdk_ffi_macros::export]
impl VerificationRequest {
/// The id of the other user that is participating in this verification
/// request.
@@ -636,12 +640,12 @@ impl VerificationRequest {
/// # Arguments
///
/// * `user_id` - The ID of the user for which we would like to accept the
/// verification requests.
/// verification requests.
///
/// * `flow_id` - The ID that uniquely identifies the verification flow.
///
/// * `methods` - A list of verification methods that we want to advertise
/// as supported.
/// as supported.
pub fn accept(&self, methods: Vec<String>) -> Option<OutgoingVerificationRequest> {
let methods = methods.into_iter().map(VerificationMethod::from).collect();
self.inner.accept_with_methods(methods).map(|r| r.into())
@@ -659,10 +663,10 @@ impl VerificationRequest {
/// # Arguments
///
/// * `user_id` - The ID of the user for which we would like to start the
/// SAS verification.
/// SAS verification.
///
/// * `flow_id` - The ID of the verification request that initiated the
/// verification flow.
/// verification flow.
pub fn start_sas_verification(&self) -> Result<Option<StartSasResult>, CryptoStoreError> {
Ok(self.runtime.block_on(self.inner.start_sas())?.map(|(sas, r)| StartSasResult {
sas: Arc::new(Sas { inner: sas, runtime: self.runtime.clone() }),
@@ -677,11 +681,11 @@ impl VerificationRequest {
///
/// # Arguments
///
/// * `user_id` - The ID of the user for which we would like to start the
/// QR code verification.
/// * `user_id` - The ID of the user for which we would like to start the QR
/// code verification.
///
/// * `flow_id` - The ID of the verification request that initiated the
/// verification flow.
/// verification flow.
pub fn start_qr_verification(&self) -> Result<Option<Arc<QrCode>>, CryptoStoreError> {
Ok(self
.runtime
@@ -697,14 +701,14 @@ impl VerificationRequest {
///
/// # Arguments
///
/// * `user_id` - The ID of the user for which we would like to start the
/// QR code verification.
/// * `user_id` - The ID of the user for which we would like to start the QR
/// code verification.
///
/// * `flow_id` - The ID of the verification request that initiated the
/// verification flow.
/// verification flow.
///
/// * `data` - The data that was extracted from the scanned QR code as an
/// base64 encoded string, without padding.
/// base64 encoded string, without padding.
pub fn scan_qr_code(&self, data: String) -> Option<ScanResult> {
let data = base64_decode(data).ok()?;
let data = QrVerificationData::from_bytes(data).ok()?;
@@ -748,7 +752,7 @@ impl VerificationRequest {
RustVerificationRequestState::Ready {
their_methods,
our_methods,
other_device_id: _,
other_device_data: _,
} => VerificationRequestState::Ready {
their_methods: their_methods.iter().map(|m| m.to_string()).collect(),
our_methods: our_methods.iter().map(|m| m.to_string()).collect(),
@@ -0,0 +1,3 @@
fn main() {
uniffi::uniffi_bindgen_main()
}
+24
View File
@@ -0,0 +1,24 @@
[package]
description = "Helper macros to write FFI bindings"
edition = "2021"
homepage = "https://github.com/matrix-org/matrix-rust-sdk"
keywords = ["matrix", "chat", "messaging", "ruma"]
license = "Apache-2.0"
name = "matrix-sdk-ffi-macros"
readme = "README.md"
repository = "https://github.com/matrix-org/matrix-rust-sdk"
rust-version = { workspace = true }
version = "0.7.0"
[lib]
proc-macro = true
test = false
doctest = false
[dependencies]
proc-macro2 = "1.0.86"
quote = "1.0.18"
syn = { version = "2.0.43", features = ["full", "extra-traits"] }
[lints]
workspace = true
+14
View File
@@ -0,0 +1,14 @@
[![Build Status](https://img.shields.io/travis/matrix-org/matrix-rust-sdk.svg?style=flat-square)](https://travis-ci.org/matrix-org/matrix-rust-sdk)
[![codecov](https://img.shields.io/codecov/c/github/matrix-org/matrix-rust-sdk/main.svg?style=flat-square)](https://codecov.io/gh/matrix-org/matrix-rust-sdk)
[![License](https://img.shields.io/badge/License-Apache%202.0-yellowgreen.svg?style=flat-square)](https://opensource.org/licenses/Apache-2.0)
[![#matrix-rust-sdk](https://img.shields.io/badge/matrix-%23matrix--rust--sdk-blue?style=flat-square)](https://matrix.to/#/#matrix-rust-sdk:matrix.org)
# matrix-sdk-ffi-macros
Internal macros used for the FFI layer (bindings) of the Rust Matrix SDK.
**NOTE:** These are just macros that help build the matrix-rust-sdk bindings, you're probably
interested in the main [rust-sdk](https://github.com/matrix-org/matrix-rust-sdk/) crate.
[Matrix]: https://matrix.org/
[Rust]: https://www.rust-lang.org/
+65
View File
@@ -0,0 +1,65 @@
// Copyright 2024 The Matrix.org Foundation C.I.C.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use proc_macro::TokenStream;
use quote::quote;
use syn::{ImplItem, Item, TraitItem};
/// Attribute to specify the async runtime parameter for the `uniffi`
/// export macros if there any `async fn`s in the input.
#[proc_macro_attribute]
pub fn export(attr: TokenStream, item: TokenStream) -> TokenStream {
let has_async_fn = |item| {
if let Item::Fn(fun) = &item {
if fun.sig.asyncness.is_some() {
return true;
}
} else if let Item::Impl(blk) = &item {
for item in &blk.items {
if let ImplItem::Fn(fun) = item {
if fun.sig.asyncness.is_some() {
return true;
}
}
}
} else if let Item::Trait(blk) = &item {
for item in &blk.items {
if let TraitItem::Fn(fun) = item {
if fun.sig.asyncness.is_some() {
return true;
}
}
}
}
false
};
let attr2 = proc_macro2::TokenStream::from(attr);
let item2 = proc_macro2::TokenStream::from(item.clone());
let res = match syn::parse(item) {
Ok(item) => match has_async_fn(item) {
true => quote! { #[uniffi::export(async_runtime = "tokio", #attr2)] },
false => quote! { #[uniffi::export(#attr2)] },
},
Err(e) => e.into_compile_error(),
};
quote! {
#res
#item2
}
.into()
}
+36
View File
@@ -0,0 +1,36 @@
# unreleased
Breaking changes:
- `EventSendState` now has two additional variants: `CrossSigningNotSetup` and
`SendingFromUnverifiedDevice`. These indicate that your own device is not
properly cross-signed, which is a requirement when using the identity-based
strategy, and can only be returned when using the identity-based strategy.
In addition, the `VerifiedUserHasUnsignedDevice` and
`VerifiedUserChangedIdentity` variants can be returned when using the
identity-based strategy, in addition to when using the device-based strategy
with `error_on_verified_user_problem` is set.
- `EventSendState` now has two additional variants: `VerifiedUserHasUnsignedDevice` and
`VerifiedUserChangedIdentity`. These reflect problems with verified users in the room
and as such can only be returned when the room key recipient strategy has
`error_on_verified_user_problem` set.
- The `AuthenticationService` has been removed:
- Instead of calling `configure_homeserver`, build your own client with the `serverNameOrHomeserverUrl` builder
method to keep the same behaviour.
- The parts of `AuthenticationError` related to discovery will be represented in the `ClientBuildError` returned
when calling `build()`.
- The remaining methods can be found on the built `Client`.
- There is a new `abortOidcLogin` method that should be called if the webview is dismissed without a callback (
or fails to present).
- The rest of `AuthenticationError` is now found in the OidcError type.
- `OidcAuthenticationData` is now called `OidcAuthorizationData`.
- The `get_element_call_required_permissions` function now requires the device_id.
Additions:
- Add `Encryption::get_user_identity` which returns `UserIdentity`
- Add `ClientBuilder::room_key_recipient_strategy`
- Add `Room::send_raw`
+14 -13
View File
@@ -24,37 +24,30 @@ vergen = { version = "8.1.3", features = ["build", "git", "gitcl"] }
anyhow = { workspace = true }
as_variant = { workspace = true }
async-compat = "0.2.1"
base64 = "0.21"
eyeball-im = { workspace = true }
extension-trait = "1.0.1"
futures-core = { workspace = true }
futures-util = { workspace = true }
matrix-sdk-ui = { workspace = true, features = ["e2e-encryption", "uniffi"] }
log-panics = { version = "2", features = ["with-backtrace"] }
matrix-sdk-ffi-macros = { workspace = true }
matrix-sdk-ui = { workspace = true, features = ["uniffi"] }
mime = "0.3.16"
once_cell = { workspace = true }
opentelemetry = "0.21.0"
opentelemetry_sdk = { version = "0.21.0", features = ["rt-tokio"] }
opentelemetry-otlp = { version = "0.14.0", features = ["tokio", "reqwest-client", "http-proto"] }
ruma = { workspace = true, features = ["html", "unstable-unspecified", "unstable-msc3488", "compat-unset-avatar", "unstable-msc3245-v1-compat"] }
sanitize-filename-reader-friendly = "2.2.1"
serde = { workspace = true }
serde_json = { workspace = true }
thiserror = { workspace = true }
tracing = { workspace = true }
tracing-core = { workspace = true }
tracing-opentelemetry = "0.22.0"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
tracing-subscriber = { workspace = true, features = ["env-filter"] }
tracing-appender = { version = "0.2.2" }
tokio = { version = "1", features = ["rt-multi-thread", "macros"] }
tokio-stream = { workspace = true, features = ["time"] }
tokio = { workspace = true, features = ["rt-multi-thread", "macros"] }
uniffi = { workspace = true, features = ["tokio"] }
url = "2.2.2"
url = { workspace = true }
zeroize = { workspace = true }
uuid = { version = "1.4.1", features = ["v4"] }
language-tags = "0.3.2"
[target.'cfg(target_os = "android")'.dependencies]
log-panics = { version = "2", features = ["with-backtrace"] }
paranoid-android = "0.2.1"
[target.'cfg(target_os = "android")'.dependencies.matrix-sdk]
@@ -69,6 +62,7 @@ features = [
"rustls-tls", # note: differ from block below
"socks",
"sqlite",
"uniffi",
]
[target.'cfg(not(target_os = "android"))'.dependencies.matrix-sdk]
@@ -83,4 +77,11 @@ features = [
"native-tls", # note: differ from block above
"socks",
"sqlite",
"uniffi",
]
[lints]
workspace = true
[package.metadata.release]
release = false
-8
View File
@@ -2,14 +2,6 @@
This uses [`uniffi`](https://mozilla.github.io/uniffi-rs/Overview.html) to build the matrix bindings for native support and wasm-bindgen for web-browser assembly support. Please refer to the specific section to figure out how to build and use the bindings for your platform.
# OpenTelemetry support
The bindings have support for OpenTelemetry, allowing for the upload of traces to
any OpenTelemetry collector. This support is provided through the
[`opentelemetry`](https://docs.rs/opentelemetry/latest/opentelemetry/)
crate, which requires the [`protoc`] binary to be installed during the build
process.
## Platforms
### Swift/iOS sync
+39 -17
View File
@@ -1,34 +1,56 @@
use std::{env, error::Error};
use std::{env, error::Error, path::PathBuf, process::Command};
use vergen::EmitBuilder;
/// Adds a temporary workaround for an issue with the Rust compiler and Android
/// in x86_64 devices: https://github.com/rust-lang/rust/issues/109717.
/// The workaround comes from: https://github.com/mozilla/application-services/pull/5442
/// The workaround is based on: https://github.com/mozilla/application-services/pull/5442
///
/// IMPORTANT: if you modify this, make sure to modify
/// [../matrix-sdk-crypto-ffi/build.rs] too!
fn setup_x86_64_android_workaround() {
let target_os = env::var("CARGO_CFG_TARGET_OS").expect("CARGO_CFG_TARGET_OS not set");
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").expect("CARGO_CFG_TARGET_ARCH not set");
if target_arch == "x86_64" && target_os == "android" {
let android_ndk_home = env::var("ANDROID_NDK_HOME").expect("ANDROID_NDK_HOME not set");
let build_os = match env::consts::OS {
"linux" => "linux",
"macos" => "darwin",
"windows" => "windows",
_ => panic!(
"Unsupported OS. You must use either Linux, MacOS or Windows to build the crate."
),
};
const DEFAULT_CLANG_VERSION: &str = "14.0.7";
let clang_version =
env::var("NDK_CLANG_VERSION").unwrap_or_else(|_| DEFAULT_CLANG_VERSION.to_owned());
let linux_x86_64_lib_dir = format!(
"toolchains/llvm/prebuilt/{build_os}-x86_64/lib64/clang/{clang_version}/lib/linux/"
// Configure rust to statically link against the `libclang_rt.builtins` supplied
// with clang.
// cargo-ndk sets CC_x86_64-linux-android to the path to `clang`, within the
// Android NDK.
let clang_path = PathBuf::from(
env::var("CC_x86_64-linux-android").expect("CC_x86_64-linux-android not set"),
);
println!("cargo:rustc-link-search={android_ndk_home}/{linux_x86_64_lib_dir}");
// clang_path should now look something like
// `.../sdk/ndk/28.0.12674087/toolchains/llvm/prebuilt/linux-x86_64/bin/clang`.
// We strip `/bin/clang` from the end to get the toolchain path.
let toolchain_path = clang_path
.ancestors()
.nth(2)
.expect("could not find NDK toolchain path")
.to_str()
.expect("NDK toolchain path is not valid UTF-8");
let clang_version = get_clang_major_version(&clang_path);
println!("cargo:rustc-link-search={toolchain_path}/lib/clang/{clang_version}/lib/linux/");
println!("cargo:rustc-link-lib=static=clang_rt.builtins-x86_64-android");
}
}
/// Run the clang binary at `clang_path`, and return its major version number
fn get_clang_major_version(clang_path: &PathBuf) -> String {
let clang_output =
Command::new(clang_path).arg("-dumpversion").output().expect("failed to start clang");
if !clang_output.status.success() {
panic!("failed to run clang: {}", String::from_utf8_lossy(&clang_output.stderr));
}
let clang_version = String::from_utf8(clang_output.stdout).expect("clang output is not utf8");
clang_version.split('.').next().expect("could not parse clang output").to_owned()
}
fn main() -> Result<(), Box<dyn Error>> {
setup_x86_64_android_workaround();
uniffi::generate_scaffolding("./src/api.udl").expect("Building the UDL file failed");
-7
View File
@@ -13,10 +13,3 @@ interface RoomMessageEventContentWithoutRelation {
interface ClientError {
Generic(string msg);
};
interface MediaSource {
[Name=from_json, Throws=ClientError]
constructor(string json);
string to_json();
string url();
};
@@ -0,0 +1,243 @@
use std::{
collections::HashMap,
fmt::{self, Debug},
sync::Arc,
};
use matrix_sdk::{
oidc::{
registrations::OidcRegistrationsError,
types::{
iana::oauth::OAuthClientAuthenticationMethod,
oidc::ApplicationType,
registration::{ClientMetadata, Localized, VerifiedClientMetadata},
requests::GrantType,
},
OidcError as SdkOidcError,
},
Error,
};
use url::Url;
use crate::client::{Client, OidcPrompt, SlidingSyncVersion};
#[derive(uniffi::Object)]
pub struct HomeserverLoginDetails {
pub(crate) url: String,
pub(crate) sliding_sync_version: SlidingSyncVersion,
pub(crate) supports_oidc_login: bool,
pub(crate) supported_oidc_prompts: Vec<OidcPrompt>,
pub(crate) supports_password_login: bool,
}
#[matrix_sdk_ffi_macros::export]
impl HomeserverLoginDetails {
/// The URL of the currently configured homeserver.
pub fn url(&self) -> String {
self.url.clone()
}
/// The sliding sync version.
pub fn sliding_sync_version(&self) -> SlidingSyncVersion {
self.sliding_sync_version.clone()
}
/// Whether the current homeserver supports login using OIDC.
pub fn supports_oidc_login(&self) -> bool {
self.supports_oidc_login
}
/// The prompts advertised by the authentication issuer for use in the login
/// URL.
pub fn supported_oidc_prompts(&self) -> Vec<OidcPrompt> {
self.supported_oidc_prompts.clone()
}
/// Whether the current homeserver supports the password login flow.
pub fn supports_password_login(&self) -> bool {
self.supports_password_login
}
}
/// An object encapsulating the SSO login flow
#[derive(uniffi::Object)]
pub struct SsoHandler {
/// The wrapped Client.
pub(crate) client: Arc<Client>,
/// The underlying URL for authentication.
pub(crate) url: String,
}
#[matrix_sdk_ffi_macros::export]
impl SsoHandler {
/// Returns the URL for starting SSO authentication. The URL should be
/// opened in a web view. Once the web view succeeds, call `finish` with
/// the callback URL.
pub fn url(&self) -> String {
self.url.clone()
}
/// Completes the SSO login process.
pub async fn finish(&self, callback_url: String) -> Result<(), SsoError> {
let auth = self.client.inner.matrix_auth();
let url = Url::parse(&callback_url).map_err(|_| SsoError::CallbackUrlInvalid)?;
let builder =
auth.login_with_sso_callback(url).map_err(|_| SsoError::CallbackUrlInvalid)?;
builder.await.map_err(|_| SsoError::LoginWithTokenFailed)?;
Ok(())
}
}
impl Debug for SsoHandler {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
fmt.debug_struct("SsoHandler").field("url", &self.url).finish_non_exhaustive()
}
}
#[derive(Debug, thiserror::Error, uniffi::Error)]
#[uniffi(flat_error)]
pub enum SsoError {
#[error("The supplied callback URL used to complete SSO is invalid.")]
CallbackUrlInvalid,
#[error("Logging in with the token from the supplied callback URL failed.")]
LoginWithTokenFailed,
#[error("An error occurred: {message}")]
Generic { message: String },
}
/// The configuration to use when authenticating with OIDC.
#[derive(uniffi::Record)]
pub struct OidcConfiguration {
/// The name of the client that will be shown during OIDC authentication.
pub client_name: Option<String>,
/// The redirect URI that will be used when OIDC authentication is
/// successful.
pub redirect_uri: String,
/// A URI that contains information about the client.
pub client_uri: Option<String>,
/// A URI that contains the client's logo.
pub logo_uri: Option<String>,
/// A URI that contains the client's terms of service.
pub tos_uri: Option<String>,
/// A URI that contains the client's privacy policy.
pub policy_uri: Option<String>,
/// An array of e-mail addresses of people responsible for this client.
pub contacts: Option<Vec<String>>,
/// Pre-configured registrations for use with issuers that don't support
/// dynamic client registration.
pub static_registrations: HashMap<String, String>,
/// A file path where any dynamic registrations should be stored.
///
/// Suggested value: `{base_path}/oidc/registrations.json`
pub dynamic_registrations_file: String,
}
impl TryInto<VerifiedClientMetadata> for &OidcConfiguration {
type Error = OidcError;
fn try_into(self) -> Result<VerifiedClientMetadata, Self::Error> {
let redirect_uri =
Url::parse(&self.redirect_uri).map_err(|_| OidcError::CallbackUrlInvalid)?;
let client_name = self.client_name.as_ref().map(|n| Localized::new(n.to_owned(), []));
let client_uri = self.client_uri.localized_url()?;
let logo_uri = self.logo_uri.localized_url()?;
let policy_uri = self.policy_uri.localized_url()?;
let tos_uri = self.tos_uri.localized_url()?;
let contacts = self.contacts.clone();
ClientMetadata {
application_type: Some(ApplicationType::Native),
redirect_uris: Some(vec![redirect_uri]),
grant_types: Some(vec![
GrantType::RefreshToken,
GrantType::AuthorizationCode,
GrantType::DeviceCode,
]),
// A native client shouldn't use authentication as the credentials could be intercepted.
token_endpoint_auth_method: Some(OAuthClientAuthenticationMethod::None),
// The server should display the following fields when getting the user's consent.
client_name,
contacts,
client_uri,
logo_uri,
policy_uri,
tos_uri,
..Default::default()
}
.validate()
.map_err(|_| OidcError::MetadataInvalid)
}
}
#[derive(Debug, thiserror::Error, uniffi::Error)]
#[uniffi(flat_error)]
pub enum OidcError {
#[error(
"The homeserver doesn't provide an authentication issuer in its well-known configuration."
)]
NotSupported,
#[error("Unable to use OIDC as the supplied client metadata is invalid.")]
MetadataInvalid,
#[error("Failed to use the supplied registrations file path.")]
RegistrationsPathInvalid,
#[error("The supplied callback URL used to complete OIDC is invalid.")]
CallbackUrlInvalid,
#[error("The OIDC login was cancelled by the user.")]
Cancelled,
#[error("An error occurred: {message}")]
Generic { message: String },
}
impl From<SdkOidcError> for OidcError {
fn from(e: SdkOidcError) -> OidcError {
match e {
SdkOidcError::MissingAuthenticationIssuer => OidcError::NotSupported,
SdkOidcError::MissingRedirectUri => OidcError::MetadataInvalid,
SdkOidcError::InvalidCallbackUrl => OidcError::CallbackUrlInvalid,
SdkOidcError::InvalidState => OidcError::CallbackUrlInvalid,
SdkOidcError::CancelledAuthorization => OidcError::Cancelled,
_ => OidcError::Generic { message: e.to_string() },
}
}
}
impl From<OidcRegistrationsError> for OidcError {
fn from(e: OidcRegistrationsError) -> OidcError {
match e {
OidcRegistrationsError::InvalidFilePath => OidcError::RegistrationsPathInvalid,
_ => OidcError::Generic { message: e.to_string() },
}
}
}
impl From<Error> for OidcError {
fn from(e: Error) -> OidcError {
match e {
Error::Oidc(e) => e.into(),
_ => OidcError::Generic { message: e.to_string() },
}
}
}
/* Helpers */
trait OptionExt {
/// Convenience method to convert a string to a URL and returns it as a
/// Localized URL. No localization is actually performed.
fn localized_url(&self) -> Result<Option<Localized<Url>>, OidcError>;
}
impl OptionExt for Option<String> {
fn localized_url(&self) -> Result<Option<Localized<Url>>, OidcError> {
self.as_deref()
.map(|uri| -> Result<Localized<Url>, OidcError> {
Ok(Localized::new(Url::parse(uri).map_err(|_| OidcError::MetadataInvalid)?, []))
})
.transpose()
}
}
@@ -1,615 +0,0 @@
use std::{
collections::HashMap,
sync::{Arc, RwLock},
};
use matrix_sdk::{
oidc::{
types::{
client_credentials::ClientCredentials,
errors::ClientErrorCode::AccessDenied,
iana::oauth::OAuthClientAuthenticationMethod,
oidc::ApplicationType,
registration::{ClientMetadata, Localized, VerifiedClientMetadata},
requests::{GrantType, Prompt},
},
AuthorizationResponse, Oidc, OidcError,
},
AuthSession,
};
use matrix_sdk_ui::authentication::oidc::{ClientId, OidcRegistrations, OidcRegistrationsError};
use ruma::{
api::client::discovery::discover_homeserver::AuthenticationServerInfo, IdParseError,
OwnedUserId,
};
use url::Url;
use zeroize::Zeroize;
use super::{client::Client, client_builder::ClientBuilder, RUNTIME};
use crate::{client::ClientSessionDelegate, client_builder::UrlScheme, error::ClientError};
#[derive(uniffi::Object)]
pub struct AuthenticationService {
base_path: String,
passphrase: Option<String>,
user_agent: Option<String>,
client: RwLock<Option<Arc<Client>>>,
homeserver_details: RwLock<Option<Arc<HomeserverLoginDetails>>>,
oidc_configuration: Option<OidcConfiguration>,
custom_sliding_sync_proxy: RwLock<Option<String>>,
cross_process_refresh_lock_id: Option<String>,
session_delegate: Option<Arc<dyn ClientSessionDelegate>>,
}
impl Drop for AuthenticationService {
fn drop(&mut self) {
self.passphrase.zeroize();
}
}
#[derive(Debug, thiserror::Error, uniffi::Error)]
#[uniffi(flat_error)]
pub enum AuthenticationError {
#[error("A successful call to configure_homeserver must be made first.")]
ClientMissing,
#[error("{message}")]
InvalidServerName { message: String },
#[error("The homeserver doesn't provide a trusted sliding sync proxy in its well-known configuration.")]
SlidingSyncNotAvailable,
#[error("Login was successful but is missing a valid Session to configure the file store.")]
SessionMissing,
#[error("Failed to use the supplied base path.")]
InvalidBasePath,
#[error(
"The homeserver doesn't provide an authentication issuer in its well-known configuration."
)]
OidcNotSupported,
#[error("Unable to use OIDC as no client metadata has been supplied.")]
OidcMetadataMissing,
#[error("Unable to use OIDC as the supplied client metadata is invalid.")]
OidcMetadataInvalid,
#[error("The supplied callback URL used to complete OIDC is invalid.")]
OidcCallbackUrlInvalid,
#[error("The OIDC login was cancelled by the user.")]
OidcCancelled,
#[error("An error occurred with OIDC: {message}")]
OidcError { message: String },
#[error("An error occurred: {message}")]
Generic { message: String },
}
impl From<anyhow::Error> for AuthenticationError {
fn from(e: anyhow::Error) -> AuthenticationError {
AuthenticationError::Generic { message: e.to_string() }
}
}
impl From<IdParseError> for AuthenticationError {
fn from(e: IdParseError) -> AuthenticationError {
AuthenticationError::InvalidServerName { message: e.to_string() }
}
}
impl From<OidcRegistrationsError> for AuthenticationError {
fn from(e: OidcRegistrationsError) -> AuthenticationError {
match e {
OidcRegistrationsError::InvalidBasePath => AuthenticationError::InvalidBasePath,
_ => AuthenticationError::OidcError { message: e.to_string() },
}
}
}
impl From<OidcError> for AuthenticationError {
fn from(e: OidcError) -> AuthenticationError {
AuthenticationError::OidcError { message: e.to_string() }
}
}
/// The configuration to use when authenticating with OIDC.
#[derive(uniffi::Record)]
pub struct OidcConfiguration {
/// The name of the client that will be shown during OIDC authentication.
pub client_name: Option<String>,
/// The redirect URI that will be used when OIDC authentication is
/// successful.
pub redirect_uri: String,
/// A URI that contains information about the client.
pub client_uri: Option<String>,
/// A URI that contains the client's logo.
pub logo_uri: Option<String>,
/// A URI that contains the client's terms of service.
pub tos_uri: Option<String>,
/// A URI that contains the client's privacy policy.
pub policy_uri: Option<String>,
/// An array of e-mail addresses of people responsible for this client.
pub contacts: Option<Vec<String>>,
/// Pre-configured registrations for use with issuers that don't support
/// dynamic client registration.
pub static_registrations: HashMap<String, String>,
}
/// The data required to authenticate against an OIDC server.
#[derive(uniffi::Object)]
pub struct OidcAuthenticationData {
/// The underlying URL for authentication.
url: Url,
/// A unique identifier for the request, used to ensure the response
/// originated from the authentication issuer.
state: String,
}
#[uniffi::export]
impl OidcAuthenticationData {
/// The login URL to use for authentication.
pub fn login_url(&self) -> String {
self.url.to_string()
}
}
#[derive(uniffi::Object)]
pub struct HomeserverLoginDetails {
url: String,
supports_oidc_login: bool,
supports_password_login: bool,
}
#[uniffi::export]
impl HomeserverLoginDetails {
/// The URL of the currently configured homeserver.
pub fn url(&self) -> String {
self.url.clone()
}
/// Whether the current homeserver supports login using OIDC.
pub fn supports_oidc_login(&self) -> bool {
self.supports_oidc_login
}
/// Whether the current homeserver supports the password login flow.
pub fn supports_password_login(&self) -> bool {
self.supports_password_login
}
}
#[uniffi::export]
impl AuthenticationService {
/// Creates a new service to authenticate a user with.
#[uniffi::constructor]
pub fn new(
base_path: String,
passphrase: Option<String>,
user_agent: Option<String>,
oidc_configuration: Option<OidcConfiguration>,
custom_sliding_sync_proxy: Option<String>,
session_delegate: Option<Box<dyn ClientSessionDelegate>>,
cross_process_refresh_lock_id: Option<String>,
) -> Arc<Self> {
Arc::new(AuthenticationService {
base_path,
passphrase,
user_agent,
client: RwLock::new(None),
homeserver_details: RwLock::new(None),
oidc_configuration,
custom_sliding_sync_proxy: RwLock::new(custom_sliding_sync_proxy),
session_delegate: session_delegate.map(Into::into),
cross_process_refresh_lock_id,
})
}
pub fn homeserver_details(&self) -> Option<Arc<HomeserverLoginDetails>> {
self.homeserver_details.read().unwrap().clone()
}
/// Updates the service to authenticate with the homeserver for the
/// specified address.
pub fn configure_homeserver(
&self,
server_name_or_homeserver_url: String,
) -> Result<(), AuthenticationError> {
let mut builder = self.new_client_builder();
// Attempt discovery as a server name first.
let result = matrix_sdk::sanitize_server_name(&server_name_or_homeserver_url);
match result {
Ok(server_name) => {
let protocol = if server_name_or_homeserver_url.starts_with("http://") {
UrlScheme::Http
} else {
UrlScheme::Https
};
builder = builder.server_name_with_protocol(server_name.to_string(), protocol);
}
Err(e) => {
// When the input isn't a valid server name check it is a URL.
// If this is the case, build the client with a homeserver URL.
if Url::parse(&server_name_or_homeserver_url).is_ok() {
builder = builder.homeserver_url(server_name_or_homeserver_url.clone());
} else {
return Err(e.into());
}
}
}
let client = builder.build_inner().or_else(|e| {
if !server_name_or_homeserver_url.starts_with("http://")
&& !server_name_or_homeserver_url.starts_with("https://")
{
return Err(e);
}
// When discovery fails, fallback to the homeserver URL if supplied.
let mut builder = self.new_client_builder();
builder = builder.homeserver_url(server_name_or_homeserver_url);
builder.build_inner()
})?;
let details = RUNTIME.block_on(self.details_from_client(&client))?;
// Now we've verified that it's a valid homeserver, make sure
// there's a sliding sync proxy available one way or another.
if self.custom_sliding_sync_proxy.read().unwrap().is_none()
&& client.discovered_sliding_sync_proxy().is_none()
{
return Err(AuthenticationError::SlidingSyncNotAvailable);
}
*self.client.write().unwrap() = Some(client);
*self.homeserver_details.write().unwrap() = Some(Arc::new(details));
Ok(())
}
/// Performs a password login using the current homeserver.
pub fn login(
&self,
username: String,
password: String,
initial_device_name: Option<String>,
device_id: Option<String>,
) -> Result<Arc<Client>, AuthenticationError> {
let Some(client) = self.client.read().unwrap().clone() else {
return Err(AuthenticationError::ClientMissing);
};
// Login and ask the server for the full user ID as this could be different from
// the username that was entered.
client.login(username, password, initial_device_name, device_id).map_err(|e| match e {
ClientError::Generic { msg } => AuthenticationError::Generic { message: msg },
})?;
let whoami = client.whoami()?;
let session =
client.inner.matrix_auth().session().ok_or(AuthenticationError::SessionMissing)?;
self.finalize_client(client, session, whoami.user_id)
}
/// Requests the URL needed for login in a web view using OIDC. Once the web
/// view has succeeded, call `login_with_oidc_callback` with the callback it
/// returns.
pub fn url_for_oidc_login(&self) -> Result<Arc<OidcAuthenticationData>, AuthenticationError> {
let Some(client) = self.client.read().unwrap().clone() else {
return Err(AuthenticationError::ClientMissing);
};
let Some(authentication_server) = client.discovered_authentication_server() else {
return Err(AuthenticationError::OidcNotSupported);
};
let Some(oidc_configuration) = &self.oidc_configuration else {
return Err(AuthenticationError::OidcMetadataMissing);
};
let redirect_url = Url::parse(&oidc_configuration.redirect_uri)
.map_err(|_e| AuthenticationError::OidcMetadataInvalid)?;
let oidc = client.inner.oidc();
RUNTIME.block_on(async {
self.configure_oidc(&oidc, authentication_server, oidc_configuration).await?;
let mut data_builder = oidc.login(redirect_url, None)?;
// TODO: Add a check for the Consent prompt when MAS is updated.
data_builder = data_builder.prompt(vec![Prompt::Consent]);
let data = data_builder.build().await?;
Ok(Arc::new(OidcAuthenticationData { url: data.url, state: data.state }))
})
}
/// Completes the OIDC login process.
pub fn login_with_oidc_callback(
&self,
authentication_data: Arc<OidcAuthenticationData>,
callback_url: String,
) -> Result<Arc<Client>, AuthenticationError> {
let Some(client) = self.client.read().unwrap().clone() else {
return Err(AuthenticationError::ClientMissing);
};
let oidc = client.inner.oidc();
let url =
Url::parse(&callback_url).map_err(|_| AuthenticationError::OidcCallbackUrlInvalid)?;
let response = AuthorizationResponse::parse_uri(&url)
.map_err(|_| AuthenticationError::OidcCallbackUrlInvalid)?;
let code = match response {
AuthorizationResponse::Success(code) => code,
AuthorizationResponse::Error(err) => {
if err.error.error == AccessDenied {
// The user cancelled the login in the web view.
return Err(AuthenticationError::OidcCancelled);
}
return Err(AuthenticationError::OidcError {
message: err.error.error.to_string(),
});
}
};
if code.state != authentication_data.state {
return Err(AuthenticationError::OidcCallbackUrlInvalid);
};
RUNTIME.block_on(async move {
oidc.finish_authorization(code).await?;
oidc.finish_login()
.await
.map_err(|e| AuthenticationError::OidcError { message: e.to_string() })
})?;
let user_id = client.inner.user_id().unwrap().to_owned();
let session =
client.inner.oidc().full_session().ok_or(AuthenticationError::SessionMissing)?;
self.finalize_client(client, session, user_id)
}
}
impl AuthenticationService {
/// A new client builder pre-configured with the service's base path and
/// user agent if specified
fn new_client_builder(&self) -> Arc<ClientBuilder> {
let mut builder = ClientBuilder::new().base_path(self.base_path.clone());
if let Some(user_agent) = self.user_agent.clone() {
builder = builder.user_agent(user_agent);
}
builder
}
/// Get the homeserver login details from a client.
async fn details_from_client(
&self,
client: &Arc<Client>,
) -> Result<HomeserverLoginDetails, AuthenticationError> {
let supports_oidc_login = client.discovered_authentication_server().is_some();
let supports_password_login = client.supports_password_login().await.ok().unwrap_or(false);
let url = client.homeserver();
Ok(HomeserverLoginDetails { url, supports_oidc_login, supports_password_login })
}
/// Handle any necessary configuration in order for login via OIDC to
/// succeed. This includes performing dynamic client registration against
/// the homeserver's issuer or restoring a previous registration if one has
/// been stored.
async fn configure_oidc(
&self,
oidc: &Oidc,
authentication_server: AuthenticationServerInfo,
configuration: &OidcConfiguration,
) -> Result<(), AuthenticationError> {
if oidc.client_credentials().is_some() {
tracing::info!("OIDC is already configured.");
return Ok(());
};
let oidc_metadata = self.oidc_metadata(configuration)?;
if self.load_client_registration(oidc, &authentication_server, oidc_metadata.clone()).await
{
tracing::info!("OIDC configuration loaded from disk.");
return Ok(());
}
tracing::info!("Registering this client for OIDC.");
let registration_response = oidc
.register_client(&authentication_server.issuer, oidc_metadata.clone(), None)
.await?;
// The format of the credentials changes according to the client metadata that
// was sent. Public clients only get a client ID.
let credentials =
ClientCredentials::None { client_id: registration_response.client_id.clone() };
oidc.restore_registered_client(authentication_server, oidc_metadata, credentials);
tracing::info!("Persisting OIDC registration data.");
self.store_client_registration(oidc).await?;
Ok(())
}
/// Stores the current OIDC dynamic client registration so it can be re-used
/// if we ever log in via the same issuer again.
async fn store_client_registration(&self, oidc: &Oidc) -> Result<(), AuthenticationError> {
let issuer = Url::parse(oidc.issuer().ok_or(AuthenticationError::OidcNotSupported)?)
.map_err(|_| AuthenticationError::OidcError {
message: String::from("Failed to parse issuer URL."),
})?;
let client_id = oidc
.client_credentials()
.ok_or(AuthenticationError::OidcError {
message: String::from("Missing client registration."),
})?
.client_id()
.to_owned();
let metadata = oidc.client_metadata().ok_or(AuthenticationError::OidcError {
message: String::from("Missing client metadata."),
})?;
let registrations = OidcRegistrations::new(
&self.base_path,
metadata.clone(),
self.oidc_static_registrations(),
)?;
registrations.set_and_write_client_id(ClientId(client_id), issuer)?;
Ok(())
}
/// Attempts to load an existing OIDC dynamic client registration for the
/// currently configured issuer.
async fn load_client_registration(
&self,
oidc: &Oidc,
authentication_server: &AuthenticationServerInfo,
oidc_metadata: VerifiedClientMetadata,
) -> bool {
let Ok(issuer) = Url::parse(&authentication_server.issuer) else {
tracing::error!("Failed to parse {:?}", authentication_server.issuer);
return false;
};
let Some(registrations) = OidcRegistrations::new(
&self.base_path,
oidc_metadata.clone(),
self.oidc_static_registrations(),
)
.ok() else {
return false;
};
let Some(client_id) = registrations.client_id(&issuer) else {
return false;
};
oidc.restore_registered_client(
authentication_server.clone(),
oidc_metadata,
ClientCredentials::None { client_id: client_id.0 },
);
true
}
/// Creates and verifies OIDC client metadata for the supplied OIDC
/// configuration.
fn oidc_metadata(
&self,
configuration: &OidcConfiguration,
) -> Result<VerifiedClientMetadata, AuthenticationError> {
let redirect_uri = Url::parse(&configuration.redirect_uri)
.map_err(|_| AuthenticationError::OidcCallbackUrlInvalid)?;
let client_name =
configuration.client_name.as_ref().map(|n| Localized::new(n.to_owned(), []));
let client_uri = configuration.client_uri.localized_url()?;
let logo_uri = configuration.logo_uri.localized_url()?;
let policy_uri = configuration.policy_uri.localized_url()?;
let tos_uri = configuration.tos_uri.localized_url()?;
let contacts = configuration.contacts.clone();
ClientMetadata {
application_type: Some(ApplicationType::Native),
redirect_uris: Some(vec![redirect_uri]),
grant_types: Some(vec![GrantType::RefreshToken, GrantType::AuthorizationCode]),
// A native client shouldn't use authentication as the credentials could be intercepted.
token_endpoint_auth_method: Some(OAuthClientAuthenticationMethod::None),
// The server should display the following fields when getting the user's consent.
client_name,
contacts,
client_uri,
logo_uri,
policy_uri,
tos_uri,
..Default::default()
}
.validate()
.map_err(|_| AuthenticationError::OidcMetadataInvalid)
}
fn oidc_static_registrations(&self) -> HashMap<Url, ClientId> {
let registrations = self
.oidc_configuration
.as_ref()
.map(|c| c.static_registrations.clone())
.unwrap_or_default();
registrations
.iter()
.filter_map(|(issuer, client_id)| {
let Ok(issuer) = Url::parse(issuer) else {
tracing::error!("Failed to parse {:?}", issuer);
return None;
};
Some((issuer, ClientId(client_id.clone())))
})
.collect()
}
/// Creates a new client to setup the store path now the user ID is known.
fn finalize_client(
&self,
client: Arc<Client>,
session: impl Into<AuthSession>,
user_id: OwnedUserId,
) -> Result<Arc<Client>, AuthenticationError> {
let homeserver_url = client.homeserver();
let sliding_sync_proxy: Option<String>;
if let Some(custom_proxy) = self.custom_sliding_sync_proxy.read().unwrap().clone() {
sliding_sync_proxy = Some(custom_proxy);
} else if let Some(discovered_proxy) = client.discovered_sliding_sync_proxy() {
sliding_sync_proxy = Some(discovered_proxy.to_string());
} else {
sliding_sync_proxy = None;
}
let mut client = self
.new_client_builder()
.passphrase(self.passphrase.clone())
.homeserver_url(homeserver_url)
.sliding_sync_proxy(sliding_sync_proxy)
.username(user_id.to_string());
if let Some(id) = &self.cross_process_refresh_lock_id {
let Some(ref session_delegate) = self.session_delegate else {
return Err(AuthenticationError::OidcError {
message: "cross-process refresh lock requires session delegate".to_owned(),
});
};
client = client
.enable_cross_process_refresh_lock_inner(id.clone(), session_delegate.clone());
} else if let Some(ref session_delegate) = self.session_delegate {
client = client.set_session_delegate_inner(session_delegate.clone());
}
let client = client.build_inner()?;
// Restore the client using the session from the login request.
client.restore_session_inner(session)?;
Ok(client)
}
}
trait OptionExt {
/// Convenience method to convert a string to a URL and returns it as a
/// Localized URL. No localization is actually performed.
fn localized_url(&self) -> Result<Option<Localized<Url>>, AuthenticationError>;
}
impl OptionExt for Option<String> {
fn localized_url(&self) -> Result<Option<Localized<Url>>, AuthenticationError> {
self.as_deref()
.map(|uri| -> Result<Localized<Url>, AuthenticationError> {
Ok(Localized::new(
Url::parse(uri).map_err(|_| AuthenticationError::OidcMetadataInvalid)?,
[],
))
})
.transpose()
}
}
File diff suppressed because it is too large Load Diff
+610 -132
View File
@@ -1,57 +1,345 @@
use std::{fs, path::PathBuf, sync::Arc};
use std::{fs, num::NonZeroUsize, path::PathBuf, sync::Arc, time::Duration};
use futures_util::StreamExt;
use matrix_sdk::{
encryption::{BackupDownloadStrategy, EncryptionSettings},
ruma::{
api::{error::UnknownVersionError, MatrixVersion},
ServerName, UserId,
authentication::qrcode::{self, DeviceCodeErrorResponseType, LoginFailureReason},
crypto::{
types::qr_login::{LoginQrCodeDecodeError, QrCodeModeData},
CollectStrategy, TrustRequirement,
},
Client as MatrixClient, ClientBuilder as MatrixClientBuilder,
encryption::{BackupDownloadStrategy, EncryptionSettings},
event_cache::EventCacheError,
reqwest::Certificate,
ruma::{ServerName, UserId},
sliding_sync::{
Error as MatrixSlidingSyncError, VersionBuilder as MatrixSlidingSyncVersionBuilder,
VersionBuilderError,
},
Client as MatrixClient, ClientBuildError as MatrixClientBuildError, HttpError, IdParseError,
RumaApiError,
};
use sanitize_filename_reader_friendly::sanitize;
use ruma::api::error::{DeserializationError, FromHttpResponseError};
use tracing::{debug, error};
use url::Url;
use zeroize::Zeroizing;
use super::{client::Client, RUNTIME};
use crate::{client::ClientSessionDelegate, error::ClientError, helpers::unwrap_or_clone_arc};
use crate::{
authentication::OidcConfiguration, client::ClientSessionDelegate, error::ClientError,
helpers::unwrap_or_clone_arc, task_handle::TaskHandle,
};
#[derive(Clone)]
pub(crate) enum UrlScheme {
Http,
Https,
/// A list of bytes containing a certificate in DER or PEM form.
pub type CertificateBytes = Vec<u8>;
#[derive(Debug, Clone)]
enum HomeserverConfig {
Url(String),
ServerName(String),
ServerNameOrUrl(String),
}
/// Data for the QR code login mechanism.
///
/// The [`QrCodeData`] can be serialized and encoded as a QR code or it can be
/// decoded from a QR code.
#[derive(Debug, uniffi::Object)]
pub struct QrCodeData {
inner: qrcode::QrCodeData,
}
#[matrix_sdk_ffi_macros::export]
impl QrCodeData {
/// Attempt to decode a slice of bytes into a [`QrCodeData`] object.
///
/// The slice of bytes would generally be returned by a QR code decoder.
#[uniffi::constructor]
pub fn from_bytes(bytes: Vec<u8>) -> Result<Arc<Self>, QrCodeDecodeError> {
Ok(Self { inner: qrcode::QrCodeData::from_bytes(&bytes)? }.into())
}
}
/// Error type for the decoding of the [`QrCodeData`].
#[derive(Debug, thiserror::Error, uniffi::Error)]
#[uniffi(flat_error)]
pub enum QrCodeDecodeError {
#[error("Error decoding QR code: {error:?}")]
Crypto {
#[from]
error: LoginQrCodeDecodeError,
},
}
#[derive(Debug, thiserror::Error, uniffi::Error)]
pub enum HumanQrLoginError {
#[error("Linking with this device is not supported.")]
LinkingNotSupported,
#[error("The sign in was cancelled.")]
Cancelled,
#[error("The sign in was not completed in the required time.")]
Expired,
#[error("A secure connection could not have been established between the two devices.")]
ConnectionInsecure,
#[error("The sign in was declined.")]
Declined,
#[error("An unknown error has happened.")]
Unknown,
#[error("The homeserver doesn't provide sliding sync in its configuration.")]
SlidingSyncNotAvailable,
#[error("Unable to use OIDC as the supplied client metadata is invalid.")]
OidcMetadataInvalid,
#[error("The other device is not signed in and as such can't sign in other devices.")]
OtherDeviceNotSignedIn,
}
impl From<qrcode::QRCodeLoginError> for HumanQrLoginError {
fn from(value: qrcode::QRCodeLoginError) -> Self {
use qrcode::{QRCodeLoginError, SecureChannelError};
match value {
QRCodeLoginError::LoginFailure { reason, .. } => match reason {
LoginFailureReason::UnsupportedProtocol => HumanQrLoginError::LinkingNotSupported,
LoginFailureReason::AuthorizationExpired => HumanQrLoginError::Expired,
LoginFailureReason::UserCancelled => HumanQrLoginError::Cancelled,
_ => HumanQrLoginError::Unknown,
},
QRCodeLoginError::Oidc(e) => {
if let Some(e) = e.as_request_token_error() {
match e {
DeviceCodeErrorResponseType::AccessDenied => HumanQrLoginError::Declined,
DeviceCodeErrorResponseType::ExpiredToken => HumanQrLoginError::Expired,
_ => HumanQrLoginError::Unknown,
}
} else {
HumanQrLoginError::Unknown
}
}
QRCodeLoginError::SecureChannel(e) => match e {
SecureChannelError::Utf8(_)
| SecureChannelError::MessageDecode(_)
| SecureChannelError::Json(_)
| SecureChannelError::RendezvousChannel(_) => HumanQrLoginError::Unknown,
SecureChannelError::SecureChannelMessage { .. }
| SecureChannelError::Ecies(_)
| SecureChannelError::InvalidCheckCode => HumanQrLoginError::ConnectionInsecure,
SecureChannelError::InvalidIntent => HumanQrLoginError::OtherDeviceNotSignedIn,
},
QRCodeLoginError::UnexpectedMessage { .. }
| QRCodeLoginError::CrossProcessRefreshLock(_)
| QRCodeLoginError::DeviceKeyUpload(_)
| QRCodeLoginError::SessionTokens(_)
| QRCodeLoginError::UserIdDiscovery(_)
| QRCodeLoginError::SecretImport(_) => HumanQrLoginError::Unknown,
}
}
}
/// Enum describing the progress of the QR-code login.
#[derive(Debug, Default, Clone, uniffi::Enum)]
pub enum QrLoginProgress {
/// The login process is starting.
#[default]
Starting,
/// We established a secure channel with the other device.
EstablishingSecureChannel {
/// The check code that the device should display so the other device
/// can confirm that the channel is secure as well.
check_code: u8,
/// The string representation of the check code, will be guaranteed to
/// be 2 characters long, preserving the leading zero if the
/// first digit is a zero.
check_code_string: String,
},
/// We are waiting for the login and for the OIDC provider to give us an
/// access token.
WaitingForToken { user_code: String },
/// The login has successfully finished.
Done,
}
#[matrix_sdk_ffi_macros::export(callback_interface)]
pub trait QrLoginProgressListener: Sync + Send {
fn on_update(&self, state: QrLoginProgress);
}
impl From<qrcode::LoginProgress> for QrLoginProgress {
fn from(value: qrcode::LoginProgress) -> Self {
use qrcode::LoginProgress;
match value {
LoginProgress::Starting => Self::Starting,
LoginProgress::EstablishingSecureChannel { check_code } => {
let check_code = check_code.to_digit();
Self::EstablishingSecureChannel {
check_code,
check_code_string: format!("{check_code:02}"),
}
}
LoginProgress::WaitingForToken { user_code } => Self::WaitingForToken { user_code },
LoginProgress::Done => Self::Done,
}
}
}
#[derive(Debug, thiserror::Error, uniffi::Error)]
#[uniffi(flat_error)]
pub enum ClientBuildError {
#[error("The supplied server name is invalid.")]
InvalidServerName,
#[error(transparent)]
ServerUnreachable(HttpError),
#[error(transparent)]
WellKnownLookupFailed(RumaApiError),
#[error(transparent)]
WellKnownDeserializationError(DeserializationError),
#[error(transparent)]
#[allow(dead_code)] // rustc's drunk, this is used
SlidingSync(MatrixSlidingSyncError),
#[error(transparent)]
SlidingSyncVersion(VersionBuilderError),
#[error(transparent)]
Sdk(MatrixClientBuildError),
#[error(transparent)]
EventCache(#[from] EventCacheError),
#[error("Failed to build the client: {message}")]
Generic { message: String },
}
impl From<MatrixClientBuildError> for ClientBuildError {
fn from(e: MatrixClientBuildError) -> Self {
match e {
MatrixClientBuildError::InvalidServerName => ClientBuildError::InvalidServerName,
MatrixClientBuildError::Http(e) => ClientBuildError::ServerUnreachable(e),
MatrixClientBuildError::AutoDiscovery(FromHttpResponseError::Server(e)) => {
ClientBuildError::WellKnownLookupFailed(e)
}
MatrixClientBuildError::AutoDiscovery(FromHttpResponseError::Deserialization(e)) => {
ClientBuildError::WellKnownDeserializationError(e)
}
MatrixClientBuildError::SlidingSyncVersion(e) => {
ClientBuildError::SlidingSyncVersion(e)
}
_ => ClientBuildError::Sdk(e),
}
}
}
impl From<IdParseError> for ClientBuildError {
fn from(e: IdParseError) -> ClientBuildError {
ClientBuildError::Generic { message: format!("{e:#}") }
}
}
impl From<std::io::Error> for ClientBuildError {
fn from(e: std::io::Error) -> ClientBuildError {
ClientBuildError::Generic { message: format!("{e:#}") }
}
}
impl From<url::ParseError> for ClientBuildError {
fn from(e: url::ParseError) -> ClientBuildError {
ClientBuildError::Generic { message: format!("{e:#}") }
}
}
impl From<ClientError> for ClientBuildError {
fn from(e: ClientError) -> ClientBuildError {
ClientBuildError::Generic { message: format!("{e:#}") }
}
}
#[derive(Clone, uniffi::Object)]
pub struct ClientBuilder {
base_path: Option<String>,
session_paths: Option<SessionPaths>,
username: Option<String>,
server_name: Option<(String, UrlScheme)>,
homeserver_url: Option<String>,
server_versions: Option<Vec<String>>,
homeserver_cfg: Option<HomeserverConfig>,
passphrase: Zeroizing<Option<String>>,
user_agent: Option<String>,
sliding_sync_proxy: Option<String>,
sliding_sync_version_builder: SlidingSyncVersionBuilder,
proxy: Option<String>,
disable_ssl_verification: bool,
disable_automatic_token_refresh: bool,
inner: MatrixClientBuilder,
cross_process_refresh_lock_id: Option<String>,
cross_process_store_locks_holder_name: Option<String>,
enable_oidc_refresh_lock: bool,
session_delegate: Option<Arc<dyn ClientSessionDelegate>>,
additional_root_certificates: Vec<Vec<u8>>,
disable_built_in_root_certificates: bool,
encryption_settings: EncryptionSettings,
room_key_recipient_strategy: CollectStrategy,
decryption_trust_requirement: TrustRequirement,
request_config: Option<RequestConfig>,
/// Whether to enable use of the event cache store, for reloading events
/// when building timelines et al.
use_event_cache_persistent_storage: bool,
}
#[uniffi::export]
#[matrix_sdk_ffi_macros::export]
impl ClientBuilder {
#[uniffi::constructor]
pub fn new() -> Arc<Self> {
Arc::new(Self::default())
Arc::new(Self {
session_paths: None,
username: None,
homeserver_cfg: None,
passphrase: Zeroizing::new(None),
user_agent: None,
sliding_sync_version_builder: SlidingSyncVersionBuilder::None,
proxy: None,
disable_ssl_verification: false,
disable_automatic_token_refresh: false,
cross_process_store_locks_holder_name: None,
enable_oidc_refresh_lock: false,
session_delegate: None,
additional_root_certificates: Default::default(),
disable_built_in_root_certificates: false,
encryption_settings: EncryptionSettings {
auto_enable_cross_signing: false,
backup_download_strategy:
matrix_sdk::encryption::BackupDownloadStrategy::AfterDecryptionFailure,
auto_enable_backups: false,
},
room_key_recipient_strategy: Default::default(),
decryption_trust_requirement: TrustRequirement::Untrusted,
request_config: Default::default(),
use_event_cache_persistent_storage: false,
})
}
pub fn enable_cross_process_refresh_lock(
/// Whether to use the event cache persistent storage or not.
///
/// This is a temporary feature flag, for testing the event cache's
/// persistent storage. Follow new developments in https://github.com/matrix-org/matrix-rust-sdk/issues/3280.
///
/// This is disabled by default. When disabled, a one-time cleanup is
/// performed when creating the client, and it will clear all the events
/// previously stored in the event cache.
///
/// When enabled, it will attempt to store events in the event cache as
/// they're received, and reuse them when reconstructing timelines.
pub fn use_event_cache_persistent_storage(self: Arc<Self>, value: bool) -> Arc<Self> {
let mut builder = unwrap_or_clone_arc(self);
builder.use_event_cache_persistent_storage = value;
Arc::new(builder)
}
pub fn cross_process_store_locks_holder_name(
self: Arc<Self>,
process_id: String,
session_delegate: Box<dyn ClientSessionDelegate>,
holder_name: String,
) -> Arc<Self> {
self.enable_cross_process_refresh_lock_inner(process_id, session_delegate.into())
let mut builder = unwrap_or_clone_arc(self);
builder.cross_process_store_locks_holder_name = Some(holder_name);
Arc::new(builder)
}
pub fn enable_oidc_refresh_lock(self: Arc<Self>) -> Arc<Self> {
let mut builder = unwrap_or_clone_arc(self);
builder.enable_oidc_refresh_lock = true;
Arc::new(builder)
}
pub fn set_session_delegate(
@@ -63,9 +351,15 @@ impl ClientBuilder {
Arc::new(builder)
}
pub fn base_path(self: Arc<Self>, path: String) -> Arc<Self> {
/// Sets the paths that the client will use to store its data and caches.
/// Both paths **must** be unique per session as the SDK stores aren't
/// capable of handling multiple users, however it is valid to use the
/// same path for both stores on a single session.
///
/// Leaving this unset tells the client to use an in-memory data store.
pub fn session_paths(self: Arc<Self>, data_path: String, cache_path: String) -> Arc<Self> {
let mut builder = unwrap_or_clone_arc(self);
builder.base_path = Some(path);
builder.session_paths = Some(SessionPaths { data_path, cache_path });
Arc::new(builder)
}
@@ -75,22 +369,21 @@ impl ClientBuilder {
Arc::new(builder)
}
pub fn server_versions(self: Arc<Self>, versions: Vec<String>) -> Arc<Self> {
let mut builder = unwrap_or_clone_arc(self);
builder.server_versions = Some(versions);
Arc::new(builder)
}
pub fn server_name(self: Arc<Self>, server_name: String) -> Arc<Self> {
let mut builder = unwrap_or_clone_arc(self);
// Assume HTTPS if no protocol is provided.
builder.server_name = Some((server_name, UrlScheme::Https));
builder.homeserver_cfg = Some(HomeserverConfig::ServerName(server_name));
Arc::new(builder)
}
pub fn homeserver_url(self: Arc<Self>, url: String) -> Arc<Self> {
let mut builder = unwrap_or_clone_arc(self);
builder.homeserver_url = Some(url);
builder.homeserver_cfg = Some(HomeserverConfig::Url(url));
Arc::new(builder)
}
pub fn server_name_or_homeserver_url(self: Arc<Self>, server_name_or_url: String) -> Arc<Self> {
let mut builder = unwrap_or_clone_arc(self);
builder.homeserver_cfg = Some(HomeserverConfig::ServerNameOrUrl(server_name_or_url));
Arc::new(builder)
}
@@ -106,9 +399,12 @@ impl ClientBuilder {
Arc::new(builder)
}
pub fn sliding_sync_proxy(self: Arc<Self>, sliding_sync_proxy: Option<String>) -> Arc<Self> {
pub fn sliding_sync_version_builder(
self: Arc<Self>,
version_builder: SlidingSyncVersionBuilder,
) -> Arc<Self> {
let mut builder = unwrap_or_clone_arc(self);
builder.sliding_sync_proxy = sliding_sync_proxy;
builder.sliding_sync_version_builder = version_builder;
Arc::new(builder)
}
@@ -130,70 +426,156 @@ impl ClientBuilder {
Arc::new(builder)
}
pub fn build(self: Arc<Self>) -> Result<Arc<Client>, ClientError> {
Ok(self.build_inner()?)
}
}
impl ClientBuilder {
pub(crate) fn enable_cross_process_refresh_lock_inner(
pub fn add_root_certificates(
self: Arc<Self>,
process_id: String,
session_delegate: Arc<dyn ClientSessionDelegate>,
certificates: Vec<CertificateBytes>,
) -> Arc<Self> {
let mut builder = unwrap_or_clone_arc(self);
builder.cross_process_refresh_lock_id = Some(process_id);
builder.session_delegate = Some(session_delegate);
builder.additional_root_certificates = certificates;
Arc::new(builder)
}
pub(crate) fn set_session_delegate_inner(
self: Arc<Self>,
session_delegate: Arc<dyn ClientSessionDelegate>,
) -> Arc<Self> {
/// Don't trust any system root certificates, only trust the certificates
/// provided through
/// [`add_root_certificates`][ClientBuilder::add_root_certificates].
pub fn disable_built_in_root_certificates(self: Arc<Self>) -> Arc<Self> {
let mut builder = unwrap_or_clone_arc(self);
builder.session_delegate = Some(session_delegate);
builder.disable_built_in_root_certificates = true;
Arc::new(builder)
}
pub(crate) fn server_name_with_protocol(
pub fn auto_enable_cross_signing(
self: Arc<Self>,
server_name: String,
protocol: UrlScheme,
auto_enable_cross_signing: bool,
) -> Arc<Self> {
let mut builder = unwrap_or_clone_arc(self);
builder.server_name = Some((server_name, protocol));
builder.encryption_settings.auto_enable_cross_signing = auto_enable_cross_signing;
Arc::new(builder)
}
pub(crate) fn build_inner(self: Arc<Self>) -> anyhow::Result<Arc<Client>> {
/// Select a strategy to download room keys from the backup. By default
/// we download after a decryption failure.
///
/// Take a look at the [`BackupDownloadStrategy`] enum for more options.
pub fn backup_download_strategy(
self: Arc<Self>,
backup_download_strategy: BackupDownloadStrategy,
) -> Arc<Self> {
let mut builder = unwrap_or_clone_arc(self);
builder.encryption_settings.backup_download_strategy = backup_download_strategy;
Arc::new(builder)
}
/// Automatically create a backup version if no backup exists.
pub fn auto_enable_backups(self: Arc<Self>, auto_enable_backups: bool) -> Arc<Self> {
let mut builder = unwrap_or_clone_arc(self);
builder.encryption_settings.auto_enable_backups = auto_enable_backups;
Arc::new(builder)
}
/// Set the strategy to be used for picking recipient devices when sending
/// an encrypted message.
pub fn room_key_recipient_strategy(self: Arc<Self>, strategy: CollectStrategy) -> Arc<Self> {
let mut builder = unwrap_or_clone_arc(self);
builder.room_key_recipient_strategy = strategy;
Arc::new(builder)
}
/// Set the trust requirement to be used when decrypting events.
pub fn room_decryption_trust_requirement(
self: Arc<Self>,
trust_requirement: TrustRequirement,
) -> Arc<Self> {
let mut builder = unwrap_or_clone_arc(self);
builder.decryption_trust_requirement = trust_requirement;
Arc::new(builder)
}
/// Add a default request config to this client.
pub fn request_config(self: Arc<Self>, config: RequestConfig) -> Arc<Self> {
let mut builder = unwrap_or_clone_arc(self);
builder.request_config = Some(config);
Arc::new(builder)
}
pub async fn build(self: Arc<Self>) -> Result<Arc<Client>, ClientBuildError> {
let builder = unwrap_or_clone_arc(self);
let mut inner_builder = builder.inner;
let mut inner_builder = MatrixClient::builder();
if let Some(holder_name) = &builder.cross_process_store_locks_holder_name {
inner_builder =
inner_builder.cross_process_store_locks_holder_name(holder_name.clone());
}
if let Some(session_paths) = &builder.session_paths {
let data_path = PathBuf::from(&session_paths.data_path);
let cache_path = PathBuf::from(&session_paths.cache_path);
debug!(
data_path = %data_path.to_string_lossy(),
cache_path = %cache_path.to_string_lossy(),
"Creating directories for data and cache stores.",
);
if let (Some(base_path), Some(username)) = (builder.base_path, &builder.username) {
// Determine store path
let data_path = PathBuf::from(base_path).join(sanitize(username));
fs::create_dir_all(&data_path)?;
fs::create_dir_all(&cache_path)?;
inner_builder = inner_builder.sqlite_store(&data_path, builder.passphrase.as_deref());
inner_builder = inner_builder.sqlite_store_with_cache_path(
&data_path,
&cache_path,
builder.passphrase.as_deref(),
);
} else {
debug!("Not using a store path.");
}
// Determine server either from URL, server name or user ID.
if let Some(homeserver_url) = builder.homeserver_url {
inner_builder = inner_builder.homeserver_url(homeserver_url);
} else if let Some((server_name, protocol)) = builder.server_name {
let server_name = ServerName::parse(server_name)?;
inner_builder = match protocol {
UrlScheme::Http => inner_builder.insecure_server_name_no_tls(&server_name),
UrlScheme::Https => inner_builder.server_name(&server_name),
};
} else if let Some(username) = builder.username {
let user = UserId::parse(username)?;
inner_builder = inner_builder.server_name(user.server_name());
} else {
anyhow::bail!(
"Failed to build: One of homeserver_url, server_name or username must be called."
);
inner_builder = match builder.homeserver_cfg {
Some(HomeserverConfig::Url(url)) => inner_builder.homeserver_url(url),
Some(HomeserverConfig::ServerName(server_name)) => {
let server_name = ServerName::parse(server_name)?;
inner_builder.server_name(&server_name)
}
Some(HomeserverConfig::ServerNameOrUrl(server_name_or_url)) => {
inner_builder.server_name_or_homeserver_url(server_name_or_url)
}
None => {
if let Some(username) = builder.username {
let user = UserId::parse(username)?;
inner_builder.server_name(user.server_name())
} else {
return Err(ClientBuildError::Generic {
message: "Failed to build: One of homeserver_url, server_name, server_name_or_homeserver_url or username must be called.".to_owned(),
});
}
}
};
let mut certificates = Vec::new();
for certificate in builder.additional_root_certificates {
// We don't really know what type of certificate we may get here, so let's try
// first one type, then the other.
match Certificate::from_der(&certificate) {
Ok(cert) => {
certificates.push(cert);
}
Err(der_error) => {
let cert = Certificate::from_pem(&certificate).map_err(|pem_error| {
ClientBuildError::Generic {
message: format!("Failed to add a root certificate as DER ({der_error:?}) or PEM ({pem_error:?})"),
}
})?;
certificates.push(cert);
}
}
}
inner_builder = inner_builder.add_root_certificates(certificates);
if builder.disable_built_in_root_certificates {
inner_builder = inner_builder.disable_built_in_root_certificates();
}
if let Some(proxy) = builder.proxy {
@@ -212,66 +594,162 @@ impl ClientBuilder {
inner_builder = inner_builder.user_agent(user_agent);
}
if let Some(server_versions) = builder.server_versions {
inner_builder = inner_builder.server_versions(
server_versions
.iter()
.map(|s| MatrixVersion::try_from(s.as_str()))
.collect::<Result<Vec<MatrixVersion>, UnknownVersionError>>()?,
);
inner_builder = inner_builder
.with_encryption_settings(builder.encryption_settings)
.with_room_key_recipient_strategy(builder.room_key_recipient_strategy)
.with_decryption_trust_requirement(builder.decryption_trust_requirement);
match builder.sliding_sync_version_builder {
SlidingSyncVersionBuilder::None => {
inner_builder = inner_builder
.sliding_sync_version_builder(MatrixSlidingSyncVersionBuilder::None)
}
SlidingSyncVersionBuilder::Proxy { url } => {
inner_builder = inner_builder.sliding_sync_version_builder(
MatrixSlidingSyncVersionBuilder::Proxy {
url: Url::parse(&url)
.map_err(|e| ClientBuildError::Generic { message: e.to_string() })?,
},
)
}
SlidingSyncVersionBuilder::Native => {
inner_builder = inner_builder
.sliding_sync_version_builder(MatrixSlidingSyncVersionBuilder::Native)
}
SlidingSyncVersionBuilder::DiscoverProxy => {
inner_builder = inner_builder
.sliding_sync_version_builder(MatrixSlidingSyncVersionBuilder::DiscoverProxy)
}
SlidingSyncVersionBuilder::DiscoverNative => {
inner_builder = inner_builder
.sliding_sync_version_builder(MatrixSlidingSyncVersionBuilder::DiscoverNative)
}
}
let sdk_client = RUNTIME.block_on(async move { inner_builder.build().await })?;
// At this point, `sdk_client` might contain a `sliding_sync_proxy` that has
// been configured by the homeserver (if it's a `ServerName` and the
// `.well-known` file is filled as expected).
//
// If `builder.sliding_sync_proxy` contains `Some(_)`, it means one wants to
// overwrite this value. It would be an error to call
// `sdk_client.set_sliding_sync_proxy()` with `None`, as it would erase the
// `sliding_sync_proxy` if any, and it's not the intended behavior.
//
// So let's call `sdk_client.set_sliding_sync_proxy()` if and only if there is
// `Some(_)` value in `builder.sliding_sync_proxy`. That's really important: It
// might not break an existing app session, but it is likely to break a new
// session, which not immediate to detect if there is no test.
if let Some(sliding_sync_proxy) = builder.sliding_sync_proxy {
sdk_client.set_sliding_sync_proxy(Some(Url::parse(&sliding_sync_proxy)?));
if let Some(config) = builder.request_config {
let mut updated_config = matrix_sdk::config::RequestConfig::default();
if let Some(retry_limit) = config.retry_limit {
updated_config = updated_config.retry_limit(retry_limit);
}
if let Some(timeout) = config.timeout {
updated_config = updated_config.timeout(Duration::from_millis(timeout));
}
if let Some(max_concurrent_requests) = config.max_concurrent_requests {
if max_concurrent_requests > 0 {
updated_config = updated_config.max_concurrent_requests(NonZeroUsize::new(
max_concurrent_requests as usize,
));
}
}
if let Some(retry_timeout) = config.retry_timeout {
updated_config = updated_config.retry_timeout(Duration::from_millis(retry_timeout));
}
inner_builder = inner_builder.request_config(updated_config);
}
Ok(Client::new(
sdk_client,
builder.cross_process_refresh_lock_id,
builder.session_delegate,
)?)
let sdk_client = inner_builder.build().await?;
if builder.use_event_cache_persistent_storage {
// Enable the persistent storage \o/
sdk_client.event_cache().enable_storage()?;
} else {
// Get rid of all the previous events, if any.
let store = sdk_client
.event_cache_store()
.lock()
.await
.map_err(EventCacheError::LockingStorage)?;
store.clear_all_rooms_chunks().await.map_err(EventCacheError::Storage)?;
}
Ok(Arc::new(
Client::new(sdk_client, builder.enable_oidc_refresh_lock, builder.session_delegate)
.await?,
))
}
}
impl Default for ClientBuilder {
fn default() -> Self {
let encryption_settings = EncryptionSettings {
auto_enable_cross_signing: true,
auto_enable_backups: true,
backup_download_strategy: BackupDownloadStrategy::AfterDecryptionFailure,
/// Finish the building of the client and attempt to log in using the
/// provided [`QrCodeData`].
///
/// This method will build the client and immediately attempt to log the
/// client in using the provided [`QrCodeData`] using the login
/// mechanism described in [MSC4108]. As such this methods requires OIDC
/// support as well as sliding sync support.
///
/// The usage of the progress_listener is required to transfer the
/// [`CheckCode`] to the existing client.
///
/// [MSC4108]: https://github.com/matrix-org/matrix-spec-proposals/pull/4108
pub async fn build_with_qr_code(
self: Arc<Self>,
qr_code_data: &QrCodeData,
oidc_configuration: &OidcConfiguration,
progress_listener: Box<dyn QrLoginProgressListener>,
) -> Result<Arc<Client>, HumanQrLoginError> {
let QrCodeModeData::Reciprocate { server_name } = &qr_code_data.inner.mode_data else {
return Err(HumanQrLoginError::OtherDeviceNotSignedIn);
};
let inner = MatrixClient::builder().with_encryption_settings(encryption_settings);
Self {
base_path: None,
username: None,
server_name: None,
homeserver_url: None,
server_versions: None,
passphrase: Zeroizing::new(None),
user_agent: None,
sliding_sync_proxy: None,
proxy: None,
disable_ssl_verification: false,
disable_automatic_token_refresh: false,
inner,
cross_process_refresh_lock_id: None,
session_delegate: None,
}
let builder = self.server_name_or_homeserver_url(server_name.to_owned());
let client = builder.build().await.map_err(|e| match e {
ClientBuildError::SlidingSync(_) => HumanQrLoginError::SlidingSyncNotAvailable,
_ => {
error!("Couldn't build the client {e:?}");
HumanQrLoginError::Unknown
}
})?;
let client_metadata =
oidc_configuration.try_into().map_err(|_| HumanQrLoginError::OidcMetadataInvalid)?;
let oidc = client.inner.oidc();
let login = oidc.login_with_qr_code(&qr_code_data.inner, client_metadata);
let mut progress = login.subscribe_to_progress();
// We create this task, which will get cancelled once it's dropped, just in case
// the progress stream doesn't end.
let _progress_task = TaskHandle::new(RUNTIME.spawn(async move {
while let Some(state) = progress.next().await {
progress_listener.on_update(state.into());
}
}));
login.await?;
Ok(client)
}
}
#[derive(Clone)]
/// The store paths the client will use when built.
struct SessionPaths {
/// The path that the client will use to store its data.
data_path: String,
/// The path that the client will use to store its caches. This path can be
/// the same as the data path if you prefer to keep everything in one place.
cache_path: String,
}
#[derive(Clone, uniffi::Record)]
/// The config to use for HTTP requests by default in this client.
pub struct RequestConfig {
/// Max number of retries.
retry_limit: Option<u64>,
/// Timeout for a request in milliseconds.
timeout: Option<u64>,
/// Max number of concurrent requests. No value means no limits.
max_concurrent_requests: Option<u64>,
/// Base delay between retries.
retry_timeout: Option<u64>,
}
#[derive(Clone, uniffi::Enum)]
pub enum SlidingSyncVersionBuilder {
None,
Proxy { url: String },
Native,
DiscoverProxy,
DiscoverNative,
}
+22
View File
@@ -0,0 +1,22 @@
use serde::Deserialize;
use crate::ClientError;
/// Well-known settings specific to ElementCall
#[derive(Deserialize, uniffi::Record)]
pub struct ElementCallWellKnown {
widget_url: String,
}
/// Element specific well-known settings
#[derive(Deserialize, uniffi::Record)]
pub struct ElementWellKnown {
call: Option<ElementCallWellKnown>,
registration_helper_url: Option<String>,
}
/// Helper function to parse a string into a ElementWellKnown struct
#[matrix_sdk_ffi_macros::export]
pub fn make_element_well_known(string: String) -> Result<ElementWellKnown, ClientError> {
serde_json::from_str(&string).map_err(ClientError::new)
}
+252 -15
View File
@@ -1,39 +1,49 @@
use std::sync::Arc;
use futures_util::StreamExt;
use matrix_sdk::encryption::{backups, recovery};
use matrix_sdk::{
encryption,
encryption::{backups, recovery},
};
use thiserror::Error;
use tracing::{error, info};
use zeroize::Zeroize;
use super::RUNTIME;
use crate::{error::ClientError, task_handle::TaskHandle};
use crate::{client::Client, error::ClientError, ruma::AuthData, task_handle::TaskHandle};
#[derive(uniffi::Object)]
pub struct Encryption {
inner: matrix_sdk::encryption::Encryption,
pub(crate) inner: matrix_sdk::encryption::Encryption,
/// A reference to the FFI client.
///
/// Note: we do this to make it so that the FFI `NotificationClient` keeps
/// the FFI `Client` and thus the SDK `Client` alive. Otherwise, we
/// would need to repeat the hack done in the FFI `Client::drop` method.
pub(crate) _client: Arc<Client>,
}
impl From<matrix_sdk::encryption::Encryption> for Encryption {
fn from(value: matrix_sdk::encryption::Encryption) -> Self {
Self { inner: value }
}
}
#[uniffi::export(callback_interface)]
#[matrix_sdk_ffi_macros::export(callback_interface)]
pub trait BackupStateListener: Sync + Send {
fn on_update(&self, status: BackupState);
}
#[uniffi::export(callback_interface)]
#[matrix_sdk_ffi_macros::export(callback_interface)]
pub trait BackupSteadyStateListener: Sync + Send {
fn on_update(&self, status: BackupUploadState);
}
#[uniffi::export(callback_interface)]
#[matrix_sdk_ffi_macros::export(callback_interface)]
pub trait RecoveryStateListener: Sync + Send {
fn on_update(&self, status: RecoveryState);
}
#[matrix_sdk_ffi_macros::export(callback_interface)]
pub trait VerificationStateListener: Sync + Send {
fn on_update(&self, status: VerificationState);
}
#[derive(uniffi::Enum)]
pub enum BackupUploadState {
Waiting,
@@ -153,7 +163,7 @@ impl From<recovery::RecoveryState> for RecoveryState {
}
}
#[uniffi::export(callback_interface)]
#[matrix_sdk_ffi_macros::export(callback_interface)]
pub trait EnableRecoveryProgressListener: Sync + Send {
fn on_update(&self, status: EnableRecoveryProgress);
}
@@ -186,8 +196,37 @@ impl From<recovery::EnableProgress> for EnableRecoveryProgress {
}
}
#[uniffi::export(async_runtime = "tokio")]
#[derive(uniffi::Enum)]
pub enum VerificationState {
Unknown,
Verified,
Unverified,
}
impl From<encryption::VerificationState> for VerificationState {
fn from(value: encryption::VerificationState) -> Self {
match &value {
encryption::VerificationState::Unknown => Self::Unknown,
encryption::VerificationState::Verified => Self::Verified,
encryption::VerificationState::Unverified => Self::Unverified,
}
}
}
#[matrix_sdk_ffi_macros::export]
impl Encryption {
/// Get the public ed25519 key of our own device. This is usually what is
/// called the fingerprint of the device.
pub async fn ed25519_key(&self) -> Option<String> {
self.inner.ed25519_key().await
}
/// Get the public curve25519 key of our own device in base64. This is
/// usually what is called the identity key of the device.
pub async fn curve25519_key(&self) -> Option<String> {
self.inner.curve25519_key().await.map(|k| k.to_base64())
}
pub fn backup_state_listener(&self, listener: Box<dyn BackupStateListener>) -> Arc<TaskHandle> {
let mut stream = self.inner.backups().state_stream();
@@ -215,7 +254,7 @@ impl Encryption {
/// Therefore it is necessary to poll the server for an answer every time
/// you want to differentiate between those two states.
pub async fn backup_exists_on_server(&self) -> Result<bool, ClientError> {
Ok(self.inner.backups().exists_on_server().await?)
Ok(self.inner.backups().fetch_exists_on_server().await?)
}
pub fn recovery_state(&self) -> RecoveryState {
@@ -277,6 +316,7 @@ impl Encryption {
pub async fn enable_recovery(
&self,
wait_for_backups_to_upload: bool,
mut passphrase: Option<String>,
progress_listener: Box<dyn EnableRecoveryProgressListener>,
) -> Result<String> {
let recovery = self.inner.recovery();
@@ -287,6 +327,12 @@ impl Encryption {
recovery.enable()
};
let enable = if let Some(passphrase) = &passphrase {
enable.with_passphrase(passphrase)
} else {
enable
};
let mut progress_stream = enable.subscribe_to_progress();
let task = RUNTIME.spawn(async move {
@@ -299,6 +345,7 @@ impl Encryption {
let ret = enable.await?;
task.abort();
passphrase.zeroize();
Ok(ret)
}
@@ -319,6 +366,22 @@ impl Encryption {
Ok(result?)
}
/// Completely reset the current user's crypto identity: reset the cross
/// signing keys, delete the existing backup and recovery key.
pub async fn reset_identity(&self) -> Result<Option<Arc<IdentityResetHandle>>, ClientError> {
if let Some(reset_handle) = self
.inner
.recovery()
.reset_identity()
.await
.map_err(|e| ClientError::Generic { msg: e.to_string() })?
{
return Ok(Some(Arc::new(IdentityResetHandle { inner: reset_handle })));
}
Ok(None)
}
pub async fn recover(&self, mut recovery_key: String) -> Result<()> {
let result = self.inner.recovery().recover(&recovery_key).await;
@@ -326,4 +389,178 @@ impl Encryption {
Ok(result?)
}
pub fn verification_state(&self) -> VerificationState {
self.inner.verification_state().get().into()
}
pub fn verification_state_listener(
self: Arc<Self>,
listener: Box<dyn VerificationStateListener>,
) -> Arc<TaskHandle> {
let mut subscriber = self.inner.verification_state();
Arc::new(TaskHandle::new(RUNTIME.spawn(async move {
while let Some(verification_state) = subscriber.next().await {
listener.on_update(verification_state.into());
}
})))
}
/// Waits for end-to-end encryption initialization tasks to finish, if any
/// was running in the background.
pub async fn wait_for_e2ee_initialization_tasks(&self) {
self.inner.wait_for_e2ee_initialization_tasks().await;
}
/// Get the E2EE identity of a user.
///
/// This method always tries to fetch the identity from the store, which we
/// only have if the user is tracked, meaning that we are both members
/// of the same encrypted room. If no user is found locally, a request will
/// be made to the homeserver.
///
/// # Arguments
///
/// * `user_id` - The ID of the user that the identity belongs to.
///
/// Returns a `UserIdentity` if one is found. Returns an error if there
/// was an issue with the crypto store or with the request to the
/// homeserver.
///
/// This will always return `None` if the client hasn't been logged in.
pub async fn user_identity(
&self,
user_id: String,
) -> Result<Option<Arc<UserIdentity>>, ClientError> {
match self.inner.get_user_identity(user_id.as_str().try_into()?).await {
Ok(Some(identity)) => {
return Ok(Some(Arc::new(UserIdentity { inner: identity })));
}
Ok(None) => {
info!("No identity found in the store.");
}
Err(error) => {
error!("Failed fetching identity from the store: {}", error);
}
};
info!("Requesting identity from the server.");
let identity = self.inner.request_user_identity(user_id.as_str().try_into()?).await?;
Ok(identity.map(|identity| Arc::new(UserIdentity { inner: identity })))
}
}
/// The E2EE identity of a user.
#[derive(uniffi::Object)]
pub struct UserIdentity {
inner: matrix_sdk::encryption::identities::UserIdentity,
}
#[matrix_sdk_ffi_macros::export]
impl UserIdentity {
/// Remember this identity, ensuring it does not result in a pin violation.
///
/// When we first see a user, we assume their cryptographic identity has not
/// been tampered with by the homeserver or another entity with
/// man-in-the-middle capabilities. We remember this identity and call this
/// action "pinning".
///
/// If the identity presented for the user changes later on, the newly
/// presented identity is considered to be in "pin violation". This
/// method explicitly accepts the new identity, allowing it to replace
/// the previously pinned one and bringing it out of pin violation.
///
/// UIs should display a warning to the user when encountering an identity
/// which is not verified and is in pin violation.
pub(crate) async fn pin(&self) -> Result<(), ClientError> {
Ok(self.inner.pin().await?)
}
/// Get the public part of the Master key of this user identity.
///
/// The public part of the Master key is usually used to uniquely identify
/// the identity.
///
/// Returns None if the master key does not actually contain any keys.
pub(crate) fn master_key(&self) -> Option<String> {
self.inner.master_key().get_first_key().map(|k| k.to_base64())
}
/// Is the user identity considered to be verified.
///
/// If the identity belongs to another user, our own user identity needs to
/// be verified as well for the identity to be considered to be verified.
pub fn is_verified(&self) -> bool {
self.inner.is_verified()
}
}
#[derive(uniffi::Object)]
pub struct IdentityResetHandle {
pub(crate) inner: matrix_sdk::encryption::recovery::IdentityResetHandle,
}
#[matrix_sdk_ffi_macros::export]
impl IdentityResetHandle {
/// Get the underlying [`CrossSigningResetAuthType`] this identity reset
/// process is using.
pub fn auth_type(&self) -> CrossSigningResetAuthType {
self.inner.auth_type().into()
}
/// This method starts the identity reset process and
/// will go through the following steps:
///
/// 1. Disable backing up room keys and delete the active backup
/// 2. Disable recovery and delete secret storage
/// 3. Go through the cross-signing key reset flow
/// 4. Finally, re-enable key backups only if they were enabled before
pub async fn reset(&self, auth: Option<AuthData>) -> Result<(), ClientError> {
if let Some(auth) = auth {
self.inner
.reset(Some(auth.into()))
.await
.map_err(|e| ClientError::Generic { msg: e.to_string() })
} else {
self.inner.reset(None).await.map_err(|e| ClientError::Generic { msg: e.to_string() })
}
}
pub async fn cancel(&self) {
self.inner.cancel().await;
}
}
#[derive(uniffi::Enum)]
pub enum CrossSigningResetAuthType {
/// The homeserver requires user-interactive authentication.
Uiaa,
// /// OIDC is used for authentication and the user needs to open a URL to
// /// approve the upload of cross-signing keys.
Oidc {
info: OidcCrossSigningResetInfo,
},
}
impl From<&matrix_sdk::encryption::CrossSigningResetAuthType> for CrossSigningResetAuthType {
fn from(value: &matrix_sdk::encryption::CrossSigningResetAuthType) -> Self {
match value {
encryption::CrossSigningResetAuthType::Uiaa(_) => Self::Uiaa,
encryption::CrossSigningResetAuthType::Oidc(info) => Self::Oidc { info: info.into() },
}
}
}
#[derive(uniffi::Record)]
pub struct OidcCrossSigningResetInfo {
/// The URL where the user can approve the reset of the cross-signing keys.
pub approval_url: String,
}
impl From<&matrix_sdk::encryption::OidcCrossSigningResetInfo> for OidcCrossSigningResetInfo {
fn from(value: &matrix_sdk::encryption::OidcCrossSigningResetInfo) -> Self {
Self { approval_url: value.approval_url.to_string() }
}
}
+139 -4
View File
@@ -1,12 +1,16 @@
use std::fmt::Display;
use std::{collections::HashMap, fmt, fmt::Display};
use matrix_sdk::{
self, encryption::CryptoStoreError, oidc::OidcError, HttpError, IdParseError,
NotificationSettingsError as SdkNotificationSettingsError, StoreError,
encryption::CryptoStoreError, event_cache::EventCacheError, oidc::OidcError, reqwest,
room::edit::EditError, send_queue::RoomSendQueueError, HttpError, IdParseError,
NotificationSettingsError as SdkNotificationSettingsError,
QueueWedgeError as SdkQueueWedgeError, StoreError,
};
use matrix_sdk_ui::{encryption_sync_service, notification_client, sync_service, timeline};
use uniffi::UnexpectedUniFFICallbackError;
use crate::room_list::RoomListError;
#[derive(Debug, thiserror::Error)]
pub enum ClientError {
#[error("client error: {msg}")]
@@ -14,7 +18,7 @@ pub enum ClientError {
}
impl ClientError {
fn new<E: Display>(error: E) -> Self {
pub(crate) fn new<E: Display>(error: E) -> Self {
Self::Generic { msg: error.to_string() }
}
}
@@ -25,6 +29,12 @@ impl From<anyhow::Error> for ClientError {
}
}
impl From<reqwest::Error> for ClientError {
fn from(e: reqwest::Error) -> Self {
Self::new(e)
}
}
impl From<UnexpectedUniFFICallbackError> for ClientError {
fn from(e: UnexpectedUniFFICallbackError) -> Self {
Self::new(e)
@@ -91,6 +101,12 @@ impl From<timeline::Error> for ClientError {
}
}
impl From<timeline::UnsupportedEditItem> for ClientError {
fn from(e: timeline::UnsupportedEditItem) -> Self {
Self::new(e)
}
}
impl From<notification_client::Error> for ClientError {
fn from(e: notification_client::Error) -> Self {
Self::new(e)
@@ -115,6 +131,120 @@ impl From<RoomError> for ClientError {
}
}
impl From<RoomListError> for ClientError {
fn from(e: RoomListError) -> Self {
Self::new(e)
}
}
impl From<EventCacheError> for ClientError {
fn from(e: EventCacheError) -> Self {
Self::new(e)
}
}
impl From<EditError> for ClientError {
fn from(e: EditError) -> Self {
Self::new(e)
}
}
impl From<RoomSendQueueError> for ClientError {
fn from(e: RoomSendQueueError) -> Self {
Self::new(e)
}
}
/// Bindings version of the sdk type replacing OwnedUserId/DeviceIds with simple
/// String.
///
/// Represent a failed to send unrecoverable error of an event sent via the
/// send_queue. It is a serializable representation of a client error, see
/// `From` implementation for more details. These errors can not be
/// automatically retried, but yet some manual action can be taken before retry
/// sending. If not the only solution is to delete the local event.
#[derive(Debug, Clone, uniffi::Enum)]
pub enum QueueWedgeError {
/// This error occurs when there are some insecure devices in the room, and
/// the current encryption setting prohibit sharing with them.
InsecureDevices {
/// The insecure devices as a Map of userID to deviceID.
user_device_map: HashMap<String, Vec<String>>,
},
/// This error occurs when a previously verified user is not anymore, and
/// the current encryption setting prohibit sharing when it happens.
IdentityViolations {
/// The users that are expected to be verified but are not.
users: Vec<String>,
},
/// It is required to set up cross-signing and properly erify the current
/// session before sending.
CrossVerificationRequired,
/// Some media content to be sent has disappeared from the cache.
MissingMediaContent,
/// Some mime type couldn't be parsed.
InvalidMimeType { mime_type: String },
/// Other errors.
GenericApiError { msg: String },
}
/// Simple display implementation that strips out userIds/DeviceIds to avoid
/// accidental logging.
impl Display for QueueWedgeError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
QueueWedgeError::InsecureDevices { .. } => {
f.write_str("There are insecure devices in the room")
}
QueueWedgeError::IdentityViolations { .. } => {
f.write_str("Some users that were previously verified are not anymore")
}
QueueWedgeError::CrossVerificationRequired => {
f.write_str("Own verification is required")
}
QueueWedgeError::MissingMediaContent => {
f.write_str("Media to be sent disappeared from local storage")
}
QueueWedgeError::InvalidMimeType { mime_type } => {
write!(f, "Invalid mime type '{mime_type}' for media upload")
}
QueueWedgeError::GenericApiError { msg } => f.write_str(msg),
}
}
}
impl From<SdkQueueWedgeError> for QueueWedgeError {
fn from(value: SdkQueueWedgeError) -> Self {
match value {
SdkQueueWedgeError::InsecureDevices { user_device_map } => Self::InsecureDevices {
user_device_map: user_device_map
.iter()
.map(|(user_id, devices)| {
(
user_id.to_string(),
devices.iter().map(|device_id| device_id.to_string()).collect(),
)
})
.collect(),
},
SdkQueueWedgeError::IdentityViolations { users } => Self::IdentityViolations {
users: users.iter().map(ruma::OwnedUserId::to_string).collect(),
},
SdkQueueWedgeError::CrossVerificationRequired => Self::CrossVerificationRequired,
SdkQueueWedgeError::MissingMediaContent => Self::MissingMediaContent,
SdkQueueWedgeError::InvalidMimeType { mime_type } => {
Self::InvalidMimeType { mime_type }
}
SdkQueueWedgeError::GenericApiError { msg } => Self::GenericApiError { msg },
}
}
}
#[derive(Debug, thiserror::Error, uniffi::Error)]
#[uniffi(flat_error)]
pub enum RoomError {
@@ -186,3 +316,8 @@ impl From<matrix_sdk::Error> for NotificationSettingsError {
Self::Generic { msg: e.to_string() }
}
}
/// Something has not been implemented yet.
#[derive(thiserror::Error, Debug)]
#[error("not implemented yet")]
pub struct NotYetImplemented;
+220 -10
View File
@@ -1,16 +1,29 @@
use anyhow::{bail, Context};
use ruma::events::{
room::message::Relation, AnySyncMessageLikeEvent, AnySyncStateEvent, AnySyncTimelineEvent,
AnyTimelineEvent, MessageLikeEventContent as RumaMessageLikeEventContent, RedactContent,
RedactedStateEventContent, StaticStateEventContent, SyncMessageLikeEvent, SyncStateEvent,
use matrix_sdk::IdParseError;
use matrix_sdk_ui::timeline::TimelineEventItemId;
use ruma::{
events::{
room::{
message::{MessageType as RumaMessageType, Relation},
redaction::SyncRoomRedactionEvent,
},
AnySyncMessageLikeEvent, AnySyncStateEvent, AnySyncTimelineEvent, AnyTimelineEvent,
MessageLikeEventContent as RumaMessageLikeEventContent, RedactContent,
RedactedStateEventContent, StaticStateEventContent, SyncMessageLikeEvent, SyncStateEvent,
},
EventId,
};
use crate::{room_member::MembershipState, ruma::MessageType, ClientError};
use crate::{
room_member::MembershipState,
ruma::{MessageType, NotifyType},
ClientError,
};
#[derive(uniffi::Object)]
pub struct TimelineEvent(pub(crate) AnySyncTimelineEvent);
#[uniffi::export]
#[matrix_sdk_ffi_macros::export]
impl TimelineEvent {
pub fn event_id(&self) -> String {
self.0.event_id().to_string()
@@ -95,7 +108,7 @@ impl TryFrom<AnySyncStateEvent> for StateEventContent {
let original_content = get_state_event_original_content(content)?;
StateEventContent::RoomMemberContent {
user_id: state_key,
membership_state: original_content.membership.into(),
membership_state: original_content.membership.try_into()?,
}
}
AnySyncStateEvent::RoomName(_) => StateEventContent::RoomName,
@@ -117,6 +130,7 @@ impl TryFrom<AnySyncStateEvent> for StateEventContent {
pub enum MessageLikeEventContent {
CallAnswer,
CallInvite,
CallNotify { notify_type: NotifyType },
CallHangup,
CallCandidates,
KeyVerificationReady,
@@ -130,7 +144,7 @@ pub enum MessageLikeEventContent {
ReactionContent { related_event_id: String },
RoomEncrypted,
RoomMessage { message_type: MessageType, in_reply_to_event_id: Option<String> },
RoomRedaction,
RoomRedaction { redacted_event_id: Option<String>, reason: Option<String> },
Sticker,
}
@@ -141,6 +155,12 @@ impl TryFrom<AnySyncMessageLikeEvent> for MessageLikeEventContent {
let content = match value {
AnySyncMessageLikeEvent::CallAnswer(_) => MessageLikeEventContent::CallAnswer,
AnySyncMessageLikeEvent::CallInvite(_) => MessageLikeEventContent::CallInvite,
AnySyncMessageLikeEvent::CallNotify(content) => {
let original_content = get_message_like_event_original_content(content)?;
MessageLikeEventContent::CallNotify {
notify_type: original_content.notify_type.into(),
}
}
AnySyncMessageLikeEvent::CallHangup(_) => MessageLikeEventContent::CallHangup,
AnySyncMessageLikeEvent::CallCandidates(_) => MessageLikeEventContent::CallCandidates,
AnySyncMessageLikeEvent::KeyVerificationReady(_) => {
@@ -185,11 +205,21 @@ impl TryFrom<AnySyncMessageLikeEvent> for MessageLikeEventContent {
_ => None,
});
MessageLikeEventContent::RoomMessage {
message_type: original_content.msgtype.into(),
message_type: original_content.msgtype.try_into()?,
in_reply_to_event_id,
}
}
AnySyncMessageLikeEvent::RoomRedaction(_) => MessageLikeEventContent::RoomRedaction,
AnySyncMessageLikeEvent::RoomRedaction(c) => {
let (redacted_event_id, reason) = match c {
SyncRoomRedactionEvent::Original(o) => {
let id =
if o.content.redacts.is_some() { o.content.redacts } else { o.redacts };
(id.map(|id| id.to_string()), o.content.reason)
}
SyncRoomRedactionEvent::Redacted(_) => (None, None),
};
MessageLikeEventContent::RoomRedaction { redacted_event_id, reason }
}
AnySyncMessageLikeEvent::Sticker(_) => MessageLikeEventContent::Sticker,
_ => bail!("Unsupported Event Type"),
};
@@ -216,3 +246,183 @@ where
event.as_original().context("Failed to get original content")?.content.clone();
Ok(original_content)
}
#[derive(Clone, uniffi::Enum)]
pub enum StateEventType {
CallMember,
PolicyRuleRoom,
PolicyRuleServer,
PolicyRuleUser,
RoomAliases,
RoomAvatar,
RoomCanonicalAlias,
RoomCreate,
RoomEncryption,
RoomGuestAccess,
RoomHistoryVisibility,
RoomJoinRules,
RoomMemberEvent,
RoomName,
RoomPinnedEvents,
RoomPowerLevels,
RoomServerAcl,
RoomThirdPartyInvite,
RoomTombstone,
RoomTopic,
SpaceChild,
SpaceParent,
}
impl From<StateEventType> for ruma::events::StateEventType {
fn from(val: StateEventType) -> Self {
match val {
StateEventType::CallMember => Self::CallMember,
StateEventType::PolicyRuleRoom => Self::PolicyRuleRoom,
StateEventType::PolicyRuleServer => Self::PolicyRuleServer,
StateEventType::PolicyRuleUser => Self::PolicyRuleUser,
StateEventType::RoomAliases => Self::RoomAliases,
StateEventType::RoomAvatar => Self::RoomAvatar,
StateEventType::RoomCanonicalAlias => Self::RoomCanonicalAlias,
StateEventType::RoomCreate => Self::RoomCreate,
StateEventType::RoomEncryption => Self::RoomEncryption,
StateEventType::RoomGuestAccess => Self::RoomGuestAccess,
StateEventType::RoomHistoryVisibility => Self::RoomHistoryVisibility,
StateEventType::RoomJoinRules => Self::RoomJoinRules,
StateEventType::RoomMemberEvent => Self::RoomMember,
StateEventType::RoomName => Self::RoomName,
StateEventType::RoomPinnedEvents => Self::RoomPinnedEvents,
StateEventType::RoomPowerLevels => Self::RoomPowerLevels,
StateEventType::RoomServerAcl => Self::RoomServerAcl,
StateEventType::RoomThirdPartyInvite => Self::RoomThirdPartyInvite,
StateEventType::RoomTombstone => Self::RoomTombstone,
StateEventType::RoomTopic => Self::RoomTopic,
StateEventType::SpaceChild => Self::SpaceChild,
StateEventType::SpaceParent => Self::SpaceParent,
}
}
}
#[derive(Clone, uniffi::Enum)]
pub enum MessageLikeEventType {
CallAnswer,
CallCandidates,
CallHangup,
CallInvite,
CallNotify,
KeyVerificationAccept,
KeyVerificationCancel,
KeyVerificationDone,
KeyVerificationKey,
KeyVerificationMac,
KeyVerificationReady,
KeyVerificationStart,
PollEnd,
PollResponse,
PollStart,
Reaction,
RoomEncrypted,
RoomMessage,
RoomRedaction,
Sticker,
UnstablePollEnd,
UnstablePollResponse,
UnstablePollStart,
}
impl From<MessageLikeEventType> for ruma::events::MessageLikeEventType {
fn from(val: MessageLikeEventType) -> Self {
match val {
MessageLikeEventType::CallAnswer => Self::CallAnswer,
MessageLikeEventType::CallInvite => Self::CallInvite,
MessageLikeEventType::CallNotify => Self::CallNotify,
MessageLikeEventType::CallHangup => Self::CallHangup,
MessageLikeEventType::CallCandidates => Self::CallCandidates,
MessageLikeEventType::KeyVerificationReady => Self::KeyVerificationReady,
MessageLikeEventType::KeyVerificationStart => Self::KeyVerificationStart,
MessageLikeEventType::KeyVerificationCancel => Self::KeyVerificationCancel,
MessageLikeEventType::KeyVerificationAccept => Self::KeyVerificationAccept,
MessageLikeEventType::KeyVerificationKey => Self::KeyVerificationKey,
MessageLikeEventType::KeyVerificationMac => Self::KeyVerificationMac,
MessageLikeEventType::KeyVerificationDone => Self::KeyVerificationDone,
MessageLikeEventType::Reaction => Self::Reaction,
MessageLikeEventType::RoomEncrypted => Self::RoomEncrypted,
MessageLikeEventType::RoomMessage => Self::RoomMessage,
MessageLikeEventType::RoomRedaction => Self::RoomRedaction,
MessageLikeEventType::Sticker => Self::Sticker,
MessageLikeEventType::PollEnd => Self::PollEnd,
MessageLikeEventType::PollResponse => Self::PollResponse,
MessageLikeEventType::PollStart => Self::PollStart,
MessageLikeEventType::UnstablePollEnd => Self::UnstablePollEnd,
MessageLikeEventType::UnstablePollResponse => Self::UnstablePollResponse,
MessageLikeEventType::UnstablePollStart => Self::UnstablePollStart,
}
}
}
#[derive(Debug, PartialEq, Clone, uniffi::Enum)]
pub enum RoomMessageEventMessageType {
Audio,
Emote,
File,
Image,
Location,
Notice,
ServerNotice,
Text,
Video,
VerificationRequest,
Other,
}
impl From<RumaMessageType> for RoomMessageEventMessageType {
fn from(val: ruma::events::room::message::MessageType) -> Self {
match val {
RumaMessageType::Audio { .. } => Self::Audio,
RumaMessageType::Emote { .. } => Self::Emote,
RumaMessageType::File { .. } => Self::File,
RumaMessageType::Image { .. } => Self::Image,
RumaMessageType::Location { .. } => Self::Location,
RumaMessageType::Notice { .. } => Self::Notice,
RumaMessageType::ServerNotice { .. } => Self::ServerNotice,
RumaMessageType::Text { .. } => Self::Text,
RumaMessageType::Video { .. } => Self::Video,
RumaMessageType::VerificationRequest { .. } => Self::VerificationRequest,
_ => Self::Other,
}
}
}
/// Contains the 2 possible identifiers of an event, either it has a remote
/// event id or a local transaction id, never both or none.
#[derive(Clone, uniffi::Enum)]
pub enum EventOrTransactionId {
EventId { event_id: String },
TransactionId { transaction_id: String },
}
impl From<TimelineEventItemId> for EventOrTransactionId {
fn from(value: TimelineEventItemId) -> Self {
match value {
TimelineEventItemId::EventId(event_id) => {
EventOrTransactionId::EventId { event_id: event_id.to_string() }
}
TimelineEventItemId::TransactionId(transaction_id) => {
EventOrTransactionId::TransactionId { transaction_id: transaction_id.to_string() }
}
}
}
}
impl TryFrom<EventOrTransactionId> for TimelineEventItemId {
type Error = IdParseError;
fn try_from(value: EventOrTransactionId) -> Result<Self, Self::Error> {
match value {
EventOrTransactionId::EventId { event_id } => {
Ok(TimelineEventItemId::EventId(EventId::parse(event_id)?))
}
EventOrTransactionId::TransactionId { transaction_id } => {
Ok(TimelineEventItemId::TransactionId(transaction_id.into()))
}
}
}
}
@@ -1,4 +1,4 @@
// Copyright 2023 The Matrix.org Foundation C.I.C.
// Copyright 2024 The Matrix.org Foundation C.I.C.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -12,6 +12,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.
pub mod oidc;
use matrix_sdk::crypto::IdentityState;
// TODO(pixlwave) Move AuthenticationService from the FFI into here.
#[derive(uniffi::Record)]
pub struct IdentityStatusChange {
/// The user ID of the user whose identity status changed
pub user_id: String,
/// The new state of the identity of the user.
pub changed_to: IdentityState,
}
+12 -24
View File
@@ -1,63 +1,51 @@
// TODO: target-os conditional would be good.
#![allow(unused_qualifications, clippy::new_without_default)]
#![allow(clippy::empty_line_after_doc_comments)] // Needed because uniffi macros contain empty
// lines after docs.
macro_rules! unwrap_or_clone_arc_into_variant {
(
$arc:ident $(, .$field:tt)?, $pat:pat => $body:expr
) => {
#[allow(unused_variables)]
match &(*$arc)$(.$field)? {
$pat => {
#[warn(unused_variables)]
match crate::helpers::unwrap_or_clone_arc($arc)$(.$field)? {
$pat => Some($body),
_ => unreachable!(),
}
},
_ => None,
}
};
}
mod authentication_service;
mod authentication;
mod chunk_iterator;
mod client;
mod client_builder;
mod element;
mod encryption;
mod error;
mod event;
mod helpers;
mod identity_status_change;
mod notification;
mod notification_settings;
mod platform;
mod room;
mod room_alias;
mod room_directory_search;
mod room_info;
mod room_list;
mod room_member;
mod room_preview;
mod ruma;
mod session_verification;
mod sync_service;
mod task_handle;
mod timeline;
mod timeline_event_filter;
mod tracing;
mod utils;
mod widget;
use async_compat::TOKIO1 as RUNTIME;
use matrix_sdk::ruma::events::room::{
message::RoomMessageEventContentWithoutRelation, MediaSource,
};
use matrix_sdk::ruma::events::room::message::RoomMessageEventContentWithoutRelation;
use self::{
error::ClientError,
ruma::{MediaSourceExt, Mentions, RoomMessageEventContentWithoutRelationExt},
ruma::{Mentions, RoomMessageEventContentWithoutRelationExt},
task_handle::TaskHandle,
};
uniffi::include_scaffolding!("api");
#[uniffi::export]
#[matrix_sdk_ffi_macros::export]
fn sdk_git_sha() -> String {
env!("VERGEN_GIT_SHA").to_owned()
}
+18 -57
View File
@@ -1,15 +1,11 @@
use std::sync::Arc;
use matrix_sdk_ui::notification_client::{
NotificationClient as MatrixNotificationClient,
NotificationClientBuilder as MatrixNotificationClientBuilder,
NotificationItem as MatrixNotificationItem, NotificationProcessSetup,
NotificationClient as MatrixNotificationClient, NotificationItem as MatrixNotificationItem,
};
use ruma::{EventId, RoomId};
use crate::{
client::Client, error::ClientError, event::TimelineEvent, helpers::unwrap_or_clone_arc, RUNTIME,
};
use crate::{client::Client, error::ClientError, event::TimelineEvent};
#[derive(uniffi::Enum)]
pub enum NotificationEvent {
@@ -21,6 +17,7 @@ pub enum NotificationEvent {
pub struct NotificationSenderInfo {
pub display_name: Option<String>,
pub avatar_url: Option<String>,
pub is_name_ambiguous: bool,
}
#[derive(uniffi::Record)]
@@ -63,9 +60,10 @@ impl NotificationItem {
sender_info: NotificationSenderInfo {
display_name: item.sender_display_name,
avatar_url: item.sender_avatar_url,
is_name_ambiguous: item.is_sender_name_ambiguous,
},
room_info: NotificationRoomInfo {
display_name: item.room_display_name,
display_name: item.room_computed_display_name,
avatar_url: item.room_avatar_url,
canonical_alias: item.room_canonical_alias,
joined_members_count: item.joined_members_count,
@@ -78,74 +76,37 @@ impl NotificationItem {
}
}
#[derive(Clone, uniffi::Object)]
pub struct NotificationClientBuilder {
client: Arc<Client>,
builder: MatrixNotificationClientBuilder,
}
impl NotificationClientBuilder {
pub(crate) fn new(
client: Arc<Client>,
process_setup: NotificationProcessSetup,
) -> Result<Arc<Self>, ClientError> {
let builder = RUNTIME.block_on(async {
MatrixNotificationClient::builder((*client.inner).clone(), process_setup).await
})?;
Ok(Arc::new(Self { builder, client }))
}
}
#[uniffi::export]
impl NotificationClientBuilder {
/// Filter out the notification event according to the push rules present in
/// the event.
pub fn filter_by_push_rules(self: Arc<Self>) -> Arc<Self> {
let this = unwrap_or_clone_arc(self);
let builder = this.builder.filter_by_push_rules();
Arc::new(Self { builder, client: this.client })
}
pub fn finish(self: Arc<Self>) -> Arc<NotificationClient> {
let this = unwrap_or_clone_arc(self);
Arc::new(NotificationClient { inner: this.builder.build(), _client: this.client })
}
}
#[derive(uniffi::Object)]
pub struct NotificationClient {
inner: MatrixNotificationClient,
pub(crate) inner: MatrixNotificationClient,
/// A reference to the FFI client.
///
/// Note: we do this to make it so that the FFI `NotificationClient` keeps
/// the FFI `Client` and thus the SDK `Client` alive. Otherwise, we
/// would need to repeat the hack done in the FFI `Client::drop` method.
_client: Arc<Client>,
pub(crate) _client: Arc<Client>,
}
#[uniffi::export]
#[matrix_sdk_ffi_macros::export]
impl NotificationClient {
/// See also documentation of
/// `MatrixNotificationClient::get_notification`.
pub fn get_notification(
pub async fn get_notification(
&self,
room_id: String,
event_id: String,
) -> Result<Option<NotificationItem>, ClientError> {
let room_id = RoomId::parse(room_id)?;
let event_id = EventId::parse(event_id)?;
RUNTIME.block_on(async move {
let item = self
.inner
.get_notification(&room_id, &event_id)
.await
.map_err(ClientError::from)?;
if let Some(item) = item {
Ok(Some(NotificationItem::from_inner(item)))
} else {
Ok(None)
}
})
let item =
self.inner.get_notification(&room_id, &event_id).await.map_err(ClientError::from)?;
if let Some(item) = item {
Ok(Some(NotificationItem::from_inner(item)))
} else {
Ok(None)
}
}
}
@@ -1,4 +1,4 @@
use std::sync::Arc;
use std::sync::{Arc, RwLock};
use matrix_sdk::{
event_handler::EventHandlerHandle,
@@ -13,9 +13,8 @@ use ruma::{
push::{PredefinedOverrideRuleId, PredefinedUnderrideRuleId, RuleKind},
RoomId,
};
use tokio::sync::RwLock;
use tokio::sync::RwLock as AsyncRwLock;
use super::RUNTIME;
use crate::error::NotificationSettingsError;
/// Enum representing the push notification modes for a room.
@@ -50,7 +49,7 @@ impl From<RoomNotificationMode> for SdkRoomNotificationMode {
}
/// Delegate to notify of changes in push rules
#[uniffi::export(callback_interface)]
#[matrix_sdk_ffi_macros::export(callback_interface)]
pub trait NotificationSettingsDelegate: Sync + Send {
fn settings_did_change(&self);
}
@@ -73,7 +72,7 @@ impl RoomNotificationSettings {
#[derive(Clone, uniffi::Object)]
pub struct NotificationSettings {
sdk_client: MatrixClient,
sdk_notification_settings: Arc<RwLock<SdkNotificationSettings>>,
sdk_notification_settings: Arc<AsyncRwLock<SdkNotificationSettings>>,
pushrules_event_handler: Arc<RwLock<Option<EventHandlerHandle>>>,
}
@@ -82,10 +81,9 @@ impl NotificationSettings {
sdk_client: MatrixClient,
sdk_notification_settings: SdkNotificationSettings,
) -> Self {
let sdk_notification_settings = Arc::new(RwLock::new(sdk_notification_settings));
Self {
sdk_client,
sdk_notification_settings,
sdk_notification_settings: Arc::new(AsyncRwLock::new(sdk_notification_settings)),
pushrules_event_handler: Arc::new(RwLock::new(None)),
}
}
@@ -94,15 +92,13 @@ impl NotificationSettings {
impl Drop for NotificationSettings {
fn drop(&mut self) {
// Remove the event handler on the sdk_client.
RUNTIME.block_on(async move {
if let Some(event_handler) = self.pushrules_event_handler.read().await.as_ref() {
self.sdk_client.remove_event_handler(event_handler.clone());
}
});
if let Some(event_handler) = self.pushrules_event_handler.read().unwrap().as_ref() {
self.sdk_client.remove_event_handler(event_handler.clone());
}
}
}
#[uniffi::export(async_runtime = "tokio")]
#[matrix_sdk_ffi_macros::export]
impl NotificationSettings {
pub fn set_delegate(&self, delegate: Option<Box<dyn NotificationSettingsDelegate>>) {
if let Some(delegate) = delegate {
@@ -114,18 +110,14 @@ impl NotificationSettings {
delegate.settings_did_change();
});
RUNTIME.block_on(async move {
*self.pushrules_event_handler.write().await = Some(event_handler);
});
*self.pushrules_event_handler.write().unwrap() = Some(event_handler);
} else {
// Remove the event handler if there is no delegate
RUNTIME.block_on(async move {
let event_handler = &mut *self.pushrules_event_handler.write().await;
if let Some(event_handler) = event_handler {
self.sdk_client.remove_event_handler(event_handler.clone());
}
*event_handler = None;
});
let event_handler = &mut *self.pushrules_event_handler.write().unwrap();
if let Some(event_handler) = event_handler {
self.sdk_client.remove_event_handler(event_handler.clone());
}
*event_handler = None;
}
}
@@ -143,9 +135,11 @@ impl NotificationSettings {
is_encrypted: bool,
is_one_to_one: bool,
) -> Result<RoomNotificationSettings, NotificationSettingsError> {
let notification_settings = self.sdk_notification_settings.read().await;
let parsed_room_id = RoomId::parse(&room_id)
.map_err(|_e| NotificationSettingsError::InvalidRoomId { room_id })?;
let notification_settings = self.sdk_notification_settings.read().await;
// Get the current user defined mode for this room
if let Some(mode) =
notification_settings.get_user_defined_room_notification_mode(&parsed_room_id).await
@@ -158,6 +152,7 @@ impl NotificationSettings {
let mode = notification_settings
.get_default_room_notification_mode(is_encrypted.into(), is_one_to_one.into())
.await;
Ok(RoomNotificationSettings::new(mode.into(), true))
}
@@ -167,10 +162,15 @@ impl NotificationSettings {
room_id: String,
mode: RoomNotificationMode,
) -> Result<(), NotificationSettingsError> {
let notification_settings = self.sdk_notification_settings.read().await;
let parsed_room_id = RoomId::parse(&room_id)
.map_err(|_e| NotificationSettingsError::InvalidRoomId { room_id })?;
notification_settings.set_room_notification_mode(&parsed_room_id, mode.into()).await?;
self.sdk_notification_settings
.read()
.await
.set_room_notification_mode(&parsed_room_id, mode.into())
.await?;
Ok(())
}
@@ -297,10 +297,10 @@ impl NotificationSettings {
Ok(enabled)
}
/// Check if [MSC 4028 push rule][rule] is enabled.
/// Returns true if [MSC 4028 push rule][rule] is supported and enabled.
///
/// [rule]: https://github.com/matrix-org/matrix-spec-proposals/blob/giomfo/push_encrypted_events/proposals/4028-push-all-encrypted-events-except-for-muted-rooms.md
pub async fn can_homeserver_push_encrypted_event_to_device(&self) -> bool {
pub async fn can_push_encrypted_event_to_device(&self) -> bool {
let notification_settings = self.sdk_notification_settings.read().await;
// Check stable identifier
if let Ok(enabled) = notification_settings
@@ -308,17 +308,22 @@ impl NotificationSettings {
.await
{
enabled
// Check unstable identifier
} else if let Ok(enabled) = notification_settings
.is_push_rule_enabled(RuleKind::Override, ".org.matrix.msc4028.encrypted_event")
.await
{
enabled
} else {
false
// Check unstable identifier
notification_settings
.is_push_rule_enabled(RuleKind::Override, ".org.matrix.msc4028.encrypted_event")
.await
.unwrap_or(false)
}
}
/// Check whether [MSC 4028 push rule][rule] is enabled on the homeserver.
///
/// [rule]: https://github.com/matrix-org/matrix-spec-proposals/blob/giomfo/push_encrypted_events/proposals/4028-push-all-encrypted-events-except-for-muted-rooms.md
pub async fn can_homeserver_push_encrypted_event_to_device(&self) -> bool {
self.sdk_client.can_homeserver_push_encrypted_event_to_device().await.unwrap()
}
/// Set whether user mentions are enabled.
pub async fn set_user_mention_enabled(
&self,
+86 -127
View File
@@ -1,95 +1,19 @@
use std::{collections::HashMap, fmt::Debug, pin::Pin};
use base64::{engine::general_purpose::STANDARD, Engine};
use futures_core::future::BoxFuture;
use opentelemetry::KeyValue;
use opentelemetry_otlp::{Protocol, WithExportConfig};
use opentelemetry_sdk::{runtime::RuntimeChannel, trace::Tracer, Resource};
use tokio::runtime::Handle;
use tracing_appender::rolling::{RollingFileAppender, Rotation};
use tracing_core::Subscriber;
use tracing_subscriber::{
fmt::{self, time::FormatTime, FormatEvent, FormatFields, FormattedFields},
field::RecordFields,
fmt::{
self,
format::{DefaultFields, Writer},
time::FormatTime,
FormatEvent, FormatFields, FormattedFields,
},
layer::SubscriberExt,
registry::LookupSpan,
util::SubscriberInitExt,
EnvFilter, Layer,
};
use crate::RUNTIME;
#[derive(Clone, Debug)]
struct TokioRuntime {
runtime: Handle,
}
impl opentelemetry_sdk::runtime::Runtime for TokioRuntime {
type Interval = tokio_stream::wrappers::IntervalStream;
type Delay = Pin<Box<tokio::time::Sleep>>;
fn interval(&self, period: std::time::Duration) -> Self::Interval {
let _guard = self.runtime.enter();
tokio_stream::wrappers::IntervalStream::new(tokio::time::interval(period))
}
fn spawn(&self, future: BoxFuture<'static, ()>) {
#[allow(clippy::let_underscore_future)]
let _ = self.runtime.spawn(future);
}
fn delay(&self, duration: std::time::Duration) -> Self::Delay {
let _guard = self.runtime.enter();
Box::pin(tokio::time::sleep(duration))
}
}
impl RuntimeChannel for TokioRuntime {
type Receiver<T: Debug + Send> = tokio_stream::wrappers::ReceiverStream<T>;
type Sender<T: Debug + Send> = tokio::sync::mpsc::Sender<T>;
fn batch_message_channel<T: Debug + Send>(
&self,
capacity: usize,
) -> (Self::Sender<T>, Self::Receiver<T>) {
let (sender, receiver) = tokio::sync::mpsc::channel(capacity);
(sender, tokio_stream::wrappers::ReceiverStream::new(receiver))
}
}
pub fn create_otlp_tracer(
user: String,
password: String,
otlp_endpoint: String,
client_name: String,
) -> anyhow::Result<Tracer> {
let runtime = RUNTIME.handle().to_owned();
let auth = STANDARD.encode(format!("{user}:{password}"));
let headers = HashMap::from([("Authorization".to_owned(), format!("Basic {auth}"))]);
let http_client = matrix_sdk::reqwest::ClientBuilder::new().build()?;
let exporter = opentelemetry_otlp::new_exporter()
.http()
.with_http_client(http_client)
.with_protocol(Protocol::HttpBinary)
.with_endpoint(otlp_endpoint)
.with_headers(headers);
let tracer_runtime = TokioRuntime { runtime: runtime.to_owned() };
let _guard = runtime.enter();
let tracer = opentelemetry_otlp::new_pipeline()
.tracing()
.with_exporter(exporter)
.with_trace_config(
opentelemetry_sdk::trace::config()
.with_resource(Resource::new(vec![KeyValue::new("service.name", client_name)])),
)
.install_batch(tracer_runtime)?;
Ok(tracer)
}
#[cfg(target_os = "android")]
pub fn log_panics() {
std::env::set_var("RUST_BACKTRACE", "1");
log_panics::init();
@@ -179,17 +103,19 @@ where
if let Some(scope) = ctx.event_scope() {
writer.write_str(" | spans: ")?;
let mut first = true;
for span in scope.from_root() {
if !first {
writer.write_str(" > ")?;
}
first = false;
write!(writer, "{}", span.metadata().name())?;
let ext = span.extensions();
if let Some(fields) = &ext.get::<FormattedFields<N>>() {
first = false;
write!(writer, "{}", span.name())?;
if let Some(fields) = &span.extensions().get::<FormattedFields<N>>() {
if !fields.is_empty() {
write!(writer, "{{{fields}}}")?;
}
@@ -202,20 +128,69 @@ where
}
let file_layer = config.write_to_files.map(|c| {
let mut builder = RollingFileAppender::builder()
.rotation(Rotation::HOURLY)
.filename_prefix(&c.file_prefix);
if let Some(max_files) = c.max_files {
builder = builder.max_log_files(max_files as usize)
};
if let Some(file_suffix) = c.file_suffix {
builder = builder.filename_suffix(file_suffix)
}
let writer = builder.build(&c.path).expect("Failed to create a rolling file appender.");
// Another fields formatter is necessary because of this bug
// https://github.com/tokio-rs/tracing/issues/1372. Using a new
// formatter for the fields forces to record them in different span
// extensions, and thus remove the duplicated fields in the span.
#[derive(Default)]
struct FieldsFormatterForFiles(DefaultFields);
impl<'writer> FormatFields<'writer> for FieldsFormatterForFiles {
fn format_fields<R: RecordFields>(
&self,
writer: Writer<'writer>,
fields: R,
) -> std::fmt::Result {
self.0.format_fields(writer, fields)
}
}
fmt::layer()
.fmt_fields(FieldsFormatterForFiles::default())
.event_format(EventFormatter::new())
// EventFormatter doesn't support ANSI colors anyways, but the
// default field formatter does, which is unhelpful for iOS +
// Android logs, but enabled by default.
.with_ansi(false)
.with_writer(tracing_appender::rolling::hourly(c.path, c.file_prefix))
.with_writer(writer)
});
Layer::and_then(
file_layer,
config.write_to_stdout_or_system.then(|| {
// Another fields formatter is necessary because of this bug
// https://github.com/tokio-rs/tracing/issues/1372. Using a new
// formatter for the fields forces to record them in different span
// extensions, and thus remove the duplicated fields in the span.
#[derive(Default)]
struct FieldsFormatterFormStdoutOrSystem(DefaultFields);
impl<'writer> FormatFields<'writer> for FieldsFormatterFormStdoutOrSystem {
fn format_fields<R: RecordFields>(
&self,
writer: Writer<'writer>,
fields: R,
) -> std::fmt::Result {
self.0.format_fields(writer, fields)
}
}
#[cfg(not(target_os = "android"))]
return fmt::layer()
.fmt_fields(FieldsFormatterFormStdoutOrSystem::default())
.event_format(EventFormatter::new())
// See comment above.
.with_ansi(false)
@@ -223,6 +198,7 @@ where
#[cfg(target_os = "android")]
return fmt::layer()
.fmt_fields(FieldsFormatterFormStdoutOrSystem::default())
.event_format(EventFormatter::for_logcat())
// See comment above.
.with_ansi(false)
@@ -233,24 +209,41 @@ where
)
}
/// Configuration to save logs to (rotated) log-files.
#[derive(uniffi::Record)]
pub struct TracingFileConfiguration {
/// Base location for all the log files.
path: String,
/// Prefix for the log files' names.
file_prefix: String,
/// Optional suffix for the log file's names.
file_suffix: Option<String>,
/// Maximum number of rotated files.
///
/// If not set, there's no max limit, i.e. the number of log files is
/// unlimited.
max_files: Option<u64>,
}
#[derive(uniffi::Record)]
pub struct TracingConfiguration {
/// A filter line following the [RUST_LOG format].
///
/// [RUST_LOG format]: https://rust-lang-nursery.github.io/rust-cookbook/development_tools/debugging/config_log.html
filter: String,
/// Controls whether to print to stdout or, equivalent, the system logs on
/// Android.
/// Whether to log to stdout, or in the logcat on Android.
write_to_stdout_or_system: bool,
/// If set, configures rotated log files where to write additional logs.
write_to_files: Option<TracingFileConfiguration>,
}
#[uniffi::export]
#[matrix_sdk_ffi_macros::export]
pub fn setup_tracing(config: TracingConfiguration) {
#[cfg(target_os = "android")]
log_panics();
tracing_subscriber::registry()
@@ -258,37 +251,3 @@ pub fn setup_tracing(config: TracingConfiguration) {
.with(text_layers(config))
.init();
}
#[derive(uniffi::Record)]
pub struct OtlpTracingConfiguration {
client_name: String,
user: String,
password: String,
otlp_endpoint: String,
filter: String,
/// Controls whether to print to stdout or, equivalent, the system logs on
/// Android.
write_to_stdout_or_system: bool,
write_to_files: Option<TracingFileConfiguration>,
}
#[uniffi::export]
pub fn setup_otlp_tracing(config: OtlpTracingConfiguration) {
#[cfg(target_os = "android")]
log_panics();
let otlp_tracer =
create_otlp_tracer(config.user, config.password, config.otlp_endpoint, config.client_name)
.expect("Couldn't configure the OpenTelemetry tracer");
let otlp_layer = tracing_opentelemetry::layer().with_tracer(otlp_tracer);
tracing_subscriber::registry()
.with(EnvFilter::new(&config.filter))
.with(text_layers(TracingConfiguration {
filter: config.filter,
write_to_stdout_or_system: config.write_to_stdout_or_system,
write_to_files: config.write_to_files,
}))
.with(otlp_layer)
.init();
}
File diff suppressed because it is too large Load Diff
+17
View File
@@ -0,0 +1,17 @@
use matrix_sdk::RoomDisplayName;
/// Verifies the passed `String` matches the expected room alias format:
///
/// This means it's lowercase, with no whitespace chars, has a single leading
/// `#` char and a single `:` separator between the local and domain parts, and
/// the local part only contains characters that can't be percent encoded.
#[matrix_sdk_ffi_macros::export]
fn is_room_alias_format_valid(alias: String) -> bool {
matrix_sdk::utils::is_room_alias_format_valid(alias)
}
/// Transforms a Room's display name into a valid room alias name.
#[matrix_sdk_ffi_macros::export]
fn room_alias_name_from_room_display_name(room_name: String) -> String {
RoomDisplayName::Named(room_name).to_room_alias_name()
}
@@ -0,0 +1,203 @@
// Copyright 2024 Mauro Romito
// Copyright 2024 The Matrix.org Foundation C.I.C.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use std::{fmt::Debug, sync::Arc};
use eyeball_im::VectorDiff;
use futures_util::StreamExt;
use matrix_sdk::room_directory_search::RoomDirectorySearch as SdkRoomDirectorySearch;
use ruma::ServerName;
use tokio::sync::RwLock;
use super::RUNTIME;
use crate::{error::ClientError, task_handle::TaskHandle};
#[derive(uniffi::Enum)]
pub enum PublicRoomJoinRule {
Public,
Knock,
}
impl TryFrom<ruma::directory::PublicRoomJoinRule> for PublicRoomJoinRule {
type Error = String;
fn try_from(value: ruma::directory::PublicRoomJoinRule) -> Result<Self, Self::Error> {
match value {
ruma::directory::PublicRoomJoinRule::Public => Ok(Self::Public),
ruma::directory::PublicRoomJoinRule::Knock => Ok(Self::Knock),
rule => Err(format!("unsupported join rule: {rule:?}")),
}
}
}
#[derive(uniffi::Record)]
pub struct RoomDescription {
pub room_id: String,
pub name: Option<String>,
pub topic: Option<String>,
pub alias: Option<String>,
pub avatar_url: Option<String>,
pub join_rule: Option<PublicRoomJoinRule>,
pub is_world_readable: bool,
pub joined_members: u64,
}
impl From<matrix_sdk::room_directory_search::RoomDescription> for RoomDescription {
fn from(value: matrix_sdk::room_directory_search::RoomDescription) -> Self {
Self {
room_id: value.room_id.to_string(),
name: value.name,
topic: value.topic,
alias: value.alias.map(|alias| alias.to_string()),
avatar_url: value.avatar_url.map(|url| url.to_string()),
join_rule: value.join_rule.try_into().ok(),
is_world_readable: value.is_world_readable,
joined_members: value.joined_members,
}
}
}
/// A helper for performing room searches in the room directory.
/// The way this is intended to be used is:
///
/// 1. Register a callback using [`RoomDirectorySearch::results`].
/// 2. Start the room search with [`RoomDirectorySearch::search`].
/// 3. To get more results, use [`RoomDirectorySearch::next_page`].
#[derive(uniffi::Object)]
pub struct RoomDirectorySearch {
pub(crate) inner: RwLock<SdkRoomDirectorySearch>,
}
impl RoomDirectorySearch {
pub fn new(inner: SdkRoomDirectorySearch) -> Self {
Self { inner: RwLock::new(inner) }
}
}
#[matrix_sdk_ffi_macros::export]
impl RoomDirectorySearch {
/// Asks the server for the next page of the current search.
pub async fn next_page(&self) -> Result<(), ClientError> {
let mut inner = self.inner.write().await;
inner.next_page().await?;
Ok(())
}
/// Starts a filtered search for the server.
///
/// If the `filter` is not provided it will search for all the rooms.
/// You can specify a `batch_size` to control the number of rooms to fetch
/// per request.
///
/// If the `via_server` is not provided it will search in the current
/// homeserver by default.
///
/// This method will clear the current search results and start a new one.
pub async fn search(
&self,
filter: Option<String>,
batch_size: u32,
via_server_name: Option<String>,
) -> Result<(), ClientError> {
let server = via_server_name.map(ServerName::parse).transpose()?;
let mut inner = self.inner.write().await;
inner.search(filter, batch_size, server).await?;
Ok(())
}
/// Get the number of pages that have been loaded so far.
pub async fn loaded_pages(&self) -> Result<u32, ClientError> {
let inner = self.inner.read().await;
Ok(inner.loaded_pages() as u32)
}
/// Get whether the search is at the last page.
pub async fn is_at_last_page(&self) -> Result<bool, ClientError> {
let inner = self.inner.read().await;
Ok(inner.is_at_last_page())
}
/// Registers a callback to receive new search results when starting a
/// search or getting new paginated results.
pub async fn results(
&self,
listener: Box<dyn RoomDirectorySearchEntriesListener>,
) -> Arc<TaskHandle> {
let (initial_values, mut stream) = self.inner.read().await.results();
Arc::new(TaskHandle::new(RUNTIME.spawn(async move {
listener.on_update(vec![RoomDirectorySearchEntryUpdate::Reset {
values: initial_values.into_iter().map(Into::into).collect(),
}]);
while let Some(diffs) = stream.next().await {
listener.on_update(diffs.into_iter().map(|diff| diff.into()).collect());
}
})))
}
}
#[derive(uniffi::Record)]
pub struct RoomDirectorySearchEntriesResult {
pub entries_stream: Arc<TaskHandle>,
}
#[derive(uniffi::Enum)]
pub enum RoomDirectorySearchEntryUpdate {
Append { values: Vec<RoomDescription> },
Clear,
PushFront { value: RoomDescription },
PushBack { value: RoomDescription },
PopFront,
PopBack,
Insert { index: u32, value: RoomDescription },
Set { index: u32, value: RoomDescription },
Remove { index: u32 },
Truncate { length: u32 },
Reset { values: Vec<RoomDescription> },
}
impl From<VectorDiff<matrix_sdk::room_directory_search::RoomDescription>>
for RoomDirectorySearchEntryUpdate
{
fn from(diff: VectorDiff<matrix_sdk::room_directory_search::RoomDescription>) -> Self {
match diff {
VectorDiff::Append { values } => {
Self::Append { values: values.into_iter().map(|v| v.into()).collect() }
}
VectorDiff::Clear => Self::Clear,
VectorDiff::PushFront { value } => Self::PushFront { value: value.into() },
VectorDiff::PushBack { value } => Self::PushBack { value: value.into() },
VectorDiff::PopFront => Self::PopFront,
VectorDiff::PopBack => Self::PopBack,
VectorDiff::Insert { index, value } => {
Self::Insert { index: index as u32, value: value.into() }
}
VectorDiff::Set { index, value } => {
Self::Set { index: index as u32, value: value.into() }
}
VectorDiff::Remove { index } => Self::Remove { index: index as u32 },
VectorDiff::Truncate { length } => Self::Truncate { length: length as u32 },
VectorDiff::Reset { values } => {
Self::Reset { values: values.into_iter().map(|v| v.into()).collect() }
}
}
}
}
#[matrix_sdk_ffi_macros::export(callback_interface)]
pub trait RoomDirectorySearchEntriesListener: Send + Sync + Debug {
fn on_update(&self, room_entries_update: Vec<RoomDirectorySearchEntryUpdate>);
}
+63 -22
View File
@@ -1,36 +1,52 @@
use std::sync::Arc;
use std::collections::HashMap;
use matrix_sdk::RoomState;
use ruma::OwnedMxcUri;
use tracing::warn;
use crate::{
notification_settings::RoomNotificationMode, room::Membership, room_member::RoomMember,
timeline::EventTimelineItem,
client::JoinRule,
notification_settings::RoomNotificationMode,
room::{Membership, RoomHero},
room_member::RoomMember,
};
#[derive(uniffi::Record)]
pub struct RoomInfo {
id: String,
name: Option<String>,
creator: Option<String>,
/// The room's name from the room state event if received from sync, or one
/// that's been computed otherwise.
display_name: Option<String>,
/// Room name as defined by the room state event only.
raw_name: Option<String>,
topic: Option<String>,
avatar_url: Option<String>,
is_direct: bool,
is_public: bool,
is_space: bool,
is_tombstoned: bool,
is_favourite: bool,
canonical_alias: Option<String>,
alternative_aliases: Vec<String>,
membership: Membership,
latest_event: Option<Arc<EventTimelineItem>>,
inviter: Option<Arc<RoomMember>>,
/// Member who invited the current user to a room that's in the invited
/// state.
///
/// Can be missing if the room membership invite event is missing from the
/// store.
inviter: Option<RoomMember>,
heroes: Vec<RoomHero>,
active_members_count: u64,
invited_members_count: u64,
joined_members_count: u64,
user_power_levels: HashMap<String, i64>,
highlight_count: u64,
notification_count: u64,
user_defined_notification_mode: Option<RoomNotificationMode>,
cached_user_defined_notification_mode: Option<RoomNotificationMode>,
has_room_call: bool,
active_room_call_participants: Vec<String>,
/// Whether this room has been explicitly marked as unread
is_marked_unread: bool,
/// "Interesting" messages received in that room, independently of the
/// notification settings.
num_unread_messages: u64,
@@ -40,43 +56,65 @@ pub struct RoomInfo {
/// Events causing mentions/highlights for the user, according to their
/// notification settings.
num_unread_mentions: u64,
/// The currently pinned event ids.
pinned_event_ids: Vec<String>,
/// The join rule for this room, if known.
join_rule: Option<JoinRule>,
}
impl RoomInfo {
pub(crate) async fn new(
room: &matrix_sdk::Room,
avatar_url: Option<OwnedMxcUri>,
latest_event: Option<Arc<EventTimelineItem>>,
) -> matrix_sdk::Result<Self> {
pub(crate) async fn new(room: &matrix_sdk::Room) -> matrix_sdk::Result<Self> {
let unread_notification_counts = room.unread_notification_counts();
let power_levels_map = room.users_with_power_levels().await;
let mut user_power_levels = HashMap::<String, i64>::new();
for (id, level) in power_levels_map.iter() {
user_power_levels.insert(id.to_string(), *level);
}
let pinned_event_ids =
room.pinned_event_ids().unwrap_or_default().iter().map(|id| id.to_string()).collect();
let join_rule = room.join_rule().try_into();
if let Err(e) = &join_rule {
warn!("Failed to parse join rule: {:?}", e);
}
Ok(Self {
id: room.room_id().to_string(),
name: room.name(),
creator: room.creator().as_ref().map(ToString::to_string),
display_name: room.cached_display_name().map(|name| name.to_string()),
raw_name: room.name(),
topic: room.topic(),
avatar_url: avatar_url.map(Into::into),
avatar_url: room.avatar_url().map(Into::into),
is_direct: room.is_direct().await?,
is_public: room.is_public(),
is_space: room.is_space(),
is_tombstoned: room.is_tombstoned(),
is_favourite: room.is_favourite(),
canonical_alias: room.canonical_alias().map(Into::into),
alternative_aliases: room.alt_aliases().into_iter().map(Into::into).collect(),
membership: room.state().into(),
latest_event,
inviter: match room.state() {
RoomState::Invited => {
room.invite_details().await?.inviter.map(|inner| Arc::new(RoomMember { inner }))
}
RoomState::Invited => room
.invite_details()
.await
.ok()
.and_then(|details| details.inviter)
.map(TryInto::try_into)
.transpose()
.ok()
.flatten(),
_ => None,
},
heroes: room.heroes().into_iter().map(Into::into).collect(),
active_members_count: room.active_members_count(),
invited_members_count: room.invited_members_count(),
joined_members_count: room.joined_members_count(),
user_power_levels,
highlight_count: unread_notification_counts.highlight_count,
notification_count: unread_notification_counts.notification_count,
user_defined_notification_mode: room
.user_defined_notification_mode()
.await
cached_user_defined_notification_mode: room
.cached_user_defined_notification_mode()
.map(Into::into),
has_room_call: room.has_active_room_call(),
active_room_call_participants: room
@@ -84,9 +122,12 @@ impl RoomInfo {
.iter()
.map(|u| u.to_string())
.collect(),
is_marked_unread: room.is_marked_unread(),
num_unread_messages: room.num_unread_messages(),
num_unread_notifications: room.num_unread_notifications(),
num_unread_mentions: room.num_unread_mentions(),
pinned_event_ids,
join_rule: join_rule.ok(),
})
}
}
+407 -214
View File
@@ -1,28 +1,34 @@
use std::{fmt::Debug, sync::Arc, time::Duration};
#![allow(deprecated)]
use std::{fmt::Debug, mem::MaybeUninit, ptr::addr_of_mut, sync::Arc, time::Duration};
use eyeball_im::VectorDiff;
use futures_util::{pin_mut, StreamExt};
use matrix_sdk::{
ruma::{
api::client::sync::sync_events::{
v4::RoomSubscription as RumaRoomSubscription,
UnreadNotificationsCount as RumaUnreadNotificationsCount,
},
assign, RoomId,
use futures_util::{pin_mut, StreamExt, TryFutureExt};
use matrix_sdk::ruma::{
api::client::sync::sync_events::UnreadNotificationsCount as RumaUnreadNotificationsCount,
RoomId,
};
use matrix_sdk_ui::{
room_list_service::filters::{
new_filter_all, new_filter_any, new_filter_category, new_filter_favourite,
new_filter_fuzzy_match_room_name, new_filter_invite, new_filter_joined,
new_filter_non_left, new_filter_none, new_filter_normalized_match_room_name,
new_filter_unread, BoxedFilterFn, RoomCategory,
},
RoomListEntry as MatrixRoomListEntry,
};
use matrix_sdk_ui::room_list_service::filters::{
new_filter_all, new_filter_all_non_left, new_filter_fuzzy_match_room_name, new_filter_none,
new_filter_normalized_match_room_name,
timeline::default_event_filter,
unable_to_decrypt_hook::UtdHookManager,
};
use ruma::{OwnedRoomOrAliasId, OwnedServerName, ServerName};
use tokio::sync::RwLock;
use crate::{
error::ClientError,
room::Room,
room::{Membership, Room},
room_info::RoomInfo,
room_preview::RoomPreview,
timeline::{EventTimelineItem, Timeline},
timeline_event_filter::TimelineEventTypeFilter,
utils::AsyncRuntimeDropped,
TaskHandle, RUNTIME,
};
@@ -38,6 +44,16 @@ pub enum RoomListError {
RoomNotFound { room_name: String },
#[error("invalid room ID: {error}")]
InvalidRoomId { error: String },
#[error("A timeline instance already exists for room {room_name}")]
TimelineAlreadyExists { room_name: String },
#[error("A timeline instance hasn't been initialized for room {room_name}")]
TimelineNotInitialized { room_name: String },
#[error("Timeline couldn't be initialized: {error}")]
InitializingTimeline { error: String },
#[error("Event cache ran into an error: {error}")]
EventCache { error: String },
#[error("The requested room doesn't match the membership requirements {expected:?}, observed {actual:?}")]
IncorrectRoomMembership { expected: Vec<Membership>, actual: Membership },
}
impl From<matrix_sdk_ui::room_list_service::Error> for RoomListError {
@@ -47,8 +63,14 @@ impl From<matrix_sdk_ui::room_list_service::Error> for RoomListError {
match value {
SlidingSync(error) => Self::SlidingSync { error: error.to_string() },
UnknownList(list_name) => Self::UnknownList { list_name },
InputCannotBeApplied(_) => Self::InputCannotBeApplied,
RoomNotFound(room_id) => Self::RoomNotFound { room_name: room_id.to_string() },
TimelineAlreadyExists(room_id) => {
Self::TimelineAlreadyExists { room_name: room_id.to_string() }
}
InitializingTimeline(source) => {
Self::InitializingTimeline { error: source.to_string() }
}
EventCache(error) => Self::EventCache { error: error.to_string() },
}
}
}
@@ -59,33 +81,13 @@ impl From<ruma::IdParseError> for RoomListError {
}
}
#[derive(uniffi::Record)]
pub struct RoomListRange {
pub start: u32,
pub end_inclusive: u32,
}
#[derive(uniffi::Enum)]
pub enum RoomListInput {
Viewport { ranges: Vec<RoomListRange> },
}
impl From<RoomListInput> for matrix_sdk_ui::room_list_service::Input {
fn from(value: RoomListInput) -> Self {
match value {
RoomListInput::Viewport { ranges } => Self::Viewport(
ranges.iter().map(|range| range.start..=range.end_inclusive).collect(),
),
}
}
}
#[derive(uniffi::Object)]
pub struct RoomListService {
pub(crate) inner: Arc<matrix_sdk_ui::RoomListService>,
pub(crate) utd_hook: Option<Arc<UtdHookManager>>,
}
#[uniffi::export(async_runtime = "tokio")]
#[matrix_sdk_ffi_macros::export]
impl RoomListService {
fn state(&self, listener: Box<dyn RoomListServiceStateListener>) -> Arc<TaskHandle> {
let state_stream = self.inner.state();
@@ -103,7 +105,8 @@ impl RoomListService {
let room_id = <&RoomId>::try_from(room_id.as_str()).map_err(RoomListError::from)?;
Ok(Arc::new(RoomListItem {
inner: Arc::new(RUNTIME.block_on(async { self.inner.room(room_id).await })?),
inner: Arc::new(self.inner.room(room_id)?),
utd_hook: self.utd_hook.clone(),
}))
}
@@ -114,17 +117,6 @@ impl RoomListService {
}))
}
async fn invites(self: Arc<Self>) -> Result<Arc<RoomList>, RoomListError> {
Ok(Arc::new(RoomList {
room_list_service: self.clone(),
inner: Arc::new(self.inner.invites().await.map_err(RoomListError::from)?),
}))
}
async fn apply_input(&self, input: RoomListInput) -> Result<(), RoomListError> {
self.inner.apply_input(input.into()).await.map(|_| ()).map_err(Into::into)
}
fn sync_indicator(
&self,
delay_before_showing_in_ms: u32,
@@ -144,6 +136,19 @@ impl RoomListService {
}
})))
}
fn subscribe_to_rooms(&self, room_ids: Vec<String>) -> Result<(), RoomListError> {
let room_ids = room_ids
.into_iter()
.map(|room_id| {
RoomId::parse(&room_id).map_err(|_| RoomListError::InvalidRoomId { error: room_id })
})
.collect::<Result<Vec<_>, _>>()?;
self.inner.subscribe_to_rooms(&room_ids.iter().map(AsRef::as_ref).collect::<Vec<_>>());
Ok(())
}
}
#[derive(uniffi::Object)]
@@ -152,7 +157,7 @@ pub struct RoomList {
inner: Arc<matrix_sdk_ui::room_list_service::RoomList>,
}
#[uniffi::export]
#[matrix_sdk_ffi_macros::export]
impl RoomList {
fn loading_state(
&self,
@@ -172,42 +177,98 @@ impl RoomList {
})
}
fn entries(&self, listener: Box<dyn RoomListEntriesListener>) -> RoomListEntriesResult {
let (entries, entries_stream) = self.inner.entries();
RoomListEntriesResult {
entries: entries.into_iter().map(Into::into).collect(),
entries_stream: Arc::new(TaskHandle::new(RUNTIME.spawn(async move {
pin_mut!(entries_stream);
while let Some(diff) = entries_stream.next().await {
listener.on_update(diff.into_iter().map(Into::into).collect());
}
}))),
}
}
fn entries_with_dynamic_adapters(
&self,
self: Arc<Self>,
page_size: u32,
listener: Box<dyn RoomListEntriesListener>,
) -> RoomListEntriesWithDynamicAdaptersResult {
let (entries_stream, dynamic_entries_controller) =
self.inner.entries_with_dynamic_adapters(page_size.try_into().unwrap());
) -> Arc<RoomListEntriesWithDynamicAdaptersResult> {
let this = self.clone();
let utd_hook = self.room_list_service.utd_hook.clone();
RoomListEntriesWithDynamicAdaptersResult {
controller: Arc::new(RoomListDynamicEntriesController::new(
dynamic_entries_controller,
self.room_list_service.inner.client(),
)),
entries_stream: Arc::new(TaskHandle::new(RUNTIME.spawn(async move {
pin_mut!(entries_stream);
// The following code deserves a bit of explanation.
// `matrix_sdk_ui::room_list_service::RoomList::entries_with_dynamic_adapters`
// returns a `Stream` with a lifetime bounds to its `self` (`RoomList`). This is
// problematic here as this `Stream` is returned as part of
// `RoomListEntriesWithDynamicAdaptersResult` but it is not possible to store
// `RoomList` with it inside the `Future` that is run inside the `TaskHandle`
// that consumes this `Stream`. We have a lifetime issue: `RoomList` doesn't
// live long enough!
//
// To solve this issue, the trick is to store the `RoomList` inside the
// `RoomListEntriesWithDynamicAdaptersResult`. Alright, but then we have another
// lifetime issue! `RoomList` cannot move inside this struct because it is
// borrowed by `entries_with_dynamic_adapters`. Indeed, the struct is built
// after the `Stream` is obtained.
//
// To solve this issue, we need to build the struct field by field, starting
// with `this`, and use a reference to `this` to call
// `entries_with_dynamic_adapters`. This is unsafe because a couple of
// invariants must hold, but all this is legal and correct if the invariants are
// properly fulfilled.
while let Some(diff) = entries_stream.next().await {
listener.on_update(diff.into_iter().map(Into::into).collect());
}
}))),
// Create the struct result with uninitialized fields.
let mut result = MaybeUninit::<RoomListEntriesWithDynamicAdaptersResult>::uninit();
let ptr = result.as_mut_ptr();
// Initialize the first field `this`.
//
// SAFETY: `ptr` is correctly aligned, this is guaranteed by `MaybeUninit`.
unsafe {
addr_of_mut!((*ptr).this).write(this);
}
// Get a reference to `this`. It is only borrowed, it's not moved.
let this =
// SAFETY: `ptr` is correct aligned, the `this` field is correctly aligned,
// is dereferenceable and points to a correctly initialized value as done
// in the previous line.
unsafe { addr_of_mut!((*ptr).this).as_ref() }
// SAFETY: `this` contains a non null value.
.unwrap();
// Now we can create `entries_stream` and `dynamic_entries_controller` by
// borrowing `this`, which is going to live long enough since it will live as
// long as `entries_stream` and `dynamic_entries_controller`.
let (entries_stream, dynamic_entries_controller) =
this.inner.entries_with_dynamic_adapters(page_size.try_into().unwrap());
// FFI dance to make those values consumable by foreign language, nothing fancy
// here, that's the real code for this method.
let dynamic_entries_controller =
Arc::new(RoomListDynamicEntriesController::new(dynamic_entries_controller));
let entries_stream = Arc::new(TaskHandle::new(RUNTIME.spawn(async move {
pin_mut!(entries_stream);
while let Some(diffs) = entries_stream.next().await {
listener.on_update(
diffs
.into_iter()
.map(|diff| RoomListEntriesUpdate::from(diff, utd_hook.clone()))
.collect(),
);
}
})));
// Initialize the second field `controller`.
//
// SAFETY: `ptr` is correctly aligned.
unsafe {
addr_of_mut!((*ptr).controller).write(dynamic_entries_controller);
}
// Initialize the third and last field `entries_stream`.
//
// SAFETY: `ptr` is correctly aligned.
unsafe {
addr_of_mut!((*ptr).entries_stream).write(entries_stream);
}
// The result is complete, let's return it!
//
// SAFETY: `result` is fully initialized, all its fields have received a valid
// value.
Arc::new(unsafe { result.assume_init() })
}
fn room(&self, room_id: String) -> Result<Arc<RoomListItem>, RoomListError> {
@@ -215,16 +276,22 @@ impl RoomList {
}
}
#[derive(uniffi::Record)]
pub struct RoomListEntriesResult {
pub entries: Vec<RoomListEntry>,
pub entries_stream: Arc<TaskHandle>,
#[derive(uniffi::Object)]
pub struct RoomListEntriesWithDynamicAdaptersResult {
this: Arc<RoomList>,
controller: Arc<RoomListDynamicEntriesController>,
entries_stream: Arc<TaskHandle>,
}
#[derive(uniffi::Record)]
pub struct RoomListEntriesWithDynamicAdaptersResult {
pub controller: Arc<RoomListDynamicEntriesController>,
pub entries_stream: Arc<TaskHandle>,
#[matrix_sdk_ffi_macros::export]
impl RoomListEntriesWithDynamicAdaptersResult {
fn controller(&self) -> Arc<RoomListDynamicEntriesController> {
self.controller.clone()
}
fn entries_stream(&self) -> Arc<TaskHandle> {
self.entries_stream.clone()
}
}
#[derive(uniffi::Record)]
@@ -294,65 +361,80 @@ impl From<matrix_sdk_ui::room_list_service::RoomListLoadingState> for RoomListLo
}
}
#[uniffi::export(callback_interface)]
#[matrix_sdk_ffi_macros::export(callback_interface)]
pub trait RoomListServiceStateListener: Send + Sync + Debug {
fn on_update(&self, state: RoomListServiceState);
}
#[uniffi::export(callback_interface)]
#[matrix_sdk_ffi_macros::export(callback_interface)]
pub trait RoomListLoadingStateListener: Send + Sync + Debug {
fn on_update(&self, state: RoomListLoadingState);
}
#[uniffi::export(callback_interface)]
#[matrix_sdk_ffi_macros::export(callback_interface)]
pub trait RoomListServiceSyncIndicatorListener: Send + Sync + Debug {
fn on_update(&self, sync_indicator: RoomListServiceSyncIndicator);
}
#[derive(uniffi::Enum)]
pub enum RoomListEntriesUpdate {
Append { values: Vec<RoomListEntry> },
Append { values: Vec<Arc<RoomListItem>> },
Clear,
PushFront { value: RoomListEntry },
PushBack { value: RoomListEntry },
PushFront { value: Arc<RoomListItem> },
PushBack { value: Arc<RoomListItem> },
PopFront,
PopBack,
Insert { index: u32, value: RoomListEntry },
Set { index: u32, value: RoomListEntry },
Insert { index: u32, value: Arc<RoomListItem> },
Set { index: u32, value: Arc<RoomListItem> },
Remove { index: u32 },
Truncate { length: u32 },
Reset { values: Vec<RoomListEntry> },
Reset { values: Vec<Arc<RoomListItem>> },
}
impl From<VectorDiff<matrix_sdk::RoomListEntry>> for RoomListEntriesUpdate {
fn from(other: VectorDiff<matrix_sdk::RoomListEntry>) -> Self {
match other {
VectorDiff::Append { values } => {
Self::Append { values: values.into_iter().map(Into::into).collect() }
}
impl RoomListEntriesUpdate {
fn from(
vector_diff: VectorDiff<matrix_sdk_ui::room_list_service::Room>,
utd_hook: Option<Arc<UtdHookManager>>,
) -> Self {
match vector_diff {
VectorDiff::Append { values } => Self::Append {
values: values
.into_iter()
.map(|value| Arc::new(RoomListItem::from(value, utd_hook.clone())))
.collect(),
},
VectorDiff::Clear => Self::Clear,
VectorDiff::PushFront { value } => Self::PushFront { value: value.into() },
VectorDiff::PushBack { value } => Self::PushBack { value: value.into() },
VectorDiff::PushFront { value } => {
Self::PushFront { value: Arc::new(RoomListItem::from(value, utd_hook)) }
}
VectorDiff::PushBack { value } => {
Self::PushBack { value: Arc::new(RoomListItem::from(value, utd_hook)) }
}
VectorDiff::PopFront => Self::PopFront,
VectorDiff::PopBack => Self::PopBack,
VectorDiff::Insert { index, value } => {
Self::Insert { index: u32::try_from(index).unwrap(), value: value.into() }
}
VectorDiff::Set { index, value } => {
Self::Set { index: u32::try_from(index).unwrap(), value: value.into() }
}
VectorDiff::Insert { index, value } => Self::Insert {
index: u32::try_from(index).unwrap(),
value: Arc::new(RoomListItem::from(value, utd_hook)),
},
VectorDiff::Set { index, value } => Self::Set {
index: u32::try_from(index).unwrap(),
value: Arc::new(RoomListItem::from(value, utd_hook)),
},
VectorDiff::Remove { index } => Self::Remove { index: u32::try_from(index).unwrap() },
VectorDiff::Truncate { length } => {
Self::Truncate { length: u32::try_from(length).unwrap() }
}
VectorDiff::Reset { values } => {
Self::Reset { values: values.into_iter().map(Into::into).collect() }
}
VectorDiff::Reset { values } => Self::Reset {
values: values
.into_iter()
.map(|value| Arc::new(RoomListItem::from(value, utd_hook.clone())))
.collect(),
},
}
}
}
#[uniffi::export(callback_interface)]
#[matrix_sdk_ffi_macros::export(callback_interface)]
pub trait RoomListEntriesListener: Send + Sync + Debug {
fn on_update(&self, room_entries_update: Vec<RoomListEntriesUpdate>);
}
@@ -360,34 +442,20 @@ pub trait RoomListEntriesListener: Send + Sync + Debug {
#[derive(uniffi::Object)]
pub struct RoomListDynamicEntriesController {
inner: matrix_sdk_ui::room_list_service::RoomListDynamicEntriesController,
client: matrix_sdk::Client,
}
impl RoomListDynamicEntriesController {
fn new(
dynamic_entries_controller: matrix_sdk_ui::room_list_service::RoomListDynamicEntriesController,
client: &matrix_sdk::Client,
) -> Self {
Self { inner: dynamic_entries_controller, client: client.clone() }
Self { inner: dynamic_entries_controller }
}
}
#[uniffi::export]
#[matrix_sdk_ffi_macros::export]
impl RoomListDynamicEntriesController {
fn set_filter(&self, kind: RoomListEntriesDynamicFilterKind) -> bool {
use RoomListEntriesDynamicFilterKind as Kind;
match kind {
Kind::All => self.inner.set_filter(new_filter_all()),
Kind::AllNonLeft => self.inner.set_filter(new_filter_all_non_left(&self.client)),
Kind::None => self.inner.set_filter(new_filter_none()),
Kind::NormalizedMatchRoomName { pattern } => {
self.inner.set_filter(new_filter_normalized_match_room_name(&self.client, &pattern))
}
Kind::FuzzyMatchRoomName { pattern } => {
self.inner.set_filter(new_filter_fuzzy_match_room_name(&self.client, &pattern))
}
}
self.inner.set_filter(kind.into())
}
fn add_one_page(&self) {
@@ -401,26 +469,88 @@ impl RoomListDynamicEntriesController {
#[derive(uniffi::Enum)]
pub enum RoomListEntriesDynamicFilterKind {
All,
AllNonLeft,
All { filters: Vec<RoomListEntriesDynamicFilterKind> },
Any { filters: Vec<RoomListEntriesDynamicFilterKind> },
NonLeft,
Joined,
Unread,
Favourite,
Invite,
Category { expect: RoomListFilterCategory },
None,
NormalizedMatchRoomName { pattern: String },
FuzzyMatchRoomName { pattern: String },
}
#[derive(uniffi::Enum)]
pub enum RoomListFilterCategory {
Group,
People,
}
impl From<RoomListFilterCategory> for RoomCategory {
fn from(value: RoomListFilterCategory) -> Self {
match value {
RoomListFilterCategory::Group => Self::Group,
RoomListFilterCategory::People => Self::People,
}
}
}
impl From<RoomListEntriesDynamicFilterKind> for BoxedFilterFn {
fn from(value: RoomListEntriesDynamicFilterKind) -> Self {
use RoomListEntriesDynamicFilterKind as Kind;
match value {
Kind::All { filters } => Box::new(new_filter_all(
filters.into_iter().map(|filter| BoxedFilterFn::from(filter)).collect(),
)),
Kind::Any { filters } => Box::new(new_filter_any(
filters.into_iter().map(|filter| BoxedFilterFn::from(filter)).collect(),
)),
Kind::NonLeft => Box::new(new_filter_non_left()),
Kind::Joined => Box::new(new_filter_joined()),
Kind::Unread => Box::new(new_filter_unread()),
Kind::Favourite => Box::new(new_filter_favourite()),
Kind::Invite => Box::new(new_filter_invite()),
Kind::Category { expect } => Box::new(new_filter_category(expect.into())),
Kind::None => Box::new(new_filter_none()),
Kind::NormalizedMatchRoomName { pattern } => {
Box::new(new_filter_normalized_match_room_name(&pattern))
}
Kind::FuzzyMatchRoomName { pattern } => {
Box::new(new_filter_fuzzy_match_room_name(&pattern))
}
}
}
}
#[derive(uniffi::Object)]
pub struct RoomListItem {
inner: Arc<matrix_sdk_ui::room_list_service::Room>,
utd_hook: Option<Arc<UtdHookManager>>,
}
#[uniffi::export(async_runtime = "tokio")]
impl RoomListItem {
fn from(
value: matrix_sdk_ui::room_list_service::Room,
utd_hook: Option<Arc<UtdHookManager>>,
) -> Self {
Self { inner: Arc::new(value), utd_hook }
}
}
#[matrix_sdk_ffi_macros::export]
impl RoomListItem {
fn id(&self) -> String {
self.inner.id().to_string()
}
fn name(&self) -> Option<String> {
RUNTIME.block_on(async { self.inner.name().await })
/// Returns the room's name from the state event if available, otherwise
/// compute a room name based on the room's nature (DM or not) and number of
/// members.
fn display_name(&self) -> Option<String> {
self.inner.cached_display_name()
}
fn avatar_url(&self) -> Option<String> {
@@ -428,101 +558,164 @@ impl RoomListItem {
}
fn is_direct(&self) -> bool {
RUNTIME.block_on(async { self.inner.inner_room().is_direct().await.unwrap_or(false) })
RUNTIME.block_on(self.inner.inner_room().is_direct()).unwrap_or(false)
}
fn canonical_alias(&self) -> Option<String> {
self.inner.inner_room().canonical_alias().map(|alias| alias.to_string())
}
pub async fn room_info(&self) -> Result<RoomInfo, ClientError> {
let avatar_url = self.inner.avatar_url();
let latest_event = self.inner.latest_event().await.map(EventTimelineItem).map(Arc::new);
Ok(RoomInfo::new(self.inner.inner_room(), avatar_url, latest_event).await?)
async fn room_info(&self) -> Result<RoomInfo, ClientError> {
Ok(RoomInfo::new(self.inner.inner_room()).await?)
}
/// Building a `Room`.
/// The room's current membership state.
fn membership(&self) -> Membership {
self.inner.inner_room().state().into()
}
/// Builds a `Room` FFI from an invited room without initializing its
/// internal timeline.
///
/// Be careful that building a `Room` builds its entire `Timeline` at the
/// same time.
async fn full_room(&self) -> Arc<Room> {
Arc::new(Room::with_timeline(
self.inner.inner_room().clone(),
Arc::new(RwLock::new(Some(Timeline::from_arc(self.inner.timeline().await)))),
))
/// An error will be returned if the room is a state different than invited.
///
/// ⚠️ Holding on to this room instance after it has been joined is not
/// safe. Use `full_room` instead.
#[deprecated(note = "Please use `preview_room` instead.")]
fn invited_room(&self) -> Result<Arc<Room>, RoomListError> {
if !matches!(self.membership(), Membership::Invited) {
return Err(RoomListError::IncorrectRoomMembership {
expected: vec![Membership::Invited],
actual: self.membership(),
});
}
Ok(Arc::new(Room::new(self.inner.inner_room().clone())))
}
// Temporary workaround for coroutine leaks on Kotlin.
fn full_room_blocking(&self) -> Arc<Room> {
RUNTIME.block_on(async move { self.full_room().await })
}
/// Builds a `RoomPreview` from a room list item. This is intended for
/// invited or knocked rooms.
///
/// An error will be returned if the room is in a state other than invited
/// or knocked.
async fn preview_room(&self, via: Vec<String>) -> Result<Arc<RoomPreview>, ClientError> {
// Validate parameters first.
let server_names: Vec<OwnedServerName> = via
.into_iter()
.map(|server| ServerName::parse(server).map_err(ClientError::from))
.collect::<Result<_, ClientError>>()?;
fn subscribe(&self, settings: Option<RoomSubscription>) {
self.inner.subscribe(settings.map(Into::into));
}
// Validate internal room state.
let membership = self.membership();
if !matches!(membership, Membership::Invited | Membership::Knocked) {
return Err(RoomListError::IncorrectRoomMembership {
expected: vec![Membership::Invited, Membership::Knocked],
actual: membership,
}
.into());
}
fn unsubscribe(&self) {
self.inner.unsubscribe();
}
// Do the thing.
let client = self.inner.client();
let (room_or_alias_id, mut server_names) = if let Some(alias) = self.inner.canonical_alias()
{
let room_or_alias_id: OwnedRoomOrAliasId = alias.into();
(room_or_alias_id, Vec::new())
} else {
let room_or_alias_id: OwnedRoomOrAliasId = self.inner.id().to_owned().into();
(room_or_alias_id, server_names)
};
async fn latest_event(&self) -> Option<Arc<EventTimelineItem>> {
self.inner.latest_event().await.map(EventTimelineItem).map(Arc::new)
}
fn has_unread_notifications(&self) -> bool {
self.inner.has_unread_notifications()
}
fn unread_notifications(&self) -> Arc<UnreadNotificationsCount> {
Arc::new(self.inner.unread_notifications().into())
}
}
#[derive(Clone, Debug, uniffi::Enum)]
pub enum RoomListEntry {
Empty,
Invalidated { room_id: String },
Filled { room_id: String },
}
impl From<MatrixRoomListEntry> for RoomListEntry {
fn from(value: MatrixRoomListEntry) -> Self {
(&value).into()
}
}
impl From<&MatrixRoomListEntry> for RoomListEntry {
fn from(value: &MatrixRoomListEntry) -> Self {
match value {
MatrixRoomListEntry::Empty => Self::Empty,
MatrixRoomListEntry::Filled(room_id) => Self::Filled { room_id: room_id.to_string() },
MatrixRoomListEntry::Invalidated(room_id) => {
Self::Invalidated { room_id: room_id.to_string() }
// If no server names are provided and the room's membership is invited,
// add the server name from the sender's user id as a fallback value
if server_names.is_empty() {
if let Ok(invite_details) = self.inner.invite_details().await {
if let Some(inviter) = invite_details.inviter {
server_names.push(inviter.user_id().server_name().to_owned());
}
}
}
let room_preview = client.get_room_preview(&room_or_alias_id, server_names).await?;
Ok(Arc::new(RoomPreview::new(AsyncRuntimeDropped::new(client), room_preview)))
}
}
#[derive(uniffi::Record)]
pub struct RequiredState {
pub key: String,
pub value: String,
}
/// Build a full `Room` FFI object, filling its associated timeline.
///
/// An error will be returned if the room is a state different than joined
/// or if its internal timeline hasn't been initialized.
fn full_room(&self) -> Result<Arc<Room>, RoomListError> {
if !matches!(self.membership(), Membership::Joined) {
return Err(RoomListError::IncorrectRoomMembership {
expected: vec![Membership::Joined],
actual: self.membership(),
});
}
#[derive(uniffi::Record)]
pub struct RoomSubscription {
pub required_state: Option<Vec<RequiredState>>,
pub timeline_limit: Option<u32>,
}
if let Some(timeline) = self.inner.timeline() {
Ok(Arc::new(Room::with_timeline(
self.inner.inner_room().clone(),
Arc::new(RwLock::new(Some(Timeline::from_arc(timeline)))),
)))
} else {
Err(RoomListError::TimelineNotInitialized {
room_name: self.inner.inner_room().room_id().to_string(),
})
}
}
impl From<RoomSubscription> for RumaRoomSubscription {
fn from(val: RoomSubscription) -> Self {
assign!(RumaRoomSubscription::default(), {
required_state: val.required_state.map(|r|
r.into_iter().map(|s| (s.key.into(), s.value)).collect()
).unwrap_or_default(),
timeline_limit: val.timeline_limit.map(|u| u.into())
})
/// Checks whether the Room's timeline has been initialized before.
fn is_timeline_initialized(&self) -> bool {
self.inner.is_timeline_initialized()
}
/// Initializes the timeline for this room using the provided parameters.
///
/// * `event_type_filter` - An optional [`TimelineEventTypeFilter`] to be
/// used to filter timeline events besides the default timeline filter. If
/// `None` is passed, only the default timeline filter will be used.
/// * `internal_id_prefix` - An optional String that will be prepended to
/// all the timeline item's internal IDs, making it possible to
/// distinguish different timeline instances from each other.
async fn init_timeline(
&self,
event_type_filter: Option<Arc<TimelineEventTypeFilter>>,
internal_id_prefix: Option<String>,
) -> Result<(), RoomListError> {
let mut timeline_builder = self
.inner
.default_room_timeline_builder()
.await
.map_err(|err| RoomListError::InitializingTimeline { error: err.to_string() })?;
if let Some(event_type_filter) = event_type_filter {
timeline_builder = timeline_builder.event_filter(move |event, room_version_id| {
// Always perform the default filter first
default_event_filter(event, room_version_id) && event_type_filter.filter(event)
});
}
if let Some(internal_id_prefix) = internal_id_prefix {
timeline_builder = timeline_builder.with_internal_id_prefix(internal_id_prefix);
}
if let Some(utd_hook) = self.utd_hook.clone() {
timeline_builder = timeline_builder.with_unable_to_decrypt_hook(utd_hook);
}
self.inner.init_timeline_with_builder(timeline_builder).map_err(RoomListError::from).await
}
/// Checks whether the room is encrypted or not.
///
/// **Note**: this info may not be reliable if you don't set up
/// `m.room.encryption` as required state.
async fn is_encrypted(&self) -> bool {
self.inner.is_encrypted().await.unwrap_or(false)
}
async fn latest_event(&self) -> Option<EventTimelineItem> {
self.inner.latest_event().await.map(Into::into)
}
}
@@ -532,7 +725,7 @@ pub struct UnreadNotificationsCount {
notification_count: u32,
}
#[uniffi::export]
#[matrix_sdk_ffi_macros::export]
impl UnreadNotificationsCount {
fn highlight_count(&self) -> u32 {
self.highlight_count
+71 -200
View File
@@ -1,7 +1,7 @@
use matrix_sdk::room::RoomMember as SdkRoomMember;
use matrix_sdk::room::{RoomMember as SdkRoomMember, RoomMemberRole};
use ruma::UserId;
use super::RUNTIME;
use crate::ClientError;
use crate::error::{ClientError, NotYetImplemented};
#[derive(Clone, uniffi::Enum)]
pub enum MembershipState {
@@ -19,219 +19,90 @@ pub enum MembershipState {
/// The user has left.
Leave,
/// A custom membership state value.
Custom { value: String },
}
impl From<matrix_sdk::ruma::events::room::member::MembershipState> for MembershipState {
fn from(m: matrix_sdk::ruma::events::room::member::MembershipState) -> Self {
impl TryFrom<matrix_sdk::ruma::events::room::member::MembershipState> for MembershipState {
type Error = NotYetImplemented;
fn try_from(
m: matrix_sdk::ruma::events::room::member::MembershipState,
) -> Result<Self, Self::Error> {
match m {
matrix_sdk::ruma::events::room::member::MembershipState::Ban => MembershipState::Ban,
matrix_sdk::ruma::events::room::member::MembershipState::Invite => {
MembershipState::Invite
matrix_sdk::ruma::events::room::member::MembershipState::Ban => {
Ok(MembershipState::Ban)
}
matrix_sdk::ruma::events::room::member::MembershipState::Invite => {
Ok(MembershipState::Invite)
}
matrix_sdk::ruma::events::room::member::MembershipState::Join => {
Ok(MembershipState::Join)
}
matrix_sdk::ruma::events::room::member::MembershipState::Join => MembershipState::Join,
matrix_sdk::ruma::events::room::member::MembershipState::Knock => {
MembershipState::Knock
Ok(MembershipState::Knock)
}
matrix_sdk::ruma::events::room::member::MembershipState::Leave => {
MembershipState::Leave
Ok(MembershipState::Leave)
}
matrix_sdk::ruma::events::room::member::MembershipState::_Custom(_) => {
Ok(MembershipState::Custom { value: m.to_string() })
}
_ => {
tracing::warn!("Other membership state change not yet implemented");
Err(NotYetImplemented)
}
_ => todo!(
"Handle Custom case: https://github.com/matrix-org/matrix-rust-sdk/issues/1254"
),
}
}
}
#[derive(uniffi::Object)]
#[matrix_sdk_ffi_macros::export]
pub fn suggested_role_for_power_level(power_level: i64) -> RoomMemberRole {
// It's not possible to expose the constructor on the Enum through Uniffi ☹️
RoomMemberRole::suggested_role_for_power_level(power_level)
}
#[matrix_sdk_ffi_macros::export]
pub fn suggested_power_level_for_role(role: RoomMemberRole) -> i64 {
// It's not possible to expose methods on an Enum through Uniffi ☹️
role.suggested_power_level()
}
/// Generates a `matrix.to` permalink to the given userID.
#[matrix_sdk_ffi_macros::export]
pub fn matrix_to_user_permalink(user_id: String) -> Result<String, ClientError> {
let user_id = UserId::parse(user_id)?;
Ok(user_id.matrix_to_uri().to_string())
}
#[derive(uniffi::Record)]
pub struct RoomMember {
pub(crate) inner: SdkRoomMember,
pub user_id: String,
pub display_name: Option<String>,
pub avatar_url: Option<String>,
pub membership: MembershipState,
pub is_name_ambiguous: bool,
pub power_level: i64,
pub normalized_power_level: i64,
pub is_ignored: bool,
pub suggested_role_for_power_level: RoomMemberRole,
}
#[uniffi::export]
impl RoomMember {
pub fn user_id(&self) -> String {
self.inner.user_id().to_string()
}
impl TryFrom<SdkRoomMember> for RoomMember {
type Error = NotYetImplemented;
pub fn display_name(&self) -> Option<String> {
self.inner.display_name().map(|d| d.to_owned())
}
pub fn avatar_url(&self) -> Option<String> {
self.inner.avatar_url().map(ToString::to_string)
}
pub fn membership(&self) -> MembershipState {
self.inner.membership().to_owned().into()
}
pub fn is_name_ambiguous(&self) -> bool {
self.inner.name_ambiguous()
}
pub fn power_level(&self) -> i64 {
self.inner.power_level()
}
pub fn normalized_power_level(&self) -> i64 {
self.inner.normalized_power_level()
}
pub fn is_ignored(&self) -> bool {
self.inner.is_ignored()
}
pub fn is_account_user(&self) -> bool {
self.inner.is_account_user()
}
/// Adds the room member to the current account data's ignore list
/// which will ignore the user across all rooms.
pub fn ignore(&self) -> Result<(), ClientError> {
RUNTIME.block_on(async move {
self.inner.ignore().await?;
Ok(())
fn try_from(m: SdkRoomMember) -> Result<Self, Self::Error> {
Ok(RoomMember {
user_id: m.user_id().to_string(),
display_name: m.display_name().map(|s| s.to_owned()),
avatar_url: m.avatar_url().map(|a| a.to_string()),
membership: m.membership().clone().try_into()?,
is_name_ambiguous: m.name_ambiguous(),
power_level: m.power_level(),
normalized_power_level: m.normalized_power_level(),
is_ignored: m.is_ignored(),
suggested_role_for_power_level: m.suggested_role_for_power_level(),
})
}
/// Removes the room member from the current account data's ignore list
/// which will unignore the user across all rooms.
pub fn unignore(&self) -> Result<(), ClientError> {
RUNTIME.block_on(async move {
self.inner.unignore().await?;
Ok(())
})
}
pub fn can_ban(&self) -> bool {
self.inner.can_ban()
}
pub fn can_invite(&self) -> bool {
self.inner.can_invite()
}
pub fn can_kick(&self) -> bool {
self.inner.can_kick()
}
pub fn can_redact(&self) -> bool {
self.inner.can_redact()
}
pub fn can_send_state(&self, state_event: StateEventType) -> bool {
self.inner.can_send_state(state_event.into())
}
pub fn can_send_message(&self, event: MessageLikeEventType) -> bool {
self.inner.can_send_message(event.into())
}
pub fn can_trigger_room_notification(&self) -> bool {
self.inner.can_trigger_room_notification()
}
}
impl RoomMember {
pub fn new(room_member: SdkRoomMember) -> Self {
RoomMember { inner: room_member }
}
}
#[derive(Clone, uniffi::Enum)]
pub enum StateEventType {
CallMember,
PolicyRuleRoom,
PolicyRuleServer,
PolicyRuleUser,
RoomAliases,
RoomAvatar,
RoomCanonicalAlias,
RoomCreate,
RoomEncryption,
RoomGuestAccess,
RoomHistoryVisibility,
RoomJoinRules,
RoomMemberEvent,
RoomName,
RoomPinnedEvents,
RoomPowerLevels,
RoomServerAcl,
RoomThirdPartyInvite,
RoomTombstone,
RoomTopic,
SpaceChild,
SpaceParent,
}
impl From<StateEventType> for ruma::events::StateEventType {
fn from(val: StateEventType) -> Self {
match val {
StateEventType::CallMember => Self::CallMember,
StateEventType::PolicyRuleRoom => Self::PolicyRuleRoom,
StateEventType::PolicyRuleServer => Self::PolicyRuleServer,
StateEventType::PolicyRuleUser => Self::PolicyRuleUser,
StateEventType::RoomAliases => Self::RoomAliases,
StateEventType::RoomAvatar => Self::RoomAvatar,
StateEventType::RoomCanonicalAlias => Self::RoomCanonicalAlias,
StateEventType::RoomCreate => Self::RoomCreate,
StateEventType::RoomEncryption => Self::RoomEncryption,
StateEventType::RoomGuestAccess => Self::RoomGuestAccess,
StateEventType::RoomHistoryVisibility => Self::RoomHistoryVisibility,
StateEventType::RoomJoinRules => Self::RoomJoinRules,
StateEventType::RoomMemberEvent => Self::RoomMember,
StateEventType::RoomName => Self::RoomName,
StateEventType::RoomPinnedEvents => Self::RoomPinnedEvents,
StateEventType::RoomPowerLevels => Self::RoomPowerLevels,
StateEventType::RoomServerAcl => Self::RoomServerAcl,
StateEventType::RoomThirdPartyInvite => Self::RoomThirdPartyInvite,
StateEventType::RoomTombstone => Self::RoomTombstone,
StateEventType::RoomTopic => Self::RoomTopic,
StateEventType::SpaceChild => Self::SpaceChild,
StateEventType::SpaceParent => Self::SpaceParent,
}
}
}
#[derive(Clone, uniffi::Enum)]
pub enum MessageLikeEventType {
CallAnswer,
CallInvite,
CallHangup,
CallCandidates,
KeyVerificationReady,
KeyVerificationStart,
KeyVerificationCancel,
KeyVerificationAccept,
KeyVerificationKey,
KeyVerificationMac,
KeyVerificationDone,
ReactionSent,
RoomEncrypted,
RoomMessage,
RoomRedaction,
Sticker,
}
impl From<MessageLikeEventType> for ruma::events::MessageLikeEventType {
fn from(val: MessageLikeEventType) -> Self {
match val {
MessageLikeEventType::CallAnswer => Self::CallAnswer,
MessageLikeEventType::CallInvite => Self::CallInvite,
MessageLikeEventType::CallHangup => Self::CallHangup,
MessageLikeEventType::CallCandidates => Self::CallCandidates,
MessageLikeEventType::KeyVerificationReady => Self::KeyVerificationReady,
MessageLikeEventType::KeyVerificationStart => Self::KeyVerificationStart,
MessageLikeEventType::KeyVerificationCancel => Self::KeyVerificationCancel,
MessageLikeEventType::KeyVerificationAccept => Self::KeyVerificationAccept,
MessageLikeEventType::KeyVerificationKey => Self::KeyVerificationKey,
MessageLikeEventType::KeyVerificationMac => Self::KeyVerificationMac,
MessageLikeEventType::KeyVerificationDone => Self::KeyVerificationDone,
MessageLikeEventType::ReactionSent => Self::Reaction,
MessageLikeEventType::RoomEncrypted => Self::RoomEncrypted,
MessageLikeEventType::RoomMessage => Self::RoomMessage,
MessageLikeEventType::RoomRedaction => Self::RoomRedaction,
MessageLikeEventType::Sticker => Self::Sticker,
}
}
}
+148
View File
@@ -0,0 +1,148 @@
use anyhow::Context as _;
use matrix_sdk::{room_preview::RoomPreview as SdkRoomPreview, Client};
use ruma::{room::RoomType as RumaRoomType, space::SpaceRoomJoinRule};
use tracing::warn;
use crate::{
client::JoinRule,
error::ClientError,
room::{Membership, RoomHero},
room_member::RoomMember,
utils::AsyncRuntimeDropped,
};
/// A room preview for a room. It's intended to be used to represent rooms that
/// aren't joined yet.
#[derive(uniffi::Object)]
pub struct RoomPreview {
inner: SdkRoomPreview,
client: AsyncRuntimeDropped<Client>,
}
#[matrix_sdk_ffi_macros::export]
impl RoomPreview {
/// Returns the room info the preview contains.
pub fn info(&self) -> Result<RoomPreviewInfo, ClientError> {
let info = &self.inner;
Ok(RoomPreviewInfo {
room_id: info.room_id.to_string(),
canonical_alias: info.canonical_alias.as_ref().map(|alias| alias.to_string()),
name: info.name.clone(),
topic: info.topic.clone(),
avatar_url: info.avatar_url.as_ref().map(|url| url.to_string()),
num_joined_members: info.num_joined_members,
num_active_members: info.num_active_members,
room_type: info.room_type.as_ref().into(),
is_history_world_readable: info.is_world_readable,
membership: info.state.map(|state| state.into()),
join_rule: info
.join_rule
.clone()
.try_into()
.map_err(|_| anyhow::anyhow!("unhandled SpaceRoomJoinRule kind"))?,
is_direct: info.is_direct,
heroes: info
.heroes
.as_ref()
.map(|heroes| heroes.iter().map(|h| h.to_owned().into()).collect()),
})
}
/// Leave the room if the room preview state is either joined, invited or
/// knocked.
///
/// Will return an error otherwise.
pub async fn leave(&self) -> Result<(), ClientError> {
let room =
self.client.get_room(&self.inner.room_id).context("missing room for a room preview")?;
room.leave().await.map_err(Into::into)
}
/// Get the user who created the invite, if any.
pub async fn inviter(&self) -> Option<RoomMember> {
let room = self.client.get_room(&self.inner.room_id)?;
let invite_details = room.invite_details().await.ok()?;
invite_details.inviter.and_then(|m| m.try_into().ok())
}
}
impl RoomPreview {
pub(crate) fn new(client: AsyncRuntimeDropped<Client>, inner: SdkRoomPreview) -> Self {
Self { client, inner }
}
}
/// The preview of a room, be it invited/joined/left, or not.
#[derive(uniffi::Record)]
pub struct RoomPreviewInfo {
/// The room id for this room.
pub room_id: String,
/// The canonical alias for the room.
pub canonical_alias: Option<String>,
/// The room's name, if set.
pub name: Option<String>,
/// The room's topic, if set.
pub topic: Option<String>,
/// The MXC URI to the room's avatar, if set.
pub avatar_url: Option<String>,
/// The number of joined members.
pub num_joined_members: u64,
/// The number of active members, if known (joined + invited).
pub num_active_members: Option<u64>,
/// The room type (space, custom) or nothing, if it's a regular room.
pub room_type: RoomType,
/// Is the history world-readable for this room?
pub is_history_world_readable: Option<bool>,
/// The membership state for the current user, if known.
pub membership: Option<Membership>,
/// The join rule for this room (private, public, knock, etc.).
pub join_rule: JoinRule,
/// Whether the room is direct or not, if known.
pub is_direct: Option<bool>,
/// Room heroes.
pub heroes: Option<Vec<RoomHero>>,
}
impl TryFrom<SpaceRoomJoinRule> for JoinRule {
type Error = ();
fn try_from(join_rule: SpaceRoomJoinRule) -> Result<Self, ()> {
Ok(match join_rule {
SpaceRoomJoinRule::Invite => JoinRule::Invite,
SpaceRoomJoinRule::Knock => JoinRule::Knock,
SpaceRoomJoinRule::Private => JoinRule::Private,
SpaceRoomJoinRule::Restricted => JoinRule::Restricted { rules: Vec::new() },
SpaceRoomJoinRule::KnockRestricted => JoinRule::KnockRestricted { rules: Vec::new() },
SpaceRoomJoinRule::Public => JoinRule::Public,
SpaceRoomJoinRule::_Custom(_) => JoinRule::Custom { repr: join_rule.to_string() },
_ => {
warn!("unhandled SpaceRoomJoinRule: {join_rule}");
return Err(());
}
})
}
}
/// The type of room for a [`RoomPreviewInfo`].
#[derive(Debug, Clone, uniffi::Enum)]
pub enum RoomType {
/// It's a plain chat room.
Room,
/// It's a space that can group several rooms.
Space,
/// It's a custom implementation.
Custom { value: String },
}
impl From<Option<&RumaRoomType>> for RoomType {
fn from(value: Option<&RumaRoomType>) -> Self {
match value {
Some(RumaRoomType::Space) => RoomType::Space,
Some(RumaRoomType::_Custom(_)) => RoomType::Custom {
// SAFETY: this was checked in the match branch above
value: value.unwrap().to_string(),
},
_ => RoomType::Room,
}
}
}
+348 -94
View File
@@ -15,12 +15,11 @@
use std::{collections::BTreeSet, sync::Arc, time::Duration};
use extension_trait::extension_trait;
use matrix_sdk::attachment::{
BaseAudioInfo, BaseFileInfo, BaseImageInfo, BaseThumbnailInfo, BaseVideoInfo,
};
use matrix_sdk::attachment::{BaseAudioInfo, BaseFileInfo, BaseImageInfo, BaseVideoInfo};
use ruma::{
assign,
events::{
call::notify::NotifyType as RumaNotifyType,
location::AssetType as RumaAssetType,
poll::start::PollKind as RumaPollKind,
room::{
@@ -41,47 +40,141 @@ use ruma::{
VideoInfo as RumaVideoInfo,
VideoMessageEventContent as RumaVideoMessageEventContent,
},
ImageInfo as RumaImageInfo, MediaSource, ThumbnailInfo as RumaThumbnailInfo,
ImageInfo as RumaImageInfo, MediaSource as RumaMediaSource,
ThumbnailInfo as RumaThumbnailInfo,
},
},
matrix_uri::MatrixId as RumaMatrixId,
serde::JsonObject,
OwnedUserId, UInt, UserId,
MatrixToUri, MatrixUri as RumaMatrixUri, OwnedUserId, UInt, UserId,
};
use tracing::info;
use crate::{
error::{ClientError, MediaInfoError},
helpers::unwrap_or_clone_arc,
timeline::MessageContent,
utils::u64_to_uint,
};
#[uniffi::export]
pub fn media_source_from_url(url: String) -> Arc<MediaSource> {
Arc::new(MediaSource::Plain(url.into()))
#[derive(uniffi::Enum)]
pub enum AuthData {
/// Password-based authentication (`m.login.password`).
Password { password_details: AuthDataPasswordDetails },
}
#[uniffi::export]
#[derive(uniffi::Record)]
pub struct AuthDataPasswordDetails {
/// One of the user's identifiers.
identifier: String,
/// The plaintext password.
password: String,
}
impl From<AuthData> for ruma::api::client::uiaa::AuthData {
fn from(value: AuthData) -> ruma::api::client::uiaa::AuthData {
match value {
AuthData::Password { password_details } => {
let user_id = ruma::UserId::parse(password_details.identifier).unwrap();
ruma::api::client::uiaa::AuthData::Password(ruma::api::client::uiaa::Password::new(
user_id.into(),
password_details.password,
))
}
}
}
}
/// Parse a matrix entity from a given URI, be it either
/// a `matrix.to` link or a `matrix:` URI
#[matrix_sdk_ffi_macros::export]
pub fn parse_matrix_entity_from(uri: String) -> Option<MatrixEntity> {
if let Ok(matrix_uri) = RumaMatrixUri::parse(&uri) {
return Some(MatrixEntity {
id: matrix_uri.id().into(),
via: matrix_uri.via().iter().map(|via| via.to_string()).collect(),
});
}
if let Ok(matrix_to_uri) = MatrixToUri::parse(&uri) {
return Some(MatrixEntity {
id: matrix_to_uri.id().into(),
via: matrix_to_uri.via().iter().map(|via| via.to_string()).collect(),
});
}
None
}
/// A Matrix entity that can be a room, room alias, user, or event, and a list
/// of via servers.
#[derive(uniffi::Record)]
pub struct MatrixEntity {
id: MatrixId,
via: Vec<String>,
}
/// A Matrix ID that can be a room, room alias, user, or event.
#[derive(Clone, uniffi::Enum)]
pub enum MatrixId {
Room { id: String },
RoomAlias { alias: String },
User { id: String },
EventOnRoomId { room_id: String, event_id: String },
EventOnRoomAlias { alias: String, event_id: String },
}
impl From<&RumaMatrixId> for MatrixId {
fn from(value: &RumaMatrixId) -> Self {
match value {
RumaMatrixId::User(id) => MatrixId::User { id: id.to_string() },
RumaMatrixId::Room(id) => MatrixId::Room { id: id.to_string() },
RumaMatrixId::RoomAlias(id) => MatrixId::RoomAlias { alias: id.to_string() },
RumaMatrixId::Event(room_id_or_alias, event_id) => {
if room_id_or_alias.is_room_id() {
MatrixId::EventOnRoomId {
room_id: room_id_or_alias.to_string(),
event_id: event_id.to_string(),
}
} else if room_id_or_alias.is_room_alias_id() {
MatrixId::EventOnRoomAlias {
alias: room_id_or_alias.to_string(),
event_id: event_id.to_string(),
}
} else {
panic!("Unexpected MatrixId type: {:?}", room_id_or_alias)
}
}
_ => panic!("Unexpected MatrixId type: {:?}", value),
}
}
}
#[matrix_sdk_ffi_macros::export]
pub fn message_event_content_new(
msgtype: MessageType,
) -> Result<Arc<RoomMessageEventContentWithoutRelation>, ClientError> {
Ok(Arc::new(RoomMessageEventContentWithoutRelation::new(msgtype.try_into()?)))
}
#[uniffi::export]
#[matrix_sdk_ffi_macros::export]
pub fn message_event_content_from_markdown(
md: String,
) -> Arc<RoomMessageEventContentWithoutRelation> {
Arc::new(RoomMessageEventContentWithoutRelation::new(RumaMessageType::text_markdown(md)))
}
#[uniffi::export]
#[matrix_sdk_ffi_macros::export]
pub fn message_event_content_from_markdown_as_emote(
md: String,
) -> Arc<RoomMessageEventContentWithoutRelation> {
Arc::new(RoomMessageEventContentWithoutRelation::new(RumaMessageType::emote_markdown(md)))
}
#[uniffi::export]
#[matrix_sdk_ffi_macros::export]
pub fn message_event_content_from_html(
body: String,
html_body: String,
@@ -91,7 +184,7 @@ pub fn message_event_content_from_html(
)))
}
#[uniffi::export]
#[matrix_sdk_ffi_macros::export]
pub fn message_event_content_from_html_as_emote(
body: String,
html_body: String,
@@ -101,21 +194,84 @@ pub fn message_event_content_from_html_as_emote(
)))
}
#[extension_trait]
pub impl MediaSourceExt for MediaSource {
fn from_json(json: String) -> Result<MediaSource, ClientError> {
let res = serde_json::from_str(&json)?;
Ok(res)
#[derive(Clone, uniffi::Object)]
pub struct MediaSource {
pub(crate) media_source: RumaMediaSource,
}
#[matrix_sdk_ffi_macros::export]
impl MediaSource {
#[uniffi::constructor]
pub fn from_url(url: String) -> Result<Arc<MediaSource>, ClientError> {
let media_source = RumaMediaSource::Plain(url.into());
media_source.verify()?;
Ok(Arc::new(MediaSource { media_source }))
}
fn to_json(&self) -> String {
serde_json::to_string(self).expect("Media source should always be serializable ")
pub fn url(&self) -> String {
self.media_source.url()
}
// Used on Element X Android
#[uniffi::constructor]
pub fn from_json(json: String) -> Result<Arc<Self>, ClientError> {
let media_source: RumaMediaSource = serde_json::from_str(&json)?;
media_source.verify()?;
Ok(Arc::new(MediaSource { media_source }))
}
// Used on Element X Android
pub fn to_json(&self) -> String {
serde_json::to_string(&self.media_source)
.expect("Media source should always be serializable ")
}
}
impl TryFrom<RumaMediaSource> for MediaSource {
type Error = ClientError;
fn try_from(value: RumaMediaSource) -> Result<Self, Self::Error> {
value.verify()?;
Ok(Self { media_source: value })
}
}
impl TryFrom<&RumaMediaSource> for MediaSource {
type Error = ClientError;
fn try_from(value: &RumaMediaSource) -> Result<Self, Self::Error> {
value.verify()?;
Ok(Self { media_source: value.clone() })
}
}
impl From<MediaSource> for RumaMediaSource {
fn from(value: MediaSource) -> Self {
value.media_source
}
}
#[extension_trait]
pub(crate) impl MediaSourceExt for RumaMediaSource {
fn verify(&self) -> Result<(), ClientError> {
match self {
RumaMediaSource::Plain(url) => {
url.validate().map_err(|e| ClientError::Generic { msg: e.to_string() })?;
}
RumaMediaSource::Encrypted(file) => {
file.url.validate().map_err(|e| ClientError::Generic { msg: e.to_string() })?;
}
}
Ok(())
}
fn url(&self) -> String {
match self {
MediaSource::Plain(url) => url.to_string(),
MediaSource::Encrypted(file) => file.url.to_string(),
RumaMediaSource::Plain(url) => url.to_string(),
RumaMediaSource::Encrypted(file) => file.url.to_string(),
}
}
}
@@ -129,6 +285,7 @@ pub impl RoomMessageEventContentWithoutRelationExt for RoomMessageEventContentWi
}
}
#[derive(Clone)]
pub struct Mentions {
pub user_ids: Vec<String>,
pub room: bool,
@@ -162,8 +319,25 @@ pub enum MessageType {
Other { msgtype: String, body: String },
}
/// From MSC2530: https://github.com/matrix-org/matrix-spec-proposals/blob/main/proposals/2530-body-as-caption.md
/// If the filename field is present in a media message, clients should treat
/// body as a caption instead of a file name. Otherwise, the body is the
/// file name.
///
/// So:
/// - if a media has a filename and a caption, the body is the caption, filename
/// is its own field.
/// - if a media only has a filename, then body is the filename.
fn get_body_and_filename(filename: String, caption: Option<String>) -> (String, Option<String>) {
if let Some(caption) = caption {
(caption, Some(filename))
} else {
(filename, None)
}
}
impl TryFrom<MessageType> for RumaMessageType {
type Error = serde_json::Error;
type Error = ClientError;
fn try_from(value: MessageType) -> Result<Self, Self::Error> {
Ok(match value {
@@ -172,23 +346,42 @@ impl TryFrom<MessageType> for RumaMessageType {
formatted: content.formatted.map(Into::into),
}))
}
MessageType::Image { content } => Self::Image(
RumaImageMessageEventContent::new(content.body, (*content.source).clone())
.info(content.info.map(Into::into).map(Box::new)),
),
MessageType::Audio { content } => Self::Audio(
RumaAudioMessageEventContent::new(content.body, (*content.source).clone())
.info(content.info.map(Into::into).map(Box::new)),
),
MessageType::Video { content } => Self::Video(
RumaVideoMessageEventContent::new(content.body, (*content.source).clone())
.info(content.info.map(Into::into).map(Box::new)),
),
MessageType::File { content } => Self::File(
RumaFileMessageEventContent::new(content.body, (*content.source).clone())
.filename(content.filename)
.info(content.info.map(Into::into).map(Box::new)),
),
MessageType::Image { content } => {
let (body, filename) = get_body_and_filename(content.filename, content.caption);
let mut event_content =
RumaImageMessageEventContent::new(body, (*content.source).clone().into())
.info(content.info.map(Into::into).map(Box::new));
event_content.formatted = content.formatted_caption.map(Into::into);
event_content.filename = filename;
Self::Image(event_content)
}
MessageType::Audio { content } => {
let (body, filename) = get_body_and_filename(content.filename, content.caption);
let mut event_content =
RumaAudioMessageEventContent::new(body, (*content.source).clone().into())
.info(content.info.map(Into::into).map(Box::new));
event_content.formatted = content.formatted_caption.map(Into::into);
event_content.filename = filename;
Self::Audio(event_content)
}
MessageType::Video { content } => {
let (body, filename) = get_body_and_filename(content.filename, content.caption);
let mut event_content =
RumaVideoMessageEventContent::new(body, (*content.source).clone().into())
.info(content.info.map(Into::into).map(Box::new));
event_content.formatted = content.formatted_caption.map(Into::into);
event_content.filename = filename;
Self::Video(event_content)
}
MessageType::File { content } => {
let (body, filename) = get_body_and_filename(content.filename, content.caption);
let mut event_content =
RumaFileMessageEventContent::new(body, (*content.source).clone().into())
.info(content.info.map(Into::into).map(Box::new));
event_content.formatted = content.formatted_caption.map(Into::into);
event_content.filename = filename;
Self::File(event_content)
}
MessageType::Notice { content } => {
Self::Notice(assign!(RumaNoticeMessageEventContent::plain(content.body), {
formatted: content.formatted.map(Into::into),
@@ -209,9 +402,11 @@ impl TryFrom<MessageType> for RumaMessageType {
}
}
impl From<RumaMessageType> for MessageType {
fn from(value: RumaMessageType) -> Self {
match value {
impl TryFrom<RumaMessageType> for MessageType {
type Error = ClientError;
fn try_from(value: RumaMessageType) -> Result<Self, Self::Error> {
Ok(match value {
RumaMessageType::Emote(c) => MessageType::Emote {
content: EmoteMessageContent {
body: c.body.clone(),
@@ -220,15 +415,20 @@ impl From<RumaMessageType> for MessageType {
},
RumaMessageType::Image(c) => MessageType::Image {
content: ImageMessageContent {
body: c.body.clone(),
source: Arc::new(c.source.clone()),
info: c.info.as_deref().map(Into::into),
filename: c.filename().to_owned(),
caption: c.caption().map(ToString::to_string),
formatted_caption: c.formatted_caption().map(Into::into),
source: Arc::new(c.source.try_into()?),
info: c.info.as_deref().map(TryInto::try_into).transpose()?,
},
},
RumaMessageType::Audio(c) => MessageType::Audio {
content: AudioMessageContent {
body: c.body.clone(),
source: Arc::new(c.source.clone()),
filename: c.filename().to_owned(),
caption: c.caption().map(ToString::to_string),
formatted_caption: c.formatted_caption().map(Into::into),
source: Arc::new(c.source.try_into()?),
info: c.info.as_deref().map(Into::into),
audio: c.audio.map(Into::into),
voice: c.voice.map(Into::into),
@@ -236,17 +436,20 @@ impl From<RumaMessageType> for MessageType {
},
RumaMessageType::Video(c) => MessageType::Video {
content: VideoMessageContent {
body: c.body.clone(),
source: Arc::new(c.source.clone()),
info: c.info.as_deref().map(Into::into),
filename: c.filename().to_owned(),
caption: c.caption().map(ToString::to_string),
formatted_caption: c.formatted_caption().map(Into::into),
source: Arc::new(c.source.try_into()?),
info: c.info.as_deref().map(TryInto::try_into).transpose()?,
},
},
RumaMessageType::File(c) => MessageType::File {
content: FileMessageContent {
body: c.body.clone(),
filename: c.filename.clone(),
source: Arc::new(c.source.clone()),
info: c.info.as_deref().map(Into::into),
filename: c.filename().to_owned(),
caption: c.caption().map(ToString::to_string),
formatted_caption: c.formatted_caption().map(Into::into),
source: Arc::new(c.source.try_into()?),
info: c.info.as_deref().map(TryInto::try_into).transpose()?,
},
},
RumaMessageType::Notice(c) => MessageType::Notice {
@@ -282,6 +485,30 @@ impl From<RumaMessageType> for MessageType {
msgtype: value.msgtype().to_owned(),
body: value.body().to_owned(),
},
})
}
}
#[derive(Clone, uniffi::Enum)]
pub enum NotifyType {
Ring,
Notify,
}
impl From<RumaNotifyType> for NotifyType {
fn from(val: RumaNotifyType) -> Self {
match val {
RumaNotifyType::Ring => Self::Ring,
_ => Self::Notify,
}
}
}
impl From<NotifyType> for RumaNotifyType {
fn from(value: NotifyType) -> Self {
match value {
NotifyType::Ring => RumaNotifyType::Ring,
NotifyType::Notify => RumaNotifyType::Notify,
}
}
}
@@ -294,14 +521,20 @@ pub struct EmoteMessageContent {
#[derive(Clone, uniffi::Record)]
pub struct ImageMessageContent {
pub body: String,
/// The computed filename, for use in a client.
pub filename: String,
pub caption: Option<String>,
pub formatted_caption: Option<FormattedBody>,
pub source: Arc<MediaSource>,
pub info: Option<ImageInfo>,
}
#[derive(Clone, uniffi::Record)]
pub struct AudioMessageContent {
pub body: String,
/// The computed filename, for use in a client.
pub filename: String,
pub caption: Option<String>,
pub formatted_caption: Option<FormattedBody>,
pub source: Arc<MediaSource>,
pub info: Option<AudioInfo>,
pub audio: Option<UnstableAudioDetailsContent>,
@@ -310,15 +543,20 @@ pub struct AudioMessageContent {
#[derive(Clone, uniffi::Record)]
pub struct VideoMessageContent {
pub body: String,
/// The computed filename, for use in a client.
pub filename: String,
pub caption: Option<String>,
pub formatted_caption: Option<FormattedBody>,
pub source: Arc<MediaSource>,
pub info: Option<VideoInfo>,
}
#[derive(Clone, uniffi::Record)]
pub struct FileMessageContent {
pub body: String,
pub filename: Option<String>,
/// The computed filename, for use in a client.
pub filename: String,
pub caption: Option<String>,
pub formatted_caption: Option<FormattedBody>,
pub source: Arc<MediaSource>,
pub info: Option<FileInfo>,
}
@@ -342,7 +580,7 @@ impl From<ImageInfo> for RumaImageInfo {
mimetype: value.mimetype,
size: value.size.map(u64_to_uint),
thumbnail_info: value.thumbnail_info.map(Into::into).map(Box::new),
thumbnail_source: value.thumbnail_source.map(|source| (*source).clone()),
thumbnail_source: value.thumbnail_source.map(|source| (*source).clone().into()),
blurhash: value.blurhash,
})
}
@@ -447,7 +685,7 @@ impl From<VideoInfo> for RumaVideoInfo {
mimetype: value.mimetype,
size: value.size.map(u64_to_uint),
thumbnail_info: value.thumbnail_info.map(Into::into).map(Box::new),
thumbnail_source: value.thumbnail_source.map(|source| (*source).clone()),
thumbnail_source: value.thumbnail_source.map(|source| (*source).clone().into()),
blurhash: value.blurhash,
})
}
@@ -490,7 +728,7 @@ impl From<FileInfo> for RumaFileInfo {
mimetype: value.mimetype,
size: value.size.map(u64_to_uint),
thumbnail_info: value.thumbnail_info.map(Into::into).map(Box::new),
thumbnail_source: value.thumbnail_source.map(|source| (*source).clone()),
thumbnail_source: value.thumbnail_source.map(|source| (*source).clone().into()),
})
}
}
@@ -525,21 +763,6 @@ impl From<ThumbnailInfo> for RumaThumbnailInfo {
}
}
impl TryFrom<&ThumbnailInfo> for BaseThumbnailInfo {
type Error = MediaInfoError;
fn try_from(value: &ThumbnailInfo) -> Result<Self, MediaInfoError> {
let height = UInt::try_from(value.height.ok_or(MediaInfoError::MissingField)?)
.map_err(|_| MediaInfoError::InvalidField)?;
let width = UInt::try_from(value.width.ok_or(MediaInfoError::MissingField)?)
.map_err(|_| MediaInfoError::InvalidField)?;
let size = UInt::try_from(value.size.ok_or(MediaInfoError::MissingField)?)
.map_err(|_| MediaInfoError::InvalidField)?;
Ok(BaseThumbnailInfo { height: Some(height), width: Some(width), size: Some(size) })
}
}
#[derive(Clone, uniffi::Record)]
pub struct NoticeMessageContent {
pub body: String,
@@ -612,8 +835,10 @@ pub enum MessageFormat {
Unknown { format: String },
}
impl From<&matrix_sdk::ruma::events::room::ImageInfo> for ImageInfo {
fn from(info: &matrix_sdk::ruma::events::room::ImageInfo) -> Self {
impl TryFrom<&matrix_sdk::ruma::events::room::ImageInfo> for ImageInfo {
type Error = ClientError;
fn try_from(info: &matrix_sdk::ruma::events::room::ImageInfo) -> Result<Self, Self::Error> {
let thumbnail_info = info.thumbnail_info.as_ref().map(|info| ThumbnailInfo {
height: info.height.map(Into::into),
width: info.width.map(Into::into),
@@ -621,15 +846,20 @@ impl From<&matrix_sdk::ruma::events::room::ImageInfo> for ImageInfo {
size: info.size.map(Into::into),
});
Self {
Ok(Self {
height: info.height.map(Into::into),
width: info.width.map(Into::into),
mimetype: info.mimetype.clone(),
size: info.size.map(Into::into),
thumbnail_info,
thumbnail_source: info.thumbnail_source.clone().map(Arc::new),
thumbnail_source: info
.thumbnail_source
.as_ref()
.map(TryInto::try_into)
.transpose()?
.map(Arc::new),
blurhash: info.blurhash.clone(),
}
})
}
}
@@ -643,8 +873,10 @@ impl From<&RumaAudioInfo> for AudioInfo {
}
}
impl From<&RumaVideoInfo> for VideoInfo {
fn from(info: &RumaVideoInfo) -> Self {
impl TryFrom<&RumaVideoInfo> for VideoInfo {
type Error = ClientError;
fn try_from(info: &RumaVideoInfo) -> Result<Self, Self::Error> {
let thumbnail_info = info.thumbnail_info.as_ref().map(|info| ThumbnailInfo {
height: info.height.map(Into::into),
width: info.width.map(Into::into),
@@ -652,21 +884,28 @@ impl From<&RumaVideoInfo> for VideoInfo {
size: info.size.map(Into::into),
});
Self {
Ok(Self {
duration: info.duration,
height: info.height.map(Into::into),
width: info.width.map(Into::into),
mimetype: info.mimetype.clone(),
size: info.size.map(Into::into),
thumbnail_info,
thumbnail_source: info.thumbnail_source.clone().map(Arc::new),
thumbnail_source: info
.thumbnail_source
.as_ref()
.map(TryInto::try_into)
.transpose()?
.map(Arc::new),
blurhash: info.blurhash.clone(),
}
})
}
}
impl From<&RumaFileInfo> for FileInfo {
fn from(info: &RumaFileInfo) -> Self {
impl TryFrom<&RumaFileInfo> for FileInfo {
type Error = ClientError;
fn try_from(info: &RumaFileInfo) -> Result<Self, Self::Error> {
let thumbnail_info = info.thumbnail_info.as_ref().map(|info| ThumbnailInfo {
height: info.height.map(Into::into),
width: info.width.map(Into::into),
@@ -674,16 +913,21 @@ impl From<&RumaFileInfo> for FileInfo {
size: info.size.map(Into::into),
});
Self {
Ok(Self {
mimetype: info.mimetype.clone(),
size: info.size.map(Into::into),
thumbnail_info,
thumbnail_source: info.thumbnail_source.clone().map(Arc::new),
}
thumbnail_source: info
.thumbnail_source
.as_ref()
.map(TryInto::try_into)
.transpose()?
.map(Arc::new),
})
}
}
#[derive(uniffi::Enum)]
#[derive(Clone, uniffi::Enum)]
pub enum PollKind {
Disclosed,
Undisclosed,
@@ -710,3 +954,13 @@ impl From<RumaPollKind> for PollKind {
}
}
}
/// Creates a [`RoomMessageEventContentWithoutRelation`] given a
/// [`MessageContent`] value.
#[matrix_sdk_ffi_macros::export]
pub fn content_without_relation_from_message(
message: MessageContent,
) -> Result<Arc<RoomMessageEventContentWithoutRelation>, ClientError> {
let msg_type = message.msg_type.try_into()?;
Ok(Arc::new(RoomMessageEventContentWithoutRelation::new(msg_type)))
}
@@ -1,15 +1,16 @@
use std::sync::{Arc, RwLock};
use anyhow::Context as _;
use futures_util::StreamExt;
use matrix_sdk::{
encryption::{
identities::UserIdentity,
verification::{SasState, SasVerification, VerificationRequest},
verification::{SasState, SasVerification, VerificationRequest, VerificationRequestState},
Encryption,
},
ruma::events::{key::verification::VerificationMethod, AnyToDeviceEvent},
};
use ruma::UserId;
use tracing::{error, info};
use super::RUNTIME;
use crate::error::ClientError;
@@ -20,7 +21,7 @@ pub struct SessionVerificationEmoji {
description: String,
}
#[uniffi::export]
#[matrix_sdk_ffi_macros::export]
impl SessionVerificationEmoji {
pub fn symbol(&self) -> String {
self.symbol.clone()
@@ -37,8 +38,20 @@ pub enum SessionVerificationData {
Decimals { values: Vec<u16> },
}
#[uniffi::export(callback_interface)]
/// Details about the incoming verification request
#[derive(Debug, uniffi::Record)]
pub struct SessionVerificationRequestDetails {
sender_id: String,
flow_id: String,
device_id: String,
display_name: Option<String>,
/// First time this device was seen in milliseconds since epoch.
first_seen_timestamp: u64,
}
#[matrix_sdk_ffi_macros::export(callback_interface)]
pub trait SessionVerificationControllerDelegate: Sync + Send {
fn did_receive_verification_request(&self, details: SessionVerificationRequestDetails);
fn did_accept_verification_request(&self);
fn did_start_sas_verification(&self);
fn did_receive_verification_data(&self, data: SessionVerificationData);
@@ -58,19 +71,53 @@ pub struct SessionVerificationController {
sas_verification: Arc<RwLock<Option<SasVerification>>>,
}
#[uniffi::export(async_runtime = "tokio")]
#[matrix_sdk_ffi_macros::export]
impl SessionVerificationController {
pub async fn is_verified(&self) -> Result<bool, ClientError> {
let device =
self.encryption.get_own_device().await?.context("Our own device is missing")?;
Ok(device.is_cross_signed_by_owner())
}
pub fn set_delegate(&self, delegate: Option<Box<dyn SessionVerificationControllerDelegate>>) {
*self.delegate.write().unwrap() = delegate;
}
/// Set this particular request as the currently active one and register for
/// events pertaining it.
/// * `sender_id` - The user requesting verification.
/// * `flow_id` - - The ID that uniquely identifies the verification flow.
pub async fn acknowledge_verification_request(
&self,
sender_id: String,
flow_id: String,
) -> Result<(), ClientError> {
let sender_id = UserId::parse(sender_id.clone())?;
let verification_request = self
.encryption
.get_verification_request(&sender_id, flow_id)
.await
.ok_or(ClientError::new("Unknown session verification request"))?;
*self.verification_request.write().unwrap() = Some(verification_request.clone());
RUNTIME.spawn(Self::listen_to_verification_request_changes(
verification_request,
self.sas_verification.clone(),
self.delegate.clone(),
));
Ok(())
}
/// Accept the previously acknowledged verification request
pub async fn accept_verification_request(&self) -> Result<(), ClientError> {
let verification_request = self.verification_request.read().unwrap().clone();
if let Some(verification_request) = verification_request {
let methods = vec![VerificationMethod::SasV1];
verification_request.accept_with_methods(methods).await?;
}
Ok(())
}
/// Request verification for the current device
pub async fn request_verification(&self) -> Result<(), ClientError> {
let methods = vec![VerificationMethod::SasV1];
let verification_request = self
@@ -78,30 +125,41 @@ impl SessionVerificationController {
.request_verification_with_methods(methods)
.await
.map_err(anyhow::Error::from)?;
*self.verification_request.write().unwrap() = Some(verification_request);
*self.verification_request.write().unwrap() = Some(verification_request.clone());
RUNTIME.spawn(Self::listen_to_verification_request_changes(
verification_request,
self.sas_verification.clone(),
self.delegate.clone(),
));
Ok(())
}
/// Transition the current verification request into a SAS verification
/// flow.
pub async fn start_sas_verification(&self) -> Result<(), ClientError> {
let verification_request = self.verification_request.read().unwrap().clone();
if let Some(verification) = verification_request {
match verification.start_sas().await {
Ok(Some(verification)) => {
*self.sas_verification.write().unwrap() = Some(verification.clone());
let Some(verification_request) = verification_request else {
return Err(ClientError::new("Verification request missing."));
};
if let Some(delegate) = &*self.delegate.read().unwrap() {
delegate.did_start_sas_verification()
}
match verification_request.start_sas().await {
Ok(Some(verification)) => {
*self.sas_verification.write().unwrap() = Some(verification.clone());
let delegate = self.delegate.clone();
RUNTIME.spawn(Self::listen_to_changes(delegate, verification));
if let Some(delegate) = &*self.delegate.read().unwrap() {
delegate.did_start_sas_verification()
}
_ => {
if let Some(delegate) = &*self.delegate.read().unwrap() {
delegate.did_fail()
}
let delegate = self.delegate.clone();
RUNTIME.spawn(Self::listen_to_sas_verification_changes(verification, delegate));
}
_ => {
if let Some(delegate) = &*self.delegate.read().unwrap() {
delegate.did_fail()
}
}
}
@@ -109,31 +167,37 @@ impl SessionVerificationController {
Ok(())
}
/// Confirm that the short auth strings match on both sides.
pub async fn approve_verification(&self) -> Result<(), ClientError> {
let sas_verification = self.sas_verification.read().unwrap().clone();
if let Some(sas_verification) = sas_verification {
sas_verification.confirm().await?;
}
Ok(())
let Some(sas_verification) = sas_verification else {
return Err(ClientError::new("SAS verification missing"));
};
Ok(sas_verification.confirm().await?)
}
/// Reject the short auth string
pub async fn decline_verification(&self) -> Result<(), ClientError> {
let sas_verification = self.sas_verification.read().unwrap().clone();
if let Some(sas_verification) = sas_verification {
sas_verification.mismatch().await?;
}
Ok(())
let Some(sas_verification) = sas_verification else {
return Err(ClientError::new("SAS verification missing"));
};
Ok(sas_verification.mismatch().await?)
}
/// Cancel the current verification request
pub async fn cancel_verification(&self) -> Result<(), ClientError> {
let verification_request = self.verification_request.read().unwrap().clone();
if let Some(verification) = verification_request {
verification.cancel().await?;
}
Ok(())
let Some(verification_request) = verification_request else {
return Err(ClientError::new("Verification request missing."));
};
Ok(verification_request.cancel().await?)
}
}
@@ -149,58 +213,88 @@ impl SessionVerificationController {
}
pub(crate) async fn process_to_device_message(&self, event: AnyToDeviceEvent) {
match event {
// TODO: Use the changes stream for this as well once we expose
// VerificationRequest::changes() in the main crate.
AnyToDeviceEvent::KeyVerificationStart(event) => {
if !self.is_transaction_id_valid(event.content.transaction_id.to_string()) {
return;
}
if let Some(verification) = self
.encryption
.get_verification(
self.user_identity.user_id(),
event.content.transaction_id.as_str(),
)
.await
{
if let Some(sas_verification) = verification.sas() {
*self.sas_verification.write().unwrap() = Some(sas_verification.clone());
if let AnyToDeviceEvent::KeyVerificationRequest(event) = event {
info!("Received verification request: {:}", event.sender);
if sas_verification.accept().await.is_ok() {
if let Some(delegate) = &*self.delegate.read().unwrap() {
delegate.did_start_sas_verification()
}
let Some(request) = self
.encryption
.get_verification_request(&event.sender, &event.content.transaction_id)
.await
else {
error!("Failed retrieving verification request");
return;
};
let delegate = self.delegate.clone();
RUNTIME.spawn(Self::listen_to_changes(delegate, sas_verification));
} else if let Some(delegate) = &*self.delegate.read().unwrap() {
delegate.did_fail()
if !request.is_self_verification() {
info!("Received non-self verification request. Ignoring.");
return;
}
let VerificationRequestState::Requested { other_device_data, .. } = request.state()
else {
error!("Received key verification event but the request is in the wrong state.");
return;
};
if let Some(delegate) = &*self.delegate.read().unwrap() {
delegate.did_receive_verification_request(SessionVerificationRequestDetails {
sender_id: request.other_user_id().into(),
flow_id: request.flow_id().into(),
device_id: other_device_data.device_id().into(),
display_name: other_device_data.display_name().map(str::to_string),
first_seen_timestamp: other_device_data.first_time_seen_ts().get().into(),
});
}
}
}
async fn listen_to_verification_request_changes(
verification_request: VerificationRequest,
sas_verification: Arc<RwLock<Option<SasVerification>>>,
delegate: Delegate,
) {
let mut stream = verification_request.changes();
while let Some(state) = stream.next().await {
match state {
VerificationRequestState::Transitioned { verification } => {
let Some(verification) = verification.sas() else {
error!("Invalid, non-sas verification flow. Returning.");
return;
};
*sas_verification.write().unwrap() = Some(verification.clone());
if verification.accept().await.is_ok() {
if let Some(delegate) = &*delegate.read().unwrap() {
delegate.did_start_sas_verification()
}
let delegate = delegate.clone();
RUNTIME.spawn(Self::listen_to_sas_verification_changes(
verification,
delegate,
));
} else if let Some(delegate) = &*delegate.read().unwrap() {
delegate.did_fail()
}
}
}
AnyToDeviceEvent::KeyVerificationReady(event) => {
if !self.is_transaction_id_valid(event.content.transaction_id.to_string()) {
return;
VerificationRequestState::Ready { .. } => {
if let Some(delegate) = &*delegate.read().unwrap() {
delegate.did_accept_verification_request()
}
}
if let Some(delegate) = &*self.delegate.read().unwrap() {
delegate.did_accept_verification_request()
VerificationRequestState::Cancelled(..) => {
if let Some(delegate) = &*delegate.read().unwrap() {
delegate.did_cancel();
}
}
_ => {}
}
_ => (),
}
}
fn is_transaction_id_valid(&self, transaction_id: String) -> bool {
match &*self.verification_request.read().unwrap() {
Some(verification) => verification.flow_id() == transaction_id,
None => false,
}
}
async fn listen_to_changes(delegate: Delegate, sas: SasVerification) {
async fn listen_to_sas_verification_changes(sas: SasVerification, delegate: Delegate) {
let mut stream = sas.changes();
while let Some(state) = stream.next().await {
@@ -246,7 +340,10 @@ impl SessionVerificationController {
}
break;
}
SasState::Started { .. } | SasState::Accepted { .. } | SasState::Confirmed => (),
SasState::Created { .. }
| SasState::Started { .. }
| SasState::Accepted { .. }
| SasState::Confirmed => (),
}
}
}
+140 -14
View File
@@ -12,14 +12,20 @@
// See the License for that specific language governing permissions and
// limitations under the License.
use std::{fmt::Debug, sync::Arc};
use std::{fmt::Debug, sync::Arc, time::Duration};
use futures_util::pin_mut;
use matrix_sdk::Client;
use matrix_sdk_ui::sync_service::{
State as MatrixSyncServiceState, SyncService as MatrixSyncService,
SyncServiceBuilder as MatrixSyncServiceBuilder,
use matrix_sdk::{crypto::types::events::UtdCause, Client};
use matrix_sdk_ui::{
sync_service::{
State as MatrixSyncServiceState, SyncService as MatrixSyncService,
SyncServiceBuilder as MatrixSyncServiceBuilder,
},
unable_to_decrypt_hook::{
UnableToDecryptHook, UnableToDecryptInfo as SdkUnableToDecryptInfo, UtdHookManager,
},
};
use tracing::error;
use crate::{
error::ClientError, helpers::unwrap_or_clone_arc, room_list::RoomListService, TaskHandle,
@@ -45,7 +51,7 @@ impl From<MatrixSyncServiceState> for SyncServiceState {
}
}
#[uniffi::export(callback_interface)]
#[matrix_sdk_ffi_macros::export(callback_interface)]
pub trait SyncServiceStateObserver: Send + Sync + Debug {
fn on_update(&self, state: SyncServiceState);
}
@@ -53,12 +59,16 @@ pub trait SyncServiceStateObserver: Send + Sync + Debug {
#[derive(uniffi::Object)]
pub struct SyncService {
pub(crate) inner: Arc<MatrixSyncService>,
utd_hook: Option<Arc<UtdHookManager>>,
}
#[uniffi::export(async_runtime = "tokio")]
#[matrix_sdk_ffi_macros::export]
impl SyncService {
pub fn room_list_service(&self) -> Arc<RoomListService> {
Arc::new(RoomListService { inner: self.inner.room_list_service() })
Arc::new(RoomListService {
inner: self.inner.room_list_service(),
utd_hook: self.utd_hook.clone(),
})
}
pub async fn start(&self) {
@@ -84,25 +94,141 @@ impl SyncService {
#[derive(Clone, uniffi::Object)]
pub struct SyncServiceBuilder {
client: Client,
builder: MatrixSyncServiceBuilder,
utd_hook: Option<Arc<UtdHookManager>>,
}
impl SyncServiceBuilder {
pub(crate) fn new(client: Client) -> Arc<Self> {
Arc::new(Self { builder: MatrixSyncService::builder(client) })
Arc::new(Self {
client: client.clone(),
builder: MatrixSyncService::builder(client),
utd_hook: None,
})
}
}
#[uniffi::export(async_runtime = "tokio")]
#[matrix_sdk_ffi_macros::export]
impl SyncServiceBuilder {
pub fn with_cross_process_lock(self: Arc<Self>, app_identifier: Option<String>) -> Arc<Self> {
pub fn with_cross_process_lock(self: Arc<Self>) -> Arc<Self> {
let this = unwrap_or_clone_arc(self);
let builder = this.builder.with_cross_process_lock(app_identifier);
Arc::new(Self { builder })
let builder = this.builder.with_cross_process_lock();
Arc::new(Self { client: this.client, builder, utd_hook: this.utd_hook })
}
pub async fn with_utd_hook(
self: Arc<Self>,
delegate: Box<dyn UnableToDecryptDelegate>,
) -> Arc<Self> {
// UTDs detected before this duration may be reclassified as "late decryption"
// events (or discarded, if they get decrypted fast enough).
const UTD_HOOK_GRACE_PERIOD: Duration = Duration::from_secs(60);
let this = unwrap_or_clone_arc(self);
let mut utd_hook = UtdHookManager::new(Arc::new(UtdHook { delegate }), this.client.clone())
.with_max_delay(UTD_HOOK_GRACE_PERIOD);
if let Err(e) = utd_hook.reload_from_store().await {
error!("Unable to reload UTD hook data from data store: {}", e);
// Carry on with the setup anyway; we shouldn't fail setup just
// because the UTD hook failed to load its data.
}
Arc::new(Self {
client: this.client,
builder: this.builder,
utd_hook: Some(Arc::new(utd_hook)),
})
}
pub async fn finish(self: Arc<Self>) -> Result<Arc<SyncService>, ClientError> {
let this = unwrap_or_clone_arc(self);
Ok(Arc::new(SyncService { inner: Arc::new(this.builder.build().await?) }))
Ok(Arc::new(SyncService {
inner: Arc::new(this.builder.build().await?),
utd_hook: this.utd_hook,
}))
}
}
#[matrix_sdk_ffi_macros::export(callback_interface)]
pub trait UnableToDecryptDelegate: Sync + Send {
fn on_utd(&self, info: UnableToDecryptInfo);
}
struct UtdHook {
delegate: Box<dyn UnableToDecryptDelegate>,
}
impl std::fmt::Debug for UtdHook {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("UtdHook").finish_non_exhaustive()
}
}
impl UnableToDecryptHook for UtdHook {
fn on_utd(&self, info: SdkUnableToDecryptInfo) {
const IGNORE_UTD_PERIOD: Duration = Duration::from_secs(4);
// UTDs that have been decrypted in the `IGNORE_UTD_PERIOD` are just ignored and
// not considered UTDs.
if let Some(duration) = &info.time_to_decrypt {
if *duration < IGNORE_UTD_PERIOD {
return;
}
}
// Report the UTD to the client.
self.delegate.on_utd(info.into());
}
}
#[derive(uniffi::Record)]
pub struct UnableToDecryptInfo {
/// The identifier of the event that couldn't get decrypted.
event_id: String,
/// If the event could be decrypted late (that is, the event was encrypted
/// at first, but could be decrypted later on), then this indicates the
/// time it took to decrypt the event. If it is not set, this is
/// considered a definite UTD.
///
/// If set, this is in milliseconds.
pub time_to_decrypt_ms: Option<u64>,
/// What we know about what caused this UTD. E.g. was this event sent when
/// we were not a member of this room?
pub cause: UtdCause,
/// The difference between the event creation time (`origin_server_ts`) and
/// the time our device was created. If negative, this event was sent
/// *before* our device was created.
pub event_local_age_millis: i64,
/// Whether the user had verified their own identity at the point they
/// received the UTD event.
pub user_trusts_own_identity: bool,
/// The homeserver of the user that sent the undecryptable event.
pub sender_homeserver: String,
/// Our local user's own homeserver, or `None` if the client is not logged
/// in.
pub own_homeserver: Option<String>,
}
impl From<SdkUnableToDecryptInfo> for UnableToDecryptInfo {
fn from(value: SdkUnableToDecryptInfo) -> Self {
Self {
event_id: value.event_id.to_string(),
time_to_decrypt_ms: value.time_to_decrypt.map(|ttd| ttd.as_millis() as u64),
cause: value.cause,
event_local_age_millis: value.event_local_age_millis,
user_trusts_own_identity: value.user_trusts_own_identity,
sender_homeserver: value.sender_homeserver.to_string(),
own_homeserver: value.own_homeserver.map(String::from),
}
}
}
+1 -1
View File
@@ -17,7 +17,7 @@ impl TaskHandle {
}
}
#[uniffi::export]
#[matrix_sdk_ffi_macros::export]
impl TaskHandle {
// Cancel a task handle.
pub fn cancel(&self) {
+167 -78
View File
@@ -14,39 +14,83 @@
use std::{collections::HashMap, sync::Arc};
use matrix_sdk_ui::timeline::{PollResult, TimelineDetails};
use tracing::warn;
use matrix_sdk::{crypto::types::events::UtdCause, room::power_levels::power_level_user_changes};
use matrix_sdk_ui::timeline::{PollResult, RoomPinnedEventsChange, TimelineDetails};
use ruma::events::{room::MediaSource as RumaMediaSource, EventContent, FullStateEventContent};
use super::ProfileDetails;
use crate::ruma::{ImageInfo, MessageType, PollKind};
use crate::{
error::ClientError,
ruma::{ImageInfo, MediaSource, MediaSourceExt, Mentions, MessageType, PollKind},
};
#[derive(Clone, uniffi::Object)]
pub struct TimelineItemContent(pub(crate) matrix_sdk_ui::timeline::TimelineItemContent);
#[uniffi::export]
impl TimelineItemContent {
pub fn kind(&self) -> TimelineItemContentKind {
impl From<matrix_sdk_ui::timeline::TimelineItemContent> for TimelineItemContent {
fn from(value: matrix_sdk_ui::timeline::TimelineItemContent) -> Self {
use matrix_sdk_ui::timeline::TimelineItemContent as Content;
match &self.0 {
Content::Message(_) => TimelineItemContentKind::Message,
Content::RedactedMessage => TimelineItemContentKind::RedactedMessage,
Content::Sticker(sticker) => {
let content = sticker.content();
TimelineItemContentKind::Sticker {
body: content.body.clone(),
info: (&content.info).into(),
url: content.url.to_string(),
match value {
Content::Message(message) => {
let msgtype = message.msgtype().msgtype().to_owned();
match TryInto::<MessageContent>::try_into(message) {
Ok(message) => TimelineItemContent::Message { content: message },
Err(error) => TimelineItemContent::FailedToParseMessageLike {
event_type: msgtype,
error: error.to_string(),
},
}
}
Content::Poll(poll_state) => TimelineItemContentKind::from(poll_state.results()),
Content::UnableToDecrypt(msg) => {
TimelineItemContentKind::UnableToDecrypt { msg: EncryptedMessage::new(msg) }
Content::RedactedMessage => TimelineItemContent::RedactedMessage,
Content::Sticker(sticker) => {
let content = sticker.content();
let media_source = RumaMediaSource::from(content.source.clone());
if let Err(error) = media_source.verify() {
return TimelineItemContent::FailedToParseMessageLike {
event_type: sticker.content().event_type().to_string(),
error: error.to_string(),
};
}
match TryInto::<ImageInfo>::try_into(&content.info) {
Ok(info) => TimelineItemContent::Sticker {
body: content.body.clone(),
info,
source: Arc::new(MediaSource { media_source }),
},
Err(error) => TimelineItemContent::FailedToParseMessageLike {
event_type: sticker.content().event_type().to_string(),
error: error.to_string(),
},
}
}
Content::MembershipChange(membership) => TimelineItemContentKind::RoomMembership {
user_id: membership.user_id().to_string(),
change: membership.change().map(Into::into),
},
Content::Poll(poll_state) => TimelineItemContent::from(poll_state.results()),
Content::CallInvite => TimelineItemContent::CallInvite,
Content::CallNotify => TimelineItemContent::CallNotify,
Content::UnableToDecrypt(msg) => {
TimelineItemContent::UnableToDecrypt { msg: EncryptedMessage::new(&msg) }
}
Content::MembershipChange(membership) => {
let reason = match membership.content() {
FullStateEventContent::Original { content, .. } => content.reason.clone(),
_ => None,
};
TimelineItemContent::RoomMembership {
user_id: membership.user_id().to_string(),
user_display_name: membership.display_name(),
change: membership.change().map(Into::into),
reason,
}
}
Content::ProfileChange(profile) => {
let (display_name, prev_display_name) = profile
.displayname_change()
@@ -61,47 +105,81 @@ impl TimelineItemContent {
)
})
.unzip();
TimelineItemContentKind::ProfileChange {
TimelineItemContent::ProfileChange {
display_name: display_name.flatten(),
prev_display_name: prev_display_name.flatten(),
avatar_url: avatar_url.flatten(),
prev_avatar_url: prev_avatar_url.flatten(),
}
}
Content::OtherState(state) => TimelineItemContentKind::State {
Content::OtherState(state) => TimelineItemContent::State {
state_key: state.state_key().to_owned(),
content: state.content().into(),
},
Content::FailedToParseMessageLike { event_type, error } => {
TimelineItemContentKind::FailedToParseMessageLike {
TimelineItemContent::FailedToParseMessageLike {
event_type: event_type.to_string(),
error: error.to_string(),
}
}
Content::FailedToParseState { event_type, state_key, error } => {
TimelineItemContentKind::FailedToParseState {
TimelineItemContent::FailedToParseState {
event_type: event_type.to_string(),
state_key: state_key.to_string(),
state_key,
error: error.to_string(),
}
}
}
}
}
pub fn as_message(self: Arc<Self>) -> Option<Arc<Message>> {
use matrix_sdk_ui::timeline::TimelineItemContent as Content;
unwrap_or_clone_arc_into_variant!(self, .0, Content::Message(msg) => Arc::new(Message(msg)))
#[derive(Clone, uniffi::Record)]
pub struct MessageContent {
pub msg_type: MessageType,
pub body: String,
pub in_reply_to: Option<Arc<InReplyToDetails>>,
pub thread_root: Option<String>,
pub is_edited: bool,
pub mentions: Option<Mentions>,
}
impl TryFrom<matrix_sdk_ui::timeline::Message> for MessageContent {
type Error = ClientError;
fn try_from(value: matrix_sdk_ui::timeline::Message) -> Result<Self, Self::Error> {
Ok(Self {
msg_type: value.msgtype().clone().try_into()?,
body: value.body().to_owned(),
in_reply_to: value.in_reply_to().map(|r| Arc::new(r.clone().into())),
is_edited: value.is_edited(),
thread_root: value.thread_root().map(|id| id.to_string()),
mentions: value.mentions().cloned().map(|m| m.into()),
})
}
}
#[derive(uniffi::Enum)]
pub enum TimelineItemContentKind {
Message,
impl From<ruma::events::Mentions> for Mentions {
fn from(value: ruma::events::Mentions) -> Self {
Self {
user_ids: value.user_ids.iter().map(|id| id.to_string()).collect(),
room: value.room,
}
}
}
#[derive(Clone, uniffi::Enum)]
pub enum TimelineItemContent {
Message {
content: MessageContent,
},
RedactedMessage,
Sticker {
body: String,
info: ImageInfo,
url: String,
source: Arc<MediaSource>,
},
Poll {
question: String,
@@ -112,12 +190,16 @@ pub enum TimelineItemContentKind {
end_time: Option<u64>,
has_been_edited: bool,
},
CallInvite,
CallNotify,
UnableToDecrypt {
msg: EncryptedMessage,
},
RoomMembership {
user_id: String,
user_display_name: Option<String>,
change: Option<MembershipChange>,
reason: Option<String>,
},
ProfileChange {
display_name: Option<String>,
@@ -141,45 +223,36 @@ pub enum TimelineItemContentKind {
}
#[derive(Clone, uniffi::Object)]
pub struct Message(matrix_sdk_ui::timeline::Message);
#[uniffi::export]
impl Message {
pub fn msgtype(&self) -> MessageType {
self.0.msgtype().clone().into()
}
pub fn body(&self) -> String {
self.0.msgtype().body().to_owned()
}
pub fn in_reply_to(&self) -> Option<InReplyToDetails> {
self.0.in_reply_to().map(InReplyToDetails::from)
}
pub fn is_threaded(&self) -> bool {
self.0.is_threaded()
}
pub fn is_edited(&self) -> bool {
self.0.is_edited()
}
}
#[derive(uniffi::Record)]
pub struct InReplyToDetails {
event_id: String,
event: RepliedToEventDetails,
}
impl From<&matrix_sdk_ui::timeline::InReplyToDetails> for InReplyToDetails {
fn from(inner: &matrix_sdk_ui::timeline::InReplyToDetails) -> Self {
impl InReplyToDetails {
pub(crate) fn new(event_id: String, event: RepliedToEventDetails) -> Self {
Self { event_id, event }
}
}
#[matrix_sdk_ffi_macros::export]
impl InReplyToDetails {
pub fn event_id(&self) -> String {
self.event_id.clone()
}
pub fn event(&self) -> RepliedToEventDetails {
self.event.clone()
}
}
impl From<matrix_sdk_ui::timeline::InReplyToDetails> for InReplyToDetails {
fn from(inner: matrix_sdk_ui::timeline::InReplyToDetails) -> Self {
let event_id = inner.event_id.to_string();
let event = match &inner.event {
TimelineDetails::Unavailable => RepliedToEventDetails::Unavailable,
TimelineDetails::Pending => RepliedToEventDetails::Pending,
TimelineDetails::Ready(event) => RepliedToEventDetails::Ready {
content: Arc::new(TimelineItemContent(event.content().to_owned())),
content: event.content().clone().into(),
sender: event.sender().to_string(),
sender_profile: event.sender_profile().into(),
},
@@ -192,11 +265,11 @@ impl From<&matrix_sdk_ui::timeline::InReplyToDetails> for InReplyToDetails {
}
}
#[derive(uniffi::Enum)]
#[derive(Clone, uniffi::Enum)]
pub enum RepliedToEventDetails {
Unavailable,
Pending,
Ready { content: Arc<TimelineItemContent>, sender: String, sender_profile: ProfileDetails },
Ready { content: TimelineItemContent, sender: String, sender_profile: ProfileDetails },
Error { message: String },
}
@@ -211,6 +284,10 @@ pub enum EncryptedMessage {
MegolmV1AesSha2 {
/// The ID of the session used to encrypt the message.
session_id: String,
/// What we know about what caused this UTD. E.g. was this event sent
/// when we were not a member of this room?
cause: UtdCause,
},
Unknown,
}
@@ -224,9 +301,9 @@ impl EncryptedMessage {
let sender_key = sender_key.clone();
Self::OlmV1Curve25519AesSha2 { sender_key }
}
Message::MegolmV1AesSha2 { session_id, .. } => {
Message::MegolmV1AesSha2 { session_id, cause, .. } => {
let session_id = session_id.clone();
Self::MegolmV1AesSha2 { session_id }
Self::MegolmV1AesSha2 { session_id, cause: *cause }
}
Message::Unknown => Self::Unknown,
}
@@ -236,7 +313,6 @@ impl EncryptedMessage {
#[derive(Clone, uniffi::Record)]
pub struct Reaction {
pub key: String,
pub count: u64,
pub senders: Vec<ReactionSenderData>,
}
@@ -306,8 +382,8 @@ pub enum OtherState {
RoomHistoryVisibility,
RoomJoinRules,
RoomName { name: Option<String> },
RoomPinnedEvents,
RoomPowerLevels,
RoomPinnedEvents { change: RoomPinnedEventsChange },
RoomPowerLevels { users: HashMap<String, i64>, previous: Option<HashMap<String, i64>> },
RoomServerAcl,
RoomThirdPartyInvite { display_name: Option<String> },
RoomTombstone,
@@ -349,8 +425,21 @@ impl From<&matrix_sdk_ui::timeline::AnyOtherFullStateEventContent> for OtherStat
};
Self::RoomName { name }
}
Content::RoomPinnedEvents(_) => Self::RoomPinnedEvents,
Content::RoomPowerLevels(_) => Self::RoomPowerLevels,
Content::RoomPinnedEvents(c) => Self::RoomPinnedEvents { change: c.into() },
Content::RoomPowerLevels(c) => match c {
FullContent::Original { content, prev_content } => Self::RoomPowerLevels {
users: power_level_user_changes(content, prev_content)
.iter()
.map(|(k, v)| (k.to_string(), *v))
.collect(),
previous: prev_content.as_ref().map(|prev_content| {
prev_content.users.iter().map(|(k, &v)| (k.to_string(), v.into())).collect()
}),
},
FullContent::Redacted(_) => {
Self::RoomPowerLevels { users: Default::default(), previous: None }
}
},
Content::RoomServerAcl(_) => Self::RoomServerAcl,
Content::RoomThirdPartyInvite(c) => {
let display_name = match c {
@@ -374,15 +463,15 @@ impl From<&matrix_sdk_ui::timeline::AnyOtherFullStateEventContent> for OtherStat
}
}
#[derive(uniffi::Record)]
#[derive(Clone, uniffi::Record)]
pub struct PollAnswer {
pub id: String,
pub text: String,
}
impl From<PollResult> for TimelineItemContentKind {
impl From<PollResult> for TimelineItemContent {
fn from(value: PollResult) -> Self {
TimelineItemContentKind::Poll {
TimelineItemContent::Poll {
question: value.question,
kind: PollKind::from(value.kind),
max_selections: value.max_selections,
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,55 @@
use std::sync::Arc;
use matrix_sdk_ui::timeline::event_type_filter::TimelineEventTypeFilter as InnerTimelineEventTypeFilter;
use ruma::events::{AnySyncTimelineEvent, TimelineEventType};
use crate::event::{MessageLikeEventType, StateEventType};
#[derive(uniffi::Object)]
pub struct TimelineEventTypeFilter {
inner: InnerTimelineEventTypeFilter,
}
#[matrix_sdk_ffi_macros::export]
impl TimelineEventTypeFilter {
#[uniffi::constructor]
pub fn include(event_types: Vec<FilterTimelineEventType>) -> Arc<Self> {
let event_types: Vec<TimelineEventType> =
event_types.iter().map(|t| t.clone().into()).collect();
Arc::new(Self { inner: InnerTimelineEventTypeFilter::Include(event_types) })
}
#[uniffi::constructor]
pub fn exclude(event_types: Vec<FilterTimelineEventType>) -> Arc<Self> {
let event_types: Vec<TimelineEventType> =
event_types.iter().map(|t| t.clone().into()).collect();
Arc::new(Self { inner: InnerTimelineEventTypeFilter::Exclude(event_types) })
}
}
impl TimelineEventTypeFilter {
/// Filters an [`event`] to decide whether it should be part of the timeline
/// based on [`AnySyncTimelineEvent::event_type()`].
pub(crate) fn filter(&self, event: &AnySyncTimelineEvent) -> bool {
self.inner.filter(event)
}
}
#[derive(uniffi::Enum, Clone)]
pub enum FilterTimelineEventType {
MessageLike { event_type: MessageLikeEventType },
State { event_type: StateEventType },
}
impl From<FilterTimelineEventType> for TimelineEventType {
fn from(value: FilterTimelineEventType) -> TimelineEventType {
match value {
FilterTimelineEventType::MessageLike { event_type } => {
ruma::events::MessageLikeEventType::from(event_type).into()
}
FilterTimelineEventType::State { event_type } => {
ruma::events::StateEventType::from(event_type).into()
}
}
}
}
+6 -6
View File
@@ -19,7 +19,7 @@ use tracing_core::{identify_callsite, metadata::Kind as MetadataKind};
/// level + target) it is called with. Please make sure that the number of
/// different combinations of those parameters this can be called with is
/// constant in the final executable.
#[uniffi::export]
#[matrix_sdk_ffi_macros::export]
fn log_event(file: String, line: Option<u32>, level: LogLevel, target: String, message: String) {
static CALLSITES: Mutex<BTreeMap<MetadataId, &'static DefaultCallsite>> =
Mutex::new(BTreeMap::new());
@@ -96,7 +96,7 @@ fn span_or_event_enabled(callsite: &'static DefaultCallsite) -> bool {
#[derive(uniffi::Object)]
pub struct Span(tracing::Span);
#[uniffi::export]
#[matrix_sdk_ffi_macros::export]
impl Span {
/// Create a span originating at the given callsite (file, line and column).
///
@@ -107,10 +107,10 @@ impl Span {
/// target passed for second and following creation of a span with the same
/// callsite will be ignored.
///
/// This function leaks a little bit of memory for each unique (file + line
/// + level + target + name) it is called with. Please make sure that the
/// number of different combinations of those parameters this can be called
/// with is constant in the final executable.
/// This function leaks a little bit of memory for each unique (file +
/// line + level + target + name) it is called with. Please make sure that
/// the number of different combinations of those parameters this can be
/// called with is constant in the final executable.
///
/// For a span to have an effect, you must `.enter()` it at the start of a
/// logical unit of work and `.exit()` it at the end of the same (including
+45
View File
@@ -12,6 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use std::{mem::ManuallyDrop, ops::Deref};
use async_compat::TOKIO1 as RUNTIME;
use ruma::UInt;
use tracing::warn;
@@ -21,3 +24,45 @@ pub(crate) fn u64_to_uint(u: u64) -> UInt {
UInt::MAX
})
}
/// Tiny wrappers for data types that must be dropped in the context of an async
/// runtime.
///
/// This is useful whenever such a data type may transitively call some
/// runtime's `block_on` function in their `Drop` impl (since we lack async drop
/// at the moment), like done in some `deadpool` drop impls.
pub(crate) struct AsyncRuntimeDropped<T>(ManuallyDrop<T>);
impl<T> AsyncRuntimeDropped<T> {
/// Create a new wrapper for this type that will be dropped under an async
/// runtime.
pub fn new(val: T) -> Self {
Self(ManuallyDrop::new(val))
}
}
impl<T> Drop for AsyncRuntimeDropped<T> {
fn drop(&mut self) {
let _guard = RUNTIME.enter();
// SAFETY: self.inner is never used again, which is the only requirement
// for ManuallyDrop::drop to be used safely.
unsafe {
ManuallyDrop::drop(&mut self.0);
}
}
}
// What is an `AsyncRuntimeDropped<T>`, if not a `T` in disguise?
impl<T> Deref for AsyncRuntimeDropped<T> {
type Target = T;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl<T: Clone> Clone for AsyncRuntimeDropped<T> {
fn clone(&self) -> Self {
Self(self.0.clone())
}
}
+138 -23
View File
@@ -5,6 +5,7 @@ use matrix_sdk::{
async_trait,
widget::{MessageLikeEventFilter, StateEventFilter},
};
use ruma::events::MessageLikeEventType;
use tracing::error;
use crate::{room::Room, RUNTIME};
@@ -15,7 +16,7 @@ pub struct WidgetDriverAndHandle {
pub handle: Arc<WidgetDriverHandle>,
}
#[uniffi::export]
#[matrix_sdk_ffi_macros::export]
pub fn make_widget_driver(settings: WidgetSettings) -> Result<WidgetDriverAndHandle, ParseError> {
let (driver, handle) = matrix_sdk::widget::WidgetDriver::new(settings.try_into()?);
Ok(WidgetDriverAndHandle {
@@ -29,7 +30,7 @@ pub fn make_widget_driver(settings: WidgetSettings) -> Result<WidgetDriverAndHan
#[derive(uniffi::Object)]
pub struct WidgetDriver(Mutex<Option<matrix_sdk::widget::WidgetDriver>>);
#[uniffi::export(async_runtime = "tokio")]
#[matrix_sdk_ffi_macros::export]
impl WidgetDriver {
pub async fn run(
&self,
@@ -96,7 +97,7 @@ impl From<matrix_sdk::widget::WidgetSettings> for WidgetSettings {
/// * `room` - A matrix room which is used to query the logged in username
/// * `props` - Properties from the client that can be used by a widget to adapt
/// to the client. e.g. language, font-scale...
#[uniffi::export(async_runtime = "tokio")]
#[matrix_sdk_ffi_macros::export]
pub async fn generate_webview_url(
widget_settings: WidgetSettings,
room: Arc<Room>,
@@ -236,10 +237,12 @@ impl From<VirtualElementCallWidgetOptions> for matrix_sdk::widget::VirtualElemen
/// This function returns a `WidgetSettings` object which can be used
/// to setup a widget using `run_client_widget_api`
/// and to generate the correct url for the widget.
/// # Arguments
/// * - `props` A struct containing the configuration parameters for a element
///
/// # Arguments
///
/// * `props` - A struct containing the configuration parameters for a element
/// call widget.
#[uniffi::export]
#[matrix_sdk_ffi_macros::export]
pub fn new_virtual_element_call_widget(
props: VirtualElementCallWidgetOptions,
) -> Result<WidgetSettings, ParseError> {
@@ -259,31 +262,84 @@ pub fn new_virtual_element_call_widget(
/// Editing and extending the capabilities from this function is also possible,
/// but should only be done as temporal workarounds until this function is
/// adjusted
#[uniffi::export]
pub fn get_element_call_required_permissions() -> WidgetCapabilities {
#[matrix_sdk_ffi_macros::export]
pub fn get_element_call_required_permissions(
own_user_id: String,
own_device_id: String,
) -> WidgetCapabilities {
use ruma::events::StateEventType;
let read_send = vec![
// To read and send rageshake requests from other room members
WidgetEventFilter::MessageLikeWithType {
event_type: "org.matrix.rageshake_request".to_owned(),
},
// To read and send encryption keys
// TODO change this to the appropriate to-device version once ready
WidgetEventFilter::MessageLikeWithType {
event_type: "io.element.call.encryption_keys".to_owned(),
},
// To read and send custom EC reactions. They are different to normal `m.reaction`
// because they can be send multiple times to the same event.
WidgetEventFilter::MessageLikeWithType {
event_type: "io.element.call.reaction".to_owned(),
},
// This allows send raise hand reactions.
WidgetEventFilter::MessageLikeWithType {
event_type: MessageLikeEventType::Reaction.to_string(),
},
// This allows to detect if someone does not raise their hand anymore.
WidgetEventFilter::MessageLikeWithType {
event_type: MessageLikeEventType::RoomRedaction.to_string(),
},
];
WidgetCapabilities {
read: vec![
// To compute the current state of the matrixRTC session.
WidgetEventFilter::StateWithType { event_type: StateEventType::CallMember.to_string() },
// To detect leaving/kicked room members during a call.
WidgetEventFilter::StateWithType { event_type: StateEventType::RoomMember.to_string() },
WidgetEventFilter::MessageLikeWithType {
event_type: "org.matrix.rageshake_request".to_owned(),
// To decide whether to encrypt the call streams based on the room encryption setting.
WidgetEventFilter::StateWithType {
event_type: StateEventType::RoomEncryption.to_string(),
},
WidgetEventFilter::MessageLikeWithType {
event_type: "io.element.call.encryption_keys".to_owned(),
},
],
// This allows the widget to check the room version, so it can know about
// version-specific auth rules (namely MSC3779).
WidgetEventFilter::StateWithType { event_type: StateEventType::RoomCreate.to_string() },
]
.into_iter()
.chain(read_send.clone())
.collect(),
send: vec![
WidgetEventFilter::StateWithType { event_type: StateEventType::CallMember.to_string() },
WidgetEventFilter::StateWithType {
event_type: "org.matrix.rageshake_request".to_owned(),
// To send the call participation state event (main MatrixRTC event).
// This is required for legacy state events (using only one event for all devices with
// a membership array). TODO: remove once legacy call member events are
// sunset.
WidgetEventFilter::StateWithTypeAndStateKey {
event_type: StateEventType::CallMember.to_string(),
state_key: own_user_id.clone(),
},
WidgetEventFilter::StateWithType {
event_type: "io.element.call.encryption_keys".to_owned(),
// `delayed_event`` version for session memberhips
// [MSC3779](https://github.com/matrix-org/matrix-spec-proposals/pull/3779), with no leading underscore.
WidgetEventFilter::StateWithTypeAndStateKey {
event_type: StateEventType::CallMember.to_string(),
state_key: format!("{own_user_id}_{own_device_id}"),
},
],
// The same as above but with an underscore.
// To work around the issue that state events starting with `@` have to be matrix id's
// but we use mxId+deviceId.
WidgetEventFilter::StateWithTypeAndStateKey {
event_type: StateEventType::CallMember.to_string(),
state_key: format!("_{own_user_id}_{own_device_id}"),
},
]
.into_iter()
.chain(read_send)
.collect(),
requires_client: true,
update_delayed_event: true,
send_delayed_event: true,
}
}
@@ -313,7 +369,7 @@ impl From<ClientProperties> for matrix_sdk::widget::ClientProperties {
#[derive(uniffi::Object)]
pub struct WidgetDriverHandle(matrix_sdk::widget::WidgetDriverHandle);
#[uniffi::export(async_runtime = "tokio")]
#[matrix_sdk_ffi_macros::export]
impl WidgetDriverHandle {
/// Receive a message from the widget driver.
///
@@ -345,6 +401,10 @@ pub struct WidgetCapabilities {
/// This means clients should not offer to open the widget in a separate
/// browser/tab/webview that is not connected to the postmessage widget-api.
pub requires_client: bool,
/// This allows the widget to ask the client to update delayed events.
pub update_delayed_event: bool,
/// This allows the widget to send events with a delay.
pub send_delayed_event: bool,
}
impl From<WidgetCapabilities> for matrix_sdk::widget::Capabilities {
@@ -353,6 +413,8 @@ impl From<WidgetCapabilities> for matrix_sdk::widget::Capabilities {
read: value.read.into_iter().map(Into::into).collect(),
send: value.send.into_iter().map(Into::into).collect(),
requires_client: value.requires_client,
update_delayed_event: value.update_delayed_event,
send_delayed_event: value.send_delayed_event,
}
}
}
@@ -363,12 +425,14 @@ impl From<matrix_sdk::widget::Capabilities> for WidgetCapabilities {
read: value.read.into_iter().map(Into::into).collect(),
send: value.send.into_iter().map(Into::into).collect(),
requires_client: value.requires_client,
update_delayed_event: value.update_delayed_event,
send_delayed_event: value.send_delayed_event,
}
}
}
/// Different kinds of filters that could be applied to the timeline events.
#[derive(uniffi::Enum)]
#[derive(uniffi::Enum, Clone)]
pub enum WidgetEventFilter {
/// Matches message-like events with the given `type`.
MessageLikeWithType { event_type: String },
@@ -420,7 +484,7 @@ impl From<matrix_sdk::widget::EventFilter> for WidgetEventFilter {
}
}
#[uniffi::export(callback_interface)]
#[matrix_sdk_ffi_macros::export(callback_interface)]
pub trait WidgetCapabilitiesProvider: Send + Sync {
fn acquire_capabilities(&self, capabilities: WidgetCapabilities) -> WidgetCapabilities;
}
@@ -491,3 +555,54 @@ impl From<url::ParseError> for ParseError {
}
}
}
#[cfg(test)]
mod tests {
use matrix_sdk::widget::Capabilities;
use super::get_element_call_required_permissions;
#[test]
fn element_call_permissions_are_correct() {
let widget_cap = get_element_call_required_permissions(
"@my_user:my_domain.org".to_owned(),
"ABCDEFGHI".to_owned(),
);
// We test two things:
// Converting the WidgetCapability (ffi struct) to Capabilities (rust sdk
// struct)
let cap = Into::<Capabilities>::into(widget_cap);
// Converting Capabilities (rust sdk struct) to a json list.
let cap_json_repr = serde_json::to_string(&cap).unwrap();
// Converting to a Vec<String> allows to check if the required elements exist
// without breaking the test each time the order of permissions might
// change.
let permission_array: Vec<String> = serde_json::from_str(&cap_json_repr).unwrap();
let cap_assert = |capability: &str| {
assert!(
permission_array.contains(&capability.to_owned()),
"The \"{}\" capability was missing from the element call capability list.",
capability
);
};
cap_assert("io.element.requires_client");
cap_assert("org.matrix.msc4157.update_delayed_event");
cap_assert("org.matrix.msc4157.send.delayed_event");
cap_assert("org.matrix.msc2762.receive.state_event:org.matrix.msc3401.call.member");
cap_assert("org.matrix.msc2762.receive.state_event:m.room.member");
cap_assert("org.matrix.msc2762.receive.state_event:m.room.encryption");
cap_assert("org.matrix.msc2762.receive.event:org.matrix.rageshake_request");
cap_assert("org.matrix.msc2762.receive.event:io.element.call.encryption_keys");
cap_assert("org.matrix.msc2762.receive.state_event:m.room.create");
cap_assert("org.matrix.msc2762.send.state_event:org.matrix.msc3401.call.member#@my_user:my_domain.org");
cap_assert("org.matrix.msc2762.send.state_event:org.matrix.msc3401.call.member#@my_user:my_domain.org_ABCDEFGHI");
cap_assert("org.matrix.msc2762.send.state_event:org.matrix.msc3401.call.member#_@my_user:my_domain.org_ABCDEFGHI");
cap_assert("org.matrix.msc2762.send.event:org.matrix.rageshake_request");
cap_assert("org.matrix.msc2762.send.event:io.element.call.encryption_keys");
}
}
+2 -1
View File
@@ -1,3 +1,4 @@
[bindings.kotlin]
package_name = "org.matrix.rustcomponents.sdk"
cdylib_name = "matrix_sdk_ffi"
cdylib_name = "matrix_sdk_ffi"
android_cleaner = true
@@ -1,4 +1,4 @@
This models the room key sharing algorithm as a decision tree and provides
This models the room key forwarding algorithm as a decision tree and provides
tooling to render it as a PDF or PNG.
# Usage
@@ -1,5 +1,5 @@
digraph {
label="Matrix room key sharing algorithm"
label="Matrix room key forwarding algorithm"
fontname="Fira Sans"
ratio=0.5
@@ -16,10 +16,10 @@ digraph {
/* End states */
allow_verified [label="Share the entire session from the earliest known index.\n\nOk(None)", color=4, fillcolor=3]
allow_limited [label="Share a limited session starting from index i, which is the index we previously shared at.\n\nOk(Some(i))", color=4, fillcolor=3]
refuse_device_key_changed [label="Sender key changed, refuse to share.\n\nErr(KeyForwardDecision::ChangedSenderKey)", color=6, fillcolor=5]
refuse_not_shared [label="Session was never shared with this device, refuse to share.\n\nErr(KeyForwardDecision::OutboundSessionNotShared)", color=6, fillcolor=5]
refuse_untrusted_own_device [label="Our own device, but it is untrusted and we haven't previously shared with it. Refuse to share.\n\nErr(KeyForwardDecision::UntrustedDevice)", color=6, fillcolor=5]
refuse_missing_outbound_session [label="Not our device and haven't previously shared with it. Refuse to share.\n\nErr(KeyForwardDecision::MissingOutboundSession)", color=6, fillcolor=5]
refuse_device_key_changed [label="Sender key changed, refuse to forward.\n\nErr(KeyForwardDecision::ChangedSenderKey)", color=6, fillcolor=5]
refuse_not_shared [label="Session was never shared with this device, refuse to forward.\n\nErr(KeyForwardDecision::OutboundSessionNotShared)", color=6, fillcolor=5]
refuse_untrusted_own_device [label="Our own device, but it is untrusted and we haven't previously shared with it. Refuse to forward.\n\nErr(KeyForwardDecision::UntrustedDevice)", color=6, fillcolor=5]
refuse_missing_outbound_session [label="Not our device and haven't previously shared with it. Refuse to forward.\n\nErr(KeyForwardDecision::MissingOutboundSession)", color=6, fillcolor=5]
/* Checks */
Binary file not shown.

After

Width:  |  Height:  |  Size: 150 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 151 KiB

+100
View File
@@ -1,3 +1,103 @@
# Changelog
All notable changes to this project will be documented in this file.
<!-- next-header -->
## [Unreleased] - ReleaseDate
## [0.9.0] - 2024-12-18
### Features
- Introduced support for
[MSC4171](https://github.com/matrix-org/matrix-rust-sdk/pull/4335), enabling
the designation of certain users as service members. These flagged users are
excluded from the room display name calculation.
([#4335](https://github.com/matrix-org/matrix-rust-sdk/pull/4335))
### Bug Fixes
- Fix an off-by-one error in the `ObservableMap` when the `remove()` method is
called. Previously, items following the removed item were not shifted left by
one position, leaving them at incorrect indices.
([#4346](https://github.com/matrix-org/matrix-rust-sdk/pull/4346))
## [0.8.0] - 2024-11-19
### Bug Fixes
- Add more invalid characters for room aliases.
- Use the `DisplayName` struct to protect against homoglyph attacks.
### Features
- Add `BaseClient::room_key_recipient_strategy` field
- `AmbiguityCache` contains the room member's user ID.
- [**breaking**] `Media::get_thumbnail` and `MediaFormat::Thumbnail` allow to
request an animated thumbnail They both take a `MediaThumbnailSettings`
instead of `MediaThumbnailSize`.
- Consider knocked members to be part of the room for display name
disambiguation.
- `Client::cross_process_store_locks_holder_name` is used everywhere:
- `StoreConfig::new()` now takes a
`cross_process_store_locks_holder_name` argument.
- `StoreConfig` no longer implements `Default`.
- `BaseClient::new()` has been removed.
- `BaseClient::clone_with_in_memory_state_store()` now takes a
`cross_process_store_locks_holder_name` argument.
- `BaseClient` no longer implements `Default`.
- `EventCacheStoreLock::new()` no longer takes a `key` argument.
- `BuilderStoreConfig` no longer has
`cross_process_store_locks_holder_name` field for `Sqlite` and
`IndexedDb`.
- Make `ObservableMap::stream` works on `wasm32-unknown-unknown`.
- Allow aborting media uploads.
- Replace the `Notification` type from Ruma in `SyncResponse` and `StateChanges`
by a custom one.
- Introduce a `DisplayName` struct which normalizes and sanitizes
display names.
### Refactor
- [**breaking**] Rename `DisplayName` to `RoomDisplayName`.
- Rename `AmbiguityMap` to `DisplayNameUsers`.
- Move `event_cache_store/` to `event_cache/store/` in `matrix-sdk-base`.
- Move `linked_chunk` from `matrix-sdk` to `matrix-sdk-common`.
- Move `Event` and `Gap` into `matrix_sdk_base::event_cache`.
- The ambiguity maps in `SyncResponse` are moved to `JoinedRoom` and `LeftRoom`.
- `Store::get_rooms` and `Store::get_rooms_filtered` are way faster because they
don't acquire the lock for every room they read.
- `Store::get_rooms`, `Store::get_rooms_filtered` and `Store::get_room` are
renamed `Store::rooms`, `Store::rooms_filtered` and `Store::room`.
- [**breaking**] `Client::get_rooms` and `Client::get_rooms_filtered` are renamed
`Client::rooms` and `Client::rooms_filtered`.
- [**breaking**] `Client::get_stripped_rooms` has finally been removed.
- [**breaking**] The `StateStore` methods to access data in the media cache
where moved to a separate `EventCacheStore` trait.
- [**breaking**] The `instant` module was removed, use the `ruma::time` module instead.
# 0.7.0
- Rename `RoomType` to `RoomState`
+27 -7
View File
@@ -9,7 +9,7 @@ name = "matrix-sdk-base"
readme = "README.md"
repository = "https://github.com/matrix-org/matrix-rust-sdk"
rust-version = { workspace = true }
version = "0.7.0"
version = "0.9.0"
[package.metadata.docs.rs]
all-features = true
@@ -21,8 +21,19 @@ e2e-encryption = ["dep:matrix-sdk-crypto"]
js = ["matrix-sdk-common/js", "matrix-sdk-crypto?/js", "ruma/js", "matrix-sdk-store-encryption/js"]
qrcode = ["matrix-sdk-crypto?/qrcode"]
automatic-room-key-forwarding = ["matrix-sdk-crypto?/automatic-room-key-forwarding"]
message-ids = ["matrix-sdk-crypto?/message-ids"]
experimental-sliding-sync = ["ruma/unstable-msc3575"]
experimental-sliding-sync = [
"ruma/unstable-msc3575",
"ruma/unstable-msc4186",
]
uniffi = ["dep:uniffi", "matrix-sdk-crypto?/uniffi", "matrix-sdk-common/uniffi"]
# Private feature, see
# https://github.com/matrix-org/matrix-rust-sdk/pull/3749#issuecomment-2312939823 for the gory
# details.
test-send-sync = ["matrix-sdk-crypto?/test-send-sync"]
# "message-ids" feature doesn't do anything and is deprecated.
message-ids = []
# helpers for testing features build upon this
testing = [
@@ -38,22 +49,27 @@ as_variant = { workspace = true }
assert_matches = { workspace = true, optional = true }
assert_matches2 = { workspace = true, optional = true }
async-trait = { workspace = true }
bitflags = "2.1.0"
eyeball = { workspace = true }
bitflags = { version = "2.6.0", features = ["serde"] }
decancer = "3.2.8"
eyeball = { workspace = true, features = ["async-lock"] }
eyeball-im = { workspace = true }
futures-util = { workspace = true }
growable-bloom-filter = { workspace = true }
http = { workspace = true, optional = true }
matrix-sdk-common = { workspace = true }
matrix-sdk-crypto = { workspace = true, optional = true }
matrix-sdk-store-encryption = { workspace = true }
matrix-sdk-test = { workspace = true, optional = true }
once_cell = { workspace = true }
ruma = { workspace = true, features = ["canonical-json", "unstable-msc3381"] }
regex = "1.11.1"
ruma = { workspace = true, features = ["canonical-json", "unstable-msc3381", "unstable-msc2867", "rand"] }
unicode-normalization = { workspace = true }
serde = { workspace = true, features = ["rc"] }
serde_json = { workspace = true }
tokio = { workspace = true }
thiserror = { workspace = true }
tracing = { workspace = true }
uniffi = { workspace = true, optional = true }
[dev-dependencies]
assert_matches = { workspace = true }
@@ -63,9 +79,13 @@ futures-executor = { workspace = true }
http = { workspace = true }
matrix-sdk-test = { workspace = true }
stream_assert = { workspace = true }
similar-asserts = { workspace = true }
[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
tokio = { workspace = true, features = ["rt-multi-thread", "macros"] }
[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
wasm-bindgen-test = "0.3.33"
wasm-bindgen-test = { workspace = true }
[lints]
workspace = true
File diff suppressed because it is too large Load Diff
+19 -47
View File
@@ -14,13 +14,12 @@
//! Helpers for creating `std::fmt::Debug` implementations.
use std::{collections::BTreeMap, fmt};
use std::fmt;
pub use matrix_sdk_common::debug::*;
use ruma::{
api::client::{push::get_notifications::v3::Notification, sync::sync_events::v3::InvitedRoom},
api::client::sync::sync_events::v3::{InvitedRoom, KnockedRoom},
serde::Raw,
OwnedRoomId,
};
/// A wrapper around a slice of `Raw` events that implements `Debug` in a way
@@ -28,7 +27,7 @@ use ruma::{
pub struct DebugListOfRawEventsNoId<'a, T>(pub &'a [Raw<T>]);
#[cfg(not(tarpaulin_include))]
impl<'a, T> fmt::Debug for DebugListOfRawEventsNoId<'a, T> {
impl<T> fmt::Debug for DebugListOfRawEventsNoId<'_, T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut list = f.debug_list();
list.entries(self.0.iter().map(DebugRawEventNoId));
@@ -36,54 +35,13 @@ impl<'a, T> fmt::Debug for DebugListOfRawEventsNoId<'a, T> {
}
}
/// A wrapper around a notification map as found in `/sync` responses that
/// implements `Debug` in a way that only prints the event ID and event type
/// for the raw events contained in each notification.
pub struct DebugNotificationMap<'a>(pub &'a BTreeMap<OwnedRoomId, Vec<Notification>>);
#[cfg(not(tarpaulin_include))]
impl<'a> fmt::Debug for DebugNotificationMap<'a> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut map = f.debug_map();
map.entries(self.0.iter().map(|(room_id, raw)| (room_id, DebugNotificationList(raw))));
map.finish()
}
}
struct DebugNotificationList<'a>(&'a [Notification]);
#[cfg(not(tarpaulin_include))]
impl<'a> fmt::Debug for DebugNotificationList<'a> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut list = f.debug_list();
list.entries(self.0.iter().map(DebugNotification));
list.finish()
}
}
struct DebugNotification<'a>(&'a Notification);
#[cfg(not(tarpaulin_include))]
impl<'a> fmt::Debug for DebugNotification<'a> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Notification")
.field("actions", &self.0.actions)
.field("event", &DebugRawEvent(&self.0.event))
.field("profile_tag", &self.0.profile_tag)
.field("read", &self.0.read)
.field("room_id", &self.0.room_id)
.field("ts", &self.0.ts)
.finish()
}
}
/// A wrapper around an invited room as found in `/sync` responses that
/// implements `Debug` in a way that only prints the event ID and event type for
/// the raw events contained in `invite_state`.
pub struct DebugInvitedRoom<'a>(pub &'a InvitedRoom);
#[cfg(not(tarpaulin_include))]
impl<'a> fmt::Debug for DebugInvitedRoom<'a> {
impl fmt::Debug for DebugInvitedRoom<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("InvitedRoom")
.field("invite_state", &DebugListOfRawEvents(&self.0.invite_state.events))
@@ -91,10 +49,24 @@ impl<'a> fmt::Debug for DebugInvitedRoom<'a> {
}
}
/// A wrapper around a knocked on room as found in `/sync` responses that
/// implements `Debug` in a way that only prints the event ID and event type for
/// the raw events contained in `knock_state`.
pub struct DebugKnockedRoom<'a>(pub &'a KnockedRoom);
#[cfg(not(tarpaulin_include))]
impl fmt::Debug for DebugKnockedRoom<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("KnockedRoom")
.field("knock_state", &DebugListOfRawEvents(&self.0.knock_state.events))
.finish()
}
}
pub(crate) struct DebugListOfRawEvents<'a, T>(pub &'a [Raw<T>]);
#[cfg(not(tarpaulin_include))]
impl<'a, T> fmt::Debug for DebugListOfRawEvents<'a, T> {
impl<T> fmt::Debug for DebugListOfRawEvents<'_, T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut list = f.debug_list();
list.entries(self.0.iter().map(DebugRawEvent));
@@ -14,29 +14,35 @@
//! SDK-specific variations of response types from Ruma.
use std::{collections::BTreeMap, fmt};
use std::{collections::BTreeMap, fmt, hash::Hash, iter};
pub use matrix_sdk_common::deserialized_responses::*;
use once_cell::sync::Lazy;
use regex::Regex;
use ruma::{
events::{
room::{
member::{MembershipState, RoomMemberEvent, RoomMemberEventContent},
power_levels::{RoomPowerLevels, RoomPowerLevelsEventContent},
},
AnyStrippedStateEvent, AnySyncStateEvent, EventContentFromType,
AnyStrippedStateEvent, AnySyncStateEvent, AnySyncTimelineEvent, EventContentFromType,
PossiblyRedactedStateEventContent, RedactContent, RedactedStateEventContent,
StateEventContent, StaticStateEventContent, StrippedStateEvent, SyncStateEvent,
},
serde::Raw,
EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedRoomId, OwnedUserId, UserId,
EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedRoomId, OwnedUserId, UInt, UserId,
};
use serde::Serialize;
use unicode_normalization::UnicodeNormalization;
/// A change in ambiguity of room members that an `m.room.member` event
/// triggers.
#[derive(Clone, Debug, Default)]
#[derive(Clone, Debug)]
#[non_exhaustive]
pub struct AmbiguityChange {
/// The user ID of the member that is contained in the state key of the
/// `m.room.member` event.
pub member_id: OwnedUserId,
/// Is the member that is contained in the state key of the `m.room.member`
/// event itself ambiguous because of the event.
pub member_ambiguous: bool,
@@ -46,6 +52,15 @@ pub struct AmbiguityChange {
pub ambiguated_member: Option<OwnedUserId>,
}
impl AmbiguityChange {
/// Get an iterator over the user IDs listed in this `AmbiguityChange`.
pub fn user_ids(&self) -> impl Iterator<Item = &UserId> {
iter::once(&*self.member_id)
.chain(self.disambiguated_member.as_deref())
.chain(self.ambiguated_member.as_deref())
}
}
/// Collection of ambiguity changes that room member events trigger.
#[derive(Clone, Debug, Default)]
#[non_exhaustive]
@@ -55,6 +70,178 @@ pub struct AmbiguityChanges {
pub changes: BTreeMap<OwnedRoomId, BTreeMap<OwnedEventId, AmbiguityChange>>,
}
static MXID_REGEX: Lazy<Regex> = Lazy::new(|| {
Regex::new(DisplayName::MXID_PATTERN)
.expect("We should be able to create a regex from our static MXID pattern")
});
static LEFT_TO_RIGHT_REGEX: Lazy<Regex> = Lazy::new(|| {
Regex::new(DisplayName::LEFT_TO_RIGHT_PATTERN)
.expect("We should be able to create a regex from our static left-to-right pattern")
});
static HIDDEN_CHARACTERS_REGEX: Lazy<Regex> = Lazy::new(|| {
Regex::new(DisplayName::HIDDEN_CHARACTERS_PATTERN)
.expect("We should be able to create a regex from our static hidden characters pattern")
});
/// Regex to match `i` characters.
///
/// This is used to replace an `i` with a lowercase `l`, i.e. to mark "Hello"
/// and "HeIlo" as ambiguous. Decancer will lowercase an `I` for us.
static I_REGEX: Lazy<Regex> = Lazy::new(|| {
Regex::new("[i]").expect("We should be able to create a regex from our uppercase I pattern")
});
/// Regex to match `0` characters.
///
/// This is used to replace an `0` with a lowercase `o`, i.e. to mark "HellO"
/// and "Hell0" as ambiguous. Decancer will lowercase an `O` for us.
static ZERO_REGEX: Lazy<Regex> = Lazy::new(|| {
Regex::new("[0]").expect("We should be able to create a regex from our zero pattern")
});
/// Regex to match a couple of dot-like characters, also matches an actual dot.
///
/// This is used to replace a `.` with a `:`, i.e. to mark "@mxid.domain.tld" as
/// ambiguous.
static DOT_REGEX: Lazy<Regex> = Lazy::new(|| {
Regex::new("[.\u{1d16d}]").expect("We should be able to create a regex from our dot pattern")
});
/// A high-level wrapper for strings representing display names.
///
/// This wrapper provides attempts to determine whether a display name
/// contains characters that could make it ambiguous or easily confused
/// with similar names.
///
///
/// # Examples
///
/// ```
/// use matrix_sdk_base::deserialized_responses::DisplayName;
///
/// let display_name = DisplayName::new("𝒮𝒶𝒽𝒶𝓈𝓇𝒶𝒽𝓁𝒶");
///
/// // The normalized and sanitized string will be returned by DisplayName.as_normalized_str().
/// assert_eq!(display_name.as_normalized_str(), Some("sahasrahla"));
/// ```
///
/// ```
/// # use matrix_sdk_base::deserialized_responses::DisplayName;
/// let display_name = DisplayName::new("@alice:localhost");
///
/// // The display name looks like an MXID, which makes it ambiguous.
/// assert!(display_name.is_inherently_ambiguous());
/// ```
#[derive(Debug, Clone, Eq)]
pub struct DisplayName {
raw: String,
decancered: Option<String>,
}
impl Hash for DisplayName {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
if let Some(decancered) = &self.decancered {
decancered.hash(state);
} else {
self.raw.hash(state);
}
}
}
impl PartialEq for DisplayName {
fn eq(&self, other: &Self) -> bool {
match (self.decancered.as_deref(), other.decancered.as_deref()) {
(None, None) => self.raw == other.raw,
(None, Some(_)) | (Some(_), None) => false,
(Some(this), Some(other)) => this == other,
}
}
}
impl DisplayName {
/// Regex pattern matching an MXID.
const MXID_PATTERN: &'static str = "@.+[:.].+";
/// Regex pattern matching some left-to-right formatting marks:
/// * LTR and RTL marks U+200E and U+200F
/// * LTR/RTL and other directional formatting marks U+202A - U+202F
const LEFT_TO_RIGHT_PATTERN: &'static str = "[\u{202a}-\u{202f}\u{200e}\u{200f}]";
/// Regex pattern matching bunch of unicode control characters and otherwise
/// misleading/invisible characters.
///
/// This includes:
/// * various width spaces U+2000 - U+200D
/// * Combining characters U+0300 - U+036F
/// * Blank/invisible characters (U2800, U2062-U2063)
/// * Arabic Letter RTL mark U+061C
/// * Zero width no-break space (BOM) U+FEFF
const HIDDEN_CHARACTERS_PATTERN: &'static str =
"[\u{2000}-\u{200D}\u{300}-\u{036f}\u{2062}-\u{2063}\u{2800}\u{061c}\u{feff}]";
/// Creates a new [`DisplayName`] from the given raw string.
///
/// The raw display name is transformed into a Unicode-normalized form, with
/// common confusable characters removed to reduce ambiguity.
///
/// **Note**: If removing confusable characters fails,
/// [`DisplayName::is_inherently_ambiguous`] will return `true`, and
/// [`DisplayName::as_normalized_str()`] will return `None.
pub fn new(raw: &str) -> Self {
let normalized = raw.nfd().collect::<String>();
let replaced = DOT_REGEX.replace_all(&normalized, ":");
let replaced = HIDDEN_CHARACTERS_REGEX.replace_all(&replaced, "");
let decancered = decancer::cure!(&replaced).ok().map(|cured| {
let removed_left_to_right = LEFT_TO_RIGHT_REGEX.replace_all(cured.as_ref(), "");
let replaced = I_REGEX.replace_all(&removed_left_to_right, "l");
// We re-run the dot replacement because decancer normalized a lot of weird
// characets into a `.`, it just doesn't do that for /u{1d16d}.
let replaced = DOT_REGEX.replace_all(&replaced, ":");
let replaced = ZERO_REGEX.replace_all(&replaced, "o");
replaced.to_string()
});
Self { raw: raw.to_owned(), decancered }
}
/// Is this display name considered to be ambiguous?
///
/// If the display name has cancer (i.e. fails normalisation or has a
/// different normalised form) or looks like an MXID, then it's ambiguous.
pub fn is_inherently_ambiguous(&self) -> bool {
// If we look like an MXID or have hidden characters then we're ambiguous.
self.looks_like_an_mxid() || self.has_hidden_characters() || self.decancered.is_none()
}
/// Returns the underlying raw and and unsanitized string of this
/// [`DisplayName`].
pub fn as_raw_str(&self) -> &str {
&self.raw
}
/// Returns the underlying normalized and and sanitized string of this
/// [`DisplayName`].
///
/// Returns `None` if normalization failed during construction of this
/// [`DisplayName`].
pub fn as_normalized_str(&self) -> Option<&str> {
self.decancered.as_deref()
}
fn has_hidden_characters(&self) -> bool {
HIDDEN_CHARACTERS_REGEX.is_match(&self.raw)
}
fn looks_like_an_mxid(&self) -> bool {
self.decancered
.as_deref()
.map(|d| MXID_REGEX.is_match(d))
.unwrap_or_else(|| MXID_REGEX.is_match(&self.raw))
}
}
/// A deserialized response for the rooms members API call.
///
/// [`GET /_matrix/client/r0/rooms/{roomId}/members`](https://spec.matrix.org/v1.5/client-server-api/#get_matrixclientv3roomsroomidmembers)
@@ -66,6 +253,16 @@ pub struct MembersResponse {
pub ambiguity_changes: AmbiguityChanges,
}
/// Wrapper around both versions of any event received via sync.
#[derive(Clone, Debug, Serialize)]
#[serde(untagged)]
pub enum RawAnySyncOrStrippedTimelineEvent {
/// An event from a room in joined or left state.
Sync(Raw<AnySyncTimelineEvent>),
/// An event from a room in invited state.
Stripped(Raw<AnyStrippedStateEvent>),
}
/// Wrapper around both versions of any raw state event.
#[derive(Clone, Debug, Serialize)]
#[serde(untagged)]
@@ -272,10 +469,29 @@ impl MemberEvent {
///
/// It there is no `displayname` in the event's content, the localpart or
/// the user ID is returned.
pub fn display_name(&self) -> &str {
self.original_content()
.and_then(|c| c.displayname.as_deref())
.unwrap_or_else(|| self.user_id().localpart())
pub fn display_name(&self) -> DisplayName {
DisplayName::new(
self.original_content()
.and_then(|c| c.displayname.as_deref())
.unwrap_or_else(|| self.user_id().localpart()),
)
}
/// The optional reason why the membership changed.
pub fn reason(&self) -> Option<&str> {
match self {
MemberEvent::Sync(SyncStateEvent::Original(c)) => c.content.reason.as_deref(),
MemberEvent::Stripped(e) => e.content.reason.as_deref(),
_ => None,
}
}
/// The optional timestamp for this member event.
pub fn timestamp(&self) -> Option<UInt> {
match self {
MemberEvent::Sync(SyncStateEvent::Original(c)) => Some(c.origin_server_ts.0),
_ => None,
}
}
}
@@ -288,3 +504,240 @@ impl SyncOrStrippedState<RoomPowerLevelsEventContent> {
}
}
}
#[cfg(test)]
mod test {
macro_rules! assert_display_name_eq {
($left:expr, $right:expr $(, $desc:expr)?) => {{
let left = crate::deserialized_responses::DisplayName::new($left);
let right = crate::deserialized_responses::DisplayName::new($right);
similar_asserts::assert_eq!(
left,
right
$(, $desc)?
);
}};
}
macro_rules! assert_display_name_ne {
($left:expr, $right:expr $(, $desc:expr)?) => {{
let left = crate::deserialized_responses::DisplayName::new($left);
let right = crate::deserialized_responses::DisplayName::new($right);
assert_ne!(
left,
right
$(, $desc)?
);
}};
}
macro_rules! assert_ambiguous {
($name:expr) => {
let name = crate::deserialized_responses::DisplayName::new($name);
assert!(
name.is_inherently_ambiguous(),
"The display {:?} should be considered amgibuous",
name
);
};
}
macro_rules! assert_not_ambiguous {
($name:expr) => {
let name = crate::deserialized_responses::DisplayName::new($name);
assert!(
!name.is_inherently_ambiguous(),
"The display {:?} should not be considered amgibuous",
name
);
};
}
#[test]
fn test_display_name_inherently_ambiguous() {
// These should not be inherently ambiguous, only if another similarly looking
// display name appears should they be considered to be ambiguous.
assert_not_ambiguous!("Alice");
assert_not_ambiguous!("Carol");
assert_not_ambiguous!("Car0l");
assert_not_ambiguous!("Ivan");
assert_not_ambiguous!("𝒮𝒶𝒽𝒶𝓈𝓇𝒶𝒽𝓁𝒶");
assert_not_ambiguous!("Ⓢⓐⓗⓐⓢⓡⓐⓗⓛⓐ");
assert_not_ambiguous!("🅂🄰🄷🄰🅂🅁🄰🄷🄻🄰");
assert_not_ambiguous!("Sahasrahla");
// Left to right is fine, if it's the only one in the room.
assert_not_ambiguous!("\u{202e}alharsahas");
// These on the other hand contain invisible chars.
assert_ambiguous!("Sa̴hasrahla");
assert_ambiguous!("Sahas\u{200D}rahla");
}
#[test]
fn test_display_name_equality_capitalization() {
// Display name with different capitalization
assert_display_name_eq!("Alice", "alice");
}
#[test]
fn test_display_name_equality_different_names() {
// Different display names
assert_display_name_ne!("Alice", "Carol");
}
#[test]
fn test_display_name_equality_capital_l() {
// Different display names
assert_display_name_eq!("Hello", "HeIlo");
}
#[test]
fn test_display_name_equality_confusable_zero() {
// Different display names
assert_display_name_eq!("Carol", "Car0l");
}
#[test]
fn test_display_name_equality_cyrilic() {
// Display name with scritpure symbols
assert_display_name_eq!("alice", "аlice");
}
#[test]
fn test_display_name_equality_scriptures() {
// Display name with scritpure symbols
assert_display_name_eq!("Sahasrahla", "𝒮𝒶𝒽𝒶𝓈𝓇𝒶𝒽𝓁𝒶");
}
#[test]
fn test_display_name_equality_frakturs() {
// Display name with fraktur symbols
assert_display_name_eq!("Sahasrahla", "𝔖𝔞𝔥𝔞𝔰𝔯𝔞𝔥𝔩𝔞");
}
#[test]
fn test_display_name_equality_circled() {
// Display name with circled symbols
assert_display_name_eq!("Sahasrahla", "Ⓢⓐⓗⓐⓢⓡⓐⓗⓛⓐ");
}
#[test]
fn test_display_name_equality_squared() {
// Display name with squared symbols
assert_display_name_eq!("Sahasrahla", "🅂🄰🄷🄰🅂🅁🄰🄷🄻🄰");
}
#[test]
fn test_display_name_equality_big_unicode() {
// Display name with big unicode letters
assert_display_name_eq!("Sahasrahla", "Sahasrahla");
}
#[test]
fn test_display_name_equality_left_to_right() {
// Display name with a left-to-right character
assert_display_name_eq!("Sahasrahla", "\u{202e}alharsahas");
}
#[test]
fn test_display_name_equality_diacritical() {
// Display name with a diacritical mark.
assert_display_name_eq!("Sahasrahla", "Sa̴hasrahla");
}
#[test]
fn test_display_name_equality_zero_width_joiner() {
// Display name with a zero-width joiner
assert_display_name_eq!("Sahasrahla", "Sahas\u{200B}rahla");
}
#[test]
fn test_display_name_equality_zero_width_space() {
// Display name with zero-width space.
assert_display_name_eq!("Sahasrahla", "Sahas\u{200D}rahla");
}
#[test]
fn test_display_name_equality_ligatures() {
// Display name with a ligature.
assert_display_name_eq!("ff", "\u{FB00}");
}
#[test]
fn test_display_name_confusable_mxid_colon() {
assert_display_name_eq!("@mxid:domain.tld", "@mxid\u{0589}domain.tld");
assert_display_name_eq!("@mxid:domain.tld", "@mxid\u{05c3}domain.tld");
assert_display_name_eq!("@mxid:domain.tld", "@mxid\u{0703}domain.tld");
assert_display_name_eq!("@mxid:domain.tld", "@mxid\u{0a83}domain.tld");
assert_display_name_eq!("@mxid:domain.tld", "@mxid\u{16ec}domain.tld");
assert_display_name_eq!("@mxid:domain.tld", "@mxid\u{205a}domain.tld");
assert_display_name_eq!("@mxid:domain.tld", "@mxid\u{2236}domain.tld");
assert_display_name_eq!("@mxid:domain.tld", "@mxid\u{fe13}domain.tld");
assert_display_name_eq!("@mxid:domain.tld", "@mxid\u{fe52}domain.tld");
assert_display_name_eq!("@mxid:domain.tld", "@mxid\u{fe30}domain.tld");
assert_display_name_eq!("@mxid:domain.tld", "@mxid\u{ff1a}domain.tld");
// Additionally these should be considered to be ambiguous on their own.
assert_ambiguous!("@mxid\u{0589}domain.tld");
assert_ambiguous!("@mxid\u{05c3}domain.tld");
assert_ambiguous!("@mxid\u{0703}domain.tld");
assert_ambiguous!("@mxid\u{0a83}domain.tld");
assert_ambiguous!("@mxid\u{16ec}domain.tld");
assert_ambiguous!("@mxid\u{205a}domain.tld");
assert_ambiguous!("@mxid\u{2236}domain.tld");
assert_ambiguous!("@mxid\u{fe13}domain.tld");
assert_ambiguous!("@mxid\u{fe52}domain.tld");
assert_ambiguous!("@mxid\u{fe30}domain.tld");
assert_ambiguous!("@mxid\u{ff1a}domain.tld");
}
#[test]
fn test_display_name_confusable_mxid_dot() {
assert_display_name_eq!("@mxid:domain.tld", "@mxid:domain\u{0701}tld");
assert_display_name_eq!("@mxid:domain.tld", "@mxid:domain\u{0702}tld");
assert_display_name_eq!("@mxid:domain.tld", "@mxid:domain\u{2024}tld");
assert_display_name_eq!("@mxid:domain.tld", "@mxid:domain\u{fe52}tld");
assert_display_name_eq!("@mxid:domain.tld", "@mxid:domain\u{ff0e}tld");
assert_display_name_eq!("@mxid:domain.tld", "@mxid:domain\u{1d16d}tld");
// Additionally these should be considered to be ambiguous on their own.
assert_ambiguous!("@mxid:domain\u{0701}tld");
assert_ambiguous!("@mxid:domain\u{0702}tld");
assert_ambiguous!("@mxid:domain\u{2024}tld");
assert_ambiguous!("@mxid:domain\u{fe52}tld");
assert_ambiguous!("@mxid:domain\u{ff0e}tld");
assert_ambiguous!("@mxid:domain\u{1d16d}tld");
}
#[test]
fn test_display_name_confusable_mxid_replacing_a() {
assert_display_name_eq!("@mxid:domain.tld", "@mxid:dom\u{1d44e}in.tld");
assert_display_name_eq!("@mxid:domain.tld", "@mxid:dom\u{0430}in.tld");
// Additionally these should be considered to be ambiguous on their own.
assert_ambiguous!("@mxid:dom\u{1d44e}in.tld");
assert_ambiguous!("@mxid:dom\u{0430}in.tld");
}
#[test]
fn test_display_name_confusable_mxid_replacing_l() {
assert_display_name_eq!("@mxid:domain.tld", "@mxid:domain.tId");
assert_display_name_eq!("mxid:domain.tld", "mxid:domain.t\u{217c}d");
assert_display_name_eq!("mxid:domain.tld", "mxid:domain.t\u{ff4c}d");
assert_display_name_eq!("mxid:domain.tld", "mxid:domain.t\u{1d5f9}d");
assert_display_name_eq!("mxid:domain.tld", "mxid:domain.t\u{1d695}d");
assert_display_name_eq!("mxid:domain.tld", "mxid:domain.t\u{2223}d");
// Additionally these should be considered to be ambiguous on their own.
assert_ambiguous!("@mxid:domain.tId");
assert_ambiguous!("@mxid:domain.t\u{217c}d");
assert_ambiguous!("@mxid:domain.t\u{ff4c}d");
assert_ambiguous!("@mxid:domain.t\u{1d5f9}d");
assert_ambiguous!("@mxid:domain.t\u{1d695}d");
assert_ambiguous!("@mxid:domain.t\u{2223}d");
}
}

Some files were not shown because too many files have changed in this diff Show More