Compare commits

..

7353 Commits

Author SHA1 Message Date
Damir Jelić 4c46e42201 chore: Release matrix-sdk version 0.10.0 2025-02-04 16:32:55 +01:00
Damir Jelić 0d4bc65e28 chore: Enable releases for the test crates 2025-02-04 16:32:55 +01:00
Jorge Martín 5e1bae02fe feat(ffi): Add RoomPreview::forget action in the FFI layer 2025-02-04 16:26:15 +01:00
Ivan Enderlin 77a67de7df fix(ui): Fix performance of ReadReceiptTimelineUpdate::apply.
This patch improves the performance of
`ReadReceiptTimelineUpdate::apply`, which does 2 things: it calls
`remove_old_receipt` and `add_new_receipt`. Both of them need an
timeline item position. Until this patch, `rfind_event_by_id` was used
and was the bottleneck. The improvement is twofold as is as follows.

First off, when collecting data to create `ReadReceiptTimelineUpdate`,
the timeline item position can be known ahead of time by using
`EventMeta::timeline_item_index`. This data is not always available, for
example if the timeline item isn't created yet. But let's try to collect
these data if there are some.

Second, inside `ReadReceiptTimelineUpdate::remove_old_receipt`, we use
the timeline item position collected from `EventMeta` if it exists.
Otherwise, let's fallback to a similar `rfind_event_by_id` pattern,
without using intermediate types. It's more straightforward here: we
don't need an `EventTimelineItemWithId`, we only need the position.
Once the position is known, it is stored in `Self` (!), this is the
biggest improvement here. Le't see why.

Finally, inside `ReadReceiptTimelineUpdate::add_new_receipt`, we use
the timeline item position collected from `EventMeta` if it exists,
similarly to what `remove_old_receipt` does. Otherwise, let's fallback
to an iterator to find the position. However, instead of iterating over
**all** items, we can skip the first ones, up to the position of the
timeline item holding the old receipt, so up to the position found by
`remove_old_receipt`.

I'm testing this patch with the `test_lazy_back_pagination` test in
https://github.com/matrix-org/matrix-rust-sdk/pull/4594. With 10_000
events in the sync, the `ReadReceipts::maybe_update_read_receipt` method
was taking 52% of the whole execution time. With this patch, it takes
8.1%.
2025-02-04 16:02:29 +01:00
JoFrost f27eb4d1c8 fix[oidc]: fix docstring in oidc module 2025-02-04 15:33:28 +01:00
Jorge Martín 05814c5559 refactor(ffi): Map client API errors to ClientError::MatrixApi, containing the error kind, their error code and the associated message 2025-02-04 12:25:51 +01:00
Kévin Commaille d5d9898fb4 feat: Upgrade Ruma to 0.12.1
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-02-04 12:00:40 +01:00
Ivan Enderlin 3f71d9a379 fix(sdk): Improve performance of RoomEvents::maybe_apply_new_redaction.
This patch improves the performance of
`RoomEvents::maybe_apply_new_redaction`. This method deserialises
all the events it receives, entirely. If the event is not an
`m.room.redaction`, then the method returns early. Most of the time,
the event is deserialised for nothing because most events aren't of kind
`m.room.redaction`!

This patch first uses `Raw::get_field("type")` to detect the type of
the event. If it's a `m.room.redaction`, then the event is entirely
deserialized, otherwise the method returns.

When running the `test_lazy_back_pagination` from
https://github.com/matrix-org/matrix-rust-sdk/pull/4594 with 10'000
events, prior to this patch, this method takes 11% of the execution
time. With this patch, this method takes 2.5%.
2025-02-04 09:49:58 +01:00
Jorge Martín b077f45e78 test(room_preview): Add tests for where get_room_preview gets its data from for each room state 2025-02-04 09:33:31 +01:00
Jorge Martín 648d527f2f fix(room_preview): Return room preview info based on local data for banned rooms too
Any remote endpoint would just return a `403` status code so we have no other choice than trusting the local room info we already have.
2025-02-04 09:33:31 +01:00
Jorge Martín 8513547e92 feat(ffi): Add FFI bindings for Room::forget.
Also make sure rooms the user has been banned from can also be forgotten, not only left ones.
2025-02-03 19:48:27 +01:00
dependabot[bot] d18669e8d9 chore(deps): bump crate-ci/typos from 1.29.4 to 1.29.5
Bumps [crate-ci/typos](https://github.com/crate-ci/typos) from 1.29.4 to 1.29.5.
- [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.29.4...v1.29.5)

---
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>
2025-02-03 16:52:27 +01:00
Benjamin Bouvier a0426251a3 test(timeline): test that editing a replied-to doesn't lose the latest edit JSON 2025-02-03 16:52:12 +01:00
Benjamin Bouvier 2739c5bf27 test(timeline): test that adding a response or ending a poll doesn't clear the latest edit JSON 2025-02-03 16:52:12 +01:00
Benjamin Bouvier 381f4d419f fix(timeline): don't clear the latest_edit_json under certain conditions 2025-02-03 16:52:12 +01:00
Ivan Enderlin 9ab5547065 fix(ui): Fix performance of AllRemoteEvents::(in|de)crement_all_timeline_item_index_after.
This patch fixes the performance of
`AllRemoteEvents::increment_all_timeline_item_index_after` and
`decrment_all_timeline_item_index_after`.

It appears that the code was previously iterating over all items. This
is a waste of time. This patch updates the code to iterate over all
items in reverse order:

- if `new_timeline_item_index` is 0, we need to shift all items anyways,
  so all items must be traversed, the iterator direction doesn't matter,
- otherwise, it's unlikely we want to traverse all items: the item has
  been either inserted or pushed back, so there is no need to traverse
  the first items; we can also break the iteration as soon as all
  timeline item index after `new_timeline_item_index` has been updated.

I'm testing this patch with the `test_lazy_back_pagination` test in
https://github.com/matrix-org/matrix-rust-sdk/pull/4594. With 10_000
events in the sync, the `ObservableItems::push_back` method (that uses
`AllRemoteEvents::increment_all_timeline_item_index_after`) was taking
7% of the whole execution time. With this patch, it takes 0.7%.
2025-02-03 11:25:48 +01:00
Kévin Commaille df3cb002a5 chore: Add changelog entries
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-02-03 11:22:23 +01:00
Kévin Commaille 6ebd4295b9 feat(sqlite): Limit size of WAL file
The WAL file can grow depending on the transactions that are run. A
critical case is VACUUM which basically writes the content of the DB
file to the WAL file before writing it back to the DB file.

SQLite doesn't try to reduce the size of the file after that unless we
set an explicit limit,
so we could end up taking twice the size of the database on the
filesystem.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-02-03 11:22:23 +01:00
Kévin Commaille c5104d68fd feat(sqlite): Run PRAGMA optimize regularly
As recommended by the SQLite docs.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-02-03 11:22:23 +01:00
Kévin Commaille 0064839283 fix(sqlite): Vaccum the SqliteStateStore
It should have been done in the migration of version 7, to reduce the
size of the database on the filesystem after the media cache was moved
to the SqliteEventCacheStore. Better late than never.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-02-03 11:22:23 +01:00
Kévin Commaille 2727d72916 fix(timeline): Do not filter out own receipts in load_read_receipts_for_event
Fixes #4517.

It turns out that the bugs found in that test were due to 2 causes:

- First commit: `TestRoomDataProvider` didn't use `initial_user_receipts` but returned hardcoded values.
- Second commit: Our own read receipts were ignored in `TimelineStateTransaction::load_read_receipts_for_event`, although we need to process all read receipts via `ReadReceipts::maybe_update_read_receipt` because it knows how to filter out our own read receipts were needed.
2025-02-03 10:15:25 +00:00
Ivan Enderlin 33a2cc3031 chore(cargo): Bump the minimum stable rust version (MSRV). 2025-02-03 10:27:45 +01:00
Ivan Enderlin 38097f90b2 fix(ui): Fix performance of TimelineEventHandler::deduplicate_local_timeline_item.
This patch drastically improves the performance of
`TimelineEventHandler::deduplicate_local_timeline_item`.

Before this patch, `rfind_event_item` was used to iterate over all
timeline items: for each item in reverse order, if it was an event
timeline item, and if it was a local event timeline item, and if it was
matching the event ID or transaction ID, then a duplicate was found.

The problem is the following: all items are traversed.

However, local event timeline items are always at the back of the items.
Even virtual timeline items are before local event timeline items. Thus,
it is not necessary to traverse all items. It is possible to stop the
iteration as soon as (i) a non event timeline item is met, or (ii) a non
local event timeline item is met.

This patch updates
`TimelineEventHandler::deduplicate_local_timeline_item` to replace to
use of `rfind_event_item` by a custom iterator that stops as soon as a
non event timeline item, or a non local event timeline item, is met, or
—of course— when a local event timeline item is a duplicate.

To do so, [`Iterator::try_fold`] is probably the best companion.
[`Iterator::try_find`] would have been nice, but it is available on
nightlies, not on stable versions of Rust. However, many methods in
`Iterator` are using `try_fold`, like `find` or any other methods that
need to do a “short-circuit”. Anyway, `try_fold` works pretty nice here,
and does exactly what we need.

Our use of `try_fold` is to return a `ControlFlow<Option<(usize,
TimelineItem)>, ()>`. After `try_fold`, we call
`ControlFlow::break_value`, which returns an `Option`. Hence the need
to call `Option::flatten` at the end to get a single `Option` instead of
having an `Option<Option<(usize, TimelineItem)>>`.

I'm testing this patch with the `test_lazy_back_pagination` test in
https://github.com/matrix-org/matrix-rust-sdk/pull/4594. With 10_000
events in the sync, the test was taking 13s to run on my machine. With
this patch, it takes 10s to run. It's a 23% improvement. This
`deduplicate_local_timeline_item` method was taking a large part of the
computation according to the profiler. With this patch, this method is
barely visible in the profiler it is so small.

[`Iterator::try_fold`]: https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.try_fold
[`Iterator::try_find`]: https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.try_find
2025-02-03 10:27:45 +01:00
Ivan Enderlin 47d08683a2 fix(security): Update OpenSSL.
See this note https://rustsec.org/advisories/RUSTSEC-2025-0004.

This patch updates OpenSSL to 0.10.70.
2025-02-03 09:42:58 +01:00
Damir Jelić 57919f5480 chore: Bump most of our deps 2025-01-31 17:14:37 +01:00
Damir Jelić b8949cfe26 chore: Bump vodozemac 2025-01-31 17:14:37 +01:00
Damir Jelić 8d27b0c811 test: Simplify some tests using the assert_next_with_timeout macro 2025-01-31 14:15:18 +01:00
Damir Jelić 3707d2fb81 test: Make the timeout parameter in the assert_next_with_timeout macro optional 2025-01-31 14:15:18 +01:00
Damir Jelić eaaa5e17a0 chore: Fix a doc example in the MatrixMockServer 2025-01-31 14:15:18 +01:00
Ivan Enderlin e3958b754c chore(crypto-ffi): Done is a unit type, no need for { .. }. 2025-01-31 14:07:43 +01:00
Ivan Enderlin 78d9e1292f chore(sdk): Do not iterate over the entire iterator when we can reach back.
This patch uses `next_back()` instead of `last()`, which is equivalent
but `last()` requires to iterate over the entire iterator, while
`next_back()` is a single operation.
2025-01-31 14:07:43 +01:00
Ivan Enderlin d594b4dad7 chore(sdk): Remove a useless type conversion.
This patch removes a useless type conversion. The `Room::event()` method
returns a `TimelineEvent`, so calling `Into::into` is useless: we map
`TimelineEvent` to `TimelineEvent`.
2025-01-31 14:07:43 +01:00
Ivan Enderlin 3f40ad83a5 chore(sdk): Remove a useless type conversion.
This patch removes a useless type conversion. The iterator produces
`TimelineEvent`, so mapping to `TimelineEvent::from` is useless: we map
`TimelineEvent` to `TimelineEvent`.
2025-01-31 14:07:43 +01:00
Ivan Enderlin 5049d1a3b6 chore(sqlite): Use repeat_n(…, n) instead of repeat(…).take(n).
Thanks Clippy!
2025-01-31 14:07:43 +01:00
Damir Jelić 29862fc9bd refactor: Add the assert_next_eq_with_timeout test helper
This test helper is the same as the assert_next_eq helper, but it waits
for the stream to be ready for a certain amount of time instead of
expecting it to be ready right away.
2025-01-31 09:58:55 +01:00
Damir Jelić 585224b2fa chore(ui): Replace the unit type with an empty block 2025-01-31 09:58:55 +01:00
Damir Jelić 0dc5e69ace fix: Retry the sync even in case of network errors 2025-01-31 09:58:55 +01:00
Damir Jelić b323802ab0 fix(ui): Enable retries for network failures of the /versions check in the SyncService 2025-01-31 09:58:55 +01:00
Damir Jelić 252786d2ef refactor(ui): Make SyncService::stop infallible
The `SyncService::stop()` method could fail for the following reasons:

1. The supervisor was not properly started up, this is a programmer error.
2. The supervisor task wouldn't shut down and instead it returns a JoinError.
3. We couldn't notify the supervisor task that it should shutdown due the channel being closed.

All of those cases shouldn't ever happen and the supervisor task will be
stopped in all of them.

1. Since there is no supervisor to be stopped, we can safely just log an
   error, our tests ensure that a `SyncService::start()` does create a
   supervisor.

2. A JoinError can be returned if the task has been cancelled or if the
   supervisor task has panicked. Since we never cancel the task, nor
   have any panics in the supervisor task, we can assume that this won't
   happen.

3. The supervisor task holds on to a reference to the receiving end of
   the channel, as long as the task is alive the channel can not be
   closed.

In conclusion, it doesn't seem to be useful to forward these error cases
to the user.
2025-01-31 09:58:55 +01:00
Damir Jelić 97cbe57d3f docs: Document the offline mode for the SyncService 2025-01-31 09:58:55 +01:00
Damir Jelić 0d8ad159c3 test(ui): Write tests for the SyncService offline mode 2025-01-31 09:58:55 +01:00
Damir Jelić 9d732395ce feat(ui): Introduce a "offline" mode for the SyncService 2025-01-31 09:58:55 +01:00
Damir Jelić 6a772d1c56 test: Add a method to mock the /versions endpoint to the MatrixMockServer 2025-01-31 09:58:55 +01:00
Damir Jelić b71499ffe6 refactor(ui): Move the start/stop implementations under the inner SyncService
This will allow us to more easily implement a restart method.
2025-01-31 09:58:55 +01:00
Damir Jelić 4dadf8581a refactor(ui): Move the creation of the child tasks in the SyncService around
This patch moves the creations of the child tasks of the SyncService
into the supervisor tasks itself. This should make it easier to let the
supervisor recreate tasks.

This will become useful once we introduce a offline mode where the
supervisor task becomes responsible to restart syncing once we notice
that the server is back online.
2025-01-31 09:58:55 +01:00
Benjamin Bouvier 4d4cd61363 chore: update copyright years for files newly introduced 2025-01-31 08:50:41 +01:00
Richard van der Hoff 6f42b0a67b crypto: withhold outgoing messages to unsigned dehydrated devices
Per https://github.com/matrix-org/matrix-rust-sdk/issues/4313, we should not
send outgoing messages to dehydrated devices that are not signed by the current
pinned/verified identity.
2025-01-29 17:37:36 +00:00
Richard van der Hoff e3b348761e test: test helpers in share_strategy tests
Split the existing `set_up_test_machine` into two parts, so we can set up
the test OlmMachine without importing data for other users
2025-01-29 17:37:36 +00:00
Ivan Enderlin d755a8a3aa chore(ui): Move EventMeta inside the metadata module.
This patch moves the `EventMeta` type from `state.rs` to `metadata.rs`.
2025-01-29 11:44:27 +01:00
Ivan Enderlin 66e3ddec47 chore(ui): Move TimelineMetadata into its own module.
This patch moves `TimelineMetadata`, its implementation and companion
types (like `RelativePosition`) into its own module. The idea is to
reduce the size of the `state.rs` module.
2025-01-29 11:44:27 +01:00
Ivan Enderlin 720d443452 chore(ui): Move TimelineStateTransaction into its own module.
This patch moves `TimelineStateTransaction` and its implementation into
its own module. The idea is to reduce the size of the `state.rs` module.
2025-01-29 11:44:27 +01:00
Ivan Enderlin 33d691a58e Merge pull request #4571 from zecakeh/media-retention-policy
feat: Add MediaRetentionPolicy to the EventCacheStore, take 2
2025-01-28 17:27:02 +01:00
Kévin Commaille c2f39c1086 Merge branch 'main' into media-retention-policy 2025-01-28 16:53:52 +01:00
Kévin Commaille df9c355aed Merge branch 'main' into media-retention-policy
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-01-28 15:46:55 +01:00
Kévin Commaille 0334ff3f64 chore(sdk): Add changelog entry for MediaRetentionPolicy
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-01-28 15:44:44 +01:00
Kévin Commaille 8262726369 chore(sqlite): Add changelog entry for EventCacheStore changes
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-01-28 15:44:44 +01:00
Kévin Commaille a4a6bf540d chore(base): Add changelog entry for MediaRetentionPolicy and associated changes
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-01-28 15:44:44 +01:00
Kévin Commaille 9b38f38aea fix(base): Organize changelog the same way as other crates
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-01-28 15:44:44 +01:00
Kévin Commaille 2e05cc74bf feat(sdk): Add methods to Media to interact with MediaRetentionPolicy
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-01-28 15:44:44 +01:00
Kévin Commaille eb9b86971a feat(base): Add methods for MediaRetentionPolicy to EventCacheStore
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-01-28 15:44:42 +01:00
Ivan Enderlin 31e7ec182c chore(ui): Remove TimelineNewItemPosition.
This patch removes the `TimelineNewItemPosition` type a sit is no longer
used.
2025-01-28 15:43:06 +01:00
Ivan Enderlin 5e8f3b2bc8 chore(ui): Remove HandleManyEventsResult.
This patch removes the `HandleManyEventsResult` type as it is no longer
used.
2025-01-28 15:43:06 +01:00
Ivan Enderlin c0b91c4b0e chore(ui): Remove TimelineState(Transaction)::add_remote_events_at.
This patch removes `TimelineState::add_remote_events_at` and
`TimelineStateTransaction::add_remote_events_at` as they are no longer
used.
2025-01-28 15:43:06 +01:00
Ivan Enderlin 46d90afa9c refactor(ui): Use handle_remote_events_with_diffs instead of add_remote_events.
This patch replaces a call to `add_remote_events` by
`handle_remote_events_with_diffs`.

The idea is to remove all calls to `add_remote_events`.
2025-01-28 15:43:06 +01:00
Ivan Enderlin 29e19b729b chore(ui): Remove TimelineController::add_events_at.
This patch removes `TimelineController::add_events_at` since it's a
non-public method and it's unused.
2025-01-28 15:43:06 +01:00
Ivan Enderlin 20c1eff391 refactor(ui): The Timeline no longer use add_events_at.
This patch replaces all uses of `TimelineController::add_events_at` by
`TimelineController::handle_remote_events_with_diffs` in the `Timeline`
itself.

The idea is to remove `add_events_at`, as we currently have 2 ways to
add or to handle remote events in the `Timeline`. We want a single one,
because it's simpler!
2025-01-28 15:43:06 +01:00
Ivan Enderlin 3e40db3d7f test(ui): Tests no longer use add_events_at.
This patch replaces all uses of `TimelineController::add_events_at` by
`TimelineController::handle_remote_events_with_diffs` in the tests.

The idea is to remove `add_events_at`, as we currently have 2 ways to
add or to handle remote events in the `Timeline`. We want a single one,
because it's simpler!
2025-01-28 15:43:06 +01:00
Kévin Commaille 8ca5983093 feat(sqlite): Implement EventCacheStoreMedia for SqliteEventCacheStore
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-01-28 15:38:18 +01:00
Kévin Commaille 144f568a5c feat(base): Implement EventCacheStoreMedia for MemoryStore
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-01-28 15:37:30 +01:00
Kévin Commaille 34c7dd48ae refactor(base): Use struct for media content in the MemoryStore
It is already a 3-tuple and we want to add more data so it will be clearer to use a stuct with named fields.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-01-28 15:36:16 +01:00
Kévin Commaille 6c7d8c16bb feat(base): Add macro for integration tests of EventCacheStoreMedia
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-01-28 15:36:16 +01:00
Kévin Commaille 2c930df8aa feat(base): Add MediaService
This is an API to handle the MediaRetentionPolicy with a lower level
EventCacheStoreMedia trait.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-01-28 15:36:06 +01:00
Kévin Commaille 834bed2b1a feat(base): Add MediaRetentionPolicy
This will be used as a configuration to decide whether or not to keep
media in the cache, allowing to do periodic cleanups to avoid to have
the size of the media cache grow indefinitely.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-01-28 15:35:26 +01:00
Valere 8d530ef220 Merge pull request #4558 from matrix-org/valere/memory_store_consistent_with_other_stores
refactor(crypto): Make memory store behave more like other stores
2025-01-28 15:27:03 +01:00
Valere 542d68dcda fix(test): Properly set up test crypto memory store by saving own device 2025-01-28 15:02:30 +01:00
Valere 50696a0d74 refact(mem_store) Add a global save change lock similar to other stores 2025-01-28 15:02:30 +01:00
Valere 182fc6fd8f refact(mem_store): Ser/Deser inbound group sessions 2025-01-28 15:02:30 +01:00
Valere fe85cddf88 refact(mem_store): Serialize/Deserialise olm sessions 2025-01-28 15:02:30 +01:00
Valere 9ff3761cac refact(mem_store): Serialize account and cache static account data 2025-01-28 15:02:30 +01:00
Valere a311dcbd3e refact(mem_store): Replace unwrap with expect 2025-01-28 15:02:30 +01:00
Andy Balaam 447bd67fe1 feat(crypto): Ignore to-device messages from dehydrated devices 2025-01-28 12:57:30 +00:00
Andy Balaam d8ba2b521c refactor(crypto): extract a method from a test that I will re-use later 2025-01-28 12:57:30 +00:00
Damir Jelić 8de15429fb chore: Fix a typo 2025-01-28 12:48:55 +01:00
Damir Jelić 3f398d8934 chore(ui): Move the SyncService stop logic out of the State::Running branch 2025-01-28 12:48:55 +01:00
Damir Jelić f8ec957193 doc(ui): Reword the doc comment for the is_supervisor_task_running method 2025-01-28 12:48:55 +01:00
Damir Jelić 7cc121ab38 docs(ui): Clarify that the supervisor encapsulates the child tasks in its own task 2025-01-28 12:48:55 +01:00
Damir Jelić 8a4918309a refactor(ui): Rename the abortion sender in the SyncService
Termination aligns better with the existing terminology.
2025-01-28 12:48:55 +01:00
Damir Jelić 30d7fac927 refactor(ui): Remove some unneeded references from the SyncServiceInner 2025-01-28 12:48:55 +01:00
Damir Jelić be71c6df56 docs: Document that the SyncService requires MSC4186 2025-01-28 12:48:55 +01:00
Damir Jelić 06ad67f99c docs(ui): Polish the documentation of the SyncService a bit 2025-01-28 12:48:55 +01:00
Damir Jelić 28fb6f7c27 fix(ui): Shutdown the child tasks if the channel got closed in the supervisor 2025-01-28 12:48:55 +01:00
Damir Jelić 842d32d41b refactor(ui): Prettify the two sync tasks a bit 2025-01-28 12:48:55 +01:00
Damir Jelić b52cf8327a refactor(ui): Remove some early returns from the sync service
Now that the various match branches in the start and stop method of the
SyncService are minimized we can remove the early returns.

This should allow us to more easily add new branches.
2025-01-28 12:48:55 +01:00
Damir Jelić d14526f161 refactor(ui): Move the task spawning functions under the supervisor 2025-01-28 12:48:55 +01:00
Damir Jelić 1b8a6b705c refactor(ui): Move the expiration of the sync services closer to the action 2025-01-28 12:48:55 +01:00
Damir Jelić 7c2b15fe86 refactor(ui): Move the spawning of the child tasks into the supervisor 2025-01-28 12:48:55 +01:00
Damir Jelić 3085f05d51 refactor(ui): Create a Supervisor for the SyncService
The supervisor is defined as two optional fields that are set and
removed at the same time.

This patch converts the two optional fields into a single optional
struct. The fields inside the struct now aren't anymore optional. This
ensures that they are always set and destroyed at the same time.
2025-01-28 12:48:55 +01:00
Damir Jelić 4344e06707 refactor(ui): Rename the scheduler task to supervisor task
From cambridge a scheduler is defined as:
    > someone whose job is to create or work with schedules

While supervisor is defined as:
    > a person whose job is to supervise someone or something

Well ok, that doesn't tell us much, supervise is defined as:
    > to watch a person or activity to make certain that everything is done correctly, safely, etc.:

In conclusion, supervising a task is the more common and better
understood terminology here I would say.
2025-01-28 12:48:55 +01:00
Damir Jelić 173ec75bb3 refactor(ui): Move common data of the SyncService under a lock
Previously we had a lock protecting an empty value, but the logic wants
to protect a bunch of data in the SyncService.

Let's do the usual thing and create a SyncServiceInner which holds the
data and protect that with a lock.
2025-01-28 12:48:55 +01:00
Ivan Enderlin 1d3f8bf898 doc(ui): Update the CHANGELOG. 2025-01-28 09:54:31 +01:00
Ivan Enderlin 5b3b87d3e2 chore(ui): Rename Timeline::subscribe_batched to ::subscribe.
This patch renames `Timeline::subscribe_batched` to
`Timeline::subscribe`. Since the `Timeline::subscribe` method has been
removed because unused, it no longer makes sense to have a “batched”
variant here. Let's simplify things!
2025-01-28 09:54:31 +01:00
Ivan Enderlin 6dc5b33d87 chore(ui): Remove useless trace!.
This patch removes useless `trace!` calls.
2025-01-28 09:54:31 +01:00
Richard van der Hoff 408b843156 test: fix cross-signing in legacy dehydrated device test
We missed a call to `sign_device_keys`. Pull out a test helper to make it more
obvious where this code is coming from.
2025-01-27 17:49:47 +00:00
Ivan Enderlin 0820170261 doc(ui): Update the CHANGELOG. 2025-01-27 17:02:09 +01:00
Ivan Enderlin 254ac6f2ce refactor(ui): Unify the Timeline pagination API.
This patch simplifies the `Timeline` pagination API as follows:

- a unique `paginate_backwards` method (no more
  `focused_paginate_backwards` and `live_paginate_backwards`),
- a unique `paginate_forwards` method (no more
  `focused_paginate_forwards`, the `live` variant was absent).

The idea is to unify pagination by hiding the `live` and `focused` mode.
It was already partially the case with `paginate_backards`, but the
`live` and `focused` variants were also present. I believe it creates
an unnecessary confusion.
2025-01-27 17:02:09 +01:00
Ivan Enderlin 468a7ac883 doc(ffi): Remove useless #[cfg(doc)] imports.
This patch removes 2 useless imports that are behind a `#[cfg(doc)]` but
never used.
2025-01-27 17:02:09 +01:00
Richard van der Hoff 3e610c80e1 Merge pull request #4581 from matrix-org/rav/refactor_share_keys
crypto: refactor the room key sharing strategies
2025-01-27 15:51:04 +00:00
Richard van der Hoff f43edbd31f refactor(crypto): split up split_devices_for_user_for_error_on_verified_user_problem_strategy
to make it easier to grok, I hope
2025-01-27 15:34:43 +00:00
Richard van der Hoff 7c57f2cee4 crypto: split out new device collection strategies
Rather than a bunch of flags on `DeviceBasedStrategy`, separate the strategies
properly.
2025-01-27 15:34:43 +00:00
Richard van der Hoff 8d612eca46 crypto: break up split_devices_for_user
handle the separate flags with separate methods.
2025-01-27 15:34:43 +00:00
Richard van der Hoff 98f4d55aa0 test: check serialization format of DeviceBasedStrategy 2025-01-27 15:34:43 +00:00
Richard van der Hoff 709b09c4ec test: factor out test helpers in share_strategy tests
Some helpers for creating common `EncryptionSettings`
2025-01-27 15:34:43 +00:00
Richard van der Hoff 818876a22e crypto: factor out common code between device collection cases
Firstly, build a `CollectRecipientsResult` as we go, rather than building its
components separately and then assembling it at the end.

Then, factor the common code between the two code paths into a method to update
the `CollectRecipientsResult`.
2025-01-27 15:34:43 +00:00
Stefan Ceriu 2657eb7866 feat(ui): expose a method for checking whether a message contains only emojis and should be boosted (use a bigger font size) (#4577)
- supports only text room message types
- enumerates through their body's grapheme clusters and check that every
single one of them is an emoji
- part of the `LazyTimelineItemProvider` so that it can be opt in
2025-01-27 14:00:01 +00:00
torrybr aaecbf07f2 refactor: dont panic if beacon_info is not found 2025-01-27 11:05:24 +01:00
torrybr f336638a17 refactor: move subscribe into arc 2025-01-27 11:05:24 +01:00
torrybr 839fbe477c feat(beacons): expose ffi functions to start, stop and subscribe 2025-01-27 11:05:24 +01:00
Richard van der Hoff 35ad5441d3 crypto: split common struct out of device collection results
`split_devices_for_user` returns a superset of the results of
`split_recipients_withhelds_for_user_based_on_identity`: let's reflect that in
the return types so we can start to share code.

Also, rename `split_recipients_withhelds_for_user_based_on_identity` to
`split_devices_for_user_for_identity_based_strategy` while we are here.
2025-01-26 22:50:15 +00:00
Kevin Boos 756dec264d Upgrade imbl, eyeball-im, eyeball-im-util to fix bounds check
A bounds check was recently relaxed in `imbl`'s `Focus::narrow()`
function: https://github.com/jneem/imbl/pull/89,
which fixed a bug that would cause a panic if the downstream user
of `matrix-sdk-ui` attempted to narrow a focus of Timeline items
using a range that included the last item in the Timeline.
Example: https://github.com/project-robius/robrix/issues/330

This fix has been incorporated in `eyeball-im` and `eyeball-im-util`
and has been tested by me to no longer trigger upon the aforementioned
conditions.
2025-01-25 02:13:22 -05:00
Doug 87983ab610 chore: Remove an old todo
This was already done by moving the methods into Client.
2025-01-24 18:06:05 +01:00
Neil Johnson 66ffc3448e Update README.md
style

Signed-off-by: Neil Johnson <neil@matrix.org>
2025-01-24 11:20:20 +01:00
Neil Johnson c6e308717d update maturity and contribution call to action 2025-01-24 10:56:05 +01:00
maan2003 4c4dd03411 fix(wasm): don't use tokio::time::{timeout,sleep} (#4573)
Tokio timeout and sleep don't work on wasm so provide alternative versions

---------

Signed-off-by: Manmeet Singh <manmeetmann2003@gmail.com>
Signed-off-by: Andy Balaam <andy.balaam@matrix.org>
Co-authored-by: Andy Balaam <andy.balaam@matrix.org>
2025-01-23 08:57:11 +00:00
Benjamin Bouvier 2d0f873342 refactor: send respects to multiple automated lints and checks 2025-01-22 20:24:48 +01:00
Benjamin Bouvier 041627ec4a test: rename EventFactory::into_sync to into_event 2025-01-22 20:24:48 +01:00
Benjamin Bouvier da4b8004f2 docs: add changelog entries 2025-01-22 20:24:48 +01:00
Benjamin Bouvier 3428494468 refactor: rename SyncTimelineEvent to TimelineEvent 2025-01-22 20:24:48 +01:00
Benjamin Bouvier 0c2046f93b refactor: have SyncTimelineEvent::push_actions be optional 2025-01-22 20:24:48 +01:00
Benjamin Bouvier eb31f035e6 refactor: turn TimelineEvent into SyncTimelineEvent
As the comment noted, they're essentially doing the same thing. A
`TimelineEvent` may not have computed push actions, and in that regard
it seemed more correct than `SyncTimelineEvent`, so another commit will
make the field optional.
2025-01-22 20:24:48 +01:00
Kévin Commaille df51404a14 chore(sdk): Add changelog for move of matrix_auth and oidc
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-01-22 20:22:13 +01:00
Kévin Commaille 3e78e441d4 refactor(sdk): Move oidc module to authentication::oidc
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-01-22 20:22:13 +01:00
Kévin Commaille 02c2e55855 refactor(sdk): Move matrix_auth module to authentication::matrix
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-01-22 20:22:13 +01:00
Stefan Ceriu a528624274 chore(ffi): replace all the different timeline builder methods with one taking a configuration (#4561) 2025-01-22 13:56:53 +02:00
Ivan Enderlin 1d83d42e9f chore(ui): Remove Timeline::subscribe.
This patch removes `Timeline::subscribe`. There is
`Timeline::subscribe_batched`, which is the only useful API.
`subscribe` was only used by our tests, and `matrix-sdk-ffi` uses
`subscribe_batched` only.
2025-01-22 11:55:23 +01:00
Ivan Enderlin 4684cfb780 chore: Replace Timeline::subscribe by Timeline::subscribe_batched.
This patch changes all calls to `Timeline::subscribe` to replace them by
`Timeline::subscribe_batched`. Most of them are in tests. It's the first
step of a plan to remove `Timeline::subscribe`.

The rest of the patch updates all the tests to use
`Timeline::subscribe_batched`.
2025-01-22 11:55:23 +01:00
Stefan Ceriu 991c9ad610 chore(ci): simplify formatting checks by using xtask instead 2025-01-22 12:20:47 +02:00
Hubert Chathi e826c54a42 Use the dehydrated device format implemented by vodozemac (#4421)
Signed-off-by: Hubert Chathi <hubertc@matrix.org>
2025-01-22 09:38:48 +01:00
Kévin Commaille 9ae658c1b9 feat(sdk): Enable HTTP/2 support
It became an optional default feature in reqwest 0.12, and we disable
the default features,
so I don't think it was meant to be disabled when the crate was
upgraded.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-01-22 09:08:00 +01:00
Benjamin Bouvier 4341aaf65c test: remove some uses of sync_timeline_event! in the base and sdk crates (#4565)
Part of #3716.
2025-01-21 14:33:22 +00:00
Jorge Martín ad847a82c8 refactor: Remove TestHelper in pinned_events.rs
Use helper functions instead.
2025-01-21 12:56:19 +01:00
Jorge Martín dad3e6839f test: update the code in pinned_events integration tests
This is done so the tests there use the new APIs based on `MatrixMockServer`.
2025-01-21 12:56:19 +01:00
Jorge Martín d078ef6155 fix: fix mock_room_event not being able to properly filter out event ids since the regex was incorrectly parsed by wiremock 2025-01-21 12:56:19 +01:00
Benjamin Bouvier 210c5749f1 test: minimize usage of EventFactory::state_key
It was used in places where we could make use of other helpers, in some
cases. Also introduces the `room_avatar` helper to create the room
avatar state event.
2025-01-21 10:50:29 +01:00
Benjamin Bouvier 0c74abbc50 test: get rid of EventBuilder (#4560)
This gets rid of `EventBuilder`, and makes more usage of the
`EventFactory`, which is more ergonomic to create test events.

A large part of
https://github.com/matrix-org/matrix-rust-sdk/issues/3716.
2025-01-21 09:23:03 +00:00
Jorge Martín dbadfe19b0 fix(timeline): avoid adding non-pinned events to the pinned events timeline when back paginating 2025-01-20 17:38:50 +01:00
dependabot[bot] f3e43dbfa4 chore(deps): bump malinskiy/action-android/install-sdk@release/0.1.4
Bumps [malinskiy/action-android/install-sdk@release/0.1.4](https://github.com/malinskiy/action-android) from 0.1.4 to 0.1.7.
- [Release notes](https://github.com/malinskiy/action-android/releases)
- [Commits](https://github.com/malinskiy/action-android/compare/release/0.1.4...release/0.1.7)

---
updated-dependencies:
- dependency-name: malinskiy/action-android/install-sdk@release/0.1.4
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-01-20 16:22:38 +01:00
dependabot[bot] b846a6dd81 chore(deps): bump crate-ci/typos from 1.28.3 to 1.29.4
Bumps [crate-ci/typos](https://github.com/crate-ci/typos) from 1.28.3 to 1.29.4.
- [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.3...v1.29.4)

---
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>
2025-01-20 16:22:31 +01:00
Ivan Enderlin c82e469fc3 chore(cargo): Update Ruma to include https://github.com/ruma/ruma/pull/1995. 2025-01-20 15:02:53 +01:00
Kévin Commaille f2c9a8f723 fix(ui): Fix latest_edit_json for live edits
This was a regression introduced in
f0d98602a9.

`latest_edit_json` was first set by the call to
`EventTimelineItem::with_content()`.
It was overwritten in the next section because of the
`if let EventTimelineItemKind::Remote(remote_event)`
that uses `item` instead of `new_item`.
It means that the updated `RemoteEventTimelineItem`
inside`new_item` was replaced by the outdated one inside `item`,
so `latest_edit_json` goes back to its previous value.

I believe that part of why that went unnoticed is that the code looks
more
complicated due to the need to set an inner field, so I decided to
change the API and
move `with_encryption_info` to `EventTimelineItem`, which makes the code
look cleaner.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-01-20 13:07:13 +01:00
torrybr 47fc073b70 refactor(live_location_share): exclude live location events of own user (#4535)
This change ensures that the user's own live location events are
excluded from the location sharing stream. Since the user's location is
already represented on the map by the blue dot, processing their own
events is redundant and unnecessary.
2025-01-17 14:56:10 +00:00
Jonas Platte 160600e8c0 chore(ui): Copy some attributes from matrix-sdk
The others should likely be copied at some point as well, but including
the readme as crate documentation is not currently useful since the
readme for the ui crate is empty, and warning about missing docs or
debug implementations would make CI fail without substantial extra work.
2025-01-17 15:35:28 +01:00
Jonas Platte 993c103270 ci: Add wasm job for matrix-sdk-ui 2025-01-17 15:35:28 +01:00
Jonas Platte e077980ba2 ci: Shorten job name
The extra 'wasm-flags' does not seem to add clarity.
2025-01-17 15:35:28 +01:00
Jonas Platte 63d14b798b ci: Reorder workflow matrix items to match ci.rs 2025-01-17 15:35:28 +01:00
Jonas Platte 077d63a9fc chore(ui): Re-export matrix-sdk's js feature 2025-01-17 15:35:28 +01:00
Ivan Enderlin 453c4e12db doc(sdk): Simplify documentation of RoomEventCache::subscribe.
This patch removes a `XXX` (which I believe is a TODO) in the
documentation of `RoomEventCache::subscribe`. We are not going to change
this API anytime soon.
2025-01-17 15:32:00 +01:00
Jonas Platte f7db52e069 Use Send-less BoxFuture for HttpClient Service impl on wasm 2025-01-17 12:21:21 +01:00
Richard van der Hoff 2bd8c56e64 crypto: add some more documentation to DeviceKeys
This confused me for a while, so I thought more documentation might help.
2025-01-16 15:13:25 +00:00
Richard van der Hoff f231c74314 test: simplify examples for KeyQueryResponseTemplate
Generating keys from slices rather than base64 is easier.

Also, s/builder/template/.
2025-01-16 15:13:11 +00:00
Stefan Ceriu 2cb6ee8e6d chore(ffi): silence useless logs coming out of the ffi crate
Setting the default log level to `debug` results in logs like:

```
log: log_event
log: latest_event
log: log_event
log: log_event
log: room_info
log: latest_event
log: log_event
log: room_info
```

Presumably they're coming out of the custom tracing configuration and we definitely don't need them.
2025-01-16 15:17:24 +02:00
Richard van der Hoff c24770a774 test: add support for dehydrated devices to KeyQueryResponseTemplate (#4540)
#4476 added some test helpers to generate `/keys/query` responses. We're
going to need to test dehydrated devices, so this PR adds support for
that.
2025-01-16 11:26:52 +00:00
Benjamin Bouvier 7fa06cb028 refactor(timeline): rename TimelineItemPosition::UpdateDecrypted to UpdateAt 2025-01-16 12:26:32 +01:00
Benjamin Bouvier 50383098ff feat(event cache): redact events in the database whenever they're redacted 2025-01-16 12:26:32 +01:00
Benjamin Bouvier 6f780a499c test(timeline): use assert_let_timeout more in the timeline's code 2025-01-16 12:26:32 +01:00
Benjamin Bouvier 425e48a46d feat(linked chunk): add LinkedChunk::replace_item_at to replace an item from a given position 2025-01-16 12:26:32 +01:00
Richard van der Hoff 3dd81fbe2c test: rename snapshots not to contain :
Windows doens't allow you to have `:` in its filenames
2025-01-16 11:11:38 +00:00
Benjamin Bouvier 6a0333e812 test: replace Option::default() by None 2025-01-16 11:34:42 +01:00
Benjamin Bouvier b3a789af90 test: get rid of the synced_client helper
Not running a large sync with many events make for simpler test cases,
with a more focused scope.
2025-01-16 11:34:42 +01:00
Benjamin Bouvier 560e582e41 test: get rid of mock_redaction and replace it with the holy MatrixMockServer 2025-01-16 11:34:42 +01:00
Benjamin Bouvier de7397a20e feat(event cache): handle redacted redactions in the AllEventsCache
This is unlikely that it will affect us, so not worth adding a test IMO,
but for the sake of completeness: this handles redacted redactions in
the `AllEventsCache` too.
2025-01-16 10:05:45 +01:00
Andy Balaam 8bd94318c0 fix(tests): Fix a flaky test by marking a room's members as synced.
This is intended to prevent the test
`test_when_user_in_verification_violation_becomes_verified_we_report_it`
flaking. I found that sometimes when it called `Room::members` the
result was empty due to it trying to fetch the answer from the server.
This change prevents that behaviour. I don't know why the behaviour was
inconsistent before.
2025-01-15 15:24:49 +00:00
Richard van der Hoff fe3cc09ae0 test: add examples for the new builder 2025-01-15 10:42:21 +00:00
Richard van der Hoff 3a3cc54067 test: generate dan's data dynamically 2025-01-15 10:42:21 +00:00
Richard van der Hoff 47f8b32ea1 test: give Dan new keys
Regenerate Dan's data with new cross-signing and device keys, for which I know
the private keys.

The signatures are manually calculated for now; this will be improved in a
later commit.
2025-01-15 10:42:21 +00:00
Richard van der Hoff 49748dbd4b test: factor out common parts of dan_keys_query_response{_loggedout} 2025-01-15 10:42:21 +00:00
Richard van der Hoff 25ea5fdd73 test: use builder for some more test data 2025-01-15 10:42:21 +00:00
Richard van der Hoff 5fadde5a6d test: implement test user data builder type
... and use it for some simple data
2025-01-15 10:42:21 +00:00
Richard van der Hoff b6be4d5170 test: remove redundant sig on master key
Our test helper won't do this, and it's redundant
2025-01-15 10:42:21 +00:00
Richard van der Hoff c9bac4ff2b test: snapshot the generated object rather than the JSON
We're going to be switching away from JSON-twiddling, so let's snapshot the
real object rather than the JSON.
2025-01-15 10:42:21 +00:00
Richard van der Hoff fedf7d214f test: add some snapshot tests before we change anything 2025-01-15 10:42:21 +00:00
Valere c969f903b7 Merge pull request #4526 from matrix-org/valere/test_encrypted_crypto_sql_snapshot
tests: Add an encrypted snapshot of a SQLite db for regression tests
2025-01-15 09:37:27 +01:00
Jorge Martín bd5d7aafee feat(ffi): Add FFI bindings for fn Room::own_membership_details.
Also add `membership_change_reason` field to `ffi::RoomMember`.
2025-01-14 16:23:51 +01:00
Jorge Martín e015a531da feat(room): Add fn Room::own_membership_details
This will retrieve the room member info of both the current user and the info for the sender of the current user's room member event.
2025-01-14 16:23:51 +01:00
Benjamin Bouvier b9014a5e2a test: keep a single sync in test_delayed_invite_response_and_sent_message_decryption()
This removes one sync that happens in the background, because it's
likely spurious and may be confusing the server about what's been seen
by the current client.
2025-01-14 15:07:10 +01:00
Jorge Martín e9487b0851 fix(timeline): Add UTDs to the timeline conditionally 2025-01-14 12:25:49 +01:00
Damir Jelić c60bfb877a chore: Add some missing links to the changelog 2025-01-13 19:27:44 +01:00
Valere ee32b1f600 tests: Add an encrypted snapshot of a SQLite db for regression tests 2025-01-13 17:50:50 +01:00
Daniel Salinas 9641aa9082 feat(send queue): Add an enqueued time to to-be-sent events (#4385)
Add a new created_at to the send_queue_events and
dependent_send_queue_events stored records. This will allow clients to
understand how stale a pending message might be in the event that the
queue encounters and error and becomes wedged.

This change is exposed through the FFI on the `EventTimelineItem` struct
as a new optional field named `local_created_at`. It will be `None` for
any Remote event, and `Some` for Local events (except for those that
were enqueued before the migrations were run).

Signed-off-by: Daniel Salinas

---------

Signed-off-by: Daniel Salinas <zzorba@users.noreply.github.com>
Co-authored-by: Daniel Salinas <danielsalinas@daniels-mbp-2.myfiosgateway.com>
Co-authored-by: Benjamin Bouvier <benjamin@bouvier.cc>
Co-authored-by: Daniel Salinas <danielsalinas@Daniels-MBP-2.attlocal.net>
2025-01-13 16:41:05 +00:00
Benjamin Bouvier a8ca77f4fc feat(base): remove cached events when forgetting about a room 2025-01-13 17:36:33 +01:00
Benjamin Bouvier e647ff935e feat(event cache store): allow removing an entire room at once 2025-01-13 17:36:33 +01:00
Benjamin Bouvier 7f04a9a18b fix(memory chunk): only remove a given room's events when clearing a roo 2025-01-13 17:36:33 +01:00
Damir Jelić 67d2cb790d chore: Fix a couple of typos 2025-01-13 17:25:00 +01:00
Benjamin Bouvier 279c78b3e2 chore!(encryption): rename are_we_the_last_man_standing to is_last_device
While the former name is arguably more fun, the latter is more
descriptive of what the function does.
2025-01-13 16:51:33 +01:00
Benjamin Bouvier 9514388108 tests: rename RoomMessagesResponse to RoomMessagesResponseTemplate 2025-01-13 14:50:21 +01:00
Benjamin Bouvier e6dc10933c tests: add helper to delay a room /messages response
This removes a few manual uses of `ResponseTemplate`, which is sweet and
guarantees some better typing for those responses overall.
2025-01-13 14:50:21 +01:00
Benjamin Bouvier c456356424 tests: add a helper to create a room /messages response 2025-01-13 14:50:21 +01:00
Benjamin Bouvier 5af326b36e fix(event cache): keep the previous-batch token when we haven't enabled storage 2025-01-13 14:50:21 +01:00
Jorge Martín 5548f38393 feat(ffi): Add FFI bindings for the new room privacy settings feature. 2025-01-13 11:29:10 +01:00
Jorge Martín d9c1188f87 test(room): Add integration tests for publishing and removing room aliases 2025-01-13 11:29:10 +01:00
Jorge Martín 588702756b feat(room): Add fn RoomPrivacySettings::remove_room_alias_in_room_directory. 2025-01-13 11:29:10 +01:00
Jorge Martín d6a74d389d feat(room): Add fn RoomPrivacySettings::publish_room_alias_in_room_directory.
This also needs some new mocks for resolving room aliases.
2025-01-13 11:29:10 +01:00
Jorge Martín d807d71e22 feat(room): Add fn RoomPrivacySettings::update_room_visibility. 2025-01-13 11:29:10 +01:00
Jorge Martín 587545ae82 feat(room): Add fn RoomPrivacySettings::get_room_visibility. 2025-01-13 11:29:10 +01:00
Jorge Martín 49985e5476 feat(room): Add fn RoomPrivacySettings::update_join_rule. 2025-01-13 11:29:10 +01:00
Jorge Martín 4fbe79a27d feat(room): Add fn RoomPrivacySettings::update_room_history_visibility. 2025-01-13 11:29:10 +01:00
Jorge Martín f61ad19ae6 feat(room): Add RoomPrivacySettings helper struct.
This can be accessed through `fn Room::privacy_settings` and will wrap the functionality related to a room's access and privacy settings.

This commit includes the `fn RoomPrivacySettings::update_canonical_alias` to modify the canonical alias of a room.
2025-01-13 11:29:10 +01:00
Benjamin Bouvier c9a49006f6 chore(xtask): tweak the TWiM report to include only merged PRs, not created PRs
As an outsider, I am mostly interested in features and new developments
that have happened, not those that *may* happen. An open-but-not-merged
PR may not get merged in the end, or it may not get merged any time
soon, creating false expectations. Merged PRs, on the other hand, have
definitely happened (even if they get undone, that happens via other PRs
that will get merged later). As such, I think it brings more value to
outsiders.
2025-01-13 11:03:08 +01:00
Kévin Commaille ca9eb70db5 Add PR link to changelog
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-01-13 08:46:10 +01:00
Kévin Commaille f173aea6e4 feat(sdk): Expose Client::server_versions publicly
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-01-13 08:46:10 +01:00
Jonas Platte e37ad11b47 refactor(ui): Use RPITIT / AFIT for RoomDataProvider 2025-01-11 13:19:16 -05:00
Damir Jelić d6c2a63f5c refactor: Use the simplified locks in the encryption tasks 2025-01-11 09:33:33 +01:00
Damir Jelić 4ebf5056be chore: Remove our ancient upgrade guide 2025-01-10 20:22:27 +01:00
Valere a79d409f9d task(bindings): Expose withdraw_verification in UserIdentity 2025-01-10 15:18:12 +01:00
Kévin Commaille 5941495e68 feat(sdk): Implement Default for AttachmentInfo types
Since all of their fields are optional, it simplifies their
construction.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-01-10 14:37:56 +01:00
Kévin Commaille b3491582d0 feat(sdk): Allow to set and check whether an image is animated
Using MSC4230.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-01-10 14:37:56 +01:00
Damir Jelić def4bbbed2 fix(store-encryption): Remove an unwrap that snuck in (#4506) 2025-01-10 14:13:10 +01:00
Valere 1dd2b2c9e8 test: Test the KnownSenderData migration with optimised [u8] serialization 2025-01-10 14:12:32 +01:00
Damir Jelić e4b269e0de fix: Implement visit_bytes for the Ed25519PublicKey deserialization
This fixes the deserialization of the SenderData since it switched to
the base64 encoding for serialization of the master key in one of its
variants.

The issue was introduced in 5ff556f6c3.
2025-01-10 14:12:32 +01:00
Kévin Commaille cb72d4375f chore: Upgrade Ruma
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-01-10 11:31:56 +01:00
Andy Balaam 7ec384c61a fix: Fix incorrect debug_struct calls in several places 2025-01-10 09:27:31 +01:00
Jonas Platte 7466f77eae refactor(ui): Replace tokio::spawn with matrix_sdk::executor::spawn 2025-01-10 03:02:37 -05:00
Jonas Platte 526b5c4630 refactor(ui): Relax some Send constraints on WASM 2025-01-10 03:02:37 -05:00
Jonas Platte 4043f9bf5d refactor(sdk): Un-cfg SendAttachment::with_send_progress_observable
It (now) compiles on WASM just fine.
2025-01-10 03:02:37 -05:00
Jonas Platte ff5dcbf631 refactor(common): Warn if LinkedChunk::updates() return value is not used 2025-01-09 16:20:51 -05:00
Jonas Platte 6c053a86bf chore: Fix new nightly warnings 2025-01-09 16:20:51 -05:00
Benjamin Bouvier 0cae54cc3f chore(ui): rename "utils" to "algorithms"
It only contains functions used to search items in the timeline now \o/
2025-01-09 17:27:53 +01:00
Benjamin Bouvier 692aceba50 chore(ui): move RelativePosition in timeline/controller 2025-01-09 17:27:53 +01:00
Benjamin Bouvier c4a86a3d0a chore(ui): move timeline/read_receipts to timeline/controller/read_receipts
Read receipts only make sense in the context of the timeline controller.
2025-01-09 17:27:53 +01:00
Benjamin Bouvier 5f5aa81174 chore(ui): move date and timestamp functionality to timeline/date_dividers.rs
`util.rs` files are… not the best thing. These types and functions were
only used by the date dividers file, so let's move them there.
2025-01-09 17:27:53 +01:00
Benjamin Bouvier 6e0f258a39 chore(sdk): move send_queue.rs to send_queue/mod.rs 2025-01-09 17:27:53 +01:00
Stefan Ceriu c4bfbd0f44 feat(ffi): move tracing setup from the final client to the ffi layer (#4492)
Having the final clients define the tracing filters / log levels proved
to be tricky to keep in check resulting missing logs (e.g. recently
introduced modules like the event cache) or unexpected behaviors (e.g.
missing panics because we don't set a global filter). As such we decided
to move the tracing setup and default definitions over to the rust side
and let rust developers have full control over them.

We will now take a general log level and optional extra targets and 
apply them on top of the rust side defined defaults. Targets that log
more than the requested by default will remain unchanged while the
others will increase their log levels to match. Certain targets like
`hyper` will be ignored in this step as they're too verbose others 
like `matrix_sdk` because they're too generic.
2025-01-09 18:08:44 +02:00
Benjamin Bouvier 8e0ee47637 refactor(event cache): eliminate intermediate function append_events_locked
and replace it with an inlined call to `append_events_locked_impl`,
that's then renamed `append_events_locked`.
2025-01-09 15:36:36 +01:00
Benjamin Bouvier 0915eeed51 chore(event cache): simplify and add logs to RoomEventCacheState::propagate_changes 2025-01-09 15:36:36 +01:00
Benjamin Bouvier fb54e869e9 chore(event cache): add more logs when the event cache tasks are shutting down 2025-01-09 15:36:36 +01:00
Benjamin Bouvier 9e97ed3134 test(event cache): add a regression test for not deleting a gap that wasn't inserted 2025-01-09 12:12:12 +01:00
Benjamin Bouvier b926c4287a refactor(event cache): use a more fine-grained check for the gap removal 2025-01-09 12:12:12 +01:00
Ivan Enderlin ddf4d575b7 fix(sdk): Ensure a gap has been inserted before removing it.
This patch fixes a bug where the code assumes a gap has been inserted,
and thus, is always present. But this isn't the case. If `prev_batch`
is `None`, a gap is not inserted, and so we cannot remove it. This patch
checks that `prev_batch` is `Some(_)`, which means the invariant is
correct, and the code can remove the gap.
2025-01-09 12:12:12 +01:00
Damir Jelić 2a954e3ce3 fix(base): Correctly name the LeftRoomUpdate in its debug implementation (#4487)
Signed-off-by: Damir Jelić <poljar@termina.org.uk>
Co-authored-by: Benjamin Bouvier <benjamin@bouvier.cc>
2025-01-09 11:10:33 +00:00
Jonas Platte b837865226 refactor(ui): Inherit Send / Sync bounds on RoomDataProvider from super traits 2025-01-09 09:26:55 +01:00
Jonas Platte eac5a5eb35 refactor(ui): Fix unused import on wasm 2025-01-09 09:26:55 +01:00
Jonas Platte d6c64027f6 refactor(sdk): Un-cfg Client::rooms_stream
It compiles on WASM too.
2025-01-09 09:26:55 +01:00
Ivan Enderlin df4b69666c chore: Make Clippy and wasm-pack happy. 2025-01-08 21:30:41 +01:00
Ivan Enderlin 5675ac7f46 refactor(sdk): Remove SlidingSyncRoomInner::client.
This patch removes `SlidingSyncRoomInner::client` because, first
off, it's not `Send`, and second, it's useless. Nobody uses it, it's
basically dead code… annoying dead code… bad dead code!
2025-01-08 21:30:41 +01:00
Ivan Enderlin 6b2233f8c4 fix(sdk): Use spawn from matrix_sdk_common to make it compatible with wasm32-u-u. 2025-01-08 21:30:41 +01:00
Ivan Enderlin 61dd560499 feat: Remove the experimental-sliding-sync feature flag.
Sliding sync is no longer experimental. It has a solid MSC4186, along
with a solid implementation inside Synapse. It's time to consider it
mature.

The SDK continues to support the old MSC3575 in addition to MSC4186.
This patch only removes the `experimental-sliding-sync` feature flag.
2025-01-08 21:30:41 +01:00
Damir Jelić 62567ca6eb refactor(crypto): Use the simplified locks across the crypto crate 2025-01-08 18:59:22 +01:00
Damir Jelić 46dc2a9c5e refactor: Use the simplified locks in the failures cache 2025-01-08 18:59:22 +01:00
Damir Jelić 891583b70e refactor: Add Mutex and RwLock wrappers that panic on poison 2025-01-08 18:59:22 +01:00
Ivan Enderlin e19bdbfd59 test(ui): Adjust tests according to the new Timeline behaviour. 2025-01-08 17:04:58 +01:00
Ivan Enderlin 14d0cc1935 refactor(ui): Remove TimelineSettings::vectordiffs_as_inputs.
From now on, this patch considers that `VectorDiff`s are the official
input type for the `Timeline`, via `RoomEventCacheUpdate` (notably
`::UpdateTimelineEvents`).

This patch removes `TimelineSettings::vectordiffs_as_inputs`. It thus
removes all deduplication logics, as it is supposed to be managed by the
`EventCache` itself.
2025-01-08 17:04:58 +01:00
Ivan Enderlin b8d0384da7 refactor: Remove RoomEventCacheUpdate::AddTimelineEvents.
This patch removes the `AddTimelineEvents` variant from
`RoomEventCacheUpdate` since it is replaced by `UpdateTimelineEvents`
which shares `VectorDiff`.

This patch also tests all uses of `UpdateTimelineEvents` in existing
tests.
2025-01-08 17:04:58 +01:00
Ivan Enderlin 4e0a6d15ca chore(sdk): Merge imports for the sake of clarity. 2025-01-08 17:04:58 +01:00
Ivan Enderlin 251433382f chore(test): Remove a warning.
`owned_user_id` is only used by a test behind the
`experimental-sliding-sync` feature flag.
2025-01-08 17:04:58 +01:00
Benjamin Bouvier 34e993435d fix(ffi): ensure the log level for panic is always set (#4485)
If it's present, we just let it untouched. Otherwise, we set it to
`error` if it's missing. See code comment explaining why we need this.

This makes sure we log panics at the FFI layer, since the `log-panics`
crate will use the `panic` target at the error level.
2025-01-08 15:51:14 +00:00
Benjamin Bouvier dc2775e194 chore!(ffi): rename thumbnail_url to thumbnail_path
This is a breaking change because uniffi may use foreign-language named
parameters based on the Rust parameter name.
2025-01-08 14:20:06 +01:00
Benjamin Bouvier 45c3752cae refactor!(ffi): common out more code in send_attachment and distinguish early from late errors
Some errors can be handled immediately and don't need a request to be
spawned, e.g. invalid mimetype and so on. The returned task handle still
deals about "late" errors about the upload failing (for sync uploads) or
the send queue failing to push the media upload (for async uploads).
2025-01-08 14:20:06 +01:00
Benjamin Bouvier ed178602d7 chore!(ffi): group parameters to upload in UploadParameters
Note: `Box<dyn ProgressWatcher>` couldn't be put in a `Record`, so
doesn't belong in `UploadParameters` as a result.
2025-01-08 14:20:06 +01:00
Benjamin Bouvier 35a03278c3 chore(ffi): rename url to filename in the FFI methods for sending attachments 2025-01-08 14:20:06 +01:00
Valere 9e69b631ee Merge pull request #4450 from matrix-org/valere/serialize_known_sender_data_b64
fix(crypto): Serialize sender data msk in base64 instead of numbers
2025-01-08 14:06:13 +01:00
Valere 5ff556f6c3 fix(crypto): Serialize sender data msk in base64 instead of numbers 2025-01-08 13:22:37 +01:00
Ivan Enderlin d64960679f refactor(sdk): Rename RoomEvents::filter_duplicated_events.
This patch renames `RoomEvents::filter_duplicated_events` to
`collect_valid_and_duplicated_events` as I believe it improves the
understanding of the code. The variables named `unique_events` are
renamed `events` as all (valid) events are returned, not only the unique
ones.
2025-01-08 13:01:59 +01:00
Ivan Enderlin 7ff1170681 chore: Re-indent. 2025-01-08 11:47:24 +01:00
Ivan Enderlin 55e25a3717 feat(sdk,ui): Add EventsOrigin::Pagination.
This patch adds the `Pagination` variant to the `EventsOrigin` enum.
Not something really mandatory and that is likely to fix a bug, but it's
now correct.
2025-01-08 11:43:03 +01:00
Joe Groocock 3f977b79fa feat(timeline): allow sending mentions along with media
Since 8205da898e it has been possible to
attach (intentional) mentions to _edited_ media captions, but the
send_$mediatype() timeline APIs provided no way to send them with the
initial event. This fixes that.

Signed-off-by: Joe Groocock <me@frebib.net>
2025-01-08 10:43:43 +01:00
Benjamin Bouvier aca8c8b8ee chore: remove some allow(dead_code) annotations and associated dead code (#4472)
We have quite a few `allow(dead_code)` annotations. While it's OK to use
in situations where the Cargo-feature combination explodes and makes it
hard to reason about when something is actually used or not, in other
situations it can be avoided, and show actual, dead code.
2025-01-08 10:37:18 +01:00
Kévin Commaille 47c24b9a17 fix(sdk): Fix test now that Ruma is fixed
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-01-08 10:35:28 +01:00
Kévin Commaille 47445b10f1 chore: Upgrade Ruma
This is using the ruma-0.12 branch where non-breaking changes are backported.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-01-08 10:35:28 +01:00
Jonas Platte c5a9a1e215 Clean up some imports
With experimental-sliding-sync enabled and e2e-encryption disabled,
there were a bunch of warnings about unused imports. This fixes them
(but a few warnings about other unused items remain).
2025-01-08 09:18:56 +01:00
Benjamin Bouvier 2ef14ded41 refactor(event cache): a few AllEventsCache refactorings (#4471)
I was investigating a potential deadlock with the event cache storage,
and only found a few places where to make the code a bit more idiomatic
and more readable.
2025-01-07 17:25:52 +01:00
Benjamin Bouvier 8205da898e feat(send queue): allow setting intentional mentions in media captions edits
Fixes #4302.
2025-01-07 16:52:53 +01:00
Benjamin Bouvier 618e47250d feat!(base): reintroduce Room::display_name
`compute_display_name` is made private again, and used only within the
base crate. A new public counterpart `Room::display_name` is introduced,
which returns a cached value for, or computes (and fills in cache) the
display name. This is simpler to use, and likely what most users expect
anyways.
2025-01-07 15:25:32 +01:00
Benjamin Bouvier 5110aa64aa doc(base): update lying doc comment of compute_display_name
It claimed that it would immediately return when the cached display name
value was computed, but that's absolutely not the case.

Spotted while reviewing a PR updating `iamb` to the latest version of
the SDK.
2025-01-07 14:39:07 +01:00
Benjamin Bouvier bcad0a3059 test(timeline): rewrite a test to use the MatrixMockServer instead 2025-01-07 11:58:34 +01:00
Benjamin Bouvier b7b88f58d2 feat!(send queue): make unrecoverable errors stop the sending queue
Instead of keeping on handling unwedged events from the sending queue,
it's now required to re-enable the send queue manually for the room that
encountered the sending error, all the time. This is more consistent,
and avoids weird behavior when a user would 1. send an event for which
sending fails, in an unrecoverable manner, 2. send an event that's
actually sendable.
2025-01-07 11:58:34 +01:00
Damir Jelić 412fcab4dc test: Await the device creation in the notification client redecryption test 2025-01-07 11:06:28 +01:00
Jonas Platte 8e75a940f7 Use Instant from web-time in more places (via ruma re-export)
web-time's Instant type is already used elsewhere in the project. It is
an alias for std's Instant type on most targets, but tries to call into
JavaScript on wasm32-unknown-unknown (assuming that the wasm blob is
used in from a browser context). Its Duration type is a plain re-export
of std's Duration, even on wasm32-unknown-unknown.
2025-01-07 09:35:52 +01:00
Kévin Commaille 70fb7899e6 feat!(timeline): Allow to send attachments from bytes (#4451)
Sometimes we can get the bytes directly, e.g. in Fractal we can get an
image from the clipboard. It avoids to have to write the data to a
temporary file only to have the data loaded back in memory by the SDK
right after.

The first commit to accept any type that implements `Into<String>` for
the filename is grouped here because it simplifies slightly the second
commit.

Note that we could also use `AttachmentSource` in the other
`send_attachment` APIs, on `Room` and `RoomSendQueue`, for consistency.

---------

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-01-06 15:44:29 +01:00
Benjamin Bouvier 1480fada6e refactor(event cache): make it clearer that vecdiff updates must be handled with with_events_mut
Every caller to `with_events_mut` must propagate the vector diff
updates, otherwise updates would be missing to the room event cache's
observers. This slightly tweaks the signature to make this a bit
clearer, and adjusts the code comment as well.
2025-01-06 13:14:31 +01:00
Kévin Commaille c50358366f refactor!(sdk): Set thumbnail in AttachmentConfig with builder method instead of constructor
`AttachmentConfig::with_thumbnail()` is replaced by
`AttachmentConfig::new().thumbnail()`.

Simplifies the use of `AttachmentConfig`, by avoiding code like:

```rust
let config = if let Some(thumbnail) = thumbnail {
  AttachmentConfig::with_thumbnail(thumbnail)
} else {
  AttachmentConfig::new()
};
```

---------

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-12-22 17:45:04 +00:00
Valere adb4428a69 test(crypto): Add some basic snapshot testing in crypto crate 2024-12-20 19:52:37 +01:00
Damir Jelić 667a8e684c chore: Fix a typo in the changelog 2024-12-20 13:59:54 +01:00
Ivan Enderlin f4b50db972 test: Increase timeout for codecoverage. 2024-12-20 13:57:45 +01:00
Ivan Enderlin 1abb2efc51 refactor(sdk): Rename two variables. 2024-12-20 13:57:45 +01:00
Ivan Enderlin c4132252d3 feat(ui): Enable TimelineSettings::vectordiffs_as_inputs if event cache storage is enabled.
This patch automatically enables
`TimelineSettings::vectordiffs_as_inputs` if and only if the event cache
storage is enabled.
2024-12-20 13:57:45 +01:00
Ivan Enderlin 51c76a15ad chore(ui): Make Clippy happy. 2024-12-20 13:57:45 +01:00
Ivan Enderlin f1842ba5d0 refactor(ui): Timeline receives pagination events as VectorDiffs!
This patch allows the paginated events of a `Timeline` to be received
via `RoomEventCacheUpdate::UpdateTimelineEvents` as `VectorDiff`s.
2024-12-20 13:57:45 +01:00
Ivan Enderlin d8dd72fd9c refactor(ui): Deduplicate timeline items conditionnally.
A previous patch deduplicates the remote events conditionnally. This
patch does the same but for timeline items.

The `Timeline` has its own deduplication algorithm (for remote
events, and for timeline items). The `Timeline` is about to receive
its updates via the `EventCache` which has its own deduplication
mechanism (`matrix_sdk::event_cache::Deduplicator`). To avoid conflicts
between the two, we conditionnally deduplicate timeline items based on
`TimelineSettings::vectordiffs_as_inputs`.

This patch takes the liberty to refactor the deduplication mechanism of
the timeline items to make it explicit with its own methods, so
that it can be re-used for `TimelineItemPosition::At`. A specific
short-circuit was present before, which is no more possible with the
rewrite to a generic mechanism. Consequently, when a local timeline
item becomes a remote timeline item, it was previously updated (via
`ObservableItems::replace`), but now the local timeline item is removed
(via `ObservableItems::remove`), and then the remote timeline item is
inserted (via `ObservableItems::insert`). Depending of whether a virtual
timeline item like a date divider is around, the position of the removal
and the insertion might not be the same (!), which is perfectly fine as
the date divider will be re-computed anyway. The result is exactly the
same, but the `VectorDiff` updates emitted by the `Timeline` are a bit
different (different paths, same result).

This is why this patch needs to update a couple of tests.
2024-12-20 13:57:45 +01:00
Ivan Enderlin 054f5e28f6 fix(common): Use a trick to avoid hitting the recursion_limit too quickly.
This patch adds a trick around `SyncTimelineEvent` to avoid reaching the
`recursion_limit` too quickly. Read the documentation in this patch to
learn more.
2024-12-20 13:57:45 +01:00
Ivan Enderlin 38e35b99d0 test(ui): Increase the recursion_limit.
Since we have added a new variant to `RoomEventCacheUpdate`, a macro
hits the recursion limit. It needs to be updated in order for tests to
run again.
2024-12-20 13:57:45 +01:00
Ivan Enderlin 39afb531ef task(ui): DayDivider has been renamed DateDivider.
This patch updates this branch to `main` where `DayDivider` has been
renamed `DateDivider`.
2024-12-20 13:57:45 +01:00
Ivan Enderlin c1ff5ff49f refactor(ui): Deduplicate remote events conditionnally.
The `Timeline` has its own remote event deduplication mechanism. But
we are transitioning to receive updates from the `EventCache` via
`VectorDiff`, which are emitted via `RoomEvents`, which already runs its
own deduplication mechanism (`matrix_sdk::event_cache::Deduplicator`).
Deduplication from the `EventCache` will generate `VectorDiff::Remove`
for example. It can create a conflict with the `Timeline` deduplication
mechanism.

This patch updates the deduplication mechanism from the `Timeline`
when adding or updating remote events to be conditionnal: when
`TimelineSettings::vectordiffs_as_inputs` is enabled, the deduplication
mechanism of the `Timeline` is silent, it does nothing, otherwise it
runs.
2024-12-20 13:57:45 +01:00
Ivan Enderlin 2358e4c32f task(ui): Support VectorDiff::Remove, in TimelineStateTransaction::handle_remote_events_with_diffs.
This patch updates
`TimelineStateTransaction::handle_remote_events_with_diffs` to support
`VectorDiff::Remove,`.
2024-12-20 13:57:45 +01:00
Ivan Enderlin 409fccb709 task(ui): Support VectorDiff::Insert in TimelineStateTransaction::handle_remote_events_with_diffs.
This patch updates
`TimelineStateTransaction::handle_remote_events_with_diffs` to support
`VectorDiff::Insert`.
2024-12-20 13:57:45 +01:00
Ivan Enderlin b25fd830ec task(ui): Add AllRemoteEvents::range.
This patch adds the `AllRemoteEvents::range` method. This
is going to be useful to support `VectorDiff::Insert` inside
`TimelineStateTransaction::handle_remote_events_with_diffs`.
2024-12-20 13:57:45 +01:00
Ivan Enderlin 02ab57870a task(ui): Add ObservableItems::insert_remote_event.
This patch adds the `ObservavbleItems::insert_remote_event` method.
This is going to be useful to implement `VectorDiff::Insert` inside
`TimelineStateTransaction::handle_remote_events_with_diffs`.
2024-12-20 13:57:45 +01:00
Ivan Enderlin eca3749b28 task(ui): Support VectorDiff::Clear in TimelineStateTransaction::handle_remote_events_with_diffs.
This patch updates
`TimelineStateTransaction::handle_remote_events_with_diffs` to support
`VectorDiff::Clear`.
2024-12-20 13:57:45 +01:00
Ivan Enderlin 3f17325bac task(ui): Support VectorDiff::PushBack in TimelineStateTransaction::handle_remote_events_with_diffs.
This patch updates
`TimelineStateTransaction::handle_remote_events_with_diffs` to support
`VectorDiff::PushBack`.
2024-12-20 13:57:45 +01:00
Ivan Enderlin 23c09b2c9d task(ui): Support VectorDiff::PushFront in TimelineStateTransaction::handle_remote_events_with_diffs.
This patch updates
`TimelineStateTransaction::handle_remote_events_with_diffs` to support
`VectorDiff::PushFront`.
2024-12-20 13:57:45 +01:00
Ivan Enderlin c1f8232450 task(ui): Support VectorDiff::Append in TimelineStateTransaction::handle_remote_events_with_diffs.
This patch updates
`TimelineStateTransaction::handle_remote_events_with_diffs` to support
`VectorDiff::Append`.
2024-12-20 13:57:45 +01:00
Ivan Enderlin e28073361d feat(ui): Add blank handle_remote_events_with_diffs. 2024-12-20 13:57:45 +01:00
Ivan Enderlin 1c2fb1ab72 refactor(sdk): Add RoomEventCacheUpdate::UpdateTimelineEvents.
This patch adds a new variant to `RoomEventCacheUpdate`, namely
`UpdateTimelineEvents. It's going to replace `AddTimelineEvents` soon
once it's stable enough. This is a transition. They are read by the
`Timeline` if and only if `TimelineSettings::vectordiffs_as_inputs` is
turned on.
2024-12-20 13:57:45 +01:00
Ivan Enderlin be89e3aacb feat(ui): Add TimelineBuilder::with_vectordiffs_as_inputs.
This patch adds `with_vectordiffs_as_inputs` on `TimelineBuilder` and
`vectordiffs_as_inputs` on `TimelineSettings`. This new flag allows to
transition from one system to another for the `Timeline`, when enabled,
the `Timeline` will accept `VectorDiff<SyncTimelineEvent>` for the
inputs instead of `Vec<SyncTimelineEvent>`.
2024-12-20 13:57:45 +01:00
Damir Jelić 36427b0e12 fix(ui): Consider banned rooms as rooms we left in the non-left rooms matcher
Recently we started to differentiate between rooms we've been banned
from from rooms we have left on our own.

Sadly the non-left rooms matcher only checked if the room state is not
equal to the Left state. This then accidentally moved all the banned
rooms to be considered as non-left.

We replace the single if expression with a match and list all the
states, this way we're going to be notified by the compiler that we need
to consider any new states we add in the future.
2024-12-20 12:35:34 +01:00
Daniel Salinas f8a9d12c88 Use a type alias to allow bindings to take advantage of custom types 2024-12-20 10:46:13 +01:00
Benjamin Bouvier 5f5e979e16 refactor!: Put the RequestConfig argument of Client::send() into a builder method
Instead of `Client::send(request, request_config)`, consumers can now do
`Client::send(request).with_request_config(request_config)`.
2024-12-20 10:35:18 +01:00
Valere 519f281844 Merge pull request #4428 from matrix-org/valere/insta_rs_snapshot_testing
test(snapshot): Use snapshot testing in sdk-common
2024-12-19 18:30:49 +01:00
Valere 3b31bbec0c test(snapshot): Use snapshot testing in sdk-common 2024-12-19 18:11:55 +01:00
Benjamin Bouvier f2942db316 refactor: avoid use of async_trait for RoomIdentityProvider
This is an 8 seconds (out of 22) decrease of the matrix-sdk compile
times.
2024-12-19 17:38:59 +01:00
Andy Balaam e4712be946 task(crypto): Support receiving stable identifier for MSC4147 2024-12-19 15:27:34 +00:00
Benjamin Bouvier bc8c4f5e58 fix(event cache): don't touch the linked chunk if an operation wouldn't cause meaningful changes
See comment on top of `deduplicated_all_new_events`.
2024-12-19 14:19:55 +01:00
Benjamin Bouvier fe9354a886 test: make test_room_keys_received_on_notification_client_trigger_redecryption more stable
When starting to back-paginate, in this test, we:

- either have a previous-batch token, that points to the first event
*before* the message was sent,
- or have no previous-batch token, because we stopped sync before
receiving the first sync result.

Because of the behavior introduced in 944a9220, we don't restart
back-paginating from the end, if we've reached the start. Now, if we are
in the case described by the first bullet item, then we may backpaginate
until the start of the room, and stop then, because we've back-paginated
all events. And so we'll never see the message sent by Alice after we
stopped sync'ing.

One solution to get to the desired state is to clear the internal state
of the room event cache, thus deleting the previous-batch token, thus
causing the situation described in the second bullet item. This achieves
what we want, that is, back-paginating from the end of the timeline.
2024-12-19 14:19:55 +01:00
Benjamin Bouvier d00ff8fa1f refactor(event cache): remove duplicated method RoomEventCacheState::clear() 2024-12-19 14:19:55 +01:00
Benjamin Bouvier 60f521cc23 feat(event cache): don't add a previous gap if all events were deduplicated, after back-pagination 2024-12-19 14:19:55 +01:00
Benjamin Bouvier bcb9a86a00 feat(event cache): don't add a previous gap if all events were deduplicated, after sync 2024-12-19 14:19:55 +01:00
Benjamin Bouvier 3f0712010f refactor(event cache): add a way to know if we deduplicated all events (at least one) 2024-12-19 14:19:55 +01:00
Benjamin Bouvier d89194f071 refactor: display source pagination error in PaginatorError::SdkError 2024-12-19 14:19:55 +01:00
Benjamin Bouvier a20ad728b5 feat(event cache): don't restart back-pagination from the end if we had no prev-batch token 2024-12-19 14:19:55 +01:00
Benjamin Bouvier 0d546dce5f refactor(event cache): move PaginationToken from the pagination to room/mod file 2024-12-19 14:19:55 +01:00
Jorge Martín 38cc9fb7c8 test(room): Improve Room::room_member_updates_sender tests 2024-12-19 14:14:05 +01:00
Jorge Martín 616c193a30 feat(room): create a cleanup task in Room::subscribe_to_knock_requests
This cleanup task will run while the knock request subscription runs and will use the `Room::room_member_updates_sender` notification to call `Room::remove_outdated_seen_knock_requests_ids` and remove outdated seen knock request ids automatically.
2024-12-19 14:14:05 +01:00
Jorge Martín 4a88e7cfee feat(room): add BaseRoom::remove_outdated_seen_knock_requests_ids fn
This will check the current seen knock request ids against the room members related to them and will remove those seen ids for members which are no longer in knock state or come from an outdated knock member event.
2024-12-19 14:14:05 +01:00
Jorge Martín 5d0fed5e53 feat(room): add helper methods to BaseRoom to get and write the current seen knock request ids while keeping them thread-safe with a lock around them 2024-12-19 14:14:05 +01:00
Jorge Martín 9975365a1e feat(room): add Room::room_member_updates_sender
This sender will notify receivers when new room members are received: this can happen either when reloading the full room member list from the HS or when new member events arrive during a sync.

The sender will emit a `RoomMembersUpdate`, which can be either a full reload or a partial one, including the user ids of the members that changed.
2024-12-19 14:14:05 +01:00
Integral f18e0b18a1 Replace PathBuf/Utf8PathBuf with Path/Utf8Path when ownership not needed 2024-12-19 13:29:09 +01:00
Jorge Martín b18100228e test(room): add test to verify how Room::observe_events will behave when several events are received in a short while 2024-12-19 12:16:49 +01:00
Benjamin Bouvier de568837fb fix(linked chunk): fix order handling of initial chunks in UpdateToVectorDiff::new()
The code would use a chunk iterator that moves forward, but call
`push_front()` repetitively on each chunk, semantically storing the
lengths in *reverse* order.

This could result in subsequent panics, when a new chunk was added,
because the links would not match what's expected (e.g. the last chunk
must have no successor, etc.).
2024-12-18 19:50:25 +01:00
Ivan Enderlin bc582ae101 doc(common): Update documentation of AsVector.
This patch updates the documentation of `AsVector`.
2024-12-18 19:47:25 +01:00
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ć dda080c497 sqlite: Bump the version 2024-07-19 10:18:27 +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
Damir Jelić a18f90bfaa chore: Fix some invalid test data 2024-07-18 17:10:00 +02:00
Damir Jelić 60ed367fd9 chore: Format the changelog a bit better 2024-07-18 17:10:00 +02:00
Damir Jelić 1157067dba chore: Prepare the matrix-sdk-crypto release 0.7.2 2024-07-18 17:10:00 +02:00
Damir Jelić 8efdba6136 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 17:10:00 +02:00
Damir Jelić 1029e51eb3 chore: Use a released version of vodozemac (#3721) 2024-07-18 17:10:00 +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
Damir Jelić f25916cb5c chore: Remove an unused import 2024-05-13 12:48:30 +02:00
Damir Jelić 637e830e85 chore: Fix the formatting 2024-05-13 12:48:30 +02: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ć 04362cdc36 chore(crypto): Bump the version of the crypto crate to 0.7.1 2024-05-13 12:31:26 +02:00
Valere fa10bbb5dd fix(crypto): 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-05-13 12:31:26 +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 4164effbf9 Bump matrix-sdk to 0.7.1 2024-01-22 11:27:03 +01:00
Sami J. Mäkinen 917e8c291e Upgrade aquamarine dependency 2024-01-22 11:25:56 +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
Jonas Platte 3e17fc2072 Add a description for matrix-sdk-ui 2024-01-05 14:23:41 +01:00
Jonas Platte f08e978540 Upgrade uniffi
… and specify a version such that publishing of the ui crate becomes possible.

We still use a git dependency for FFI crate builds because there were some
likely important breaking changes that haven't been released.

This is required to publish `matrix-sdk-ui`.
2024-01-05 14:03:44 +01:00
Jonas Platte 40b09cda2f Bump all of the versions to 0.7.0 2024-01-05 12:58:54 +01:00
Jonas Platte 2710a85897 Rename matrix-sdk-base/{Changelog => CHANGELOG.md}
… for consistency.
2024-01-05 12:58:54 +01:00
Jonas Platte 315e6c9d85 Use workspace dependencies for matrix-sdk-test 2024-01-05 12:58:54 +01:00
Benjamin Bouvier 2822f2471a Update crates/matrix-sdk/src/room/mod.rs
Signed-off-by: Benjamin Bouvier <public@benj.me>
2024-01-05 12:12:52 +01:00
Kévin Commaille b0530ba3a6 sdk: Create ReportedContentScore
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-01-05 12:12:52 +01:00
Kévin Commaille 844212e965 sdk: Add method to report an event
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-01-05 12:12:52 +01:00
Jonas Platte eb33c3754a bindings: Move matrix_sdk_ui enum definitions out of UDL 2024-01-04 17:14:44 +01:00
Richard van der Hoff cf57992346 indexeddb: logging for open sequence (#2983)
I was trying to figure out what was taking so long, so added some logging.
2024-01-04 15:10:54 +00:00
Jonas Platte d9f99f84f5 Fix Cargo warning about deafult-features
`default-features = false` was already a no-op prior to workspace dependency change,
as `matrix-sdk-crypto` has no default features.
2024-01-04 14:54:33 +01:00
Benjamin Bouvier afd05a24df Rename BaseClient::update_summary to BaseClient::set_room_info 2024-01-04 11:41:50 +01:00
Benjamin Bouvier 0f91eebc96 BaseClient::apply_changes doesn't need to be async 2024-01-04 11:41:50 +01:00
Benjamin Bouvier 0f8b99b744 Remove spurious testing guards in the read status integration test 2024-01-04 11:41:50 +01:00
Benjamin Bouvier 30714c3f92 Don't cause a spurious room info update when setting the latest event 2024-01-04 11:41:50 +01:00
Benjamin Bouvier 96b427a332 Add test showing the spurious room info update 2024-01-04 11:41:50 +01:00
Jonas Platte 1c7bf820bf Use workspace dependencies for crates/* dependencies
… except from examples (such that they remain copy-pastable).
2024-01-04 10:02:07 +01:00
Jonas Platte 24b879bbc0 Clean up Cargo manifest formattting 2024-01-04 10:02:07 +01:00
Jonas Platte 51a0bb6f3b ci: Upgrade typos action 2024-01-04 09:53:17 +01:00
Jonas Platte 9eca314511 Fix a typo 2024-01-04 09:53:17 +01:00
Jonas Platte c4724c082e Upgrade dependencies 2024-01-02 19:12:42 +01:00
manuroe 3d9d3b7ca6 Merge pull request #2977 from matrix-org/valere/long_mark_as_sent
Remove an expensive database call only used for tracing prupose
2024-01-02 13:35:36 +01:00
Valere 541d9184c6 remove expensive db call for tracing 2023-12-22 16:19:25 +01:00
Benjamin Bouvier 45bdbf5067 Add test to make sure notification count is taken into account when processing sliding sync 2023-12-22 14:45:54 +01:00
Benjamin Bouvier 04ef3d9f95 Fix: revert notification count change from read receipts PR
This was modified and then removed from the PR, and forgot to put back the previous
implementation.
2023-12-22 14:45:54 +01:00
Benjamin Bouvier 75fe874cae read receipts: don't update a RoomInfo if the read receipts haven't changed 2023-12-21 17:41:35 +01:00
Benjamin Bouvier 2a77aaa068 read receipts: update the API shape of compute_notifications 2023-12-21 15:54:19 +01:00
Benjamin Bouvier 4a686229e1 read receipts: make find_and_count_events a method of RoomReadReceipts 2023-12-21 15:54:19 +01:00
Benjamin Bouvier d64fb8241d read receipts: add test for find_and_count_events 2023-12-21 15:54:19 +01:00
Benjamin Bouvier 870d1eafb4 read receipts: add RoomReadReceipts::reset 2023-12-21 15:54:19 +01:00
Benjamin Bouvier a9905eaedd read receipts: don't count the same action multiple time per event 2023-12-21 15:54:19 +01:00
Benjamin Bouvier f1c15da87d read receipts: make count_unread_and_mention a method of RoomReadReceipts and rename it 2023-12-21 15:54:19 +01:00
Benjamin Bouvier f2b53080b6 read receipts: move RoomReadReceipts to the read_receipts.rs file 2023-12-21 15:54:19 +01:00
Benjamin Bouvier 7fe4e22076 read receipts: test count_unread_and_highlights 2023-12-21 15:54:19 +01:00
Benjamin Bouvier b6dab1a3a5 read receipts: compute_notifications doesn't need to be async 2023-12-21 15:54:19 +01:00
Andy Balaam ec833c81e0 Migrate inbound_group_session2 to fix keys incorrectly copied from old store version (#2957)
In migrate_data_for_v6, we incorrectly copied the keys in inbound_group_sessions verbatim into inbound_group_sessions2. What we should have done is re-encrypt them using the new table name, so we fix that up with a new migration here.

This caused the bug because we were looking for sessions to mark as backed up by calculating their key (from room_id and session_id) but that key did not exist, because the old sessions were stored under the incorrect keys. So no sessions were marked as backed up, and we repeatedly tried to re-mark them.
2023-12-21 14:52:02 +00:00
Ivan Enderlin de0574aa14 Merge pull request #2925 from zecakeh/create-dm-encrypted
client: Allow to create encrypted DM
2023-12-21 14:38:32 +01:00
Benjamin Bouvier fb1ff70538 Disable integration test in code coverage build
The test fails only in the codecov build, not in a local build or in the other integration test.

Needs further investigation.
2023-12-21 11:55:29 +01:00
Benjamin Bouvier d6bcbf2281 Address review comments
- copyright notice
- doc comments and better doc in general
- use static dispatch instead of &dyn T
- other misc comments
2023-12-21 11:55:29 +01:00
Benjamin Bouvier cbc832411d read receipts: add an extra num_unread_notifications field
This helps supporting cases where we want to show that a room has some activity (unread messages) but no notifications.
2023-12-21 11:55:29 +01:00
Benjamin Bouvier 843fcac3c1 read receipts: don't clone cached events for computing the read receipt state
Before this patch, we needed to clone the inner `timeline_queue` and turn it into a concrete `Vec<SyncTimelineEvent>`, just to iterate on the elements,
and because returning an iterator from a trait method is impractical. This now changes it to return the actual concrete type of `timeline_queue`, so
we don't need the extra allocations.

Ideally, matrix-sdk and matrix-sdk-base would be merged, so we don't need to use a trait at all here.
2023-12-21 11:55:29 +01:00
Benjamin Bouvier b3a8f34655 read receipts: move the unread messages and mentions counts to separate fields of RoomInfo 2023-12-21 11:55:29 +01:00
Benjamin Bouvier 73af3d9cfa Make it clear that some functions are tests or test helpers only 2023-12-21 11:55:29 +01:00
Benjamin Bouvier 09e355a7bc read receipts: add integration tests for read receipts 2023-12-21 11:55:29 +01:00
Benjamin Bouvier 9ba09b2ae8 sync: process unread notification count client-side 2023-12-21 11:55:29 +01:00
Benjamin Bouvier c9b02ad068 doc: document SlidingSyncRoomInner::timeline_queue a bit better 2023-12-21 11:55:29 +01:00
Benjamin Bouvier 07c428ec56 sdk base: add latest_read_receipt_event_id field to RoomInfo 2023-12-21 11:55:29 +01:00
Valere d4b8f88e10 Fix regenerate_olm_machine losing backup state (#2961)
* Fix regenerate_olm_machine loosing backup state

* use new helper

* clippy fix

* quick review
2023-12-21 09:43:55 +01:00
Stefan Ceriu 28a58479e7 Bring back original (slower) build style under the sequentially fla… (#2960)
* Bring back original (slower) build style under the `sequentially` flag to work around new build style hanging on older machines

* 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>
2023-12-21 08:15:21 +00:00
Benjamin Bouvier 320b868694 style: remove spurious fully-qualified path 2023-12-18 15:47:45 +01:00
Benjamin Bouvier 8615b1283a sliding sync: don't cause a spurious RoomInfo update
The room_info variable in this function contains the latest_event, and later it's set as the Room's room info (`inner.inner`) field.
Calling `set_latest_event` manually here will cause an update of the `RoomInfo` subscriber, while we're not done processing the full
room, and a room info update will happen anyways later (when the entire room is processed), so this one is spurious and will only
show a partial update of the fields.
2023-12-18 15:47:45 +01:00
Benjamin Bouvier 9a4d539428 sliding sync: optimize finding the room member state event
- We can look up the session meta only once, it's not useful to do it once per event as it's
loop-invariant.
- We can look at the events backwards and stop after the first room membership event we see
in that order.
2023-12-18 15:47:45 +01:00
Kévin Commaille 4d3fc44425 Put imports behind feature
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-12-18 14:07:01 +01:00
Kévin Commaille 8b878c6591 Fix test
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-12-18 14:05:01 +01:00
Kévin Commaille 738f7f0336 client: Create DM as encrypted by default
If `e2e-encryption` feature is enabled.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-12-18 13:04:39 +01:00
Valere f5fb44bd80 Maybe trigger backup at end of sync (#2939)
* maybe trigger backup at end of sync

* add test for backup upload

* missing e2e cfg

* add sliding sync tests

* fix borrow

* fix indent

* fix naming from copy/paste

* Remove extracted function

* fix clippy

* style: inline a few variables only used once into their use sites

---------

Co-authored-by: Benjamin Bouvier <public@benj.me>
2023-12-18 10:41:44 +00:00
Doug e0ba9f5a22 xtask: Use Uniffi Library mode for Kotlin too. 2023-12-18 10:34:38 +01:00
Doug b5aeea0a3b xtask: Handle multiple headers/modulemaps. 2023-12-18 10:34:38 +01:00
Ivan Enderlin 19526cea6b Merge pull request #2928 from zecakeh/qrcode-changes
verification: Expose the `QrVerificationState` and the stream for its changes
2023-12-15 12:52:50 +01:00
Ivan Enderlin 99d0b37914 Merge pull request #2951 from matrix-org/andybalaam/clarify-meaning-of-pendingbackup-sessions
Clarify the meaning of the sessions field in PendingBackup
2023-12-15 12:45:29 +01:00
Andy Balaam b21a438b7e Merge pull request #2934 from matrix-org/andybalaam/mark_sessions_as_backed_up
Provide `CryptoStore::mark_inbound_group_sessions_as_backed_up` on stores and use it in `BackupMachine::mark_request_as_sent`
2023-12-15 11:40:50 +00:00
Andy Balaam f3101baa08 Merge branch 'main' into andybalaam/mark_sessions_as_backed_up 2023-12-15 10:47:36 +00:00
Andy Balaam 0cf99db001 Delete accidentally-copied repeat_vars function
Signed-off-by: Andy Balaam <andy.balaam@matrix.org>
2023-12-15 10:47:11 +00:00
Andy Balaam a032d33d21 Remove comments in favour of a separate PR with type aliases
Signed-off-by: Andy Balaam <andy.balaam@matrix.org>
2023-12-15 10:40:36 +00:00
Andy Balaam 92212cc328 Clarify the meaning of the sessions field in PendingBackup
Signed-off-by: Andy Balaam <andy.balaam@matrix.org>
2023-12-15 10:38:56 +00:00
Kévin Commaille 6ffb0181e4 Make sure qrcode feature is additive
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-12-15 11:01:03 +01:00
dependabot[bot] 614bf942c0 build(deps): bump zerocopy from 0.7.26 to 0.7.31
Bumps [zerocopy](https://github.com/google/zerocopy) from 0.7.26 to 0.7.31.
- [Release notes](https://github.com/google/zerocopy/releases)
- [Changelog](https://github.com/google/zerocopy/blob/main/CHANGELOG.md)
- [Commits](https://github.com/google/zerocopy/compare/v0.7.26...v0.7.31)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-12-15 10:39:21 +01:00
Andy Balaam 512509ce8b Switch to using chunk_large_query_over in mark_inbound_group_sessions_as_backed_up
Signed-off-by: Andy Balaam <andy.balaam@matrix.org>
2023-12-14 16:56:13 +00:00
Andy Balaam dfb33c9534 Move chunk_large_query_over into SqliteObjectExt so it can be reused
Signed-off-by: Andy Balaam <andy.balaam@matrix.org>
2023-12-14 16:55:36 +00:00
Andy Balaam 03aad4e965 Move repeat_vars into utils so it can be reused
Signed-off-by: Andy Balaam <andy.balaam@matrix.org>
2023-12-14 16:34:45 +00:00
Andy Balaam 9e67b6fcb1 Merge branch 'main' into andybalaam/mark_sessions_as_backed_up 2023-12-14 15:25:43 +00:00
Ivan Enderlin 9443f455a4 Test Media caching, and re-implement it inside MemoryStore
Test Media caching, and re-implement it inside `MemoryStore`
2023-12-14 15:51:04 +01:00
Ivan Enderlin 384deec1c8 chore(base): Simplify code. 2023-12-14 15:39:24 +01:00
Kévin Commaille 5310f41cda integration-testing: Add test for QR verification
And check room ID in SAS test.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-12-14 15:23:16 +01:00
Ivan Enderlin 95a1db8fc7 Merge pull request #2947 from matrix-org/andybalaam/use-correct-limit-in-chunk_large_query_over
Use the limit() method to find the variable limit in chunk_large_query_over
2023-12-14 14:31:40 +01:00
Ivan Enderlin 3d9dffa3b7 chore(base): Remove unused imports. 2023-12-14 14:18:56 +01:00
Andy Balaam 3d7e1d5989 Merge branch 'main' into andybalaam/use-correct-limit-in-chunk_large_query_over 2023-12-14 13:17:06 +00:00
Ivan Enderlin a46bf76d74 test(base): Improve test_media_content.
This patch improves `test_media_content` to ensure that, in case of
multiple medias, only the expected ones are removed. Previously, the
test wasn't testing _other_ medias that should be kept in case of
removals.

This patch continues to improve `test_media_content` to ensure that the
content of the media are the expected ones.

Finally, this patch updates the `MemoryStore` implementation to make
tests happy.
2023-12-14 14:15:01 +01:00
Ivan Enderlin 326935db63 feat(base): Correct implementations for MemoryStore media removal.
This patch rewrites `MemoryStore::add_media_content`,
`::get_media_content`, `::remove_media_content` and
`::remove_media_content_for_uri` to (i) work on `mxc://` URI instead
of “unique key”, and (ii) to handle removal correctly thanks to the new
`RingBuffer::remove` method.
2023-12-14 13:54:12 +01:00
Ivan Enderlin 416bc8b0e4 feat(base): Implement Media::uri.
This new method returns the `MxcUri` associated to the `Media`.
2023-12-14 13:53:23 +01:00
Ivan Enderlin edd113a17c feat(common): Implement RingBuffer::remove. 2023-12-14 13:28:17 +01:00
Ivan Enderlin 66411d7b2e Merge pull request #2946 from matrix-org/andybalaam/tests-for-repeat_vars
Unit tests for the repeat_vars function
2023-12-14 13:10:12 +01:00
Ivan Enderlin 4a53bf1f3d Merge pull request #2945 from matrix-org/andybalaam/limits-access-for-sqlite
Provide a limit() method in sqlite to find limit values
2023-12-14 13:10:02 +01:00
Andy Balaam a3aa55ce91 Use the limit() method to find the variable limit
Signed-off-by: Andy Balaam <andy.balaam@matrix.org>
2023-12-14 11:31:01 +00:00
Andy Balaam 0066ae6614 Unit tests for the repeat_vars function
Signed-off-by: Andy Balaam <andy.balaam@matrix.org>
2023-12-14 11:26:43 +00:00
Andy Balaam 17ebc23719 Provide a limit() method in sqlite to find limit values
Signed-off-by: Andy Balaam <andy.balaam@matrix.org>
2023-12-14 11:21:25 +00:00
Ivan Enderlin cdb3449ce2 test(sdk): Test that Media::get_media_content with caching works. 2023-12-14 12:11:24 +01:00
Ivan Enderlin c5b11fc2f8 feat(sdk): Simplify code from Media::get_media_content.
If `use_cache` is true and the cache exists, let's return everything in
one go instead of declaring a `content` variable. It makes the code
easier to read and to understand.
2023-12-14 12:10:08 +01:00
Ivan Enderlin 2ad6acb930 doc(common): Add documentation for RingBuffer::drain. 2023-12-14 12:07:08 +01:00
Ivan Enderlin dac779f4fc test(base): Re-implement a super basic media cache for MemoryStore.
This is a rather over simplistic media cache implementation for the
`MemoryStore`.

It's based on a `RingBuffer` of size 20.

`remove_media_content` pops all medias until the correct one is met (if
it exists). `remove_media_content_for_uri` removes all medias, it
ignores the URI.
2023-12-14 12:04:58 +01:00
Kévin Commaille e2ea19ee77 Add rule kind to error messages
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-12-14 11:39:42 +01:00
Kévin Commaille cc38768bf4 notification settings: Don't error if poll start rules are not found
These rules are unstable so they might not be
found in every ruleset.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-12-14 11:39:42 +01:00
Kévin Commaille c87bd4d4ec notification settings: Log errors from requests
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-12-14 11:39:42 +01:00
Kévin Commaille 5700c700f0 error: Use NotificationSettingsError::RuleNotFound's rule ID in display impl
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-12-14 11:39:42 +01:00
Kévin Commaille fff9882792 notification settings: Rely more on Ruma methods
Simplifies code.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-12-14 11:39:42 +01:00
Kévin Commaille 45f8ff11c2 notification settings: Derive Copy for enum types
This a good practice for inexpensive types
and avoids to have to call `.clone()` explicitely.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-12-14 11:39:42 +01:00
Kévin Commaille 7c9d842d05 notification settings: Use private method to get poll start rule ID
A `From` implementation is part of the public API
and this conversion does not make sense outside of the module.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-12-14 11:39:42 +01:00
Kévin Commaille c3706d7ca0 notification settings: Allow to manage keywords (#2905)
* notification settings: Allow to manage keywords
* Fix wording of docs

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
Signed-off-by: Kévin Commaille <76261501+zecakeh@users.noreply.github.com>
Co-authored-by: Ivan Enderlin <ivan@mnt.io>
2023-12-14 11:16:40 +01:00
Ivan Enderlin b314da37b8 feat(ffi): Timeline::send_image and send_video takes an optional thumbnail_url
feat(ffi): `Timeline::send_image` and `send_video` takes an optional `thumbnail_url`
2023-12-14 10:48:16 +01:00
Ivan Enderlin 02ba6c0dbe feat(ffi): Client::*media* are now async
feat(ffi): `Client::*media*` are now async
2023-12-14 09:14:39 +01:00
Ivan Enderlin 22d9c62262 feat(ffi): Timeline::send_image and send_video takes an optional thumbnail_url.
This patch updates `Timeline::send_image` and `Timeline::send_video` so
that `thumbnail_url` is now an `Option<String>`.

The idea is to allow sending an image or a video without a thumbnail.
2023-12-13 17:07:03 +01:00
Ivan Enderlin 18b6387a7a Merge pull request #2935 from matrix-org/rav/fix_nonmonotonic_panic
Configure `Instant` wasm polyfill to use monotonic time
2023-12-13 15:57:32 +01:00
Ivan Enderlin c5ddba2e13 feat(ffi): Client::*media* are now async.
This patch removes `RUNTIME.block_on` inside `Client::get_media_file`,
`::upload_media`, `::get_media_content` and `::get_media_thumbnail`, and
makes those methods async.
2023-12-13 15:33:01 +01:00
Kévin Commaille 9756ed28cf verification: Expose the room ID where the verification is happening
Useful if we want to know in what room
we just sent a VerificationRequest,
with UserIdentity::request_verification

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-12-13 15:22:13 +01:00
Richard van der Hoff 5701cea51e Configure Instant wasm polyfill to use monotonic time
With the `inaccurate` feature, this polyfill uses `Date.now()` to emulate
`Instant`, which is not monotonic, causing problems like
https://github.com/element-hq/element-web/issues/26416.
2023-12-13 12:08:54 +00:00
Andy Balaam 794b7ead7a Clippy fixes 2023-12-13 08:43:59 +00:00
Andy Balaam f879f3d866 Formatting 2023-12-13 08:32:00 +00:00
Andy Balaam 4ebb8e29b4 Provide CryptoStore::mark_sessions_as_backed_up on stores and use it in BackupMachine::mark_request_as_sent
Signed-off-by: Andy Balaam <andy.balaam@matrix.org>
2023-12-12 16:09:22 +00:00
Doug d764fca7da xtask: Move all the Swift files found
… and fix build swift errors.

- The XCFramework was being built with dylibs which aren't supported on iOS
- The tests build was attempting to generate uniffi from a moved file
2023-12-12 16:51:49 +01:00
Jonas Platte 3b7f9f7361 Reapply "bindings: Use new uniffi-bindgen build mode"
This reverts commit 0d24bcf6e5.
2023-12-12 16:51:49 +01:00
Doug 73770b78bb room: Add test for unban_user. 2023-12-12 16:13:09 +01:00
Doug 7cffc34984 ffi: Support banning, unbanning and kicking users. 2023-12-12 16:13:09 +01:00
Benjamin Bouvier c4ef967523 dx: tweak debugging of user/device pairs missing a session 2023-12-11 17:11:11 +01:00
Kévin Commaille f0b378179e matrix auth: Await save_session_callback
Otherwise the future will not run.
Changes the corresponding test to fail with the old behavior.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-12-11 16:54:53 +01:00
Kévin Commaille ee344112f3 verification: Expose the QrVerificationState and the stream for its changes
Allows to have a similar API as SasVerification

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-12-11 16:13:56 +01:00
Benoit Marty 1f52aca210 Fix typo in doc. 2023-12-11 12:13:05 +01:00
Kévin Commaille 74091de8ef sdk: Make sure "testing" feature is enabled for integration tests
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-12-11 11:53:25 +01:00
Kévin Commaille 0f6efc391a client: Allow to create encrypted DM
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-12-11 11:14:19 +01:00
Mauro c707e1f17e feat(bindings): expose a function to send private read receipts (#2906) 2023-12-11 09:29:06 +00:00
Benjamin Bouvier 5ab69f7400 ffi: add emoji indices in the session verification data + use decimals as a fallback 2023-12-08 14:48:48 +01:00
Jonas Platte e652069896 sdk: Use crates.io release of mas-oidc-client 2023-12-07 17:34:36 +01:00
Benjamin Bouvier 5337c9d9ea refactoring: make it clear that notifications aren't stored in the state store
`notifications` were stored in the `StateChanges` struct, which made me think that they're then persisted in the database. It's not the case, they
were just stored there by convenience. This commit changes it to a parameter that's passed, as it's not too invasive and clearer that this is only
transient data.
2023-12-07 16:56:18 +01:00
Benjamin Bouvier 9fd52e5df7 timeline: document event_filter better 2023-12-07 10:35:42 +01:00
Benjamin Bouvier 4ab79a4085 timeline: add the room version in the event_filter parameters 2023-12-07 10:35:42 +01:00
Benjamin Bouvier a132c0a885 read receipts: apply a default event filter only for events that get rendered 2023-12-07 10:35:42 +01:00
Benjamin Bouvier 5081802177 room: try restoring from a key backup during backpagination too 2023-12-05 16:53:06 +01:00
Stefan Ceriu 736188811f ffi: expose the call member state event type for clients to check if users can join calls 2023-12-05 15:51:28 +01:00
Benoit Marty 1337fdf0b8 ffi: Expose is_invite_for_me_enabled and set_invite_for_me_enabled in notification settings 2023-12-04 17:04:19 +01:00
Ivan Enderlin 0573137835 Merge pull request #2902 from matrix-org/rav/outgoing_key_requests_switch
Crypto: add new methods for turning off room key requests
2023-12-04 15:12:33 +01:00
Ivan Enderlin 21ce2b07a7 Merge pull request #2904 from matrix-org/jme/add-typing-notice-bindings
Add FFI bindgings for `Room.typing_notice()`
2023-12-04 15:09:46 +01:00
Richard van der Hoff 6451a9dffe rename toggle -> set 2023-12-04 12:53:02 +00:00
Kévin Commaille a6af31984a Assert that the stream is pending
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-12-04 13:30:43 +01:00
Kévin Commaille 2de45bcb51 notification settings: Do not expose NotificationSettings::new in the public API
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-12-04 13:30:43 +01:00
Kévin Commaille 7bdc1448bd notification settings: Drop event handler only when last instance is dropped
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-12-04 13:30:43 +01:00
Kévin Commaille 511c44c588 Add test for NotificationSettings::subscribe_to_changes
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-12-04 13:30:43 +01:00
Kévin Commaille a915900580 notification settings: Allow to subscribe to changes
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-12-04 13:30:43 +01:00
Kévin Commaille e12f6fcbb7 notification settings: Accept any type that implements AsRef<str> as rule_id
Simplifies the use of this API with the Predefined{*}RuleId Ruma types.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-12-04 13:30:43 +01:00
Jorge Martín 72dfd3d1fd Add FFI bindgings for Room.typing_notice() 2023-12-01 16:19:32 +01:00
Richard van der Hoff a6c206118d changelog 2023-12-01 12:50:43 +00:00
Richard van der Hoff 2536373546 Add new methods for turning off room key requests 2023-12-01 12:47:44 +00:00
Jorge Martín 045d94ab4b Rename message inside an error, since it clashes with Kotlin's default message property in exceptions 2023-12-01 12:07:40 +01:00
Benjamin Bouvier d8c02d7e55 timeline builder: tweak comments 2023-12-01 11:05:53 +01:00
Benjamin Bouvier b20313c492 read receipts: rename ReadReceipts fields
The "read_receipts" suffix isn't useful since we're looking at the fields of `ReadReceipts` already.
2023-12-01 11:05:53 +01:00
Benjamin Bouvier c3ea2c3736 Format with rustfmt nightly. 2023-12-01 11:05:53 +01:00
Benjamin Bouvier 2c1377b2b5 read receipts: a few function renamings and add getter/setter for receipts on events 2023-12-01 11:05:53 +01:00
Benjamin Bouvier bb85af9279 read receipts: add getter/setter for the latest read receipts cache 2023-12-01 11:05:53 +01:00
Benjamin Bouvier 58ab6704ff read receipts: a few function renamings
Add the prefix `load` to make it clear this may load from the storage.
2023-12-01 11:05:53 +01:00
Benjamin Bouvier 94a64296d1 Show the wrapped error when displaying a SlidingSync::JoinError 2023-11-30 19:52:20 +01:00
Benjamin Bouvier 7d6c16956f fix: reify reformat of missing_session_devices_by_user
`itertools::format` is known to cause issues when its display implementation is being
used multiple times, as it consumes the iterator it was given (and that can only happen once,
unless caching it). This is bad, as our production apps may have multiple subscribers they will
run into a panic.

The fix is to reify the debug string before it's logged, so the tracing consumer will only see
a string, and not the display implementation that would panic on the second use.
2023-11-30 19:52:20 +01:00
Damir Jelić 916bf69e5c Enable backups and set the backup download strategy for the bindings 2023-11-30 16:51:06 +01:00
Damir Jelić 915c10e1b4 Test for the one-by-one download of room keys 2023-11-30 16:20:51 +01:00
Damir Jelić 5e122c5c5e Add a background task which downloads room keys from the backup one-by-one 2023-11-30 16:20:51 +01:00
Damir Jelić 49e5461ef7 Add a method to check if we have a room key stored locally 2023-11-30 16:20:51 +01:00
Damir Jelić 27927c676d Allow the to create a FailuresCache with different values for the max timeout 2023-11-30 16:20:51 +01:00
Damir Jelić ac5a9e106b Move the FailuresCache into the common crate 2023-11-30 16:20:51 +01:00
Damir Jelić 94c4e685fc Test for recovery 2023-11-30 15:12:22 +01:00
Damir Jelić f248e272e9 Expose the recovery stuff in the bindings 2023-11-30 15:12:22 +01:00
Damir Jelić 97026fc3a6 Recovery support
Co-authored-by: Jonas Platte <jplatte@matrix.org>
2023-11-30 15:12:22 +01:00
Richard van der Hoff 1fcd5af526 indexeddb: Update storage for inbound_group_sessions (#2885)
Currently, querying for inbound group sessions which need backing up is very
inefficient: we have to search through the whole list.

Here, we change the way they are stored so that we can maintain an index of the
ones that need a backup.

Fixes: https://github.com/vector-im/element-web/issues/26488
Fixes: https://github.com/matrix-org/matrix-rust-sdk/issues/2877

---

* indexeddb: Update storage for inbound_group_sessions

Currently, querying for inbound group sessions which need backing up is very
inefficient: we have to search through the whole list.

Here, we change the way they are stored so that we can maintain an index of the
ones that need a backup.

* Rename functions for clarity

* Remove spurious log line

This was a bit verbose

* Rename constants for i_g_s store names

* improve log messages

* add a warning

* Rename `InboundGroupSessionIndexedDbObject.data`

* formatting
2023-11-30 12:01:20 +01:00
Benjamin Bouvier 8b04db666c Remove room.rs file added by mistake
Thanks @jaller94 for noticing and letting me know :)
2023-11-30 10:27:25 +01:00
Timo 1ff2c5bb3e Add recommended vscode settings in contrib/ide 2023-11-28 13:41:04 +01:00
Jonas Platte 05f0106e06 ui: Improve logging for sync update processing 2023-11-27 18:55:21 +01:00
Jonas Platte fd0f369f75 ui: Add extra tracing spans for reactions 2023-11-27 18:55:21 +01:00
Jonas Platte 39fc283353 ui: Improve logging for redactions 2023-11-27 18:55:21 +01:00
Jonas Platte 3ebd8afa49 ui: Add more logging for Timeline::retry_send 2023-11-27 18:55:21 +01:00
Jonas Platte 2483ba2cc6 ui: Raise log level for local events
Local events don't happen as often, so we can afford a higher log level.
2023-11-27 18:55:21 +01:00
Jonas Platte 2d3a458a08 ui: Improve logging for sending attachments 2023-11-27 18:55:21 +01:00
Jonas Platte 246a128ec3 ui: Add logging for send-event cancellation 2023-11-27 18:55:21 +01:00
Jonas Platte 932f12e76d ui: Improve logging for timeline resets 2023-11-27 18:55:21 +01:00
Richard van der Hoff bfe79468c6 Indexeddb: Groundwork for fixing inbound_group_session lookups (#2884)
A set of non-functional changes which lay some groundwork in preparation for fixing vector-im/element-web#26488.
2023-11-27 15:59:49 +00:00
Timo 9503eb49c7 ffi: Expose power level overwrites on room creation 2023-11-27 14:38:35 +00:00
Marco Romano ded854425a timeline: Add poll history API
Allow to retrieve the Poll history of a Room.
The poll history is a Timeline instance that filters only on poll events.
2023-11-27 14:28:40 +00:00
Jonas Platte 959e90252b ffi: Create separate timeline object, mirroring the Rust API 2023-11-27 11:55:48 +01:00
Jonas Platte e761ad8f97 ffi: Remove remove_timeline method
It was somewhat of a footgun because it affected the cached timeline in
`RoomListItem`s as well and is not used anywhere anymore.
2023-11-27 11:55:48 +01:00
Jonas Platte ceeb5e78b6 ffi: Move more things into ruma module 2023-11-24 19:25:44 +01:00
Jonas Platte 04c4284b33 ffi: Split timeline into smaller modules 2023-11-24 19:25:44 +01:00
Jonas Platte bae191b4ed ffi: Move Ruma wrappers / extension traits to new module 2023-11-24 19:25:44 +01:00
Damir Jelić ea2e85c5f5 feat: Support for server-side key backups #2666 2023-11-24 18:16:42 +01:00
Damir Jelić d6401ef278 When disabling backups first delete it from the server 2023-11-24 18:01:05 +01:00
Damir Jelić 9bba437fdd Simplify the secret inbox handling for backups 2023-11-24 18:01:05 +01:00
Damir Jelić 19e65c05cf Remove the CheckingIfUploadNeeded UploadState variant 2023-11-24 18:01:05 +01:00
Damir Jelić 369ca7024f Apply suggestions from code review
Co-authored-by: Denis Kasak <dkasak@termina.org.uk>
2023-11-24 18:01:05 +01:00
Damir Jelić e958b1ce28 Don't run the event handler examples 2023-11-24 18:01:05 +01:00
Damir Jelić 4912cd8a40 Typos please 2023-11-24 18:01:05 +01:00
Damir Jelić c99b0e8344 Fix some clippy warnings 2023-11-24 18:01:04 +01:00
Damir Jelić b38f501902 Add an example for the room key backup support 2023-11-24 17:59:00 +01:00
Damir Jelić f37467f81f Add tests for backups 2023-11-24 17:59:00 +01:00
Damir Jelić 6239231ba0 Try to resume backups if we restore the client
Co-authored-by: Benjamin Bouvier <public@benj.me>
2023-11-24 17:59:00 +01:00
Damir Jelić aa1623b891 Add a hack so the timeline retries to decrypt if we receive room keys from backup 2023-11-24 17:59:00 +01:00
Damir Jelić 99131d0d7a Fetch the backup recovery key when we import all known secrets 2023-11-24 17:59:00 +01:00
Damir Jelić c5c62d8fda Add a client task that will upload room keys to the backup 2023-11-24 17:58:58 +01:00
Damir Jelić b909f4400d Add support for backups 2023-11-24 17:56:09 +01:00
Damir Jelić 18d69f7515 Add a ChannelObservable 2023-11-24 17:53:33 +01:00
Richard van der Hoff 456d8bb4f2 Reduce logspam during encryption (#2859)
A few different changes to reduce the number of lines that get logged during an
encryption operation.
2023-11-24 14:21:01 +00:00
Jonas Platte b277423237 sdk: Upgrade mas-oicd-client 2023-11-24 15:01:17 +01:00
Jonas Platte 4621dd4317 ffi: Upgrade opentelemetry 2023-11-24 15:01:17 +01:00
Jonas Platte 17797da71a indexeddb: Upgrade dependencies 2023-11-24 15:01:17 +01:00
Jonas Platte eec4227dfc sdk: Upgrade async-related dependencies 2023-11-24 15:01:17 +01:00
Jonas Platte 64ddfd872c sqlite: Upgrade rusqlite / deadpool-sqlite 2023-11-24 15:01:17 +01:00
Jonas Platte 19a990ad41 Update Cargo.lock
The reqwest update is held back to avoid linking issues on iOS.
2023-11-24 15:01:17 +01:00
Jonas Platte 53ad6f5fe5 Upgrade itertools 2023-11-24 15:01:17 +01:00
Jonas Platte 8038414de2 Raise minimum version for Ruma
Otherwise the matrix-sdk crate can be used with an older version of
ruma-client-api which uses different types for a sliding sync type.

The sliding sync breaking change was allowed to be part of a patch
release because sliding sync is an unstable feature in Ruma.
2023-11-24 15:01:17 +01:00
Jonas Platte 560d71ceea sdk: Implement a custom event formatter for javascript logging
Somehow `fmt::pretty` manages to be both overcomplicated and not flexible
enough.

The driver here is that I want to put the event "fields" on a separate line to
the message.
2023-11-24 13:48:35 +01:00
Richard van der Hoff 6591a6ef04 Apply suggestions from code review
Co-authored-by: Jonas Platte <jplatte@matrix.org>
2023-11-24 12:35:36 +00:00
Benjamin Bouvier 35bac2a6c3 test: add an integration test for left rooms 2023-11-23 15:17:26 +01:00
Benjamin Bouvier 7455b90d24 Tweak debug message wording for a timeline event
Probably from a bad copy-pasta with a poll event.
2023-11-23 15:11:54 +01:00
Benjamin Bouvier 1e359576ad room list service: add a new filter to get all rooms but the left ones
This allows to get a list of all the rooms except for left ones, since they're still part of a sliding sync server response.
2023-11-23 15:06:00 +01:00
Alfonso Grillo fe02752f29 fix: EventTimelineItem.is_editable() respects poll’s preconditions for editing (#2875)
This PR fixes the `EventTimelineItem.is_editable()` function for polls.

Before this changes it always returned false.
Now it consider poll's preconditions for editing:
- The poll has no votes yet
- The poll hasn't an end event
2023-11-23 14:03:25 +00:00
Jonas Platte aa7d2a21a3 test: Fix new clippy lints 2023-11-23 14:15:21 +01:00
Jonas Platte 337f2ad415 Upgrade nightly toolchain used for ci, xtask 2023-11-23 14:15:21 +01:00
Jonas Platte c5c3850edf Use the same nightly toolchain for all xtask commands 2023-11-23 14:15:21 +01:00
Richard van der Hoff 086e988e68 crypto: Be consistent about /keys/query endpoint name
Sometimes, we called this `keys query`, sometimes `/keys/query`, and sometimes,
just for variety, `keys/query`. Generally in Matrix we talk about `/keys/query`
so let's standardise on that.
2023-11-22 14:02:39 +00:00
Val Lorentz 5c37acb81c sdk: Add method to get the set of parent spaces of a room 2023-11-22 14:31:52 +01:00
Richard van der Hoff 2aaa709b0e Reinstate tracing instrumentation on ReadOnlyDevice::encrypt (#2873)
Until https://github.com/matrix-org/matrix-rust-sdk/pull/2862,
`GroupSessionManager::encrypt_session_for` called `Device::encrypt` (via
`Device::maybe_encrypt_room_key`.

`Device::encrypt` is a thin wrapper for `ReadOnlyDevice::encrypt`, but it also
has an `instrument` annotation.

https://github.com/matrix-org/matrix-rust-sdk/pull/2862 short-cuts
`Device::encrypt` and calls `ReadOnlyDevice::encrypt` directly: that was
functionally fine but of course means that we no longer benefit from the
`instrument` annotation.

This PR rectifies the situation by pushing the annotation down to
`ReadOnlyDevice::encrypt`. It also adds some documentation for that function,
since we are using it in more places now.

(Longer-term, I think we should probably aim to get rid of `Device::encrypt`
altogether, but that's a refactor I don't want to take on today.)
2023-11-22 13:04:36 +00:00
Alfonso Grillo 8fe501c4ed ui: Add poll editing API 2023-11-22 13:46:37 +01:00
Stefan Ceriu 79c020f169 Switch from building each target individually to letting cargo figure out the optimal way 2023-11-22 12:33:26 +01:00
Damir Jelić bb4254b9c9 Prepare our /keys/claim response handling to handle multiple OTKs (#2870)
This is useful if we ever decide to switch to X3DH for the session
establishment. It also refactors a bit the /keys/claim response handling
method.

Co-authored-by: Jonas Platte <jplatte@matrix.org>
2023-11-22 10:41:08 +01:00
Damir Jelić ee0010e831 Make the mocks in some notification tests a bit more specific
The mocks in some notification tests mock any PUT/DELETE request without
the request to hit a certain path. These mocks then might respond to
unintended new requests the client might make.

The tests also assert a bunch of things manually instead of using
expectations when building the mock and calling server.verify().
2023-11-22 10:02:32 +01:00
Richard van der Hoff c9ddf92e25 Disable coverage checking for js_tracing 2023-11-22 07:37:21 +00:00
Jonas Platte c7712b52e6 crypto: Use Option instead of JsOption
We don't need to distinguish null from an absent field in any of the
places we used JsOption, so a regular Option is better.
2023-11-21 16:35:07 +01:00
Richard van der Hoff ead29388f2 crypto: Add instrument annotations to various methods 2023-11-21 14:31:41 +00:00
Benjamin Bouvier 06c9a1a355 Update crates/matrix-sdk/src/sliding_sync/room.rs
Co-authored-by: Jonas Platte <jplatte@matrix.org>
2023-11-21 14:50:04 +01:00
Benjamin Bouvier 0ed4a9950c test: add a unit test for the group avatar being set and unset 2023-11-21 14:50:04 +01:00
Benjamin Bouvier 844340e0f7 sliding sync: fix unsetting the avatar in a sliding sync room
The meaning of "null" and "undefined" were conflated by Ruma, previously. This updates to the latest Ruma, which changed the `avatar` type from
`Option` to `JsOption` and thus allowed us to distinguish both cases: `null` means the avatar has been unset, `undefined` means it's not changed
since the previous request.
2023-11-21 14:50:04 +01:00
Benjamin Bouvier 692be61043 test: add an integration test for avatar in group conversations 2023-11-21 14:50:04 +01:00
Jonas Platte d0b6771251 crypto: Simplify double reference handling 2023-11-21 13:15:27 +01:00
Jonas Platte 47298b9200 test: Fix indentation 2023-11-21 13:15:27 +01:00
Jonas Platte a262cb23d9 Fix rustc, clippy warnings 2023-11-21 13:15:27 +01:00
Richard van der Hoff a881cd0712 crypto: Improve logging in receive_keys_claim_response 2023-11-21 11:40:48 +01:00
Richard van der Hoff c536760fc1 Improve performance of share_room_key (#2862)
Encryption doesn't usually require access to the user identity, so we can skip loading that from the store.

Unfortunately that means a fair bit of refectoring, in the form of replacing Device with ReadOnlyDevice.

This reduces the time taken to encrypt a message in a large room from about 3 seconds to 1 second.
2023-11-20 18:46:58 +00:00
Timo 894f4c218d element call: Remove E2EEenabled flag (#2847)
This is a deprecated flag for element call using livekit. It was used to enable/disable matrix signalling event encryption. This is not relevant for embedded mode at all since there the hosting client is taking care of encryption.

---

* Remove E2EEenabled flag from the rust sdk.
This is a deprecated flag for element call using livekit. It is replaced
by the `password` and the `perParticipantE2EE` flag.
If `perParticipantE2EE` is set to `false`
and there is now password encryption is disabled implicitly.

Signed-off-by: Timo K <toger5@hotmail.de>

* `cargo +nightly fmt`

Signed-off-by: Timo K <toger5@hotmail.de>

* change test based on review

Signed-off-by: Timo K <toger5@hotmail.de>

* Apply suggestions from code review

---------

Signed-off-by: Timo K <toger5@hotmail.de>
Co-authored-by: Benjamin Bouvier <public@benj.me>
2023-11-20 16:43:33 +01:00
Jonas Platte 6472ba5109 Upgrade UniFFI 2023-11-20 11:43:05 +01:00
Benjamin Bouvier bcf33c0bcb Test that a live read receipt update received in sliding sync updates the timeline 2023-11-20 10:53:38 +01:00
Benjamin Bouvier fe541bc601 sliding sync: include read receipts into room updates so they're handled by the timeline too 2023-11-20 10:53:38 +01:00
Richard van der Hoff 2d3ee89477 delint, again 2023-11-19 14:50:02 +00:00
Richard van der Hoff cb1827f151 delint 2023-11-17 18:37:57 +00:00
Richard van der Hoff 4299697935 Implement a custom event formatter for javascript logging
Somehow `fmt::pretty` manages to be both overcomplicated and not flexible
enough.

The driver here is that I want to put the event "fields" on a separate line to
the message.
2023-11-17 18:30:21 +00:00
Richard van der Hoff 7e53c6821b Improve performance of get_missing_sessions (#2845)
Two sets of improvements to `get_missing_sessions` here:

 * Currently, for any users who have an empty device list, we call `KeyQueryManager::wait_if_user_key_query_pending`, which waits up to 5 seconds for a `/keys/query` response. (Arguably, we should be waiting longer: it is not unusual for such a request to take a while.)

   The problem is that that user's server may have been blacklisted, in which case we won't even be trying to do `/keys/query` resquests for that user, so we'll be waiting for something that never happens.

   To fix this, let's check the failures list when deciding if we should wait for a user's devices.

 * Separately, but closely related: for each user thus affected, we do the wait *in series*. This is a bit silly: there is no point waiting 50 times. We can parallelise the work.

Fixes #2793.

---

* Move `get_user_devices` to `IdentityManager`

... since it's going to need to interact with the `FailuresCache` which is
stored there.

* `get_user_devices_for_encryption`: don't wait for failed servers

* `get_missing_sessions`: wait for users in parallel

Rather than waiting for each pending user in series, do all the waits in
parallel.

* Changelog

* Update crates/matrix-sdk-crypto/src/identities/manager.rs

* Address review comments
2023-11-17 12:45:16 +01:00
Benjamin Bouvier f21a9b704b doc: update doc comment for OlmMachine::receive_sync_changes and mention it in the changelog
Fixes #2846.

Update crates/matrix-sdk-crypto/src/machine.rs

Co-authored-by: Jonas Platte <jplatte@matrix.org>
2023-11-16 16:53:21 +01:00
Jonas Platte cb08e5a103 crypto: Fix some typos 2023-11-16 15:58:28 +01:00
Jonas Platte e43a25a703 Avoid verbose string conversions when logging / printing 2023-11-16 15:58:28 +01:00
Jonas Platte ee9af5f501 crypto: Remove redundant tracing event field
Already logged as part of the parent span.
2023-11-16 15:58:28 +01:00
Jonas Platte f9aeb590e0 crypto: Generalize encryption methods 2023-11-16 15:58:28 +01:00
Jonas Platte 2d2eef8b0e crypto: Improve some documentation strings 2023-11-16 15:58:28 +01:00
Jonas Platte bfd2a1c445 Upgrade ruma crates to pull in bugfixes
Includes the following bugfixes:

- Fix the name of the fallback text field for extensible events in
  `RoomMessageEventContentWithoutRelation::make_reply_to_raw()`
- Allow to deserialize `(New)ConditionalPushRule` with a missing `conditions`
  field
- Fix deserialization of `claim_keys` responses without a `failures` field
2023-11-16 11:06:19 +01:00
Timo 6e5682d8d2 ffi: Add get_element_call_required_permissions 2023-11-15 12:00:53 +01:00
Alfonso Grillo 4a428b4731 Update ruma-events 2023-11-15 11:49:42 +01:00
Mauro c24830d794 ffi: Add a method to check if MSC 4028 is enabled on the homeserver 2023-11-15 09:30:23 +00:00
Richard van der Hoff 5786b1a631 Update changelog for matrix-sdk-crypto (#2837)
- Add an entry which I forgot for #2805

 - Reorder a few other items that have been added since
 https://github.com/matrix-org/matrix-rust-sdk/pull/2591.
2023-11-10 12:19:40 +00:00
Val Lorentz 445bf3b02a Add missing "room_id" to test_json::MEMBERS
It doesn't matter at the moment as the only test using `test_json::MEMBERS`
does not rely on the event being valid, but it shows this error
nonetheless:

```
2023-11-10T08:54:29.920782Z DEBUG receive_members{room_id="!hIMjEx205EXNyjVPCV:localhost"}: matrix_sdk_base::client: Failed to deserialize member event: missing field `room_id` at line 1 column 297 event_id="$151800140517rfvjc:localhost"
```

and https://spec.matrix.org/v1.8/client-server-api/#get_matrixclientv3roomsroomidmembers
says it is a required key.
2023-11-10 09:35:47 +00:00
Richard van der Hoff 71a2d23bf3 Handle missing devices in /keys/claim responses (#2805)
Keep a record of devices that were included in a /keys/claim request, and then, if they are missing in the response, register them as "failed".
2023-11-09 18:30:10 +00:00
Damir Jelić 955d611aaa Bump our deps so we pull in the new release of ruma-client-api 2023-11-09 17:40:03 +01:00
Ivan Enderlin 0f4a175a99 Merge pull request #2833 from matrix-org/mauroromito/notification_has_mention
feat (bindings): `has_mention` in `NotificationItem`
2023-11-09 11:39:33 +01:00
Mauro b553dbb31c Merge branch 'main' into mauroromito/notification_has_mention 2023-11-09 11:14:56 +01:00
Benjamin Bouvier 1abe039582 style: decrease indent in GroupSessionManager::mark_request_as_sent 2023-11-09 11:01:50 +01:00
Benjamin Bouvier 6c490b7aec crypto: inline GroupSessionCache::get_with_id into its single callsite 2023-11-09 11:01:50 +01:00
Benjamin Bouvier c17acd5fe3 crypto: remove direct usage of GroupSessionCache::sessions_being_shared outside the struct 2023-11-09 11:01:50 +01:00
Benjamin Bouvier 8c05d09e4d crypto: remove usage of GroupSessionCache::sessions fields in external users 2023-11-09 11:01:50 +01:00
Jonas Platte 72254caf08 sdk: Enable indexeddb in docsrs feature
… so `ClientBuilder::indexeddb_store` is visible on docs.rs.
2023-11-09 09:25:39 +01:00
Mauro Romito b232cd37e8 implement has_mentions 2023-11-08 17:53:06 +01:00
Jonas Platte 6baf092bc8 sdk: Exclude query parameters from logging
Unfortunately there are a few requests like
check_registration_token_validity that include secrets in the query
parameters.
2023-11-08 10:58:42 +01:00
Jonas Platte c109119b35 sdk: Clean up http_client logging
- Log URI instead of separate homeserver, path
- Always log query parameters (not just for sliding sync)
- Only log request size for requests that could have a body based on the
  HTTP verb
2023-11-08 09:33:39 +01:00
Benjamin Bouvier 8bce5e2416 oidc: add custom hex display to SessionHash
The most important thing is that it's stable and doesn't miss any byte.
2023-11-07 16:44:27 +01:00
Benjamin Bouvier a03b29ac70 oidc(style): avoid qualifying module name when not needed 2023-11-07 16:44:27 +01:00
Benjamin Bouvier c7f7941734 oidc: use hex logging for the hashed oidc tokens 2023-11-07 16:44:27 +01:00
Kévin Commaille 8895ce40d1 Add test for PaginationOptions::until_num_items
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-11-07 12:36:01 +01:00
Kévin Commaille edf32e8941 Store back-pagination tokens in same order as timeline
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-11-07 12:36:01 +01:00
Kévin Commaille 73ddd34cb1 Make several requests if the back-pagination token is not updated
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-11-07 12:36:01 +01:00
Kévin Commaille 0916c93641 ui: Update back-pagination token with the first or last event added
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-11-07 12:36:01 +01:00
Kévin Commaille 8a65e32e7e ui: Update back-pagination token even if chunk is empty or event fails to deserialize
Otherwise back-pagination goes in a loop because the token is never correct

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-11-07 12:36:01 +01:00
Jonas Platte 91c4bc0b3e Upgrade tracing-opentelemetry 2023-11-06 18:41:48 +01:00
Jonas Platte 6f710063b5 Upgrade mas-oidc-client 2023-11-06 18:41:48 +01:00
Jonas Platte e788a6b099 ffi: Simplify Drop implementation for Client 2023-11-06 16:16:40 +01:00
Jonas Platte 8c1baf6ba8 crypto-ffi: Simplify ManuallyDrop usage 2023-11-06 16:16:40 +01:00
Damir Jelić 99032511aa Order the changelog, new entries at the top 2023-11-06 15:17:39 +01:00
Damir Jelić 645bbd67df Remove a unused error type 2023-11-06 14:19:12 +01:00
Damir Jelić 26ede608b0 Add a method which checks if a backup decryption key matches a backup info 2023-11-06 14:19:12 +01:00
Damir Jelić 554aa0404a Add a higher level method to decrypt backed up room keys 2023-11-06 14:19:12 +01:00
Damir Jelić 3438e7de9b Add a higher level method to sign backup versions (#2819) 2023-11-06 12:50:51 +00:00
Damir Jelić 44bb9a3d8f Add a method to create an ExportedRoomKey from a BackedUpRoomKey 2023-11-06 13:41:57 +01:00
Damir Jelić bc5b190509 Add a method to get the RoomKeyBackupInfo to the BackupDecryptionKey 2023-11-06 12:41:22 +01:00
Damir Jelić 2e20f00d99 Add an example for the secret storage support 2023-11-06 10:41:44 +01:00
Damir Jelić 760053b15d Add a test for the secret storage support in the main crate 2023-11-06 10:41:44 +01:00
Damir Jelić e599fa1ccf Add secret storage support to the main SDK crate 2023-11-06 10:41:44 +01:00
Jonas Platte c7fbfd4db8 ffi: Add MediaFileHandle::persist 2023-11-06 10:32:11 +01:00
Jonas Platte ad392a1977 sdk: Add MediaFileHandle::persist 2023-11-06 10:32:11 +01:00
Jonas Platte 57136247bf ffi: Add use_cache parameter to get_media_file 2023-11-06 10:32:11 +01:00
Damir Jelić e5b06bd6d8 Enable backups in the crypto crate by default 2023-11-03 19:17:10 +01:00
Damir Jelić beb01eacfa fixup! Use the better Signatures type in the MegolmV1BackupKey type 2023-11-03 17:01:47 +01:00
Damir Jelić 1e9fab1e4e Use the better Signatures type in the MegolmV1BackupKey type 2023-11-03 17:01:47 +01:00
Benjamin Bouvier 1be7fab4fd ffi: have the (ffi) NotificationClient keep the (ffi) Client alive
Otherwise, it's possible for the `NotificationClient` to be destroyed *after* the ffi `Client`, and then the hack introduced in the previous commit won't work.
2023-11-03 16:54:54 +01:00
Benjamin Bouvier ad5761bfb5 fix(ffi): don't leak Client instances
A detached task was spawned to react upon session changes, and that task captured a clone of the current `Client`.
This caused a leak of the `Client`, because that task would never get aborted, and would not stop by itself.
The fix here consists in having `Client::set_delegate` return a task handle that needs to be stashed by the FFI
users, and cancelled when the Client gets out of scope. This fixes the leak, by removing the last reference onto
the Client.

Then, when dropping the Client, we have to drop the Stores in it. These stores may be sqlite-based stores, which
make use of deadpool. Deadpool has a sync wrapper that will call `block_on` in a `drop` method, and as such it
requires to be in the scope of a tokio runtime to run properly. To avoid breaking all abstractions and giving
access to the inners of the `Client`, the hack used here to properly be in a runtime when dropping the stores is
to replace the inner sdk `Client` in the FFI `Client::drop` method (and replace it with a dummy client that is
minimally configured and will use in-memory stores).
2023-11-03 16:54:54 +01:00
Damir Jelić efb72063ac Add a backup specific method to import room keys 2023-11-03 15:34:11 +01:00
Jonas Platte 9ef6103912 Insert strategic Box::pin to reduce async stack size 2023-11-03 12:23:59 +01:00
Jonas Platte 71c6b98d6a crypto: Box inner field of Account
This reduces its stack size to less than a third of what it previously
was and thus helps with async fn stack size problems.
2023-11-03 12:23:59 +01:00
Jonas Platte dc86835ae2 base: Box large RoomInfo fields
RoomInfo is often passed around by value, including in futures where
holding types with a large stack size is especially problematic¹.
It might make sense to move the actual data of (Base)RoomInfo into
an inner struct that is always held inside a Box or Arc, but this change
should have most of the benefits of that while being a bit simpler.

¹ https://github.com/rust-lang/rust/issues/69826
2023-11-03 12:23:59 +01:00
Benjamin Bouvier ab4c524212 crypto(perf): don't hold the cache lock while waiting on a user key query (#2806)
* crypto(fix): don't hold the cache lock while waiting on a user key query

Fixes #2802. The lock was only useful to sync the database and the in-memory cache for the users awaiting a key query request.
So it's possible to slightly tweak the API by moving the method from `SyncedKeyQueryManager` to non-synced `KeyQueryManager`, and require a
`StoreCacheGuard` (i.e. the owned lock, so we can manually drop it when we feel like so).

I've looked at all the other methods, and they do require the cache for writing into it and the store.
At the limit we could also move `SyncedKeyQueryManager::users_for_key_query`
into `KeyQueryManager`, but the lock in there is hold for a very short-time, so it shouldn't be an issue.

* Add test for the key query deadlock while waiting for the response.

* Update crates/matrix-sdk-crypto/src/machine.rs

Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
2023-11-03 11:36:54 +01:00
Richard van der Hoff c2f422209f Review comment: process failed devices together 2023-11-03 10:43:26 +01:00
Richard van der Hoff d90c623375 Add a test for devices with no key map 2023-11-03 10:43:26 +01:00
Richard van der Hoff abd6779210 Inline OlmMachine::receive_keys_claim_response
it's a bit pointless.
2023-11-03 10:43:26 +01:00
Richard van der Hoff d48c27dc86 Remove redundant key_id arg on create_session test helper 2023-11-03 10:43:26 +01:00
Richard van der Hoff 303417eae2 Factor out SessionManager::create_sessions
... and use it in some tests.

Simplify some of the test code by not building a whole keys/claim response.
2023-11-03 10:43:26 +01:00
Richard van der Hoff 017d72e80f Hoist check for missing OTKs to SessionManager
`Account::create_outbound_session` no longer takes an entire list of keys;
rather it takes a single key and it is up to the caller to pick a key out of
the list.

This in turn means that `SessionCreationError` loses one of its reason codes.
2023-11-03 10:43:26 +01:00
Timo d7f6231acd Add perParticipantE2EE to element call url. (#2807)
* Add `perParticipantE2EE` to element call url
* add ffi
* nightly fmt
* refactor to use enum + test
* rename to PerParticipantKeys
* cleanup (spelling + formatting)

Signed-off-by: Timo K <toger5@hotmail.de>
2023-11-03 10:42:50 +01:00
Marco Romano 6a27fc2e04 Upgrade uniffi
This will include https://github.com/mozilla/uniffi-rs/pull/1781
Which fixes https://github.com/mozilla/uniffi-rs/issues/1760
2023-11-03 10:19:20 +01:00
Jonas Platte 3481cde1dc Fix unquoted strings in tracing fields 2023-11-02 17:46:38 +01:00
Jonas Platte d821d611ba sdk: Clean up logging in sliding_sync
- Don't include pos in event data, it's available in a parent span
- Remove superfluous backtick
- Rewrap an `info!` invocation
2023-11-02 17:46:38 +01:00
Jonas Platte 4485abbfdf Replace all two uses of async-std with equivalent tokio functionality 2023-11-02 17:21:48 +01:00
Jonas Platte 2d19c7ad65 crypto: Use Option::map in UsersForKeyQuery::maybe_register_waiting_task 2023-11-02 17:21:48 +01:00
Jonas Platte 1692460b30 Simplify dependency specifications for tokio
matrix-sdk-common and matrix-sdk-crypto were repeating things that would
be inherited from the workspace dependency specification anyways.
2023-11-02 17:21:48 +01:00
Benjamin Bouvier 250d63c6da fix: change the event_type after encrypting
The event_type passed to `encrypt_room_event_raw` must be the one of the cleartext event, not `m.room.encrypted`. The returned event has the expected type.
2023-11-02 16:56:50 +01:00
Jonas Platte 0a33642851 widget: Change content to RawValue representation 2023-11-02 16:56:50 +01:00
Jonas Platte 64c9fa5542 sdk: Allow different raw JSON types for send_raw, send_state_event_raw 2023-11-02 16:56:50 +01:00
Jonas Platte d042bcce04 crypto: Optimize OutboundGroupSession::encrypt 2023-11-02 16:56:50 +01:00
Jonas Platte 7d52322687 crypto: Update raw encryption methods to take &Raw content 2023-11-02 16:56:50 +01:00
Jonas Platte b797635255 crypto: Restrict visibility of internal types
This makes it more obvious that breaking changes to these types don't
break the public API.
2023-11-02 16:56:50 +01:00
Jonas Platte d9845c1658 crypto: Put event type before content for raw encryption methods 2023-11-02 16:56:50 +01:00
Daniel Abramov 4428b525ea widget: Implement limits for requests 2023-11-02 14:56:51 +00:00
Jonas Platte b67ca2c123 ci: Increase log level for coverage job 2023-11-02 12:58:03 +01:00
Jonas Platte 7be84ca71a test: Deduplicate tracing_subscriber initialization
… and set a sensible default log level.
2023-11-02 12:58:03 +01:00
Jonas Platte 9956b56a2c test: Remove unused helpers feature from integration testing crate 2023-11-02 12:58:03 +01:00
Jonas Platte afcc7022a2 Exclude remaining Debug impls from coverage reporting 2023-11-02 12:58:03 +01:00
Benjamin Bouvier 8de33f68f3 integration tests: randomize user names better
In the previous situation, running the tests with `cargo test` would sometimes fail because despite appending the number of milliseconds since
the start of epoch to the user names, some user names would clash across different tests, leading to unexpected results. This fixes it by using
an actual RNG in there, so the names don't ever clash.
2023-11-01 07:57:46 +01:00
Damir Jelić 2efb09907b Add a minimal integration test that sends a message in an encrypted room (#2799) 2023-10-31 19:45:18 +01:00
Jonas Platte 91e7f2f722 sdk: Add changes to send-event API to changelog 2023-10-31 12:46:10 +01:00
Kévin Commaille 7e1eaddf5d Bump tracing in cargo manifest
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-10-31 11:18:44 +00:00
Jonas Platte 61eb9cea8c sdk: Improve documentation of send, send_raw 2023-10-31 11:13:25 +01:00
Jonas Platte a00c0c1c02 ffi: Fix outdated / misplaced comment 2023-10-31 11:13:25 +01:00
Jonas Platte 3fc1b3adb9 sdk: Update argument order for send_state_event_raw 2023-10-31 11:13:25 +01:00
Jonas Platte 1609a73e99 sdk: Update argument order for send_raw 2023-10-31 11:13:25 +01:00
Jonas Platte 8f108d4064 sdk: Fix tracing span field "encrypted" in send_raw 2023-10-31 11:13:25 +01:00
Jonas Platte 463a02a4ef sdk: Make transaction_id truly optional for send and send_raw
… by removing the parameter and returning a named future with a
builder-style `with_transaction_id` method.
2023-10-31 11:13:25 +01:00
Jonas Platte 8a1506206b sdk: Clean up logging in send_raw 2023-10-31 11:13:25 +01:00
Jonas Platte 4b702da8e8 Make IntoFuture implementations a little easier to read and write 2023-10-31 11:13:25 +01:00
Jonas Platte 18b714116e sdk: Stop re-exporting named futures in regular modules
Instead make futures modules part of the API. It is extremely uncommon
to actually refer to a type that implements `Future` by its name / path,
so it's better if these don't show up in documentation pages that are
already large and somewhat cluttered.
2023-10-31 11:13:25 +01:00
Benjamin Bouvier 380735ab46 crypto: put the KeyQueryManager in the IdentityManager 2023-10-31 10:42:14 +01:00
Benjamin Bouvier 4158d00fac crypto: rename KeyQueryManager::tracked_user_loading_lock to loaded_tracked_users 2023-10-31 10:42:14 +01:00
Benjamin Bouvier 56aff649c5 crypto: introduce a KeyQueryManager 2023-10-31 10:42:14 +01:00
Benjamin Bouvier f945a50d22 Update crates/matrix-sdk-ui/src/timeline/mod.rs 2023-10-30 16:37:03 +01:00
Kévin Commaille 901518d745 Merge compare_receipts and pub_or_priv_receipt into a more generic method
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-10-30 16:37:03 +01:00
Kévin Commaille 1fe4bff05c Improve docs
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-10-30 16:37:03 +01:00
Kévin Commaille 3690bdd6a1 ui: Add regression test for clearing read receipts
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-10-30 16:37:03 +01:00
Kévin Commaille 70eb400d11 ui: Add method to know the position in the timeline of a user read receipt
Even if the event it applies to is not visible

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-10-30 16:37:03 +01:00
Kévin Commaille 1c602a8919 ui: Clear all read receipts maps
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-10-30 16:37:03 +01:00
Benjamin Bouvier e4ec8f03eb crypto: remove useless fallibility of StoreTransaction::new 2023-10-30 16:08:06 +01:00
Benjamin Bouvier 597cff5d9d crypto: make it impossible to have two Accounts alive at the same time 2023-10-30 16:08:06 +01:00
Daniel Abramov 7dde4ec1e8 widget: Add reading of message-like events 2023-10-30 14:41:21 +01:00
Daniel Abramov 0f420a61dc widget: Add tests for non-allowed matrix requests 2023-10-30 14:41:21 +01:00
Benjamin Bouvier 9d5e7c59f3 Fix tracing timer API so it works with updated tracing 2023-10-30 14:34:56 +01:00
Benjamin Bouvier 1f534821f6 Bump tracing 2023-10-30 14:34:56 +01:00
Jonas Platte 245c102169 examples: Add required clap feature for example-timeline 2023-10-30 12:26:34 +01:00
Benjamin Bouvier 1da785e6cb fix(crypto): upload device keys *before* sending the keys signature during XSigning bootstrapping
There was a bug previously, that the cross-signing bootstrapping could include a signature for a device key that hadn't been uploaded yet.
This fixes it by returning a third (!) request in `bootstrap_cross_signing`, that must be sent as the second in order, and will upload
keys, if required.

Also tweaks documentation. Fixes #2749.
2023-10-27 16:22:24 +02:00
Benjamin Bouvier f917b32407 crypto: remove useless async in a few functions 2023-10-27 16:22:24 +02:00
Benjamin Bouvier 631ab26d8b Rename some variables in crypto related to cross-signing bootstrapping 2023-10-27 16:22:24 +02:00
Benjamin Bouvier 0f442b4c83 crypto: don't use a transaction when it can be avoided
The transaction is useless since the account is used in read-only mode here.
2023-10-27 16:22:24 +02:00
Richard van der Hoff 0c333ed335 Refactor olm message decryption logic (#2751)
The driver for this is really to make sure that we log a warning whenever there is an error, but tbh IMHO the result is somewhat easier to understand.
2023-10-27 12:57:18 +01:00
Jonas Platte 28c4f2dc14 base: Inline MemoryStore inherent methods into StateStore impl block
They were not used anywhere else and had no reason to exist as inherent
methods.
2023-10-27 13:53:26 +02:00
Jonas Platte 686fc99ebd sdk: Replace dashmap usage by std types 2023-10-27 13:53:26 +02:00
Jonas Platte 113bdbd835 base: Replace dashmap usage by std types 2023-10-27 13:53:26 +02:00
Benjamin Bouvier 1d90dd554c Test some verification getters in the heavyweight verification integration test 2023-10-27 13:03:20 +02:00
Jonas Platte 05a1021724 Use assert_let! instead of assert_matches! with bindings 2023-10-26 17:29:29 +02:00
Jonas Platte 23571d0257 ui: Replace qualified path with use 2023-10-26 17:29:29 +02:00
Benjamin Bouvier c533297efd test: move the mocked endpoints into their own functions
Code-motion only.
2023-10-26 17:10:57 +02:00
Benjamin Bouvier 870faa48d1 tests: add mutual verification test 2023-10-26 15:12:34 +02:00
Jonas Platte a515bc8f03 ffi: Remove tokio::Runtime::block_on usage in async fn 2023-10-25 16:16:58 +02:00
Jonas Platte bc81cc317f ui: Log event type when an event fails to deserialize 2023-10-25 15:15:09 +02:00
Stefan Ceriu 570ef38de3 Remove unused anyhow import 2023-10-24 17:00:08 +02:00
Benjamin Bouvier 468337f026 Update bindings/matrix-sdk-ffi/src/session_verification.rs 2023-10-24 17:00:08 +02:00
Stefan Ceriu 040d095a04 Change the is_verified flag source to device.is_cross_signed_by_owner as theoretically the previous implementation was wrong 2023-10-24 17:00:08 +02:00
Stefan Ceriu fa90269e7e Fixes vector-im/element-x-ios/issues/1868 - Incorrect is_verified flag after successfully running verification flow
- the inner user_identity isn't automatically updated when the flow finishes, needs to be fetched again from encryption
2023-10-24 17:00:08 +02:00
Benjamin Bouvier 93edf7a064 tests: add test for cross-signing bootstrapping and unchecked self-verification 2023-10-24 15:20:15 +02:00
Jonas Platte 79065edabf ui: Test next_event_limit for different pagination strategies 2023-10-24 14:04:07 +02:00
Jonas Platte cd1e3928ad ui: Exclude another Debug impl from coverage reporting 2023-10-24 14:04:07 +02:00
Jonas Platte 61335af40d widget: Add a test for receiving live events 2023-10-24 12:58:39 +02:00
Jonas Platte a0128a94ef base: Log when the same sync response is received twice 2023-10-24 12:58:39 +02:00
Damir Jelić 95ced18edd Implement Default for the CrossSigningKeyExport
Co-authored-by: Jonas Platte <jplatte@matrix.org>
2023-10-24 11:23:45 +02:00
Damir Jelić cd310d52d4 Add a convenience method to check if we have all cross-signing keys 2023-10-24 11:23:45 +02:00
Damir Jelić dc92ce8b40 Add a convenience method to get your own device out of the store 2023-10-24 11:23:45 +02:00
Daniel Abramov b0aa0ec5de widget: Add unit test to cover possible "deadlock" 2023-10-23 22:31:56 +02:00
Daniel Abramov d81d2bf01a widget: Let machine's process() return Action 2023-10-23 22:31:56 +02:00
Richard van der Hoff 7d2d1a53bf Exclude Store from tracing
Debug output for the `Store` is extremely verbose, so we don't want to log it
every time we touch this function.
2023-10-23 19:50:25 +02:00
Benjamin Bouvier 0107bcfd0d cross-signing bootstrapping: test that failure in bootstrapping doesn't block login 2023-10-23 19:38:30 +02:00
Benjamin Bouvier e1feefcbb0 chore: make clippy happy 2023-10-23 19:38:30 +02:00
Benjamin Bouvier 456472af6c tests: for cross-signing bootstrapping 2023-10-23 19:38:30 +02:00
Benjamin Bouvier 536d1ab527 feat: allow cross-signing bootstrapping in OIDC too 2023-10-23 19:38:30 +02:00
Benjamin Bouvier 0754c75436 client builder: add a method to set encryption settings 2023-10-23 19:38:30 +02:00
Benjamin Bouvier 1c0c9b8ab3 encryption: prefix a few test case names with test_ 2023-10-23 19:38:30 +02:00
Benjamin Bouvier 11f4b54394 encryption: add documentation for the new methods 2023-10-23 19:38:30 +02:00
Damir Jelić 80bbd77f3b feat: allow automatically enabling cross-signing on login 2023-10-23 19:38:30 +02:00
Jonas Platte 6f992d1ad8 ui: Add a test for updating member profiles 2023-10-23 19:34:23 +02:00
Jonas Platte 1ce67cc9e6 test: Use DEFAULT_TEST_ROOM_ID in more places 2023-10-23 19:34:23 +02:00
Jonas Platte 254efed150 test: Rename DEFAULT_SYNC_ROOM_ID to DEFAULT_TEST_ROOM_ID
… and move to matrix-sdk-test's crate root.
2023-10-23 19:34:23 +02:00
Valere f43eb94a8c Better documentation for share_room_key (#2741)
Co-authored-by: Damir Jelić <poljar@termina.org.uk>
2023-10-23 18:37:56 +02:00
Damir Jelić 9ccc36ccc8 Add more tests for the secret storage support in the crypto crate 2023-10-23 18:35:54 +02:00
Benjamin Bouvier 17dead5641 read receipts: avoid allocating an indexmap consumed as an iterator thereafter 2023-10-23 17:51:10 +02:00
Benjamin Bouvier 3ea9b8ed53 Apply suggestions from code review 2023-10-23 17:26:11 +02:00
Kévin Commaille a07062a990 Use std::cmp::Ordering
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-10-23 17:26:11 +02:00
Kévin Commaille 7b2a502e7d ui: Add tests for initial user read receipt
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-10-23 17:26:11 +02:00
Kévin Commaille 177f15b2e5 ui: Allow to get latest user read receipt for any room data provider
Allows to test the method with unit test

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-10-23 17:26:11 +02:00
Kévin Commaille 3bd10a05c1 Add a test for receipt comparison
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-10-23 17:26:11 +02:00
Kévin Commaille ff83f5abcb ui: Handle read receipts in the main thread
Improves the compatibility with clients using threads

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-10-23 17:26:11 +02:00
Kévin Commaille ddb4bf13b1 ui: Add user_receipt method on RoomDataProvider
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-10-23 17:26:11 +02:00
Stefan Ceriu 0006f85103 Make reldbg inherit dbg and contain debug symbols 2023-10-23 15:31:22 +02:00
Timo 4933a50496 Add active calls to RoomInfo 2023-10-23 15:05:12 +02:00
Benjamin Bouvier a052f26748 Bump synapse image version in integration testing 2023-10-23 14:56:11 +02:00
Benjamin Bouvier b9b4e4e1e0 test: bump the sliding-sync image versions 2023-10-23 13:55:42 +02:00
Benjamin Bouvier 55257f2b8d test: remove uninteresting smoke test for sliding sync in integration suite 2023-10-23 13:55:42 +02:00
Benjamin Bouvier 6368c699c2 test: Merge the two integration test suites into a single one 2023-10-23 13:55:42 +02:00
Damir Jelić 7440ce0a0c Use the GlobalAccountDataEventType instead of a string for the event type 2023-10-23 10:24:14 +02:00
Damir Jelić fda24d312b Re-export the MacError type of the secret storage module 2023-10-23 10:24:14 +02:00
Richard van der Hoff 21a4e7d1b2 Clean up to-device message logging (#2747) 2023-10-20 17:54:27 +00:00
Richard van der Hoff ed6f658405 Fix spurious "unknown secret request" warning (#2755) 2023-10-20 18:37:17 +01:00
Daniel Abramov 4ea8ecaac8 widget: Add missing unit tests for error cases 2023-10-20 17:52:10 +02:00
Benjamin Bouvier 71627a29a6 style: use not().then() in one place 2023-10-20 17:04:40 +02:00
Benjamin Bouvier 2f90f9d55d account: make it more obvious what Account::clone_internal is, so it can't be misused 2023-10-20 17:04:40 +02:00
Benjamin Bouvier eb5bf4d51f store cache: copy the account back into the cache if there were pending changes to it 2023-10-20 17:04:40 +02:00
Benjamin Bouvier fc35d86a69 test: use unwrap() instead of Result in a test 2023-10-20 17:04:40 +02:00
Benjamin Bouvier 08450da5e1 crypto: move Store::mark_tracked_users_as_up_to_date to the StoreCache 2023-10-20 17:04:40 +02:00
Benjamin Bouvier 9ecc6ddd1e crypto: move Store::tracked_users to StoreCache 2023-10-20 17:04:40 +02:00
Benjamin Bouvier 71229dd98b crypto: remove useless parameter in receive_device_changes 2023-10-20 17:04:40 +02:00
Benjamin Bouvier a2702e6d98 crypto: move Store::update_tracked_users to the StoreCache 2023-10-20 17:04:40 +02:00
Benjamin Bouvier 0feccc7fee crypto: remove useless call to self.cache in Store::users_for_key_query
The store cache can be filled lazily when it's actually needed. It's not needed in this
function here, and may be needed in another function the caller of this function may call
later. No need to preemptively fill the cache here.
2023-10-20 17:04:40 +02:00
Benjamin Bouvier f580966408 crypto: move Store::mark_user_as_changed to the StoreCache too 2023-10-20 17:04:40 +02:00
Benjamin Bouvier 537ac8a269 crypto: fix test failure 2023-10-20 17:04:40 +02:00
Benjamin Bouvier 65f4cc151c crypto: move Store::mark_tracked_users_as_changed to StoreCache 2023-10-20 17:04:40 +02:00
Benjamin Bouvier 7c51950167 crypto: move Store::ensure_sync_tracked_users to the StoreCache 2023-10-20 17:04:40 +02:00
Benjamin Bouvier 3030bcbf1e crypto: introduce a RwLock on the StoreCache 2023-10-20 17:04:40 +02:00
Benjamin Bouvier 3d7a56e468 crypto: remove inner mutable shared state from Account 2023-10-20 17:04:40 +02:00
Benjamin Bouvier 8bfcd20801 crypto: make Account not clonable and the Account in the cache optional 2023-10-20 17:04:40 +02:00
Benjamin Bouvier 3570519c0c crypto: make StoreCache::account fallible and async 2023-10-20 17:04:40 +02:00
Benjamin Bouvier a82964ac75 crypto: get rid of test-only OlmMachine::account 2023-10-20 17:04:40 +02:00
Benjamin Bouvier be96ddb24a crypto: introduce StoreCache::account() function 2023-10-20 17:04:40 +02:00
Jonas Platte 6d0ed67679 widget: Rename remaining "permissions" to capabilities
… a few uppercase Permissions were missed last time.
2023-10-20 13:28:53 +02:00
Jonas Platte 3c74809374 widget: Attach room ID to events from sync 2023-10-20 13:00:43 +02:00
Jonas Platte fc6549213b widget: Filter incoming matrix events 2023-10-20 13:00:43 +02:00
Jonas Platte f937e7d14a widget: Fix ResponseData type for notify requests 2023-10-20 13:00:43 +02:00
Daniel Abramov 9d8e5a0d08 widget: Add subscribe / unsubscribe event handling 2023-10-20 13:00:43 +02:00
Daniel Abramov 4900089669 widget: Remove obsolete allow(dead_code) 2023-10-20 13:00:43 +02:00
Jonas Platte a4fd054705 widget: Properly handle matrix driver request errors
Co-authored-by: Daniel Abramov <daniel.abramov@element.io>
2023-10-20 12:05:03 +02:00
Daniel Abramov 685c51b3af widget: Add OpenID request handling 2023-10-20 12:05:03 +02:00
Jonas Platte 70b8ac425f widget: Fix name, response fields of capabilities request 2023-10-20 09:56:36 +02:00
Jonas Platte 7582b4fda9 widget: Fix field name in supported-versions response 2023-10-20 09:56:36 +02:00
Jonas Platte a2d05ed002 widget: Remove unnecessary type wrapping
… and move some types around.
2023-10-20 09:56:36 +02:00
Jonas Platte 489d699cc5 widget: Remove unused Serialize implementation 2023-10-20 09:56:36 +02:00
Jonas Platte 561db87b64 widget: Add integration tests for sending events 2023-10-19 15:25:53 +02:00
Jonas Platte 4982f87c59 widget: Add support for send-event fromWidget requests
Co-authored-by: Daniel Abramov <daniel.abramov@element.io>
2023-10-19 15:25:53 +02:00
Jonas Platte 14cf923361 widget: Add tests for event reading requests 2023-10-19 13:01:57 +02:00
Jonas Platte 3ce7126d58 widget: Add support for read-state-event fromWidget requests
Co-authored-by: Daniel Abramov <daniel.abramov@element.io>
2023-10-19 13:01:57 +02:00
Jonas Platte 946976a561 widget: Add EventFilter::matches_state_event_with_any_state_key 2023-10-19 13:01:57 +02:00
Jonas Platte e58ee3bcf1 widget: Fix copy-paste comment error 2023-10-19 13:01:57 +02:00
Jonas Platte c0985942dd widget: Actually add request ID to process_from_widget_request span 2023-10-19 13:01:57 +02:00
Jonas Platte 3b4108e519 widget: Add Deserialize impl for StateKeySelector 2023-10-19 13:01:57 +02:00
dependabot[bot] 70524e2f5c build(deps): bump rustix from 0.37.24 to 0.37.25
Bumps [rustix](https://github.com/bytecodealliance/rustix) from 0.37.24 to 0.37.25.
- [Release notes](https://github.com/bytecodealliance/rustix/releases)
- [Commits](https://github.com/bytecodealliance/rustix/compare/v0.37.24...v0.37.25)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-10-19 11:58:24 +02:00
Jonas Platte d5bda8147f ffi: Remove _blocking functions
Except for full_room_blocking, which is apparently noticably faster.
They were only added as a workaround for a UniFFI bug that has now been
fixed.
2023-10-19 07:56:06 +02:00
Jonas Platte 02a0916bc2 widget: Rename "permissions" to "capabilities"
… to match the postMessage JSON API.
2023-10-18 18:17:31 +02:00
Jonas Platte 01ec91bda4 widget: Rename Capabilities to CapabilitiesState
… and move the None case into it to avoid having to wrap it in Option.
2023-10-18 18:17:31 +02:00
Jonas Platte 12db7516ef widget: Add get_supported_api_versions support
Co-authored-by: Timo K <timok@element.io>
2023-10-18 15:52:00 +00:00
Jonas Platte af71d831c6 Fix 'verifying' typos 2023-10-18 17:50:51 +02:00
Daniel Abramov b623c7c357 widget: Complete ContentLoaded implementation
And cover it with tests.
2023-10-18 16:44:03 +02:00
Mauro Romito 5f0e5c7407 added the with_mentions method 2023-10-18 15:42:14 +02:00
Jonas Platte 2c80307e53 widget: Add content_loaded initialization 2023-10-18 15:03:58 +02:00
Jonas Platte 1aef675a97 widget: Fix a small error in test code 2023-10-18 15:03:58 +02:00
Jonas Platte ea36eaa09a widget: Implement fromWidget response sending
… and send an error response when the request fails to deserialize.
2023-10-18 15:03:58 +02:00
Jonas Platte 9c71c2b733 widget: Rename process_message_from_widget to process_widget_message
… to make it clearer that it's not specifically about fromWidget messages.
2023-10-18 15:03:58 +02:00
Jonas Platte 46a8f4e841 widget: Clean up json! indentation in test 2023-10-18 15:03:58 +02:00
Daniel Abramov eb5f05d8c5 widget: Add missing driver requests 2023-10-18 14:44:46 +02:00
Jonas Platte 29fc3d0289 widget: Shorten tracing instrument args 2023-10-18 13:26:51 +02:00
Daniel Abramov 04fcc0bb87 widget: split parsing of common widget header 2023-10-18 13:26:51 +02:00
Daniel Abramov 77bae6f421 widget: add a note to the error handling 2023-10-18 13:26:51 +02:00
Daniel Abramov a99cb7c30f widget: move things around in function (chore)
So that most important functions (public interface) come first.
2023-10-18 13:26:51 +02:00
Daniel Abramov 6363cd5902 widget: extract capability negotiation into fn
We will need to re-use it when processing the `ContentLoaded` message
from a widget.
2023-10-18 13:26:51 +02:00
Jonas Platte 541c0ef559 widget: Add an integration test for immediate capability negotiation 2023-10-18 12:34:34 +02:00
Jonas Platte 65cc926612 widget: Add more tracing events 2023-10-18 12:34:34 +02:00
Jonas Platte c550fa80a7 widget: Coalesce matrix driver response messages into an enum 2023-10-18 12:34:34 +02:00
Jonas Platte 5113d6e161 widget: Don't alias ruma request type 2023-10-18 12:34:34 +02:00
Jonas Platte f910d10f6b widget: Rename Event -> IncomingMessage 2023-10-18 12:34:34 +02:00
Jonas Platte 29620144fe widget: Split up Machine::process and add more sanity checks 2023-10-18 12:34:34 +02:00
Daniel Abramov deff0a06f5 widget: Implement capability negotiation 2023-10-18 12:34:34 +02:00
Jonas Platte e038ced2c6 widget: Add toWidget & MatrixDriver response handling skeleton 2023-10-18 12:34:34 +02:00
Richard van der Hoff f75b2cd1d0 Documentation on /keys/query parsing functions (#2674)
These functions are a bit confusing, so I wrote some comments. I also factored out
`get_user_signing_key_from_response`, to reduce duplication and (IMHO) improve clarity.
2023-10-17 16:55:26 +01:00
Jonas Platte 7c4046e463 widget: Implement requesting of capabilities w/o init_on_content_load 2023-10-17 16:55:02 +02:00
Jonas Platte a4cc28f94a widget: Rename client module to machine 2023-10-17 16:55:02 +02:00
Jonas Platte de0543c2e2 widget: Rename settings#id to widget_id 2023-10-17 16:55:02 +02:00
Jonas Platte 4a1e4cd279 widget: Rename ClientApi to WidgetMachine 2023-10-17 16:55:02 +02:00
Jonas Platte a812f17ec4 widget: Clarify MatrixDriver's purpose 2023-10-17 16:55:02 +02:00
Jonas Platte 7c958498bf ui: Raise log level for prev_batch wait timeout
… since it can cause rather annoying problems with the SS proxy
if it happens.
2023-10-17 11:02:15 +02:00
Jonas Platte 06e3fc4235 widget: Add a failing (ignored) test for reading room messages 2023-10-17 10:54:51 +02:00
Jonas Platte 07951b88d3 widget: Separate reading of message and state events
… and use the state store for the latter.

Co-authored-by: Timo K <timok@element.io>
2023-10-17 10:54:51 +02:00
Jonas Platte 5775a6e628 widget: Group trait impls in client::outgoing 2023-10-17 10:54:51 +02:00
Jonas Platte 20021abee3 widget: Fix clippy warning 2023-10-17 10:54:51 +02:00
Jonas Platte b3f37459b7 widget: Reduce visibility on widget::matrix types and their methods 2023-10-17 10:54:51 +02:00
Jonas Platte 8496673310 sdk: Move WidgetSettings constructor to top of impl block 2023-10-17 10:54:51 +02:00
Richard van der Hoff 3c9f48dcb5 common: Add a tracing MakeWriter for writing to a JS Logger
Replace the old `tracing_subscriber::layer::Layer` with a `MakeWriter` which
can then be plugged into a `fmt::Subscriber`.
2023-10-16 20:10:41 +02:00
Jonas Platte 7f3fef5d8b ci: Run documentation CI workflow when un-drafting a PR 2023-10-16 15:44:20 +02:00
Timo 7ee872c4bd Fix avatar url and display name in element call link generation
Signed-off-by: Timo K <toger5@hotmail.de>
Co-authored-by: Jonas Platte <jplatte@matrix.org>
2023-10-16 11:00:32 +02:00
Richard van der Hoff a433d51efc Add static lifetimes to some constants
My compiler is complaining about lack of explicit lifetimes on these consts
2023-10-13 13:59:56 +02:00
Benjamin Bouvier 41a26e30e9 oidc: use sha2 to hash everything oidc-related
Hashes computed by `compute_session_hash` may be stored in the crypto store, and may or may not
be encrypted; make them slightly more secure by using a more secure hash. Also use sha2 for
the logged hashes that are useful for debugging OIDC issues.
2023-10-13 11:06:08 +02:00
Benjamin Bouvier efb16ed5b4 oidc: remove logging of hashed token
This was useful during development of the OIDC feature, but now that it's rather stable,
let's remove it from the traces.
2023-10-13 11:06:08 +02:00
Jonas Platte 735b0d2d24 ffi: Allow MessageType to contain arbitrary msgtype values, plus body
… allows the FFI type MessageLikeEventContent to hold custom msgtypes,
which is useful for notification.
Also allows sending custom msgtypes, as long as no fields other than the
msgtype itself and body are needed.
2023-10-13 10:06:07 +02:00
Jonas Platte 51ee8209bd sdk: Use BTreeSet instead of HashSet in widget tests
… for deterministic / comparable debug formatting.
2023-10-12 18:39:47 +02:00
Jonas Platte bc0e3609d0 sdk: Rewrap strings in widget tests 2023-10-12 18:39:47 +02:00
Jonas Platte a6a4695dd4 ffi: Inline local variables in WidgetSettings conversion 2023-10-12 18:39:47 +02:00
Alfonso Grillo f826999773 feature: send voice message API (#2697)
This PR adds a ffi binding for sending voice messages in the legacy format (before extensible events). It also makes minor changes in the `matrix-sdk` crate to accomodate this change.

* Add send_voice_message api

* Update ruma-events dependency

* Fix attachment info mapping

* Remove unstable dependency in attachment.rs

* Bump ruma-events

* Fix matrix-sdk Cargo.toml

* Fix formatting issues

* Refactor Voice case

* Remove clone from AttachmentInfo

* Remove duplicate code

* Remove unused imports

* Fix formatting issue

* Rename update function
2023-10-12 16:34:09 +00:00
Jonas Platte ba2a5137dc ui: Fix missing thread relation when sending reply to threaded message 2023-10-12 16:02:34 +02:00
Alfonso Grillo eadc7b9052 feat: enable push rules when changing actions (#2708) 2023-10-12 14:41:12 +02:00
Daniel Abramov b98c4772e5 widget: Define outgoing request types
This includes the requests that are sent to the matrix client (i.e.
a request to send a matrix event) as well as requests that are sent to
the widget.

The difference between this and `Action` is that `Action` is rather
"low-level" (i.e. it has a generic `SendToWidget(String)` variant),
whereas this API is a high-level API that we will use internally to
conveniently issue and `await` for outgoing responses.
2023-10-12 12:20:13 +02:00
Kévin Commaille 10393eee8d ui: Require PaginationOptions strategy to be Sync
Otherwise PaginationOption is not Send.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-10-12 09:44:40 +00:00
Jonas Platte 4e86954008 Upgrade async-compat 2023-10-11 15:21:18 +02:00
Jonas Platte 4b98d24230 Upgrade UniFFI 2023-10-11 15:21:18 +02:00
Jonas Platte d54668305e ci: Run widget tests in coverage job
… the other experimental features were already getting enabled through
matrix-sdk-ui, so don't need to be enabled explicitly.
2023-10-11 15:13:08 +02:00
Daniel Abramov 9cea46c459 widget: add unit tests for Permissions 2023-10-11 15:13:08 +02:00
Daniel Abramov f0521f72d5 widget: add serialize/deserialize for permissions
Co-authored-by: Jonas Platte <jplatte@matrix.org>
2023-10-11 15:13:08 +02:00
Benjamin Bouvier 77cb1b7f11 oidc: add cross-process lock test 2023-10-11 14:58:52 +02:00
Jonas Platte b8185c0c67 ui: Fix hidden lifetime warnings 2023-10-11 14:42:24 +02:00
Benjamin Bouvier 97844ea8af oidc: remove dead code 2023-10-11 14:18:55 +02:00
Benjamin Bouvier 51b6ecc0b8 oidc: add test for getters 2023-10-11 14:18:55 +02:00
Benjamin Bouvier 2ad567883c oidc: add test for session_token_stream 2023-10-11 14:18:55 +02:00
Benjamin Bouvier f74f2eda76 oidc: remove dead code
This code path could never be taken:

- the only way to set the cross_process_token_refresh_manager is from calling the same function
- this function is guarded against a lock, so it's not reentrant
- this function's only internally called, during `restore_session` or after a successful login:
both will set a session, hence those functions would fail beforehands if another session had
been set earlier.
2023-10-11 14:18:55 +02:00
Benjamin Bouvier 9e8c6e639b oidc: add comments and tarpaulin annotations 2023-10-11 14:18:55 +02:00
Kévin Commaille b14ac1f2b9 Add test for event visibility change
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-10-11 12:00:09 +02:00
Kévin Commaille 818a1ba992 Log inconsistent state
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-10-11 12:00:09 +02:00
Kévin Commaille d88437e707 Fix visibility of types
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-10-11 12:00:09 +02:00
Kévin Commaille dae8c0a37f Update read receipt of prev event if visibility changed
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-10-11 12:00:09 +02:00
Kévin Commaille d0f74a76d6 ui: Expose read receipts of hidden events on visible events
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-10-11 12:00:09 +02:00
Kévin Commaille 54bbb05c22 ui: Rename receipt to new_receipt
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-10-11 12:00:09 +02:00
Kévin Commaille 148c75120c ui: Move maybe_add_implicit_read_receipt as a method of TimelineInnerStateTransaction
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-10-11 12:00:09 +02:00
Kévin Commaille aca6210b6b ui: Keep track of read receipts on all events
Not only event items

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-10-11 12:00:09 +02:00
Benjamin Bouvier 1a56d6c0d8 fix: live-migrate LatestEvent data from the former format to the newer
#2587 introduced a breaking change in the serialized format of `RoomInfo`, changing the `event`
field format in particular, without a migration. As a result, this lead to users state stores
being invalidated for containing incorrect data, and thus being logged out.

This mitigates the issue by making sure that the LatestEvent type is either deserialized as its
newer format (aka `SerializedLatestEvent`) or its older format (aka `SyncTimelineEvent`). This
way, we maintain compatibility with the previous format. We always serialize to the new one, so
we'd only run this migration once.
2023-10-11 09:08:12 +00:00
Daniel Abramov 3567c9dc65 widget: move client into own module and split up 2023-10-11 09:50:58 +02:00
Daniel Abramov d8d136b330 widget: change signature of the ClientApi
Return `Self` and the channel to process incoming actions.
2023-10-11 09:50:58 +02:00
Daniel Abramov 5b92b0ac37 widget: move client into its own module 2023-10-11 09:50:58 +02:00
Damir Jelić c2bb76029a Rename the encrypt_with_iv method so it's clear that it also can decrypt 2023-10-10 18:15:45 +02:00
Damir Jelić 372e0d3d98 Secret storage support
Co-authored-by: Ivan Enderlin <ivan@mnt.io>
Co-authored-by: Denis Kasak <dkasak@termina.org.uk>
2023-10-10 18:15:45 +02:00
Jonas Platte 194c448047 ui: Update send_reply arguments
- `content` is now of type `RoomMessageEventContentWithoutRelation`,
  the relation was previously always overwritten if set
- `add_mentions` is now inferred from `content.mentions`
2023-10-10 17:14:55 +02:00
Richard van der Hoff 63fab7e292 Clean up duplicate/incomplete tracing 2023-10-10 14:28:06 +02:00
Richard van der Hoff 4e4077d6e0 Improve documentation on QrVerificationData (#2689)
I spent a while trying to figure out how all of this works.
2023-10-10 12:06:16 +00:00
Damir Jelić d62cf340c9 Pin reqwests to 0.11.20 2023-10-10 14:00:55 +02:00
Damir Jelić c1d24aea90 Upgrade the deps for the store-encryption and crypto-ffi crates 2023-10-10 14:00:55 +02:00
Damir Jelić 06bb81aaf2 fixup! Add a test ensuring that we didn't mess up our Device deserialization 2023-10-10 14:00:55 +02:00
Damir Jelić 235a8bd5ed Run cargo update for all the things 2023-10-10 14:00:55 +02:00
Damir Jelić 2fce44a16a Add a test ensuring that we didn't mess up our Device deserialization 2023-10-10 14:00:55 +02:00
Damir Jelić 97fe9614e5 Upgrade our pbkdf dependency 2023-10-10 14:00:55 +02:00
Damir Jelić cda0a5da13 Remove atomic from our deps 2023-10-10 14:00:55 +02:00
Jonas Platte 129a5e1acc ui: Wait for pagination token across multiple sync response notifs
… if wait_for_token flag is set for backwards-pagination.
2023-10-10 13:39:59 +02:00
Damir Jelić 04565378fa Only mark our own user identity as verified if it wasn't already 2023-10-10 13:04:09 +02:00
Damir Jelić 2843aef352 Ensure that the private cross-signing keys get persisted after invalidation 2023-10-10 13:04:09 +02:00
Damir Jelić 626df0b589 Test that the invalidated private cross-signing keys get correctly persisted 2023-10-10 13:04:09 +02:00
Damir Jelić 4918710cdc Add the ability to create a test IdentityManager with an arbitrary user ID 2023-10-10 13:04:09 +02:00
Kévin Commaille e674ccf5a4 Use timeline.items() instead of stream
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-10-10 12:05:57 +02:00
Kévin Commaille d25acdf237 Remove is_empty variable
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-10-10 12:05:57 +02:00
Kévin Commaille f7bf417996 ui: Test explicit read receipt ignored when implicit read receipt exists
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-10-10 12:05:57 +02:00
Kévin Commaille e778316918 ui: Do not add explicit receipts if implicit receipt is newer
Should avoid users receipts appearing on two different events in the timeline

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-10-10 12:05:57 +02:00
Kévin Commaille d03c255342 ui: Create ReadReceipts struct
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-10-10 12:05:57 +02:00
Jonas Platte a88afd818b ui: Add more tracing events around back-pagination tokens 2023-10-09 17:21:52 +02:00
Daniel Abramov 880e918a5e widget: Add missing license headers 2023-10-09 14:55:58 +00:00
Benjamin Bouvier c64d3b4b7a Introduce a store transaction for Account (#2660)
This adds a new `StoreTransaction` type, that wraps a `StoreCache` and a `Store`. The idea is that it will allow write access to the `Store` (and maintains the cache at the same time), while the `Store::cache` method will only give read-only access to the store's content.

Another new data type is introduced, `PendingChanges`, that reflects `Changes` but for fields that are properly maintained in the `StoreCache` and that one can write in the `StoreTransaction`. In the future, it wouldn't be possible to use `save_pending_changes` from the outside of a `StoreTransaction` context.

The layering is the following:

- `Store` wraps the `DynCryptoStore`, contains a reference to a `StoreCache`.
- When read-only access is sufficient, one can get a handle to the cache with `Store::cache()`.
- When a write happens, then one can create a `StoreTransaction` (later, only one at a time will be allowed, by putting the `StoreCache` behind a `RwLock`; this has been deferred to not make the PR grow too much).
- Any field in the `StoreCache` will get a method to get a reference to the cached thing: it will either load from the DB if not cached, or return the previously cached value. 
- Any field that can be written to will get a method to get a mutable reference in the `StoreTransaction`: it will either load from the cache into a `PendingChanges` scratch pad, or return the scratchpad temporary value.
- When a `StoreTransaction::commit()` happens, fields are backpropagated into the DB *and* the cache. 

Then, this `StoreTransaction` is used to update a `ReadOnlyAccount` in multiple places (and usage of `ReadOnlyAccount` is minimized so as not to require a transaction or cache function call as much as possible). With this, the read-only account only exists transiently, and it's only stored long-term in the cache.

Followup PRs include:

- making the `ReadOnlyAccount` not cloneable
- remove inner mutability from the `ReadOnlyAccount`
- add a `RwLock` on the `StoreTransaction`

Part of https://github.com/matrix-org/matrix-rust-sdk/issues/2624 + https://github.com/matrix-org/matrix-rust-sdk/issues/2000.

---

* crypto: Replace some uses of `ReadOnlyAccount` with `StaticAccountData` and identify tests

* crypto: introduce `StoreTransaction` to modify a `ReadOnlyAccount`

* crypto: introduce `save_pending_changes`, aka `save_changes` v2

* crypto: Start using `StoreTransaction`s to save the account, get rid of `Store::save_account` + `Account::save`

* crypto: use `StoreTransaction` to save an account in `keys_for_upload`

* crypto: use `StoreTransaction` and the cache in more places

* crypto: remove `Account` from the `Changes` \o/

* crypto: remove last (test-only) callers of `Store::account()`

* crypto: move `ReadOnlyAccount` inside the cache only

* crypto: use `ReadOnlyAccount` and `Account` in fewer places

whenever we can use `StaticAccountData` in place.

* crypto: make tests rely less on OlmMachine

* crypto: Don't put the `ReadOnlyAccount` behind a RwLock just yet

+ clippy
2023-10-09 14:16:06 +00:00
Kévin Commaille 41de52b6b0 ui: Reimplement compare_events_positions using all timeline events
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-10-09 12:13:03 +02:00
Kévin Commaille 155ec45a9e ui: Keep track of the order of all events in the Timeline
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-10-09 12:13:03 +02:00
Ivan Enderlin 487f85b9e3 feat: Make latest_event faster regarding member profile
feat: Make `latest_event` faster regarding member profile
2023-10-09 11:41:32 +02:00
Ivan Enderlin 76ace82298 doc(ui): Fix a typo. 2023-10-09 11:22:43 +02:00
Ivan Enderlin a61bc77572 chore(base): Clean up. 2023-10-09 11:21:56 +02:00
Jonas Platte d216414608 ui: Make loop / continue comments less ambiguous 2023-10-09 11:16:03 +02:00
Jonas Platte 23390403b6 ui: Add more tracing to pagination 2023-10-09 11:16:03 +02:00
Jonas Platte d1ad16fbab ui: Document paginate_backwards_impl 2023-10-09 11:16:03 +02:00
Benjamin Bouvier 2a78b925e4 crypto: move all the Account methods in a single impl block 2023-10-09 11:00:13 +02:00
Benjamin Bouvier 57b1442e1c crypto: rename ReadOnlyAccount to Account \o/ \o/ \o/ \o/ 2023-10-09 11:00:13 +02:00
Benjamin Bouvier 1e9c05ad6f crypto: get rid of Account \o/ \o/ \o/ 2023-10-09 11:00:13 +02:00
Benjamin Bouvier 05d65e9b60 crypto: move methods from Account to ReadOnlyAccount 2023-10-09 11:00:13 +02:00
Benjamin Bouvier 850d25d8ec crypto: tweak a few code comments 2023-10-09 11:00:13 +02:00
Benjamin Bouvier 0b818fe4a5 crypto: use a Store in the DehydratedDevice data structure as it's sufficient 2023-10-09 11:00:13 +02:00
Benjamin Bouvier 03b4e87bd9 crypto: retrieve the StaticAccountData from the store in more places 2023-10-09 11:00:13 +02:00
Benjamin Bouvier d379d755e9 Fix: recreate a rehydrated OlmMachine with the correct DeviceId 2023-10-09 11:00:13 +02:00
Benjamin Bouvier 0013963ea5 crypto: retrieve the UserId/DeviceId from store methods instead of duplicating them 2023-10-09 11:00:13 +02:00
Daniel Abramov 0726955678 widget: minor fixes in formatting, typos, etc 2023-10-09 10:55:48 +02:00
Daniel Abramov 8e501c5d6b widget: rename widget_settings -> settings mod
To stay consistent with the rest of the concise naming "conventions"
within the `widget` module.
2023-10-09 10:55:48 +02:00
Ivan Enderlin 7842611ad9 test: Use the sync_timeline_event! macro once more. 2023-10-09 10:26:08 +02:00
Ivan Enderlin c5b137a83c test(ui): Write test for EventTimelineItem::from_latest_event with cached sender info. 2023-10-09 10:24:23 +02:00
Ivan Enderlin 438c51708d chore: Address feedbacks. 2023-10-09 09:52:29 +02:00
Damir Jelić 6c9cfe1368 Bump our vodozemac version 2023-10-06 16:19:03 +02:00
Jonas Platte d85ab43b81 crypto: Replace dashmap usage in the rest of the crate 2023-10-06 14:42:36 +02:00
Jonas Platte dfabef0036 crypto: Replace dashmap usage by std types in MemoryStore 2023-10-06 14:42:36 +02:00
Jonas Platte 131c3dbf30 crypto: Put both maps in WaitQueue behind one lock 2023-10-06 14:42:36 +02:00
Jonas Platte feba68779b Remove build as parent span of room_update_handler
… but record the relationship between them using follows_from.
2023-10-06 14:01:02 +02:00
Nicolas Mauri 108508e365 Fix: wait for disk operations to finish before returning the media file in get_media_file. (#2672)
Co-authored-by: Benjamin Bouvier <public@benj.me>
2023-10-06 09:57:48 +00:00
Jonas Platte b017e49d89 crypto: Detect and fix 'sign'-related typos 2023-10-06 11:38:32 +02:00
Jonas Platte a8158ae6bf crypto: Silence clippy false-positives
Upstream issue: https://github.com/rust-lang/rust-clippy/issues/11383
2023-10-06 10:55:17 +02:00
Jonas Platte a099c7c4a9 sdk: Replace str::to_string with to_owned 2023-10-06 10:55:17 +02:00
Timo 2120acabbb sdk: Add url creation to WidgetSettings
Signed-off-by: Timo K <toger5@hotmail.de>
2023-10-05 19:54:46 +02:00
Jonas Platte 7576a73fcb Upgrade Ruma to latest crates.io release 2023-10-05 17:46:34 +02:00
Benjamin Bouvier d8c2ad7693 ffi: use Timeline::send_single_receipt instead of Room::send_single_receipt for sending read receipts
The latter will always send a query, while the former will attempt to deduplicate sending a read receipt, if the event was already marked as read.
2023-10-05 16:59:28 +02:00
Benjamin Bouvier 1d01c32491 chore: remove unused FFI send_read_marker 2023-10-05 16:59:28 +02:00
Jonas Platte 2315c46a1d sdk: Remove sync gap broadcast channels
They were a stop-gap solution for detecting limited responses and have
been obsolete since the introduction of room update handlers.
2023-10-05 09:29:59 +02:00
Alfonso Grillo aa1b871d00 ffi: Refine NotificationSettingsError type 2023-10-04 15:58:44 +02:00
Jonas Platte 504861a532 sqlite: Upgrade deadpool, rusqlite 2023-10-04 15:43:08 +02:00
Jonas Platte d3902fe375 ci: Upgrade crate-ci/typos 2023-10-04 13:48:31 +02:00
Jonas Platte 749b4df321 ui: Move magic number to a named constant 2023-10-04 13:23:47 +02:00
Jonas Platte 7482246668 test: Test timeline reset while pagination is running 2023-10-04 13:23:47 +02:00
Jonas Platte 2bc0651c94 test: Test back-pagination request deduplication 2023-10-04 13:23:47 +02:00
Jonas Platte 7f934040bc test: Test wait_for_token functionality in back-pagination 2023-10-04 13:23:47 +02:00
Jonas Platte b9c05ca934 test: Move room messages test JSON to the only module that uses it 2023-10-04 13:23:47 +02:00
Jonas Platte 75d64e697e test: Remove unused constants from test_json::messages 2023-10-04 13:23:47 +02:00
Jonas Platte f62d561cb0 ui: Verify token before prepending events from back-pagination 2023-10-04 13:23:47 +02:00
Jonas Platte 6cfa383652 ui: Move BackPaginationStatus definition to pagination module 2023-10-04 13:23:47 +02:00
Jonas Platte 1ab305a9d8 ui: Store back-pagination tokens inside TimelineInnerMetadata 2023-10-04 13:23:47 +02:00
Jonas Platte 0dcfe4f4f5 ui: Fix a typo 2023-10-04 13:23:47 +02:00
Jonas Platte 03c70220a1 ui: Remove forwards pagination token
It's not currently used.
2023-10-04 13:23:47 +02:00
Benjamin Bouvier 0d592e4051 chore: make Client::homeserver not async by changing the underlying kind of mutex
The mutex used for the `homeserver` field is very short-lived, so use a std mutex instead, which
makes a few methods sync instead of async.
2023-10-03 14:25:48 +02:00
Alfonso Grillo 08b3c0e47e Feature: add API for setting underride push rule's actions (#2644) 2023-10-03 10:08:17 +02:00
Benjamin Bouvier 7e8827aec2 fix: make the crypto memory store write the next_batch_token only if provided
This matches the behaviors of the two other implementations.
2023-10-02 19:05:07 +02:00
Benjamin Bouvier 3fa79ce891 chore: make the crypto stores more robust by serializing save_changes()
Stores may race when performing writes, since in `save_changes` some data is pickled, and live across await points (it could be stale after an
await point). To prevent multiple threads racing when calling into `save_changes`, a new lock is introduced there.
2023-10-02 19:05:07 +02:00
Benjamin Bouvier 76c3f2a139 chore: remove a few spurious async on MemoryStore 2023-10-02 19:05:07 +02:00
Benjamin Bouvier 8d6f414375 chore: move CryptoStore::save_account to Store::save_account
as it can be implemented in terms of other methods already present in the `CryptoStore` trait.
2023-10-02 19:05:07 +02:00
Matthew Hodgson 9ddef138c1 feat: support creating emotes (#2648)
* support creating emotes

adds an emote param to message_event_content_from_markdown and
message_event_content_from_html so that clients can create
m.room.message events with msgtype emote (on the assumption
that the msgtype returned in the RoomMessageEventContentWithoutRelation
is immutable, and so can't be overridden by the client)

* lint

* switch to separate methods per review feedback
2023-10-02 18:48:33 +02:00
Benjamin Bouvier 7203ae9576 fix: use insecure OIDC whenever configuring with an http homeserver URL (#2652)
Fixes https://github.com/matrix-org/matrix-rust-sdk/issues/2645.

The previous PR only enabled support for `server_name` homeserver configurations, this makes it work for `homeserver_url` too.
2023-10-02 10:27:30 +00:00
Ivan Enderlin 584db1d54c chore(base): Fix imports and features. 2023-10-02 10:45:08 +02:00
Ivan Enderlin 160f9233fa chore(sdk): Fix imports and features. 2023-10-02 10:44:50 +02:00
Ivan Enderlin ed759cae85 chore(ui): Replace EventTimelineItem with Self. 2023-10-02 10:11:17 +02:00
Ivan Enderlin 2f97301d5c chore(ui): Add homepage and license to Cargo.toml
chore(ui): Add `homepage` and `license` to `Cargo.toml`
2023-10-02 10:07:41 +02:00
Ivan Enderlin ba21e3bb02 feat(ui): Fallback to the slow path if profile is None. 2023-10-02 10:02:03 +02:00
Ivan Enderlin 0a119b55b3 fix(base): Fix migration helper for RoomInfo. 2023-10-02 10:01:48 +02:00
Ivan Enderlin 58998e4bbe feat(ui): Profile implements Default. 2023-10-02 09:49:56 +02:00
Ivan Enderlin 86ed582744 feat(ui): RoomDataProvider has profile_from_latest_event.
This patch renames `RoomDataProvider::profile`
to `::profile_from_user_id`. This patch also adds
`RoomDataProvider::profile_from_latest_event`.
2023-10-02 09:49:56 +02:00
Ivan Enderlin 5c55c2c51f feat(base): Rename LatestEvent::sender_profile to ::has_sender_profile. 2023-10-02 09:49:56 +02:00
Ivan Enderlin c0a3cc478d feat(base): LatestEvent has more methods.
This patch implements `LatestEvent::sender_display_name()`,
`::sender_name_ambiguous()` and `::sender_avatar_url()`.
2023-10-02 09:49:56 +02:00
Ivan Enderlin 83e7d7df11 feat(base): LatestEvent can hold a MinimalRoomMemberEvent.
This patch adds a `sender_profile: Option<MinimalRoomMemberEvent>`
field. Thus, `cache_latest_events` now receives an
`Option<&StateChanges>` and an `Option<&Store>`. The `StateChanges`
is used to read the most recent sender profile, otherwise the sender
profile will be fetch from the storage.
2023-10-02 09:49:56 +02:00
Ivan Enderlin f71a6fc738 feat(base): Latest event is represented by the new LatestEvent type.
This patch adds a new `LatestEvent` type. It wraps the
`SyncTimelineEvent` that was used before. The idea is to add more fields
onto this `LatestEvent` struct, but this patch starts easy by using
`LatestEvent` everywhere where it's required.
2023-10-02 09:49:56 +02:00
Ivan Enderlin 9027607347 doc(ui): Format doc. 2023-10-02 09:49:56 +02:00
Ivan Enderlin 84b1b741a3 feat(ui): all_rooms requires m.room.member: $LAZY.
This patch updates `all_rooms` to require the `m.room.member` state set
to `$LAZY`. That way, it's more likely to get the `m.room.member` event
associated to the latest event without needing to sync all the members.
2023-10-02 09:49:56 +02:00
Ivan Enderlin f7c008af3c chore(ui): Add repository and license to Cargo.toml. 2023-10-02 09:41:29 +02:00
kegsay 58e15f812d oidc: allow http scheme during discovery (#2642)
This is to enable entirely local stacks of Element X to work correctly. It's mostly seamless (no ffi changes) because it ties into `ClientBuilder.insecure_server_name_no_tls()`.

---------

Co-authored-by: Benjamin Bouvier <public@benj.me>
2023-09-29 11:29:30 +00:00
Benjamin Bouvier 9cc9221808 notifications: match decryption errors more precisely when waiting for decryption in the background 2023-09-29 12:37:16 +02:00
Benjamin Bouvier e679182fb5 fix(notifications): don't hard-fail if decrypting failed
Before this commit, a call to get_notification would fail if decrypting failed on the first attempt, because `Room::decrypt_event` will hard-fail if the key wasn't found.
2023-09-29 12:37:16 +02:00
Benjamin Bouvier 787a85615c chore(notifications): tweak logs in notification client 2023-09-29 12:37:16 +02:00
Benjamin Bouvier 6a5a4db5fc fix(notifications): add a mutex to serialize e2ee encryption requests 2023-09-29 12:37:16 +02:00
Benjamin Bouvier 1cedd1097a chore(notifications): rename sliding_sync_mutex to notification_sync_mutex 2023-09-29 12:37:16 +02:00
Benjamin Bouvier 2677d16f2e chore: look ma i'm a 10x engineer ok 2023-09-29 12:25:52 +02:00
Benjamin Bouvier 1e5e13bb19 chore: make use of StaticAccountData in one extra location 2023-09-29 12:25:52 +02:00
Benjamin Bouvier 1eeee288b9 chore: move unsigned_device_keys to StaticAccountData too 2023-09-29 12:25:52 +02:00
Benjamin Bouvier e4fd8e7ac6 chore: move methods from ReadOnlyAccount to StaticAccountData 2023-09-29 12:25:52 +02:00
Valere ab2f18df3b Add new API to request missing secrets (#2641) 2023-09-29 12:12:34 +02:00
Benjamin Bouvier a1f6e2fb16 chore: clippy + remove spurious Arc 2023-09-28 17:21:53 +02:00
Benjamin Bouvier 8f541c9a09 chore: remove ReadOnlyAccount from the Account
And use the `self.store.account()` when we really need the `ReadOnlyAccount`. Also cache the immutable account data in this Account.
2023-09-28 17:21:53 +02:00
Benjamin Bouvier c01d2d990c chore: use StaticAccountData in more places
Sorry, this commit is a bit big. What happened is that I've pulled a thread: put a `StaticAccountData` there, look at caller; it seems to use only a
static account too, so keep up.

The only contender was the `OwnUserIdentity` data structure which really wants to sign things. Lucky for us, we could pass it a `ReadOnlyAccount`
from a store, in those cases, since we always had a `Store` hanging around; in the future it'll read it from the store cache, which is somewhat
identical.
2023-09-28 17:21:53 +02:00
Benjamin Bouvier 13be4b0dce chore: use a StaticAccountData in the Sas data structures 2023-09-28 17:21:53 +02:00
Benjamin Bouvier 650d99a875 chore: rename account_info/get_account_info to static_account/get_static_account 2023-09-28 17:21:53 +02:00
Benjamin Bouvier 1c311555ef chore: put the immutable parts of ReadOnlyAccount into its own data struct 2023-09-28 17:21:53 +02:00
Kévin Commaille f115bd0e25 base: Fix typo
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-09-28 16:54:03 +02:00
Kévin Commaille 4595e2c064 indexeddb: Close DB less often during migrations
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-09-28 16:54:03 +02:00
Kévin Commaille f3b8bdbe1e indexeddb: Migrate RoomInfo to new format
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-09-28 16:54:03 +02:00
Kévin Commaille 23b34bfc2b indexeddb: Make sure each migration is discrete
We might need to rely on the data in the DB to already be corrected
before using it for another migration

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-09-28 16:54:03 +02:00
Kévin Commaille d4f0f7a704 sqlite: Migrate RoomInfo to new format
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-09-28 16:54:03 +02:00
Kévin Commaille 0856cf10fe base: Add migration helpers for converting serialized format of RoomInfo
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-09-28 16:54:03 +02:00
Kévin Commaille cd4bc7a62c base: Return m.room.create event's content even if it is redacted
Starting with room version 11, all fields are kept when the event is redacted

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-09-28 16:54:03 +02:00
Kévin Commaille acfb999e76 base: Make BaseRoomInfo compatible with room version 11
By copying the sender field as the creator field of m.room.create's event content

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-09-28 16:54:03 +02:00
Benjamin Bouvier 79f408b511 feat: automatically reload the tracked users when getting the cache 2023-09-28 16:37:52 +02:00
Benjamin Bouvier c18ac12ce9 Apply suggestions from code review
Co-authored-by: Damir Jelić <poljar@termina.org.uk>
2023-09-28 16:37:52 +02:00
Benjamin Bouvier 216b3b9d77 feat: add a dummy StoreCacheGuard too, and make use of it 2023-09-28 16:37:52 +02:00
Benjamin Bouvier 00d6b2d2ae chore: rename Store::load_tracked_users to Store::ensure_sync_tracked_users 2023-09-28 16:37:52 +02:00
Benjamin Bouvier 2499d13839 chore: remove outdated code comment 2023-09-28 16:37:52 +02:00
Benjamin Bouvier 074bcca02e feat: introduce dummy crypto cache for the store 2023-09-28 16:37:52 +02:00
Benjamin Bouvier 851b3f2982 chore(crypto): simplify Store::load_tracked_users 2023-09-28 16:37:52 +02:00
Daniel Abramov 585508f461 sdk(widget): Add the matrix (i/o) part 2023-09-28 16:01:26 +02:00
Hubert Chathi 4478826a2f Fix a typo 2023-09-28 15:31:25 +02:00
Marco Romano 0158422dcd Bump ruma
- Bumps ruma to include https://github.com/ruma/ruma/pull/1665
- Enables ruma `compat-arbitrary-length-ids` flag instead of using the now deprecated `lax-id-validation`
2023-09-28 14:01:18 +02:00
Damir Jelić 1f695bf26e Move most of our locks in the Client into the ClientLocks struct 2023-09-28 13:06:09 +02:00
Damir Jelić e37cfe6036 Don't use a static for the mark_room_as_dm lock
Using a static lock would prevent two Client instances to call the
method at the same time.

We're going to assume that people won't have multiple Client instances
for the same user, in which case a static lock would have been helpful.

Co-authored-by: Jonas Platte <jplatte@matrix.org>
2023-09-28 13:06:09 +02:00
Richard van der Hoff bcbb7c61f8 Enable the tests for encrypted indexeddb stores
Empirically, these seem to work for me, so let's re-enable them
2023-09-28 12:53:40 +02:00
Valere 4c432a66b4 Distinguish between changed and unchanged user identities (#2618) 2023-09-28 10:14:09 +02:00
Damir Jelić 24a203a126 Ensure that we can't try to mark two rooms as a DM at the same time 2023-09-27 16:24:57 +02:00
Jonas Platte cbb7b24cb5 Rewrite public widget API 2023-09-27 14:45:33 +02:00
Jonas Platte ae524b3fa6 ffi: Use FFI's tokio runtime explicitly for acquire_permissions 2023-09-27 13:13:27 +02:00
Richard van der Hoff 563072e7f8 Change the way we store gossip requests in indexeddb (#2626)
Instead of using three separate object stores, use a single one with some structured objects and indexes.

Fixes #2605 (or at least, should make whatever is going wrong much more obvious).

Consists of a series of commits which should be reviewable on their own.
2023-09-27 11:43:07 +01:00
Richard van der Hoff e3d9408d0a matrix-sdk-common: add js console tracing layer (#2620)
Implement a `tracing_subsciber` `Layer` which sends output to the javascript
console.

Obviously, this only works on the wasm32 target.

This is lifted from `matrix-rust-sdk-crypto-wasm`, so that we can use it in
tests etc for other crates.
2023-09-27 11:42:33 +01:00
Jonas Platte b35d40d111 test: Remove unused sync events from test_json 2023-09-27 10:06:32 +02:00
Jonas Platte 3196ac53b2 test: Remove TimelineTestEvent 2023-09-27 10:06:32 +02:00
Jonas Platte 145c5078f2 test: Remove example from SyncResponseBuilder docs
It is only an internal utility, we can copy-paste from other tests.
2023-09-27 10:06:32 +02:00
Jonas Platte 62ecff3e1d test: Remove outdated documentation 2023-09-27 10:06:32 +02:00
Richard van der Hoff fcd593b0bf Improve documentation on xtask ci {wasm,wasm-pack} 2023-09-26 21:30:40 +02:00
Richard van der Hoff 299256fe50 Fix IndexeddbCryptoStore::get_outgoing_secret_requests
Fix a bug which caused `get_outgoing_secret_requests` to return no data.

This is exposed as a public function, and when called that way it does *not*
expect the key to be escaped and encrypted.
2023-09-26 17:40:16 +02:00
Jonas Platte 956d5ef7e7 ffi: Update Room::edit to not make unnecessary network requests 2023-09-26 15:29:23 +02:00
Jonas Platte 2e27142336 ui: Add highlevel API for editing 2023-09-26 15:29:23 +02:00
Jonas Platte 9aa1dd725d test: Use EventBuilder for timeline edit integration test 2023-09-26 15:29:23 +02:00
Jonas Platte 6a69543f64 test: Move timeline edit integration test into new module 2023-09-26 15:29:23 +02:00
Jonas Platte 88194b6828 ui: Remove outdated documentation 2023-09-26 15:29:23 +02:00
Daniel Abramov a1d67206b6 sdk(widget): temporarily supress dead code warning 2023-09-26 13:19:38 +02:00
Daniel Abramov d017bab144 sdk(widget): add sans-io client api impl skeleton 2023-09-26 13:19:38 +02:00
Benjamin Bouvier 1180c6aef9 feat: add integration test for fetch_members causing UTDs 🧪 2023-09-26 12:33:41 +02:00
Benjamin Bouvier 43723c88ec feat: add unit tests 🧪 2023-09-26 12:33:41 +02:00
Benjamin Bouvier cb14813f84 chore: address review comments 2023-09-26 12:33:41 +02:00
Benjamin Bouvier e9362f75f2 chore: fix test that was affected by the issue
An encryption state request was failing, but before the patch, subsequent
requests would end up in success, while this wasn't the case. The new failure
introduced by this patch was a real one, because the encryption state was
not mocked as part of this test (which tries to send a message to a homeserver).
2023-09-26 12:33:41 +02:00
Benjamin Bouvier 502ecfa636 chore: get rid of the outer pinned box, weeeee 2023-09-26 12:33:41 +02:00
Benjamin Bouvier 928be57666 chore: polish DeduplicatedRequestHandler API 2023-09-26 12:33:41 +02:00
Benjamin Bouvier f5521e9e1c feat/fix: also correctly deduplicate preshare_room_key 2023-09-26 12:33:41 +02:00
Benjamin Bouvier 3aa5d12ab7 feat/fix: implement DeduplicatedRequestHandler + use it for encryption_state_request 2023-09-26 12:33:41 +02:00
Benjamin Bouvier e9d6351471 fix: also check the result of base::Client::receive_members 2023-09-26 12:33:41 +02:00
Benjamin Bouvier 120ac7150c reformat: no else after return 2023-09-26 12:33:41 +02:00
Benjamin Bouvier 2a235d8ea6 fix: signal that a concurrent request failed to the caller, instead of assuming it succeeded 2023-09-26 12:33:41 +02:00
Benjamin Bouvier a08327907c fix: don't cause that any /members request following a failed one result in immediate success 2023-09-26 12:33:41 +02:00
Jonas Platte a3799190d4 ui: Remove sender information from logs where it's not relevant 2023-09-26 11:26:25 +02:00
Jonas Platte e8528926be ui: Move debug-logging code out of main event handler logic 2023-09-26 11:26:25 +02:00
Alfonso Grillo b248aa9862 ffi: Add push notification support for unstable m.poll.start 2023-09-26 10:38:24 +02:00
Jonas Platte f47b7f02cc Use as_variant macro in more cases 2023-09-26 10:14:04 +02:00
Jonas Platte 6e15e34700 Use bool::then where applicable 2023-09-26 10:14:04 +02:00
Jonas Platte 1f08e22d0d crypto: Separate module declarations and reexports from imports 2023-09-26 10:14:04 +02:00
Jonas Platte f2c569440e ui: Remove transaction ID parameter on Timeline methods
There is no reason for it to be configurable in the high-level API,
since the timeline manages local echoes automatically.
2023-09-25 16:50:59 +02:00
Jonas Platte 753793c451 ui: Add a test for redacting a TimelineItemContent::MembershipChange 2023-09-25 14:27:50 +02:00
Jonas Platte c791fd6f1d ui: Move m.room.message specific content types into new module
`content.rs` was approaching 1K lines, which is a lot for a single file.
2023-09-25 14:27:50 +02:00
Jonas Platte 8e2ef9b2d0 ui: Move reaction types out of event_item::content
… into their own submodule.
2023-09-25 14:27:50 +02:00
dependabot[bot] 0ae6f740b9 chore(deps): bump aes-gcm from 0.10.2 to 0.10.3
Bumps [aes-gcm](https://github.com/RustCrypto/AEADs) from 0.10.2 to 0.10.3.
- [Commits](https://github.com/RustCrypto/AEADs/compare/aes-gcm-v0.10.2...aes-gcm-v0.10.3)

---
updated-dependencies:
- dependency-name: aes-gcm
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-09-25 11:38:08 +02:00
Jonas Platte 7213cfe152 ui: Add a test for Timeline::send_reply 2023-09-25 11:26:51 +02:00
Jonas Platte cb8c71ad68 ffi: Add EventTimelineItem::can_be_replied_to 2023-09-25 11:26:51 +02:00
Jonas Platte 579f59c54b ffi: Update send_reply to not make unnecessary network requests
… and add Room::get_event_timeline_item_by_event_id so send_reply can be
called more easily by EX-iOS given its code structure.
2023-09-25 11:26:51 +02:00
Jonas Platte 7430201f56 ui: Add highlevel API for replying 2023-09-25 11:26:51 +02:00
Jonas Platte dd7b3ab7d7 ui: Add timeline::error module 2023-09-25 11:26:51 +02:00
Benjamin Bouvier e8624706d4 logs(sliding sync): don't accumulate room ids when computing limited 2023-09-22 12:05:58 +02:00
Kévin Commaille d4a800aadc base: Small test code fix
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-09-22 10:54:09 +02:00
Kévin Commaille 9b732e1895 base: Ensure room name is not empty
Ruma used to handle this during deserialization when the field was
an Option.

Especially meaningful when computing the room name, where
an empty string means the name is not set.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-09-22 10:54:09 +02:00
Jonas Platte ff7aa63c5c ui: Ignore flaky test 2023-09-21 19:12:01 +02:00
Jonas Platte 454304a20d Enable eyeball's tracing feature 2023-09-21 19:12:01 +02:00
Marco Romano bd18c373fe Workaround uniffi kotlin bug with empty structs
Adds a dummy fuield to `UnstableVoiceContent`, otherwise uniffi
will generate an empty Kotlin data class which breaks compilation
(Kotlin data classes must have at least 1 field).
Upstream bug: https://github.com/mozilla/uniffi-rs/issues/1760
2023-09-21 14:28:55 +00:00
Jonas Platte fd822fc683 testing: Move last event creation code from TestTimeline to EventBuilder 2023-09-21 16:00:11 +02:00
Jonas Platte 5cf3c1e731 testing: Use EventBuilder in timeline teply integration tests 2023-09-21 16:00:11 +02:00
Jonas Platte 37912a1909 testing: Update EventBuilder method names for clarity 2023-09-21 16:00:11 +02:00
Jonas Platte c89b38b19f testing: Update EventBuilder::make_message_event_with_id argument order 2023-09-21 16:00:11 +02:00
Jonas Platte 2376f16214 testing: Change make_message_event_with_id to take event_id by reference 2023-09-21 16:00:11 +02:00
Jonas Platte 5d5f5e18de testing: Move ALICE, BOB, CAROL statics to test crate 2023-09-21 16:00:11 +02:00
Jonas Platte a5a9940ad9 testing: Extract EventBuilder out of TestTimeline 2023-09-21 16:00:11 +02:00
Jonas Platte fe2e60c60d testing: Replace TimelineTestEvent::Custom with sync_timeline_event! 2023-09-21 16:00:11 +02:00
Jonas Platte 054d26774c testing: Generalize add_timeline_event for sync response room builders 2023-09-21 16:00:11 +02:00
Jonas Platte c8a4bc799b testing: Add sync_timeline_event macro for more type safety in tests 2023-09-21 16:00:11 +02:00
Jonas Platte 82f793ec0f testing: Rename event_builder module to sync_builder
It used to contain a type named EventBuilder, but that has been renamed
to SyncResponseBuilder a while ago.
2023-09-21 16:00:11 +02:00
Ivan Enderlin cce8698e6e Merge pull request #2597 from Hywan/fix-base-poll-unstable-ruma-feature 2023-09-21 14:00:55 +02:00
Ivan Enderlin b495988424 fix(cargo): Move the unstable-msc3381 feature to matrix-sdk-base. 2023-09-21 13:19:10 +02:00
Ivan Enderlin 77d6c3144e Merge pull request #2581 from Hywan/feat-ffi-room-avatar-image-info 2023-09-21 12:24:02 +02:00
Ivan Enderlin 9f4b2bec05 fix(cargo): Enable unstable-msc3381 on ruma.
Without this feature:

```sh
$ cargo check -p matrix-sdk --features experimental-sliding-sync
    Checking matrix-sdk-base v0.6.1 (/Users/hwhost/Development/Element/matrix-rust-sdk/crates/matrix-sdk-base)
error[E0433]: failed to resolve: could not find `poll` in `events`
 --> crates/matrix-sdk-base/src/latest_event.rs:7:5
  |
7 |     poll::unstable_start::SyncUnstablePollStartEvent, room::message::SyncRoomMessageEvent,
  |     ^^^^ could not find `poll` in `events`

error[E0599]: no variant or associated item named `UnstablePollStart` found for enum `AnySyncMessageLikeEvent` in the current scope
  --> crates/matrix-sdk-base/src/latest_event.rs:40:68
   |
40 |         AnySyncTimelineEvent::MessageLike(AnySyncMessageLikeEvent::UnstablePollStart(poll)) => {
   |                                                                    ^^^^^^^^^^^^^^^^^ variant or associated item not found in `AnySyncMessageLikeEvent`
```

With the feature, everything goes well.
2023-09-21 11:41:02 +02:00
Ivan Enderlin 2ef05eb464 feat(sdk): Remove SlidingSyncList::room_list_filtered_stream
feat(sdk): Remove `SlidingSyncList::room_list_filtered_stream`
2023-09-21 10:31:20 +02:00
Ivan Enderlin 0989dd7fb7 feat(ui): Add the none filter
feat(ui): Add the `none` filter
2023-09-21 10:20:07 +02:00
Ivan Enderlin 3d8bdba268 feat(sdk): Remove SlidingSyncList::room_list_filtered_stream.
This patch removes `SlidingSyncList::room_list_filtered_stream.
Of course, the only place where it was used,
`RoomList::entries_with_dynamic_adapters` now use `.filter` from
`VectorSubscriberExt`. It's basically less code.
2023-09-21 10:17:06 +02:00
Ivan Enderlin 424135b831 fix(ffi): RoomListItem::full_room is now async
fix(ffi): `RoomListItem::full_room` is now `async`
2023-09-21 09:55:24 +02:00
Ivan Enderlin 7fc77a2d7e fix(ffi): RoomListItem::full_room is now async.
Because it creates a bug on iOS when using `RUNTIME.block_on` here.

This patch also adds `full_room_blocking` temporarily for Kotlin.
2023-09-21 09:35:16 +02:00
Ivan Enderlin ce2bac6818 feat(ffi): Add RoomListEntriesDynamicFilterKind::None. 2023-09-21 09:32:12 +02:00
Ivan Enderlin ef8c82113d test(ui): Test the none filter in real life. 2023-09-21 09:32:12 +02:00
Ivan Enderlin e91f170589 feat(ui): Add the none filter.
It's the opposite of the `all` filter. This one rejects all entries.
2023-09-21 09:32:12 +02:00
Ivan Enderlin 95e8f49afc test(ui): Test an empty pattern for filters. 2023-09-21 09:32:12 +02:00
Jonas Platte 1a15802201 Upgrade Ruma 2023-09-20 14:19:06 +02:00
Jonas Platte 784171e261 ffi: Don't check original sender of message when editing
The timeline checks this already. The network request made for this was
wasteful and unnecessary.
2023-09-20 11:57:38 +02:00
Marco Romano 9a0cc58e4a Support polls as latest event of a room 2023-09-20 09:45:25 +00:00
Ivan Enderlin 8217d18117 doc(ffi): Document media_info of Room::upload_avatar. 2023-09-20 10:32:47 +02:00
Ivan Enderlin a23d497d5c feat(ffi): Room::upload_avatar now has an Option<ImageInfo>.
This patch adds `Option<ImageInfo>` as an argument of
`Room::upload_avatar`.

To achieve that, this patch implements
`TryFrom<ImageInfo> for ruma::events::room::avatar::ImageInfo`.
2023-09-20 10:25:40 +02:00
Ivan Enderlin dfdc32f89a feat(ffi): Rename TimelineError to MediaInfoError.
The `TimelineError` type only contains error variants used for
`ImageInfo`, `AudioInfo`, `VideoInfo`, `FileInfo` and so on. It's never
used for something strictly related to the `Timeline`.

This patch then renames `TimelineError` to `MediaInfoError`.
The `MissingMediaInfoField` variant becomes `MediaField`. The
`InvalidMediaInfoField` becomes `InvalidField`.
2023-09-20 10:00:40 +02:00
Nicolas Mauri 31cb34f909 ffi: Add support for voice messages sent as m.room.message 2023-09-19 18:11:52 +00:00
Jonas Platte a37c487763 examples: Remove nonsensical room state check
Stripped state events are only received for rooms in invite state.
2023-09-19 17:57:39 +02:00
Damir Jelić eeb27adad2 Use the extracted ciphers for the file-based key export support 2023-09-19 15:23:46 +02:00
Damir Jelić 0c726d521b Add a new ciphers module for AES-CTR-256 with HMAC-SHA256
This module is mainly extracting logic we're already using for the
file-based key exporting.

Co-authored-by: Denis Kasak <dkasak@termina.org.uk>
2023-09-19 15:23:46 +02:00
Jonas Platte 13c9b0f803 ffi: Add _blocking versions of async methods in notification_settings 2023-09-19 12:13:42 +02:00
Jonas Platte 40f701986c ffi: Add _blocking versions of async methods in session_verification 2023-09-19 12:13:42 +02:00
Jonas Platte 7f2f3053f1 ffi: Add _blocking versions of async methods in sync_service 2023-09-19 12:13:42 +02:00
Jonas Platte 0ceb93a410 ffi: Add _blocking versions of async methods in room 2023-09-19 12:13:42 +02:00
Jonas Platte 52ce2eed23 Upgrade eyeball, eyeball-im-util
Pulls in an important bug fix for the Limit adapter.
2023-09-19 11:35:18 +02:00
Ivan Enderlin 1e80aae780 feat(ui): RoomList dynamic entries simplifications
feat(ui): `RoomList` dynamic entries simplifications
2023-09-19 11:00:35 +02:00
Ivan Enderlin af7cf3148b test(ui): Ensure that it's fine to reset_to_one_page multiple times. 2023-09-19 10:40:02 +02:00
Ivan Enderlin d0da4ae159 feat(ui): Update the limit if it's different.
Use `SharedObservable::set_if_not_eq` instead of `::set`, so that it
doesn't update the limit to the same value, which would be unnecesary in
this case.
2023-09-19 10:34:27 +02:00
Ivan Enderlin c2166c50b1 chore(ui): Remove a useless clone.
It was necessary before 0f7e5ba4b0, but it
isn't anymore.
2023-09-19 10:33:19 +02:00
Ivan Enderlin a1a5b85fd8 feat(ui): Remove one Mutex.
This patch removes the `Mutex` around `Subscriber<Option<u32>>` inside
the `RoomListDynamicEntriesController`. The `Mutex` was necessary to
get a mutable reference, so that `Subscriber::next_now` could have been
used. However, it's not necessary to use `new_now` in this particular
context. We can use `get` instead, which take an immutable reference,
thus removing the need for the `Mutex`.

A `Mutex` has a non-negligeable cost. This function can be used in a
critical hot path, and must as fast as possible.
2023-09-19 10:29:49 +02:00
Ivan Enderlin 12316ad281 feat(ui): Improve the InputCannotBeApplied displaying
feat(ui): Improve the `InputCannotBeApplied` displaying
2023-09-19 08:56:55 +02:00
Jonas Platte 97c5acff7c Use new functionality from eyeball-im-util 0.5 2023-09-18 19:56:06 +02:00
Jonas Platte 0504eafc0a Upgrade most dependencies 2023-09-18 19:56:06 +02:00
Jonas Platte beeeec34f7 sdk: Wait on sync beat asynchronously 2023-09-18 19:56:06 +02:00
Jonas Platte 45b7e075c9 Remove unused dependencies 2023-09-18 19:56:06 +02:00
Benjamin Bouvier 0ecdc2f43c fix(e2ee): query keys for untracked users even if we didn't explicitly sync members ourselves 2023-09-18 17:24:21 +02:00
Ivan Enderlin ae27164bb3 feat(ui): Improve the InputCannotBeApplied displaying. 2023-09-18 17:02:41 +02:00
Ivan Enderlin e5ba445c56 feat(sqlite) chunk_large_query_over doesn't chunk if not necessary
feat(sqlite) `chunk_large_query_over` doesn't chunk if not necessary
2023-09-18 16:33:52 +02:00
Ivan Enderlin 1f98159213 chore(sqlite): Simplify Vec capacity calculation.
Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
2023-09-18 16:20:05 +02:00
Ivan Enderlin 4c244c6d83 feat(sqlite) chunk_large_query_over doesn't chunk if not necessary.
This patch updates `chunk_large_query_over`. This function works great
when it's required to chunk some data over a query. However, if the
data don't need to be chunked, it is possible to get a quicker path that
doesn't involve 2 `Vec` allocations, nor a `split_off` of one `Vec`, nor
a `Vec::extend` (which move data in memory). The quicker path, which is
also the most likely to be hit, simply does a single `Vec` allocation,
and that's it.
2023-09-18 15:13:45 +02:00
Benjamin Bouvier 284bb9702b example(oidc): add automatic persist on session update 2023-09-18 14:34:10 +02:00
Benjamin Bouvier bed0faa143 example(oidc): add sync service integration
And allow to run with an insecure server + auto-refresh token + properly restore session using homeserver discovery
2023-09-18 14:34:10 +02:00
Benjamin Bouvier 5ff83c00c5 Add tests for OIDC (#2558)
* chore(oidc): put impl of OIDC server behind a trait and add tests for the OIDC flow

chore(oidc): add first tests for login/AuthorizationResponse

chore(oidc): add tests for finish_authorization/finish_login/refresh_access_token

chore(oidc): add test for logout

chore(🤷): clippy/fmt

* chore(oidc): move account management test to the new `tests` module

* chore(oidc): address review comments
2023-09-18 14:33:35 +02:00
Damir Jelić f44ebf1bf9 Merge pull request #2553 from matrix-org/poljar/fix-mark-dm-as-room
Add method to fetch account data and fetch the m.direct account data from the server when marking rooms as DMs
2023-09-18 11:19:48 +02:00
Ivan Enderlin 7198239ea6 feat(ui): RoomListService::sync_indicator takes delays as parameters
feat(ui): `RoomListService::sync_indicator` takes delays as parameters
2023-09-18 11:06:24 +02:00
Damir Jelić 790944f216 Update crates/matrix-sdk/src/account.rs
Co-authored-by: Ivan Enderlin <ivan@mnt.io>
2023-09-18 11:04:40 +02:00
Marco Romano 3bad812ff8 Use new poll event replacement types
* Bump ruma
* Use new ruma types for UnstablePollStartEventContent
* Use from/into for UnstablePollStartEventContent.
2023-09-18 11:03:41 +02:00
Ivan Enderlin 5e28257d77 feat(ui): RoomListService::sync_indicator takes delays as parameters.
Prior to this patch, we were using 2 constants to define the
sync indicator delays: `SYNC_INDICATOR_DELAY_BEFORE_SHOWING` and
`SYNC_INDICATOR_DELAY_BEFORE_HIDING`. After some discussions with
some users, it appears that it's desirable to make these values
parameterizable.

Thus, this patch updates `RoomListService::sync_indicator` to accept 2
parameters: `delay_before_showing` and `delay_before_hiding`. The patch
also updates the FFI bindings.
2023-09-18 10:44:03 +02:00
Ivan Enderlin 463b207422 feat(ui): Use an initial limit in room list dynamic entries
feat(ui): Use an initial limit in room list dynamic entries
2023-09-18 10:42:28 +02:00
Ivan Enderlin 442e6ca8c0 fix(ui): The invites sliding sync is no longer cached
fix(ui): The `invites` sliding sync is no longer cached
2023-09-18 10:42:00 +02:00
Ivan Enderlin 79231f940f feat(ffi): Improve performances of Room::members
feat(ffi): Improve performances of `Room::members`
2023-09-18 10:40:48 +02:00
Ivan Enderlin 0f7e5ba4b0 feat(ui): Use an initial limit in room list dynamic entries.
In `RoomList::entries_with_dynamic_adapters`, we were using the
`Limit::dynamic` constructor. It builds a `Limit` stream adapter where
the limits come from a `Stream`. The immediate impact is that this
constructor does only return a new `Stream`, but it cannot return
the initial items of the vector. Thus, it wasn't possible to reset
the final `Stream` with a `VectorDiff::Reset { values }`. Instead, we
were emitting a `Clear` (from this code) then a `Append` (from the
`Limit` stream). Sadly, for some client apps, like Element X iOS, these
2 diffs (`Clear` and `Append`) result in a “rendering blink”.

Hopefully for us, now there is new constructors for `Limit`! One of them
is `Limit::dynamic_with_initial_limit`, which returns the initial items
along with the new `Stream`. That's perfect, we can reset the final
`Stream` with `Reset { values }` again, thus removing the “UI blinking”
effect in Element X iOS.

This patch switches `Limit::dynamic` to
`Limit::dynamic_with_initial_limit`, and updates/simplifies the tests
accordingly.
2023-09-18 10:21:51 +02:00
Ivan Enderlin b7240b898c fix(ci): Change tarpaulin output format from Xml to xml
fix(ci): Change tarpaulin output format from `Xml` to `xml`
2023-09-18 10:21:15 +02:00
Ivan Enderlin 17e1e81023 fix(ui): The invites sliding sync is no longer cached.
`RoomListService::new_internal` were creating the `invites` sliding
sync list, with a cache. It is not a good idea. It should not be cached.
Let's remove that :-).
2023-09-18 10:06:37 +02:00
Ivan Enderlin 005d2638cb fix(ci): Change tarpaulin output format from Xml to xml.
It's better huh?
2023-09-18 09:58:09 +02:00
Ivan Enderlin af402b3864 fix(ui): Set RoomListLoadingState initial value
fix(ui): Set `RoomListLoadingState` initial value
2023-09-18 09:55:15 +02:00
Ivan Enderlin 1cf5f3a0ee fix(ui): Set RoomListLoadingState initial value.
`RoomListLoadingState` was initialized with the `NotLoaded` state. This
is always true… except when there is a cache! If the cache contains
N rooms, the loading state should be `Loaded { … }`. Then the next
sync (if any) will update the loading state to `Loaded { … }` with
an adjusted number of rooms or something like that, but semantically
speaking, the presence of the cache should result in a `Loaded` state.

This patch fixes this behavior, and also adds the tests.
2023-09-18 09:26:37 +02:00
Ivan Enderlin 8032c39fda at(ui): Use a dynamic limit over the RoomList entries
feat(ui): Use a dynamic limit over the `RoomList` entries
2023-09-15 17:06:51 +02:00
Ivan Enderlin b6af934635 chore(ui): let + else FTW! 2023-09-15 16:51:08 +02:00
Damir Jelić 3fb6f206fc Record the HTTP method in our logs 2023-09-15 16:51:05 +02:00
Damir Jelić b61f2fbdc4 Test if we're doing the correct request when marking a room as a DM 2023-09-15 16:51:05 +02:00
Damir Jelić a61205088b Fetch the account data from the server before marking rooms as DMs 2023-09-15 16:51:05 +02:00
Damir Jelić de90cf413b Add a method to retrieve global account data events from the server 2023-09-15 16:47:22 +02:00
Ivan Enderlin db1125d427 chore(cargo): Back to regular eyeball. 2023-09-15 15:02:04 +02:00
Ivan Enderlin a5e19201df chore(ui): Produce Clear instead of Truncate { length: 0 }. 2023-09-15 14:43:21 +02:00
Ivan Enderlin 16bfd14b81 !fixup 2023-09-15 14:35:03 +02:00
Ivan Enderlin be6da14f16 test(ui): Add more tests. 2023-09-15 13:46:41 +02:00
Ivan Enderlin d12eda5839 feat(ui): RoomList provides entries that are limited.
For some room lists, the number of entries can be gigantic. For example,
some accounts have 800, 2500, or even 4000 rooms! It's not necessary for
the client/app to display all the 4000 rooms. First, it can create some
performance issues, second, nobody will scroll 4000 rooms to search for
a particular room :-). Such users are more likely to use a search bar or
something equivalent. The idea is that `RoomListService` will continue
to sync all the data, but only a _limited_ version of it will be shared
to the client/app.

This patch takes `RoomList::entries_with_dynamic_filter`, and improves
it to include this (dynamic) limit.

This patch renames `RoomList::entries_with_dynamic_filter`
to `::entries_with_dynamic_adapters`. It now returns a
`RoomListDynamicEntriesController`, which is a renaming of
`DynamicRoomListFilter`. Basically, the “dynamic filter” becomes a
“dynamic controller” because `RoomList::entries_with_dynamic_adapters`
manages more than a filter. It now uses
`eyeball_im_util::vector::DynamicLimit` to dynamically limit the size
of entries. And that's the major idea behind this patch.

`RoomListDynamicEntriesController::set` is renamed `::set_filter`, and 2
new methods are introduced: `add_one_page` and `reset_to_one_page`.

A _page_ is like a chunk of room entries we want to view or add. When
doing `next_page`, the limit increases to `old_limit + page_size`. The
`reset_pages` method resets the `limit` to `page_size` only.
2023-09-15 13:34:20 +02:00
Benjamin Bouvier 774f695eb8 chore(doc): fix documentation 2023-09-15 13:03:11 +02:00
Benjamin Bouvier ab0982e512 chore(matrix auth): simplify a bit the code of matrix auth's refresh_access_token 2023-09-15 13:03:11 +02:00
Benjamin Bouvier 0cb5f666ae chore(oidc): remove a few unnecessary wrappers, now that OidcCtx is in an Arc'd data structure 2023-09-15 13:03:11 +02:00
Benjamin Bouvier b9b042ec4a chore(auth): prefix Session data structures with the auth kind 2023-09-15 13:03:11 +02:00
Benjamin Bouvier 7665b15c5a chore(auth): prefix SessionTokens data structures with the auth kind 2023-09-15 13:03:11 +02:00
Benjamin Bouvier b42cb1c43f chore(oidc): rename OidcContext to OidcCtx for symmetry with AuthCtx 2023-09-15 13:03:11 +02:00
Benjamin Bouvier 2acf21fcd4 refactor(oidc): move AuthCtx::authentication_server_info into OidcContext 2023-09-15 13:03:11 +02:00
Benjamin Bouvier 3144d87c3a refactor(oidc): put the OidcContext in the AuthCtx 2023-09-15 13:03:11 +02:00
Benjamin Bouvier 7e142c8132 refactor(oidc): lower cognitive load by removing RegisteredClientData 2023-09-15 13:03:11 +02:00
Benjamin Bouvier 23f4aedf47 chore(oidc): update some code comments 2023-09-15 13:03:11 +02:00
Benjamin Bouvier 6db19198fc chore(oidc): restore_registered_client doesn't need to be async 2023-09-15 13:03:11 +02:00
Benjamin Bouvier dde2f408c5 chore(sliding sync): log the room id in the limited flag computation 2023-09-14 19:14:52 +02:00
Benjamin Bouvier b749b3546f feat(auth): make the session callbacks work for the matrix auth scheme too 2023-09-14 17:42:56 +02:00
Jorge Martín 6c45e56d61 ffi: Add Client.remove_avatar function 2023-09-14 17:02:23 +02:00
Jonas Platte 84daf1f079 ffi: Add RoomListItem::room_info_blocking 2023-09-14 16:49:36 +02:00
Nicolas Mauri 6d8d174a5e ffi: RoomInfo notification mode must reflect the user-defined mode (#2545) 2023-09-14 14:23:32 +02:00
Jonas Platte fd17bce300 ui: Fix day divider logic
… for when a remote event is re-received while a local echo is pending.
Also simplify test_togglling_reaction integration test so it still passes.
2023-09-14 14:14:44 +02:00
Benjamin Bouvier 67b0305a3e feat: Add a cross-process lock mechanism for OIDC token refresh (#2440)
This adds a cross-process lock for refresh to work correctly.

We want to coordinate token refresh across multiple processes. For that, we're using a cross-process lock, and a value in the database identifying the latest session tokens that are valid (a hash of the actual tokens, for security reasons).

Whenever we run into an HTTP error indicating that the tokens have been invalidated, we try to refresh the access tokens; that's already existing prior to this PR. The novelty introduced is that we take a cross-process lock before doing so, now. Taking this lock will also load a session hash from the database, and we'll compare it against the latest "known" session hash (that the current process saved into its memory).

If there's no mismatch (i.e. the database and the currently known are the same), then we're all good and can keep going with the refresh, synchronize the hashes everywhere (in-memory and database), make sure the client is notified about it (through a new user-provided callback `SaveSessionCallback`; on iOS this will save it into the device's keychain).

Otherwise, that means another process has done a refresh under our feet. In that case, we ask an authoritative source for trusted session tokens. On iOS, they're reloaded from the device keychain; that happens through a new user-provided callback `ReloadSessionCallback`. Then, we make sure that the DB and the in-memory value recall this latest value.

An embedder who would like to make use of the cross-process locking mechanism should call `client.oidc().set_session_callbacks` and `client.oidc().enable_cross_process_refresh`. If only interested with the pings for new sessions, the client may only call `client.oidc().set_session_callbacks`.

Fixes https://github.com/matrix-org/matrix-rust-sdk/issues/2418.
Fixes https://github.com/matrix-org/matrix-rust-sdk/issues/2476

## Future improvements

- More testing of the whole flow. Not sure if mocking will be quite fit for OIDC, as this may require setting up an HTTPS server for the authentication code exchange and other OIDC-specific flows.
- Get rid of `SessionChange`, which duplicates in some way how a client can be notified about session changes.

---

* chore: replace manual StateMemoryStore::new with derived Default

* feat: add store backing for cross-process locking in state store

* chore: rename CryptoStoreLock to CrossProcessStoreLock

* chore: generalize cross-process lock

* feat: move the cross-process locking mechanism to the main crate

* feat: add support for cross-process store lock in the state store 🥳

* feat: implement a cross-process lock for OIDC token refresh

* chore: tweak comment + function name

* feat: make restore_session safe wrt cross-process lock

* feat: add FFI method + add mechanism to reload from keychain

* fix rename

* feat: return early when there was another process refreshed tokens

* fix FFI compile error + tweak some comments

* fix: put the reload_session callback and cross-process locks behind Arc to share them across clients

* feat: Add session retrieval to FFI.

* HACKY; KIDS DON'T DO THIS AT HOME

* chore: log if the hash from db isn't the same from the one from the returned session

* make it simpler to test OIDC token refresh

* some work, that includes fixes and a first test

* feat: require that the reload_session_callback be set at the same time as the cross-process lock

* chore: traces, traces everywhere

* fix: inherit session_change_sender when creating the notification client

* Some FFI improvements to help with tokio problems

* feat: resilient mode when DB/callback disagree about session (callback wins!)

* chore: move sender.send to the finish_refreshing function

* feat: add a save_session callback in the FFI and use it to save the session in keychain while holding XP lock

* fix test expectation after adding the check 🤷

* feat: split the ClientDelegate into two parts, including brand new ClientSessionDelegate

* chore: get rid of lease lock impl in the state store, as it's now unused

* a mix of fmt + clippy

* feat: add ctor for the crossprocessrefreshlockctx

* Include user ID when retrieving session.

Necessary as this isn't known when creating the AuthenticationService.

* yo dawg, you can't block while you block

* share auth data between parent and child client, add lock, AAAAAA this is messy

* tweaks

* feat: make the cross-process store locks generic

And move the implementation to the common crate.

* chore: upgrade some code comments to doc comments in `OngoingMigration`

* feat: implement `CryptoStore::remove_custom_value`

As it's going to be used for the OIDC PR, so as to remove a remembered hash of session tokens.

* remove unneeded remnants

* correctly wait for current request to finish

* feat: make it possible to setup session delegates on android too(?)

* put the cross process stuff in its own file

* typos 🤷

* fix: detach before sending token refresh request, to make sure the response tokens are always properly saved

* kleepee

* First round of review, thanks jonas!

* review round 2. FIGHT

* remove useless logs + avoid using deref explicitly

* more specialized error when cross-process lock is enabled without session callbacks

* fix: avoid cyclic reference between the session callback and client

---------

Co-authored-by: Doug <douglase@element.io>
Co-authored-by: Jonas Platte <jplatte@matrix.org>
2023-09-14 12:47:47 +02:00
Jonas Platte 0c4b8c602c ui: Sanitize m.room.message events in notifications
… including reply fallback stripping.
2023-09-14 12:18:30 +02:00
Jonas Platte 03bbdce15f ffi: Add in_reply_to field to MessageLikeEventContent::RoomMessage 2023-09-14 12:18:30 +02:00
Jonas Platte af400357f5 Use Self keyword more 2023-09-13 18:33:33 +02:00
Jonas Platte 4da3806a01 indexeddb: Simplify filter_map closure 2023-09-13 18:33:33 +02:00
Jonas Platte 1cbcee4fea Use as_variant crate for shorter code 2023-09-13 18:33:33 +02:00
Jonas Platte 1542abd25a ui: Adjust logs to use natural numbering 2023-09-13 15:17:55 +02:00
Doug 3b685e01b5 feat(bindings): Expose account management action in the bindings. 2023-09-13 14:14:02 +02:00
Doug 7d8c6521ed feat(sdk): Add an action parameter to the OIDC account URL. 2023-09-13 14:14:02 +02:00
Jonas Platte 9a30878f43 ui: Fix a typo 2023-09-13 11:45:11 +02:00
Jonas Platte 958ed1855e ui: Log a warning when TimelineInnerStateTransaction is cancelled 2023-09-13 11:45:11 +02:00
Jonas Platte a1d730f87b ui: Simplify TimelineInner subscription methods 2023-09-13 11:45:11 +02:00
Jonas Platte fa0d949600 ui: Change TimelineInnerStateTransaction to be committed explicitly 2023-09-13 11:45:11 +02:00
Jonas Platte be4c376423 ui: Use ObservableVectorTransaction for timeline 2023-09-13 11:45:11 +02:00
Jonas Platte 55be56e78f ui: Move some functions to TimelineInnerMetadata 2023-09-13 11:45:11 +02:00
Jonas Platte c6fd3ec4b0 ui: Split non-items fields of TimelineInnerState into separate struct
… as a preparation for further refactorings.
2023-09-13 11:45:11 +02:00
Jonas Platte 7168df8b30 ui: Fix indentation 2023-09-13 11:45:11 +02:00
Jonas Platte 7fad343390 ui: Remove unused import 2023-09-13 11:45:11 +02:00
Jonas Platte 768f062e0c ui: Ignore flaky test
It's still compiled, but not run unless `--ignored` or `--include-ignored`
is passed on the commandline.
2023-09-13 11:40:54 +02:00
Jonas Platte 96ccd6e2bd sdk: Fix unit tests not compiling without testing feature 2023-09-12 18:31:15 +02:00
Jonas Platte a4101e2f45 Upgrade Ruma 2023-09-12 17:19:56 +02:00
Benjamin Bouvier d35a8b7fa0 chore: remove one level of indent thanks to let else 2023-09-12 17:02:42 +02:00
Benjamin Bouvier 2d932dc29f feat: don't process the limited flag for e2ee-only sliding syncs 2023-09-12 17:02:42 +02:00
Benjamin Bouvier 654a2f2495 fix(sliding sync): don't mark a response to a locally empty room as limited
When receiving a sliding sync room response for a room that had no local events in its timeline cache,
we'd mark the room as limited before, which is incorrect. It was made worse by the fact that later in
the code, we'd clear the local cache if a room was marked as limited, so this is a problem that would
repeat itself over time (assuming empty responses for that room).

This fixes it and unifies logs so there's only one log line per room, at most.

Fixes https://github.com/vector-im/element-x-android/issues/1281
Fixes https://github.com/matrix-org/matrix-rust-sdk/issues/2540
2023-09-12 17:02:42 +02:00
Jonas Platte a53bfe5748 Some documentation cleanup 2023-09-12 09:25:19 +02:00
Benjamin Bouvier b565acd462 feat: log the x-sentry-event-id if we receive it from the server 2023-09-11 14:41:42 +02:00
Jonas Platte 6131e41183 sdk: Replace deprecated function 2023-09-08 12:35:01 +02:00
Jonas Platte d4904a01b0 Upgrade dependencies
Most notably eyeball-im-util 0.3.1, which includes an important bugfix.
2023-09-08 12:35:01 +02:00
Damir Jelić c32f2444fc Use the base64 encoding/decoding methods from vodozemac in the bindings 2023-09-08 11:43:32 +02:00
Damir Jelić 72e3079aab Use the base64 encoding/decoding functions from vodozemac 2023-09-08 11:43:32 +02:00
Damir Jelić 7e06ad130c Add a base64 prefix to the names of the base64 encoding/decoding functions 2023-09-08 11:43:32 +02:00
Richard van der Hoff 8d1308ef6a fix doc 2023-09-07 22:31:34 +01:00
Richard van der Hoff 783adb424e Impmenent Store::identity_stream_raw
An alternative to `user_identity_stream`, which does not hold a reference to
the `CryptoStore` and hence is less prone to leaking references
2023-09-07 22:17:09 +01:00
Doug eb865f490a chore(bindings): Handle OIDC metadata changes. (#2503)
Currently when the AuthenticationService is given updated metadata, it is ignored if a dynamic registration has already been made for a selected issuer. This PR fixes that by storing the metadata's hash and resetting the store when there is a mis-match.

Additionally it moves OidcRegistrations out of the FFI into a new authentication module in the UI crate and adds some tests.
2023-09-07 17:28:58 +00:00
dependabot[bot] 4991450d6a chore(deps): bump webpki from 0.22.0 to 0.22.1
Bumps [webpki](https://github.com/briansmith/webpki) from 0.22.0 to 0.22.1.
- [Commits](https://github.com/briansmith/webpki/commits)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-09-07 18:51:15 +02:00
Mauro Romito fa91a74452 feat(bindings): upload user avatar 2023-09-07 18:12:16 +02:00
Doug d7f5cd51e4 chore(bindings): Add missing contacts field on OidcConfiguration. 2023-09-07 17:43:20 +02:00
Jonas Platte e655490b9f ffi: Add is_threaded method to timeline Message object 2023-09-07 16:54:21 +02:00
Jonas Platte 36942e4f22 ui: Add threaded property to timeline Message type 2023-09-07 16:54:21 +02:00
Jonas Platte 619085a190 Use ObservableVectorTransaction for room list 2023-09-07 15:30:18 +02:00
Jonas Platte 71cc7318ca Upgrade eyeball-im, eyeball-im-util 2023-09-07 15:30:18 +02:00
Benjamin Bouvier dbf9e80c8f encryption sync: disable the shared pos in the encryption sync
It is racy and would require a cross-process lock held during the whole
flow (from creating the request to processing the response).
2023-09-07 14:55:55 +02:00
Benjamin Bouvier ab7ec1bc38 feat: implement CryptoStore::remove_custom_value
As it's going to be used for the OIDC PR, so as to remove a remembered hash of session tokens.
2023-09-07 11:41:22 +02:00
Benjamin Bouvier 87be58bc2c chore: upgrade some code comments to doc comments in OngoingMigration 2023-09-07 11:41:22 +02:00
Benjamin Bouvier 685cc2bbc3 feat: make the cross-process store locks generic
And move the implementation to the common crate.
2023-09-07 11:41:22 +02:00
Ivan Enderlin 243cc6773a chore(ffi): Make Clippy happy. 2023-09-07 11:27:06 +02:00
Ivan Enderlin 4e50bcddc2 feat(ffi) Room::members returns a RoomMembersIterator.
This patch updates `Room::members` to return
`Result<Arc<RoomMembersIterator>, ClientError>`. This
`RoomMembersIterator` type is new, and is implemented in this patch too.

The idea behind this patch is to allow the bindings to “paginate” over
the list of members for a particular room, in case the room has 17k
members for example.
2023-09-07 11:03:16 +02:00
Ivan Enderlin 08424366d8 feat(ffi): Add ChunkIterator<T>.
This patch implements a generic `ChunkIterator` type. It's not tailored
for use via FFI, but it can be embedded inside a `uniffi::Object` for
example.
2023-09-07 11:01:39 +02:00
Benjamin Bouvier 9802795d8d fix: don't overwrite the parent session when creating a child Client 2023-09-07 10:34:54 +02:00
Benjamin Bouvier 7ba06c3136 chore: unify implementations of SendRequest::into_future and Client::send_with_homeserver 2023-09-07 10:34:54 +02:00
Benjamin Bouvier 0d6e12f3cd chore: tweak implementation of Oidc::set_session_tokens to make it less contrived 2023-09-07 10:34:54 +02:00
Benjamin Bouvier bb82a068c2 chore: move the auth_data field into AuthCtx 2023-09-07 10:34:54 +02:00
Benjamin Bouvier 6c55767c73 chore: move the session_changer_sender field into AuthCtx 2023-09-07 10:34:54 +02:00
Benjamin Bouvier 7db45a4b23 chore: move the refresh_token_lock into the AuthCtx 2023-09-07 10:34:54 +02:00
Benjamin Bouvier 4802a50609 chore: put handle_refresh_tokens in the AuthCtx 2023-09-07 10:34:54 +02:00
Benjamin Bouvier 28ab8e9efc chore: remove Client::authentication_server_info as it's duplicated from Oidc::authentication_server_info 2023-09-07 10:34:54 +02:00
Benjamin Bouvier 44a13fac9f chore(client): introduce AuthCtx to contain all data relative to auth(entication|orization) 2023-09-07 10:34:54 +02:00
Ivan Enderlin 74c5c2825a test(ci): Exponential backoff when retrying flaky tests
test(ci): Exponential backoff when retrying flaky tests
2023-09-07 09:51:17 +02:00
Ivan Enderlin f08524baa6 test(ci): Exponential backoff when retrying flaky tests.
This patch changes the backoff strategy from `fixed` to `exponential`
when a flaky test is retried. The `count` value is also updated to
3. Finally, we try to avoid the thundering herd problems with `jitter
= true`.
2023-09-07 09:12:29 +02:00
Ivan Enderlin b8dd45546d doc(sdk): Add documentation. 2023-09-07 09:06:16 +02:00
Ivan Enderlin 29fecf5109 test(ui): Adjust request_margin to avoid a flaky test
test(ui): Adjust `request_margin` to avoid a flaky test
2023-09-06 20:50:44 +02:00
Ivan Enderlin c5e4ea4e3c test(ui): Adjust request_margin to avoid a flaky test. 2023-09-06 20:34:57 +02:00
Damir Jelić 9174f120b4 Expose the user identities and devices streams in the main crate 2023-09-06 19:00:37 +02:00
Damir Jelić 578c1a473a Broadcast new and updated devices 2023-09-06 19:00:37 +02:00
Damir Jelić 53c4735944 Broadcast new and updated user identities 2023-09-06 19:00:37 +02:00
Damir Jelić 7419b2c86b Add our user ID to the CryptoStoreWrapper
This will become useful once we start broadcasting user identity
updates, we'll need to know which user identity is our own.
2023-09-06 19:00:37 +02:00
Ivan Enderlin 64bdbdcbaa feat(ui): Implement RoomListService::sync_indicator
feat(ui): Implement `RoomListService::sync_indicator`
2023-09-06 17:56:11 +02:00
Ivan Enderlin 77cc84a6d9 feat(ffi): Room::fetch_members no longer return a TaskHandle.
This patch changes the behavior of `Room::fetch_members. Since it's now
an async method, it no longer needs to return a `TaskHandle`.
2023-09-06 17:44:48 +02:00
Ivan Enderlin f3d33efa0f feat(ffi): Make fetch_members, members and member async.
This patch makes the following methods on `Room` async: `fetch_members`,
`members`, and `member`.
2023-09-06 17:37:05 +02:00
Ivan Enderlin b8ed566d78 feat(ffi): Add bindings for RoomListService::sync_indicator.
This patch adds the `RoomListService::sync_indicator` method, along
with the `RoomListServiceSyncIndicatorListener` callback interface, and
`RoomListServiceSyncIndicator` enum.
2023-09-06 17:16:36 +02:00
Ivan Enderlin 8a1ff1967f feat(ui): Implement RoomListService::sync_indicator.
This patch implements a new method: `RoomListService::sync_indicator`.
It returns a `impl Stream<Item = SyncIndicator>` where `SyncIndicator`
is a new enum with 2 variants: `Show` and `Hide`.

`SyncIndicator` is the UI equivalent of a sync spinner/loader/toaster,
that the app might want to show to the user to indicate when a _first_
request is sent and might be slow, i.e. the first response is taking
a little bit of time to come. The term _first_ may be innapropriate as
it covers the actual first sync request, but also the recovering sync
request. It means that when a sync error happened, the sync indicator
will be shown too, which is a pretty useful information for the user.

It's not because a `SyncIndicator` should be shown that it must be send
immediately onto the `Stream`. In case of a normal network conditions,
without any delay, it can lead to a “blinking” visual effect. Some
constants configure how long it takes to consider that a request is
“slow”, and that the `SyncIndicator` is necessary to be shown (or
hidden).
2023-09-06 17:16:36 +02:00
Jonas Platte 2787d058de ui: Remove Option from return type
… of TimelineItemContent::from_suitable_latest_event_content.
It had no branches that returned None.
2023-09-06 12:59:08 +02:00
Jonas Platte 57ba63d432 base: Allow redacted events as latest event 2023-09-06 12:59:08 +02:00
Ivan Enderlin acb731af2f fix: & without an explicit lifetime name cannot be used here
fix: `&` without an explicit lifetime name cannot be used here
2023-09-06 11:04:50 +02:00
Richard van der Hoff 3f3f599877 Add OlmMachine::get_room_event_encryption_info (#2510)
Since the verification status of an event can change, we need to be able to
refetch the verification status without doing the whole decryption dance.

Hence, we expose a new `get_room_event_encryption_info` method.
2023-09-06 10:03:15 +01:00
Richard van der Hoff d116e31733 Implement new CryptoStoreWrapper (#2515)
... so that `VerificationStore` and `StoreInner` can share the same
`save_changes` impl which broadcasts updates to the broadcast channels.
2023-09-06 09:57:40 +01:00
Ivan Enderlin f13282ea30 fix: & without an explicit lifetime name cannot be used here.
This was previously accepted by the compiler but is being phased out;
it will become a hard error in a future release! See https://github.com/
rust-lang/rust/issues/115010.
2023-09-06 09:37:51 +02:00
Benjamin Bouvier 896f62eb68 fix(tests): don't reuse the same store name in multiple tests 2023-09-05 18:45:51 +02:00
Benjamin Bouvier cc469f6d4a chore: derive Default for the state MemoryStore 2023-09-05 15:44:31 +02:00
Jonas Platte 2d47aecd37 Remove the appservice feature from matrix-sdk, matrix-sdk-test 2023-09-05 15:40:38 +02:00
Jonas Platte 7d674b39aa Remove matrix-sdk-appservice
There is unfortunately no capacity for maintaining it as a first-party
component of the Rust SDK.
2023-09-05 15:40:38 +02:00
Benjamin Bouvier 11b3be1a03 feat(notification client): always retry decryption if it failed before
Now that we can decrypt on both of {single|multi} process setups (i.e. available for both android
and ios), we can enable retrying decrypting notifications by default.
2023-09-05 14:17:41 +02:00
Benjamin Bouvier f13adb24dd feat(sync service): enable the encryption sync by default 2023-09-05 14:17:41 +02:00
Benjamin Bouvier 94cfa9fc12 chore(tests): move check_requests from encryption_sync_service to sliding_sync helper file 2023-09-05 14:17:41 +02:00
Benjamin Bouvier 3d89d750fb chore: rename EncryptionSync to EncryptionSyncService 2023-09-05 14:17:41 +02:00
Benjamin Bouvier 242c5bcb37 chore(ui): move xyz/mod.rs to xyz.rs for the encryption_sync and sync_service 2023-09-05 14:17:41 +02:00
Benjamin Bouvier d6f0635023 chore: clippy + review feedback 2023-09-05 11:17:14 +02:00
Benjamin Bouvier ea2826aac6 chore(FFI): update bindings for changes to the NotificationClient builder 2023-09-05 11:17:14 +02:00
Benjamin Bouvier 508091af80 feat: use the encryption sync permit from the SyncService in the NotificationClient
Also rejigger the parameters passed to the notification client builder, so that it's always required to pass
a process setup. With that, we're one step closer to removing the retry_decryption() function and enable it
by default.
2023-09-05 11:17:14 +02:00
Benjamin Bouvier de9b6d25cd feat: have the SyncService own the EncryptionSyncPermit and add try_get_encryption_sync_permit 2023-09-05 11:17:14 +02:00
Benjamin Bouvier 9469b77741 feat: add an EncryptionSyncPermit object allowing to use an EncryptionSync
The comment above the type should help understanding what it is about.
2023-09-05 11:17:14 +02:00
Jonas Platte 06ec19b50b ui: Add test for transfering reply details 2023-09-05 10:39:48 +02:00
Jonas Platte bd99c5e72b ui: Transfer reply details from old to new item when receiving dup event 2023-09-05 10:39:48 +02:00
Jonas Platte bdddb0ce7a ui: Move reply test into a separate module 2023-09-05 10:39:48 +02:00
Jonas Platte 73a9cd40d3 sdk: Remove warning about event without txn ID
… it doesn't make sense to have as long as it's still very common to get
duplicate non-echo events from the SS proxy.
2023-09-05 10:39:48 +02:00
Ivan Enderlin 465c9bcbed test(ui): Test Timeline is reset when a user is ignored/unignored. 2023-09-04 17:39:02 +02:00
Jonas Platte 4f2477fbe8 ui: Reset the timeline when ignore user list changes 2023-09-04 17:39:02 +02:00
Ivan Enderlin cf419566e8 feat(ui): TimelineInnerStateLock::lock is replaced by ::read and ::write
feat(ui): `TimelineInnerStateLock::lock` is replaced by `::read` and `::write`
2023-09-04 15:44:13 +02:00
Damir Jelić e835d9a1cc The export_room_key method does not encrypt the room keys nor does it panic 2023-09-04 15:39:10 +02:00
Ivan Enderlin 91784ded72 feat(ui): TimelineInnerStateLock::lock is replaced by read and write.
The `Timeline` batches its updates to its subscribers (e.g. a client app,
like Element X). A batch is built every time the inner state lock of
the `Timeline` is released. On the paper, it's nice; in practise, even
a read operation on the `Timeline` leads to building a new batch. This
is inefficient and consumes resources (like CPU cycles, FFI boundary
crossings, memory allocations etc.) even if there is no update to put in
the batch: this will just batch empty updates.

To avoid that, one needs to make the difference between read or write
operations onto the inner state. Only the write operations will fire a
batch.

This patch splits the `TimelineInnerStateLock::lock` method into
`::read` and `::write`. The idea is that a read-only lock doesn't
hold a clone of the lock release observer (`lock_release_ob:
SharedObservable<()>`), it will not notify the observer. Then it's only
the write lock that holds a clone of the lock release observer, and will
notify it.

This patch updates the code accordingly as best as possible.
2023-09-04 15:05:52 +02:00
Benjamin Bouvier e8e7738dfa chore: introduce fail! macro to avoid repetitive work 2023-09-01 16:06:46 +02:00
Benjamin Bouvier 2d5f5879ab chore: remove spurious clone 2023-09-01 16:06:46 +02:00
Benjamin Bouvier 0162e62feb fix: don't save the latest_id_token upon refresh (thanks @zecakeh!) 2023-09-01 16:06:46 +02:00
Benjamin Bouvier d37656d9f0 chore: use a hash() function instead of hashing manually 2023-09-01 16:06:46 +02:00
Benjamin Bouvier 5451d39ba3 chore: move notification within the refresh_access_token_inner function 2023-09-01 15:15:02 +02:00
Benjamin Bouvier a17a7608f3 chore: add more focused logs for OIDC 2023-09-01 15:15:02 +02:00
Benjamin Bouvier 4cdef7255e fix: save the OIDC refresh token from the response (!) 2023-09-01 15:15:02 +02:00
Jonas Platte 2b18a02488 ffi: Use avatar_url from sliding sync for RoomInfo where applicable 2023-09-01 10:47:48 +02:00
Jonas Platte db565fcff3 ci: Improve caching for matrix-rust-components-swift and tarpaulin 2023-09-01 10:43:52 +02:00
Jonas Platte e02676616f sdk: Make use of clonable FnOnce in event handlers 2023-09-01 10:42:22 +02:00
Jonas Platte a6b4e04181 sdk: Revert observable diff buffer capacity change 2023-09-01 10:06:07 +02:00
Benjamin Bouvier d060ec2830 chore: add e2e-encryption cfg guards 2023-08-31 16:08:45 +02:00
Benjamin Bouvier 51dcdac46d TERRIBLE HACK: save the pos value in the crypto store 2023-08-31 16:08:45 +02:00
Benjamin Bouvier be3616c6b2 chore: rename restore_pos_from_database to share_pos 2023-08-31 16:08:45 +02:00
Benjamin Bouvier 05a8343d03 chore: rename previous_pos to pos 2023-08-31 16:08:45 +02:00
Benjamin Bouvier 28d25882c2 chore: fmt + clippy 2023-08-31 16:08:45 +02:00
Benjamin Bouvier 5eb455032e tests: add test and maintain property that in-memory pos == db pos at all times 2023-08-31 16:08:45 +02:00
Benjamin Bouvier 6b84d03e2f feat(encryption sync): restore the stream position from the database 2023-08-31 16:08:45 +02:00
Benjamin Bouvier 08b9f0640c feat: add a new sliding sync option to restore the stream position from the database 2023-08-31 16:08:45 +02:00
Benjamin Bouvier 4b67a6608e feat: persist previous pos when saving/restoring a sliding sync 2023-08-31 16:08:45 +02:00
Benjamin Bouvier 941ecbfe0d chore: refactor fields restored by restore_sliding_sync_state 2023-08-31 16:08:45 +02:00
Ivan Enderlin 719cbee96e feat(ui): Fine-tuning RoomList again
feat(ui): Fine-tuning `RoomList` again
2023-08-31 12:57:27 +02:00
Benjamin Bouvier 11404010e6 chore: disable colors for logging in FFI for logcat and stdout too 2023-08-31 12:13:25 +02:00
Ivan Enderlin 4b04f15bc5 chore(ui): Naming is hard :-). 2023-08-31 12:04:14 +02:00
Doug 7e71c79072 chore(sdk): Log the OIDC refresh token (hashed). (#2486)
* chore(sdk): Log the OIDC refresh token (hashed).
* chore(sdk): Fix Clippy and PR comments.
2023-08-31 09:25:46 +00:00
Benjamin Bouvier 50a3da386e feat: enable read receipts in the room list service sliding sync 2023-08-31 11:08:56 +02:00
Benjamin Bouvier eebf271d6c chore: use a workspace dependency for assert-json-diff 2023-08-31 10:34:46 +02:00
Benjamin Bouvier 4665277842 test(sliding sync): skipping b/o mode change doesn't change parameters in other lists
w
2023-08-31 10:34:46 +02:00
Ivan Enderlin 5a0c230a2d feat(ui): visible_rooms can shrink its timeline_limit.
This patch updates the behavior of `visible_rooms` where its
`timeline_limit` is shrunk and expanded when the state machine is
recovering.
2023-08-31 10:31:44 +02:00
Ivan Enderlin 7819938149 feat(ui): invites is always defined in RoomListService.
This patch updates `RoomListService` to install the `invites` sliding
sync list from the start, along with `all_rooms`. Prior to the patch,
`invites` was installed after the first sync.

`invites` is installed in selective sync-mode with a range of `0..=0`.
After the next sync, `invites` switched its sync-mode to growing with a
batch size of `0..=19`.
2023-08-30 21:20:29 +02:00
Jonas Platte 06a19f016e ffi: Only ever call ClientDelegate methods in a blocking task
… and clean up a few unnecessary Arc's.
2023-08-30 15:29:06 +02:00
Jonas Platte 5630851062 Upgrade Ruma 2023-08-30 15:22:00 +02:00
Ivan Enderlin 6b50a8988b Merge pull request #2463 from matrix-org/jmartinesp/add-x86-64-workaround-to-crypto-sdk-in-main
Add the x86-64 Android workaround to the Crypto SDK too
2023-08-30 15:12:17 +02:00
Jonas Platte 1311ddbae3 ffi: Disable colorization of tracing fields 2023-08-30 14:07:22 +02:00
Ivan Enderlin 5564d323f5 fix(ui): Try to make RoomListService fast for gigantic accounts with various network speeds
fix(ui): Try to make `RoomListService` fast for gigantic accounts with various network speeds
2023-08-30 14:06:23 +02:00
Ivan Enderlin 3062f30e08 chore(ffi): Add the RoomListServerState::Recovering variant. 2023-08-30 13:17:05 +02:00
Ivan Enderlin e8815d83b8 feat(ui): Add a new Recovering intermediate state in RoomListService.
This patch takes inspiration of
https://github.com/matrix-org/matrix-rust-sdk/pull/2480.

This patch adds a new `Recovering` state, which is a “transition”
between `Error` and `Terminated` to `Running`. When moving from `Error`
or `Terminated` to `Recovering`, `all_rooms`' sync-mode is set to
`Selective` with its initial range. Then when moving from `Recovering`
to `Running`, `all_rooms`' sync-mode is set to `Growing` with its
initial range again. For the `invites` list, it is reset to its initial
range when moving to `Recovering` too.

`Error` and `Terminated` now act the same.
2023-08-30 13:13:16 +02:00
Jonas Platte ca0c1f567a sdk: Add widget::EventFilter matching
Co-authored-by: Timo K <toger5@hotmail.de>
Co-authored-by: Daniel Abramov <inetcrack2@gmail.com>
2023-08-30 12:57:54 +02:00
Jonas Platte 04fee2952f sdk: Split widget EventFilter into sub-types
… and move them into their own module.

Co-authored-by: Timo K <toger5@hotmail.de>
Co-authored-by: Daniel Abramov <inetcrack2@gmail.com>
2023-08-30 12:57:54 +02:00
Jonas Platte c589bd0cd1 sdk: Add extra docs for widget channels 2023-08-30 12:57:54 +02:00
Jonas Platte 959b594c43 sdk: Rename widget::Info to WidgetSettings 2023-08-30 12:57:54 +02:00
Alfonso Grillo c567f963d5 ffi: Add send fn's for poll response and poll end 2023-08-30 09:44:08 +00:00
Ivan Enderlin e3aec5ebbc fix(ui): Update batch_size of all_rooms to 100.
This patch updates the `batch_size` of `all_rooms` once in growing
sync-mode to 100. It was previously increased from 50 to 200 in
12a1f25ec3. In some situations, it
generates very large payloads that can take time to be delivered to the
user with a slow network.

This patch tries to fine-tuned the `batch_size` value.
2023-08-30 08:48:55 +02:00
Ivan Enderlin e5a5dac099 fix(ui): Revert timeline_limit to 1 for all_rooms.
This patch reverts b2cc279279. On the
paper, it was a good idea. In practise, it has revealed a bug on the
server side. The only solution to mitigate this bug for now is to revert
the `timeline_limit` to 1.
2023-08-30 08:38:05 +02:00
Nicolas Mauri 1cc11ae988 feat(ffi): Add a notification_mode property to room_info (#2460)
* feat(ffi): Add a notification_mode property to room_info
* feat(sdk): Add a notification_mode() function to Room
* Fix Rust syntax
2023-08-29 12:25:26 +00:00
Doug 58d30454ae feat(bindings): Add logo_uri to OidcConfiguration
… and make most OidcConfiguration properties optional.
2023-08-29 13:35:10 +02:00
Jonas Platte 0590543df1 ffi: Add custom tracing log formatter (#2464)
Co-authored-by: Benjamin Bouvier <public@benj.me>
2023-08-28 15:05:21 +00:00
Ivan Enderlin 30731d60d7 feat(sdk): Adjust room_list observable capacity
feat(sdk): Adjust `room_list` observable capacity
2023-08-28 16:58:05 +02:00
Benjamin Bouvier 98dafac236 feat: time how long it takes to restore lists from the cache 2023-08-28 16:52:43 +02:00
Benjamin Bouvier b6c658aefa feat: introduce timer helper 2023-08-28 16:52:43 +02:00
Ivan Enderlin c23e8863fc feat(sdk): Adjust room_list observable capacity.
Prior to this patch, we have increased the
`SlidingSyncListInner::room_list` capacity, to avoid trigger
`VectorDiff::Reset` as much as possible. Now that Element X is optimised
to handle larger diff, we can discrease this number, yeeeee :-).
2023-08-28 16:33:02 +02:00
Ivan Enderlin 9d9add39fb Merge pull request #2466 from Hywan/feat-ui-roomlist-all-rooms-timeline-limit-0 2023-08-28 15:29:27 +02:00
Ivan Enderlin b2cc279279 feat(ui): Change all_rooms to timeline_limit=0.
When a user has hundreds of rooms, `RoomListService` will fetch at worst
one event per room, which can generate large responses. Let's use a
`timeline_limit=0`.
2023-08-28 14:50:55 +02:00
aringenbach 8cb00510d2 ffi: use RoomMessageEventContentWithoutRelation for send / reply / edit 2023-08-28 11:26:51 +02:00
Nicolas Mauri 63196aa6aa fix(sdk): limit the number of retries when updating push rules. (#2461)
* fix(sdk): limit the number of retries when updating push rules.
* fix Rust format
2023-08-25 15:11:49 +00:00
Jorge Martín e7ad46f5a0 Fix formatting 2023-08-25 14:37:09 +02:00
Jonas Platte 2311edecf6 ui: Remove unused import 2023-08-25 14:14:56 +02:00
Jonas Platte aed9b20195 Silence clippy lint arc_with_non_send_sync on wasm 2023-08-25 14:14:56 +02:00
Jorge Martín 1d08ffa05e Add the x86-64 Android workaround to the Crypto SDK too 2023-08-25 13:31:12 +02:00
Jonas Platte e02aa6b132 ffi: Add Room::{room_info, subscribe_to_room_info_updates} 2023-08-25 11:39:57 +02:00
Jonas Platte 9a0869dff8 base: Add Room::subscribe_info 2023-08-25 11:39:57 +02:00
Jonas Platte 72b11d5cc6 sdk: Replace Arc<RwLock<_>> around RoomInfo with SharedObservable 2023-08-25 11:39:57 +02:00
Ivan Enderlin 8f754a4f05 fix(base): BaseClient::ignore_user_list_changes is no longer behind an Arc
fix(base): `BaseClient::ignore_user_list_changes` is no longer behind an `Arc`
2023-08-24 15:17:14 +02:00
Jonas Platte 320f5c2155 Rename feature flag for widgets 2023-08-24 14:55:55 +02:00
Jonas Platte 1c3dd38b97 ffi: Add widget API skeleton 2023-08-24 14:55:55 +02:00
Ivan Enderlin 0c21827a5a fix(base): BaseClient::ignore_user_list_changes is no longer behind an Arc.
This patch first off renames `BaseClient::ignore_user_list_changes_tx`
to `::ignore_user_list_changes`.

This patch then changes the type from `Arc<SharedObservable<_>>` to
simply `SharedObservable` as this type implement `Clone`. We basically
have a double-`Arc` here.

Finally, this patch adds documentation for this field.
2023-08-24 14:54:40 +02:00
Jonas Platte 7aa6981e37 Make update_timeline_item macro compatible with Rust 1.70
… by swapping the branches around. Previously, invocations meant to
match the found + not_found branch were actually hitting the other one
prior to Rust 1.71, likely due to parser supporting type ascription
(even though it was an unstable feature).
2023-08-24 13:42:44 +02:00
Ivan Enderlin c742affa13 feat(ui): Reduce and refresh the batch_size growing sync-mode of invites in RoomListService
feat(ui): Reduce and refresh the `batch_size` growing sync-mode of `invites` in `RoomListService`
2023-08-24 13:32:29 +02:00
Ivan Enderlin 55e8f2573b feat(ui): Add the ResetInvitesListGrowingSyncMode action in RoomList.
Inside `RoomListService`, the `State` enum handles the transition from
one state to another. In case of some `State::Error`, the `all_rooms`
sliding sync was refreshed, i.e. its sync-mode was reset to its initial
value.

This patch also refreshes the `invites` sliding sync list! It adds
the `ResetInvitesListGrowingSyncMode` action, and attaches it to the
`refresh_lists` actions.

New constants are added to represent default `batch_size` values for the
growing sync-mode for various sliding sync list. It could be helpful for
further maintenance.

This patch finally adds and updates the tests accordingly.
2023-08-24 13:07:28 +02:00
Ivan Enderlin e82607c743 chore(cargo) Update ruma
chore(cargo) Update `ruma`
2023-08-24 12:41:56 +02:00
Jonas Platte aac6294755 Rename test modules to tests
… for consistency.
2023-08-24 12:28:34 +02:00
Jonas Platte 3c8a59a43a Remove module::* imports 2023-08-24 12:28:34 +02:00
Ivan Enderlin 4e25a8c3c1 chore(cargo): Update ruma. 2023-08-24 12:17:40 +02:00
Ivan Enderlin 3dbc00cd67 feat(ui): Reduce the batch_size of invites in RoomListService.
This patch changes the `batch_size` of the sliding sync list `invites`
for `RoomListService`. Previous value was 100, new value is 20.

For accounts that have a large number of invites, it won't slow the
rendering of `visible_rooms`.
2023-08-24 10:36:04 +02:00
Marco Romano b2a1e3d268 Bump ruma 2023-08-24 07:37:10 +00:00
Jonas Platte 8deb0ff2e1 base: Handle redactions if e2ee is disabled 2023-08-23 17:20:26 +02:00
Jonas Platte 2fb6bdc24c Fix more clippy lints 2023-08-23 17:20:11 +02:00
Jonas Platte 24d2ccd5f0 base: Make BaseRoomInfo::handle_redaction private
It should only be called from RoomInfo::handle_redaction.
2023-08-23 17:19:51 +02:00
Jonas Platte 9fc5a7dc92 base: Add some logging for handle_redaction 2023-08-23 17:19:51 +02:00
Daniel Abramov 6ecd640ad7 Widget API: Initial skeleton 2023-08-23 15:08:51 +00:00
Marco Romano 3bc7b9136e ui: Add support for polls in timeline 2023-08-23 12:57:52 +00:00
Ivan Enderlin 4dbb0a7cc7 fix(ui): Tweak State of RoomListService when session is forced to expire
fix(ui): Tweak `State` of `RoomListService` when session is forced to expire
2023-08-23 13:28:08 +02:00
Ivan Enderlin 2dd1caaeab doc(sdk,ui): Fix typos. 2023-08-23 13:07:24 +02:00
Ivan Enderlin 6736a4a05f Update crates/matrix-sdk-ui/src/room_list_service/mod.rs
Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
2023-08-23 13:05:21 +02:00
Ivan Enderlin 8c234f0d0d test(ui): Test that RoomList::expire_sync_session ends up in Error. 2023-08-23 12:13:54 +02:00
Jonas Platte 4df1ee140a Fix clippy lints 2023-08-23 11:36:21 +02:00
Ivan Enderlin 0dacf6edc3 fix(ui): Tweak State of RoomList when session is forced to expire.
Usually, when the sliding sync session expires, it leads the state to
be `Error`, thus some actions (like refreshing the lists) are executed.
However, if the sync-loop has been stopped manually, the state is
`Terminated`, and when the session is forced to expire, the state
remains `Terminated`, thus the actions aren't executed as expected.
Consequently, this patch updates the state to `Error` manually.
2023-08-23 11:24:01 +02:00
Ivan Enderlin 5b28e641c4 Merge pull request #2441 from matrix-org/dependabot/cargo/rustls-webpki-0.101.4
chore(deps): bump rustls-webpki from 0.101.2 to 0.101.4
2023-08-23 09:17:11 +02:00
dependabot[bot] 9bf214925c chore(deps): bump rustls-webpki from 0.101.2 to 0.101.4
Bumps [rustls-webpki](https://github.com/rustls/webpki) from 0.101.2 to 0.101.4.
- [Release notes](https://github.com/rustls/webpki/releases)
- [Commits](https://github.com/rustls/webpki/compare/v/0.101.2...v/0.101.4)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-08-22 18:10:40 +00:00
Jonas Platte 0d24bcf6e5 Revert "bindings: Use new uniffi-bindgen build mode"
This reverts commit 329b6c4eb1.
2023-08-22 18:40:20 +02:00
Kévin Commaille e01421a3dd Upgrade Ruma
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-08-22 17:25:02 +02:00
Jonas Platte 329b6c4eb1 bindings: Use new uniffi-bindgen build mode 2023-08-22 11:12:55 +02:00
Jonas Platte ef0549b8b8 xtask: Use camino path types 2023-08-22 11:12:55 +02:00
Doug 60392c299d bindings: Add OIDC support to AuthenticationService
- Use OIDC for logout when appropriate.
- Allow server's that support OIDC but not passwords to work.
- Only sign out users if token refresh is explicitly refused.
- Expose the OIDC account URL.
- Support for RP initiated logout.
2023-08-22 09:06:32 +00:00
Benjamin Bouvier 4493cbf0ac chore: rework Room::sync_up so it's really async 2023-08-21 19:36:33 +02:00
Benjamin Bouvier b7e18352c4 fix: read RoomInfo data at the very last minute before saving it
Also take ownership of the sync lock in write mode, since this operation could run concurrently
to room_joined/room_left events.
2023-08-21 19:36:33 +02:00
Benjamin Bouvier 936b6980c9 chore: move SyncTokenAwareClient to the common test helpers 2023-08-21 19:36:33 +02:00
Benjamin Bouvier e262db3505 test: write an integration test for missing keys during encryption 2023-08-21 19:36:33 +02:00
Benjamin Bouvier 0d67d14201 feat: query keys for newly sync'd members when sending encrypted message 2023-08-21 19:36:33 +02:00
Jonas Platte 78ad6a6530 ui: Remove JSON on RemotEventTimelineItem when it's redacted locally 2023-08-21 15:54:25 +02:00
Jonas Platte a5a541ec98 ui: Improve comment in redaction code
(move it to a more logical place)
2023-08-21 15:54:25 +02:00
Jonas Platte d395648165 ui: Remove outdated comment
The relevant decryption work is already done in a separate async task,
spawned in `TimelineInner::retry_event_decryption_inner`.
2023-08-21 15:00:00 +02:00
Benjamin Bouvier f5ab1084eb fix: temporarily use the pip install method for the setup-matrix-synapse action
Until https://github.com/michaelkaye/setup-matrix-synapse/issues/95 is properly resolved.
2023-08-21 11:54:25 +02:00
Benjamin Bouvier 81daf5c90a test(sliding sync): add test that caused a deadlock before this PR 2023-08-21 11:48:51 +02:00
Benjamin Bouvier c0b18c291d chore: make clippy happy 2023-08-21 11:48:51 +02:00
Benjamin Bouvier 6988bd1e6f feat(sliding sync): remove the response_handling_lock and extend the position's lock responsibilities
In the previous situation, we had two locks with similar responsibilities, the `response_handling_lock`
and the `position` lock. The latter *almost* covered the former's critical zone, albeit for a single
function call, which left room for a deadlock situation (latter taken, then former, then latter).

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

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

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

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

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

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

The impacts are the following:

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

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

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

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

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

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

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

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

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

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

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

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

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

To rectify this, the commit proposes that Room::is_encrypted analyze the
information stored in the in-memory RoomInfo, which is maintained by the
Room::request_encryption_state method. This approach mirrors the existing
behavior of Room::is_encrypted when it processes the code path where the
m.room.encryption state event has already been retrieved.
2023-08-11 13:58:12 +02:00
Damir Jelić bd1b6e7a27 Instrument the Room::send_raw method 2023-08-11 13:58:12 +02:00
Damir Jelić eae8437321 Add a test for the Room::is_encrypted method 2023-08-11 13:58:12 +02:00
Jonas Platte d14e23a676 ffi: Remove tracing callsite column, make line optional 2023-08-11 12:10:58 +02:00
Jonas Platte f7d52dfdc1 ffi: Make tracing more flexible
… at the expense of some performance.
2023-08-11 12:10:58 +02:00
Benjamin Bouvier 6e62569b8a feat(sync service): don't intertwine the state of both sliding syncs (#2362)
## Feature

There are now three tasks running in the sync service:

- the room list sliding sync task
- the encryption sync task
- a new scheduler task, that listens to messages sent by both of the previous tasks, and will take care of cleaning up tasks, stopping the services, and setting states after it received a message.

When any of the sliding sync fails, it sends a message to the scheduler task, indicating why it stopped (error or not, was it an expired session or not). Then the scheduler task will do any necessary cleanup.

`stop()` (née `pause()`) can now make use of that scheduler task as well, by sending a report requesting to stop both tasks and services. Responsibilities are now cleanly split: in particular, I like it much better that the room list task doesn't have to stop the encryption sync itself, since it's not really its duty. (And this avoids lots of code duplication to cleanup tasks and stop services.)

## Testing

This also tests the `SyncService` states. Unfortunately it's not perfectly deterministic in two places:

- we can't predict how many requests will be sent to the server (although, with the mocking server responding in 50ms, and considering a waiting time of e.g. 300ms, it should send at least two requests).
- the test `pause()` and re`start()` the sync service at some point, and then we can't guess what the next `pos` will be, in any of the syncs: it could either be the previous value (if we aborted while processing the previous response), or the next value (meaning we could finish processing the sliding sync response).

Still, it confirms at least that pausing and resuming work as expected.

---

Fixes #2382
2023-08-11 08:55:48 +00:00
Jonas Platte 5943f5f7f3 sdk: Set content-length header when streaming HTTP request body 2023-08-11 09:21:58 +02:00
Alfonso Grillo 364a4ae5a9 ffi: Add create-poll API 2023-08-10 15:38:17 +00:00
Ivan Enderlin 0372467288 chore(uniffi): Update uniffi to another branch.
This patch switches UniFFI from
https://github.com/mozilla/uniffi-rs/pull/1684 to
https://github.com/mozilla/uniffi-rs/pull/1697.
2023-08-10 17:33:36 +02:00
Benjamin Bouvier 159786fe36 feat(notification client): bump sliding sync timeouts (#2403)
The timeouts were a bit too agressive, according to some user logs, resulting in failing to
load the event mentioned in the notification.

Here's the rationale for the new timeouts: we're only limited by the iOS process which has *at
most* 30 seconds to process a notification.

- We're running at most 3 requests of the notification sliding sync, so that will be (1+3)*3 = 12
seconds allocated for that.
- If we've found an event but it required decryption, we're running the encryption sync up to
2 times, (3+4) seconds each => 14 seconds.

At most we're eating up 26 seconds of the entire time, leaving some ballast for the rest of
the program.
2023-08-10 17:31:14 +02:00
Ivan Enderlin e9d6a9bfd7 chore: Remove unnecessary clones
chore: Remove unnecessary clones
2023-08-10 16:51:41 +02:00
Ivan Enderlin 361bc18757 fix(ui): Add m.room.member: $LAZY in the require states of visible_rooms
fix(ui): Add `m.room.member: $LAZY` in the require states of `visible_rooms`
2023-08-10 16:24:58 +02:00
Nicolas Mauri ac42d07de7 sdk+ffi: in notification settings, replace members_count by is_one_to_one for more clarity 2023-08-10 16:19:11 +02:00
Ivan Enderlin 2290bae942 feat(ui): Room::latest_event uses Timeline if it exists.
This patch optimises the previous patch by simplifying the use of
`Timeline`. If the `Timeline` exists, let's return the `latest_event`
every time: whether it is a remote _or_ a local event.
2023-08-10 16:00:06 +02:00
Ivan Enderlin e0163e67be feat(ui): Room::latest_event returns the Timeline local event if any.
This patch updates `Room::latest_event` to return the `Timeline` local
event if any.

First off, it starts by checking if a `Timeline` exists. It won't create
it if it doesn't exist! Second, it checks whether a latest event exists.
Finally it checks whether it's a local event.

This patch also updates the tests accordingly.
2023-08-10 15:59:50 +02:00
Ivan Enderlin e8cd21034b chore: Remove unnecessary clones.
The types used here are not implementing `Clone`, so calling `clone`
on them` copies the reference, which does not do anything and can be
removed.
2023-08-10 15:15:06 +02:00
Ivan Enderlin f64a46a2be Merge pull request #2396 from matrix-org/nicolas/notification_settings_user_defined_room_rules
sdk+ffi: Get the user-defined notification mode for a room and all rooms for which a user-defined rule exists.
2023-08-10 14:11:35 +02:00
Ivan Enderlin 0af918b8a7 feat(sdk): Skip Sliding Sync Response if it's been received already
feat(sdk): Skip Sliding Sync `Response` if it's been received already
2023-08-10 13:35:21 +02:00
Ivan Enderlin c5d2181549 test(sdk): Ensure that avatar is serialized as expected in FrozenSlidingSyncRoom
test(sdk): Ensure that `avatar` is serialized as expected in `FrozenSlidingSyncRoom`
2023-08-10 13:30:40 +02:00
Ivan Enderlin 2b938e3f03 doc(sdk): Fix a typo.
Co-authored-by: Benjamin Bouvier <public@benj.me>
2023-08-10 13:17:15 +02:00
Ivan Enderlin 817690206c feat(sdk): Create SlidingSync::expire_session.
For the sake of clarity, this patch extracts some code into its own
`SlidingSync::expire_session`.
2023-08-10 12:14:42 +02:00
Jonas Platte 4bfcc6669d Use simpler construction functions for tokio::broadcast::Sender 2023-08-10 12:04:40 +02:00
Jonas Platte f8eefadb2d Upgrade tokio to 1.30 2023-08-10 12:04:40 +02:00
Richard van der Hoff f51bc47949 Fix rust doc on IndexedDBStore (#2394)
it's not in-memory
2023-08-10 11:47:56 +02:00
Ivan Enderlin 5d8b0c1a0d feat(sdk): Save positions at the end of handle_response. 2023-08-10 11:31:18 +02:00
Nicolas Mauri 8c6e3949e0 sdk+ffi: allow to get all room IDs for which a user-defined rule exists. 2023-08-10 10:02:11 +02:00
Nicolas Mauri 0a52fc895e ffi: Allow to get the user-defined notification mode for a room 2023-08-10 09:51:10 +02:00
Ivan Enderlin 51c25a4456 feat(ui): Implement RoomList::entries_with_dynamic_filter
feat(ui): Implement `RoomList::entries_with_dynamic_filter`
2023-08-10 08:28:43 +02:00
Ivan Enderlin d20e82380a test(ui): Adjust pos. 2023-08-09 18:07:18 +02:00
Ivan Enderlin 1f7ce2893b feat(sdk): Skip Sliding Sync Response if it's been received already.
A Sliding Sync `v4::Response` contains a `pos` value. It helps to identify
progress during several requests/responses. If two requests with the
same `pos` are sent, the server **must** reply with the same response,
as defined in the specification.

The corollary is: If a response contains a `pos` that has already
been received, the client **must** ignore it, otherwise it can create
duplications. For example, let a response containing sync operations,
like `DELETE` or `INSERT`, with indexes: if this pair of operations are
repeated twice with the same index, it creates a broken state.

To avoid this behaviour, this patch stores the last 20 position markers
received from the server. If a response contains a `pos` that has
already been received, a (new) error is returned. As with all the other
errors, the sync-loop is stopped, and must restarted. The past positions
survive to this restart, as for the rest of the state.

When the server replies with a `M_UNKNOWN_POS`, the `pos` and the
`past_positions` are all cleared.
2023-08-09 17:18:29 +02:00
Ivan Enderlin b1b0641150 test: Ensure that avatar is serialized as expected. 2023-08-09 15:30:26 +02:00
Ivan Enderlin 696e10bdad chore: Use async_test instead of tokio::test. 2023-08-09 15:30:13 +02:00
Ivan Enderlin 0f94f93080 chore: When LSP is broken… :-) 2023-08-09 15:18:24 +02:00
Ivan Enderlin 55ba580c0d chore: Simplify Fn declaration. 2023-08-09 15:08:05 +02:00
Ivan Enderlin da7e05f18f feat(ffi): Use an enum to set dynamic filter.
This patch removes
`RoomListEntriesDynamicFilter::set_with_fuzzy_match_pattern` and
replaces it by a single `::set` method. It takes a new enum as
parameter: `RoomListEntriesDynamicFilterKind`. This enum has a
`FuzzyMatchRoomName` variant to simulate the removed method. It also
adds the `All` variant, to represent the `all` filter.
2023-08-09 15:00:09 +02:00
Ivan Enderlin f35275f4fc feat(ui): Implement a new filter: all.
This patch implements a new `all` filter.
2023-08-09 14:51:15 +02:00
Ivan Enderlin 90682270ae feat(ffi): Implement RoomList::entries_with_dynamic_filter.
First, this patch makes `RoomList::entries` infallible.

Second, this patch implements `RoomList::entries_with_dynamic_filter`.
2023-08-09 14:16:23 +02:00
Ivan Enderlin 3c46a1019b test(ui): Update some tests about fuzzy matcher.
These test cases are more easy to understand than the previous one if
you ask me.
2023-08-09 14:15:10 +02:00
Ivan Enderlin 61f481c126 test(ui): Test RoomList::entries_with_dynamic_filter.
This patch updates the tests to ensure `entries_with_dynamic_filter`
works as expected.
2023-08-09 13:53:14 +02:00
Ivan Enderlin bd2f5119db feat(ui): Rename entries_filtered to entries_with_static_filter.
Because it makes more sense.
2023-08-09 13:52:55 +02:00
Jonas Platte 1b8768becc Use AsyncCell instead of mpsc channel 2023-08-09 13:24:39 +02:00
Damir Jelić 3d3021efc0 Expose bindings to manage dehydrated devices 2023-08-09 12:32:48 +02:00
Damir Jelić 64ca96543e Initial support for dehydrated devices
Co-authored-by: Jonas Platte <jplatte@matrix.org>
2023-08-09 12:32:48 +02:00
Damir Jelić 8ce3b56180 Allow an Olm Account to generate its own device id 2023-08-09 12:32:48 +02:00
Damir Jelić 3e2f531caa Split out the receive_sync_changes method into a helper
This splits the method out so the bigger chunks doesn't persist the
changes in the store.

This will be useful if we need to hijack the changes and persist them in
a different store.
2023-08-09 12:32:48 +02:00
Jonas Platte 56f771a347 ui: Remove unnecessary boxing 2023-08-09 10:46:13 +02:00
Ivan Enderlin 1ab0d2081a doc(ui): Add inline comments. 2023-08-09 10:01:24 +02:00
Ivan Enderlin 90c30e4058 ui: Add RoomList::entries_with_dynamic_filter 2023-08-09 10:01:15 +02:00
Ivan Enderlin 752e814168 fix(ui): Add m.room.member: $LAZY in the require states of visible_rooms.
This patch tries to fix https://github.com/vector-im/element-x-
ios/issues/1204 by adding the following required states in the
`visible_rooms` sliding sync list: `m.room.member: $LAZY`.
2023-08-09 09:11:20 +02:00
Benjamin Bouvier 80c9464f1e chore: fix typo in cargo xtask kotlin doc comment (#2387) 2023-08-08 16:00:20 +02:00
Benjamin Bouvier 625acb056a feat(ffi): add an optional file layer for tracing (#2384)
* feat(ffi): add an optional file logger

Also makes logging to stdout/logcat optional.

* WIP: stupidly duplicate code 🤷

* ffi: Get rid of duplication in tracing initialization

* feat: add OtlpTracingConfiguration too

* feat: log either to stdout on non-android or logcat on android

---------

Co-authored-by: Jonas Platte <jplatte@matrix.org>
2023-08-08 12:37:32 +00:00
Nicolas Mauri ff9923c6a6 Allow to define the default notification mode for a given room type (#2369)
* Add a function to define the default notification mode for a given kind of room

* Code refactoring

* sdk+ffi: code refactoring
2023-08-08 14:20:17 +02:00
Kévin Commaille 1680a7d4d6 sdk: Set the refresh token lock if refresh token is missing
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-08-08 12:16:03 +02:00
Kévin Commaille 302cff6ba9 sdk: Make RefreshTokenError authentication API-agnostic
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-08-08 12:16:03 +02:00
Ivan Enderlin dc3636d766 feat(ui): Turn on cached list for SlidingSync in RoomListService
feat(ui): Turn on cached list for `SlidingSync` in `RoomListService`
2023-08-08 11:29:51 +02:00
Ivan Enderlin 87f7fc7367 chore: Update Cargo.lock. 2023-08-07 17:48:17 +02:00
Ivan Enderlin 741bb1c12d chore: Update Cargo.lock. 2023-08-07 17:20:19 +02:00
Ivan Enderlin 7e371a642a feat(ui): Turn on cached list for SlidingSync in RoomListService.
Now is a good time to re-enable the cache :-).
2023-08-07 15:54:08 +02:00
Ivan Enderlin 1c01a146b1 chore: Update Cargo.lock. 2023-08-07 12:10:44 +02:00
Jonas Platte 074fd8b335 Upgrade opentelemetry crates 2023-08-06 12:02:41 +02:00
Benjamin Bouvier 5c74a597eb nit: prefer using assert_matches! in tests 2023-08-04 17:41:47 +02:00
Benjamin Bouvier dd3cab9409 fix: don't try /context when a notification has been filtered out 2023-08-04 17:41:47 +02:00
Benjamin Bouvier aea0b00ac2 chore: add comments to get_notification about the return type 2023-08-04 17:41:47 +02:00
Benjamin Bouvier e1c928f121 fix: compute whether a room is a DM before joining it
If we were invited and joined a room, then the computation of is_direct() was happening after
joining, and depended on the presence of a global account event of type "m.direct". This event
is added by the "set_is_direct()" call thereafter, so this couldn't ever happen.

This fixes it by computing the is_direct field *before* joining the room, and then marking the
room as a DM based on that.
2023-08-04 17:41:47 +02:00
Benjamin Bouvier 7676ff509f nit: remove else after return 2023-08-04 17:41:47 +02:00
Benjamin Bouvier 10f709450e tests(notification): add integration tests for notification events 2023-08-04 17:41:47 +02:00
Jonas Platte 4ebc3d70ad Hide test helpers from documentation 2023-08-03 21:39:56 +02:00
Jonas Platte 1679669376 Remove the 'testing' feature from matrix-sdk-ui
At the expense of slightly increasing our public API, but we can always
deprecate things.
2023-08-03 21:39:56 +02:00
Jonas Platte edc6428e69 Fix clippy warnings 2023-08-03 21:39:56 +02:00
Kévin Commaille a434b97c54 sdk: Don't derive (De)serialize for AuthSession
It turns out not all authentication API sessions (i.e. OIDC) are fully (de)serializable.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-08-03 20:47:30 +02:00
Ivan Enderlin 6c0f24b657 chore: Update UniFFI fork
chore: Update UniFFI fork
2023-08-03 15:42:30 +02:00
Ivan Enderlin 2481e1f97e chore: Update UniFFI fork. 2023-08-03 15:36:52 +02:00
Benjamin Bouvier bf754667d9 chore: get rid of Client::inherit_session
It does the same as `restore_session` now. Thanks @zecakeh for finding this out!
2023-08-03 14:10:32 +02:00
Nicolas Mauri 61d4d5b096 Fix an arithmetic overflow 2023-08-02 18:25:35 +02:00
Jonas Platte ea03b821fd ffi: Use UniFFI fork with future cancellation support
Upstream PR: https://github.com/mozilla/uniffi-rs/pull/1684
2023-08-02 16:16:24 +02:00
Jonas Platte f1b4b80460 ffi: Don't spawn tokio tasks for add_timeline_listener, send_attachment 2023-08-02 16:16:24 +02:00
Jonas Platte b39d06353a Revert "ffi: Spawn tokio tasks for the remaining async fns"
This reverts commit eb4dab138e.
2023-08-02 16:16:24 +02:00
Jonas Platte 34be01ecf2 Revert "ffi: Remove async from a few functions"
This reverts commit fc3883d08e.
2023-08-02 16:16:24 +02:00
Jonas Platte 0f6dd644b5 Upgrade async-rx 2023-08-01 17:31:29 +02:00
Jonas Platte 7d9d600eda ui: Only lock TimelineInnerState once per back-pagination response 2023-08-01 17:31:29 +02:00
Jonas Platte 8ac0f099f6 ui: Exclude Debug implementation from coverage 2023-08-01 17:31:29 +02:00
Jonas Platte 640e5fbacf ffi: Use batched timeline subscription 2023-08-01 17:31:29 +02:00
Jonas Platte 9a8c6249bb ui: Add Timeline::subscribe_batched 2023-08-01 17:31:29 +02:00
Jonas Platte a65cff01f7 ui: Create subscribe integration test sub-module 2023-08-01 17:31:29 +02:00
Benjamin Bouvier 80243615c4 chore(test): make the clear_with_echoes test more deterministic 2023-08-01 15:57:12 +02:00
Benjamin Bouvier a6aaf164aa chore(sliding sync): add logs for the limited flag computation
This should help us debug issues with false negatives.
2023-08-01 15:57:12 +02:00
Benjamin Bouvier ace282126f ffi(notifications): include full timeline event again in the NotificationEvent
The full timeline event contains both the timestamp (requested in #2361) and the sender id;
now the sender id for the invite can also be contained in there, minimizing the amount of copying we're doing in the
FFI code.

Fixes #2361.
2023-08-01 15:09:18 +02:00
Nicolas Mauri 6961a7fb36 Fix is_user_mention_enabled and is_room_mention_enabled (#2357)
* Fix is_user_mention_enabled, is_room_mention_enabled

* Fix: XXX comments in UnitTests

* Update comments

* UnitTests: code refactoring
2023-08-01 14:43:32 +02:00
Jonas Platte f6d4357d52 Update Cargo.lock 2023-08-01 10:59:40 +02:00
Jonas Platte d05bd4bf2d ui: Deduplicate in-reply-to fetching 2023-08-01 09:29:18 +02:00
Benjamin Bouvier a00ff293f1 chore: apply code review suggestions again 2023-07-31 15:02:04 +02:00
Benjamin Bouvier 505267503b chore: add a comment explaining why we need a mutex 2023-07-31 15:02:04 +02:00
Benjamin Bouvier c6f00cb633 chore(clippy): use an async mutex 2023-07-31 15:02:04 +02:00
Benjamin Bouvier 6cc4364684 chore: move comment around 2023-07-31 15:02:04 +02:00
Benjamin Bouvier d165ec8646 feat: sequentialize calls to get_notification_with_sliding_sync
There must be at most one sliding sync notification per connection id. While we could use multiple ids, it seems bad
to do so, in terms of proxy performance; so this makes it so that there is at most once notification being handled
at a time.
2023-07-31 15:02:04 +02:00
Benjamin Bouvier 30a662fdc8 chore: slim down the enum variants of NotificationEvent according to popular request 2023-07-31 15:02:04 +02:00
Benjamin Bouvier 9126937901 feat: use /context query if sliding sync failed 2023-07-31 15:02:04 +02:00
Benjamin Bouvier dec5c6bc2d feat(sliding sync): save the to-device token in OlmMachine::receive_sync_changes 2023-07-31 12:24:55 +02:00
Benjamin Bouvier 719683d284 feat: allow storing a next_batch_token in the crypto stores 2023-07-31 12:24:55 +02:00
Benjamin Bouvier e3f7b9676d chore: fix Changes::is_empty() 2023-07-31 12:24:55 +02:00
Benjamin Bouvier 745bb09e38 chore: remove unused token in KeysQueryRequest 2023-07-31 12:24:55 +02:00
Benjamin Bouvier 4c4a77da34 chore: group all the arguments to receive_sync_changes in a single struct 2023-07-31 12:24:55 +02:00
Jonas Platte 33629833bd ui: Keep local echoes when clearing timeline
This is especially important for ones that failed to send (or ones that
fail post timeline clearing), since there is no way to retry them
otherwise.
2023-07-31 12:12:35 +02:00
Benjamin Bouvier 4c7e10cbf3 chore: add messages for base-client processing 2023-07-31 11:31:12 +02:00
Benjamin Bouvier dcfea138ea chore: tweak sliding sync tracing context
- include the conn_id at the stream level, not the sync_once level (that's a child scope of the stream)\
- also include whether e2ee is enabled at this level
- shorten most static logs
- remove duplicate "sending request" logs
2023-07-31 11:31:12 +02:00
Benjamin Bouvier eb7e01e8b1 chore: lower log-levels when processing sliding sync in sdk-base 2023-07-31 11:31:12 +02:00
Damir Jelić c22f6da909 Add a js feature to the qrcode crate 2023-07-31 10:08:53 +02:00
Damir Jelić 4eba72774f Bump vodozemac 2023-07-31 10:08:53 +02:00
Jonas Platte d149782e6a ui: Reuse ID when replacing UTD after retrying decryption 2023-07-31 09:53:58 +02:00
Jonas Platte 0c3d46eb1e ui: Move some functions into new timeline::util module 2023-07-31 09:53:58 +02:00
Jonas Platte 7dfe8cedbb ui: Move timeline item creation helpers into TimelineInnerState 2023-07-31 09:53:58 +02:00
Jonas Platte e5f021f5cf ui: Simplify definition of TimelineEventHandler
Take a mutable reference to TimelineInnerState, instead of individual
mutable references to its fields.
2023-07-31 09:53:58 +02:00
Jonas Platte 05c5fdd839 ui: Move Flow into EventHandlerContext 2023-07-31 09:53:58 +02:00
Jonas Platte c15ac3978e ui: Rename EventHandlerMetadata to EventHandlerContext 2023-07-31 09:53:58 +02:00
Jonas Platte 4b2cc20c6b ui: Move TimelineInner::*_internal to TimelineInnerState 2023-07-31 09:53:58 +02:00
Jonas Platte 18590c8813 ui: Move update_timeline_reaction to TimelineInnerState 2023-07-31 09:53:58 +02:00
Jonas Platte b78abd62c0 ui: Move TimelineInnerState into its own module 2023-07-31 09:53:58 +02:00
Jonas Platte b425812fd8 ui: Remove explicit default generic argument 2023-07-31 09:53:58 +02:00
Benjamin Bouvier f57b6f5491 chore(test): don't use the same database name in multiple independent tests
This should make the test less flaky.
2023-07-28 19:17:01 +02:00
Benjamin Bouvier 18e283fee9 chore: add TODO explaining that this field should be put back into the OlmMachine later 2023-07-28 15:21:12 +02:00
Benjamin Bouvier a3291a3627 fix: store the crypto store known generation in the Client, not the OlmMachine 2023-07-28 15:21:12 +02:00
Benjamin Bouvier deb8434ee9 test: add a regression test for the spurious crypto store regeneration 2023-07-28 15:21:12 +02:00
Damir Jelić 63ce957843 fix: don't rely on having sessions in cache priori to encrypting a message 2023-07-28 15:06:12 +02:00
Benjamin Bouvier 819b46f2fb test: add regression test for invalidating the OlmMachine while sending a message 2023-07-28 15:06:12 +02:00
Marco Romano 5c71087b9c Upgrade Ruma
This is to pave the way to the upcoming "polls" work.
2023-07-28 08:38:50 +00:00
Jonas Platte d865665420 ffi: Replace tracing-android by paranoid-android 2023-07-27 18:25:15 +02:00
Jonas Platte 5f5028ddd0 ffi: Remove redundant dependency specification 2023-07-27 18:25:15 +02:00
Jonas Platte 8703fea24f ffi: Simplify OTLP tracing initialization 2023-07-27 18:25:15 +02:00
Benjamin Bouvier ab363aa420 chore: slim down UpdateSummary 2023-07-27 17:21:36 +02:00
Jonas Platte b66cd58a60 ui: Reduce work for updating sender profiles
… we should not be fetching the profile if it's already set.
2023-07-27 16:45:57 +02:00
Ivan Enderlin 7892b8b74a feat(sdk+ui+ffi): Implement (SlidingSyncRoom|Room|RoomListItem)::avatar_url
feat(sdk+ui+ffi): Implement `(SlidingSyncRoom|Room|RoomListItem)::avatar_url`
2023-07-27 16:33:33 +02:00
Jonas Platte fc3883d08e ffi: Remove async from a few functions
… to hopefully work around current issues.
2023-07-27 12:37:02 +02:00
Ivan Enderlin c2a8fbd3c9 feat(ui): Implement the “fuzzy match room name” filter
feat(ui): Implement the “fuzzy match room name” filter
2023-07-27 12:32:47 +02:00
Andrew Ferrazzutti 53668d764c Return a KeysBackupRequest instead of the more generic OutgoingRequest 2023-07-27 12:12:08 +02:00
Ivan Enderlin 936a2ee25b chore(sdk): Remove one TODO in Sliding Sync
chore(sdk): Remove one `TODO` in Sliding Sync
2023-07-27 10:37:45 +02:00
Benjamin Bouvier 1f10af9fa9 chore(encryption): replace some AuthenticationRequired with NoOlmMachine
Even if the two issues are likely caused by the same root cause (the user not being
authenticated), they should be used in different contexts, in my understanding:

- the authentication required error should happen only during HTTP requests
- the absence of olm machine should be signalled when we try to get one and it's not been initialized yet

This has caused a bit of confusion when looking at debug traces today, so this patches fixes it.
2023-07-27 10:36:57 +02:00
Ivan Enderlin 38a8ad0a66 chore(ci): Make typos happy. 2023-07-27 10:10:45 +02:00
Ivan Enderlin d1d6bcdcab doc(ui): Add missing documentation. 2023-07-27 10:10:45 +02:00
Ivan Enderlin 3e93bdbc3f feat(ui): Normallize strings when doing fuzzy matching. 2023-07-27 09:20:43 +02:00
Ivan Enderlin 63ca82c66c feat(ui): Implement the “fuzzy match room name” filter.
WIP
2023-07-26 18:22:14 +02:00
Ivan Enderlin 0c16ff1ae7 chore(cargo): Update ruma. 2023-07-26 16:38:23 +02:00
Ivan Enderlin a8e5d3ab17 feat(ffi): Update RoomListItem::avatar_url.
This patch updates `RoomListItem::avatar_url` to use
`matrix_sdk_ui::room_list_service::Room::avatar_url` instead of
`matrix_sdk::Room::avatar_url`.

This patch also moves `avatar_url` before `is_direct` (so that it's the
same order as other places in the code).
2023-07-26 16:38:23 +02:00
Chris Smith af44ac6be4 ffi: Define API stub for m.poll.start and m.poll.end 2023-07-26 14:26:03 +00:00
Ivan Enderlin 38d28e9aa0 feat(ui): Implement Room::avatar_url.
This patch implements `Room::avatar_url`. It tries to calculate
the best avatar URL as much as possible. It's either the URL from
`SlidingSyncRoom::avatar_url` or from `Room::avatar_url`.
2023-07-26 16:06:11 +02:00
Ivan Enderlin 62a203f41e feat(sdk): Implement SlidingSyncRoom::avatar_url.
Based on https://github.com/ruma/ruma/pull/1607, this patch adds
support for `avatar` from a sliding sync response. This patch implements
`SlidingSyncRoom::avatar_url` to get the avatar URL of a sliding sync
room.
2023-07-26 16:06:11 +02:00
Ivan Enderlin 15a6861b8c chore(sdk): Remove one TODO.
The batch subscriber exists in `matrix_sdk_ui::RoomList` (https://
github.com/matrix-org/matrix-rust-sdk/pull/2322) instead of being added
here.

We must keep the observable capacity to 4096, but the `TODO` is no
longer relevant.

Why keeping the capacity to 4096? Because if the batch subscriber (in
`RoomList`) isn't “listened” quickly, we don't want to get a `Reset`.
2023-07-26 15:24:24 +02:00
Ivan Enderlin 163d8ca517 feat(ui): Batch the streams returned by RoomList::entries and RoomList::entries_filtered.
feat(ui): Batch the streams returned by `RoomList::entries` and `RoomList::entries_filtered`.
2023-07-26 15:18:43 +02:00
Ivan Enderlin efd1d1e9d2 chore(cargo): Use latest version of async-rx. 2023-07-26 14:25:50 +02:00
Ivan Enderlin 8a21a8a6da chore(ui): Address some feedbacks. 2023-07-26 14:19:17 +02:00
Ivan Enderlin 2302a7b377 feat(ui): Use Subscriber<State> to simply drain the batch subscriber for entries.
This patch brings a nice code simplification.

Instead of creating a new `Stream` with `tokio` based on
`Subscriber<State>`` to drain the batch subscriber for
`RoomList::entries` and `::filtered_entries`, we can _simply_ use
`Subscriber<State>` directly! It removes one dependency: `tokio-
stream`, and remove possible issues with the broadcast channel
`tokio::sync::broadcast`. The code is much simpler and straighforward.
2023-07-26 14:07:46 +02:00
Benjamin Bouvier 7469d1c7d8 chore: remove all experimental features on the UI crate
As discussed, we think the entire UI crate should be considered experimental. We've also
observed a proliferation of feature flags there (many of those are my wrong doings, sorry).
Since the one internal user (FFI) of that crate enabled all experimental features, it seems
fine to make them all default, while not providing any extra stability guarantee based on that
action.
2023-07-26 13:35:40 +02:00
Benjamin Bouvier 2cec3b0c45 feat: Run a SlidingSync when retrieving notifications to get more information (#2252)
* feat: run a room sliding sync upon receiving a notification, to get its full content

* test: add test for the new sliding-sync in notifications \o/

* fix: try to get the push rules *after* a possibly-successful event decryption

* feat: set `is_noisy` only if we could build a push context, and test it

* feat: expose the `legacy_get_notification` in the FFI layer

* feat: retrieve events with a `/context` query

* fix: also request the client's user id's member information to get their display name

* feat: include the list of invites in the notification sliding sync

* feat: repeat the query multiple times if the event hasn't been immediately found

* chore: simplify retrying decryption

* chore: fail the sliding sync when fetching a notification if not using a memory store

* chore: update test expectations + sort invites by recency

* chore: cargo fmt

* chore: simplify getting push actions

Either they were already available in the timeline event if we had to re-run decryption, or
we manually compute them. (Previous comment was incorrect, the `push_actions` are now optional
because of another PR of yours truly.)

* fixup! chore: fail the sliding sync when fetching a notification if not using a memory store

* feat: try to handle invites correctly

* chore: build a local client with an in-memory store instead of reusing the parent client

* fix: remove dubious annotation

* feat: allow cloning a Client and modify it on the fly, use that for the notification client

* feat: get rid of the with_memory_state_store public func on ClientBuilder

* feat: include sender_id in the notification invite event

* feat: put sender's id in the `NotificationSenderInfo`

* feat: inherit the parent session when creating a notification client

* chore: reformat comments

* TMP: add logs

* chore: regenerate the olm machine when inheriting a session too

* chore: keep the parent client around for legacy_get_notification/with_context
2023-07-25 17:23:01 +00:00
Benjamin Bouvier 483465e8a8 feat(sliding sync): include the connection id conn_id in the tracing context 2023-07-25 18:49:37 +02:00
Benjamin Bouvier bef9cbfacc feat: rename Protocol to Scheme + replace server_name_with_protocol by insecure_server_name_no_tls 2023-07-25 18:43:35 +02:00
Benjamin Bouvier 122349ecec feat: allow specifying a protocol along a server name 2023-07-25 18:43:35 +02:00
Benjamin Bouvier 020d5aa292 fix: use a little state machine to handle the response
and that allows to make sure that all event handlers are correctly called for all
events contained in the response.
2023-07-25 17:36:43 +02:00
Benjamin Bouvier fb5c96e380 test: add test for previous feature 2023-07-25 17:36:43 +02:00
Benjamin Bouvier 8a809dba04 feat(sliding sync): only process encryption events (resp. room events) if configured as so 2023-07-25 17:36:43 +02:00
Benjamin Bouvier da7d1b092e chore(encryption sync): lower severity of update summary logging
The proxy server can (and does) redispatch unrelated lists/rooms from other sliding sync connections,
so the encryption sync would sometimes see room events. Apparently since this is not considered a bug
in the SS proxy, so we shouldn't spam error traces every time this happens.
2023-07-25 17:36:43 +02:00
Jonas Platte 04aac7bc13 ui: Redact replied-to event inside in_reply_to in timeline 2023-07-25 15:31:14 +02:00
Jonas Platte 004a4aa765 ui: Fix redactions for state events in the timeline 2023-07-25 15:31:14 +02:00
Jonas Platte 09fea85d92 ui: Replace Message by TimelineItemContent in RepliedToEvent 2023-07-25 15:31:14 +02:00
Jonas Platte d93f4ee4cc Fix clippy lint 2023-07-25 15:31:14 +02:00
Jonas Platte eb4dab138e ffi: Spawn tokio tasks for the remaining async fns
… as a workaround for cancellation being broken in UniFFI.
2023-07-25 14:34:31 +02:00
Damir Jelić 0a361eff5c Mark our public part of the user identity as verified if we import the private part (#2298)
Co-authored-by: Denis Kasak <dkasak@termina.org.uk>
2023-07-25 12:39:06 +02:00
Jonas Platte bf26a343da ffi: Spawn tokio tasks for async code that locks async mutexes
Since we seem to have a problem with futures being leaked in Kotlin,
which can otherwise lead to deadlocks.
2023-07-24 20:01:27 +02:00
Ivan Enderlin d60a65f82b chore: Make Clippy happy. 2023-07-24 16:59:46 +02:00
Ivan Enderlin d39cbd865b feat(ffi): RoomListEntriesListener::on_update takes a Vec<_> now.
Since `RoomList::entries` returns a batch stream, the listener
now receives a `Vec<VectorDiff<RoomListEntry>>` instead of a
`VectorDiff<RoomListEntry>`.
2023-07-24 16:53:26 +02:00
Ivan Enderlin 3bcd9680fd test(ui): Test the new batch stream on entries and filtered entries.
Only updated the macro is required here. Instead of calling
`StreamExt::now_or_never` on the `$stream`, we call `Iterator::next` on
`$entries` which is a `Vec<VectorDiff<_>>` now.
2023-07-24 16:53:26 +02:00
Ivan Enderlin 1678d0754d feat(ui): Batch the stream returned by RoomList::entries and RoomList::entries_filtered.
This patch uses a newly implemented `async-rx` crate, that provides
`StreamExt`. This trait provides new features on `Stream`, like
`StreamExt::batch_with` which allows to batch values generated by a
`Stream` into a `Vec<Stream::Item>`. The batch is drained based on
another `Stream`: every time a value is produced, it drains the batch
stream.

This feature is used in `RoomList::entries` and
`RoomList::entries_filtered` to batch `Stream<Item = VectorDiff<_>>`
into `Stream<Item = Vec<VectorDiff<_>>>`.

The “drainer” is a broadcast sender, which sends an (empty) value every
time the room list service state changes, so every time something
happens during a sync. Note that it even drains when the room list
service state jumps to `Error` or `Terminated`.
2023-07-24 16:53:26 +02:00
Ivan Enderlin ac950ac253 doc(sdk): Update documentation of RoomListEntry variants. 2023-07-24 15:12:30 +02:00
Ivan Enderlin 2e265ad9bd feat(ui): Look for Room in the ring buffer from the newest instead of the oldest
feat(ui): Look for `Room` in the ring buffer from the newest instead of the oldest
2023-07-24 15:03:53 +02:00
Jonas Platte 766be8142e ffi: Make fetch_members cancellable 2023-07-24 13:59:09 +02:00
Ivan Enderlin 5dbfa89c72 feat(ui): Look for Room in the ring buffer from the newest instead of the oldest.
In `RoomListService`, there is a cache over the `Room`s to avoid re-
computing them every time the user calls `RoomListService::room`. It
also allows async operations to have time to finish while the user
jumps back to the room list and so on.

When reading this cache, which is `matrix_sdk_common::RingBuffer`,
`RingBuffer::iter` is used with `Iter::find` to find if the
`Room` exists in the cache. The cache has a size of 128 (given by
`ROOM_OBJECT_CACHE_SIZE`), which is quite large.

`Iter::find` will iterate from the oldest to the newest room in the
cache, but realistically, I reckon we need to iterate from the newest
to the oldest room. Indeed, the app user is more likely to jump between
recently opened rooms more frequently, thus saving quite a lot of
iterations for usual cases.

One may argue than in practice, a user won't open 128 rooms anyway… :-p.
2023-07-24 09:34:36 +02:00
Jonas Platte d9f3a5476e ffi: Simplify regular (non-OTLP) tracing initialization 2023-07-21 13:59:40 +02:00
Jonas Platte 0e3cca09dd ffi: Remove duplicate dependency 2023-07-21 13:59:40 +02:00
Jonas Platte 230cacaf18 ui: Add more tracing for room update handling 2023-07-21 11:06:31 +02:00
Jonas Platte 5b639903bb ui: Add more tracing for updating sender profiles 2023-07-21 11:06:31 +02:00
Jonas Platte abab1a32aa ui: Fix a typo 2023-07-21 11:06:31 +02:00
Jonas Platte 7e1f8f4923 base: Add tracing for getting a room member 2023-07-21 11:06:31 +02:00
Jonas Platte 236f6fff88 Make example dependencies less confusing 2023-07-20 13:28:14 +02:00
Jonas Platte 80fb8ff283 ffi: Don't keep timeline locked while back-paginating 2023-07-20 12:08:41 +02:00
Richard van der Hoff c6dab4088e Rename "Recovery Key" to "Backup decryption key" (#2305)
... because there are too many "recovery keys"
2023-07-20 09:49:54 +01:00
Damir Jelić 24e3ccfbb3 Add stronger typing to the return value of receive_sync_changes in the bindings (#2297) 2023-07-19 12:43:41 +00:00
Damir Jelić 9f69c32467 Broadcast valid secrets we receive over m.secret.send
Co-authored-by: Jonas Platte <jplatte@matrix.org>
2023-07-19 14:27:18 +02:00
Damir Jelić 6ea0d886f7 Introduce a secret inbox
Up until now, users had to listen for to-device events to check for
secrets that were received as an `m.secret.send` event.

This has a bunch of shortcomings:
    1. Once the has been given to the consumer, it's gone and can't be
       retrieved anymore. Secrets may get lost if an app restart happens
       before the consumer decides what to do with it.
    2. The consumer can't be sure if the event was received in a
       secure manner.

This commit ads a inbox for our received secrets where we will long-term
store all secrets we receive until the user decides to delete them.

It's deemed fine to store all secrets, since we only accept secrets we
have requested and if they have been received from a verified device of
ours.
2023-07-19 14:27:18 +02:00
Jonas Platte 689d022b7a ui: Group timeline reaction metadata into a new struct 2023-07-19 14:01:32 +02:00
Jonas Platte 340e0b7a03 ci: Use taiki-e/install-action to install protoc 2023-07-19 10:11:21 +02:00
Jonas Platte 38a2885c10 Bump eyeball-im, enable its tracing feature 2023-07-18 16:40:47 +02:00
Jonas Platte aaa84c1489 Ensure valid room state before sending requests from Room methods 2023-07-18 15:12:03 +02:00
Jonas Platte 293cd08634 Clean up double spaces in docs 2023-07-18 15:12:03 +02:00
Jonas Platte e3ba1f1cb8 Add room API changes to changelog 2023-07-18 15:12:03 +02:00
Jonas Platte f3da79e482 Split unreleased section of changelog into sub-sections 2023-07-18 15:12:03 +02:00
Jonas Platte 92df7b22ec Rename room::Common to Room
… and export it at the matrix_sdk crate root.
2023-07-18 15:12:03 +02:00
Jonas Platte db84fcd8da Merge matrix_sdk::room::common into its parent module 2023-07-18 15:12:03 +02:00
Jonas Platte 67ef9c3fa0 Remove Room enum 2023-07-18 15:12:03 +02:00
Jonas Platte 85f66b1f96 Remove room::Joined 2023-07-18 15:12:03 +02:00
Jonas Platte fbea71aaf5 Move room::Join methods to room::Common 2023-07-18 15:12:03 +02:00
Jonas Platte 3602807641 Remove invalid reference in docs 2023-07-18 15:12:03 +02:00
Jonas Platte 6ad8086905 Move get_messages related types into a new room submodule 2023-07-18 15:12:03 +02:00
Jonas Platte 0408bd5a98 Remove room::Left 2023-07-18 15:12:03 +02:00
Jonas Platte ef00ef4158 Remove room::Joined::leave
… since room::Common::leave is now public and Joined deref's to Common.
2023-07-18 15:12:03 +02:00
Jonas Platte 9c8ed429b9 Move room::Left::forget to room::Common 2023-07-18 15:12:03 +02:00
Jonas Platte 05a817305e Remove room::Invited 2023-07-18 15:12:03 +02:00
Jonas Platte 10339ca15b Remove unreachable error variant 2023-07-18 15:12:03 +02:00
Jonas Platte 4621a47304 Move invite_details from room::Invited to room::Common 2023-07-18 15:12:03 +02:00
Jonas Platte 512dc18250 Remove room::Invited::accept_invitation in favor of room::Common::join 2023-07-18 15:12:03 +02:00
Jonas Platte 677907f8c5 Remove room::Invited::reject_invitation in favor of room::Common::leave 2023-07-18 15:12:03 +02:00
Jonas Platte 67abf707ff ui: Move ReactionSenderData to reactions module and re-export publically 2023-07-18 15:05:12 +02:00
Jonas Platte 145c796294 crypto: Remove Arc from fields of types that are no longer Clone 2023-07-18 14:58:11 +02:00
Jonas Platte a1806254a8 crypto: Remove Clone from more store related types 2023-07-18 14:58:11 +02:00
Jonas Platte 7081c67c46 Remove Arc wrapping from memory store fields 2023-07-18 14:58:11 +02:00
Jonas Platte 10d9808ecf Remove dead code 2023-07-18 14:58:11 +02:00
Jonas Platte 1c26069871 Make memory stores not clonable
It's not actually necessary and allows simplifying them.
2023-07-18 14:58:11 +02:00
Benjamin Bouvier 2f2bb82fcf add tests for the previous commit 2023-07-18 14:29:58 +02:00
Benjamin Bouvier e3cac2b637 fix: Don't mark a room as limited if the SS response doesn't contain any events 2023-07-18 14:29:58 +02:00
Jonas Platte 82bbb59965 ui: Update dedup_initial test to also test ID reuse
… and make it more realistic.
2023-07-18 14:20:29 +02:00
Jonas Platte 2720bddcc4 ui: Reuse IDs when removing and re-inserting an item 2023-07-18 14:20:29 +02:00
Jonas Platte ab0d88ae3a ui: Pull out identical code in different branches 2023-07-18 14:20:29 +02:00
Jonas Platte 78ebb7f745 ui: Remove redundant semicolon 2023-07-18 14:20:29 +02:00
Jorge Martin Espinosa 26edf4169f ffi: Use forked tracing-android temporarily
… to have readable logs in Android.
2023-07-17 15:48:56 +00:00
Benjamin Bouvier 4ad95ab1a1 chore: rename SyncService::observe_state to state 2023-07-17 16:46:07 +02:00
Benjamin Bouvier 2b3b5e9e18 feat: introduce Idle initial state 2023-07-17 16:46:07 +02:00
Benjamin Bouvier f1d67ad593 chore: remove RoomListService::is_syncing
It's preferrable that users make use of the `App::observe_state/current_state` methods, instead
as there's another sliding sync in the `App` and it properly unifies the current state of both.
2023-07-17 16:46:07 +02:00
Benjamin Bouvier 766d787779 chore: don't automatically start the App 2023-07-17 16:46:07 +02:00
Benjamin Bouvier 86ef0d41f8 feat: add getter to get the current state of the App 2023-07-17 16:46:07 +02:00
Jonas Platte a503dccdcd base: Apply redaction to latest_event in RoomInfo when applicable 2023-07-17 16:36:37 +02:00
Jonas Platte 0bb7a9de7f base: Remove wrong documentation 2023-07-17 16:36:37 +02:00
Jonas Platte 8067319208 base: Add BaseRoomInfo::room_version() 2023-07-17 16:36:37 +02:00
Jonas Platte 70421cff54 base: Restrict visibility of RoomInfo#latest_event 2023-07-17 16:36:37 +02:00
Benjamin Bouvier 68a5f70a85 chore: rename App to SyncService 2023-07-17 14:38:38 +02:00
Benjamin Bouvier a939522b1b test: add test for computing the limited flag 2023-07-17 13:51:45 +02:00
Benjamin Bouvier b3183f6315 feat: compute limited approximation client-side 2023-07-17 13:51:45 +02:00
Benjamin Bouvier 2357a09d13 chore: remove spurious feature guarding against "experimental-sliding-sync"
The whole file is guarded against this feature.
2023-07-17 13:51:45 +02:00
Mauro 91ea0ee8b1 Add PowerLevels permission checks to room::Joined
… and the FFI `Room`. These were previously already available at the `room::Member` level.
2023-07-17 11:43:31 +00:00
Benjamin Bouvier d98b296fad feat: reflect that push actions may not be available for a TimelineEvent
Before this patch, the inability to compute push actions would result in an empty vector of
push actions, leading to the false assumption that there's no push actions to account for,
while we were unable to compute them properly. This changes things up so that it's now the
user's responsibility to decide what to do when those push actions are missing.
2023-07-17 13:38:33 +02:00
Kévin Commaille 1dea482e43 ui: Expose the kind of a TimelineItem
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-07-14 19:17:17 +02:00
Kévin Commaille a6a0d722b4 ui: Fix imports behind sliding-sync feature flag
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-07-14 13:05:39 +02:00
Jonas Platte d82628725f ci: Remove serverName from setup-matrix-synapse arguments
We're getting warnings because this is not a supported parameter.
2023-07-14 12:05:02 +02:00
Benjamin Bouvier ac51adf1e5 feat: split the SlidingSyncBuilder with_timeouts method into two
Following a comment from Jonas in another PR.
2023-07-14 11:29:26 +02:00
Jonas Platte bfed0907ed Remove wasm_command_bot 2023-07-14 11:07:47 +02:00
Jonas Platte b2f7ba33c8 Patch const_panic to not use packed reference 2023-07-14 10:46:52 +02:00
Jonas Platte 6d8764f4e7 Patch const_panic 2023-07-14 10:46:52 +02:00
Jonas Platte 57c5347e81 ffi: Move more types out of UDL 2023-07-14 10:46:52 +02:00
Jonas Platte 9cf1adbfa6 Upgrade UniFFI 2023-07-14 10:46:52 +02:00
Dirk Stolle 0141dab8c9 ci: Update actions/checkout in GitHub Actions workflows to v3
Signed-off-by: Dirk Stolle <striezel-dev@web.de>
2023-07-14 10:22:55 +02:00
Dirk Stolle 0461ebe739 Fix some typos
Signed-off-by: Dirk Stolle <striezel-dev@web.de>
2023-07-14 10:10:03 +02:00
Jonas Platte 81d28d1f46 ui: Remove read-only mode for timeline
It was used when getting the latest message was done through the timeline,
which is no longer the case.
2023-07-13 15:48:56 +02:00
Jonas Platte d309cb3320 crypto-ffi: Use proc-macro definition of callback interfaces 2023-07-13 14:07:27 +02:00
Jonas Platte 3c2b2756b0 ci: Fix git ref comparison 2023-07-13 13:54:59 +02:00
Jonas Platte 5f924197fd ffi: Merge impl blocks for sync and async exported methods 2023-07-13 13:13:50 +02:00
Jonas Platte aee2ef6abf ffi: Use async-uniffi instead of block_on in app module 2023-07-13 13:13:50 +02:00
Jonas Platte 6f2fee8965 Upgrade UniFFI 2023-07-13 13:13:50 +02:00
Jonas Platte 5abc781e1f Remove matrix-sdk-crypto-js
It now lives in its own repository at
https://github.com/matrix-org/matrix-rust-sdk-crypto-web
2023-07-13 13:11:02 +02:00
Richard van der Hoff 51ba4483c0 Merge pull request #2270 from matrix-org/release-matrix-sdk-crypto-js-0.1.4
matrix-sdk-crypto-js v0.1.4
2023-07-12 17:24:16 +01:00
Richard van der Hoff b62bb90c79 matrix-sdk-crypto-js v0.1.4
Release `crypto-js` / Publish 🕸 [m]-crypto-js (push) Failing after 31s
2023-07-12 16:58:19 +01:00
Richard van der Hoff a4cece7dd7 crypto: Add OlmMachine::query_keys_for_users (#2267)
Sometimes we need our key query results to be as up-to-date as possible. Add a mechanism to allow that.

Closes #2263 .
2023-07-12 16:48:34 +01:00
Jonas Platte ec34036586 ci: Switch to branch-less GitHub pages workflow 2023-07-12 17:47:04 +02:00
Jonas Platte 6e10eb9efb Remove matrix-sdk-crypto-js
It now lives in its own repository at
https://github.com/matrix-org/matrix-rust-sdk-crypto-nodejs
2023-07-12 16:23:37 +02:00
Jonas Platte a554a92dec crypto: Re-export vodozemac entirely 2023-07-12 15:14:47 +02:00
Jonas Platte ccb6d7d05c Move ruma re-export from matrix-sdk to matrix-sdk-common
… since it's also useful for crypto bindings.
2023-07-12 15:14:47 +02:00
Jonas Platte f6c339a5d2 Enable ruma's new compat-upload-signatures feature 2023-07-12 12:42:31 +02:00
Jonas Platte 63babcd35a Upgrade Ruma 2023-07-12 12:42:31 +02:00
Jonas Platte 8c3af12e47 test: Rename EventBuilder to SyncResponseBuilder
… because that's what it is.
2023-07-12 10:29:29 +02:00
Richard van der Hoff e1c5f628e7 Merge pull request #2258 from matrix-org/matrix-sdk-crypto-js-0.1.3
Fix `receiveSyncChanges` js bindings, and release 0.1.3
2023-07-11 18:12:16 +01:00
Richard van der Hoff f1def2a458 fix another test
Release `crypto-js` / Publish 🕸 [m]-crypto-js (push) Failing after 30s
2023-07-11 17:19:58 +01:00
Richard van der Hoff 0bd1e65b49 update changelogs 2023-07-11 16:41:45 +01:00
Richard van der Hoff fd3c4f669d matrix-sdk-crypto-js v0.1.3 2023-07-11 16:41:22 +01:00
Richard van der Hoff a3a36291ad crypto-js Fix return type of receiveSyncChanges
https://github.com/matrix-org/matrix-rust-sdk/pull/2142 introduced an
unintended change such that `receiveSyncChanges` returned an array of arrays.
2023-07-11 16:29:17 +01:00
Jonas Platte 0daf3aeb6b ui: Move echoes to the bottom immediately when retrying 2023-07-11 16:36:26 +02:00
Jonas Platte 9dc6ac45d2 ui: Fix wrong field name 2023-07-11 16:36:26 +02:00
Jonas Platte 53ac8bea14 ffi: Provide tokio context for async exported method 2023-07-11 15:54:38 +02:00
Jonas Platte 01ceec43b1 ui: Use eyeball_im's new entry API 2023-07-11 15:41:34 +02:00
Benjamin Bouvier 43bbd4200e chore: inline variable and use From<bool> for WithLocking 2023-07-11 14:07:27 +02:00
Benjamin Bouvier 2d9f7d2f89 ffi: remove bindings for manually creating EncryptionSync and RoomList 2023-07-11 14:07:27 +02:00
Benjamin Bouvier dbc8f0136b ffi: add bindings for App 2023-07-11 14:07:27 +02:00
Benjamin Bouvier dd7d4ddf7c chore: rebase 2023-07-11 14:07:27 +02:00
Benjamin Bouvier e60d04b368 doc: document the App API 2023-07-11 14:07:27 +02:00
Benjamin Bouvier 704cd7784b feat: experimental App API that wraps both the encryption sync and room list API 2023-07-11 14:07:27 +02:00
Damir Jelić 1c6d85935d Generate one-time keys when we receive new one-time key counts (#2249)
Previously we would generate one-time keys, if needed, whenever we tried
to upload them. This code-path is critically missing a `save_account()`
call and we would only persist the account once we uploaded the one-time
keys.

This patch changes things up to generate one-time keys whenever we
receive new one-time key counts from the sync response. This aligns
with the way we generate fallback keys and removes the need to introduce
a new place where we persist the `Account`.

It's still possible to re-upload the same one-time keys, in the case
where the upload process succeeds on the server side but we fail to
receive the response.

Co-authored-by: Denis Kasak <dkasak@termina.org.uk>
2023-07-11 10:27:04 +00:00
Benjamin Bouvier 9985a63dd3 feat: use a ring buffer for the RoomListService cache
This will limit the memory used by the cache entries (while it was unbounded before). It's now possible to do this,
since we have the `latest_room_event` handy for all the rooms; using the unbounded cache before was papering over
the lack of that feature.

We can bikeshed on the number of entries in this cache. It has to be small enough to not blow up memory (and keep
the linear search over room id fast, but it's secondary), and high enough that we don't hit the full timeline
re-build path that often.
2023-07-11 10:57:04 +02:00
Richard van der Hoff 00e85ef275 Disable debug logging for tests
Because https://github.com/jestjs/jest/issues/4156 is closed
2023-07-11 10:56:42 +02:00
Jonas Platte 879d1b189c ui: Test unique ID tracking 2023-07-10 19:19:31 +02:00
Jonas Platte a11508fa58 ui: Linkify doc bits 2023-07-10 19:19:31 +02:00
Jonas Platte 754b668fe6 ui: Move TimelineItem, TimelineItemKind into new sub-module 2023-07-10 19:19:31 +02:00
Mauro Romito bc811cc1dc ui: Add a unique ID for all timeline items
Co-authored-by: Jonas Platte <jplatte@matrix.org>
2023-07-10 19:19:31 +02:00
Benjamin Bouvier 2acc13ed2c feat: add a new NotificationClient API 📬 (#2235)
* chore: rename EncryptionSyncMode variants

* feat: split the encryption sync modes into two different functions

* feat: make locking optional in the `EncryptionSync`

* feat: experimental notification client that retries decryption if it failed the first time

* fix: don't iloop retrying decryption

* chore: helper to convert from bool to `WithLocking`

* feat: don't loop and just retry decryption of the notification event linearly

* feat: remove unused set_notification_delegate

Dead code is dead.

* ffi: get rid of `get_notification_item` and introduce the `NotificationClient`

* fmt

* feat: don't swallow encryption sync errors when retrying notification event decryption

* keeping a tidy commit history is NP-hard

* will i ever learn

* chore: enable experimental-notification-client in the FFI crate

* test: add basic integration test for the common path

* Address first batch of review comments, thanks Jonas!
2023-07-10 18:06:13 +02:00
Vladimir Panteleev a094e10b35 base: Add unit test for deserialization failure of join events 2023-07-10 15:59:21 +02:00
Vladimir Panteleev ab781bf5f4 base: Fix deserialization failure leading to database corruption
f36a5b8cd7 introduced
deserialize_events, moving the deserialization out of handle_state.
However, the new code in deserialize_events used filter_map, which
caused a deserialization failure to lead to the indices of the
serialized and deserialized events to no longer match up.

This was not caught because iter::zip also does not require that its
arguments have matching lengths, causing the mismatch to cascade for
that batch of events, and persist in the store.  An application
affected by this form of corruption can, for example, call
room.get_state_events requesting events of a certain type, and getting
back events of a different type.

Fix the bug by using Option to preserve the length of
deserialize_events' return value, and add an assertion to ensure
handle_state's contract.

Signed-off-by: Vladimir Panteleev <git@cy.md>
2023-07-10 15:59:21 +02:00
Jonas Platte 6ea806bf18 base: Fix clippy lints 2023-07-10 14:03:58 +02:00
Richard van der Hoff 57ea8173ae Merge pull request #2248 from matrix-org/release-matrix-sdk-crypto-js-0.1.2
matrix-sdk-crypto-js v0.1.2
2023-07-10 12:27:10 +01:00
Richard van der Hoff bf1595309c matrix-sdk-crypto-js v0.1.2
Release `crypto-js` / Publish 🕸 [m]-crypto-js (push) Failing after 30s
2023-07-10 12:03:32 +01:00
Richard van der Hoff caa70db31b Prepare changelog for v0.1.2 2023-07-10 12:03:12 +01:00
aringenbach 89aa2916c7 ui/ffi: Add timestamp to reactions 2023-07-10 10:13:53 +00:00
Benjamin Bouvier 2225e8ad80 feat: make it possible to configure the state store as an in-memory store in FFI 2023-07-10 12:04:52 +02:00
Richard van der Hoff 708a7d95a7 Add Qr.state() 2023-07-10 11:45:33 +02:00
Richard van der Hoff 0ccb1efded Enable rust-sdk tracing for device tests
... because knowing why your tests are failing is nice
2023-07-10 11:45:33 +02:00
Richard van der Hoff 0a5ef29c34 device.test: Stop pretending we have independent tests
This file claimed to have lots of tests, but actually they are not independent
- they are just one big test.

It's not ideal to have one massive test like this, but I don't really have time
to rewrite them and we should stop pretending.
2023-07-10 11:45:33 +02:00
Damir Jelić 9f68b3838f Merge pull request #2142 from matrix-org/andybalaam/cache-last-event-in-roominfo
Store the last timeline event in RoomInfo
2023-07-10 11:30:13 +02:00
Jonas Platte 0a6234f40a ffi: Send initial back-pagination status to subscriber immediately
… right as the subscriber is registered.
2023-07-10 11:07:43 +02:00
Kévin Commaille 4e52125551 ui: Allow to filter events added to the Timeline
To avoid to deal with events we are not interested in in the stream.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-07-07 22:20:14 +02:00
Richard van der Hoff 0bf99d5c73 Fix handling of SAS start events once we have shown a QR code (#2242)
Fixes #2237

Also a couple of other cleanups while I'm in the area.
2023-07-07 17:55:13 +01:00
Andy Balaam bac555d31b More CI fixes 2023-07-07 16:19:38 +01:00
Andy Balaam ff0cd7c592 Fix one more JS test 2023-07-07 15:55:29 +01:00
Andy Balaam 96098e8f8b More feature flag fiddling 2023-07-07 15:44:16 +01:00
Andy Balaam 6e84f969ad More feature flag fiddling 2023-07-07 15:42:52 +01:00
Andy Balaam 9bcc1e9e00 More JavaScript test updates 2023-07-07 15:31:09 +01:00
Andy Balaam 31e9572d42 Allow unused code for read_only 2023-07-07 15:22:45 +01:00
Andy Balaam b525491bd5 Fix warnings from CI 2023-07-07 15:20:41 +01:00
Andy Balaam c9a11a58bf Format JavaScript 2023-07-07 15:11:00 +01:00
Andy Balaam 82c7a05f01 Fixes for problems found through CI 2023-07-07 15:05:48 +01:00
Nicolas Mauri fa4c1ef00b ffi: expose the notification settings (#2223) 2023-07-07 15:07:31 +02:00
Andy Balaam a2ca168573 Provide path for a doc link 2023-07-07 13:22:28 +01:00
Andy Balaam 6cb3afe6fd Merge branch 'main' into andybalaam/cache-last-event-in-roominfo 2023-07-07 13:14:52 +01:00
Andy Balaam 3fd1542a25 Fetch sender profile when returning latest event 2023-07-07 12:59:49 +01:00
Benjamin Bouvier 1f47e165ab chore: remove a few useless async 2023-07-07 13:04:31 +02:00
Benjamin Bouvier 4e065ccee9 feat: don't recreate the cross-process lock if it already existed 2023-07-07 13:04:16 +02:00
Jonas Platte 0ef819bca7 ffi: Use proc-macros for SessionVerificationControllerDelegate 2023-07-06 18:26:40 +02:00
Jonas Platte 6f295e2571 Upgrade UniFFI 2023-07-06 18:26:40 +02:00
Jonas Platte 07a82c841f ui: Spawn a background task for decryption retrying 2023-07-06 17:55:05 +02:00
Andy Balaam 98882b9c23 Store the last timeline event in RoomInfo
and the latest few encrypted events in Room.
Use the latest event to provide a room preview, and use the encrypted
events to replace the laest event when they are decrypted.
2023-07-06 16:48:27 +01:00
Florian Duros c600c64b95 BindingsJS: Release v0.1.1 (#2234) 2023-07-06 17:25:02 +02:00
Ivan Enderlin 61ddf047e0 fix(sqlite): Prevent reaching the maximum number of parameters in an SQL statement
fix(sqlite): Prevent reaching the maximum number of parameters in an SQL statement
2023-07-06 17:07:23 +02:00
Ivan Enderlin a70e79420c fix(sqlite): Ensure there is free space for static parameters, in chunk_large_query_over. 2023-07-06 16:46:35 +02:00
Ivan Enderlin 4e20dc5047 chore(sqlite): To make a friend smile. 2023-07-06 16:27:32 +02:00
Ivan Enderlin 23dae0612d chore(sqlite): Use itertools in repeat_vars. 2023-07-06 16:22:37 +02:00
Jonas Platte fe189fda06 bindings: Rename subscribe_to_back_pagination_{status => state}
For consistency with the UI crate.
2023-07-06 15:55:49 +02:00
Florian Duros 0384a52f1e Expose the verify method for the Device in the bindings (#2229) 2023-07-06 15:46:52 +02:00
Ivan Enderlin d33e2aff2e doc(sqlite): Fix a typo. 2023-07-06 15:18:41 +02:00
Ivan Enderlin 380bce0604 fix(sqlite): Prevent reaching the maximum number of parameters in an SQL statement.
This patch introduces a new `chunk_large_query_over` function. Imagine
there is a _dynamic_ query that runs potentially large number of
parameters, so much that the maximum of parameters can be hit. Then,
this function is for you. It will execute the query on chunks of
parameters.

`chunk_large_query_over` uses `Vec::split_off` to avoid cloning `Key`s
as much as possible. It's difficult to use references here because of
the async nature of `SqliteObjectExt::prepare`.

This patch updates `get_kv_blobs`, `get_room_infos`,
`get_maybe_stripped_state_events_for_keys`, `get_profiles`,
`get_user_ids`, and `get_display_names` to use this new function.

This patch finally adds the `repeat_vars` function to replace in a
more efficient way the `vec!["?"; n].join(", ")` pattern. There is less
memory allocations.
2023-07-06 15:11:42 +02:00
Jonas Platte ae17273a37 ui: Replace loading indicator and timeline start virtual timeline items
… with a BackPaginationState observable.
2023-07-06 13:57:40 +02:00
Damir Jelić 75dbfb4d46 Remove an unnecessary unwrap in the crypto crate (#2226) 2023-07-06 12:40:04 +02:00
Ivan Enderlin f2d53a272b Merge pull request #2222 from Hywan/chore-ffi-sliding-sync-bye-bye 2023-07-06 10:11:30 +02:00
Jonas Platte 438c0076f7 ui: Remove NewEventTimelineItem 2023-07-05 17:47:06 +02:00
Jonas Platte b9f98846c8 ci: Upgrade typos 2023-07-05 17:47:06 +02:00
Ivan Enderlin 6cca4ab3e5 chore(ffi): Bye bye Sliding Sync bindings!
The `RoomList` and `EncryptionSync` API provide a better developer
experience and address concrete needs. Nobody no longer uses the Sliding
Sync bindings, so we can remove them.
2023-07-05 15:05:08 +02:00
Ivan Enderlin 96ef45afe8 feat: Immediately fail if a sliding sync request failed (follow up of #2209)
feat: Immediately fail if a sliding sync request failed (follow up of #2209)
2023-07-05 14:47:54 +02:00
Ivan Enderlin 9493c8a75d chore(sdk): Feedbacks. 2023-07-05 14:29:16 +02:00
Ivan Enderlin 1ccc0c3df3 feat(sdk): Ensure that the task sending E2EE requests cannot be detached. 2023-07-05 13:35:52 +02:00
Benjamin Bouvier 1cd87ca15d feat: Immediately fail if a sliding sync request failed
For sliding sync that starts both the actual sliding sync request along the e2ee requests,
we need to make sure that, in case of failure of sliding sync, we reset `pos` as soon as possible.
With the code before this patch, the sliding sync response might be available, but the whole
processing could be waiting for the e2ee requests to finish. In the updated version, we spawn
the e2ee requests in a background task, then run the sliding sync request immediately and fail
if it failed.

Another nice benefit is that the e2ee requests won't be interrupted in the middle of processing,
if the sliding sync changed parameters and we cancelled the whole sync a bit too early.

Fixes #2206.
2023-07-05 13:13:51 +02:00
Jonas Platte afeb5dab24 sdk: Remove questionable use of assign! macro 2023-07-05 12:16:30 +02:00
Jonas Platte 206accb5fb Bump serde_html_form 2023-07-05 11:34:50 +02:00
Jonas Platte 0b24df991e Bump bs58 2023-07-05 11:34:50 +02:00
Jonas Platte dd2fefa2f3 Bump indexmap 2023-07-05 11:34:50 +02:00
Jonas Platte 2b72df7c06 Bump itertools 2023-07-05 11:34:50 +02:00
Jonas Platte 71f7f7c69e Remove mentions of labs crates
There are none at the moment.
2023-07-05 11:34:50 +02:00
Jonas Platte 4ae63caa56 Bump bitflags dependency
2.3.3 contains some bug fixes, might be relevant.
2023-07-05 11:34:50 +02:00
Ivan Enderlin b6908c0611 feat(ui): Change all_rooms batch size to 200
feat(ui): Change `all_rooms` batch size to 200
2023-07-05 10:46:01 +02:00
Ivan Enderlin 36419a7a1f chore: get rid of previous locking crypto-store methods
chore: get rid of previous locking crypto-store methods
2023-07-05 10:35:33 +02:00
Ivan Enderlin 12a1f25ec3 feat(ui): Change all_rooms batch size to 200.
`RoomListServer` defines an `all_room` sliding sync list. This list
starts in selective sync-mode, then it switches to growing sync-mode.
The previous batch size of the growing sync-mode was 50. This patch
updates it to 200, because empirically it seems a better value for
perceived performance.

This patch also rewrites how `State::next` is written. No change in the
code, just comestic.
2023-07-05 10:28:02 +02:00
Ivan Enderlin a0f40606d4 Merge pull request #2208 from bnjbvr/only-restart-growing-on-errors
feat: Only restart growing the allRooms list in case of errors
2023-07-05 10:01:58 +02:00
Jonas Platte da43d81095 ui: Keep loading indicator at the top when processing timeline events 2023-07-05 09:52:59 +02:00
Jonas Platte 5fa293b8ed crypto: Use HashMap inside DashMap
… instead of nesting DashMaps.
The previous type was tracking mutability at very fine-grained level for
no clear reason.
2023-07-04 19:50:45 +02:00
Jonas Platte 87782e9567 ffi: Expose EventTimelineItem::origin 2023-07-04 19:50:08 +02:00
Jonas Platte f344aa7669 sdk: Add EventTimelineItem::origin 2023-07-04 19:50:08 +02:00
Mauro Romito f4929fd064 joined members is now in the notification 2023-07-04 19:39:43 +02:00
Jonas Platte cb2e97f06a Upgrade eyeball to 0.8 2023-07-04 16:22:45 +00:00
Nicolas Mauri 3db72101f3 sdk: Allow to update notification settings (#2135)
* sdk: Allow to update notification settings

* Add an event listener for push rule events

* Fix: simplify insertion and deletion of rules

* Fix: Limit rules cloning

* Fix: Unit tests

* Fix: set_room_notification_mode

* Fix: potential race condition when updating the local ruleset

* Refactor RuleCommands

* RuleCommands Unit Tests

* Fix: limit lock usage

* nit: use expression assignment by default

* nit: pass Ruleset by ownership in RuleCommands' ctor

* a few nits: use to_owned() for &str -> String; use free function for notify actions; use clone() where it's more obvious

and use explicit variants so we know we have to consider this match if we were to add a new variant later

* nit: rename RuleCommands::set_enabled to set_enabled_internal

* nit: test modules don't need to be publicized

* tidy tests

* nit: pass an owned RuleCommands in Rules::apply

* add comments/questions in Rules tests

* nit: no need to publicize the tests module

* tweak NotificationSettings tests too

* rustfmt

---------

Co-authored-by: Benjamin Bouvier <public@benj.me>
2023-07-04 15:29:57 +00:00
Benjamin Bouvier bb34f69662 chore: get rid of previous locking crypto-store methods 2023-07-04 17:19:01 +02:00
Benjamin Bouvier e8a306132a feat: Only restart growing the allRooms list in case of errors
When the sync has been terminated and restarts (e.g. an app is going from the background to the foreground), then
the sliding sync is always restarting in growing mode, independently of the previous state of the sync (error or normal
termination). This is something the current sliding sync proxy can't handle nicely, because it prioritizes a change in
parameters over live data; as a matter of fact, to alleviate the burden of the proxy, we can try to only restart in
growing mode if we ran into an error (and not if we had a normal termination).
2023-07-04 13:06:49 +02:00
Jonas Platte 7bcc886429 Re-format with latest rustfmt 2023-07-03 18:57:05 +02:00
Jonas Platte 37023fe90b Fix new clippy lint 2023-07-03 18:57:05 +02:00
Jonas Platte cd4288391e Bump nightly toolchain version 2023-07-03 18:57:05 +02:00
Jonas Platte b681f234a3 Upgrade criterion, pprof 2023-07-03 18:08:01 +02:00
Alfonso Grillo 147cd970c4 Map MSC3488 fields for UniFFI (#2187)
* Update ruma

* Refactor send_location

* Add timeline parser

* Fix code format

* Add zoom_level

* Update ruma

* Map zoom_level

* Format code

* Cleanup

* Refactor LocationContent

* Apply suggestion

* Fix format issue
2023-07-03 13:34:07 +00:00
Ivan Enderlin 10c9a47f01 Merge pull request #2197 from Hywan/test-ui-room-list-assert-equal 2023-07-03 13:36:55 +02:00
Ivan Enderlin 746b13071e Merge pull request #2198 from Hywan/test-integration-fix 2023-07-03 13:36:06 +02:00
Ivan Enderlin c955de8331 test: Change the installer for setup-matrix-synapse.
There is a bug in Synapse and changing the installer seems to fix the
problem.
2023-07-03 12:47:24 +02:00
Ivan Enderlin 0c13b76d27 test(ui): Do strict assert comparison in some tests of RoomList.
It ensures that we know exactly what's happening here. Tests are still
valid without any changes in the expected data, but it prevents a
potential breaking.
2023-07-03 11:13:45 +02:00
Ivan Enderlin 4f84e33457 fix(ui): Add bump_event_types onto visible_rooms
fix(ui): Add `bump_event_types` onto `visible_rooms`
2023-07-03 10:04:31 +02:00
Ivan Enderlin 37ad562b4b test(sdk): Use async_test instead of tokio::test. 2023-07-03 09:36:45 +02:00
Ivan Enderlin ed2d3bc5b3 chore(ui) Use a function to configure all_rooms and visible_rooms.
The Sliding Sync list `all_rooms` and `visible_rooms` of the `RoomList`
must have the exact same configurations for `sort`, `filters`, and
`bump_event_types`. Instead of maintaining the same code, this patch
adds a new function: `configure_all_or_visible_rooms_list` that
configures the lists exactly the same. This function also explicitely
configures `sort` so that we do no rely on the default values from
`SlidingSyncListBuilder`.
2023-07-03 09:22:32 +02:00
Ivan Enderlin 627a1613df fix(ui): Add bump_event_types onto visible_rooms.
This patch configures the same `bump_event_types` for the
`visible_rooms` list than for the `all_rooms` list, so that we may be
sure that the sorting/ordering is the same between the two lists.
2023-06-30 21:48:30 +02:00
Ivan Enderlin f82fd896f9 chore(ui): Rename room_list module to room_list_service
chore(ui): Rename `room_list` module to `room_list_service`
2023-06-30 21:45:10 +02:00
Ivan Enderlin 9f90b6d4a8 chore(ui): Rename room_list module to room_list_service. 2023-06-30 19:59:13 +02:00
jonnyandrew 3180a1ba7c ffi: Expose proxy and insecure SSL settings (#2191)
Co-authored-by: Damir Jelić <poljar@termina.org.uk>
2023-06-30 15:31:20 +02:00
Benjamin Bouvier 4fbb3d2b63 xtask: add --features testing to most testing tasks 2023-06-30 12:41:04 +02:00
Benjamin Bouvier 66e1b94d31 test: add test for the generational counter invalidation 2023-06-30 12:41:04 +02:00
Benjamin Bouvier d642c22db7 feat: implement a generation counter for the CryptoStore lock 2023-06-30 12:41:04 +02:00
Benjamin Bouvier d72fd34325 Make pending local echoes sticky, take 2 (#2189)
* ui: Move EventSendState into timeline::event_item::local module

* [WIP] ui: Make pending local echoes stick to the bottom of the timeline

* test: update more test expectations

* chore: tweak comment to slightly better reflect reality

* nit: remove else after return

* fix: the item's insert position is insert_idx, not `items.len()` anymore

* fix: look for remote echo before local echo when processing send state

Previous code assumed that the latest timeline items would be the most recent, and that
if there was a remote echo, it would always be after the local echo, because of that.
That's not the case anymore, so we must look for possibly a remote echo first, and then
if we find it, apply the late update process.

Also, there might remain a day divider added by the local echo, if it were inserted last.
I'm not sure it covers all the cases, but I've now made it so that the day divider is removed
if it was the last element.

* feat: switch strategy; keep on pushing if there's nothing in the timeline yet

* Revert "test: update more test expectations"

This reverts commit 400cc93ba7c98042a28b5e8d5042899e854f6cff.

* test: reset test expectations

* Address review comments

* fix: don't mix up latest event with any status, with latest non-failed event index

---------

Co-authored-by: Jonas Platte <jplatte@matrix.org>
2023-06-30 09:37:49 +00:00
Richard van der Hoff 5348e7cc12 Airplane -> Aeroplane
For verification-by-emoji, the spec uses the word "Aeroplane" rather than
"Airplane". Element-web expects us to use the specced words (and will otherwise
complain about the lack of i18n data).

It seems like following the spec will help maintain consistency.
2023-06-30 10:45:52 +02:00
jonnyandrew f508109d0c Fix reaction response resolution 2023-06-30 10:26:41 +02:00
Benjamin Bouvier 77290ff2c1 feat: Get rid of "common extensions"
Common extensions are confusing, and they've included `e2ee` and `to-device` by default. This is not a sane default anymore,
now that there's the concept of `EncryptionSync`: it's either we have the encryption sync that enables e2ee and to-device +
a room list sync that doesn't, OR we have a single room list that has both.

Room List was misconfigured to always use `e2ee` and `to-device`, which was incorrect when it's running with the `EncryptionSync`
in the background. This is now removed, and properly tested.
2023-06-30 09:56:29 +02:00
Richard van der Hoff 48a6bffc1e Merge branch 'release-matrix-sdk-crypto-js-0.1.0' 2023-06-29 17:02:40 +01:00
Ivan Enderlin 1958df22a9 fix(sdk): Change how SlidingSyncList::update_room_list handles updates for out of list rooms
fix(sdk): Change how `SlidingSyncList::update_room_list` handles updates for out of list rooms
2023-06-29 15:48:39 +02:00
Ivan Enderlin 91bf84714d feat(ffi): Add methods on RoomListItem so that full_room isn't necessary
feat(ffi): Add methods on `RoomListItem` so that `full_room` isn't necessary
2023-06-29 15:39:45 +02:00
Richard van der Hoff 757716c924 matrix-sdk-crypto-js v0.1.0 2023-06-29 15:22:00 +02:00
Richard van der Hoff 1b2b6c011b update changelog 2023-06-29 15:22:00 +02:00
Ivan Enderlin bd148fd422 chore(ffi): RoomListItem::is_direct returns a bool. 2023-06-29 15:14:53 +02:00
Ivan Enderlin 363b0d9ee6 doc(ffi): Add some precisions. 2023-06-29 15:07:46 +02:00
Benjamin Bouvier 73ad51879a feat: implement time lease based locks for the CryptoStore (#2140)
This implements a new time lease based lock for the `CryptoStore`, that doesn't require explicit unlocking, so that's more robust in the context of #1928, where any process may die because the device is running out of battery, or unexpected flows cause a lock to not be released properly in one or the other process.

```
//! This is a per-process lock that may be used only for very specific use
//! cases, where multiple processes might concurrently write to the same
//! database at the same time; this would invalidate crypto store caches, so
//! that should be done mindfully. Such a lock can be acquired multiple times by
//! the same process, and it remains active as long as there's at least one user
//! in a given process.
//!
//! The lock is implemented using time-based leases to values inserted in a
//! crypto store. The store maintains the lock identifier (key), who's the
//! current holder (value), and an expiration timestamp on the side; see also
//! `CryptoStore::try_take_leased_lock` for more details.
//!
//! The lock is initially acquired for a certain period of time (namely, the
//! duration of a lease, aka `LEASE_DURATION_MS`), and then a "heartbeat" task
//! renews the lease to extend its duration, every so often (namely, every
//! `EXTEND_LEASE_EVERY_MS`). Since the tokio scheduler might be busy, the
//! extension request should happen way more frequently than the duration of a
//! lease, in case a deadline is missed. The current values have been chosen to
//! reflect that, with a ratio of 1:10 as of 2023-06-23.
//!
//! Releasing the lock happens naturally, by not renewing a lease. It happens
//! automatically after the duration of the last lease, at most.
```

---

* feat: implement a time lease based lock for the crypto store
* feat: switch the crypto-store lock a time-leased based one
* chore: fix CI, don't use unixepoch in sqlite and do time math in rust
* chore: dummy implementation in indexeddb, don't run lease locks tests there
* feat: in NSE, wait the duration of a lease if first attempt to unlock failed
* feat: immediately release the lock when there are no more holders
* chore: clippy
* chore: add comment about atomic sanity
* chore: increase sleeps in timeline queue tests?
* feat: lower lease and renew durations
* feat: keep track of the extend-lease task
* fix: increment num_holders when acquiring the lock for the first time
* chore: reduce indent + abort prev renew task on non-wasm + add logs
2023-06-29 13:05:44 +00:00
Ivan Enderlin 0cd0ade2bc feat(ffi): Add methods on RoomListItem so that full_room isn't necessary.
Calling `RoomListItem::full_room` creates its associated `Timeline`.

ElementX calls `full_room` to get the `is_direct`, `avatar_url` and
`canonical_alias` values for _all_ rooms in the room list. Instead of
doing so, let's add those methods directly in `RoomListItem` so that the
`Timeline` isn't created for _all_ rooms.
2023-06-29 14:48:37 +02:00
Ivan Enderlin eab1f8783a chore(ui): Remove unecessary qualification
chore(ui): Remove unecessary qualification
2023-06-29 14:18:09 +02:00
Richard van der Hoff 9a2f6b8fb9 matrix-sdk-crypto-js v0.1.0
Release `crypto-js` / Publish 🕸 [m]-crypto-js (push) Failing after 1m35s
2023-06-29 13:10:16 +01:00
Richard van der Hoff 082d166502 update changelog 2023-06-29 13:09:51 +01:00
Ivan Enderlin 717063eaa8 feat(common): Implement RingBuffer::drain
feat(common): Implement `RingBuffer::drain`
2023-06-29 13:49:37 +02:00
Ivan Enderlin 9b4d06272c chore(ui): Remove unecessary qualification. 2023-06-29 13:37:45 +02:00
Ivan Enderlin 6d67375f8e fix(ffi): Simplify Room::add_timeline_listener
fix(ffi): Simplify `Room::add_timeline_listener`
2023-06-29 13:24:05 +02:00
Ivan Enderlin e96097a085 feat(common): Implement RingBuffer::drain.
This patch implements `RingBuffefr::drain` because it's going to be
useful soon.
2023-06-29 13:22:43 +02:00
Richard van der Hoff 506d7c6f9b Add accessor for remaining time to VerificationRequest. (#2178) 2023-06-29 11:49:31 +01:00
Benjamin Bouvier 459b689953 tests: add unit tests for the CryptoStoreLock 2023-06-29 12:34:53 +02:00
Ivan Enderlin 61b7335dce chore(sdk): Log SlidingSync list updates
chore(sdk): Log SlidingSync list updates
2023-06-29 11:34:04 +02:00
Ivan Enderlin 62315d726f feat(ui): Do not update the viewport of the room list if it hasn't changed
feat(ui): Do not update the viewport of the room list if it hasn't changed
2023-06-29 11:33:45 +02:00
Ivan Enderlin 9bae039629 fix(sdk): Change how SlidingSyncList::update_room_list handles updates for out of list rooms.
So. `SlidingSyncList::update_room_list()` does the following:

1. It adjust room list entries,
2. It updates the `maximum_number_of_rooms`,
3. It applies the sync operations on the `room_list` entries,
4. It updates the `room_list` entries for rooms outside the sync
   operations.

SlidingSync answers with a `lists` and `rooms`. The `room_list` entries
is updated as follows: either a sync operation from `lists` has been
applied and the entries are updated, or `rooms` contains rooms that
are not updated by `lists` but that receive new events, and thus must
trigger an update in the `room_list` entries.

This patch changes a little bit the last part of this. Initially,
we were updating rooms that are part of `rooms` but absent of
`lists` sync operations, only **for the current list's ranges**.
But that's wrong! First, we have noticed a bug here: the
correct code wasn't `skip(start).take(end.saturating_add(1))` but
`skip(start).take(end.saturating_add(1) - start)`. Note a big deal, we
were iterating on more entries like it was necessary, but everything
was filtered later, so no bug, just useless computations. Second,
this `skip` and `take` is actually… useless. A room to which we have
subscribed can be out of any range, but we still want `room_list`
entries to receive an update for that particular room.

This patch fixes that once and for all.

In practise, the bug wasn't happening because if someone subscribes
to a room, its timeline is likely to be fetched, and updates will be
received, but still, this is better now from a SlidingSync strict point
of view.
2023-06-29 11:21:31 +02:00
Ivan Enderlin d01725dedb fix(ffi): Simplify Room::add_timeline_listener.
This patch does the following:

1. changes `add_timeline_listener` to be async, thus removing one
  `RUNTIME.block_on`.
2. simplifies the logic by adopting a more classical pattern we use
   elsewhere:
  * removes one `spawn_blocking`,
  * let's move the `listener` into the task as a `Box` instead of
    cloning it as an `Arc`.
2023-06-29 10:31:04 +02:00
Ivan Enderlin 111071c034 chore(sdk): Log SlidingSync list updates.
This patch removes an old log and adds a better one with more context.
2023-06-29 09:47:39 +02:00
Ivan Enderlin af4ebd8422 feat(ffi): Update RoomListService::apply_input to always return (). 2023-06-29 09:21:14 +02:00
Ivan Enderlin de09b781ec feat(ui): Do not update the viewport of the room list if it hasn't changed.
Imagine the room list has the viewport set to the range `0..=19`. The
user scrolls quickly to `50..=69` to see something below and immediately
scrolls back to its initial position, without stopping the scroll
at any moment in between. The app using this API might update the
viewport from `0..=19` to… `0..=19`. Updating the viewport, updates the
`visible_rooms` sliding sync list. Since a list is modified, the current
sync-loop iteration is skipped over and a new one restarts, i.e. the
current in-flight request is cancelled… for nothing.

This patch prevents this situation. The current viewport ranges is
stored in `RoomListService`. `RoomListService::apply_input` used to
return `Result<(), Error>`, now it returns `Result<InputResult, Error>`.
The `InputResult` enum is a new type. It represents whether an input has
been applied or ignored, which must be differentiate from errors.

So now, if the viewport changes and it's not different from the previous
value, `InputResult::Ignored` is returned.
2023-06-29 09:21:14 +02:00
Richard van der Hoff 5d9cc6be15 use assert_matches instead of manual panics 2023-06-28 16:32:07 +02:00
Richard van der Hoff c0c7c598b5 When refusing a verification, send cancel to the originating device
According to the spec, when a device receives a verification request and wants
to refuse it, it should send the `m.key.verification.cancel` to the originating
device, rather than broadcasting it.
2023-06-28 16:32:07 +02:00
Andy Balaam 33243cb9fb Fix comment wrongly referring to vector.
Co-authored-by: Jonas Platte <jplatte@matrix.org>
2023-06-28 14:07:10 +02:00
Andy Balaam 785eccc004 Add capacity to RingBuffer 2023-06-28 14:07:10 +02:00
Andy Balaam 13c7f5b0c6 Implement Default for RingBuffer 2023-06-28 14:07:10 +02:00
Richard van der Hoff 3f2eb5828c crypto-js: wait for device updates in getIdentity
We previously did something similar for `getUserDevices` in 0da8e56a. Turns out
it's useful for `getIdentity` too.
2023-06-28 13:33:23 +02:00
Jonas Platte e732b3630a ffi: Add SendAttachmentJoinHandle 2023-06-28 12:55:56 +02:00
Jonas Platte b088339710 Revert "crypto: Add Store::room_keys_for_room_received_stream"
This reverts commit e87b3def02.
2023-06-28 12:32:18 +02:00
Jonas Platte 90e39f7be2 Revert "sdk: Re-export room_keys[_for_room]_received_stream from Encryption"
This reverts commit 04d56130c3.
2023-06-28 12:32:18 +02:00
Jonas Platte fd5b28bb51 Revert "sdk: Add room::Joined::room_keys_received_stream"
This reverts commit 9f72e2cf16.
2023-06-28 12:32:18 +02:00
Jonas Platte b53eba5ec9 Revert "ui: Use new room_key stream for retrying decryption in Timeline"
This reverts commit 06600ac53f.
2023-06-28 12:32:18 +02:00
Ivan Enderlin 07b7885915 chore(sdk): Add missingn newline. 2023-06-28 11:10:53 +02:00
Jonas Platte 06600ac53f ui: Use new room_key stream for retrying decryption in Timeline 2023-06-28 10:14:59 +02:00
Jonas Platte 9f72e2cf16 sdk: Add room::Joined::room_keys_received_stream 2023-06-28 10:14:59 +02:00
Jonas Platte 04d56130c3 sdk: Re-export room_keys[_for_room]_received_stream from Encryption 2023-06-28 10:14:59 +02:00
Jonas Platte e87b3def02 crypto: Add Store::room_keys_for_room_received_stream 2023-06-28 10:14:59 +02:00
Ivan Enderlin 07700abf75 feat: Cache the RoomListService's rooms
feat: Cache the `RoomListService`'s rooms
2023-06-28 08:58:45 +02:00
Ivan Enderlin 9ab4fa0a8b chore(sdk): Log the SyncOps
chore(sdk): Log the `SyncOp`s
2023-06-28 08:41:00 +02:00
Andy Balaam 86fe3364ed Add serialization, clear and extend to RingBuffer 2023-06-27 17:25:25 +00:00
Jonas Platte 81ca1c5072 ui: Add a test for thread message reply fallback 2023-06-27 19:23:14 +02:00
Jonas Platte 4ec8bec2fc ui: Treat thread fallback the same as a regular reply
… for now, until we add proper support for threads.
2023-06-27 19:23:14 +02:00
Benjamin Bouvier 98fed1d2eb chore: use smaller critical sections
This opens up a possible race condition where an embedder calls the method twice, generating two new rooms,
but then it's fine as long as they don't cache them somewhere, which we expect they don't.
2023-06-27 16:29:35 +02:00
Benjamin Bouvier e3df97421b chore: remove useless async 2023-06-27 16:27:31 +02:00
Jonas Platte b08480baea ui: Move message-sending loop start log event
… such that it gets the timeline builder's tracing span.
2023-06-27 16:18:04 +02:00
Benjamin Bouvier ccd5e877eb feat: Cache the RoomListService's rooms
That avoids recreating a timeline object every time a user calls `RoomListService::room()` with the same room id, so that should speed up
operations like fetching the latest event for rooms we've already entered before.
2023-06-27 16:05:26 +02:00
Damir Jelić fed583c5c6 Emit room keys after they have been persisted, not before. 2023-06-27 14:30:08 +02:00
Doug d4252c4e4a feat(bindings): Add user_agent parameter to authentication_service. 2023-06-27 12:59:22 +02:00
Ivan Enderlin 61202ec19a feat(common): Propose a simple RingBuffer implementation
feat(common): Propose a simple `RingBuffer` implementation
2023-06-26 19:52:57 +02:00
Ivan Enderlin ad1b9056ae feat(common): Add RingBuffer::is_empty. 2023-06-26 19:30:27 +02:00
aringenbach 47030e7883 ffi: Use toggle_reaction and update API 2023-06-26 16:08:50 +00:00
Ivan Enderlin d69be5ee75 feat(common): Propose a simple RingBuffer implementation.
This patch propose a very simple `RingBuffer` implementation based on
`std::collections::VecDeque`.
2023-06-26 17:49:41 +02:00
jonnyandrew 7e7996d43d ui: Add local echoes for reactions to Timeline 2023-06-26 15:17:48 +00:00
Ivan Enderlin 04580f75a8 chore(sdk): Log the SyncOps. 2023-06-26 16:04:11 +02:00
Jonas Platte 49b1e8732c Upgrade most of our dependencies
Still holding back js-sys and web-sys due to unresolved wasm-bindgen issues.
2023-06-26 14:32:24 +02:00
Ivan Enderlin ba422f861e fix(sdk): Change SlidingSyncList::room_list's capacity
fix(sdk): Change `SlidingSyncList::room_list`'s capacity
2023-06-26 14:16:05 +02:00
Ivan Enderlin 749911af60 fix(sdk): Change SlidingSyncList::room_list's capacity.
This patch changes the capacity of the internal buffer of
`ObservableVector` for `SlidingSyncList::room_list` from 16 to 4096.
With an increased capacity, we reduce the probability to send a
`VectorDiff::Reset` to subscribers. `Reset` are happening quite often
for apps using `matrix-sdk`, and it impacts their performance. This
patch tries to improve this situation. This `room-list` contains
`RoomListEntry`, which is can cheap in terms of memory, compared to the
impact of sending `Reset`s too often. That's a tradeoff.
2023-06-26 13:52:15 +02:00
Jonas Platte 0e1f74f617 Increase other sleep in test a bit 2023-06-26 11:36:24 +02:00
Jonas Platte b6353f82a8 ui: Improve logging for message-sending queue 2023-06-26 11:36:24 +02:00
Benjamin Bouvier 171c1cf25b chore: fix documentation
Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-06-26 11:22:38 +02:00
Benjamin Bouvier b442d30848 feat: remove the in-memory cache for to_device_token in sliding sync
Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-06-26 11:22:38 +02:00
Benjamin Bouvier 94fa888b7b feat: always enable the SS cache by default
This makes sure that the to-device prev_batch/since token is already saved to and reloaded from disk.

Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-06-26 11:22:38 +02:00
Benjamin Bouvier 69932adb7e chore: remove unreachable UI notifications module
Remnant from a bad merge/renaming.

Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-06-26 11:22:38 +02:00
Mauro 2c58c65add ffi: Allow disabling local notification filtering using push rules 2023-06-26 08:49:06 +00:00
Ivan Enderlin 8916eb6409 test(ui): Replace sleep by yield_now
test(ui): Replace `sleep` by `yield_now`
2023-06-23 16:37:00 +02:00
Jonas Platte 44ef302bc7 Increase sleep in test a bit
since it seems flaky in CI
2023-06-23 16:17:21 +02:00
Ivan Enderlin 40db35abe7 test(ui): Replace sleep by yield_now.
Eh, removing `sleep` from the tests is always a pleasure right?
2023-06-23 16:15:57 +02:00
Jonas Platte 9b802998b3 ui: Put retries in the message-sending queue 2023-06-23 14:03:27 +02:00
Jonas Platte 0a37ce50a8 ui: Allow retrying cancelled local echoes 2023-06-23 14:03:27 +02:00
Alfonso Grillo e72bae1a8f ffi: Add send_location api 2023-06-23 11:29:01 +00:00
Jonas Platte 4c24007cb8 ui: Add a queue to serialize message sending requests 2023-06-23 09:41:07 +02:00
Jonas Platte cb6d3c3c47 ui: Add a failing test for message ordering 2023-06-23 09:41:07 +02:00
David Langley 19ba18d788 ffi: Expose the senders of reactions 2023-06-23 08:56:16 +02:00
Ivan Enderlin 73de71bd42 feat(ui): Welcome to RoomListService
feat(ui): Welcome to `RoomListService`
2023-06-22 17:36:05 +02:00
Ivan Enderlin 1c6ad4a082 chore(ui): Address feedbacks. 2023-06-22 17:16:25 +02:00
Ivan Enderlin 9eadbc302f feat(ffi): Rename Client::room_list to Client::room_list_service. 2023-06-22 17:08:30 +02:00
Ivan Enderlin 93d619249c test(ui): Reduce latency of the tests. 2023-06-22 15:37:25 +02:00
Ivan Enderlin 35ee6db152 fix(ffi): Eh UniFFI, we want Tokio compat. 2023-06-22 14:59:51 +02:00
jonnyandrew 7fd5068faa ui: Deduplicate reaction senders in timeline 2023-06-22 12:42:49 +00:00
Ivan Enderlin 1631b5ba18 chore(ui): Use matrix_sdk::executor instead of tokio. 2023-06-22 14:15:10 +02:00
Valere 3fd55c0ab1 bindings: Ignore silently malformed userId in migration of tracked users (#2130)
* bindings: Ignore silently malformed userId in migration of tracked users
* Clean: collect will now never fail

Co-authored-by: Benjamin Bouvier <public@benj.me>
2023-06-22 12:11:06 +00:00
Ivan Enderlin 083a79a408 doc(ui): Fix intra-links. 2023-06-22 14:08:09 +02:00
Ivan Enderlin f9fe7450ce Merge branch 'main' into feat-ui-roomlist-service 2023-06-22 13:48:00 +02:00
Ivan Enderlin d43d5b515e chore: Make Clippy happy. 2023-06-22 13:39:00 +02:00
Damir Jelić daa3944593 Bump Ruma 2023-06-22 13:20:37 +02:00
Benjamin Bouvier 679ec70200 feat: implement the full EncryptionSync (#2110)
* crypto: implement more primitives for the MemoryStore to work in tests

* crypto: change the shape of the `CryptoStoreLock` API

In particular:

- make the lock work across multiple threads of the same process trying to acquire it,
using `num_holders`.
- add a mechanism to get the lock only once (for the NSE process, in case the main app
had acquired the lock before).

* client: add a cross-process crypto store lock, enable it with `Encryption::enable_cross_process_store_lock`
* client: make `preshare_room_key` a critical section of the cross-process lock
* sliding sync: make it possible to define different timeouts for a `SlidingSyncInstance`

This will be handy for the NSE process on iOS, which has very little time to wait for the proxy's responses.

* feat: implement the `EncryptionSync` API (renamed from `Notification` API)
* fixup! client: add a cross-process crypto store lock, enable it with `Encryption::enable_cross_process_store_lock`
* feat: allow disabling e2ee / to-device in the RoomList API
* feat: use same SS id for main/NSE process, reload to-device token from disk before each encryption sync
* fix: better error handling if restoring the to-device token failed
* feat: add logs for the locking functions
* test: add a few tests for encryption sync
* feat: add `reload_caches` method in the `EncryptionSync` + FFI bindings
* chore: clean up FFI loop
* encryption sync: Remove unused errors, specialize some errors
* feat: include termination reason in the encryption sync loop
* feat: add more logs
* chore: fmt + clippy + doc
* comment: precise only in the presence of another process
* Tweak `room_list` APIs to include `_with_encryption` variants
* chore: rustfmt
2023-06-22 12:50:45 +02:00
Ivan Enderlin eb2213467a feat(ffi): Implement RoomList::loading_state. 2023-06-22 12:12:45 +02:00
Ivan Enderlin 398f70c9de feat(ui): Implement RoomListLoadingState.
The type is well documented. Go check it out :-).
2023-06-22 11:43:38 +02:00
Kévin Commaille 2b3d1080dc sdk: Allow to support several authentication APIs
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-06-22 11:21:50 +02:00
Kévin Commaille 7298df0db6 sdk: Move Session and SessionTokens to matrix_auth
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-06-22 11:21:50 +02:00
Kévin Commaille d6f9f08e30 sdk: Split Matrix authentication methods in a separate API
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-06-22 11:21:50 +02:00
Mauro Romito 528607f079 feat(bindings): get_notification_item filters out notifications given the push context 2023-06-22 11:09:45 +02:00
Ivan Enderlin c9e3d7988f feat(ui): Change how room_list::State is updated.
Instead of broadcasting an intermediate update for the `State`, it's
updated once after the sync.
2023-06-22 10:23:45 +02:00
aringenbach 726c1bca2c ui: Filter redacted reactions from the timeline 2023-06-21 16:21:39 +00:00
Ivan Enderlin d77a48cc2c feat(ffi): Implement RoomList::room. 2023-06-21 17:20:05 +02:00
Ivan Enderlin 40602e7bba chore(ffi): Update according to previous commits. 2023-06-21 17:11:26 +02:00
Ivan Enderlin b774110235 chore(ui): Move methods from RoomListService inside RoomList.
This patch moves `RoomListService::entries` and `::filtered_entries`
inside `RoomList`. It also implements `RoomList::new`. Finally,
it implements `RoomListService::all_rooms` and re-implement
`RoomListService::invites`.

Basically:

```rust
// 1.
room_list.entries().await?
// 2.
room_list.invites().await?
```

becomes:

```rust
// 1.
room_list.all_rooms().await?.entries()
// 2.
room_list.invites().await?.entries()
```

`all_rooms` and `invites` both return a `RoomList`.
2023-06-21 17:00:30 +02:00
Jonas Platte dccf0c29bf Update reldbg profile to optimize our own packages too
… and enable incremental compilation for it.
2023-06-21 16:36:40 +02:00
Ivan Enderlin b01bbe7e92 chore: Add missing copyright headers. 2023-06-21 16:29:55 +02:00
Ivan Enderlin dc061308bd chore(ui): Rename RoomList to RoomListService. 2023-06-21 16:29:03 +02:00
Ivan Enderlin 12a6f12461 feat(ui): Implement RoomList::stop_sync
feat(ui): Implement `RoomList::stop_sync`
2023-06-21 16:23:06 +02:00
Jonas Platte 895669e39b sdk: Upload thumbnail and attachment in parallel 2023-06-21 14:56:22 +02:00
Jonas Platte 54288cb4cb Fix clippy lints 2023-06-21 14:56:22 +02:00
Jonas Platte b883ec000a sdk: Clean up imports in encryption module 2023-06-21 14:56:22 +02:00
Jonas Platte 8a7da622d8 Rewrap comment 2023-06-21 14:56:22 +02:00
Ivan Enderlin e9c19c2110 doc(crypto-nodejs): Add docs on how to use tracing for local Node dev
Add docs on how to use tracing for local Node dev
2023-06-21 14:29:32 +02:00
Ivan Enderlin 9c62b3459f Merge pull request #2119 from matrix-org/valere/quick_fix_doc
Fix js binding bad comment
2023-06-21 14:17:46 +02:00
Ivan Enderlin f9452959a0 doc(ui): Fix a typo. 2023-06-21 13:52:14 +02:00
Ivan Enderlin 4ec917ca48 feat(ffi): Implement RoomList::is_syncing. 2023-06-21 11:58:44 +02:00
Ivan Enderlin 54fc0f38ea feat(ui): RoomList::sync no longer returns a TaskHandle.
Because there is `RoomList::stop_sync` now, which is better than dealing
with the `TaskHandle`.
2023-06-21 11:54:51 +02:00
Ivan Enderlin fe0b458403 chore(ffi): Update according to previous commits. 2023-06-21 11:53:58 +02:00
Ivan Enderlin 6e8e4bb39c feat(ui): Differentiate between error and termination in room_list::State.
This patch introduces `State::Error`, which replaces
`State::Termianted`. And a “new” `State::Terminated` state is added.

They do the same, but their semantics is different. `Error` is when an
error happened, and it's fine to restart the sync again. `Terminated`
is when a termination has been reached (either because SS sync-loop
has ended naturally, or because `RoomList::stop_sync` has been called),
in this case, it may not be fine to restart the sync automatically for
example.
2023-06-21 11:37:00 +02:00
Ivan Enderlin 7073e6f9e3 feat(ui): Remove the State::CarryOn state.
This patch removes the `State::CarryOn`. It turns out that `Running` and
`CarryOn` are doing exactly the same thing. So one of them is useless.
2023-06-21 11:14:29 +02:00
Ivan Enderlin f0bc6d6698 chore(ui): Rename State::FirstRooms and State::AllRooms.
This patch renames `State::FirstRooms` to `State::SettingUp`, and
`State::Running` as requested by users.

It hides the “inner Sliding Sync logic”, the Sliding Sync lists etc.
2023-06-21 11:12:51 +02:00
Ivan Enderlin a78ad89fdd feat(ffi): Implement RoomList::stop_sync.
This patch implements `RoomList::stop_sync` on the FFI bindings.

Technically, it's no more useful to store the `TaskHandle` of the
`sync`, but it's still here, in case of.
2023-06-21 09:22:50 +02:00
Ivan Enderlin ec5c1a3c70 feat(ui): Implement RoomList::stop_sync.
This patch implements `RoomList::stop_sync`. The goal is twofold:

1. It forces to stop the syncing, thus putting the state-machine into
   the `Terminated` state, which is semantically better than “stop
   polling the `sync`'s `Stream`”.

2. It literally forces to stop the syncing. It cancels pending futures,
   it cancels in-flight HTTP requests etc. It's a more robust way to
   stop the `RoomList` sync.
2023-06-21 09:20:44 +02:00
valere 1cc90c8ec0 Fix js binding bad comment 2023-06-21 09:11:09 +02:00
Valere 8a8074cada Add first_time_seen timestamp to devices 2023-06-21 08:49:44 +02:00
Ivan Enderlin 644410afe9 feat(ui): TimelineBuilder::build logs more data
feat(ui): `TimelineBuilder::build` logs more data
2023-06-20 21:12:55 +02:00
Ivan Enderlin 9755af5a9a Revert parts of #2111 because name is already cached in RoomInfo
Revert parts of #2111 because name is already cached in RoomInfo
2023-06-20 21:09:11 +02:00
Alfonso Grillo 673ac33579 ffi: Add location message type 2023-06-20 16:51:12 +00:00
Andy Balaam 5a0c35edb2 Revert parts of #2111 because name is already cached in RoomInfo 2023-06-20 14:58:17 +01:00
Nicolas Mauri 3f3fd58770 sdk: Add a Rules utility struct to manipulate a Ruleset 2023-06-20 14:56:33 +02:00
Ivan Enderlin a496471cf3 test(base): Tests for finding DM rooms
Tests for finding DM rooms
2023-06-20 12:37:47 +02:00
Andy Balaam 2a2ce5f05c Already-passing tests for get_dm_room including left rooms 2023-06-20 11:05:37 +01:00
Andy Balaam 40aab0c426 Already-passing tests for keeping users in direct_targets when they leave a DM 2023-06-20 11:05:37 +01:00
Andy Balaam 0e5d8bc904 Fix double-clone 2023-06-20 11:25:29 +02:00
Andy Balaam 02449a73ea Fix clippy warnings 2023-06-20 11:25:29 +02:00
Andy Balaam 7f8bc8f1c2 Avoid holding a lock over an await 2023-06-20 11:25:29 +02:00
Andy Balaam 149a9d4099 Cache room display name if it comes in from sync 2023-06-20 11:25:29 +02:00
Andy Balaam 75eb94357e Split out tests for room display names 2023-06-20 11:25:29 +02:00
Andy Balaam d84c8d91b5 Fix typo in comment 2023-06-20 11:25:29 +02:00
Jonas Platte 5273fa6f42 sdk: Move target-specific HTTP code into new submodules 2023-06-20 11:16:13 +02:00
Jonas Platte 4c1a351ead sdk: Remove HttpSend in favor of allowing reqwest customization 2023-06-20 11:16:13 +02:00
Jonas Platte ba9d8294b4 ffi: Make upload progress observable 2023-06-20 11:16:13 +02:00
Jonas Platte ac140c192a Make upload progress observable 2023-06-20 11:16:13 +02:00
Jonas Platte a668822fec Simplify HttpClient::send_request signature 2023-06-20 11:16:13 +02:00
Richard van der Hoff 6fc90609b6 Release crypto-js 0.1.0-alpha.11 (#2112) 2023-06-19 18:09:52 +00:00
Jonas Platte 93c911add3 ui: Use method syntax for shared::Observable methods 2023-06-19 16:46:43 +02:00
Benjamin Bouvier 55aad67338 Remove the sqlite-lock binary from the main repo
Will move it to a personal repository of mine.

Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-06-19 15:42:58 +02:00
Andrew Ferrazzutti c618094c19 Retitle tracing section 2023-06-19 09:11:15 -04:00
Ivan Enderlin 16a2121291 feat(ui): TimelineBuilder::build logs more data.
This patch updates `tracing::instrument` on `TimelineBuilder::build` so
that we can detect the circumstance of slow cases.
2023-06-19 15:06:55 +02:00
Andrew Ferrazzutti 1f141fc372 Format README.md 2023-06-19 08:25:27 -04:00
Kévin Commaille 6b40db4669 sdk: Keep all the discovered AuthenticationServerInfo
It has an account field besides the issuer field.
Also store it as immutable, the data used for authentication will be
stored in another variable.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-06-19 13:08:45 +02:00
Kévin Commaille 2b70d1c8c6 sdk: Export Invite
It's the type returned from Invited::invite_details() but it is not
available publicly.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-06-19 13:02:17 +02:00
Ivan Enderlin d105b72554 fix(sdk): Remove the Sliding Sync retry mechanism on M_UNKNOWN_POS
fix(sdk): Remove the Sliding Sync retry mechanism on `M_UNKNOWN_POS`
2023-06-19 12:37:48 +02:00
Ivan Enderlin 67ade0a2da doc(crypto): Fix a typo
doc(crypto): Fix a typo
2023-06-19 12:35:14 +02:00
Ivan Enderlin 0c85b178ac test(ui): Fix Notification test. 2023-06-19 12:16:26 +02:00
Ivan Enderlin 87a8ac7420 doc(crypto): Fix a typo. 2023-06-19 12:06:51 +02:00
Ivan Enderlin 30b7c4bd7f fix(sdk): Remove the Sliding Sync retry mechanism on M_UNKNOWN_POS.
`SlidingSync::sync` had a legacy behaviour when a `M_UNKNOWN_POS`
error was received from the server: It was resetting `pos` and sticky
parameters before re-running a sync-loop iteration, hoping to get a
valid response from the server after that. This retrying
mechanism was running up to 3 times in row (represented by the
`MAXIMUM_SLIDING_SYNC_SESSION_EXPIRATION` constant) before stopping the
`sync` for real.

While it seemed a good idea, it actually brings numerous problems:

1. Each iteration in the sync-loop generates a new request, thus making
   the `ranges` of the requests to move forwards. For `SlidingSyncList`
   that are in `Selective` sync-mode, there is no problem, but for
   `Growing` or `Paging` sync-modes, the `ranges` increased. Thus,
   when a `SlidingSync` session expires, instead of returning to
   the caller to do something clever (like what `RoomList` does: start
   again with a small range so that the “first” sync after a session
   expiration is guaranteed to be fast), it was running larger and
   larger requests, up to 3 times.
2. `M_UNKNOWN_POS` _is_ an error. Yes, `SlidingSync` must reset `pos`
   and must invalidate sticky parameters, but the `sync` must be
   stopped, and the error must be returned so that the caller can do
   something about it. Until now, this error was likely to be missed by
   the caller.
3. This legacy mechanism was forbidding `SlidingSync::sync`'s caller to
   do something with this special error. And since the caller was blind to
   this error, it disallowed more smart error management.

This patch removes this legacy retry mechanism entirely. When
`M_UNKNOWN_POS` is received from the server, `pos` is reset and sticky
parameters are invalidated as before, but the error is returned like any
other error.

This patch renames and updates an existing test that was testing sticky
parameters invalidation on `M_UNKNOWN_POS`, to include some assertions
on `pos` and to ensure that the sync-loop is stopped accordingly.
2023-06-19 11:43:27 +02:00
Benjamin Bouvier 4d3ca15be3 feat(ui): Implement Notification API (#2023)
This is the first PR for splitting the sync loop into two. This offers a new high-level API, `NotificationApi`, that makes use of a separate `SlidingSync` instance which sole role is to listen to to-device events and e2ee; it's pre-configured to do so. That means we're not force-enabling e2ee and to-device by default for every sliding sync instance, and as such we won't either generate Olm requests to the home server in general.

In the future, this new high-level API will hide some low-level dirty details so that its can be instantiated in multiple processes at the same time (lock across process, invalidate and refill crypto caches, etc.).

An embedder who would want to make use of this would need the following:

- a main sliding sync instance, without e2ee and to-device. Using the `matrix_sdk_ui::RoomList` would be the best bet, at this time.
- an instance of this `matrix_sdk_ui::NotificationApi`, with a different identifier.

Note that this is not ready to be used in an external process; or it will cause the same kind of issues that we're seeing as of today: invalid crypto caches resulting in UTD, etc.

Fixes https://github.com/matrix-org/matrix-rust-sdk/issues/1961.
2023-06-19 08:56:58 +00:00
Damir Jelić 7c393d73c4 Merge branch 'openqrnch/main' 2023-06-19 09:40:14 +02:00
Damir Jelić 75cf572968 Fix the formatting of the sync_with_result_callbac() docstring 2023-06-19 09:39:34 +02:00
Jan Danielsson bccd3412c1 Add a missing backtick in sync_with_result_callback() documentation. 2023-06-18 15:29:58 +02:00
Ivan Enderlin 6d4874e147 doc(ui): Fix a typo. 2023-06-18 09:20:57 +02:00
Andrew Ferrazzutti bb1bfbcb48 Add docs on how to use tracing for local Node dev 2023-06-16 11:51:10 -04:00
Richard van der Hoff ef0c230bd3 crypto-js: Simplify response type of Sas::confirm (#2066)
On the javascript side, everything is just an `OutgoingRequest`, so we may
as well return a single array rather than a tuple.
2023-06-16 16:19:35 +01:00
Damir Jelić bddc88472a Clarify the comment about creating a Olm session twice
Co-authored-by: Denis Kasak <dkasak@termina.org.uk>
2023-06-16 16:56:09 +02:00
Damir Jelić aab3d00246 Log if a session was created using a fallback key 2023-06-16 16:56:09 +02:00
Damir Jelić a94e2f06ee Ensure that we're not creating the same session twice
Usually it's impossible to create a Olm session from a pre-key message
twice. The one-time key that should be used for the 3DH step will be
used up and we're going to throw a `MissingOneTimeKey` error.

This used to be true and unproblematic until we added fallback keys,
these keys will not get discarded immediately after they have been used
once.

This means that a pre-key message, for which we already have a Session,
but decryption for it fails, might create a new Session overwriting the
existing one which will essentially reset the ratchet.
2023-06-16 16:56:09 +02:00
Damir Jelić 817dcde4d8 Test that we're not able to decrypt replayed messages 2023-06-16 16:56:09 +02:00
Benjamin Bouvier 76ed3511b5 Add a value-based lock in the CryptoStores (#2049)
This implements a value-based lock in the crypto stores. The intent is to use that for multiple processes to be able to make writes into the store concurrently, while still cooperating on who does them. In particular, we need this for #1928, since we may have up to two different processes trying to write into the crypto store at the same time.

## New methods in the `CryptoStore` trait

The idea is to introduce two new methods touching **custom values** in the crypto store:

- one to atomically insert a value, only if it was missing (so, not following the semantics of `upsert` used in the `set_custom_value`) 
- one to atomically remove a custom value

Those two operations match the semantics we want:

- take the lock only if it ain't taken already == insert an entry only if it was missing
- release the lock = remove the entry

By looking at the number of lines affected by the query, we can infer whether the insert/remove happened or not, that is, if we managed to take the lock or not.

## High-level APIs

I've also added an high-level API, `CryptoStoreLock`, that helps managing such a lock, and adds some niceties on top of that:

- exponential backoff to retry attempts at acquiring the lock, when it was already taken
- attempt to gracefully recover when the lock has been taken by an app that's been killed by the environment
- full configuration of the key / value / backoff parameters

While it'd be nice to have something like a `CryptoStoreLockGuard`, it's hard to implement without being racy, because of the `async` statements that would happen in the `Drop` method (and async drop isn't stable yet).

## Test program

There's also a test program in which I shamelessly show my rudimentary unix skills; I've put it in the `labs/` directory but this could as well be a large integration test. A parent program initially fills a custom crypto store, then creates a `pipe()` for 1-way communication with a child created with `fork()`; then the parent sends commands to the child. These commands consist in reading and writing into the crypto store, using a lock. And while the child attempts to perform these operations, the parent tries hard to get the lock at the same time. This helps figuring out a few issues and making sure that cross-process locking would work as intended.
2023-06-16 13:05:54 +00:00
Ivan Enderlin 1660c71dfd feat(ui): Add bump_event_types for all_rooms in RoomList
feat(ui): Add `bump_event_types` for `all_rooms` in `RoomList`
2023-06-16 14:52:10 +02:00
Ivan Enderlin 646fb35b3a feat(ui): Add bump_event_types for all_rooms in RoomList.
This patch configures the `bump_event_types` paramter for the
`all_rooms` list in `RoomList`.
2023-06-16 14:49:08 +02:00
Benjamin Bouvier bae1a71c81 feat: make OlmMachine resettable (#2091)
* feat: make `OlmMachine` resettable by making it an Arc<RwLock> instead of a OnceCell
* chore: fix e2e-encryption scoping
2023-06-16 12:39:08 +00:00
Ivan Enderlin 3d859674a8 fix(ui): Enable SS caching on RoomList
fix(ui): Enable SS caching on `RoomList`
2023-06-16 14:36:21 +02:00
Ivan Enderlin a75808e338 fix(ui): Enable SS caching on RoomList. 2023-06-16 14:31:45 +02:00
Ivan Enderlin dc06893130 fix(sdk): Disable the receipts extension temporarily
fix(sdk): Disable the `receipts` extension temporarily
2023-06-16 14:06:29 +02:00
Ivan Enderlin 489898fd40 fix(sdk): Disable the receipts extension temporarily.
Please see https://github.com/matrix-org/matrix-rust-sdk/issues/2037.
2023-06-16 13:40:38 +02:00
Ivan Enderlin 85b6eaa4c7 feat(ffi): Implement RoomList::invites
feat(ffi): Implement `RoomList::invites`
2023-06-16 13:31:53 +02:00
Ivan Enderlin 305d55d551 feat(base) In Sliding Sync, find out which rooms we have left from state events
In Sliding Sync, find out which rooms we have left from state events
2023-06-16 13:27:28 +02:00
Ivan Enderlin bae6fc71d0 test(ui): Add a test specifically for RoomList::invites. 2023-06-16 13:10:36 +02:00
Ivan Enderlin 7a1d59e9a2 feat(ffi): Implement RoomList::invites. 2023-06-16 12:43:36 +02:00
Ivan Enderlin e09a44831b feat(ui): Implement RoomList::invites. 2023-06-16 12:43:12 +02:00
Ivan Enderlin 5d82d5db89 feat(ui): Add the invites list in the RoomList.
The `invites` list is added when the first rooms are loaded, so that it
doesn't slow the first initial start up.
2023-06-16 12:28:42 +02:00
Richard van der Hoff 6199ca069c crypto-js: Add register_changes_callback methods to the verification classes (#2067) 2023-06-16 11:25:50 +01:00
Ivan Enderlin c9a9a5c20a fix(ui): SlidingSync::subscribe_to_room marks room as having missing members
fix(ui): `SlidingSync::subscribe_to_room` marks room as having missing members
2023-06-16 11:45:37 +02:00
Ivan Enderlin a99a7b4a5a test(sdk): Test that room subscription makes members not synced. 2023-06-16 11:23:11 +02:00
Ivan Enderlin c515643442 doc(sdk): Fix typos. 2023-06-16 10:35:32 +02:00
Ivan Enderlin d45f871106 doc(sdk): Fix intralink. 2023-06-16 10:34:48 +02:00
Ivan Enderlin 3a70b2e8ab fix(ui): SlidingSync::subscribe_to_room marks room as having missing members.
Fix https://github.com/matrix-org/matrix-rust-sdk/issues/2004.
2023-06-16 09:44:36 +02:00
Jonas Platte db5c9d8c4b ffi: Add Room::get_timeline_event_content_by_event_id 2023-06-15 17:24:18 +02:00
Ivan Enderlin ec1172c353 feat(ui+ffi): Implement RoomList::entries_loading_state
feat(ui+ffi): Implement `RoomList::entries_loading_state`
2023-06-15 17:20:42 +02:00
Ivan Enderlin 61d4850a66 chore: Make Clippy happy. 2023-06-15 16:18:08 +02:00
Ivan Enderlin 1f6a0b23f0 fix(ui): Set visible_rooms with a default range
fix(ui): Set `visible_rooms` with a default range
2023-06-15 16:08:17 +02:00
Ivan Enderlin 5673422831 test(ui): Use stream_assert to simplify the code. 2023-06-15 15:58:08 +02:00
Ivan Enderlin d935f52c86 doc(sdk): Update documentation of SlidingSyncList::state_stream. 2023-06-15 15:53:06 +02:00
Ivan Enderlin 0ff9073a14 feat(ffi): Implement RoomList::entries_loading_state.
This patch implements `RoomList::entries_loading_state`.
2023-06-15 15:50:21 +02:00
Ivan Enderlin a073c1422c test(ui): Test RoomList::entries_loading_state. 2023-06-15 15:45:30 +02:00
Ivan Enderlin 4e92738c28 feat(ui): Implement RoomList::entries_loading_state.
This patch implements `RoomList::entries_loading_state`, which
is a basic forwarding from the `all_rooms` sliding sync list'
`state_stream()` result.
2023-06-15 15:45:30 +02:00
Ivan Enderlin db6798321c feat(sdk): SlidingSyncList::state_stream returns a tuple.
This patch updates `SlidingSyncList::state_stream` to return
a tuple `(SlidingSyncListLoadingState, impl Stream<Item =
SlidingSyncListLoadingState>)`.
2023-06-15 15:45:30 +02:00
Ivan Enderlin f10f0d017d feat(sdk): Rename SlidingSyncState to SlidingSyncListLoadingState.
This patch renames `SlidingSyncState` to `SlidingSyncListLoadingState`
because:

1. It's about a list information,
2. It's about the loading state, not a generic state.
2023-06-15 15:45:28 +02:00
Ivan Enderlin 1c480398d2 fix(ui): Set visible_rooms with a default range.
The MSC3575 says that if no `ranges` for a list is provided, it defaults
to `0..=99`. We don't want that! This patch sets the default value to
`0..=19` for the `visible_rooms`.
2023-06-15 15:37:35 +02:00
Jonas Platte 52d2fa1a72 ffi: Clean up 2023-06-15 15:20:46 +02:00
Jonas Platte 12df1f38ed ffi: Remove remaining callback interfaces from UDL 2023-06-15 15:20:46 +02:00
Jonas Platte 899c0d59e6 ffi: Remove sliding sync things from UDL 2023-06-15 15:20:46 +02:00
Jonas Platte 867b3665d2 ffi: Remove re-exports from timeline module 2023-06-15 15:20:46 +02:00
Jonas Platte daf59356cb ffi: Remove room list from UDL 2023-06-15 15:20:46 +02:00
Jonas Platte 53ae4362f6 ffi: Remove unused public Rust API 2023-06-15 15:20:46 +02:00
Jonas Platte b789b9e063 ffi: Remove room / timeline things from UDL 2023-06-15 15:20:46 +02:00
Jonas Platte b1c8859eb9 Upgrade UniFFI 2023-06-15 15:20:46 +02:00
Jonas Platte 0e618bea5c ui: Don't use TryFutureExt where not necessary 2023-06-15 14:37:40 +02:00
Ivan Enderlin 31d834048f feat(fii): Implement RoomList::apply_input
feat(fii): Implement `RoomList::apply_input`
2023-06-15 13:22:09 +02:00
Benjamin Bouvier 1fd039c64f sliding sync: lazily generate and include the transaction id, only if it's useful (#2063)
* feat: lazily generate and include the transaction id, only if it's useful
* chore: add a small `LazyTransactionId` wrapper that ensures it's only created once

---------

Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-06-15 10:30:24 +00:00
Kévin Commaille 16a63d352c base: Remove the session field from StateChanges
It is never set nor used.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-06-15 11:12:40 +02:00
Ivan Enderlin 59565657fa feat(ffi): Implement RoomList::apply_input.
This patch implements `RoomList::apply_input`. Usage example:

```rust
room_list.apply_input(RoomListInput::Viewport { ranges: vec![RoomListRange { start: 10, end_inclusive: 20 }]}).await?;
```
2023-06-15 11:12:17 +02:00
Ivan Enderlin ea9a85395a chore(ui): Add missing trailing commas. 2023-06-15 11:11:48 +02:00
Jonas Platte 78135fcce9 ffi: Add message_event_content_new 2023-06-15 10:44:40 +02:00
Jonas Platte 7feba6f814 ffi: Use Duration instead of u64
Resolves FIXME comment.
2023-06-15 10:44:40 +02:00
Andy Balaam 7ca3686aea Fix formatting after merge 2023-06-15 09:37:27 +01:00
Ivan Enderlin 7756b6d725 feat(ui): Implement room subscriptions in RoomList + notification counts
feat(ui): Implement room subscriptions in `RoomList` + notification counts
2023-06-15 10:28:04 +02:00
Ivan Enderlin c07bb0ec39 test(ui): Test that RoomList receives State updates even if the same.
`RoomList::state` provides a `Subscriber` to the `State`. This patch
modifies the way the state is tested, to ensure that there is always
an update broadcasted even if the state is the same (e.g. if the state
moves from `CarryOn` to `CarryOn`).
2023-06-15 09:55:57 +02:00
Ivan Enderlin ddffa00589 test(ui): Test Room::*unread_notifications(). 2023-06-15 09:40:55 +02:00
Ivan Enderlin 6e1de8a5ee fix(ffi): RoomListItem::full_room returns a Room with a Timeline. 2023-06-15 09:26:33 +02:00
Ivan Enderlin 23d5655901 feat(ui): room_list::RoomInner holds Arc to Timeline.
This patch updates `RoomInner::timeline` and `::sneaky_timeline` to
`AsyncOnceCell<Arc<Timeline>>`. Adding `Arc` allows to copy the timeline
if necessary more easily.
2023-06-15 09:24:47 +02:00
Richard van der Hoff 6b45749e17 crypto-js: Add new methods to VerificationRequest (#2068)
A couple of useful methods for accessing things in `VerificationRequest`.
2023-06-14 15:46:36 +01:00
Andy Balaam e9e1afb5a5 Merge main into andybalaam/sliding-sync-reinvite (using imerge) 2023-06-14 15:39:26 +01:00
Andy Balaam 22fd44df10 Fix comments from review feedback 2023-06-14 15:31:25 +01:00
Jonas Platte b4cd0c71bf ui: Add loading indicator before waiting for prev_batch token
… in Timeline::paginate_backwards.
2023-06-14 14:00:58 +02:00
Kévin Commaille b4fdfee7f0 base: Use batch methods in Room::get_members
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-06-14 13:51:52 +02:00
Kévin Commaille 38fc1f7b15 base: Add method to construct RoomMember from parts
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-06-14 13:51:52 +02:00
Kévin Commaille e32e9b5a22 base: Add state store method to fetch several display_names at once
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-06-14 13:51:52 +02:00
Kévin Commaille 7cba6d0849 base: Add state store method to fetch several presence events at once
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-06-14 13:51:52 +02:00
Kévin Commaille b8abd1c022 base: Add state store method to fetch several profiles at once
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-06-14 13:51:52 +02:00
Kévin Commaille 4103d1b3e3 sdk: Add room method to fetch several state events at once
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-06-14 13:51:52 +02:00
Kévin Commaille f740195eb6 base: Add state store method to fetch several state events at once
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-06-14 13:51:52 +02:00
Jonas Platte ae4ead5550 Upgrade typos CI action
… and update the config file to reduce check flakiness.
2023-06-14 12:31:32 +02:00
Jonas Platte 820d3aff65 Rewrap base64 test strings 2023-06-14 12:31:32 +02:00
Jonas Platte b3017a1073 Fix typos 2023-06-14 12:31:32 +02:00
Ivan Enderlin b9c27b5c63 feat(ui): Implement Room::*unread_notifications. 2023-06-14 12:15:16 +02:00
Ivan Enderlin 1bc455f75b feat(ffi): Room:add_timeline_listener returns a …Result.
This patch updates `Room::add_timeline_listener` to return a `RoomTimelineListenerResult`, a new type defined as:

```rust
pub RoomTimelineListenerResult {
    items: Vec<Arc<TimelineItem>>,
    items_stream: TaskHandle,
}
```

It is not possible to cancel the `items_stream` by cancelling the
`TaskHandle`. Without this, dropping `Room` won't drop the `Timeline`,
as a clone is moved inside the spawned task. As a consequence, it will
endlessly call the listener.
2023-06-14 11:56:07 +02:00
Ivan Enderlin 97e4a5cab0 chore(ffi): Remove RoomListItem::timeline.
What the FFI user wants is to subscribe a listener to the
timeline updates. This feature is already supported by
`room_item.full_room().add_timeline_listener()`.  So we can safely
remove `RoomListItem::timeline` as we are sure it's never going to be
used for now.
2023-06-14 11:13:06 +02:00
Ivan Enderlin 192b9ce808 feat(ui+ffi): Implement Room::id as a shortcut.
It's possible to do `room.inner_room().room_id()` but it's just simpler
to call `room.id()`. This patch adds this shortcut.

It's especially useful for FFI users, where creating a “full
room” (`room_item.full_room().room_id()`) may be expensive.
2023-06-14 10:59:03 +02:00
Ivan Enderlin dba397d470 feat(ffi): Add RoomListItem::subscribe and ::unsubscribe. 2023-06-14 10:56:59 +02:00
Ivan Enderlin 712b395310 feat(ui): Add Room::subscribe and ::unsubscribe.
This patch adds the `subscribe` and `unsubscribe` method on `Room`.

To achieve that, `Room` receives an `Arc<SlidingSync>`, as the
subscription methods are on `SlidingSync`. It's just easier to put them
on `Room` for the API consumer. It makes the API also more elegant.

Finally, the patch adds the appropriate test.
2023-06-14 10:51:37 +02:00
Kévin Commaille eb5af4287f sdk: Allow to get rooms filtered by room state
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-06-14 10:45:37 +02:00
Kévin Commaille c978fa6d40 base: Deprecate BaseClient::get_stripped_rooms
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-06-14 10:45:37 +02:00
Kévin Commaille ac8ea4786c base: Deprecate StateStore::get_stripped_room_infos
It is now unused.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-06-14 10:45:37 +02:00
Kévin Commaille 281870b33f base: Remove stripped rooms list from Store
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-06-14 10:45:37 +02:00
Kévin Commaille bcd7e92a94 base: Allow to get rooms filtered by state
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-06-14 10:45:37 +02:00
Kévin Commaille ea219d836e base: Do not separate stripped room info
Since stripped and non-stripped room infos use the same types,
the separation is not necessary anymore.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-06-14 10:45:37 +02:00
Damir Jelić f67c592259 Properly support the hkdf-hmac-sha256.v2 MAC method for the SAS verification (#2064) 2023-06-14 10:17:22 +02:00
Ivan Enderlin 0db5a6a25d Merge branch 'main' into pr/2058 2023-06-14 09:55:31 +02:00
Ivan Enderlin 2c871807a3 feat(ui+ffi): Add various features to RoomList
feat(ui+ffi): Add various features to `RoomList`
2023-06-14 09:22:24 +02:00
Ivan Enderlin f55c1021c4 Merge pull request #2065 from matrix-org/rav/fix-docs
crypto-js: improvements to the documentation
2023-06-14 08:35:59 +02:00
Richard van der Hoff f78a2951e4 more doc fixes 2023-06-13 22:10:48 +01:00
Richard van der Hoff a8468cba59 crypto-js: improvements to the documentation
... mostly, writing down what things actually return.
2023-06-13 21:54:19 +01:00
Damir Jelić 48a24a6aed Use the short auth strings from the start content when accepting a verification (#2061)
Co-authored-by: Benjamin Bouvier <public@benj.me>
2023-06-13 17:33:57 +00:00
Benjamin Bouvier a79d519ff9 sliding sync: always fall back to the auto-discovered proxy URL, if any
Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-06-13 19:33:30 +02:00
Jonas Platte 47a67d1d67 Upgrade Ruma 2023-06-13 18:33:28 +02:00
Jonas Platte adb9e60fbe common: Add executor::JoinHandle
… and simplify wasm spawn implementation.

This reduces the differences on wasm vs. non-wasm. Of course it's still
possible to rely on details of the different error types, but at least
both implement a few common traits:
`Debug`, `Display`, `Error`.
2023-06-13 16:50:33 +02:00
Andy Balaam 240a7f7aae Make set_state public to avoid unused warning 2023-06-13 13:43:46 +01:00
Andy Balaam f36a5b8cd7 Deserialise events early so we don't have to do it multiple times
We pass the already-deserialised event in to handle_state and
process_sliding_sync_room_membership, to avoid deserialising inside both
of them.
2023-06-13 13:05:14 +01:00
Andy Balaam 451398612a In Sliding Sync, find out which rooms we have left from state events
Look through m.room.member events when processing Sliding Sync
responses, finding those that refer to our user's membership, so that we
can recognise which rooms we have left.
2023-06-13 13:05:14 +01:00
Benjamin Bouvier 8aa12c929a chore: group GossipMachine fields inside an Arc-struct
Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-06-13 12:28:37 +02:00
Andy Balaam 5c8a5466cf Use async_test to mark sliding sync tests 2023-06-13 12:15:49 +02:00
Andy Balaam 9a3060793c Extract a function for processing misc properties of a room in sliding sync 2023-06-13 12:15:49 +02:00
Andy Balaam 085c9767f0 Extract a function for processing membership of a room in sliding sync 2023-06-13 12:15:49 +02:00
Jonas Platte 2c71556ef2 Upgrade opentelemetry dependencies 2023-06-13 11:08:45 +02:00
Jonas Platte e78dbaf7c6 ffi: Don't require native-tls 2023-06-13 10:33:52 +02:00
Ivan Enderlin 15199316d3 doc(ui): Fix an intra-link. 2023-06-13 01:30:49 +02:00
Ivan Enderlin 1c8772848a feat(ui): Add the required state m.room.power_levels for all_rooms in RoomList. 2023-06-13 01:24:43 +02:00
Ivan Enderlin 9f6bc7d35f feat(ui): Configure filters for RoomList lists. 2023-06-13 01:24:43 +02:00
Ivan Enderlin 65959b07a4 feat(ui): Configure required_state for all_rooms in RoomList. 2023-06-13 01:24:43 +02:00
Ivan Enderlin 901deaf8e0 feat(ui): Enable common extensions on RoomList. 2023-06-13 01:24:43 +02:00
Ivan Enderlin 370083ee03 feat(ui,ffi): Add getter for matrix_sdk(_ffi)::Room. 2023-06-13 01:24:43 +02:00
Ivan Enderlin 5c01917f42 chore(ui): Split matrix_sdk_ui::room_list::mod.rs into smaller modules.
No code changes. This patch is just moving things around.
2023-06-13 01:24:43 +02:00
Ivan Enderlin 3547bd2f54 feat(ffi): Implement RoomList API
feat(ffi): Implement `RoomList` API
2023-06-13 01:23:24 +02:00
Ivan Enderlin 742ccea5ef doc(ffi): Fix a typo. 2023-06-13 00:37:14 +02:00
Ivan Enderlin 0233d65f02 In sliding sync, do all the same processing on an invited room as a joined one
In sliding sync, do all the same processing on an invited room as a joined one
2023-06-13 00:28:11 +02:00
Ivan Enderlin c65e98895a test(ui): Fix a test. 2023-06-13 00:27:26 +02:00
Ivan Enderlin d5211445a5 chore: Make Clippy happy. 2023-06-13 00:21:50 +02:00
Ivan Enderlin 235efaa85c fix(ffi): Do not overwrite Client's sliding_sync_proxy everytime.
The comment explains the fix correctly.
2023-06-13 00:12:41 +02:00
Ivan Enderlin b85dff347a chore(ffi): Simplify code and remove one method. 2023-06-12 23:36:35 +02:00
Ivan Enderlin dec1129106 chore(ffi): Remove Client::sliding_sync_proxy.
Instead of storing `sliding_sync_proxy` inside the `Client`, this patch
updates the code to store it inside `matrix_sdk::Client` directly.

That way, there is unique place where to store the sliding sync proxy
URL.
2023-06-12 23:29:23 +02:00
Ivan Enderlin 9bcc50fe2f feat(sdk): Client::sliding_sync_proxy is a StdRwLock.
This patch changes `matrix_sdk::Client::sliding_sync_proxy` to be a
`std::sync::RwLock<Option<Url>>` instead of `tokio::sync::RwLock<_>`.
It means that all methods reading or writing this field are sync instead
of async, which makes the code a lot more easier. Having an async-aware
lock wasn't necessary here.
2023-06-12 23:15:03 +02:00
Ivan Enderlin 7636a069b7 fix(ffi): Rollback how Sliding Sync proxy URL is computed.
I guess I know what's happening but I rollback some previous commits to
be sure it comes back on track.
2023-06-12 17:07:59 +02:00
Ivan Enderlin 8f102af801 chore: Make Clippy happy. 2023-06-12 16:47:22 +02:00
Ivan Enderlin 069743f3e1 feat(sdk): Change how Client::sliding_sync_proxy is represented. 2023-06-12 16:47:22 +02:00
Ivan Enderlin 38f8ebb6b9 feat(ffi): Add ability to force a Sliding Sync proxy URL from a restored session. 2023-06-12 16:47:22 +02:00
Andy Balaam f6d707cce8 Merge main into andybalaam/sliding-sync-process-unify-invited (using imerge) 2023-06-12 13:40:07 +01:00
Jonas Platte f883826db0 ffi: Add Room::cancel_send 2023-06-12 14:20:51 +02:00
Jonas Platte 4541ef6b90 sdk: Add Timeline::cancel_send 2023-06-12 14:20:51 +02:00
Benjamin Bouvier 29ddeb45d9 feat(sdk): implement sticky parameters (#1948)
* chore: add comments explaining what the position markers are
* feat(sdk): add scaffolding for sticky parameters
* test(sdk): add tests for the sticky parameters API
* feat(sdk): include the bump_event_types in the sticky parameters
* WIP: add TODO comments for deeply nested sticky parameters
* test(sdk): add extra test for sticky parameters
* feat: add extensions in the sticky parameters + test request generation + test since token
* chore: fix merge + get rid of unused inner extensions
* feat: use sticky parameters for lists too
* chore: Introduce the StickyManager, a reusable way to manage per-data sticky parameters
* chore: move the sticky scaffolding to its own module
* chore: clippy + fmt
* chore: get rid of `update_to_device_token`
* review: append SlidingSync prefix to Stick* data structures
* address review comments
* Replace nbsp with regular space
* Get rid of a write-access to a lock (because thanks inner mutability!)
* Add an integration test when losing `pos` in sticky parameters, and avoid `block_on`

Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-06-12 10:46:13 +00:00
Ivan Enderlin 790dc47fca feat(ffi): Make RoomList.room non-async. 2023-06-12 12:41:12 +02:00
Ivan Enderlin 199f5708c0 chore(sdk): Tidy sliding sync processing code
Tidy sliding sync processing code
2023-06-12 11:37:40 +02:00
Andy Balaam f4aed74fb1 Fix formatting 2023-06-12 09:50:04 +01:00
Andy Balaam 323aaffe34 Merge main into andybalaam/sliding-sync-process-tidy (using imerge) 2023-06-12 09:37:37 +01:00
Andy Balaam 9a5291b2a9 Test canonical aliases in invited rooms via sliding sync 2023-06-12 10:34:04 +02:00
Andy Balaam 1e24542dd3 Handle required state in invited rooms as well as normal 2023-06-12 10:34:04 +02:00
Andy Balaam dcd5a27a2f Rename room_to_add->room_to_store 2023-06-12 10:34:04 +02:00
Andy Balaam dafee483fa Refactor process_sliding_sync to extract a method for dealing with rooms 2023-06-12 10:34:04 +02:00
Andy Balaam 0b4fba81d8 Test for adding an invited room to the client and invite list 2023-06-12 10:34:04 +02:00
Andy Balaam 34a56a70a0 Test for finding avatars in invite rooms 2023-06-12 10:34:04 +02:00
Andy Balaam 76a7ad0cbf Test for finding an avatar in a room via sliding sync 2023-06-12 10:34:04 +02:00
Ivan Enderlin 81628d15b8 doc(ffi): Fix a link. 2023-06-12 10:06:57 +02:00
Ivan Enderlin 39a4d039dd chore(ffi): Remove ability to use a custom sliding sync proxy URL. 2023-06-12 09:58:33 +02:00
Ivan Enderlin d24a1d8d6d feat(ui): Update the Sliding Sync proxy URL when creating RoomList. 2023-06-12 09:21:08 +02:00
Ivan Enderlin 2f433138dd chore(ffi): Make Clippy happy. 2023-06-12 09:07:39 +02:00
Ivan Enderlin 6301f32ee5 chore(ffi): Rename RoomListRoom to RoomListItem. 2023-06-12 09:07:39 +02:00
Ivan Enderlin 7ae8ee14eb feat(ffi): RoomListRoom::name and ::latest_event are non-async. 2023-06-12 09:07:39 +02:00
Ivan Enderlin 070965fc87 feat(ffi): Implement RoomList::rooms.
This patch implements `RoomList::rooms` to fetch one room. The type
name is `RoomListRoom` to avoid any collision with an existing `Room`
type already.

`RoomListRoom` implements `name`, `timeline` and `latest_event`.
2023-06-12 09:07:39 +02:00
Ivan Enderlin e2480be47f feat(ffi): Make RoomList::entries async.
Because we can!
2023-06-12 09:07:39 +02:00
Ivan Enderlin cb51c766a8 feat(ffi): Rename “observer” to “listener”. 2023-06-12 09:07:39 +02:00
Ivan Enderlin 68c19f4129 feat(ffi): First step for RoomList in FFI bindings. 2023-06-12 09:07:39 +02:00
Ivan Enderlin 5416ba06f5 feat(ui): Merge RoomList::state and RoomList::state_stream.
By returning a `Subscriber`, one can call `Subscriber::get` to get the
inner value. Thus, having `state` and `state_stream` is useless. It's
possible to return have `state` which returns `Subscriber`, and we get
one value for two usages.
2023-06-12 09:07:39 +02:00
Ivan Enderlin 623332b931 feat(ffi): Extract TaskHandle into itw own module. 2023-06-12 09:07:39 +02:00
Ivan Enderlin d4e983e559 feat(ui): Rename State::Enjoy to State::CarryOn. 2023-06-12 09:07:39 +02:00
Mauro 6444848511 docs: updated readme - rust version (#2047)
* docs: update readme
* removing error
2023-06-09 13:16:09 +00:00
Andy Balaam 11adcf425c In sliding sync, do all the same processing on an invited room as a joined one
The example in MSC3575 shows a room with invite_state property, but also
timeline, joined_count etc. properties. That may or may not be very
likely in practice, but I think it makes sense to check for all these
properties even when the room is an invite, and use them if they are
present.
2023-06-09 13:25:04 +01:00
Andy Balaam 7e197ec8d4 Simplify invited room sliding sync processing
Added some comments based on my understanding of MSC3575. Previously we
had a FIXME about how we were setting the room state to invite or join
based on the presence or absence of the invite_state property. I think
this behaviour is correct, so I added some comments explaining why.

The functional change here is to note that we call
store.get_or_create_stripped_room to find/create the stripped room, and
this actually deletes any room of this ID that is in the store, so our
later call to store.get_room would always fall back to getting the
stripped room, which we already have, so there was no need to do the
get_room call at all.
2023-06-09 13:14:58 +01:00
Andy Balaam 9d943e7c62 Clarify in tests that invite_state contains very minimal JSON 2023-06-09 13:14:58 +01:00
Andy Balaam 8c2cc522bc Test canonical aliases in invited rooms via sliding sync 2023-06-09 12:54:43 +01:00
Andy Balaam 4a04c70c45 Handle required state in invited rooms as well as normal 2023-06-09 12:54:43 +01:00
Andy Balaam ee8f94cb95 Rename room_to_add->room_to_store 2023-06-09 12:54:43 +01:00
Andy Balaam 24ff62befc Refactor process_sliding_sync to extract a method for dealing with rooms 2023-06-09 12:54:43 +01:00
Andy Balaam a85c481368 Test for adding an invited room to the client and invite list 2023-06-09 12:52:26 +01:00
Andy Balaam 5545c98a85 Test for finding avatars in invite rooms 2023-06-09 12:52:26 +01:00
Andy Balaam ac7c6ba84c Test for finding an avatar in a room via sliding sync 2023-06-09 12:52:26 +01:00
Kévin Commaille ae2f834345 sqlite: Return an error when DB version is invalid or missing (#2038)
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-06-09 11:02:33 +00:00
Andy Balaam 0e30d85df4 Provide no event_id for the name state event when it comes via update_name
Also respond to a couple of minor review comments
2023-06-08 18:30:20 +02:00
Andy Balaam 02d03c55f2 Update the name of a room during sliding sync processing 2023-06-08 18:30:20 +02:00
Andy Balaam 0cff8f3697 Allow updating the name in a RoomInfo 2023-06-08 18:30:20 +02:00
Andy Balaam 0f5906a0fa Tests for processing sliding sync responses 2023-06-08 18:30:20 +02:00
Jonas Platte a977b3a8d5 ui: Use stream_assert for timeline unit tests 2023-06-08 12:25:58 +02:00
Jonas Platte 6c6c43e709 ui: Filter virtual timeline items for some tests 2023-06-08 12:25:58 +02:00
Benjamin Bouvier 43bac4995f chore: rename homeserver to sliding_sync_proxy in sliding sync
Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-06-08 11:13:40 +02:00
Jonas Platte c8b74bec0d ci: Fixes to toolchain installation 2023-06-07 17:25:24 +02:00
Jonas Platte b5339ceaba ui: Activate sdk's testing feature for unit tests
Fixes running `cargo test` without any flags from the crate root.
2023-06-07 17:25:24 +02:00
Jonas Platte 0898c76bb7 crypto: Simplify is_cross_signing_trusted 2023-06-07 17:25:24 +02:00
Jonas Platte c19d72f0f4 Use Option::is_some_and where applicable 2023-06-07 17:25:24 +02:00
Jonas Platte 0b9c082e11 ffi: Add EventTimelineItem::transaction_id 2023-06-07 16:40:14 +02:00
Jonas Platte aa3adbd53d ui: Don't wait on prev_batch token for more than 3s 2023-06-07 16:21:48 +02:00
Jonas Platte 87510a5bc2 ffi: Add wait_for_token to PaginationOptions 2023-06-07 16:21:48 +02:00
Jonas Platte af870fcff3 ui: Allow waiting for token before starting pagination 2023-06-07 16:21:48 +02:00
Jonas Platte 1e10a54d3d ui: Fix clippy lints 2023-06-07 16:21:48 +02:00
Jonas Platte bfce4d1006 ui: Merge timeline::room_ext module into timeline::traits 2023-06-07 16:21:48 +02:00
Jonas Platte 2bcc70beb9 ui: Move timeline-internal traits into separate module 2023-06-07 16:21:48 +02:00
Damir Jelić 7552f4f72a Merge pull request #2028 from matrix-org/release-matrix-sdk-crypto-js-v0.1.0-alpha.10
Bindings JS: New release `matrix-sdk-crypto-js v0.1.0-alpha.10`
2023-06-07 15:51:24 +02:00
Jonas Platte 415c13fa90 ui: Add a test for retrying a failed send 2023-06-07 13:29:42 +02:00
Jonas Platte 0ca8369a76 ui: Fix clippy warnings 2023-06-07 13:29:42 +02:00
Jonas Platte dc05d17330 Upgrade eyeball-im-util 2023-06-07 13:29:42 +02:00
Jonas Platte 9505ace8e2 ffi: Add Room::retry_send 2023-06-07 13:29:42 +02:00
Jonas Platte df7beb4afd ui: Add Timeline::retry_send 2023-06-07 13:29:42 +02:00
Jonas Platte f1e62b0bb8 ci: Run coverage when PR is ready for review 2023-06-07 11:31:39 +02:00
Ivan Enderlin 4e29e6e347 feat(ui): Disable caching and make Timelines lazy
feat(ui): Disable caching and make `Timeline`s lazy
2023-06-07 11:29:22 +02:00
Florian Duros 81d4dc8b6e matrix-sdk-crypto-js v0.1.0-alpha.10
Release `crypto-js` / Publish 🕸 [m]-crypto-js (push) Failing after 36s
2023-06-07 10:07:05 +02:00
Florian Duros 65bdb1a2e3 Update CHANGELOG.md 2023-06-07 10:06:51 +02:00
Damir Jelić 0e5e8a205c Merge pull request #2020 from matrix-org/florianduros/bindings/add-missing-key-identity
Bindings JS: Add missing keys to `UserIdentity` and `OwnUserIdentity`
2023-06-07 10:00:20 +02:00
Ivan Enderlin 5c182a0d03 sliding sync: enable read-receipts in the common extensions
sliding sync: enable read-receipts in the common extensions
2023-06-07 09:58:27 +02:00
Ivan Enderlin 3acb56aa31 feat(ui): Make Room::timeline and ::sneaky_timeline lazy.
This patch uses a new `async-once-cell` crate to make `Room::timeline`
and `Room::sneaky_timeline` by making them lazy. Their values are
computed lazily, on-demand, when calling the `Room::timeline` method or
`Room::latest_event`.
2023-06-07 09:51:56 +02:00
Ivan Enderlin a2cefedf73 RoomList API: enable account_data extension by default
`RoomList` API: enable `account_data` extension by default
2023-06-07 09:35:04 +02:00
Ivan Enderlin 169038504d fix(ui): Disable Sliding Sync caching in RoomList. 2023-06-07 09:31:52 +02:00
Benjamin Bouvier d3ddfabaef sliding sync: enable read-receipts in the common extensions
Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-06-06 20:09:03 +02:00
Benjamin Bouvier 027db88078 sliding sync: have the RoomApi use add_list instead of add_cached_list until the perf issue of reloading has been fixed
Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-06-06 19:36:42 +02:00
Benjamin Bouvier 3b10c235ab sliding sync: enable account data extension in room list API
This extension was enabled by both ElementX apps by default, along with the e2ee / to-device extensions that will be handled
by the new Notification API. To maintain the current behavior, it's important to re-enable this extension before getting
RoomList in production.

Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-06-06 19:35:20 +02:00
Florian Duros 198c8f6901 Prettier fix 2023-06-06 17:26:57 +02:00
Florian Duros 721a704540 Add tests 2023-06-06 17:23:16 +02:00
Florian Duros d0f3f1e657 Review fixes 2023-06-06 17:21:27 +02:00
Benjamin Bouvier f84ff148da feat(sdk): add an optional temporary directory to get_media_file
By default, get_media_file will attempt to use a default directory
for temporary files and directories. Unfortunately, there might not be
such a thing on some older Android devices, which use per-application
directories.

For this specific case, an optional temporary directory parameter
is added to the `get_media_files` parameters, so one can provide their own
temporary directory path.

This new parameter is expected to be set at least on Android; other platforms
should work just fine without it.

Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-06-06 15:20:06 +02:00
Florian Duros b4c440a5e7 Update CHANGELOG.md 2023-06-06 15:16:30 +02:00
Florian Duros b760c0e6ce Add keys to UserIdentity and OwnUserIdentity 2023-06-06 15:05:28 +02:00
Kévin Commaille 407375ad17 base: Move StateStore::get_member_event to StateStoreExt
It is a wrapper around get_state_event_static_for_key

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-06-06 11:56:11 +02:00
Kévin Commaille b690bcfbaf sdk: Re-export store traits
The store is exposed with `Client::store()` but the traits are not.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-06-06 11:56:11 +02:00
Benjamin Bouvier d1a1a0f5c5 Reuse upstream Ruma repository
This was a temporary replacement I've made, waiting for a PR of mine to be merged, and it's been merged since then. Oh well.

Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-06-06 10:04:20 +02:00
Ivan Enderlin f61fdcbdbe feat(ui): RoomList, step 1: the Foundation
feat(ui): `RoomList`, step 1: the Foundation
2023-06-05 20:50:25 +02:00
Ivan Enderlin 16932abeaa chore: Make Tarpaulin happy. 2023-06-05 20:17:19 +02:00
Ivan Enderlin e6fdcfdf52 chore: Make Clippy happy. 2023-06-05 20:05:46 +02:00
Ivan Enderlin 42df0d0e21 fix: Fix merge commit. 2023-06-05 19:43:32 +02:00
Ivan Enderlin d1bccacef9 chore: Make CI happy. 2023-06-05 19:40:51 +02:00
Ivan Enderlin 08559b58b6 Merge branch 'main' into feat-ui-roomlist 2023-06-05 19:22:33 +02:00
Ivan Enderlin ac7a576035 chore(ui): Address feedbacks. 2023-06-05 19:13:48 +02:00
Jonas Platte 9148eaaea1 sdk: Add a test for room update channels 2023-06-05 17:46:22 +02:00
Jonas Platte adb91262e0 ui: Do fully-read tracking in room update processing
… instead of separate event handlers.
2023-06-05 17:46:22 +02:00
Jonas Platte a916ef468e ui: Make some free functions TimelineInnerState methods instead 2023-06-05 17:46:22 +02:00
Jonas Platte 4986f98aa3 ui: Batch timeline object updates from sync response 2023-06-05 17:46:22 +02:00
Jonas Platte e59562725d ui: Move gappy sync response handling out of FFI 2023-06-05 17:46:22 +02:00
Jonas Platte 945a1228d0 ui: Use room subscription instead of event handler for timeline events 2023-06-05 17:46:22 +02:00
Jonas Platte 9489720386 Add Client::subscribe_to_room_updates
… and `room::Common::subscribe_to_updates` which does the same thing,
but more conveniently if one already has a room object.
2023-06-05 17:46:22 +02:00
Jonas Platte 63f7f4a903 Update event handler functions to take Option<&_> instead of &Option<_> 2023-06-05 17:46:22 +02:00
Jonas Platte 2c2285b5d7 ui: Deduplicate local and remote echo by event ID when it comes in late 2023-06-05 17:33:11 +02:00
Jonas Platte ede6bed948 ui: Move echo integration test into separate module 2023-06-05 17:33:11 +02:00
Jonas Platte 185fc9aa3c ui: Add copyright headers to integration tests 2023-06-05 17:33:11 +02:00
Jonas Platte 62817a8ef8 ui: Move pagination integration tests into separate module 2023-06-05 17:33:11 +02:00
Jonas Platte 3a5f83d9dc ffi: Include causes when stringifying anyhow::Error 2023-06-05 17:29:53 +02:00
Benjamin Bouvier 61c3a2a2c7 sliding sync: infer the storage key from the loop id and user id (#2008)
* sliding sync: infer the storage key from the loop id and user id
* chore: rename `sync_id` to `id`
* chore: check that the sliding sync id is less than 16 chars
* chore: rejigger the storage key creation logic

Now the prefix is visible only in the `format_storage_key_prefix` function, and other `format_storage_key` function will be based off that.

* chore: update sliding sync README with API updates and fix outdated information
* chore: clippy + fix test

Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-06-05 14:51:40 +00:00
Ivan Enderlin 4a62949b6c test(sdk): Simplify a test. 2023-06-05 15:19:18 +02:00
Ivan Enderlin ad8d7caecb feat(ui): Handle RoomList's State::Terminated properly.
This patch handles errors from the Sliding Sync loop properly.

When an error is received, the `RoomList` state machine enters the
`Terminated` state. Immediately after that, the sync stream is stopped.

When the sync stream is restarted, the next state will be calculated.
When the current state is `Terminated`, the next state is the state
that led to the `Terminated` state. To avoid having a “first” huge sync
(imagine a room list of 1000 rooms, you don't want to “resume” from an
error with a first sync for 1000 rooms), lists are partially “reset”
depending of the state where the machine is in.

An important test has been added to test all possibles cases with errors
and list' states.
2023-06-05 15:09:10 +02:00
Ivan Enderlin 4bfc48b4ae feat(sdk): Simplify returned values of SlidingSync::sync.
First off, `SlidingSync::sync_once` no longer returns
`Option<UpdateSummary>` but `UpdateSummary`. It simplifies the rest of
the patch.

Next, `SlidingSync::sync` returns either `Ok(…)` and continues to sync,
or it returns `Err(…)` and it stops the sync stream immediately. No more
error could be returned with the stream to continue syncing.

Finally, the `UnknownPos` error no longer emits an err, but silently
skip over the sync-loop until the threshold is reached; which in this
case will generate a proper error.
2023-06-05 15:05:42 +02:00
Ivan Enderlin c1a24cf033 feat(ui): Implement Room::timeline and ::latest_event.
This patch changes `RoomInner` to have an `room:
Option<matrix_sdk::room::Room>` field to `room: matrix_sdk::room::Room`.
`room` is not longer an `Option`.

Then, it's easier to have a new `timeline: Timeline` field, along with a
`sneaky_timeline: Timeline` field. Both are used by the new
`Room::timeline()` and `Room::latest_event()` method.
2023-06-02 22:38:48 +02:00
Ivan Enderlin 67ef42f4c5 feat(ui): Implement RoomList::room.
This patch implements `RoomList::room`, which returns a `Result<Room>`:
the room ay or may not exist.

A new `Room` type is created. It wraps an `Arc<RoomInner>` type, so that
it's cheap to clone it.

The `RoomInner` type owns a `SlidingSyncRoom` and
`matrix_sdk::room::Room` type. If some API or data are missing on
the former, the latter acts as a backup. This is the case for the
`Room::name` method which makes it best to return a name to the caller.
2023-06-02 21:28:45 +02:00
Ivan Enderlin 537f95b683 feat(sdk): SlidingSync::get_rooms? are now async. 2023-06-02 20:59:26 +02:00
Ivan Enderlin dcad897084 test(ui): Ensure the timeline_limit is not reset. 2023-06-02 20:49:33 +02:00
Ivan Enderlin c6dae678bd sliding sync: move the bump_event_types to be per-list
sliding sync: move the `bump_event_types` to be per-list
2023-06-02 20:29:10 +02:00
Ivan Enderlin e18728aa5f feat(ui): Set timeline_limit for all_rooms and visible_rooms. 2023-06-02 20:06:50 +02:00
Ivan Enderlin 8ee84be839 doc(ui): Write documentation for RoomList. 2023-06-02 20:06:31 +02:00
Kévin Commaille 588b58c616 crypto: Remove unnecessary to_owned
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-06-02 12:22:26 +02:00
Kévin Commaille 3ab171ca2d chore: Update log dependency
Fixes compilation of value-bag crate with Rust nightly

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-06-02 12:22:26 +02:00
Benjamin Bouvier 28c8e5df71 feat(sdk): move bump_event_types to the list sub-request
Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-06-01 18:57:45 +02:00
Benjamin Bouvier 6a58be38ca Temporarily use bnjbvr's repository for bump-event-types change in ruma
Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-06-01 18:51:53 +02:00
Ivan Enderlin 2f68c86796 feat(ui): Add the RoomList Input API.
This patch lands the first design of the `Input` API. An `Input` is
something external that can be understood by the `RoomList` state
machine. The first inpuput is `Viewport` to change the “viewport” of the
`RoomList`, which translates to the change of the ranges of one specific
Sliding Sync list.
2023-06-01 16:55:29 +02:00
Ivan Enderlin 13d38993f8 feat(sdk): Expose the Range and Ranges type in matrix_sdk::sliding_sync. 2023-06-01 16:52:16 +02:00
Ivan Enderlin e2d2cf787d test(sdk): Fix according to previous commits. 2023-06-01 16:52:09 +02:00
Ivan Enderlin f5c950c54a fix(ffi): Update according to last commits. 2023-06-01 15:58:58 +02:00
Ivan Enderlin c2d082ca8d test(ui): Update the tests according to previous commits. 2023-06-01 15:58:12 +02:00
Ivan Enderlin 553b5c6db3 Merge pull request #1 from matrix-org/feat-ui-roomlist
Feat UI roomlist
2023-06-01 15:46:00 +02:00
Jonas Platte 5106255911 On-demand stream creation 2023-06-01 15:40:39 +02:00
Jonas Platte 58e8c0a7ac Fix warning 2023-06-01 15:34:13 +02:00
Jonas Platte db0217d093 Box internally 2023-06-01 15:34:07 +02:00
Ivan Enderlin 048b054a65 feat(ui): Implement RoomList::update_entries_stream_filter.
This patch implements `RoomList::update_entries_stream_filter` which
allows to… change the… entries stream filter. This patch also provides a
test for that. How nice it is.
2023-06-01 14:55:53 +02:00
Ivan Enderlin 0a1c0547b4 test(ui): Add test to ensure RoomList::sync resumes from current state. 2023-06-01 14:18:47 +02:00
Ivan Enderlin fbe1603190 feat(ui): Rethink the state machine of RoomList. 2023-06-01 14:06:02 +02:00
Damir Jelić d6d19d9111 Don't re-encode the plaintext after decrypting a backup 2023-06-01 12:56:18 +02:00
Jonas Platte 3e2bc3a514 Drop matrix-sdk-sled 2023-06-01 12:06:35 +02:00
Kévin Commaille 7cd8898f5f indexeddb: Use parentheses for the impl_state_store macro
Allows rustfmt to do its thing.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-06-01 11:54:29 +02:00
Kévin Commaille 83e7afab5d sdk: Allow to get stripped state events from the store
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-06-01 11:13:24 +02:00
Kévin Commaille 645af31c59 base: Use generic types for (Raw)MemberEvent
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-06-01 11:13:24 +02:00
Ivan Enderlin a090a070ee chore(cargo): Add missing EOF. 2023-06-01 10:08:59 +02:00
Ivan Enderlin 697c92beb1 test(ui): Test RoomList::entries_stream with more cases. 2023-06-01 09:48:54 +02:00
Ivan Enderlin 954d798ac3 test(ui): Write an assert_entries_stream macro. 2023-06-01 09:48:54 +02:00
Ivan Enderlin a3c96dcb62 feat(ui): Implement RoomList::entries_stream. 2023-06-01 09:48:53 +02:00
Ivan Enderlin 1caa8b1aa6 chore(ui): Polish after the rebase. 2023-06-01 09:48:53 +02:00
Ivan Enderlin 4557c2a7b2 feat(ui): Add RoomList::entries.
This patch implements the `RoomList::entries` method, which allows
to get a stream of `VectorDiff` over the room list, and that can be
filtered.
2023-06-01 09:48:53 +02:00
Ivan Enderlin f058c59582 feat(sdk): Add SlidingSyncList::room_list_filtered_stream.
This patch adds a new method on `SlidingSyncList` named
`room_list_filtered_stream`, which uses the new `eyeball-im-util` crate
with its new `FilteredSubscriber` type.
2023-06-01 09:48:53 +02:00
Ivan Enderlin aa70c85e02 test(ui): Test RoomList sync from Init to Enjoy. 2023-06-01 09:48:53 +02:00
Ivan Enderlin 1173636b35 feat(ui): Add room_list::Error. 2023-06-01 09:48:53 +02:00
Ivan Enderlin 61f903a5a9 test(ui): Clean up a test. 2023-06-01 09:48:53 +02:00
Ivan Enderlin 4d6a6ac17f feat(ui) Add State::Terminated in RoomList. 2023-06-01 09:48:53 +02:00
Ivan Enderlin 26a764d9dd test(ui): Test all RoomList actions. 2023-06-01 09:48:53 +02:00
Ivan Enderlin bd175d9f66 test(sdk): Store the sync-mode in SlidingSyncListInner only for tests. 2023-06-01 09:48:53 +02:00
Ivan Enderlin f89060bbe9 chore(ui): Update after the rebase. 2023-06-01 09:48:53 +02:00
Ivan Enderlin 01366a08df !foo 2023-06-01 09:48:53 +02:00
Ivan Enderlin 4e07ac1c76 test(ui): Improve testability of RoomList. 2023-06-01 09:48:53 +02:00
Ivan Enderlin d1708ececf feat(ui): Update according to the last patch. 2023-06-01 09:48:53 +02:00
Ivan Enderlin 4fa38d23d4 feat(sdk): SlidingSync has more non-blocking API.
This patch does several things.

First, `SlidingSync::on_list` is now async, and accept async closures.

Second, `SlidingSync::lists` and `::rooms` are behind an `AsyncRwLock`
instead of a `StdRwLock`. The rest of the patch updates the consequence
of this.
2023-06-01 09:48:53 +02:00
Ivan Enderlin 5f81d829c4 feat(ui): Create an Init state, and add state observer for RoomList. 2023-06-01 09:48:52 +02:00
Ivan Enderlin 92c3003535 !baz 2023-06-01 09:48:52 +02:00
Ivan Enderlin f47c2ba125 !bar 2023-06-01 09:48:52 +02:00
Ivan Enderlin 7706b0096b !foo 2023-06-01 09:48:52 +02:00
Ivan Enderlin 5f58438389 feat(ui): Oh, a roomlist module. 2023-06-01 09:48:51 +02:00
Ivan Enderlin 81d158889a fix(sdk): Replace a panic by a log in Sliding Sync
fix(sdk): Replace a panic by a log in Sliding Sync
2023-06-01 09:47:50 +02:00
Ivan Enderlin 29346b11f3 test(ui): Use FutureExt::now_or_never instead of .await
test(ui): Use `FutureExt::now_or_never` instead of `.await`
2023-06-01 09:41:56 +02:00
Damir Jelić 036d9bf261 Add a test to check that the backup decryption works 2023-06-01 09:31:31 +02:00
Damir Jelić 811369ba28 Fix the argument order when decoding a PkMessage 2023-06-01 09:31:31 +02:00
Ivan Enderlin 06680a284a fix(sdk): Replace a panic by a log in Sliding Sync.
This patch replaces a panic (`Option::expect`) by a `tracing::error`
log.

Imagine the Sliding Sync proxy responds with the following payload:

```json
{
    "pos": …,
    "lists": {
        …: {
            "count": …,
            "ops": [
                {
                    "op": "INSERT",
                    "index": 0,
                    "room_id": !foo:bar.org",
                }
            ]
        }
    },
    "rooms": []
}
```

It's an invalid response, as it will update the room list entry (because
it's present in `lists.$list.ops`), but the room won't be created (it's
absent in the `rooms`).

This situation creates a panic in the patched code. We don't want to
crash if the server replies with invalid data.

Ultimately, we should check that the sync operations are valid regarding
the rooms' updates.
2023-06-01 09:18:20 +02:00
Ivan Enderlin fbe8826159 test(ui): Use FutureExt::now_or_never instead of .await.
This patch uses `FutureExt::now_or_never` so that we don't wait on the
future to be resolved to get a result. If we have a bug in our code and
the test expects a value, the test will hang forever, which is not a
desired behavior. With `now_or_never`, this situation cannot happen.
2023-06-01 08:39:44 +02:00
Ivan Enderlin c82c0e46be feat(sdk): Ensure SlidingSync::sync “drains” its internal channel
feat(sdk): Ensure `SlidingSync::sync` “drains” its internal channel
2023-05-31 18:08:06 +02:00
Ivan Enderlin ae25ad557a Merge branch 'main' into fix-sdk-sliding-sync-drain-internal-channel 2023-05-31 17:34:48 +02:00
Jonas Platte d27ae257ec ffi: Remove unnecessary Deref implementations 2023-05-31 17:32:46 +02:00
Ivan Enderlin f9322c5de8 test(sdk): Ensure SlidingSync starts after it has been stopped manually
test(sdk): Ensure `SlidingSync` starts after it has been stopped manually
2023-05-31 17:30:56 +02:00
Ivan Enderlin d0d23afa5c feat(sdk): Introduce SlidingSync::internal_channel_send_if_possible.
The only reason why a sender can fail to send a message is because there
is no receiver. In the current design of `SlidingSync`, there is only
one receiver active per sync-loop. Thus, calling `SlidingSync::add_list`
may fail if `sync` has not been started. Hence the need for a new
`internal_channel_send_if_possible` method which will never fail: it
will send a message is possible, otherwise it won't do anything.

This turns more functions infallible.
2023-05-31 16:53:03 +02:00
Ivan Enderlin 875f379035 feat(sdk): Change SlidingSync's internal channel to MPMC.
`tokio::sync::broadcast` is interesting as it's possible to
generate receivers per subscribers. Being able to do that allows
us to remove the new for an `AsyncLock` around the receiver in
`SlidingSync::internal_channel`, and it can even remove the need to hold
a receiver entirely!

Another improvement is that new receivers can't receive past messages,
so we no longer need to drain the internal channel.

Another improvement is that the sender' `send` method is synchronous!
Which helps to make many functions no longer `async`.
2023-05-31 16:41:50 +02:00
Ivan Enderlin 9da1a2f48b feat(sdk): Ensure SlidingSync::sync drains its internal channel.
Something weird is happening with ElementX iOS. When
`SlidingSync::stop_sync` is called, the internal message `SyncLoopStop`
has time to be sent in the internal channel, but iOS decides to suspend
the code before the sync-loop processes it. When ElementX decides to
start the sync-loop again, it immediately processes the `SyncLoopStop`
message, and… stops the sync-loop.

This patch ensures that `SlidingSync::sync` drains the internal channel
before starting the sync-loop for real. `tokio::sync::mpsc::Receiver`
type has no `drain` method, so this patch implements its
own logic by calling `try_recv` in a loop, until it returns
`Err(TryRecvError::Empty)`.
2023-05-31 15:29:13 +02:00
Damir Jelić 2fa4410dc6 Bump the vodozemac version 2023-05-31 11:52:47 +02:00
Ivan Enderlin 70525e4612 test(sdk): Ensure SlidingSync starts after it has been stopped manually. 2023-05-31 11:18:55 +02:00
Ivan Enderlin 85b37bfcc4 chore: Remove sliding sync dead tests
chore: Remove sliding sync dead tests
2023-05-31 09:22:05 +02:00
Benjamin Bouvier 4ca8d61c56 feat(ffi): expose set_sync_mode on the sliding sync list
Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-05-30 17:20:05 +02:00
Benjamin Bouvier 623ff6fa83 chore(sliding sync): remove useless mutex around ExtensionsConfig
Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-05-29 17:18:42 +02:00
Benjamin Bouvier 90d7ff764c Remove dead tests
Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-05-29 12:46:50 +02:00
Benjamin Bouvier ce9a079882 feat(sdk): use the builder pattern for the other sliding sync mode too
Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-05-26 15:08:21 +02:00
Benjamin Bouvier fa25e4d9fc sliding sync: Rejigger the range API (#1955)
* feat: introduce SlidingSyncSelectiveModeBuilder
* feat: get rid of `CannotModifyRanges` \o/
* chore: rustfmt
* chore: remove scope in test
* chore: move request generator update to its own mod, gets rid of `set_ranges`
* chore: add comments on the request generator methods
* chore: sink one range_end definition into the match arm that matters
* ffi: remove unused `add_range` method
* test: update incorrect test expectation
* chore: make clippy happy
* address first review comments
* review: don't reuse the ranges field for two things
* chore: use a builder pattern for sliding sync selective mode
* address review comments + CI

Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-05-26 13:40:46 +02:00
Damir Jelić df6d0aaa87 Log the one-time keys we received 2023-05-26 10:34:07 +00:00
Jonas Platte 84917bb59d Fix clippy lints 2023-05-26 12:26:00 +02:00
Jonas Platte ebe97623aa Upgrade Ruma 2023-05-26 12:26:00 +02:00
Damir Jelić def53962e4 Make the withheld reason part of the error message 2023-05-25 16:57:58 +02:00
Damir Jelić 1b2ba33039 Record the sender key when decrypting room events
This used to be the case previously, but it seems that things got lost
when we reshuffled the code here.
2023-05-25 16:57:58 +02:00
Benjamin Bouvier 631b51f43b chore: update sliding sync's README.md too
Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-05-25 16:17:46 +02:00
Benjamin Bouvier 829eb30e7e chore: get rid of SlidingSync::reset_lists as it's unused
Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-05-25 16:17:46 +02:00
Benjamin Bouvier 8d1b3b5b73 chore: get rid of SlidingSyncList::set_ranges, replace with SlidingSyncList::set_range (singular) in testing
Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-05-25 16:17:46 +02:00
Benjamin Bouvier 9c1919ab4c chore: get rid of SlidingSyncListBuilder::set_range and replace it with add_range in tests
Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-05-25 16:17:46 +02:00
Benjamin Bouvier dbd491383f chore: get rid of SlidingSyncListBuilder::reset_ranges
Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-05-25 16:17:46 +02:00
Benjamin Bouvier 40a0459cb9 chore: get rid of SlidingSyncListBuilder::ranges(), replace with add_range
Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-05-25 16:17:46 +02:00
Damir Jelić 8c9a54e6c8 Time out user/device pairs who have invalid one-time keys 2023-05-25 14:52:05 +02:00
Damir Jelić ac816ca1c6 Fix an indentation issue 2023-05-25 14:51:25 +02:00
Damir Jelić 2c696ae210 Fix the deserialization of encrypted m.dummy events. 2023-05-25 14:51:25 +02:00
Jonas Platte 5197e263a0 Revert "bindings: Use native async support for latest_room_message"
This reverts commit 2660e7bcf1.
2023-05-25 13:33:43 +02:00
Benjamin Bouvier 992b6b604b test: address review comments + add basic tests for to-device token
Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-05-25 11:26:32 +02:00
Benjamin Bouvier 9762c63dbc chore: remove Observable wrappers for the position markers
Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-05-25 11:26:32 +02:00
Benjamin Bouvier 0afe616e17 feat: put the to_device_token along the other position markers in sliding sync
Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-05-25 11:26:32 +02:00
Benjamin Bouvier b4c192509b chore: remove unused FFI add_common_extensions
Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-05-25 11:26:32 +02:00
Damir Jelić 5e3a114830 Log the message id when we share a room key 2023-05-24 12:29:15 +02:00
Damir Jelić 2e09bf63a6 Add a message id to our encrypted to-device events 2023-05-24 12:29:15 +02:00
Damir Jelić 19ca9478b7 Clean up some room key forwarding logs 2023-05-24 12:29:15 +02:00
Ivan Enderlin 17f4ba5c9b fix(sdk): Client::sliding_sync doesn't need to be async
fix(sdk): `Client::sliding_sync` doesn't need to be `async`
2023-05-24 12:26:33 +02:00
Ivan Enderlin a2a1b35622 fix(sdk): Client::sliding_sync doesn't need to be async.
The `Client::sliding_sync` method was declared as async. However, it's
not necessary as everything happening here is sync.
2023-05-24 11:56:38 +02:00
Ivan Enderlin b60a317174 feat(sdk): Implement SlidingSync::stop_sync
feat(sdk): Implement `SlidingSync::stop_sync`
2023-05-24 11:52:19 +02:00
Jonas Platte ac106c7059 bindings: Use native async for SessionVerificationController 2023-05-24 11:31:33 +02:00
Jonas Platte 2660e7bcf1 bindings: Use native async support for latest_room_message 2023-05-24 11:31:33 +02:00
Jonas Platte ffc8453c63 bindings: Use async-compat tokio runtime 2023-05-24 11:31:33 +02:00
Jonas Platte 587c5b05b1 Upgrade UniFFI 2023-05-24 11:31:33 +02:00
Ivan Enderlin 728cd5db86 fix(sdk): Restore the size of the SS channel.
Because it doesn't solve any problem, it just postpones it, making the
whole thing more difficult to debug.
2023-05-24 11:02:06 +02:00
Ivan Enderlin 512a5e77cd feat(sdk): Log when messages are sent internally by SlidingSync. 2023-05-24 11:01:42 +02:00
Ivan Enderlin e9bbf366ba chore(sdk): Simplify code. 2023-05-24 09:19:12 +02:00
Ivan Enderlin 849f83adb7 chore(sdk): Remove an allow(unused). 2023-05-24 09:06:32 +02:00
Ivan Enderlin 415778d44d feat(ffi): Implement SlidingSync::stop_sync. 2023-05-24 09:03:03 +02:00
Ivan Enderlin 47922f7f50 test(sdk): Test SlidingSync::stop_sync_loop. 2023-05-24 08:59:28 +02:00
Ivan Enderlin 7bde2cfd4a feat(sdk): Add log in SlidingSync when an internal message is received. 2023-05-24 08:44:51 +02:00
Ivan Enderlin 99bbf2a42b feat(sdk): Implement SlidingSync::stop_sync.
In case it's not obvious to drop the `Stream` returned by
`SlidingSync::sync` immediately to “stop” the sync-loop, one can use the
new `stop_sync` method to do achieve the same result.
2023-05-24 08:42:12 +02:00
Ivan Enderlin b8580b76f7 feat(sdk): Rename SlidingSync::stream to ::sync.
Because it doesn't start a stream, but a sync-loop.
2023-05-24 08:20:29 +02:00
Damir Jelić c042e1e63c Disable automatic-key-forwarding for the matrix-sdk-ffi bindings
Not completely sure why disabling this didn't work the first time. The
feature is now disabled by default in the matrix-sdk-crypto crate.
2023-05-23 16:42:34 +02:00
Damir Jelić 3db90fbe02 Use the new VerificationRequest signalling in the emoji example 2023-05-23 16:10:05 +02:00
Damir Jelić b07718b5d5 Expose the VerificationRequest signalling and states in the main crate 2023-05-23 16:10:05 +02:00
Damir Jelić e9c3aa1a2e Add a state for the VerificationRequest for when a request transitions
The `VerificationRequest` object is used to control the flow of the
verification but only up to a certain point.

Once we start handling of different specific verification flows (i.e.
SAS or QR code verification) the `VerificationRequest` object creates a
child object of the Verification type.

This patch adds a new `VerificationRequestState` variant called
`Transitioned` which holds the child verification object as associated
data.

This makes it much simpler to go through the whole verification flow by
allowing users to just listen to the `VerificationRequest::changes()`
method.
2023-05-23 16:10:05 +02:00
Florian Renaud 2cce236f4d feat(bindings): exposed set_name in Room 2023-05-22 17:58:14 +02:00
Jonas Platte 2f243bce55 Stop unconditionally enabling native-tls from matrix-sdk-ffi 2023-05-22 16:26:40 +02:00
Ivan Enderlin d27754cb61 Replace the libolm backup encryption code with a native Rust version
Replace the libolm backup encryption code with a native Rust version
2023-05-22 14:56:21 +02:00
Ivan Enderlin cc10f995ff feat(sdk): Implement SlidingSyncList::set_sync_mode
feat(sdk): Implement `SlidingSyncList::set_sync_mode`
2023-05-22 14:38:01 +02:00
Benjamin Bouvier befb5dbdb8 chore: add log when exiting the sync loop's stream
Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-05-22 14:13:13 +02:00
Benjamin Bouvier 5c785be7dd fix(sdk): increase the internal channel receiver size up from 8 to 256
We suspect that there might be too many internal messages being pushed, causing a deadlock on the senders' side.
This attempts to increase the value of the buffer to give it more leeway.

Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-05-22 14:13:13 +02:00
Ivan Enderlin 322f5495ac fix(sdk): SlidingSyncListInner::timeline_limit and ranges are no longer observable
fix(sdk): `SlidingSyncListInner::timeline_limit` and `ranges` are no longer observable
2023-05-22 12:05:45 +02:00
Ivan Enderlin 4eee60dc9e chore(sdk): Make Clippy happy. 2023-05-22 11:32:54 +02:00
Ivan Enderlin abf8a50c0d chore(sdk): Make Clippy happy. 2023-05-22 11:24:11 +02:00
Ivan Enderlin e9399eb635 doc(sdk): Do no link to a private function. 2023-05-22 10:54:36 +02:00
Ivan Enderlin 4e00d04611 fix(sdk): SlidingSyncListInner::timeline_limit and ranges are no longer observable.
The `SlidingSyncListInner::timeline_limit` and `::ranges` fields were
observable (behind `eyeball::Observable`). It was actually useless
as those fields were never exposed to the public API, thus it was
impossible to subscribe to them.

This patch cleans up that. `timeline_limit` and `ranges` are no longer
observable.
2023-05-22 10:50:26 +02:00
Ivan Enderlin fee1a50f38 doc(sdk): Improve documentation of next_request. 2023-05-22 09:39:43 +02:00
Ivan Enderlin 6e77804070 feat(sdk): SlidingSyncList::set_sync_mode sends an internal message.
This patch updates `SlidingSyncList::set_sync_mode` to send a
`SyncLoopSkipOverCurrentIteration` internal message to the sync loop.
2023-05-22 09:38:42 +02:00
Ivan Enderlin 82f5768df3 feat(sdk): Rename SlidingSyncInternalMessage variants.
This patch renames the variant to be more explicit about what they do
instead of re-using the “for loop vocabulary”.
2023-05-22 09:37:32 +02:00
Ivan Enderlin 4ee2f2a44b chore(sdk): Run rustfmt. 2023-05-22 08:43:10 +02:00
Ivan Enderlin f37945da13 chore(comment): fix the comment for Error::CannotModifyRanges
chore(comment): fix the comment for `Error::CannotModifyRanges`
2023-05-20 18:05:13 +02:00
Ivan Enderlin 88ebd89937 doc(sdk): Fix a typo.
Co-authored-by: Benjamin Bouvier <public@benj.me>
2023-05-20 17:57:21 +02:00
Ivan Enderlin 2f29664fb8 doc(sdk): Fix a typo.
Co-authored-by: Benjamin Bouvier <public@benj.me>
2023-05-20 17:57:11 +02:00
Benjamin Bouvier da73229e8d chore(comment): fix the comment for Error::CannotModifyRanges
The comment and the check in the code were contradicting each other; the comment was wrong, and the code was right, so there's that.

Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-05-19 16:03:59 +02:00
Damir Jelić 34aed2f939 Replace the libolm backup encryption code with a native Rust version
This patch removes our dependency to libolm completely. This should
allow WASM targets to use the backups_v1 feature of the
matrix-sdk-crypto crate as well.
2023-05-18 10:52:51 +02:00
Ivan Enderlin ff1d784e70 fix(ci): Fix path to matrix-sdk-crypto-js and allow pushd to return an error
fix(ci): Fix path to `matrix-sdk-crypto-js` and allow `pushd` to return an error
2023-05-17 20:18:03 +02:00
Ivan Enderlin 9912a4a6db doc(sdk): Fix a typo. 2023-05-17 20:16:01 +02:00
Ivan Enderlin 7b0336bb29 doc(sdk): Fix a typo. 2023-05-17 20:07:12 +02:00
Ivan Enderlin d86647db77 chore(ci): Give pushd's result a name so that it's not dropped. 2023-05-17 20:00:33 +02:00
Jonas Platte d13d41951f Silence clippy warning from macro-generated code 2023-05-17 17:20:55 +02:00
Jonas Platte f68fd6c7cf Use workspace dependencies for futures-core 2023-05-17 17:20:55 +02:00
Jonas Platte 78838e67c1 Upgrade dependencies 2023-05-17 17:20:55 +02:00
Jonas Platte 59b1fa00df Replace futures dependencies with futures-* dependencies 2023-05-17 17:20:55 +02:00
Jonas Platte 18d12b2f10 crypto: Simplify a test 2023-05-17 17:20:55 +02:00
Jonas Platte a39a6fba51 sdk: Use tokio::sync instead of futures::channel in tests
… for consistency.
2023-05-17 17:20:55 +02:00
Ivan Enderlin fc37f337fb fix(ci): Fix path to matrix-sdk-crypto-js and allow pushd to return an error.
First off, this patch changes `pushd(…)` to `pushd(…)?` so that errors
are propagated.

Second, instead of assuming that all crates live in `crates/`, let's
allow to precise a prefix, like `crates/` or `bindings/` directly in the
“folder” path of `args`.
2023-05-17 17:12:52 +02:00
Ivan Enderlin f01e8dc992 test(sdk): Test SlidingSyncList::set_sync_mode. 2023-05-17 17:10:55 +02:00
Ivan Enderlin 8bb04ed40b test(sdk): Use the Rust inclusive range syntax for ranges. 2023-05-17 17:10:55 +02:00
Ivan Enderlin d99957d370 feat(sdk): Implement SlidingSyncList::set_sync_mode.
Changing the sync-mode of a list on-the-fly is necessary to optimise the
new `RoomList` API. For example, we can start with a list in a selective
mode, a range of `0..=50` and a `timeline_limit=0` to fetch the
beginning of the room list, and then _change_ the sync-mode to growing
to continue to sync the room list in the background.

Today, this is done with 2 lists and a merge of the lists, but
(i) this is error-prone, (ii) this is not optimal. Thank to
`SlidingSyncList::set_sync_mode`, merging lists is no more necessary,
thus removing a class of bugs in client's code.
2023-05-17 17:10:55 +02:00
Ivan Enderlin 51e6e80b3b feat(sdk): SlidingSyncMode has richer variants
feat(sdk): `SlidingSyncMode` has richer variants
2023-05-17 17:10:26 +02:00
Ivan Enderlin 6dde00ebcf chore(sdk): Simplify code with a matches!. 2023-05-17 16:50:00 +02:00
Ivan Enderlin 74430e127f doc(sdk): Do not use helper constructors in the documentation. 2023-05-17 16:50:00 +02:00
Ivan Enderlin 1c175df6b3 chore(sdk): Move From impl on SSListRequestGenerator as proper constructor. 2023-05-17 16:37:11 +02:00
Ivan Enderlin ddc8d915cb doc(sdk): Fix syntax error. 2023-05-17 16:34:12 +02:00
Ivan Enderlin f8e12f6aaf doc(sdk): Update documentation according to last commits. 2023-05-17 15:42:30 +02:00
Ivan Enderlin 63feec1433 test(sdk): Test impl From<SlidingSyncMode> for …RequestGenerator`. 2023-05-17 15:32:35 +02:00
Ivan Enderlin 1a60983e8f feat(ffi): Add SlidingSyncListBuilder::sync_mode_*.
This patch replaces `sync_mode` on `SlidingSyncListBuilder` by
`sync_mode_selective`, `sync_mode_paging` and `sync_mode_growing`, which
removes the need to use `SlidingSyncMode` directly.

This patch also removes `batch_size`, `room_limit` and `no_room_limit`
as it's now arguments of `sync_mode_paging` and `sync_mode_growing`.
2023-05-17 15:18:51 +02:00
Ivan Enderlin 41c09a5ec5 feat(sdk): SlidingSyncMode has richer variants.
`SlidingSyncMode` was previously declared as:

```rust
enum SlidingSyncMode {
    Selective,
    Paging,
    Growing,
}
```

Now, the new declaration is:

```rust
enum SlidingSyncMode {
    Selective,
    Paging {
        batch_size: u32,
        maximum_number_of_rooms_to_fetch: Option<u32>,
    },
    Growing {
        batch_size: u32,
        maximum_number_of_rooms_to_fetch: Option<u32>,
    }
}
```

First off, it helps to remove the `full_sync_batch_size` and
`full_sync_maximum_number_of_rooms_to_fetch` methods and fields from
`SlidingSyncListBuilder`. It was containing default values in case of.
That was useless and needed to be fixed. Also, calling a `full_sync_*`
method with the `Selective` mode had no effect, which could disturb
the user. Well, now everything is clean on that front.

Second, `SlidingSyncListRequestGenerator` no longer has constructors,
but a `From<SlidingSyncMode>` implementation. However, the constructors
now live in `SlidingSyncMode` with `new_selective`, `new_paging` and
`new_growing` methods which are helpers. All in all, it makes creating a
`SlidingSyncListRequestGeneator` simpler: just call `sync_mode.into()`
and boom.

Finally, this patch removes the `default_with_fullsync` list builder
helper, which makes no sense at all.
2023-05-17 14:49:55 +02:00
Jonas Platte 12a02f0458 Make examples section name consistent in docs 2023-05-17 14:45:24 +02:00
Ivan Enderlin c618b03f12 feat(sdk): SlidingSync::add_list has an immediate effect
feat(sdk): `SlidingSync::add_list` has an immediate effect
2023-05-17 13:56:35 +02:00
Jonas Platte f12e827a67 Don't use block_on in no_run doctests
… and clean up formatting around the affected ones.
2023-05-17 13:49:14 +02:00
Ivan Enderlin 64cea091f9 chore(sdk): Clean up test code. 2023-05-17 13:23:21 +02:00
Ivan Enderlin 5ce9790c94 doc(sdk): Fix rebase missing doc. 2023-05-17 13:20:31 +02:00
Ivan Enderlin 39aba1dd95 fix(sdk): Rename SlidingSyncSubscribeResult to SlidingSyncAddTimelineListenerResult. 2023-05-17 13:13:17 +02:00
Ivan Enderlin b85b585bd7 feat(ffi): Make some methods async.
`SlidingSync::subscribe`, `::unsubscribe` and `::add_list` are
now async. `subscribe` has been renamed to `subscribe_to_room` and
`unsubscribe` to `unsubscribe_from_room`.

`SlidingSyncRoom::subscribe_and_add_timeline_listener` has
been removed, and replaced by a new `::subscribe_to_room` and
`::unsubscribe_from_room` methods (the `::add_timeline_listener` method
already exists).

`TaskHandle::finalizer` is no longer necessary, thus this code has been
cleaned up.
2023-05-17 13:13:17 +02:00
Ivan Enderlin 63257e6226 fix(sdk): Remove room unsubscriptions once the server has received them
fix(sdk): Remove room unsubscriptions once the server has received them
2023-05-17 11:59:16 +02:00
Ivan Enderlin 53c20fcf1a feat(sdk): SlidingSync::add_list has an immediate effect.
`SlidingSync::add_list` sends `ContinueSyncLoop` on the internal channel.
2023-05-17 11:35:53 +02:00
Damir Jelić 1510576ce1 Expose the git description and commit hash in the crypto-ffi bindings
Co-authored-by: Jonas Platte <jplatte@matrix.org>
2023-05-17 09:31:52 +00:00
Ivan Enderlin 501b990248 chore(sdk): Rename SlidingSync::unsubscribe_to_room to …_from_room. 2023-05-17 11:29:26 +02:00
Valere 405db06495 refactor(crypto): get_or_load never returns crypto error 2023-05-17 09:20:37 +00:00
Jonas Platte be7e162ce1 Restore timeline integration tests
The directory had the wrong name, so it wasn't detected by Cargo.
2023-05-17 11:14:16 +02:00
Ivan Enderlin b7374a78e9 doc(sdk): Update documentation for SlidingSync::(un)subscribe_to_room. 2023-05-17 11:10:03 +02:00
Ivan Enderlin d8a9408efe fix(sdk): Remove room unsubscriptions once the server has received them.
This bug has been found by @bnjbvr, all the credits go to him. I've just
added some comments around his code.

Prior to this patch, the room unsubscription buffer
(`SlidingSync::room_unsubscriptions`) was reset before the request was
sent. So if something went wrong, the next request would not include the
room unsubscriptions.

This patch updates this behavior. First, it replaces `Vec` by `HashSet`
to avoid a O(n^2) look up.

Second, a copy of room unsubscriptions used by the request is kept, so
that it can be used to cherry-pick which room unsubscription to remove
from the buffer once a response from the server is received. It's
important to not clear the entire room unsubscriptions buffer as more
unsubscriptions could have been inserted meanwhile.
2023-05-17 10:14:34 +02:00
Ivan Enderlin 9b7122768f chore(sdk): Rename SlidingSync room subscriptions and unsubscriptions API.
Notably, this patch renames `SlidingSync::subscribe` and `::unsubscribe`
to `subscribe_to_room` and `unsubscribe_to_room`.
2023-05-17 10:01:55 +02:00
Jonas Platte 5fa2fff8e5 ui: Re-export TLS features 2023-05-17 09:58:31 +02:00
Jonas Platte 31e32c307f ui: Add missing copyright headers 2023-05-17 09:58:31 +02:00
Jonas Platte d620f83e0d Enable syntax highlighting in sliding_sync README 2023-05-17 09:58:31 +02:00
Jonas Platte cfc8effa66 Move timeline API into a new crate
… aimed at interactive user interfaces.
2023-05-17 09:58:31 +02:00
Jonas Platte 91d97cd588 sdk: Re-export matrix_sdk_base::crypto 2023-05-17 09:58:31 +02:00
Jonas Platte 910022bca6 sdk: Make useful push related methods public 2023-05-17 09:58:31 +02:00
Jonas Platte a6fe0bb34d sdk: Merge identical ensure_members, sync_members methods 2023-05-17 09:58:31 +02:00
Damir Jelić 0144826884 crypto: Log if and which fallback key got removed 2023-05-16 16:25:20 +02:00
Damir Jelić 35a0f3af25 crypto: Improve some logs around Olm decryption and encryption 2023-05-16 16:25:20 +02:00
Damir Jelić 9f1ec9ac3a crypto: Log the result of one-time key generation 2023-05-16 16:25:20 +02:00
Jonas Platte c796302a98 ffi: Fix typo in variant name 2023-05-16 11:32:15 +02:00
Richard van der Hoff 1c8d2a1225 Merge pull request #1923 from matrix-org/release-matrix-sdk-crypto-js-0.1.0-alpha.9
matrix-sdk-crypto-js v0.1.0-alpha.9
2023-05-15 19:50:53 +01:00
Ivan Enderlin df8242a23e test(sdk): New Sliding Sync integration test suite for a mocked server
test(sdk): New Sliding Sync integration test suite for a mocked server
2023-05-15 20:30:23 +02:00
Ivan Enderlin 5b55145a1c Merge branch 'main' into test-sliding-sync-room-timeline 2023-05-15 20:06:42 +02:00
Ivan Enderlin d24a3922a0 test(sdk): Avoid ambiguity in pos. 2023-05-15 20:03:02 +02:00
Richard van der Hoff 6c0afae0f4 Merge remote-tracking branch 'origin/main' into release-matrix-sdk-crypto-js-0.1.0-alpha.9
Release `crypto-js` / Publish 🕸 [m]-crypto-js (push) Failing after 36s
2023-05-15 18:59:52 +01:00
Richard van der Hoff 923d425585 crypto-js: expose a constructor for SigningKeysUploadRequest (#1925)
... to help with testing.
2023-05-15 18:58:38 +01:00
Richard van der Hoff 89bf7f27f3 fix typo 2023-05-15 18:42:58 +01:00
Benjamin Bouvier 58dbe1e252 feat: add add_cached_list to SlidingSyncBuilder and SlidingSync (#1876)
This has slightly drifted from the initial design I thought about in the issue.

Instead of having `build()` be fallible and mutably borrow some substate (namely `BTreeMap<OwnedRoomId, SlidingSyncRoom>`) from `SlidingSync` (that may or may not already exist), I've introduced a new `add_cached_list` method on `SlidingSync` and `SlidingSyncBuilder`. This method hides all the underlying machinery, and injects the room data read from the list cache into the sliding sync room map.

In particular, with these changes:

- any list added with `add_list` **won't** be loaded from/written to the cache storage,
- any list added with `add_cached_list` will be cached, and an attempt to reload it from the cache will be done during this call (hence `async` + `Result`).
- `SlidingSyncBuilder::build()` now only fetches the `SlidingSync` data from the cache (assuming the storage key has been defined), not that of the lists anymore.

Fixes #1737.

Signed-off-by: Benjamin Bouvier <public@benj.me>
Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
2023-05-15 16:17:45 +00:00
Benjamin Bouvier c404e378a2 test: sliding sync list fields reloaded from the cache are observable in streams
Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-05-15 17:46:04 +02:00
Jonas Platte 549edeb73b sdk: Instrument sliding response handling task 2023-05-15 17:24:02 +02:00
Benjamin Bouvier b6302aca5c bench: add benchmarks for encrypted stores too
Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-05-15 17:11:50 +02:00
Benjamin Bouvier 3928259bb5 bench: add restore session benchmark
Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-05-15 17:11:50 +02:00
Richard van der Hoff 3049328078 matrix-sdk-crypto-js v0.1.0-alpha.9 2023-05-15 15:07:14 +01:00
Richard van der Hoff 3df473a56d update CHANGELOG 2023-05-15 15:07:03 +01:00
Ivan Enderlin 89384775ff chore(cargo): Update lockfile. 2023-05-15 16:04:17 +02:00
Ivan Enderlin d2e9347be4 test(sdk): Put sliding_sync behind its feature flag. 2023-05-15 16:03:54 +02:00
Richard van der Hoff 18954a6ba5 crypto-js: fix body of SignatureUploadRequest (#1917)
Currently, the `body` of a `SignatureUploadRequest` includes a spurious
`signed_keys: {...}` property in which the actual content is wrapped. Fix that.
2023-05-15 15:02:01 +01:00
Chris Smith 3449dad89b feat(bindings): expose getting member by id
Allow for retrieving a single room member by their ID.
2023-05-15 15:26:45 +02:00
Ivan Enderlin 07267767fc test(sdk): New Sliding Sync integration test suite for a mocked server. 2023-05-15 15:19:45 +02:00
Ivan Enderlin dca7800a88 chore(cargo): uuid is no longer needed. 2023-05-15 15:19:37 +02:00
Ivan Enderlin caaeb8130d feat(sdk): Remove txn_id from requests sent by SlidingSync.
We were using `txn_id` as a way to identify the running stream. Now
things are cleaner so we can remove this “debug tool”. This class of
problems should not appear anymore. For the record, the biggest problem
was the following: It was possible to start multiple `stream`s at the
same time, and thus a stream could receive a response sent by another
stream. Since we no longer need to restart SlidingSync anymore (i.e. no
need to start multiple `stream`s at the same time), this problem should
not happen.
2023-05-15 15:16:40 +02:00
Ivan Enderlin 94d5d5187f test(sdk): Rename a test about SlidingSyncRoom. 2023-05-15 15:14:58 +02:00
Ivan Enderlin d973ac1e93 doc(sdk): Add missing documentation. 2023-05-15 15:14:23 +02:00
Ivan Enderlin 6185b4050a feat(sdk): Process SlidingSync response inside handle_response.
Prior to this patch, the `v4::Response`, aka the SlidingSync response,
was processed by the client and transformed into a `SyncResponse` into
`sync_once` before being passed to `handle_response`. Now it's done in
`handle_response`.

This is not mandatory _now_, but it will be helpful in a close future.
2023-05-15 15:12:20 +02:00
Jonas Platte ee87ec7b46 Improve logs for pagination 2023-05-15 13:06:30 +02:00
Jonas Platte ab7aa68c5b Fix lints 2023-05-15 13:06:30 +02:00
Benjamin Bouvier fc8dd5a1cc Update crates/matrix-sdk/src/room/timeline/inner.rs
Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
2023-05-15 10:29:27 +02:00
Benjamin Bouvier c0f8e31e79 chore: add tracing spans for code in TimelineBuilder suspected to be slow
Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-05-15 10:29:27 +02:00
Stefan Ceriu 7ff125dae1 chore(xtask): clean apple generated bindings directory before building new ones 2023-05-12 16:27:14 +02:00
Stefan Ceriu 593c99d377 ffi: add method for getting the build time git short sha value (#1909) 2023-05-11 18:32:09 +02:00
Ivan Enderlin 9d0c40c207 feat(sdk): Clean up and test SlidingSyncRoom
feat(sdk): Clean up and test `SlidingSyncRoom`
2023-05-11 18:03:30 +02:00
Jonas Platte 870d6d6ca3 Make timeline event Debug impls less verbose 2023-05-11 18:00:17 +02:00
Jonas Platte 1d2e45191d Make Debug impl for RequestConfig less verbose
… for the common case, and more verbose for some uncommon options that
were just never printed before.
2023-05-11 18:00:17 +02:00
Jonas Platte 30eee70e9d Add DebugStructExt helper for writing less verbose Debug impls 2023-05-11 18:00:17 +02:00
Ivan Enderlin f23fd1809b Merge branch 'main' into feat-sliding-sync-room 2023-05-11 17:47:08 +02:00
Ivan Enderlin ab96a696ae test(sdk): Add test cases for SlidingSyncRoom::update.
Test when a `SlidingSyncRoom` has received a non-empty update, and then
receives an empty-update.
2023-05-11 17:45:14 +02:00
Benjamin Bouvier 149950cc29 sliding sync: Use RangeInclusive<u32> instead of raw start/end UInt values (#1877)
* chore: use RangeInclusive instead of raw start/end integers for ranges in sliding sync
* chore: have timeline_limit use a u32 instead of a Ruma UInt
* chore: Remove all the `Into<u32>` generics on timeline_limit and ranges APIs
* chore: introduce a `Bound` type alias for u32

Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-05-11 14:27:46 +02:00
Jonas Platte a84960787d Fix remaining sync response Debug event content leaks
… for real this time.
2023-05-11 13:50:20 +02:00
Jonas Platte dab4cdd863 ffi: Add MediaSource::{from_json, to_json} 2023-05-11 11:06:06 +00:00
Benjamin Bouvier d6100915df bench: add sled back to the crypto benchmarks
Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-05-11 12:31:58 +02:00
Benjamin Bouvier 5f228f408e bench: set up a Tokio context when dropping the sqlite store
Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-05-11 12:31:58 +02:00
Kévin Commaille 93f5562343 Only send verifications requests to devices that are cross-signed (#1884)
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-05-11 11:59:59 +02:00
Mauro Romito 18971e8b11 fix for notification item to get sender in invited rooms 2023-05-11 10:49:42 +02:00
Ivan Enderlin 68337d58f7 chore(ffi): Update according to last commit. 2023-05-11 09:18:43 +02:00
Ivan Enderlin 873bc6b2a4 Just to trigger the CI, after Github issues. 2023-05-11 09:01:32 +02:00
Jonas Platte 9842645377 Fix struct name for DebugNotification output 2023-05-10 23:42:32 +02:00
Jonas Platte 176934e359 Fix debug output for raw events
It was looking for an "event_type" field rather than just "type".
The code was also more complex than necessary.
2023-05-10 21:50:12 +02:00
Ivan Enderlin 75f3bbcf63 chore(ffi): Update according to last commit. 2023-05-10 15:57:43 +02:00
Ivan Enderlin 02cfee68c4 feat(sdk): SlidingSyncRoom is cheap to clone.
This patch changes `SlidingSyncRoom` to move all its fields inside an
inner type `SlidingSyncRoom` behind an `Arc`, so that cloning is cheap,
and all clones are sharing the same state.
2023-05-10 15:53:21 +02:00
Ivan Enderlin 09bb0fcdd3 test(sdk): Testing FrozenSlidingSyncRoom receives a subset of the timeline queue. 2023-05-10 14:42:00 +02:00
Ivan Enderlin 54bc774d62 test(sdk): Clarify a test with json! instead of a string. 2023-05-10 14:15:07 +02:00
Ivan Enderlin e2af4ccfe6 fix(ffi): Fix types. 2023-05-10 14:01:29 +02:00
Ivan Enderlin 1a50afe167 feat(sdk): Rethink the SlidingSyncList::state after a reset
feat(sdk): Rethink the `SlidingSyncList::state` after a reset
2023-05-10 13:56:57 +02:00
Ivan Enderlin 3a25608a6e feat(sdk): Rethink the SlidingSyncList::state after a reset.
A `SlidingSyncList` has a state, which can be either `NotLoaded`,
`Preloaded`, `PartiallyLoaded`, or `FullyLoaded`.

A `SlidingSyncList` can be reset, either manually when
`SlidingSyncList::reset` is called, or when a range is updated for
example.

Resetting a list is modifying its state. Prior to this patch, the state
was set to `NotLoaded`. However, it's not entirely true. This patch
updates this behavior to the following rules:

* When the state is `NotLoaded`, it's kept at this state as nothing has
  happened yet,
* When the state is `Preloaded`, the list is restored from the cache,
  but nothing has happened yet too, so it's kept at this state,
* When the state is `PartiallyLoaded` or `FullyLoaded`, it means some
  (or all) updates have been done, so the new state is `PartiallyLoaded`
  after the reset.

The list' state is used mostly by the client to know whether a loader
should be prompted to the users. The ranges are modified when the
users scroll inside the room list for example: scrolling in the room
list doesn't imply the state should go to `NotLoaded`. Some data
have potentially be loaded, so changing the ranges should result in a
`PartiallyLoaded` state. It seems more logical once explained like this.
2023-05-10 13:31:52 +02:00
Ivan Enderlin 22b2e54aca test(sdk): Test SlidingSyncRoom::update, esp. the timeline_queue. 2023-05-10 13:17:09 +02:00
Ivan Enderlin 7c21f8851c test(sdk): Test SlidingSyncRoom::state. 2023-05-10 09:35:45 +02:00
Ivan Enderlin c00b2db51b test(sdk): Test SlidingSyncRoom::prev_batch. 2023-05-10 09:35:45 +02:00
Ivan Enderlin e7e66dc17e test(sdk): Test SlidingSyncRoom::required_state. 2023-05-10 09:35:45 +02:00
Ivan Enderlin d688918036 feat(sdk): Don't update invite_state in SlidingSyncRoom.
`invite_state` is managed when the Sliding Sync response is processed/
handled by the `Client`. Inside `SlidingSyncRoom`, it's not necessary to
maintain it.
2023-05-10 09:35:45 +02:00
Ivan Enderlin bafcaa9c85 test(sdk): Test SlidingSyncRoom::*unread_notifications. 2023-05-10 09:35:45 +02:00
Ivan Enderlin 379c9d6520 test(sdk): Test SlidingSyncRoom::is_dm and ::is_initial_response. 2023-05-10 09:35:45 +02:00
Ivan Enderlin 04feb7a2a2 test(sdk): Test SlidingSyncRoom::name. 2023-05-10 09:35:45 +02:00
Ivan Enderlin de373c07a6 feat(sdk): Add a constant to represent the max number of timeline events to put in the cache.
This patch creates a constant to represent the
maximum number of timeline event to put in the cache:
`NUMBER_OF_TIMELINE_EVENTS_TO_KEEP_FOR_THE_CACHE`. Verbose, but easily
understandable.

This patch also renames a few variables.
2023-05-10 09:35:45 +02:00
Ivan Enderlin 39590c4e07 chore(sdk): Re-order methods on SlidingSyncRoom. 2023-05-10 09:35:45 +02:00
Ivan Enderlin 3a0ebbd271 doc(sdk): Update documentation. 2023-05-10 09:35:45 +02:00
Ivan Enderlin 32ef2f7c61 feat(sdk): Simplify SlidingSyncRoom::timeline_queue.
This patch simplifies `SlidingSyncRoom::timeline_queue` from

```rust
Arc<RwLock<ObservableVector<SyncTimelineEvent>>>
```

to

```rust
Vector<SyncTimelineEvent>
```

First, we don't need to be observable. It's never observed since
it's private, and even privately, it's never observed, there is no
subscriber.

Second, no lock is required as updates happen synchronously.

Third, `Arc` is not necessary. We want each clone of `SlidingSyncRoom`
to not share any state across them.

Finally, this patch simplifies the iterator + `.push_back` by a simple
`.extend` to update the `timeline_queue`. Behind the scene, `impl Extend
for Vector` actually does an iterate + `.push_back`; let's keep our code
simple though.
2023-05-10 09:35:45 +02:00
Ivan Enderlin 6afca5367d feat(sdk): Replace SlidingSyncRoom::is_cold by a real state enum.
`SlidingSyncRoom::is_cold` is not well-named. This patch introduces an
enum, named `SlidingSyncRoomState` which contains more detailed state:
`NotLoaded`, `Preloaded`, and `Loaded`.

The use of `AtomicBool` is also removed. Thus, we no longer need an
`Arc` for the state, which makes `Clone` more obvious: the state is not
shared across clones anymore.
2023-05-10 09:35:45 +02:00
Ivan Enderlin ef9bf87d89 chore(sdk): Write imports at the correct place. 2023-05-10 09:35:41 +02:00
Ivan Enderlin 349c7c3f68 feat(sdk): Remove SlidingSyncRoom::prev_batch.
A `SlidingSyncRoom` receives an Ruma
`api::client::sync::sync_events::v4:SlidingSyncRoom`. This value is
stored in the `SlidingSyncRoom::inner` field. From here, some getters
like `name()`, `is_dm()` etc. are using the `inner` field to compute a
result. There was one exception though: `prev_batch`. This value is part
of `v4::SlidingSyncRoom` but it was copied and updated in its own field:
`SlidingSyncRoom::prev_batch`.

I was wondering why. Turns out, there is no reason. Its getter
`prev_batch()` is public, but it's not used by the FFI bindings, so
basically nobody uses it (as this project is experimental as the time of
writing, we know our users).

This patch removes the `SlidingSyncRoom::prev_batch` field.

This patch also removes the `SlidingSyncRoom::prev_batch()` getter.

This patch finally removes the `FrozenSlidingSyncRoom::prev_batch` field
too.
2023-05-10 09:34:39 +02:00
Ivan Enderlin cb2bb84d88 fix(sdk): Remove SlidingSyncRoom::is_loading_more.
First, this field is not used by ElementX.

Second, this field is never updated, so it always returns `false`, which
seems… buggy and useless.
2023-05-10 09:34:38 +02:00
Ivan Enderlin 4132571270 doc(sdk): Write documentation for SlidingSyncRoom. 2023-05-10 09:34:38 +02:00
Ivan Enderlin 0038a0389a chore(sdk): Create one block for rooms, one block for lists.
This patch moves the code into dedicated blocks: one for updating the
rooms, one for updating the lists.
2023-05-10 09:34:27 +02:00
Ivan Enderlin 3e6dd1cecb feat(sdk): Don't remove and re-insert a room when it exists.
Prior to this patch, to check a room exists, it was removed from the
collection, then re-added if it exists. Instead of doing this `remove`
+ `insert` dance, we can simply use `get_mut`, which also returns an
`Option`. This patch does that, in addition to rewrite the code to use a
`match` instead of a `if` + `else`.
2023-05-10 09:21:20 +02:00
Mauro 6eeee8ee53 ffi: Expose EventTimelineItem::read_receipts and the NotificationItem#room_canonical_alias 2023-05-09 15:26:07 +00:00
Jonas Platte 2de786c516 Rename fetch_event_details to fetch_details_for_event 2023-05-09 17:25:39 +02:00
Jonas Platte 159b999485 Update call_event_handlers span to default level of info 2023-05-09 16:53:17 +02:00
Jonas Platte b6453772c3 Fix remaining sync response Debug event content leaks 2023-05-09 16:51:08 +02:00
Jonas Platte 0aa1f599c5 common: Make debug module public
… and remove re-exports of its contents from crate root.
2023-05-09 16:51:08 +02:00
Jonas Platte 1f01555e4e sdk: Add more logging and a new branch to fetch_in_reply_to_details 2023-05-09 16:26:52 +02:00
Jonas Platte c9d35a8fe5 sdk: Clean up spans for sliding sync_once 2023-05-09 12:49:43 +02:00
Benjamin Bouvier b257d0dacd chore: add the --workspace flag back in the documentation CI task
Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-05-09 10:21:48 +02:00
Benjamin Bouvier 1aff90a96f chore: fix doc comments in code and READMEs
Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-05-09 10:21:48 +02:00
Jonas Platte 1380e9c4ec Inline sync response structs with a single field 2023-05-09 10:08:34 +02:00
Jonas Platte 40c0f0896e Add some missing copyright headers 2023-05-09 10:08:34 +02:00
Jonas Platte aa3b2d4698 base: Don't log raw event for notifications 2023-05-09 10:08:34 +02:00
Jonas Platte 935dc6ec41 base: Remove presence events from debug output
We shouldn't be logging raw events, and there's not really a useful
subset we could include.
2023-05-09 10:08:34 +02:00
Jonas Platte ae4518c1a7 base: Remove unused Deserialize, Serialize impls 2023-05-09 10:08:34 +02:00
Jonas Platte 2d1f514a13 Box fields to reduce stack size of structs 2023-05-08 18:47:01 +02:00
Jonas Platte ce3c818156 Box futures to reduce composed future's sizes 2023-05-08 18:47:01 +02:00
Jonas Platte 1bc99a62a5 Make Store::save_changes non-lazy 2023-05-08 18:47:01 +02:00
Jonas Platte 3a74e8647b Reduce amount of local variables before .await in async fn 2023-05-08 18:47:01 +02:00
Jonas Platte c3d7a0704a A little bit of cleanup 2023-05-08 18:47:01 +02:00
Jonas Platte a8fb54ee67 Replace qualified name with use 2023-05-08 18:47:01 +02:00
Jonas Platte c5decd2294 crypto: Pass AnyToDeviceEventContent by reference
… in a few places where it doesn't need to be moved.
2023-05-08 18:47:01 +02:00
Jonas Platte 9c4cce5fd0 crypto: Clean up OlmMachine::with_store
- Remove an unnecessary else {}
- Reorder logging instructions
2023-05-08 18:47:01 +02:00
Jonas Platte 37ed3d0a59 sdk: Don't skip event reordering when re-receiving redacted event 2023-05-08 18:12:53 +02:00
Jonas Platte 3013c911fd sdk: Fix log message 2023-05-08 18:12:53 +02:00
Alfonso Grillo 7ac6ebfb7f Add invited and joined counts 2023-05-08 18:12:12 +02:00
Ivan Enderlin 43b28e6087 feat(sdk): Remove the need to “restart” SlidingSync
feat(sdk): Remove the need to “restart” `SlidingSync`
2023-05-08 17:24:36 +02:00
Ivan Enderlin 6c8a19cf01 chore: Make Clippy happy. 2023-05-08 16:58:00 +02:00
Ivan Enderlin bfcedcd49c feat(sdk): SlidingSync::*subscribe will cancel in-flight requests.
`SlidingSync::subscribe` and `SlidingSync::unsubscribe` will cancel in-
flight requests, i.e. the `SlidingSyncInternalMessage::ContinueSyncLoop`
will be sent in the internal channel, just like what `SlidingSyncList`s
already do when a parameter is changed.
2023-05-08 16:44:49 +02:00
Ivan Enderlin 748ae86a88 feat(sdk): Cloning SlidingSyncListBuilder clones the once_built closure. 2023-05-08 15:24:58 +02:00
Ivan Enderlin cfa2f1d049 chore: Make Clippy happy. 2023-05-08 14:20:18 +02:00
Ivan Enderlin 87f481ce7d !fixup 2023-05-08 14:17:39 +02:00
Ivan Enderlin 281944696a Merge branch 'main' into feat-sdk-sliding-sync-cancellation-token 2023-05-08 14:11:20 +02:00
Ivan Enderlin 673d51a9d9 test(sdk): Test SlidingSyncListBuilder::once_built. 2023-05-08 14:10:27 +02:00
Kévin Commaille f92c3649e9 ffi: Use SQLite state store
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-05-08 12:11:10 +02:00
Kévin Commaille c9fde8cf89 sdk: Add bundled-sqlite Cargo feature
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-05-08 12:11:10 +02:00
Kévin Commaille 991a42d8d6 sled: Add docsrs feature for docs generation
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-05-08 12:11:10 +02:00
Kévin Commaille d7e47501e3 benchmarks: Replace sled with SQLite
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-05-08 12:11:10 +02:00
Kévin Commaille ea826a257d sdk: Replace Sled with SQLite as defaut store
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-05-08 12:11:10 +02:00
Kévin Commaille 09e446b1d5 sqlite: Fix doc error
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-05-08 12:11:10 +02:00
Kévin Commaille 6bae0793f9 codecov: Add SQLite store as default crate
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-05-08 12:11:10 +02:00
Jonas Platte 32fafe7be3 Pin rust nightly version
Works around https://github.com/rust-lang/rust/issues/111320.
2023-05-08 10:44:14 +02:00
Ivan Enderlin 0dab71e94b fix(sdk): Fix previous merge. 2023-05-08 10:16:03 +02:00
Ivan Enderlin 150df1d6ce fix(sdk): Fix previous merge. 2023-05-08 10:07:32 +02:00
Ivan Enderlin cdb992e3b2 Merge branch 'main' into feat-sdk-sliding-sync-cancellation-token 2023-05-08 09:55:02 +02:00
Kévin Commaille 69c8b9f049 sdk: Add method to check if device is verified with cross-signing
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-05-06 20:06:40 +02:00
Kévin Commaille 2c3664c2b3 sdk: Document when a created room is set as direct
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-05-06 19:50:42 +02:00
Jonas Platte 33c84b9ffd crypto: Reduce stack size of OlmMachine 2023-05-05 14:24:44 +02:00
Jonas Platte e5375a475e crypto: Reduce stack size of Store
… and make it cheaper to clone.

Reduces the stack size of OlmMachine from 3632 bytes to 832 bytes.
2023-05-05 14:24:44 +02:00
Jonas Platte 794ab8bc9f crypto: Borrow InboundGroupSession for async fn's that don't need to own
Reduces the size of the returned futures.
2023-05-05 12:39:50 +02:00
Jonas Platte 70c2cf6fe4 sdk: Reduce size of futures in http_client 2023-05-05 12:39:50 +02:00
Jonas Platte 88580d95bf Consistently use Ruma's Owned*Id types
… for simplicity; instead of `Arc<*Id>`.
2023-05-05 12:34:15 +02:00
Mauro b9cc0b5249 ffi: Add Client::get_notification_item
… and remove NotificationService.
2023-05-05 11:27:56 +02:00
Jonas Platte 848de833cc sdk: Fill in replied-to event from timeline items when available 2023-05-05 10:54:01 +02:00
Jonas Platte 10d441f580 sdk: Log redactions of already-redacted events 2023-05-05 10:18:13 +02:00
Marcel 211690ab44 Add missing const to make epilogue.js work in ECMAScript Module compatibility mode
Signed-off-by: Marcel Radzio <mtrnord [AT] nordgedanken.dev>
2023-05-05 10:17:36 +02:00
Jonas Platte c6c5e7fca6 Add CODEOWNERS file for automatic review requests 2023-05-04 16:41:04 +02:00
Ivan Enderlin a91cd93a77 Merge pull request #1860 from bnjbvr/make-builder-build-infallible
Make `SlidingSyncListBuilder::build` infallible
2023-05-04 16:00:40 +02:00
Benjamin Bouvier e05f8001cf Mandate a Client when creating a SlidingSyncBuilder
Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-05-04 15:42:35 +02:00
Benjamin Bouvier fd480b3a8d review: remove useless Result in FFI layer too (thanks hywan!)
Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-05-04 15:42:35 +02:00
Benjamin Bouvier 0962b03a75 Get rid of the name() function builders?
Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-05-04 15:42:35 +02:00
Benjamin Bouvier 3e811d5246 Make SlidingSyncListBuilder::build infallible by mandating a name in ctor
Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-05-04 15:42:35 +02:00
Jonas Platte 3eaacaba55 sdk: Add / update copyright headers 2023-05-04 14:21:24 +02:00
Jonas Platte c5d7022272 sdk: Add a redaction test
including a check that we discard the original event if it's somehow
received again after the redaction.
2023-05-04 14:21:24 +02:00
Jonas Platte 443e729f5b sdk: Fix redaction regression 2023-05-04 14:21:24 +02:00
Jonas Platte 749b57f30a sdk: Fix logs around redactions
No need to log redaction event ID as it's already part of the span.
2023-05-04 14:21:24 +02:00
Jonas Platte 18a0c836af sdk: Move timeline redaction test to new file 2023-05-04 14:21:24 +02:00
Jonas Platte 878ab7f0e3 sdk: Don't add original form of redacted events to the timeline
If the redaction already happened server-side, it is a bug for the
server to even still have access to the non-redacted form.
We don't accept the server data in this case, and also log a warning.
2023-05-04 12:30:19 +02:00
Benjamin Bouvier 2d2874f3c0 Remove unused SlidingSyncList::new_builder
Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-05-04 11:40:26 +02:00
Ivan Enderlin 769fd9cad6 Merge pull request #1844 from matrix-org/rav/signing_keys_upload_response
crypto-js: extend `mark_request_as_sent` to accept SigningKeysUploadResponses
2023-05-04 10:34:27 +02:00
Mauro 709bea839e ffi: Expose active_members_count 2023-05-04 10:31:36 +02:00
Mauro a0cebfcba2 ffi: Fix is_noisy calculation 2023-05-04 09:13:33 +02:00
Richard van der Hoff 5c9fdc51f6 fix lint 2023-05-03 14:36:39 +01:00
Richard van der Hoff c1c1b1047d Apply suggestions from code review
Co-authored-by: Ivan Enderlin <ivan@mnt.io>
Co-authored-by: Damir Jelić <poljar@termina.org.uk>
2023-05-03 14:16:56 +01:00
Ivan Enderlin d703380f85 chore(ffi): Re-order methods. 2023-05-03 14:03:12 +02:00
Ivan Enderlin cc365215c8 feat(sdk): Introduce SlidingSyncListBuilder::once_built.
`on_built` is a method that registers a closure. This closure is called
when a list is built by `SlidingSyncListBuilder::build`. It receives
a `SlidingSyncList` and returns a `SlidingSyncList`, the list can be
updated or returned as is. It allows to configure a `SlidingSyncList`
right after it's built. `SlidingSyncBuilder::build` is responsible to
finalize the configuration, and to build all the lists. Once they are
built, the state is restored from the cache. If one wants to configure
a list before the state is restored from the cache, `once_built` will
serve well.
2023-05-03 13:42:27 +02:00
Kévin Commaille 581b4e02a1 sdk: Add timeline tests for aggregated edits, removing reply fallbacks and sanitizing HTML
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-05-03 13:18:36 +02:00
Kévin Commaille d6401e51c2 sdk: Move edit timeline unit tests to a separate module
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-05-03 13:18:36 +02:00
Kévin Commaille 4fa2c13d44 sdk: Sanitize timeline HTML input and remove reply fallbacks
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-05-03 13:18:36 +02:00
Kévin Commaille e8375a3770 sdk: Add constructor from m.room.message event for Message
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-05-03 13:18:36 +02:00
Stefan Ceriu 45cb5f0c2c Use a indermediary directory for attachment names that might cause conflicts 2023-05-03 13:00:56 +02:00
Stefan Ceriu 2d464cf2f7 fix(ffi): Generate correct temporary file names for media attachments 2023-05-03 13:00:56 +02:00
Alfonso Grillo 9f3e4e809c ffi: Expose power levels related APIs 2023-05-03 10:43:47 +00:00
Jonas Platte e6cdf4d753 Work around new rustfmt bug 2023-05-03 11:42:50 +02:00
Jonas Platte dddec7e7ee Revert "Add "opaque interface declarations""
This reverts commit 396e0a3567.
2023-05-03 11:42:50 +02:00
Jonas Platte 37be24ee19 sqlite: Fix compiler warnings 2023-05-03 11:42:50 +02:00
Jonas Platte e1db33e6fa Upgrade UniFFI 2023-05-03 11:42:50 +02:00
Mauro 2f413af0a8 ffi: Correct timestamp value and remove is_read flag
The timestamp value of the Notification was not reliable since it was the
timestamp in which it was generated internally, not the timestamp of when the
event was sent, now we instead expose the `origin_server_ts` of the
TimelineEvent.

`is_read` is also very unreliable, so it's just removed for now.
2023-05-02 15:00:05 +00:00
Benjamin Bouvier be41dcf300 Remove unused dependencies 2023-05-02 15:06:46 +02:00
Stefan Ceriu 17fd4dd5ca ffi: Support sending image attachments through the timeline 2023-05-02 14:54:01 +02:00
Jonas Platte 557d27a1a3 sdk: Add more convenient power level action checks to RoomMember 2023-05-02 12:59:28 +02:00
Damir Jelić 9e21678ce3 Merge pull request #1846 from matrix-org/release-matrix-sdk-crypto-js-v0.1.0-alpha.8
matrix-sdk-crypto-js v0.1.0-alpha.8
2023-05-02 12:52:06 +02:00
Damir Jelić b0ca52b203 Merge pull request #1839 from matrix-org/florianduros/tech/js-bindings-missing-dependencies-lockfile
JS Bindings: add typescript missing devDependencies and lockfile
2023-05-02 11:58:24 +02:00
Richard van der Hoff 584cd5963c Merge branch 'main' into rav/signing_keys_upload_response 2023-05-02 10:54:52 +01:00
Florian Duros 61312e53d8 Merge branch 'main' into release-matrix-sdk-crypto-js-v0.1.0-alpha.8
Release `crypto-js` / Publish 🕸 [m]-crypto-js (push) Failing after 42s
2023-05-02 11:43:07 +02:00
Richard van der Hoff 8f332fddc2 crypto-js: Make importCrossSigningKeys take strings (#1843)
Currently this takes a `CrossSigningKeyExport`, but that's not a class you can
construct from the JS side. Instead, let's just pass in the individual keys.
2023-05-02 09:42:16 +00:00
Florian Duros 4df887823b Update bindings/matrix-sdk-crypto-js/README.md
Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
2023-05-02 11:35:50 +02:00
Florian Duros b9920ab477 bindings: Fix Wasm conversion into base64 2023-05-02 11:35:44 +02:00
Mauro 87b938b8fe ffi: Add timestamp field to NotificationItem 2023-05-02 11:16:43 +02:00
Mauro 034aa04076 ffi: Add is_read field to NotificationItem 2023-04-28 18:04:42 +02:00
Simon Farre 396e0a3567 Add "opaque interface declarations"
Using the #[derive(uniffi::Object)] on certain types make them not show up
in the .aar file when building for Android. Could not determine why that is,
but removing the derive macro, and adding the empty interface declarations
inside the UDL, makes them show up.

We can still use #[uniffi::export] and #[uniffi::constructor].

Signed-off-by: Simon Farre <simon.farre.cx@gmail.com>
2023-04-28 17:58:41 +02:00
Jonas Platte 7ef6accab8 base: Clean up sliding sync processing a bit 2023-04-28 13:36:37 +02:00
Jonas Platte d7421b3f85 base: Clean up ephemeral event handling
Log deserialization failing, and visit all events (though there should
never be two receipt events for one room in a single sync response).
2023-04-28 13:36:37 +02:00
Jonas Platte daf611b290 base: Add spans to some medium to large BaseClient methods 2023-04-28 13:36:37 +02:00
Kévin Commaille 640e74c76a chore: Update Ruma
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-04-28 13:12:38 +02:00
Florian Duros 8ba80fc13a matrix-sdk-crypto-js v0.1.0-alpha.8 2023-04-28 11:38:56 +02:00
Damir Jelić e6f2f65ffa Merge pull request #1838 from matrix-org/florianduros/feat/optional-unused-fallback-keys-js-bindings
JS Bindings: make `unused_fallback_keys` as optional in `machine.rs/receive_sync_changes`
2023-04-28 11:33:24 +02:00
Jonas Platte cca8ac7aea ci: Only save caches from main branch
Caches saved from a PR can't be loaded from other unrelated PRs, wasting
space and possibly getting older previously-saved caches evicted first.
2023-04-28 11:17:19 +02:00
Jonas Platte 4ee4198e83 ci: Remove build caching for infrequently used release workflows 2023-04-28 11:17:19 +02:00
Jonas Platte b4faef7867 bindings: Use proc-macros for types no longer referenced in UDL 2023-04-28 11:07:47 +02:00
Jonas Platte 34d2a20b15 ffi: Use proc-macros for constructors 2023-04-28 11:07:47 +02:00
Jonas Platte 6b8ec09365 crypto-ffi: Use proc-macros for constructors 2023-04-28 11:07:47 +02:00
Jonas Platte 8aad6156bc Upgrade UniFFI 2023-04-28 11:07:47 +02:00
Richard van der Hoff fc384367ec Update bindings/matrix-sdk-crypto-js/CHANGELOG.md 2023-04-27 20:00:21 +01:00
Richard van der Hoff 8a8c29a3b5 crypto-js: extend mark_request_sent to accept SigningKeysUploadResponses
Currently, we can't pass the response to a `SigningKeysUploadRequest` into
`mark_request_sent`, which apparently we should be able to do.

So, we need to make `SigningKeysUploadRequest` have a `type` like the other
`OutgoingRequest`s, and  add support for `SigningKeysUploadResponse` to
`OwnedResponse`.
2023-04-27 19:57:31 +01:00
Jonas Platte bafcf23a29 sdk: Use new_content of edits instead of content
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-04-27 19:08:28 +02:00
Florian Duros 75870dd607 Run clippy 2023-04-27 17:57:30 +02:00
Florian Duros 2de2a14ee6 Run rustfmt 2023-04-27 17:42:19 +02:00
Mauro d919642dd6 ffi: Exposing register_notification_handler in bindings 2023-04-27 17:35:46 +02:00
Florian Duros 31b81cbf6a Run prettier 2023-04-27 17:30:55 +02:00
Florian Duros cea29dbea1 Update README.md 2023-04-27 17:07:00 +02:00
Florian Duros c74ecc449e Add yarn.lock file 2023-04-27 17:04:54 +02:00
Florian Duros 643bd328d7 Add typescript as devDependencies 2023-04-27 17:04:43 +02:00
Florian Duros 2b3d5e09e2 Update changelog 2023-04-27 17:02:53 +02:00
Florian Duros 404d5003f3 unused_fallback_keys is optional in machine.rs 2023-04-27 17:00:28 +02:00
Kévin Commaille d54b4a1d5a sdk: Use new_content of edits instead of content
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-04-27 16:02:40 +02:00
Ivan Enderlin dbdfe560e1 doc: Fix examples. 2023-04-27 14:39:15 +02:00
Ivan Enderlin cbfa134087 feat(sdk): Remove hacks for Sliding Sync ranges
feat(sdk): Remove hacks for Sliding Sync ranges
2023-04-27 14:35:05 +02:00
Ivan Enderlin 4b51a19564 chore: Clean up tests. 2023-04-27 14:26:51 +02:00
Ivan Enderlin 58bb2dc21e chore: Fix PR feedbacks. 2023-04-27 14:16:48 +02:00
Ivan Enderlin 3a8b6696f7 test: Install SS proxy v0.99.2. 2023-04-27 14:07:39 +02:00
Ivan Enderlin 5e6720b63c feat(ffi): SlidingSync::reset_lists returns a SlidingSyncError. 2023-04-27 10:53:16 +02:00
Ivan Enderlin a719f35a3e test: Use the latest Sliding Sync proxy version. 2023-04-27 10:21:04 +02:00
Ivan Enderlin 13088dff72 test: Use the latest Sliding Sync proxy version. 2023-04-27 10:02:50 +02:00
Ivan Enderlin deeefdfe90 Revert "fix(sdk): Try to find a workaround for a bug in the SS Proxy."
This reverts commit f269202ece.
2023-04-27 09:03:12 +02:00
Kévin Commaille 6ca6a9a84a Implement SQLite state store
Co-authored-by: Jonas Platte <jplatte@matrix.org>
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-04-26 17:51:11 +02:00
Kévin Commaille 4bf15a4694 base: Implement Clone for StateChanges
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-04-26 17:51:11 +02:00
Kévin Commaille 78655bd9e2 base: Allow to get RoomMemberships as a list of MembershipStates
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-04-26 17:51:11 +02:00
Kévin Commaille 91da155b55 sqlite: Change signatures of SqliteObjectExt methods
Allows to pass owned strings as well as static strings

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-04-26 17:51:11 +02:00
Jonas Platte 40272c5989 refactor: Move sqlite crypto store migrations in new subdirectory 2023-04-26 17:51:11 +02:00
Ivan Enderlin 3b9c98d1b1 Revert "fix(sdk): Try to find workarounds about the bug in SlidingSync Proxy."
This reverts commit bd6075f6b4.
2023-04-26 17:31:47 +02:00
Ivan Enderlin 2032a9fbfb test(sdk): Fix tests and examples. 2023-04-26 17:11:47 +02:00
Kévin Commaille 1a20733225 indexeddb: Avoid unnecessary clones when deserializing events
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-04-26 16:17:38 +02:00
Ivan Enderlin 576fac99db feat(sdk): Update the FFI layer to latest commits. 2023-04-26 16:08:06 +02:00
Ivan Enderlin 4b70407bcd feat(sdk): SlidingSyncBuilder implements Clone. 2023-04-26 16:05:03 +02:00
Kévin Commaille bc240951d6 crypto: Enable decoding padded base64
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-04-26 15:56:03 +02:00
Ivan Enderlin a7659f1fcb Build Node bindings against Ubuntu 20.04
Build Node bindings against Ubuntu 20.04
2023-04-26 15:12:39 +02:00
Andrew Ferrazzutti 8e0559963e Restore "Install musl-gcc for linux-musl nodejs releases"
This reverts commit cfc6ec2c0d.
2023-04-26 20:25:57 +09:00
Ivan Enderlin f26b9fb66c Merge branch 'main' into feat-sdk-sliding-sync-cancellation-token 2023-04-26 12:19:02 +02:00
Ivan Enderlin 5d0b42c42b test(sdk): Disable SlidingSync integration tests temporarily.
Because since SlidingSync no longer restarts, the behaviour is really
different. The current way the tests are written cannot assert the full
behaviour. We need to rewrite this test suite entirely.
2023-04-26 12:08:16 +02:00
Andrew Ferrazzutti 4bbea71d51 Add comment to explain why to use Ubuntu LTS-1 2023-04-26 18:45:18 +09:00
Andrew Ferrazzutti 80de0f0bbe Build Node bindings against Ubuntu 20.04
Fixes #1808
2023-04-26 18:45:16 +09:00
Ivan Enderlin f17003f00e chore(sdk): SlidingSync::stream takes a &self. 2023-04-26 11:19:11 +02:00
Ivan Enderlin bb049489ef feat(sdk): SlidingSyncList::on_list can return a value. 2023-04-26 11:18:38 +02:00
Kévin Commaille 51a2d101b6 base: Remove RoomMemberships::UNKNOWN/KNOWN
The unknown filter can be difficult to match with MembershipState,
depending on the store implementation.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-04-26 10:12:22 +02:00
Kévin Commaille f7e8b22646 memory-store: indexeddb: Store memberships as MembershipState
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-04-26 10:12:22 +02:00
Kévin Commaille 252f4cb9a2 sled: Store memberships as strings
Storing as bitset is not future-proof.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-04-26 10:12:22 +02:00
Kévin Commaille a511500e6e indexeddb: Store memberships as strings
Storing as bitset is not future-proof.
Just fix the latest migration. We assume no-one used it yet.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-04-26 10:12:22 +02:00
Kévin Commaille 3081dabb66 base: Add method to match RoomMemberships with MembershipState
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-04-26 10:12:22 +02:00
Ivan Enderlin 1709089e6d feat(sdk): SlidingSync sync loop can be controled via internal messages.
The MPSC channel that has been introduced in recent commits is now used
in this patch. The `SlidingSync::stream` method can be controlled via
the `internal_channel`.

This patch updates `SlidingSync::stream` to use the `tokio::select!
` macro to select any future that resolves first between the
`internal_channel` receiver, or `SlidingSync::sync_once`. Fairness is
biaised as the `internal_channel` has the priority.

This mechanism is already used by this patch: `SlidingSyncList::reset`
will send the `SlidingSyncInternalMessage::ContinueSyncLoop` to
“continue”… well… the sync loop, i.e. it will cancel in-flight waiting
for a response.

This entire mechanism removes the need to “stop” and “start”, i.e.
“restart” the `SlidingSync::stream` method manually, which was the
source of many bugs. Now everything is controlled internally.
2023-04-26 09:50:11 +02:00
Ivan Enderlin 770d50e2ce Merge pull request #1822 from AndrewFerr/af/update-nodejs-version
Update supported Node.js versions
2023-04-26 08:37:20 +02:00
Kévin Commaille ae79fd0af5 sdk: Deprecate Common::(active/joined)_members(_no_sync)
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-04-25 18:03:53 +02:00
Kévin Commaille b8f06ec4a1 sdk-base: Deprecate Room::(active/joined)_members
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-04-25 18:03:53 +02:00
Kévin Commaille fe6424f48c sdk: Implement Common::(active/joined)_members_no_sync with members_no_sync
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-04-25 18:03:53 +02:00
Kévin Commaille 2010c180a8 base-sdk: Implement Room::(active/joined)_members with members
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-04-25 18:03:53 +02:00
Kévin Commaille e98fbfce9a sdk: Allow to filter Common::members(_no_sync) by membership state
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-04-25 18:03:53 +02:00
Kévin Commaille f68b45aa49 base-sdk:Allow to filter Room::members by membership state
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-04-25 18:03:53 +02:00
Kévin Commaille 81a543e15b sdk-base: Deprecate get_invited_user_ids and get_joined_user_ids
get_user_ids can be used instead

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-04-25 18:03:53 +02:00
Kévin Commaille 4ffa20abde sdk-base: Allow to filter get_user_ids results by any membership state
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-04-25 18:03:53 +02:00
Kévin Commaille 58a1ad1b93 base: Use single map for all user IDs in memory store
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-04-25 18:03:53 +02:00
Andrew Ferrazzutti 564549e8af Update Node bindings' "engines"
Signed-off-by: Andrew Ferrazzutti <andrewf@element.io>
2023-04-25 23:59:22 +09:00
Andrew Ferrazzutti 46f69f7efd Update supported Node.js versions
Signed-off-by: Andrew Ferrazzutti <andrewf@element.io>
2023-04-25 23:51:53 +09:00
Jonas Platte c897f0ccaf ffi: Print location for tracing events 2023-04-25 12:19:55 +02:00
Jonas Platte bd3a37791b Distinguish events from live sync and sync cache in debug string 2023-04-25 11:50:06 +02:00
Simon Farre b105359b27 Expose fetch_event_details to FFI
Signed-off-by: Simon Farre <simon.farre.cx@gmail.com>
2023-04-24 20:50:06 +00:00
Ivan Enderlin c5c8ac8a7c feat(sdk): Add support for bump_event_types in SlidingSync
feat(sdk): Add support for `bump_event_types` in `SlidingSync`
2023-04-24 20:23:27 +02:00
Ivan Enderlin 2a912f7422 Merge pull request #1817 from matrix-org/revert-1779-af/nodejs-musl-gcc
Revert "Install musl-gcc for linux-musl nodejs releases"
2023-04-24 19:59:23 +02:00
Ivan Enderlin cfc6ec2c0d Revert "Install musl-gcc for linux-musl nodejs releases" 2023-04-24 19:59:01 +02:00
Ivan Enderlin 7e243c5a5b Merge branch 'main' into fix-issue-1728 2023-04-24 19:46:56 +02:00
Kévin Commaille 910c35b699 sled: Return all user IDs in get_user_ids
It would only return joined and invited user IDs,
since those are the only ones that were stored.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-04-24 18:54:29 +02:00
Kévin Commaille 3f1a596c8c indexeddb: Return all user IDs in get_user_ids
It would only return joined and invited user IDs,
since those are the only ones that were stored.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-04-24 18:54:29 +02:00
Kévin Commaille 493db9dd3f sdk-test: Add room member ban sync event
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-04-24 18:54:29 +02:00
Ivan Enderlin 5d63f0b215 chore(sdk): Move variables in a smaller scope to clarify the code. 2023-04-24 15:14:11 +02:00
Ivan Enderlin 304d1f445b feat(sdk): SlidingSync types share a channel to talk to each other.
`SlidingSync` has a `Receiver`, `SlidingSyncList` has a `Sender`.
2023-04-24 14:17:33 +02:00
Ivan Enderlin 30abbe3cd4 feat(sdk): SlidingSync::add_list takes a SlidingSyncListBuilder.
Prior to this patch, `SlidingSync::add_list` was taking a
`SlidingSyncList`. However, we need to inject more data when building
the list, so let's modify `add_list` to take a `SlidingSyncListBuilder`
instead. It's even better for the user as calling `build()` isn't
necessary anymore.
2023-04-24 14:14:47 +02:00
Ivan Enderlin 7f5e61831e chore(sdk): Remove a useless import. 2023-04-24 14:11:36 +02:00
Ivan Enderlin 3b8ce5c9b1 feat(sdk): Create SlidingSync::on_list. 2023-04-24 14:11:36 +02:00
Ivan Enderlin e21d1fcb93 feat(sdk): SlidingSyncList no longer implement Clone.
It's not possible to clone a `SlidingSyncList` anymore. Why? Because
it's not correct. Prior to this patch, it was possible to add a list
to a `SlidingSync` instance, then add a clone of the same list to
another `SlidingSync` instance. Weird behaviors could happen, but more
importantly, for the next Sliding Sync design we are working on, it
could lead to gigantic bugs.

Removing `Clone` from `SlidingSyncList` makes the code simpler.
For example, `SlidingSyncList.inner` no longer needs an `Arc`, or
`SlidingSync::stream` no longer needs to clone all the lists.
2023-04-24 14:11:12 +02:00
Ivan Enderlin f4e577bbe0 feat(sdk): Remove SlidingSync::pop_list.
This method is used by nobody. It's safe to remove it.
2023-04-24 14:07:27 +02:00
Jonas Platte e5f4bbdc47 Upgrade dependencies 2023-04-24 13:59:01 +02:00
Jonas Platte e15e21a3d7 ffi: Use UniFFI proc-macros for SessionVerificationController type 2023-04-24 12:42:27 +02:00
Jonas Platte 3954cab2ab ffi: Use UniFFI proc-macros for Room type 2023-04-24 12:42:27 +02:00
Jonas Platte e1a727a27f ffi: Use UniFFI proc-macros for some misellaneousc symbols 2023-04-24 12:42:27 +02:00
Jonas Platte 75e7289ede ffi: Use UniFFI proc-macros for last parts of the Client type 2023-04-24 12:42:27 +02:00
Jonas Platte 00b3057e06 ffi: Use UniFFI proc-macros for ClientBuilder::build 2023-04-24 12:42:27 +02:00
Jonas Platte 5f802c1348 ffi: Use UniFFI proc-macros as much as possible for sliding sync 2023-04-24 12:42:27 +02:00
Jonas Platte 7ab14d9428 Enable Ruma's compat-user-id feature 2023-04-24 12:42:03 +02:00
Jonas Platte d527dd37b1 Upgrade Ruma 2023-04-24 12:42:03 +02:00
Jonas Platte 24a903ccb0 Fix Cargo.lock 2023-04-24 11:17:05 +02:00
Ivan Enderlin 8aad30ea4f Merge pull request #1779 from matrix-org/af/nodejs-musl-gcc
Install musl-gcc for linux-musl nodejs releases
2023-04-24 10:51:00 +02:00
Jonas Platte c6f491861e crypto-ffi: Use proc-macros for types no longer referenced in UDL 2023-04-24 10:31:12 +02:00
Jonas Platte 055f0ff988 crypto-ffi: Use proc-macros for Verification type and methods 2023-04-24 10:31:12 +02:00
Jonas Platte 058d27e0a3 crypto-ffi: Use proc-macros for Sas methods 2023-04-24 10:31:12 +02:00
Jonas Platte cb216044e1 crypto-ffi: Use proc-macros for OlmMachine methods 2023-04-24 10:31:12 +02:00
Jonas Platte 693ced4f4d crypto-ffi: Remove unused function 2023-04-24 10:31:12 +02:00
Jonas Platte 27cf710009 crypto-ffi: Use proc-macros for VerificationRequest methods 2023-04-24 10:31:12 +02:00
Jonas Platte 5202e3e1b9 crypto-ffi: Use proc-macros for QrCode methods 2023-04-24 10:31:12 +02:00
Jonas Platte d90d7b519b crypto-ffi: Use proc-macros for types not referenced in UDL 2023-04-24 10:31:12 +02:00
Jonas Platte d15447a2c1 crypto-ffi: Use proc-macro for exporting free functions 2023-04-24 10:31:12 +02:00
Ivan Enderlin be7b79b4e5 feat(ffi): Add binding for SlidingSyncBuilder::bump_event_types.
This patch adds a new binding on `SlidingSyncBuilder` to
`matrix_sdk::SlidingSyncBuilder::bump_event_types`.
2023-04-24 10:05:00 +02:00
Ivan Enderlin 7b2b3fa78f feat(sdk): Add support for bump_event_types in SlidingSync.
The `SlidingSyncBuilder` now has a new method: `bump_event_types`, to
configure the `bump_event_types` HTTP request parameter. This value
is passed to `SlidingSync`, which is used to build the `SlidingSync`
request.
2023-04-24 10:05:00 +02:00
Ivan Enderlin 1c2e7d8c0d chore: Update Cargo.lock. 2023-04-24 09:56:55 +02:00
Valere f8e4e3d7d5 fix(bindings): Withheld code mapping 2023-04-22 21:10:56 +02:00
Jonas Platte 9ffcb8bc8a ffi: Move error type into its own module 2023-04-20 18:24:47 +02:00
Jonas Platte 4f316a130f Remove uniffi_types modules 2023-04-20 18:24:47 +02:00
Jonas Platte 7e58e72671 Upgrade UniFFI 2023-04-20 18:24:47 +02:00
Florian Duros fd739a3676 matrix-sdk-crypto-js v0.1.0-alpha.7 2023-04-20 18:24:36 +02:00
Jonas Platte 167d81e36a ci: Simplify test-all-crates job 2023-04-20 14:52:34 +02:00
Richard van der Hoff 0a0da040d2 account.rs: add some comments (#1799) 2023-04-20 13:01:44 +01:00
Jonas Platte f2d2a20987 ffi: Change make_span to be a constructor, write docs 2023-04-20 11:43:45 +02:00
Jonas Platte 29068265db ffi: Add filtering of tracing events and spans 2023-04-20 11:43:45 +02:00
Jonas Platte 50f29e5a11 ffi: Add Span::is_none 2023-04-20 11:43:45 +02:00
Jonas Platte 54bd26d683 ffi: Add Span::current 2023-04-20 11:43:45 +02:00
Jonas Platte b532d35d21 Remove root_span from Client 2023-04-20 11:43:45 +02:00
Jonas Platte bb05ac7dac ffi: Add basic tracing bindings 2023-04-20 11:43:45 +02:00
Richard van der Hoff 0da8e56a68 crypto-js: wait for device updates in getUserDevices (#1790)
Wait for up to a second for any in-flight device list updates to complete.
2023-04-20 08:58:26 +01:00
Richard van der Hoff a88f53ee85 crypto-js: Expose more data on Device (#1786)
Implement Device.algorithms and Device.isSignedByOwner for the js bindings.
2023-04-20 08:57:54 +01:00
Jonas Platte 530fceb40d Fix some rustdoc warnings 2023-04-20 09:02:28 +02:00
Jonas Platte 7d5908beef sdk: Add more data to RemoteEventTimelineItem Debug string 2023-04-20 09:02:09 +02:00
Anderas 5d94a5d2f4 Update iOS Crypto SDK docs
… and add local podspec.
2023-04-19 18:09:21 +02:00
Jonas Platte 0e08d0f9ef sdk: Make EventTimelineItem's fields pub(super)
… and avoid an unnecessary clone.
2023-04-19 14:17:16 +02:00
Jonas Platte 3f6c9956ab sdk: Move timestamp to EventTimelineItem
… from Local/RemoteEventTimelineItem.
2023-04-19 14:17:16 +02:00
Jonas Platte c97d8afa58 sdk: Remove extra visibility boundary on {Local,Remote}EventTimelineItem 2023-04-19 14:17:16 +02:00
Jonas Platte abd508676e sdk: Remove {Local,Remote}EventTimelineItem from public API 2023-04-19 14:17:16 +02:00
Jonas Platte 7376198dfa sdk: Move sender, sender_profile, content to EventTimelineItem
… from Local/RemoteEventTimelineItem.
2023-04-19 14:17:16 +02:00
Jonas Platte 2960aafe3d sdk: Make EventTimelineItem an opaque struct instead of an enum 2023-04-19 14:17:16 +02:00
Jonas Platte 4daf31f5b1 Fix clippy lint 2023-04-19 14:17:16 +02:00
Jonas Platte bf4349ffb3 base-sdk: Don't separate member events from other state events
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-04-19 14:04:53 +02:00
Kévin Commaille b87a4e8c20 base-sdk: Don't separate member events from other state events
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-04-19 13:16:55 +02:00
Alfonso Grillo 3b1ed1403d sdk: Add DM invitation to m.direct account data upon accepting it 2023-04-18 18:05:48 +02:00
Alfonso Grillo fe10bcc814 base: Use member event is_direct field for is_direct() on invited rooms 2023-04-18 18:05:48 +02:00
Jonas Platte be67c91a6b Use regular backticks in matrix-sdk-ffi/README.md 2023-04-18 15:20:51 +02:00
Jonas Platte 89c06568dd Remove unneeded explicit lifetime 2023-04-18 15:20:51 +02:00
Alfonso Grillo dffa1b16c3 sdk: Skip user's own ID when marking a room as DM 2023-04-18 13:41:34 +02:00
Jonas Platte 5bc20669c2 sdk: Implement MSC3925 for the timeline
https://github.com/matrix-org/matrix-spec-proposals/blob/main/proposals/3925-replace-aggregation-with-full-event.md
Implemented in Synapse 1.79.0:
https://github.com/matrix-org/synapse/releases/tag/v1.79.0
2023-04-18 13:14:33 +02:00
Jonas Platte 86930581a5 Upgrade Ruma 2023-04-18 13:14:33 +02:00
Jonas Platte 40c1252f48 sdk: Simplify handling of bundled relations in timeline 2023-04-18 13:14:33 +02:00
Alfonso Grillo cfdc9b2a82 Expose accept_invitation to UniFFI 2023-04-18 12:45:30 +02:00
Jorge Martin Espinosa c5919e3e63 Add workaround for building Android bindings with supported NDK versions (r23+) 2023-04-17 16:06:46 +00:00
Andrew Ferrazzutti 4fbdd70a53 Use local reference to workflow file 2023-04-14 20:20:59 +09:00
Andrew Ferrazzutti a78b260857 Install musl-gcc for linux-musl nodejs releases 2023-04-14 17:43:42 +09:00
Damir Jelić cd865d21c3 Drop outbound group sessions in the SQLite store
The format of the outbound group session struct has changed. We nowadays correctly rotate the group session if we can't restore it, but it's still good to avoid logging the error in this case.
2023-04-13 14:48:14 +00:00
Damir Jelić 8137c39f3a Don't log the raw Ruma sliding sync response 2023-04-13 16:14:47 +02:00
Jonas Platte f21946ef06 sdk: Avoid raw JSON in debug strings 2023-04-13 16:00:50 +02:00
Damir Jelić 730b66e26c Add withheld code support 2023-04-13 11:46:19 +02:00
Damir Jelić 316b29c95f Merge branch 'main' into valere/msc_2399 2023-04-13 10:59:05 +02:00
Jonas Platte 1e737208e5 sdk: Handle ephemeral events after timeline events 2023-04-12 16:15:35 +02:00
Jonas Platte 36b9064e51 sdk: Reduce indentation in read receipt handling code
… by factoring out a function.
2023-04-12 15:24:52 +02:00
Jonas Platte 086106a96d sdk: Simplify return type of fetch_in_reply_to_details 2023-04-12 13:16:36 +02:00
Simon Farre b9fba69dc7 ffi: Fix kotlin build failure
Workaround for https://github.com/mozilla/uniffi-rs/issues/1434
2023-04-12 10:11:07 +00:00
Simon Farre 8bad59bbe1 ffi: Add avatar_url getter for SlidingSyncRoom
Signed-off-by: Simon Farre <simon.farre.cx@gmail.com>
2023-04-11 15:47:40 +00:00
Damir Jelić 972d5cefdb If we can't load an outbound group session from the store, rotate it
An error is currently thrown if loading an outbound group session fails.
This error may only affect loading outbound group sessions, while other
store operations continue to work fine. As a result, the user is unable
to send messages, but can still use the application without any problems.

Since outbound group sessions are rotated frequently, we can simply
rotate the session if loading fails. However, if the error is related to
a more serious storage issue, persisting the newly rotated outbound group
session will also fail. If the error is specific to outbound group
sessions, the user will be able to continue using the application without
interruption.
2023-04-11 10:08:06 +02:00
Damir Jelić c73aeef2ed Fix the serialization of outbound group sessions in the SQLite store
The SQLite crypto store uses rmp_serde to serialize all the data we're
going to store. This works nicely for most things, one exception to this
is the OutboundGroupSession type.

The OutboundGroupSession type stores to-device requests to ensure that
the session doesn't get used before it is shared with the whole group
and to ensure that the to-device requests get restored if the
session gets restored after an application restart.

The to-device requests type critically contain `Raw<AnyToDeviceEvent>`,
the `Raw` type here being the serde_json::Raw type. rmp_serde seems to
serialize this just fine, but later deserialization fails.

We're avoiding the issue by using serde_json to serialize the
OutboundGroupSession.
2023-04-11 10:08:06 +02:00
Damir Jelić 0f8da0b723 Test that to-device requests in the group session can get deserialized 2023-04-11 10:08:06 +02:00
Kévin Commaille a1cfb4bcf1 sdk: Re-export CrossSigningStatus
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-04-08 21:47:10 +02:00
Ivan Enderlin f6fb082dc9 chore(sdk): Remove unused methods in sliding_sync
chore(sdk): Remove unused methods in `sliding_sync`
2023-04-06 18:02:08 +02:00
Ivan Enderlin df9f48dc38 chore(sdk): Replace to_string by to_owned. 2023-04-06 18:01:45 +02:00
Ivan Enderlin 0b4c94961d test(sdk): Fix a test. 2023-04-06 17:42:28 +02:00
Ivan Enderlin 41d44f0d49 chore(sdk): Remove unused methods.
Those methods are public, but never used by our current users.

Moreover, there is some big overlaps. For example, `storage_key`,
`cold_cache` and `no_cache` do the same thing: They update the
`storage_key` field. Or `add_fullsync_list` is just a helper that is
never used except in the tests etc.
2023-04-06 16:29:38 +02:00
Jonas Platte 29255781cc Fix comments in Cargo.toml 2023-04-06 15:49:09 +02:00
Ivan Enderlin 1756aabe35 fix(sdk): SlidingSyncList.room_list emits updates for non-moving rooms
fix(sdk): `SlidingSyncList.room_list` emits updates for non-moving rooms
2023-04-06 15:08:47 +02:00
Ivan Enderlin 4ee4906536 chore(sdk): Make Clippy happy. 2023-04-06 11:36:37 +02:00
Ivan Enderlin fbe162a1bc test(sdk): Fix an integration test in Sliding Sync.
The test does the following:

1. Create 2 (identical) lists,
2. Do a sync.
3. Assert that the 1st and 2nd lists are receiving an update,
4. Add a 3rd (identical) list,
5. Do a new sync,
6. Assert that 3rd list is receiving an update.

This last step is wrong. All lists should receive an update as they
are identical.
2023-04-06 11:29:10 +02:00
Damir Jelić cebeca85d0 fixup! Minor fixes to the withheld handling 2023-04-06 11:23:27 +02:00
Damir Jelić 8c23b6e7b2 Minor fixes to the withheld handling 2023-04-06 11:18:14 +02:00
Ivan Enderlin eb0e97b902 test(sdk): Test that SlidingSyncList.room_list receives “diff”.
This patch updates a test to ensure that `room_list` receives “diff”
for rooms that are modified by a sync operations, but also by another
updates (like a new event).
2023-04-06 11:14:09 +02:00
Ivan Enderlin 828e36e3af test(sdk): Test apply_sync_operations removes rooms that have been updated. 2023-04-06 11:14:09 +02:00
Ivan Enderlin d68a22c378 fix(sdk): SlidingSyncList.room_list emits updates for non-moving room.
The `SlidingSyncList.room_list` field is used to store the list of rooms
for a particular Sliding Sync list. It's used by the user to receive
“diff”s when a room sees its position modified. For example when a new
room receives a message, it “climbs back up” the entire room list to
be at the top place. Another example is when a new room is created,
some rooms will move around to give the new room a space. All those
moves will create “diff”.

However, the user also expects to receive a “diff” when a room has
received some updates, even if it's position doesn't change. For
example, when a room is already at the top of the list but receives a
new message: It has received an update, but its position stays the same.

This specific latter feature was implemented before, but it has been
removed by accident in https://github.com/matrix-org/matrix-rust-sdk/
pull/1699 (more specifically in https://github.com/matrix-org/matrix-
rust-sdk/pull/1699/commits/861a05be69a566d9a4ad125dc6ecb418d2b3210f).
At that time, it was not clear why the code was filtering for specific
filled room entires, to set the filled room entries, at the same
position. Zero comment, zero test. I didn't consider this as a feature
but as a bug.

So this patch re-introduces this feature. Hopefully in a more optimal
way. If a room has already triggered a first “diff” because of a
position change, it won't trigger a second “diff” because it has
received an update (which was the case before).

The `SlidingSyncList::handle_response` method has also been renamed
`update`, as it does update, whenever it comes from.

The code has been commented and documented to explain this feature.

Existing tests have been updated, especially for `apply_sync_operations`
which now ensure the `rooms_that_have_received_an_update` collections is
updated accordingly. Another test has been updated specifically to test
the “diff”s received by `room_list`.
2023-04-06 11:09:55 +02:00
Ivan Enderlin a71970d3de chore(sdk): Rephrase a panic message. 2023-04-06 10:50:20 +02:00
Ivan Enderlin c07b060080 feat(sdk): Create vectors with correct capacity to avoid reallocations.
`updated_rooms` and `updated_lists` can be created with an initial
capacity. Doing so will avoid reallocations if the vector is too small.
2023-04-06 10:49:15 +02:00
Jonas Platte b033508e9b Fix clippy lints 2023-04-06 09:57:37 +02:00
Damir Jelić ba95a7bfd8 Use BTreeMap instead of HashMap
We use BTreeMap everywhere else, so let's be consistent with that
choice.
2023-04-05 14:38:25 +02:00
Damir Jelić 64d76308c6 Use as_ref() instead of stars and ampersands 2023-04-05 14:29:49 +02:00
Damir Jelić 52fef9f373 Don't use a Result return type in the withheld handling method 2023-04-05 14:27:00 +02:00
Damir Jelić c3437ac4cf Apply suggestions from code review
Co-authored-by: Jonas Platte <jplatte@matrix.org>
2023-04-05 14:22:19 +02:00
Damir Jelić 6fd129dcfa Remove some commented out code and fix some formatting 2023-04-05 13:22:41 +02:00
Damir Jelić 1f8c67bbb2 Use the atomic bool seralizer for the no_olm flag 2023-04-05 13:15:51 +02:00
Damir Jelić 82a4b53cf9 fixup! Apply suggestions from code review 2023-04-05 13:15:38 +02:00
Damir Jelić 673db38a72 Apply suggestions from code review
Co-authored-by: Jonas Platte <jplatte@matrix.org>
2023-04-05 13:14:07 +02:00
Damir Jelić 50d477b91c More clippy fixes 2023-04-05 11:54:29 +02:00
Damir Jelić 1c2964f3f3 Update crates/matrix-sdk-crypto/src/types/events/room_key_withheld.rs
Co-authored-by: Jonas Platte <jplatte@matrix.org>
2023-04-05 11:52:25 +02:00
Damir Jelić 92202e20e7 Fix some clippy warnings 2023-04-05 11:45:50 +02:00
Damir Jelić c032609f4d Fix the js tests now that we bumped our DB version 2023-04-05 11:34:28 +02:00
Olivier Wilkinson (reivilibre) 9c54de1817 Downgrade memory store 'Saved changes in <time>' to debug
It doesn't seem very interesting since a memory store will be fast anyway. In practice, this fills the console quickly.
2023-04-05 11:31:37 +02:00
Damir Jelić d606bd3e9f Document the new withheld content enums 2023-04-05 11:18:50 +02:00
Ivan Enderlin 7c578dccb9 fix(sdk): SlidingSync uses the same storage keys for storing *and* restoring
fix(sdk): `SlidingSync` uses the same storage keys for storing *and* restoring
2023-04-05 11:11:47 +02:00
Ivan Enderlin 5563213106 chore(test): Make Clippy happy. 2023-04-05 10:56:08 +02:00
Jonas Platte 91dc87808d ffi: Add InReplyToDetails 2023-04-05 10:50:08 +02:00
Jonas Platte 1217067f74 ffi: Rename ProfileTimelineDetails to ProfileDetails 2023-04-05 10:50:08 +02:00
Jonas Platte 5b512f020e sdk: Rename details field to event in InReplyToDetails 2023-04-05 10:50:08 +02:00
Ivan Enderlin 042d6bab72 test(sdk): Test SlidingSync is store and restored correctly. 2023-04-05 10:06:59 +02:00
Jonas Platte ef3ffda2d3 ffi: Replace EventTimelineItem::{raw, fmt_debug} by debug_info 2023-04-05 09:56:00 +02:00
Jonas Platte 3ac6b10daa sdk: Add RemoteEventTimelineItem::latest_edit_json
… and rename raw to original_json to disambiguate.
2023-04-05 09:56:00 +02:00
Ivan Enderlin be631849e8 fix(sdk): Move SlidingSync::cache_to_storage to cache.
This patch also re-uses the `format_storage_key_*` functions to use the
same key as the `restore_sliding_sync_state` function. It fixes a bug
where the keys were mismatching.
2023-04-05 09:17:54 +02:00
Ivan Enderlin fc8b9d7de4 feat(sdk): Extract SlidingSync cache functions into their own module. 2023-04-05 09:05:03 +02:00
Jonas Platte 2c38c6c371 sdk: Log in_reply_to field in timeline::Message Debug impl 2023-04-04 18:09:08 +02:00
Damir Jelić 81e2725b6f Remove DirectWithheldCode 2023-04-04 13:30:29 +02:00
Simon Farre fc56ae3dcf Expose invite_user_by_id over the FFI
This PR is self explanatory.

Exposes said function to the FFI. Defined in the .adl file,
and defined to throw `ClientError`

Signed-off-by: Simon Farre <simon.farre.cx@gmail.com>
Co-authored-by: Damir Jelić <poljar@termina.org.uk>
2023-04-04 09:04:54 +00:00
Chris Smith e8c56f8163 feat: expose inviter to ffi
This allows us to know who has invited us to rooms
2023-04-04 10:29:04 +02:00
Ivan Enderlin 690c3b1977 Merge pull request #1699 from Hywan/feat-sdk-sliding-sync-list-revamp-sync-mode
feat(sdk) Revamp Sliding Sync List state lifetime
2023-04-03 15:04:21 +02:00
Ivan Enderlin ac800180a7 Merge branch 'main' into feat-sdk-sliding-sync-list-revamp-sync-mode 2023-04-03 14:36:26 +02:00
Damir Jelić b7a78c865c Ensure correct Olm session selection for encrypted messages
In some cases, restoring client state from backups may cause Olm sessions
to become corrupted, resulting in a backward ratchet. As a consequence,
the receiving side is unable to decrypt messages. To address this issue,
the failed side initiates a new Olm session and sends a dummy encrypted
message.

However, this dummy message also creates a new Olm session on the
sender's side. To ensure that both sides use the same new session, we
must sort sessions by their creation timestamp before encrypting new
messages.

Although the session list was sorted correctly previously, we selected
the wrong side of the list, resulting in an outdated session being
selected instead of the newest one. This patch resolves the issue by
selecting the newest Olm session and adds a test to the session getter
logic to prevent reintroduction of this bug.
2023-04-03 13:03:09 +02:00
Ivan Enderlin aeda2d363c Merge pull request #1736 from Hywan/feat-sliding-sync-storage 2023-04-03 12:54:49 +02:00
Ivan Enderlin 69af5b3c6f feat(sdk): When a SlidingSync cache is obsolete, let's remove it.
Prior to this patch, when `SlidingSync` was built with a storage key,
the storage was read to find a previous `SlidingSync` version that
was in a cache. To put a `SlidingSync` instance in the cache, it
was serialized to JSON. When one reads from the cache, the value is
deserialized. A problem happens when the internal representation of
`SlidingSync` and other types (e.g. `SlidingSyncList`) have changed (due
to an SDK update for example): Loading a previous state from the cache
results in an error.

After discussion with the teams, clients don't want to deal with
obsolete cache values. In such a scenario, (i) they cannot interact
with the cache to remove the obsolete entry, and (ii) their only
possibility is to log out and log in the user again. What an unfriendly
user experience!

This patch modifies this behaviour. When loading a `SlidingSync` type or
a `SlidingSyncList` type from the cache, 3 cases are now handled:

1. The cache entry exists and has been successfully deserialized: in
   this case, we do our business.
2. The cache entry exists, but it wasn't possible to deserialize it: the
   cache entry is declared as obsolete, and the entire `SlidingSync`
   cache is cleaned up, so all entries for `SlidingSync` and
   `SlidingSyncList` are removed from the storage,
3. The cache entry doesn't exist: we do nothing particular.

Note that if one cache is obsolete, all cache entries are removed.
2023-04-03 12:10:50 +02:00
Ivan Enderlin 56a7854b53 Merge branch 'main' into feat-sdk-sliding-sync-list-revamp-sync-mode 2023-04-03 10:10:31 +02:00
Ivan Enderlin 60d4ac14b7 Merge pull request #1725 from Hywan/feat-remove-jack-in
feat(labs): Remove `jack-in`
2023-04-01 13:27:20 +02:00
Richard van der Hoff 78b9758377 Merge pull request #1721 from matrix-org/rav/crypto-js-releases
Fixes and documentation for crypto-js releases
2023-03-31 11:22:50 +01:00
Richard van der Hoff a5fd71a251 prettify markdown 2023-03-31 11:08:26 +01:00
Alfonso Grillo 7958a20fc1 Add short_retry on get_profile 2023-03-30 22:00:09 +02:00
Jonas Platte 6878f52885 Upgrade UniFFI 2023-03-30 21:53:02 +02:00
Ivan Enderlin ea5b4c98c1 feat(labs): Remove jack-in.
This was a fun ride, but nobody uses it, and we don't need it anymore.

Thanks for all the fishes.
2023-03-30 18:03:38 +02:00
Ivan Enderlin 60432abe0d feat(ffi): Add SlidingSync::reset_lists. 2023-03-30 18:01:17 +02:00
Ivan Enderlin 2d537e5211 feat(sdk): Add SlidingSync::reset_lists.
The `SlidingSync::stream` method no longer resets the lists everytime
it is called. If one wants to reset the lists, they need to call
`SlidingSync::reset_lists`.
2023-03-30 18:01:16 +02:00
Jonas Platte 7dd086fcdc Make sqlite bundling optional 2023-03-30 17:59:51 +02:00
Ivan Enderlin bd6075f6b4 fix(sdk): Try to find workarounds about the bug in SlidingSync Proxy.
It still about https://github.com/matrix-org/sliding-sync/issues/52. We
try to rebuilt a valid `range`. Hopefully, the bug will be fixed soon,
and we will be able to clean that temporary code.
2023-03-30 17:52:33 +02:00
Kévin Commaille 48b67759ed sdk: Make PaginationOption's custom variant's strategy return a ControlFlow
It is semantically more correct than an Option.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-03-30 14:39:08 +00:00
Richard van der Hoff f60c678af8 Apply suggestions from code review
Co-authored-by: Damir Jelić <poljar@termina.org.uk>
2023-03-30 15:38:42 +01:00
innocent fish a35d96c15e Update swift.rs 2023-03-30 16:08:06 +02:00
Alfonso Grillo ade7fabb6b Add Client::get_profile 2023-03-30 15:44:27 +02:00
Ivan Enderlin dd4cb9c793 test(sdk): Fix SlidingSync doctests. 2023-03-30 15:10:17 +02:00
Ivan Enderlin 2ace220366 chore(sdk): Rename rooms_list to room_list. 2023-03-30 15:06:19 +02:00
Richard van der Hoff 4f3f9c7af8 Fixes and documentation for crypto-js releases
The tags are supposed *not* to contain `v`, for consistency with the other
crates.
2023-03-30 13:57:15 +01:00
Richard van der Hoff 43d4e7b46a Merge pull request #1719 from matrix-org/release-matrix-sdk-crypto-js-0.1.0-alpha.6
matrix-sdk-crypto-js v0.1.0-alpha.6
2023-03-30 13:53:39 +01:00
Ivan Enderlin 4be02d0e99 test(sdk): Wait longer on the server to reply. 2023-03-30 14:43:33 +02:00
Ivan Enderlin e34708862d test(sdk): Remove a useless SS test. 2023-03-30 14:31:52 +02:00
Ivan Enderlin f269202ece fix(sdk): Try to find a workaround for a bug in the SS Proxy.
See https://github.com/matrix-org/sliding-sync/issues/52 for the
explanation. And this patch has comments explaining how I try to work
around this.
2023-03-30 14:23:59 +02:00
Kévin Commaille 408f966a50 sdk: Rename flag to update fully-read marker
Its meaning has changed since it is used in more cases.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-03-30 14:23:57 +02:00
Kévin Commaille 553ffe97a8 sdk: Never insert read marker in last position in timeline
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-03-30 14:23:57 +02:00
Ivan Enderlin 23f16f065b fix(sdk): Make out-of-bounds DELETE a no-op. 2023-03-30 13:37:31 +02:00
Richard van der Hoff f246296ff9 matrix-sdk-crypto-js v0.1.0-alpha.6
Release `crypto-js` / Publish 🕸 [m]-crypto-js (push) Failing after 34s
2023-03-30 12:26:29 +01:00
Mauro ca6faffc72 bindings: Reset the timeline when the user's ignore list is updated 2023-03-30 11:22:06 +00:00
Ivan Enderlin 4c42205633 chore(labs): Update to the latest SS version. 2023-03-30 12:57:24 +02:00
Richard van der Hoff f9881065c1 Add an API to notify apps when a megolm key is received
This is useful for applications which want to have another go at decryption
when some room keys arrive.
2023-03-30 12:29:39 +02:00
Ivan Enderlin 1af1504ef3 feat(ffi): Update to the latest Sliding Sync version. 2023-03-30 11:42:22 +02:00
Damir Jelić 7fd1c93e1a Document the fact that we require protoc to build the bindings 2023-03-30 11:06:15 +02:00
Doug a33d2ad28f bindings: Add ignore_user 2023-03-30 08:59:19 +00:00
Ivan Enderlin bd8a97cfd7 feat(sdk): Update the SyncOp::Delete operation.
It seems that the `DELETE` operation actually deletes an entry. So
let's update the code to reflect that :-).
2023-03-30 10:35:27 +02:00
Ivan Enderlin ce94fcc2e2 feat(sdk): Update the SyncOp::Insert operation.
It seems that the `INSERT` operation actually inserts a new entry. So
let's update the code to reflect that :-).
2023-03-30 10:00:21 +02:00
Ivan Enderlin a442ca1893 Merge branch 'main' into feat-sdk-sliding-sync-list-revamp-sync-mode 2023-03-29 17:29:15 +02:00
Ivan Enderlin db7746062f doc(sdk): Write more doc. 2023-03-29 17:23:37 +02:00
Ivan Enderlin bc9d5016dc chore(sdk): Move maximum_number_of_rooms's update a little bit above. 2023-03-29 17:15:07 +02:00
Ivan Enderlin 581c02307e fix(sdk): Rewrite SyncOp::Invalidate entirely.
`SyncOp::Invalidate` means _invalidating_ a particular range. When a
room is `Filled`, it becomes `Invalidated`, when it is `Invalidated` it
stays `Invalidated`, and when it is `Empty` it stays `Empty`.

Before this patch, `Empty` was becoming `Invalidated`, which apparently
is a bug.

This patch also fixes out-of-bound accesses, and adds many tests.

Finally, this patch renames `update_state` to `update_room_lists`.
2023-03-29 17:11:01 +02:00
Ivan Enderlin a4f8c35efc fix(sdk): Rewrite SyncOp::Insert entirely.
`SyncOp::Insert` means _inserting_ a new room ID. The `rooms_list`
contains all possible rooms (based on `maximum_number_of_rooms`, a value
returned by the server). Here, inserting = setting
`RoomListEntry::Filled` at a particular index of `rooms_list`, that's
it.

The previous code was doing very complex stuff, like removing things
around the `index` if something etc. It was using the requested ranges
(the range passed to the request) etc.

Applying `SyncOp` should be simple and is focused on updating
`rooms_list` only: the requested ranges have nothing to do here.

This patch also prevents against out-of-bounds acccesses, which wasn't
the case before.
2023-03-29 16:30:06 +02:00
Ivan Enderlin 2878148b0e fix(sdk): Prevent ouf of bounds accesses for SyncOp::Delete.
This patch prevents out of bounds acceses for `SyncOp::Delete`, and adds
more tests.

This patch also removes a cast from `UInt` to `u32` to `usize`. It's now
from `UInt` to `usize` directly.
2023-03-29 16:10:44 +02:00
Ivan Enderlin d6cfd871c4 feat(sdk): Protect against invalid responses from the server. 2023-03-29 15:55:02 +02:00
Ivan Enderlin 18597f8f63 fix(sdk): Fix out-of-bounds and re-implement SlidingOp::Sync handler.
First off, this patch renames `ops` to `sync_operations` and `room_ops`
to `apply_sync_operations`.

Second, the `SlidingOp::Sync` was creating an out-of-bounds access
depending of the range present in the server's response. For example, if
the `rooms_list` contains 5 elements (because the
`maximum_number_of_rooms` is set to 5), and the server replies with:

```json
{
    "op": "SYNC",
    "ranges": [3, 17],
    "room_ids": […]
}
```

the previous code was setting a new `RoomListEntry` at indices `3..=17`,
whilst the `rooms_list` contains only indices from `0..=4`. That's
annoying.

The previous code was also counting the number of `room_ids` for
nothing, just to execute the iterator that was applying the actual
changes in a `map`. Well, everything was fishy.

This patch updates the code to protect against an unexpected server's
reply by raising an `Err`. This patch also adds tests.
2023-03-29 15:30:10 +02:00
Jonas Platte 6b5f0b8ec3 Reset visible timeline when a gappy sync arrives 2023-03-29 14:00:33 +02:00
Damir Jelić 172867fd4d Simplify the withheld code receiving 2023-03-29 13:44:28 +02:00
Jonas Platte 50cc356c7b Use Observable for sliding_sync_reset_broadcast_tx 2023-03-29 13:23:24 +02:00
Jonas Platte 2ac192f307 Use str::to_owned instead of str::to_string
Expresses intent more clearly.
2023-03-29 13:23:24 +02:00
Damir Jelić 03aba95e1e Switch the FFI bindings to use the SQLite cryptostore 2023-03-29 11:44:33 +02:00
Ivan Enderlin 616e57eb1c test(sdk): Update integration test suite for SS. 2023-03-29 11:05:02 +02:00
Ivan Enderlin 5c695bbf8f feat(ffi): Update add_range calling. 2023-03-29 10:55:14 +02:00
Ivan Enderlin 861a05be69 feat(sdk): Remove updated_rooms from SlidingSyncListInner::update_state.
The `updated_rooms` argument was passed to `find_rooms_in_list` to
update the `room_list`: the update is setting the filtered room list
entry to `RoomListEntry::Filled`.

_But_, `find_rooms_in_list` was already filtering rooms which are
`Filled`. So it does… nothing: it filters rooms which are `Filled` to
update them to `Filled`.

So we can remove `find_rooms_in_list` because it becomes useless. And we
can remove `updated_rooms` too.

The `rooms_list` is updated by `rooms_ops` itself. Let's keep
modifications in one unique place.
2023-03-29 10:51:33 +02:00
Damir Jelić cf17a05ecc Restructure the withheld code types 2023-03-29 10:45:26 +02:00
Ivan Enderlin 385dd9113b feat(sdk): Simplify SlidingSyncListInner::update_state.
The `update_state` method of `SlidingSyncListInner` has basically
2 cases:

1. For an initial response,
2. For other responses.

The code between the 2 cases were almost identical. Or, they could be
identical. The few exceptions are:

* In the first case, the `rooms_list` updates were taking the
  form of a `VectorDiff::Append`, while the second case, it was a
  `VectorDiff::PushBack`.
* In the first case, the `is_cold` flag was set to `false`.

It's fine for the clients to receive only a `VectorDiff::Append` event
only. So let's make it uniform.

And it appears that the `is_cold` field is now private, and never read
anywhere else. So… it's… basically useless. We can remove it! It was
previously used here to know which flow to use, but since we can make
both flows identical, its role becomes insignificant.
2023-03-29 09:52:58 +02:00
Ivan Enderlin 3f4f9c1fbd chore(sdk): Remove a useless reference. 2023-03-29 09:52:05 +02:00
Ivan Enderlin bf163ef5ad feat(sdk): Replace checked_sub + unwrap_or_default by saturating_sub. 2023-03-29 09:23:47 +02:00
Ivan Enderlin 83cf820508 chore(sdk): More code in blocks to remove mutable variables with larger scopes. 2023-03-29 09:23:10 +02:00
Jonas Platte d680b331d0 Make tokio a workspace dependency 2023-03-28 21:08:57 +02:00
Jonas Platte cd33d8ca38 Always use RwLock and Mutex from tokio
… instead of async-lock, which we previously used on wasm.
2023-03-28 21:08:57 +02:00
Jonas Platte 9bfd88cec4 sdk: Always use tokio OnceCell
Tokio's sync module works on wasm as well.
2023-03-28 21:08:57 +02:00
Damir Jelić d5fba19655 Don't allow the no_olm withheld code sent flag to be reset 2023-03-28 14:31:55 +02:00
Ivan Enderlin ab29e1b319 !debug 2023-03-27 14:32:11 +02:00
Ivan Enderlin a2dbeda758 feat(sdk): SlidingSyncList cannot be removed from SlidingSync.
`create_range` and `SlidingSyncList::next_request` return a `Result`
instead of an `Option`. It was a legacy from the old `impl Iterator` of
`SlidingSyncListRequestGenerator`. But actually, when `create_range`
fails, it must return a `Err` value, not a `None` value.

And since it's a regular error, `sync_once` can propagate the
error. Thus, it is no longer necessary to “update” the list of
`SlidingSyncList`. It's not necessary to remove some items in this list
when the `next_request` method can no return a value: it always returns
a value, except when a error happens.
2023-03-27 14:25:40 +02:00
Damir Jelić 0d3fd31893 Clean up the withheld code types 2023-03-27 09:21:48 +02:00
dependabot[bot] 8b5de47acb chore(deps): bump openssl from 0.10.45 to 0.10.48 (#1706)
Bumps [openssl](https://github.com/sfackler/rust-openssl) from 0.10.45 to 0.10.48.
- [Release notes](https://github.com/sfackler/rust-openssl/releases)
- [Commits](https://github.com/sfackler/rust-openssl/compare/openssl-v0.10.45...openssl-v0.10.48)

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

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-03-25 21:12:52 +01:00
Kévin Commaille 5a7ea607c6 sdk: Use new filter constructor to enable room members lazy-loading
* sdk: Use new filter constructor to enable room members lazy-loading

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-03-25 21:12:09 +01:00
Flescio 09fc258f9a ffi: Make name parameter optional in CreateRoomParameters 2023-03-23 16:56:52 +00:00
Ivan Enderlin fdba90587a feat(sdk): Reset the SlidingSyncList when starting a stream. 2023-03-23 17:44:25 +01:00
Ivan Enderlin 63ed675158 doc(sdk): Extract the giant SS doc inside a README.md file.
Why? Because it takes forever to scroll to the code when opening
`sliding_sync/mod.rs` :-p.
2023-03-23 17:38:20 +01:00
Ivan Enderlin 767e9b3cf2 feat(sdk) Reset SlidingSyncList when a range is modified. 2023-03-23 16:32:53 +01:00
Ivan Enderlin 8d4ceac21f test(sdk): Continue to fix, test and clean up SlidingSyncList
test(sdk): Continue to fix, test and clean up `SlidingSyncList`
2023-03-23 13:18:09 +01:00
Ivan Enderlin d1616d5654 chore(sdk): Remove a useless comma. 2023-03-23 13:17:54 +01:00
Ivan Enderlin 492e08598c feat(sdk): Revamp SlidingSyncList::*range*.
First off, `set_ranges`, `set_range`, `add_range` and `reset_ranges`
take a `&[(U, U)]` instead of a `Vec<(U, U)>` when a vector was needed,
or takes a `(U, U)` instead of 2 arguments when it was needed.

Second, all those methods now return a `Result<(), Error>`. The
`Error::CannotModifyRanges` is raised if the chosen `SlidingSyncMode`
doesn't allow to modify ranges. Basically, `Selective` does allow a
user to modufy the ranges, but there is no real ranges with `Growing` or
`Paging`. Let's make it an explicit error.

Finally, `SlidingSyncListInner` has 2 methods: `set_ranges` and
`add_range`, but without any “ranges check”; `SlidingSyncList` does call
the inner methods, but does the checks.
2023-03-23 12:34:48 +01:00
Ivan Enderlin 6716939b6d chore(sdk): Re-order fields in SlidingSyncListInner. 2023-03-23 11:56:08 +01:00
Ivan Enderlin 73959e023b feat(sdk): Remove for FullSync suffix to sync modes. 2023-03-23 11:53:39 +01:00
Ivan Enderlin ec02d462ea feat(sdk): The SlidingSyncList.full_sync_* fields are no longer useful.
They are unused. Let's remove them.
2023-03-23 11:50:38 +01:00
Ivan Enderlin 0eee472829 feat(sdk): Remove send_updates_for_items.
This field is always set to `true` by all the clients. So let's consider
that something we always want, and let's remove code complexity.
2023-03-23 11:46:56 +01:00
Ivan Enderlin 296328e8e0 feat(sdk): Don't rename SlidingSyncState's variants when serialization.
We are going to introduce a BC break. So let's take the opportunity to
get rid off of this renamings too.
2023-03-23 11:37:53 +01:00
Ivan Enderlin 831090c92c feat(sdk): Export RoomListEntry into its own module. 2023-03-23 11:24:30 +01:00
Ivan Enderlin fa361aea16 chore(sdk): Make Clippy happy. 2023-03-23 11:18:09 +01:00
Ivan Enderlin 91e9942fcd feat(sdk): Export FrozenSlidingSyncList into its own module. 2023-03-23 11:15:24 +01:00
Kévin Commaille 5eeea83c19 sdk: Get push actions of retried decrypted events in the timeline
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-03-23 10:59:55 +01:00
Kévin Commaille 98386cf527 sdk: Get push actions of decrypted events
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-03-23 10:59:55 +01:00
Kévin Commaille a3667a21c9 sdk: Simplify e2ee branching of Common::event
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-03-23 10:59:55 +01:00
Kévin Commaille fae10ae7f3 sdk: Add private method to get the current push rules
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-03-23 10:59:55 +01:00
Ivan Enderlin 1db8084c4f chore(sdk): Make Clippy happy. 2023-03-23 10:38:37 +01:00
Ivan Enderlin b544639187 chore(sdk): Re-ordering methods inside SlidingSyncList. 2023-03-23 10:07:19 +01:00
Ivan Enderlin 5e1fda9834 test(sdk): Update the assert_ranges macro to be able to define the first list state. 2023-03-23 10:05:34 +01:00
Ivan Enderlin 5bae1a2a4e chore(sdk): rooms_ops takes a &[(UInt, UInt)] for the ranges. 2023-03-22 16:59:45 +01:00
Ivan Enderlin defe48bf3c test(sdk): Test SlidingSyncList::get_room_id. 2023-03-22 16:45:53 +01:00
Ivan Enderlin caf55308a5 feat(sdk): Remove SlidingSyncList::rooms_updated_broadcast_stream.
This method is never used by the clients, so it's basically public dead
code. It doesn't fulfill a particular requirement nor a need, so let's
remove it.

Fixes https://github.com/matrix-org/matrix-rust-sdk/issues/1694.
2023-03-22 16:40:06 +01:00
Ivan Enderlin f2aebcb983 test(sdk): (Re)write a test for SlidingSyncListInnner::find_rooms_in_list. 2023-03-22 16:40:06 +01:00
Ivan Enderlin 2840242331 chore(sdk): Use &[…] instead of &Vec<…>.
One less pointer indirection.
2023-03-22 16:40:06 +01:00
Ivan Enderlin 69a779a7eb feat(sdk): Improve SlidingSyncListInner::find_rooms_in_list.
The `SlidingSyncListInner::find_rooms_in_list` method can be greatly
improved by using the `Iterator` API.

It was already using `Iterator::skip`, great! Let's continue by using
`Iterator::take` instead of using a stop index.

And let's use `Iterator::enumerate` to avoid using a mutable index.
2023-03-22 16:40:06 +01:00
Ivan Enderlin b7da197846 doc(sdk): Add missing documentation. 2023-03-22 16:40:06 +01:00
Ivan Enderlin 0b9b01727e feat(sdk): Remove find_rooms?_in_list from the public API.
`SlidingSyncList::find_room_in_list` and
`SlidingSyncList::find_rooms_in_list` aren't useful (and never used) by
the public consumer of this API. Let's remove it. They are only used for
internal purposes.
2023-03-22 16:40:06 +01:00
Ivan Enderlin 0d58695e39 feat(sdk): SlidingSyncListInner::update_request_generator_state returns a Result.
Before, the `update_request_generator_state` method was emitting an
`error!` log, but not an error. But that's clearly an error!

This patch updates the method to return a `Result<(), Error>`, and adds
a new variant to `Error`.
2023-03-22 16:40:06 +01:00
Ivan Enderlin f5ba7ddc4a fix(sdk): Prevent bugs, remove expensive clones, and simplify SlidingSyncList
fix(sdk): Prevent bugs, remove expensive clones, and simplify `SlidingSyncList`
2023-03-22 16:39:30 +01:00
Ivan Enderlin 7052e9ff64 doc(sdk): Fix typos. 2023-03-22 16:38:45 +01:00
Ivan Enderlin 8796bfe874 doc(sdk): Fix typos. 2023-03-22 16:16:33 +01:00
Ivan Enderlin 9e7c6c3632 feat(sdk): Remove deduplication logic from Sliding Sync
feat(sdk): Remove deduplication logic from Sliding Sync
2023-03-22 14:44:45 +01:00
Ivan Enderlin 6617e94a9d Merge pull request #1632 from Hywan/doc-sdk-sliding-sync
doc(sdk): Rephrase the Quick refreshing Section
2023-03-22 14:19:46 +01:00
Ivan Enderlin 7e8c8b1a14 chore(sdk): Make Clippy happy. 2023-03-22 13:31:48 +01:00
Ivan Enderlin 9078a30e28 chore(sdk): Move code around, and remove pub on fields of a private struct. 2023-03-22 13:17:52 +01:00
Ivan Enderlin 485ca402f4 test: Use available setter. 2023-03-22 13:17:52 +01:00
Ivan Enderlin d41293879a test(sdk): Move tests from list/request_generator.rs to list/mod.rs. 2023-03-22 13:17:52 +01:00
Ivan Enderlin d5babfbb88 test(sdk): Test SlidingSyncList::(set_)timeline_limit. 2023-03-22 13:17:52 +01:00
Ivan Enderlin b842b2f96d feat(sdk): Add getters and setters on SlidingSyncList. 2023-03-22 13:17:52 +01:00
Ivan Enderlin 32e83a942d fix(sdk): Prevent bugs, remove expensive clones, and simplify SlidingSyncList.
There are problems with `SlidingSyncListRequestGenerator`:

* It's part of the module API,
* It contains a clone of `SlidingSyncList`.

To create a `SlidingSyncListRequestGenerator`, one has to
call `SlidingSyncList::request_generator`. It was done in
`SlidingSync::stream`. The problem is that it clones `SlidingSyncList`.
So theoritically it is possible to create multiple request generators
for the _same_ list, and use them to send many requests and to update
the _same_ list with multiple responses. This is utterly error-prone and
can lead to really complex bugs to discover.

Moreover, it's a lot of clones. Cloning a
`SlidingSyncListRequestGenerator` isn't cheap as it means cloning a
`SlidingSyncList`. Moreover, cloning a `SlidingSyncList` isn't cheap as
it means cloning the entire struct.

Having `SlidingSyncListRequestGenerator` inside the module API also
makes the code of `SlidingSync` more complex (why having to deal with
lists and request generators at the same time? we must be very careful
to maintain both side by side? what if a list is removed but not its
request generator? and so on).

So. This patch simplifies all that.

First off, it extracts all the fields of `SlidingSyncList` into a
`SlidingSyncListInner` struct. Then, `SlidingSyncList` has only one
field: `Arc<SlidingSyncListInner>`. Boom, it's now cheap to clone it.

Second, `SlidingSyncListRequestGenerator` is only a
struct with constructors, but there is no extra methods.
`SlidingSyncListRequestGenerator` _no longer_ contains a
`SlidingSyncList`, and doesn't no need a list at all to work. It's just
values.

Third, `SlidingSyncList` holds a `SlidingSyncListRequestGenerator`, and
only one.

Fourth, `SlidingSyncList` (and `SlidingSyncListInner`) now has methods
to handle the internal request generator. The initial `impl Iterator for
SlidingSyncListRequestGenerator` becomes a simple
`SlidingSyncList::next_request` method.

Fifth, previously, the `SlidingSyncList::handle_response`
was never called directly by `SlidingSync`. It was called by
`SlidingSyncListRequestGenerator`! How confusing! `SlidingSync` called
`SlidingSyncListRequestGenerator::handle_response` which was calling
`SlidingSyncList::handle_response`. Now, the flow is more natural:
`SlidingSync` calls `SlidingSyncList::handle_response` and that's it.

Sixth, the `SlidingSyncList::handle_response` is now composed of 2
parts: updating the list itself, and updating the request generator. It
was kind of the case before, but onto two different types.
It was unclear which types were updating `SlidingSyncList`.
For example, `SlidingSyncList::state` was updated by…
`SlidingSyncListRequestGenerator`. Now `SlidingSyncList` is responsible
to update itself, and no one else.

Finally, `SlidingSync` no longer have to deal with
`SlidingSyncListRequestGenerator`. All it has is a set of
`SlidingSyncList`, and that's it!

The tests are still passing, hurray.
2023-03-22 13:17:50 +01:00
Ivan Enderlin d81e6a18f9 chore(sdk): Format a comment. 2023-03-22 13:15:50 +01:00
Ivan Enderlin e514415642 test(sdk): Write test suites for SlidingSyncList and siblings
test(sdk): Write test suites for `SlidingSyncList` and siblings
2023-03-22 12:29:27 +01:00
Ivan Enderlin d9096cc64c chore(sdk): Make Clippy happy. 2023-03-22 12:14:04 +01:00
Ivan Enderlin f085289d05 chore(sdk): Make Clippy happy. 2023-03-22 11:37:51 +01:00
Damir Jelić ef81168434 Fix some doc links in the send_attachment docs 2023-03-22 11:36:02 +01:00
Ivan Enderlin 1f04353668 test(sdk): Use vector! from imbl, not im. 2023-03-22 11:20:07 +01:00
Alfonso Grillo f70b6f5ecf Expose 'search users' to UniFFI (#1689) 2023-03-22 11:15:03 +01:00
Ivan Enderlin ee7dc2a7ab chore(sdk): Address PR feedback. 2023-03-22 11:06:21 +01:00
Ivan Enderlin 1256052134 chore(sdk): Clean up. 2023-03-22 11:06:21 +01:00
Ivan Enderlin 28eebe2043 doc(sdk): Explain what SlidingSyncList::handle_response does and does not. 2023-03-22 11:06:21 +01:00
Ivan Enderlin bb54ff7991 chore(sdk): Move and document the SlidingSyncList::request_generator method. 2023-03-22 11:06:21 +01:00
Ivan Enderlin aa75d02ae3 feat(sdk): SlidingSyncList::handle_response must be pub(self).
This method must be only visible to the current module, not from the
upper/super module.

Note: `pub(self)` is equivalent to no `pub` at all.
2023-03-22 11:06:21 +01:00
Ivan Enderlin eefef9a81b test(sdk): Move test to appropriate files. 2023-03-22 11:06:21 +01:00
Ivan Enderlin 15646ec1d6 test(sdk): Fix how TimelineEvent is constructed. 2023-03-22 11:06:21 +01:00
Ivan Enderlin 10380596cd chore(sdk): Format a comment. 2023-03-22 11:06:21 +01:00
Ivan Enderlin c4df1cb9aa chore(sdk): Rename an argument. 2023-03-22 11:06:21 +01:00
Ivan Enderlin c509b6c76a test(sdk): Add tests for SlidingSyncList.set_range, add_range and reset_ranges. 2023-03-22 11:06:21 +01:00
Ivan Enderlin 9c2e2238ed test(sdk): Add a test for SlidingSyncList::ranges. 2023-03-22 11:06:21 +01:00
Ivan Enderlin 2edb5d845e feat(sdk): SlidingSyncList.ranges & co. takes a Into<UInt>.
In `SlidingSyncListBuilder`, the `ranges`, `set_range`, and `add_range`
methods do not take a `u32` but a `U: Into<UInt>`. That's great!

However, in `SlidingSyncList`, the same methods take a `u32`. It makes
the API inconsistent.

This patch fixes that.
2023-03-22 11:06:18 +01:00
Ivan Enderlin 147e5f8f03 fix(sdk): Rename SlidingSyncList.set_ranges to ranges.
This patch renames `SlidingSyncList.set_ranges` to `ranges` so that
it matches the same terminology of the `SlidingSyncListBuilder` with
`ranges`, `set_range`, `add_range` and `reset_ranges`.

Consistency is important here.
2023-03-22 10:59:23 +01:00
Ivan Enderlin 8e9cabcbf9 test(sdk): Add test for SlidingSyncList::new_builder. 2023-03-22 10:59:23 +01:00
Ivan Enderlin 42af266806 fix(sdk): Fix SlidingSyncList::new_builder.
The `SlidingSyncList::new_builder` method creates a new builder from a
`SlidingSyncList`. This method was missing some configurations, like
`full_sync_maximum_numbre_of_rooms_to_fetch`, `send_updates_for_items`,
`filters`, `ranges` and `timeline_limit`.

This patchs adds those missing configurations.
2023-03-22 10:59:23 +01:00
Ivan Enderlin 7a1fb0b368 fix(sdk): Remove useless fields on SlidingSyncListBuilder.
The `SlidingSyncListBuilder` struct has a `state` and a `rooms_list`
fields. Those fields are never updated and no setters or getters exist
to use them. There are just set with defaults, and passed to the final
`SlidingSyncList` type within the `build` method.

If a field is present in a builder type, it means they can be modified,
but it's not the case. So this patch removes them.
2023-03-22 10:59:17 +01:00
Ivan Enderlin 3f72b10831 test(sdk): Write a test case for FrozenSlidingSyncList when serialized. 2023-03-22 10:58:40 +01:00
Ivan Enderlin 6bd95057b6 test(sdk): Write a test case for RoomListEntry when serialized. 2023-03-22 10:58:40 +01:00
Ivan Enderlin 859317a0f6 test(sdk): Write test suites for SlidingSyncState and SlidingSyncMode. 2023-03-22 10:58:40 +01:00
Ivan Enderlin ace3ff3754 test(sdk): Write test suites for RoomListEntry. 2023-03-22 10:58:40 +01:00
Ivan Enderlin 60b627c2ca feat(sdk): Rename RoomListEntry.freeze to .freeze_by_ref. 2023-03-22 10:58:40 +01:00
Ivan Enderlin 41615840dc feat(sdk): Remove deduplication logic from Sliding Sync.
Event deduplication is supposed to be handled by the `Timeline`. Sliding
Sync is not responsible to de-duplicate the events, in our model. Having
two different de-duplication logics (one in Sliding Sync, and one in the
Timeline) could create weird situations, and hard to debug issues.

We give it a try by removing the deduplication from Sliding Sync.
2023-03-22 10:53:23 +01:00
Ivan Enderlin d07b389f4b chore(sdk): Rename some variables. 2023-03-22 10:52:56 +01:00
Damir Jelić b2a35fc9cf Merge branch 'main' into valere/msc_2399 2023-03-21 16:41:55 +01:00
Damir Jelić 900a4f848c Don't log verification requests as sent if the request id doesn't match 2023-03-21 15:57:16 +01:00
Damir Jelić c4d73c9901 fixup! Don't send m.no_olm withheld codes out if another session is doing so 2023-03-21 15:56:58 +01:00
Damir Jelić eb9dd8fb0d Don't send m.no_olm withheld codes out if another session is doing so
The `m.no_olm` withheld code is supposed to be sent out only once for a
given device.

This patch prevents double sending of m.no_olm withheld code by adding
a test that ensures only one group session will send it out.

Previously, the logic for sharing group sessions was mostly correct, but
an edge case was forgotten where two group sessions attempted to share
the withheld code concurrently.

Although there's still a possibility for multiple m.no_olm withheld codes
to be sent out. This may happen during the propagation of the flag
remembering the fact that the `m.no_olm` code has been sent from the
OutboundGroupSession to Device. This scenario is likely unrealistic and
the consequences of sending things twice aren't problematic.
2023-03-21 15:45:32 +01:00
Jonas Platte a134cc378d Sort sliding-sync-integration-test dependencies 2023-03-21 13:31:58 +01:00
Jonas Platte a32fce6cdf Make all sliding-sync-integration-test dependencies dev-dependencies 2023-03-21 13:31:58 +01:00
Jonas Platte 9ee2d04a41 Feature-gate everything in sliding-sync-integration-test 2023-03-21 12:24:14 +01:00
Mauro 1ce1c5636e Add support for (un)ignoring users 2023-03-21 12:23:17 +01:00
Damir Jelić 8652cdf752 Test the VerificationState migration 2023-03-21 12:02:31 +01:00
Damir Jelić 32e2ea0288 Allow the old VerificationState enum to be deserialized into the new one 2023-03-21 12:02:31 +01:00
Damir Jelić 7263914f67 Remove the Apple specific auth service tests
These tests are doing real network requests towards hosts that are not
under our control.
2023-03-21 12:00:43 +01:00
Florian Renaud 76763a80fe ffi: Add binding for get_dm_room 2023-03-20 16:30:25 +00:00
Jonas Platte 72ae9dd885 Upgrade eyeball-im 2023-03-20 16:51:28 +01:00
Jonas Platte 816e722807 ffi: Inline uniffi_api modules
include_scaffolding! is expected to be used at the crate root now, and
clippy seems happy with the generated code right now.
2023-03-20 15:42:38 +01:00
Jonas Platte 1a1fe97d00 Use Rust conventions for variable names in UDL 2023-03-20 15:42:38 +01:00
Jonas Platte 16687f24f9 sdk: Fix documentation of create_room 2023-03-20 13:56:43 +01:00
Jonas Platte ea41076c82 sdk: Rename create_dm_room to create_dm and make it public 2023-03-20 13:56:43 +01:00
Jonas Platte 130dc58a5d Remove redundant cfg attributes
The whole encryption module is only enabled with e2e-encryption.
2023-03-20 13:56:43 +01:00
Jonas Platte 9d6e192b9f sdk: Move create_dm_room out of encryption module
Creating DM rooms makes sense for non-encryption-capable client as well.
2023-03-20 13:56:43 +01:00
Jonas Platte 82d1d64f85 sdk: Simplify create_dm_room
It doesn't need to call mark_as_dm itself as create_room will do that.
2023-03-20 13:56:43 +01:00
Jonas Platte 39a4dc911f Remove event contents from (Sync)TimelineEvent Debug impls 2023-03-20 13:21:41 +01:00
Alfonso Grillo a7ed8e0b45 Update account_data when creating a new dm room 2023-03-20 12:08:21 +01:00
Ivan Enderlin e64ab6cf9c Merge pull request #1677 from matrix-org/rav/update-js-bindings-prefix
matrix-sdk-crypto-js: drop `v` from release tags
2023-03-20 09:23:29 +01:00
Damir Jelić 43d883da9c Refactor the room key sharing logic 2023-03-16 19:40:30 +01:00
Richard van der Hoff 42dce635de matrix-sdk-crypto-js: drop v from release tags
Currently, the tags used for releases of this binding have the format:
"matrix-sdk-crypto-js-v0.1.0-alpha.5". This is inconsistent with tags used for
other parts of the project, which omit the `v` prefix.
2023-03-16 17:49:52 +00:00
Richard van der Hoff 7794b230e1 Merge pull request #1675 from matrix-org/release-matrix-sdk-crypto-js-v0.1.0-alpha.5
matrix-sdk-crypto-js: prepare v0.1.0-alpha.5
2023-03-16 17:38:33 +00:00
Ivan Enderlin 2d56f550aa fix(sdk): Fix, test, and clean up SlidingSyncListRequestGenerator
fix(sdk): Fix, test, and clean up `SlidingSyncListRequestGenerator`
2023-03-16 17:04:05 +01:00
Ivan Enderlin b39a224be8 doc(sdk): Use the Rust range notation to avoid ambiguity. 2023-03-16 17:03:25 +01:00
Richard van der Hoff e6bf74b7db matrix-sdk-crypto-js v0.1.0-alpha.5
Release `crypto-js` / Publish 🕸 [m]-crypto-js (push) Failing after 41s
2023-03-16 13:47:55 +00:00
Ivan Enderlin 5f06dc8229 doc(sdk): Fix a typo. 2023-03-16 11:53:01 +01:00
Kévin Commaille 46d8d26b71 sdk: Fix a typo
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-03-16 11:40:47 +01:00
Kévin Commaille e23be44345 sdk: Store OIDC issuer as a String rather than a Url
The url crate normalizes the string, but during OIDC verification steps,
the issuer verification must be made against the exact string that was
provided.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-03-16 11:40:47 +01:00
Ivan Enderlin 57fb659b86 Merge pull request #1666 from zecakeh/indexeddb-crypto-version
indexeddb: Use u32 to represent version of crypto store
2023-03-16 11:12:27 +01:00
Ivan Enderlin 1933fe7a8f doc(sdk): Fix a typo. 2023-03-16 11:04:18 +01:00
Ivan Enderlin 6a6d94a065 Re-expose the vodozemac and matrix-sdk-crypto versions in the bindings
Re-expose the vodozemac and matrix-sdk-crypto versions in the bindings
2023-03-16 10:56:51 +01:00
Ivan Enderlin ccfb66c576 chore(crypto-nodejs): Fix a lint. 2023-03-16 10:39:43 +01:00
Ivan Enderlin c2d3afffff feat(crypto-nodejs): Make Versions a class, not a JS object. 2023-03-16 10:33:41 +01:00
Ivan Enderlin e1f6fd8a1e feat(ffi): Create the version and vodozemac_version functions. 2023-03-16 09:53:39 +01:00
Damir Jelić 2f377d536a fixup! Re-expose the vodozemac and matrix-sdk-crypto versions in the bindings 2023-03-16 09:53:39 +01:00
Damir Jelić 26789f22b0 fixup! Re-expose the vodozemac and matrix-sdk-crypto versions in the bindings 2023-03-16 09:53:39 +01:00
Damir Jelić 3aa1c30f5c Re-expose the vodozemac and matrix-sdk-crypto versions in the bindings 2023-03-16 09:53:37 +01:00
Ivan Enderlin 5e23bd09bc feat(ci): aarch64-apple-ios should work on rustc stable. 2023-03-16 09:01:14 +01:00
Ivan Enderlin c8bad4b86e doc(sdk): Fix a typo. 2023-03-16 08:55:25 +01:00
Ivan Enderlin 07c366983d doc(sdk): Fix a typo. 2023-03-16 08:24:05 +01:00
Ivan Enderlin 51abedda59 feat(ffi): Update SlidingStateState variants. 2023-03-16 08:21:11 +01:00
Ivan Enderlin 9d5a1fda3c doc(sdk): Fix typos or improve. 2023-03-16 08:11:45 +01:00
Damir Jelić 61ea15eb39 Merge branch 'main' into valere/msc_2399 2023-03-15 19:31:04 +01:00
Kévin Commaille fe69948926 sdk: Add a method to change the room name
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-03-15 17:28:08 +00:00
Valere 248b8db309 Extended verification states
Co-authored-by: Damir Jelić <poljar@termina.org.uk>
Co-authored-by: Denis Kasak <dkasak@termina.org.uk>
2023-03-15 18:16:31 +01:00
Ivan Enderlin ca5cabb7e1 doc(sdk): Fix a typo. 2023-03-15 18:08:19 +01:00
Ivan Enderlin 7a2b1e6e1f doc(sdk): Fix a typo. 2023-03-15 17:59:11 +01:00
Ivan Enderlin c0f84bb8da test(sdk): Fix tests and improve speed.
To improve the speed, we simply reduce the numbers of rooms involved in
the test.
2023-03-15 17:54:39 +01:00
Kévin Commaille 9a9b142630 indexeddb: Use u32 to represent version of crypto store
Like for the state store, the bindings expose the version as an f64
while the web API expects an unsigned integer.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-03-15 17:08:33 +01:00
Ivan Enderlin a2dcfa905f fix(sdk): Fix, test, and clean up SlidingSyncList.
This patch should ideally be split into multiple smaller ones, but life
is life.

This main purpose of this patch is to fix and to test
`SlidingSyncListRequestGenerator`. This quest has led me to rename
mutiple fields in `SlidingSyncList` and `SlidingSyncListBuilder`, like:

* `rooms_count` becomes `maximum_number_of_rooms`, it's not something
  the _client_ counts, but it's a maximum number given by the server,

* `batch_size` becomes `full_sync_batch_size`, so that now, it
  emphasizes that it's about full-sync only,

* `limit` becomes `full_sync_maximum_number_of_rooms_to_fetch`, so that
  now, it also emphasizes that it's about ful-sync only _and_ what the
  limit is about!

This quest has continued with the renaming of the `SlidingSyncMode`
variants. After a discussion with the ElementX team, we've agreed on the
following renamings:

* `Cold` becomes `NotLoaded`,
* `Preload` becomes `Preloaded`,
* `CatchingUp` becomes `PartiallyLoaded`,
* `Live` becomes `FullyLoaded`.

Finally, _le plat de résistance_.

In `SlidingSyncListRequestGenerator`, the `make_request_for_ranges`
has been renamed to `build_request` and no longer takes a `&mut self`
but a simpler `&self`! It didn't make sense to me that something
that make/build a request was modifying `Self`. Because the type of
`SlidingSyncListRequestGenerator::ranges` has changed, all ranges now
have a consistent type (within this module at least). Consequently, this
method no longer need to do a type conversion.

Still on the same type, the `update_state` method is much more
documented, and errors on range bounds (offset by 1) are now all fixed.

The creation of new ranges happens in a new dedicated pure function,
`create_range`. It returns an `Option` because it's possible to not be
able to compute a range (previously, invalid ranges were considered
valid). It's used in the `Iterator` implementation. This `Iterator`
implementation contains a liiiittle bit more code, but at least now
we understand what it does, and it's clear what `range_start` and
`desired_size` we calculate. By the way, the `prefetch_request` method
has been removed: it's not a prefetch, it's a regular request; it was
calculating the range. But now there is `create_range`, and since it's
pure, we can unit test it!

_Pour le dessert_, this patch adds multiple tests. It is now
possible because of the previous refactoring. First off, we test the
`create_range` in many configurations. It's pretty clear to understand,
and since it's core to `SlidingSyncListRequestGenerator`, I'm pretty
happy with how it ends. Second, we test paging-, growing- and selective-
mode with a new macro: `assert_request_and_response`, which allows to
“send” requests, and to “receive” responses. The design of `SlidingSync`
allows to mimic requests and responses, that's great. We don't really
care about the responses here, but we care about the requests' `ranges`,
and the `SlidingSyncList.state` after a response is received. It also
helps to see how ranges behaves when the state is `PartiallyLoaded`
or `FullyLoaded`.
2023-03-15 16:57:29 +01:00
Kévin Commaille 1e1e0d7e6d ci: Make sure all rendered docs examples are compiling
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-03-15 14:42:12 +01:00
Kévin Commaille 5d1a738162 sdk: Fix generate_image_thumbnail example in docs
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-03-15 14:42:12 +01:00
Jonas Platte e4e9efb7d9 ffi: Put CreateRoomParameters back into the UDL file
… to restore the default values of some fields.
2023-03-15 13:09:54 +01:00
Doug b1074e400e sdk: Add get_media_file function 2023-03-15 09:22:53 +00:00
Ivan Enderlin 9574f93320 feat(sdk): Add more Sliding Sync logs
feat(sdk): Add more Sliding Sync logs
2023-03-15 09:58:02 +01:00
Ivan Enderlin c3bcbf8952 chore(sdk): Rephrase logs a little bit. 2023-03-15 09:41:39 +01:00
Jonas Platte 739dd8cf93 Fix clippy complaint 2023-03-14 18:34:23 +01:00
Jonas Platte c7e1d617ec ffi: Use UniFFI derives for types no longer referenced in UDL 2023-03-14 18:34:23 +01:00
Jonas Platte ae85e18588 ffi: Use UniFFI proc-macros for more Client methods 2023-03-14 18:34:23 +01:00
Damir Jelić 516d849ef2 Allow room key forwarding to be enabled and disabled (#1365)
Co-authored-by: Ivan Enderlin <ivan@mnt.io>
2023-03-14 18:23:39 +01:00
Damir Jelić eb2bf61236 Merge pull request #1657 from matrix-org/poljar/session-creator-info
Improve the docs of the inbound group session type
2023-03-14 17:33:24 +01:00
Damir Jelić 0985043a6a Apply suggestions from code review
Co-authored-by: Denis Kasak <dkasak@termina.org.uk>
2023-03-14 17:01:03 +01:00
Damir Jelić 36b739b830 Improve the docs of the inbound group session type 2023-03-14 15:50:03 +01:00
Doug eeea4f23bc fix(bindings): More authentication service server name fixes
- Trim any trailing slashes
- If server name parsing fails, try as a URL instead of throwing
- Add tests
- Fix typo & clippy
2023-03-14 14:40:19 +00:00
Alfonso Grillo c9a6898c73 Add a guide for contributing to UniFFI bindings 2023-03-14 15:39:09 +01:00
Damir Jelić 18c33aefa1 Merge pull request #1633 from matrix-org/rav/fix_wait_if_user_pending
Fix races in `wait_if_user_pending`
2023-03-14 14:59:20 +01:00
Damir Jelić 2c7c251e47 Silence an invalid clippy warning 2023-03-14 14:45:19 +01:00
Damir Jelić f3ee6c735b Fix some formatting issue where cargo fmt failed to take care of things 2023-03-14 14:28:34 +01:00
Damir Jelić 4f9cb48ef8 Use a Display implementation to record the SequenceNumber in logs 2023-03-14 14:28:27 +01:00
Damir Jelić 9880619d81 Merge branch 'main' into rav/fix_wait_if_user_pending 2023-03-14 14:26:28 +01:00
Mauro a8204987be Add convenience methods for updating a room's avatar 2023-03-14 13:03:52 +00:00
Kévin Commaille cc585974e0 sdk: Get push actions of events received via back pagination
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-03-14 14:02:01 +01:00
Kévin Commaille aebd5fe4eb sdk: Fix timeline highlight test
Update Ruma to fix the server default push rules.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-03-14 14:02:01 +01:00
Mauro 7ab134233e bindings: Set pusher from client + notification service stub
Co-authored-by: ismailgulek <ismailg@matrix.org>
2023-03-14 13:36:36 +01:00
Kévin Commaille 0f54877b31 feat(sdk): Add methods to only send receipts newer than the current ones in the timeline
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-03-14 13:32:30 +01:00
Kévin Commaille 1c9aa7c907 refactor(sdk): Add private method to get the fully-read event for a timeline.
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-03-14 13:32:30 +01:00
Damir Jelić 4041c875d1 Merge pull request #1460 from matrix-org/andy/enhance_store
Store encryption settings
2023-03-14 12:36:42 +01:00
Andy Uhnak d226738d15 More pub(crate) methods 2023-03-14 10:43:40 +00:00
Andy Uhnak 404b95ab84 Missing migration method in UDL 2023-03-14 10:28:41 +00:00
Andy Uhnak 0d082f6b96 Update js tests 2023-03-14 10:28:15 +00:00
Andy Uhnak 5bf9182549 Fix issues after rebase 2023-03-14 10:28:15 +00:00
Andy Uhnak 1177bdd394 Indexdb migration 2023-03-14 10:28:15 +00:00
Andy Uhnak 98ca774118 Constrain store methods 2023-03-14 10:28:12 +00:00
Andy Uhnak 8f13023333 Missing stores 2023-03-14 10:27:11 +00:00
Andy Uhnak 51b3bf4c75 Add room settings migration 2023-03-14 10:27:11 +00:00
Andy Uhnak 283137f190 Introduce RoomSettings 2023-03-14 10:27:11 +00:00
Andy Uhnak 33b348c376 Constrain new api to Store struct 2023-03-14 10:27:11 +00:00
Andy Uhnak 7e7c91699f Generic key-value API 2023-03-14 10:27:11 +00:00
Andy Uhnak b4b111f91f Store encryption settings 2023-03-14 10:27:11 +00:00
Jonas Platte 0f7d839c49 Undo room_type => room_state rename in serialized form of RoomInfo 2023-03-13 16:45:44 +01:00
Jonas Platte ee6c0d9486 Simplify TimelineEvent construction 2023-03-13 16:31:19 +01:00
Jonas Platte 7121179b6a sdk: Make test code less repetitive 2023-03-13 16:31:19 +01:00
Jonas Platte 59edc22a35 Use Action covenience methods
Now Action::Coalesce will also generate a notification.
2023-03-13 16:31:19 +01:00
Jonas Platte e9058f58be Upgrade Ruma 2023-03-13 16:31:19 +01:00
Jonas Platte 7dee9648cf sdk: Clone VerificationRequest twice in generate_qr_code method again
… required for the returned Future to be Send.
2023-03-13 15:34:14 +01:00
Alfonso Grillo 786e9b5db9 Add createRoom UniFFI binding 2023-03-13 15:33:18 +01:00
valere e20db574ec Merge branch 'main' into valere/msc_2399 2023-03-13 14:51:23 +01:00
Ivan Enderlin c6c259144a chore(sdk): Rename enum variants to be consistent across all the modules. 2023-03-13 14:29:12 +01:00
Damir Jelić 58e99a645f Don't use a type alias for the sequence number
Using a wrapper type allows us to hide the internals a bit better and
we're now implementing Ord which is used in the comparison.
2023-03-13 14:17:12 +01:00
Damir Jelić 5d6cf2d33a Remove some clones when creating a /keys/query request
The part of code that converts a list of users to the actual
/keys/query request uses the chunks() method. This method operates on
the slice. Our list/vec of users gets dereferenced into a slice before
we create our chunks. The chunks can't take ownership of the data, which
in turn requires us to clone the user IDs for them to be put into the
request.

Itertools has a chunks() method which operates on an iterator which we
can utilize to remove, not only the clone, but also a collect call.

At the same time, let's make the conversion step a simple functional
mapping and document what's going on.
2023-03-13 14:17:12 +01:00
Damir Jelić 5f1a22e26f Remove some useless ? -> Ok invocations
We can just return the result directly instead of doing the error
conversion dance using the question mark operator
2023-03-13 14:17:12 +01:00
Damir Jelić 6afb6f1e27 Use an Option for the KeysQueryDetails instead of a default value
The Option conveys our intention a bit better compared to the default
value. While nothing bad can happen, since the request IDs map will be
empty by default, it's a bit scary to have a valid sequence number since
an i64 defaults to 0.
2023-03-13 14:17:12 +01:00
Ivan Enderlin 032356566e chore(sdk): Rewrite a small part of the code to make it clearer. 2023-03-13 14:07:36 +01:00
Ivan Enderlin d7468ec158 Update crates/matrix-sdk/src/sliding_sync/mod.rs
Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
2023-03-13 13:49:21 +01:00
Kévin Commaille 929538608a timeline: Expose if an event should be highlighted
Only events received via sync.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-03-13 13:47:06 +01:00
Kévin Commaille d5a56bcbc7 sdk: Expose calculated push actions for event handlers
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-03-13 13:47:06 +01:00
Kévin Commaille 84ff8980f3 sdk-base: Expose calculated push actions on event
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-03-13 13:47:06 +01:00
Jonas Platte 84d83dda0a base: Add RoomInfo::state accessor 2023-03-13 13:17:15 +01:00
Jonas Platte fb4b347433 base: Rename RoomType to RoomState 2023-03-13 13:17:15 +01:00
Richard van der Hoff e1c6ac9787 Merge branch 'main' into rav/fix_wait_if_user_pending 2023-03-13 11:52:11 +00:00
Ivan Enderlin 35bb18a1e8 feat(sdk): Add more Sliding Sync logs.
This patch adds more logs around `SlidingSync` to ease debugging sessions.
2023-03-13 11:41:20 +01:00
Ivan Enderlin 483bef0748 Merge pull request #1645 from Hywan/fix-sdk-fixme 2023-03-13 11:21:17 +01:00
Ivan Enderlin 3c25ad1489 doc(sdk): Remove a FIXME that is actually fixed.
The #1386 issue is closed. Yepee.
2023-03-13 09:05:32 +01:00
Jonas Platte 8d83a996a6 Handle another new clippy lint
Issue about false positives:
https://github.com/rust-lang/rust-clippy/issues/10482
2023-03-11 13:13:50 +01:00
Jonas Platte 595e34aad5 Silence new clippy lint for generated code 2023-03-11 13:13:50 +01:00
Jonas Platte cc35ee72b8 Upgrade eyeball to 0.4.0 2023-03-11 13:13:50 +01:00
Jonas Platte b148ea2fb1 Bump locked version of clap
To work around this clippy bug:
https://github.com/rust-lang/rust-clippy/issues/10421
2023-03-11 13:13:50 +01:00
Mauro 2bb66f0f2e bindings: Expose leave and reject_invitation functions to FFI 2023-03-10 18:07:13 +01:00
valere 8057a3691f unused import 2023-03-10 16:00:22 +01:00
valere 057cf0bde7 unneeded trait impl 2023-03-10 08:57:56 +01:00
valere c43d9d3e43 post rebase fix 2023-03-09 17:27:34 +01:00
Ivan Enderlin 331ea35be6 fix(sdk): SlidingSync has a lock for both pos _and_ delta_token
fix(sdk): `SlidingSync` has a lock for both `pos` _and_ `delta_token`
2023-03-09 17:10:42 +01:00
Richard van der Hoff fc9dbae23b fixup! Rewrite wait_if_user_pending to fix races 2023-03-09 16:06:37 +00:00
valere 9733d9842a Merge branch 'main' into valere/msc_2399 2023-03-09 17:04:21 +01:00
Ivan Enderlin b9fd451d54 feat(sdk): Move Client.root_span inside ClientInner
feat(sdk): Move `Client.root_span` inside `ClientInner`
2023-03-09 17:03:27 +01:00
Ivan Enderlin 3511a4a053 fix(sdk): SlidingSync has a lock for both pos _and_ delta_token.
This patch updates `SlidingSync.pos` and `.delta_token`. Each field has their
own lock. It's annoying because they must updated at the same time to not be
out-of-sync.

So a new field `SlidingSync.position` of type `SlidingSyncPositionMarkers` is
created. It holds `pos` and `delta_token. This new field is behind a single
`RwLock`.
2023-03-09 16:47:11 +01:00
Ivan Enderlin 7f52292e92 chore(sdk): Remove useless comment. 2023-03-09 16:43:41 +01:00
valere 980c9cb4f5 report partially withheld error as MissingRoomKey 2023-03-09 16:39:02 +01:00
valere 2368ac74de feat(withheld) expose withheld code in error binding 2023-03-09 16:38:38 +01:00
Ivan Enderlin cc69efc3f8 feat(sdk): Move Client.root_span inside ClientInner. 2023-03-09 15:12:11 +01:00
Richard van der Hoff 5a06c11ac0 Move UserKeyQueryResult to store
Now that `wait_if_user_key_query_pending` is in Store, it makes more sense that
the result type be in the same module.
2023-03-09 13:11:34 +00:00
Richard van der Hoff d2fdc20733 Rip out redundant KeysQueryListener 2023-03-09 13:11:34 +00:00
Richard van der Hoff 16871d1dcd Rewrite wait_if_user_pending to fix races 2023-03-09 13:11:34 +00:00
Richard van der Hoff 508f1bc976 Fix races between /sync and /keys/queries (#1619)
The comments in the code should explain the general approach, but to give an overview:

We assign a unique sequence number to each device-list-invalidation notice, and keep track 
of the sequence number at which each user was most recently invalidated. Then, when we 
build a `/keys/query` request, we take note of the current sequence number. Finally, when 
we get the response from that `/keys/query` request, we compare that sequence number
with the most-recent-invalidation of each user that is now supposedly up-to-date. All 
of that means that we can see if the user has been invalidated *since* we built the 
`/keys/query` request, in which case our request may have raced against the new device,
so we do not mark the user as up-to-date.

To make that work, we need to keep track of the sequence number for in-flight `/keys/query`
requests; we do that in the `IdentityManager`. Since there should only ever be at most one
batch of requests in flight, that is relatively easy; however, we also record the request ids
just to check that the application isn't doing something weird.

There is no need to persist the sequence numbers to permanent storage: provided the
`IdentityManager` and `Store` objects have a lifetime at least as long as an in-flight
`/keys/query` request, it is sufficient just to retain the `dirty` bit in permanent storage,
and then, when we reload the ephemeral `Store` cache, to treat everything with a `dirty`
bit as a "new" invalidation.

Fixes: #1386.
2023-03-09 10:57:20 +00:00
Ivan Enderlin 0419967158 doc(sdk): Rephrase the Quick refreshing Section.
With https://github.com/matrix-org/matrix-rust-sdk/pull/1601, it's safer to
cancel a stream at any time, as any `Future` cancellation. This documentation
section of `SlidingSync` is no longer relevant as is, and can be rephrased.
2023-03-09 11:56:33 +01:00
Ivan Enderlin da5c79482b feat(ffi): Rethink TaskHandle
feat(ffi): Rethink `TaskHandle`
2023-03-08 17:21:52 +01:00
Ivan Enderlin 4996a19b31 feat(ffi): Rethink TaskHandle.
With https://github.com/matrix-org/matrix-rust-sdk/pull/1601,
`TaskHandle::with_callback` is no longer necessary.

This patch updates `TaskHandle` as follows:

1. Before, the `handle` and `callback` fields were not mutually exclusive!
   Indeed, the `callback` field was used as an abort mechanism, but _also_ as a
   finalizer, i.e. a code that runs _after_ the cancellation of `handle`. Now
   that the callback-based solution is no longer used, we can keep one usage for
   this field and rename it `finalizer`.
2. The `handle` field is no longer optional, as it will always be set.
3. The `with_callback` method is renamed `new` as it's now the only constructor.
4. The `set_callback` method is renamed `set_finalizer`.

Tadaaa.
2023-03-08 17:09:47 +01:00
Ivan Enderlin d720861fbd fix(bindings): SlidingSync.sync returns an immediately cancellable TaskHandle
fix(bindings): `SlidingSync.sync` returns an immediately cancellable `TaskHandle`
2023-03-08 16:39:09 +01:00
Ivan Enderlin c517f38ec8 sliding-sync: process receipt extension response
sliding-sync: process receipt extension response
2023-03-08 16:29:56 +01:00
Ivan Enderlin ac863409bb doc(sdk): Remove notion of fairness. 2023-03-08 16:20:50 +01:00
Kegan Dougal 417008cc87 Clippy 2023-03-08 15:14:59 +00:00
Ivan Enderlin 5dd404d2f1 doc(sdk): Precise in which order SS responses will be handled. 2023-03-08 16:09:05 +01:00
Kegan Dougal 2c0466a8cc Unbreak tests; don't shadow 2023-03-08 15:03:41 +00:00
kegsay aec65c818b Update testing/sliding-sync-integration-test/src/lib.rs
Co-authored-by: Ivan Enderlin <ivan@mnt.io>
2023-03-08 14:51:26 +00:00
Jonas Platte 0d9d130833 Replace StateStoreDataKey::encoding_key by associated constants 2023-03-08 15:51:13 +01:00
Jonas Platte 26e259455a Adhere to module naming conventions 2023-03-08 15:51:13 +01:00
Ivan Enderlin 2f637cda6f doc(sdk): Add note about fairness of the SS lock. 2023-03-08 15:33:40 +01:00
Ivan Enderlin 64ae77ec70 feat(sdk): Run SS response handling in a single non-cancellable block. 2023-03-08 15:15:16 +01:00
Jonas Platte 932cf2ad99 Fix experimental features not compiling without encryption 2023-03-08 15:03:20 +01:00
Jonas Platte 68f8ed5a92 Add futures-util as a workspace dependency
… and always activate its `alloc` feature.
Fixes building matrix-sdk without the e2e-encryption feature.
2023-03-08 15:03:20 +01:00
Kegan Dougal 4670142a83 Clippy 2023-03-08 13:21:56 +00:00
Kegan Dougal 9a53602d73 Formatting 2023-03-08 12:58:48 +00:00
Kegan Dougal 48bf20fcca Add integration test for receipts in sliding sync 2023-03-08 12:53:23 +00:00
Mauro be6c7c8b4c Add user avatar URL caching 2023-03-08 13:30:46 +01:00
Ivan Enderlin 832146b43d feat(sdk): Create SlidingSyncInner.
Move all `SlidingSync`'s fields into a new `SlidingSyncInner` type, and then
update `SlidingSync` to contain a single `inner: Arc<SlidingSyncInner>` field.

First off, it's much simpler to understand what's behind an `Arc` for
“clonability” of `SlidingSync`, and what's not. We don't need to worry about
adding a new field that is not behind an `Arc` for a specific reason or
anything. The pattern is clear now.

Second, this is required for next commits.
2023-03-08 12:12:58 +01:00
Ivan Enderlin 66d4ced90f chore: Add some inline documentation. 2023-03-08 12:01:57 +01:00
Jonas Platte 5c2915bb6a crypto-ffi: Use uniffi derives for types no longer referenced in UDL 2023-03-08 11:12:11 +01:00
Jonas Platte fb23cbff97 crypto-ffi: Use UniFFI proc-macros for more OlmMachine methods 2023-03-08 11:12:11 +01:00
Jonas Platte 9fe880d05d Clean up formatting of olm.udl 2023-03-08 11:12:11 +01:00
Jonas Platte 7af2bea2fc Upgrade UniFFI 2023-03-08 11:12:11 +01:00
Kegan Dougal f1829faa99 Merge branch 'main' into kegan/receipts-ss 2023-03-08 09:33:48 +00:00
valere a767187ff6 add more tests 2023-03-08 10:06:46 +01:00
Ivan Enderlin 7369010964 feat(sdk): Make SlidingSync::handle_response _sync_, no more _async_.
The idea is to group all async and await points in `sync_once`. It's easier to
think about it.
2023-03-08 09:41:32 +01:00
Ivan Enderlin 07f6a3b345 chore: Remove warnings. 2023-03-08 09:35:47 +01:00
Ivan Enderlin 8f6f20bbe7 fix(bindings): SlidingSync.sync returns an immediately cancellable TaskHandle.
Before this patch, `SlidingSync::sync` was returning a callback-based
`TaskHandle`. It was waiting on the “stream loop” to finish (since it's a long-
poll, it means waiting 2*30s, cf. our code), before checking an atomic flag has
some value to decide whether it was time to leave the loop or not. So when the
user is cancelling this `TaskHandle`, a response (if any) was always handled.
But in the meantime, it was possible to start a new `sync`, and it seems like
it creates bugs.

After this patch, `SlidingSync::sync` now returns a handle-based `TaskHandle`.
It means that cancelling it will cancel the “stream loop” immediately. If
no response was in-flight from the server, that's perfect, no problem. If a
response was in-flight, the inner `pos` of the `SlidingSync` instance won't be
updated as the response won't be handled. So the server will re-send the same
response with the next sync request.

I guess it's better this way. Thoughts?
2023-03-08 09:35:47 +01:00
Ivan Enderlin 6a9cf1f9ce feat(sdk): SlidingSync::stream can match expected responses
feat(sdk): `SlidingSync::stream` can match expected responses
2023-03-08 09:14:32 +01:00
Ivan Enderlin f8ce49cc49 chore: Add documentation. 2023-03-08 08:56:38 +01:00
Ivan Enderlin 46d71acb44 chore: Update ruma to a specific revision. 2023-03-08 08:56:38 +01:00
Ivan Enderlin 9f0563eb95 feat(sdk): SlidingSync::stream can match expected responses.
This patch adds a new feature.

Each call to `SlidingSync::stream` generates a unique `stream_id`. This
`stream_id` is passed to requests as a `txn_id` field. Returned responses must
hold the same `txn_id`, otherwise it means `stream` has received unexpected
responses from another `stream` or something else.

So far, when the `txn_id` field of the response and the `stream_id` don't
match, a log with the `ERROR` level is raised. Should we do more, like ignoring
the response entirely? Not sure yet.
2023-03-08 08:56:32 +01:00
valere bd48cae28d unused import 2023-03-07 19:24:50 +01:00
valere 69749ab8fe feat(withheld) fix experimental-algorithms 2023-03-07 19:07:27 +01:00
valere 97b5a3a61b feat(withheld) cleaning 2023-03-07 19:04:44 +01:00
valere 0ec3aca727 refactor(withheld) store withheld as ShareInfo
and store no_olm sent in device
2023-03-07 18:46:52 +01:00
Kévin Commaille 18e6f10367 examples: Also handle SSO login in the login example
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-03-07 15:12:33 +01:00
Kévin Commaille d77efd7327 state-store: Replace methods to get and set key-value data
Avoid to make the API bigger when we want to add new key-value data
in the store.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-03-07 13:52:37 +01:00
Kévin Commaille 5b28c69cfc sled: Rename session store to kv
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-03-07 13:52:37 +01:00
Kévin Commaille 61796a2725 sled: Move state store keys into keys module
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-03-07 13:52:37 +01:00
Kévin Commaille f538b5e595 sled: Move the state store migrations to a separate file
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-03-07 13:52:37 +01:00
Kévin Commaille 4d1363e683 indexeddb: Merge session and sync_token stores into new kv store
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-03-07 13:52:37 +01:00
Damir Jelić 9324702b04 feat(bindings): Add a method to partially migrate data 2023-03-07 13:29:00 +01:00
Jonas Platte 0c4c73084d Appease clippy 2023-03-07 12:53:32 +01:00
Jonas Platte 6ce51b5890 Remove unnecessary allow attribute 2023-03-07 12:53:32 +01:00
Jonas Platte 3ff1844da4 base: Remove unused Deserialize implementation 2023-03-07 12:53:32 +01:00
Jonas Platte 99cbf3122b ci: Work around frequent codecov upload errors 2023-03-07 11:08:09 +01:00
Kévin Commaille e09ec389d1 indexeddb: Fix migration of state store
The IndexedDB API expects an unsigned integer for the version.
The web-sys bindings expose it as a f64 so versions like 1.1 and 1.2
were used. The were converted back to uint in JS which means the version
was always 1.0 and no real upgrade was processed

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-03-07 10:04:09 +01:00
Kévin Commaille 2aec3d0502 indexeddb: Move the state store migrations to a separate file
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-03-07 10:04:09 +01:00
Damir Jelić 2f974c11f7 Simplify handling of sliding sync extensions
Simplify handling of sliding sync extensions

This patch simplifies the logic for handling sliding sync extensions.
These extensions are sticky, meaning that once enabled in one request,
they do not need to be repeatedly enabled for subsequent requests.

However, the previous logic tried to accommodate the case where the
extensions were initially disabled to reduce the size and processing
time of the initial response. This resulted in complex and error-prone
code.

With this patch, we have removed support for disabling to-device events
and streamlined the handling of sync extensions.

Co-authored-by: Jonas Platte <jplatte@matrix.org>
2023-03-07 08:48:05 +01:00
Richard van der Hoff 79ee4b59ee matrix-sdk-crypto: enable tracing for in-crate tests 2023-03-06 19:25:47 +01:00
Jonas Platte 01a66d4874 Fix unnecessary cfg(all()) 2023-03-06 18:25:16 +01:00
valere 1ddcc97f84 refactor(withheld) collect_session_recipient result struct 2023-03-06 12:23:10 +01:00
valere c6a12304ba refactor(msc2399) avoid iterating twice on devices 2023-03-06 11:46:37 +01:00
Jonas Platte 50114f4e74 Mention changelogs in PR template 2023-03-06 10:41:18 +01:00
Jonas Platte 792b60c501 Remove most mentions of conventional commits 2023-03-06 10:41:18 +01:00
Jonas Platte d8465a2c1e Add a very basic changelog to crates/matrix-sdk 2023-03-06 10:41:18 +01:00
Damir Jelić 8550eaeed0 Make sure that syncing members is only happening if they aren't already synced 2023-03-06 10:00:00 +01:00
Damir Jelić 071ba2376e Make the majority of fields of the RoomInfo private 2023-03-06 10:00:00 +01:00
Damir Jelić 7ec98ff721 Remove a race condition when fetching members and sending out room keys 2023-03-06 10:00:00 +01:00
Florian Renaud f03f7c8d1a Fix a typo in the integration tests readme 2023-03-06 09:29:23 +01:00
Stefan Ceriu 0dd2b12141 chore(ffi): Remove now unnecessarly stored is_soft_logout session and client state property. The did_receive_auth_error(is_soft_logout) client delegate is enough. 2023-03-03 18:10:57 +01:00
Stefan Ceriu d513cb9a47 chore(ffi): remove now unused start_sync method and related properties 2023-03-03 18:10:57 +01:00
Stefan Ceriu e550c16c14 Broadcast UnknownToken API client errors, handle them on the FFI client side and send a did_receive_auth_error delegate call 2023-03-03 12:13:26 +01:00
Sam Wedgwood 0da29057f8 feat(sdk): Expose prepare_encrypted_file function
Signed-off-by: Sam Wedgwood <sam@wedgwood.dev>
2023-03-03 09:27:10 +00:00
Kegan Dougal 5881503a6a Clippy 2023-03-02 14:49:16 +00:00
kegsay e261d37756 Apply suggestions from code review
Co-authored-by: Jonas Platte <jplatte@matrix.org>
2023-03-02 14:48:00 +00:00
Richard van der Hoff a2da63758c Use a separate GHA cache for each matrix build (#1605)
You can't update a GHA cache once you create it, so if we use the same cache
for each job in a matrix build, then we end up populating it for the first job
that completes, so any slower jobs don't get their dependencies cached.

On the other hand, if we create 20 500MB cache items on each build, we're going
to exhaust the cache storage as soon as we do a build. So, instead, let's just
do the caching for the main branch, and hope that other branches can still
benefit from it.
2023-03-02 14:10:53 +00:00
Richard van der Hoff a86754a317 Minor tweaks to the github actions configurations (#1606)
* Replace custom cancellation action with `concurrency`

* Improve step names

... so don't have three steps with the same name

* Bump version of checkout action

checkout@v2 uses an old version of nodejs, which is deprecated.
2023-03-02 14:04:59 +00:00
Kegan Dougal 5c3d02cb89 sliding-sync: process receipt extension response
Needs some kind of tests, but this should do the trick.
2023-03-02 13:53:11 +00:00
Kévin Commaille e84a43dbaa Split StateStore integration tests into a trait
To declare the tests, the macro is still used but the content of the
tests is moved in the StateStoreIntegrationTests trait.

Allows to get the proper line reported when a panic occurs,
and have linting, formatting and IDE suggestions.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-03-02 14:35:51 +01:00
Richard van der Hoff 2fe08a90c5 Reinstate protoc for a couple of GHA jobs (#1607)
Looks like #1604 broke the build :(
2023-03-02 12:47:58 +00:00
Richard van der Hoff bdb9d274ce Skip installing protoc where it is unneeded (#1604)
This seems to have been cargo-culted to lots of places where it is redundant.
2023-03-01 22:17:36 +00:00
Ivan Enderlin 862b4a3df7 chore(bindings): Clean up and code simplification on matrix_sdk_ffi::sliding_sync
chore(bindings): Clean up and code simplification on `matrix_sdk_ffi::sliding_sync`
2023-03-01 20:12:45 +01:00
Ivan Enderlin 1dccea8735 doc: Fix a typo. 2023-03-01 19:59:55 +01:00
Ivan Enderlin e1fe1279c2 Merge pull request #1598 from Hywan/chore-sdk-sliding-sync-list-cleanup
chore(sdk): Various clean up on Sliding Sync (List)
2023-03-01 16:56:57 +01:00
Richard van der Hoff 15513b0ada Clean up the way we build xtask in CI (#1600)
Currently, the cache of the xtask binary isn't working terribly well:

* we seem to build it on each run anyway, presumably because we don't cache any of the intermediate build
   artifacts. Running the binary directly rather than indirecting via "cargo" prevents this.
* There is no sharing of the cache between the "rust" and "bindings" CI, because we use different cache keys.

This PR addresses both problems, and hopefully speeds up CI a bit as a result.
2023-03-01 15:50:31 +00:00
Jonas Platte c9e6d3e2dc Make RemoteEventTimelineItem fields private, provide methods instead 2023-03-01 16:45:43 +01:00
Jonas Platte 400879c819 Make LocalEventTimelineItem fields private, provide methods instead 2023-03-01 16:45:43 +01:00
Jonas Platte aac9d9c29b Move TimelineItemContent and related types into a new submodule 2023-03-01 16:45:43 +01:00
Jonas Platte 770a67678c Move RemoteEventTimelineItem into its own module 2023-03-01 16:45:43 +01:00
Jonas Platte 1452a2124f Move LocalEventTimelineItem into its own module 2023-03-01 16:45:43 +01:00
Jonas Platte daa3b80870 Re-export and document LocalEventTimelineItem, RemoteEventTimelineItem 2023-03-01 16:45:43 +01:00
Ivan Enderlin ccd9ad7b49 chore(bindings): Simplify the code.
Rust is a beautiful language. Let's use all the great constructions it gives to
us to write pretty code.
2023-03-01 16:42:47 +01:00
Ivan Enderlin 4212980f32 chore(bindings): Remove a From<JoinHandle> for TaskHandle impl.
This implementation is never used.
2023-03-01 16:42:09 +01:00
Ivan Enderlin 9b1c5079e6 chore: cargo fmt. 2023-03-01 15:58:22 +01:00
Ivan Enderlin a341caa773 chore(sdk): Continue the move from view to list in Sliding Sync. 2023-03-01 15:46:40 +01:00
Ivan Enderlin b4bf544676 test: Continue the move from view to list in Sliding Sync. 2023-03-01 15:43:59 +01:00
Ivan Enderlin bfb55d782f chore(sdk): Clean up rooms_ops. 2023-03-01 15:38:15 +01:00
Ivan Enderlin 3bad2a84ad chore(sdk): Remove SlidingSyncListRequestGenerator::live_request. 2023-03-01 15:17:53 +01:00
Ivan Enderlin 866c91ffbc chore(sdk): Simplify code of Sliding Sync request generator. 2023-03-01 15:17:31 +01:00
Ivan Enderlin c03ba55f24 chore(sdk): Rename InnerSlidingSyncListRequestGenerator to GeneratorKind. 2023-03-01 15:04:37 +01:00
Ivan Enderlin 1f5c4feafc chore(sdk): Extract Sliding Sync request generators into their own module. 2023-03-01 15:01:02 +01:00
Ivan Enderlin 6d2055449d chore(bindings): Continue to rename view to list in Sliding Sync. 2023-03-01 14:51:34 +01:00
Ivan Enderlin f5cc6feccd chore(sdk): Split the list.rs module into list/mod.rs and list/builder.rs. 2023-03-01 14:43:58 +01:00
Ivan Enderlin c5d5deba8e chore: Continue the renaming from view to list for Sliding Sync. 2023-03-01 14:39:09 +01:00
Ivan Enderlin d829fd3376 chore(bindings): Continue the renaming from view to list for Sliding Sync. 2023-03-01 14:38:43 +01:00
Ivan Enderlin 50a248c18b chore(sdk): Continue the renaming from view to list for Sliding Sync. 2023-03-01 14:38:26 +01:00
Ivan Enderlin c366eadf33 chore(sdk): Rename variables, clean up code, improve documentation… 2023-03-01 14:35:46 +01:00
Jonas Platte 318ede131d refactor(indexeddb): Use IndexeddbStateStoreError in StateStore impl 2023-03-01 14:30:13 +01:00
Jonas Platte 146db59370 refactor(base): Add an Error type to StateStore trait 2023-03-01 14:30:13 +01:00
Ivan Enderlin 97dd68e7fc fix(sdk): Deal with missing data in Sliding Sync's responses
fix(sdk): Deal with missing data in Sliding Sync's responses
2023-03-01 14:24:24 +01:00
Ivan Enderlin 4e4c745032 chore(sdk): Update all mentions to view as list in SlidingSyncList. 2023-03-01 14:20:44 +01:00
Ivan Enderlin f03767318f chore(sdk): Update all mentions to view as list in SlidingSync and SlidingSyncBuilder. 2023-03-01 14:18:40 +01:00
Ivan Enderlin cf83112bf0 chore(sdk): Move FrozenSlidingSyncList lower in the file. 2023-03-01 13:58:55 +01:00
Ivan Enderlin 575eea4701 fix(sdk): Deal with missing data in Sliding Sync's responses.
The Sliding Sync server might not send some parts of the response, because they
were sent before and the server wants to save bandwidth. So let's update values
only when they exist.
2023-03-01 12:19:30 +01:00
Ivan Enderlin 5377bb7ecf fix(sdk): Rename SlidingSyncView to SlidingSyncList.
The specification describes “list”, not “view”. Consistency is important, so
let's rename this type!
2023-03-01 12:09:34 +01:00
Ivan Enderlin 629b74e4f5 chore(sdk): Rename the sliding_sync::view module to …::list. 2023-03-01 11:56:01 +01:00
Ivan Enderlin 9475bb4d53 chore(indexeddb): Update version of uuid
chore(indexeddb): Update version of `uuid`
2023-03-01 09:09:15 +01:00
Ivan Enderlin 452588a18e chore(indexeddb): Update version of uuid. 2023-03-01 08:26:28 +01:00
Stefan Ceriu ff5dedbb07 fix(sliding_sync): Prevent PagingFullSync and GrowingFullSync from going over the total room count 2023-02-28 18:32:11 +01:00
valere 6539dc3060 quick typo 2023-02-28 17:53:54 +01:00
valere 7b8608e4c5 refactor(withheld) better type for no_olm 2023-02-28 17:38:37 +01:00
Stefan Ceriu 5c3972938e chore: Add platform versions for swift CI tests 2023-02-28 15:06:23 +01:00
Jonas Platte b936d3e32d chore: Remove workaround for clippy bug that was fixed 2023-02-28 12:36:08 +01:00
Kévin Commaille da8d74ccc1 feat(sdk): Keep track of events read receipts in the timeline API
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-02-28 09:44:35 +01:00
Kévin Commaille 6aad2a661d refactor(sdk): Rename ProfileProvider to RoomDataProvider
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-02-28 09:44:35 +01:00
Kévin Commaille 3139204f4b fix(examples): Don't use the sled store if the session is not persisted
Running the same example twice
borks encryption.
Instead point to an example that shows how to do it.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-02-28 09:20:53 +01:00
Kévin Commaille 1684dbe0a1 feat(examples): Add example to persist a session
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-02-28 09:20:53 +01:00
Doug 9531dc195a fix(bindings): Fix double quotes when replying to a reply. 2023-02-27 18:23:49 +01:00
Sam Wedgwood abab6dcf0f docs(crypto): Fix typo
Signed-off-by: Sam Wedgwood <sam@wedgwood.dev>
2023-02-27 15:39:01 +00:00
Ivan Enderlin d699161981 chore(sdk): Code reorganization of the sliding_sync module + doc improvement
chore(sdk): Code reorganization of the `sliding_sync` module + doc improvement
2023-02-27 15:27:08 +01:00
Ivan Enderlin 927c44bec3 doc(sdk): Fix doctests + remove mentions to futures-signals. 2023-02-27 15:08:13 +01:00
Ivan Enderlin 96248248ca chore(sdk): Move UpdateSummary at the bottom of the module. 2023-02-27 13:56:04 +01:00
Ivan Enderlin b7b86fa95b fix(sdk): Few fixes and cleans up of SlidingSync itself
fix+chore(sdk): Few fixes and cleans up of `SlidingSync` itself
2023-02-27 13:50:48 +01:00
Ivan Enderlin 4f7186a840 chore(sdk): Simplify the implementation of RoomListEntry. 2023-02-27 13:49:34 +01:00
Ivan Enderlin 9b062fa782 chore(sdk): Move RoomListEntry into the sliding_sync::view module. 2023-02-27 13:43:40 +01:00
Ivan Enderlin 4d8c3172a4 chore(sdk): Extract Error into its own module. 2023-02-27 13:42:01 +01:00
Ivan Enderlin b1c9ea9aa3 chore(sdk): Move SlidingSyncMode into the sliding_sync::view module. 2023-02-27 13:38:54 +01:00
Ivan Enderlin 49eee14665 chore(sdk): Move SlidingSyncState into the sliding_sync::view module. 2023-02-27 13:38:09 +01:00
Ivan Enderlin 6cec946401 chore(sdk): Improve documentation of SlidingSync. 2023-02-27 13:36:08 +01:00
Jonas Platte d06e8ccfc5 refactor: Upgrade eyeball and use SharedObservable
… but not in sliding sync yet, where some planned refactorings might
conflict with this.
2023-02-27 13:29:28 +01:00
Ivan Enderlin ac1d5afac3 doc(sdk): Improve inline documentation with link to an issue. 2023-02-27 13:29:03 +01:00
Ivan Enderlin f51b51b19e chore(sdk): Avoid mapping to a function returning (). 2023-02-27 12:14:01 +01:00
Ivan Enderlin 16c9845a47 chore(sdk): Rename SlidingSync.failure_count to .reset_counter.
This patch cleans up the `SlidingSync::stream` method. It renames variables,
improves log messages etc.

This patch also creates a new `MAXIMUM_SLIDING_SYNC_SESSION_EXPIRATION`
constant. This value was previously hardcoded and lost in the code, now it's
easier to spot it for further updates.

This patch finally renames the `failure_count` field to `reset_counter`,
because it doesn't count the number of failure, but the number of
`ErrorKind::UnknownPos` exactly, i.e. the number of times we reset the
`SlidingSync` state.
2023-02-27 12:09:14 +01:00
Ivan Enderlin 4dbd1a7db4 fix(sdk): Fix join in SlidingSync::sync_once.
This patch cleans up the `SlidingSync::sync_once` method by renaming variables,
adding more comments, simplifying the code by reducing the number of variables
etc.

This patch also changes `futures_util::join!` to `futures_util::future::join`.
It does the same but the macro needs the `async-await-macros` feature to be
turned on, while the second works without any features.

Finally, this patch improves the log messages by making them more clear for a
new reader.
2023-02-27 11:56:16 +01:00
Ivan Enderlin e5c85410a8 doc(sdk): Fix documentation, add links etc. 2023-02-27 11:54:48 +01:00
Ivan Enderlin 98ea3f096b chore(sdk): Clean up code of SlidingSync::cache_to_storage. 2023-02-27 11:54:13 +01:00
Anderas f0986643ce chore(crypto): Log Olm session identifiers
Co-authored-by: Damir Jelić <poljar@termina.org.uk>
2023-02-27 10:59:30 +01:00
valere f4d4d96c8e support migration for outbound after withheld addtition 2023-02-27 09:56:56 +01:00
Ivan Enderlin b214a0e098 feat(sdk): Remove clones of large responses in Sliding Sync
feat(sdk): Remove clones of large responses in Sliding Sync
2023-02-27 09:47:26 +01:00
Ivan Enderlin 70380a6ee4 doc(sdk): Improve documentation of SlidingSync::handle_response. 2023-02-27 09:30:50 +01:00
valere 39997376af fix js binding test 2023-02-25 16:33:16 +01:00
valere 58fa9d7767 fix ci 2023-02-25 16:18:06 +01:00
valere ad18ecc2c1 cleaning 2023-02-25 10:50:37 +01:00
valere ff500fc707 fix unused result 2023-02-25 10:39:17 +01:00
valere 76a286c91d feat(withheld) sled store support 2023-02-25 10:31:23 +01:00
valere 6cc31a0e13 fix clippy 2023-02-24 17:15:51 +01:00
valere 228b963f74 feat(withheld) fix indexeddb test 2023-02-24 16:39:37 +01:00
Jonas Platte 1783cd7738 test: Remove unused constant 2023-02-24 12:39:55 +01:00
Jonas Platte 32e8cb76b0 ci: Remove unused FeatureSet variant 2023-02-24 12:39:55 +01:00
valere 81c9f57e02 clippy fix 2023-02-23 18:02:45 +01:00
Benjamin Kampmann e162c99074 feat: Handy function to update power levels of a room 2023-02-23 17:53:48 +01:00
Benjamin Kampmann 6465398322 feat: expose power_levels.user_can_do on RoomMember 2023-02-23 17:53:48 +01:00
valere 6b948711b9 feat(withheld) Integration tests 2023-02-23 17:47:57 +01:00
Ivan Enderlin f803e58e36 chore(sdk): Keep to_remove inside its own scope. 2023-02-23 16:53:16 +01:00
Ivan Enderlin 23b3e3aa10 chore(sdk): Format code a little bit. 2023-02-23 16:40:48 +01:00
Ivan Enderlin fcfdf5c57c chore(sdk): Rename a variable in SlidingSync::handle_response. 2023-02-23 16:40:48 +01:00
Ivan Enderlin 3b01e4f9a6 chore(sdk): Use T::default instead of Default::default. 2023-02-23 16:39:56 +01:00
Ivan Enderlin 3c44f87bee doc(sdk): Simplify one documentation. 2023-02-23 16:39:39 +01:00
Ivan Enderlin af6cd85cf4 chore(sdk): SlidingSyncRoom::new no longer needs a mutable inner. 2023-02-23 16:27:19 +01:00
Ivan Enderlin 54654aa0c7 chore(sdk): Simplify references, thanks Clippy. 2023-02-23 16:03:11 +01:00
Ivan Enderlin 778d1211c7 feat(bindings): Replace many scripts by one xtask
Ganfra/kotlin binding scripts
2023-02-23 15:58:40 +01:00
Ivan Enderlin c69d28ef79 feat(sdk): Remove clones of large responses in Sliding Sync.
I admit this patch is quite tricky. Please try to follow me.

So, first off, in `SlidingSyncRoom::new`, we were clearing the timeline,
because somehow it exists twice in memory at this step.

Which led me to understand how `SlidingSync::handle_response` was working.
I've clarified how this part of the code works. We are dealing with 2 kind of
responses for a specific reason: `SyncResponse` and `v4::Response`, now it's
documented and I hope it's clearer.

Then, I notice that we were passing a clone of the entire sliding sync
response (`v4::Response`) to `Client::process_sliding_sync`. I thought it was
suboptimal, so I've updated the code to take a reference. It led me to update
`BaseClient::process_sliding_sync`. It was a little bit tricky, but I reckon we
have less clones now than before.

And now, back to `SlidingSync::handle_response`, I was able to compute the
`timeline` correctly by draining it from the `v4::Response`, or by moving it
from `SyncResponse`. So it's no longer necessary to have this clearing code
inside `SlidingSyncRoom::new`. Honestly it has nothing to do at this place
before.

To conclude: We have cleaner code, and less clones.

What thing I reckon could be optimized, is that the entire `timeline`
(`Vec<TimelineEvent>`) is cloned to be passed to `Client::handle_timeline`. So
this timeline exists in 2 places: in Sliding Sync, and somewhere else. I don't
believe it's a problem now, that's how it works, but we must be aware of that.
2023-02-23 15:21:21 +01:00
Jonas Platte d0c8ec7a22 refactor: Replace remaining usage of futures-signal with eyeball(-im) 2023-02-23 15:08:41 +01:00
Doug 01e3a31a11 fix(bindings): Verify entered homeserver before proxy availability
The reported errors weren't that helpful to the user.
Additionally attempt discovery when a URL is entered before falling back to the URL directly.
2023-02-23 12:12:53 +00:00
ganfra 83dcb0eb48 xtask kotlin : fix formatting 2023-02-23 11:53:32 +01:00
Jonas Platte 6c92bf8745 refactor(sdk): Remove unused dependency 2023-02-23 11:47:51 +01:00
Jonas Platte ba6fc794b0 refactor(base): Replace futures-signals with eyeball 2023-02-23 11:47:51 +01:00
Jonas Platte 17b86b7c38 refactor(crypto): Replace futures-signals with eyeball 2023-02-23 11:47:51 +01:00
valere 9894d3c72d feature(withheld) indexeddb store implem 2023-02-23 10:13:32 +01:00
boxdot d5154577a0 feat(sdk): Add custom login method
The `Client::login_custom` allows to login by using a custom login
method. In particular, it is possible to login to Synapse which supports
JWT authentication.

Signed-off-by: boxdot <d@zerovolt.org>
2023-02-23 08:16:04 +01:00
Ivan Enderlin 5be00d5950 chore(sdk): Many clean ups in SlidingSync
chore(sdk): Many clean ups in `SlidingSync`
2023-02-22 20:16:54 +01:00
Ivan Enderlin f3928e8d35 chore(sdk): Remove an unnecessary clone in SlidingSyncRoom::update. 2023-02-22 20:03:11 +01:00
Ivan Enderlin c766d8b3ef chore(sdk): Address PR feedback. 2023-02-22 20:00:49 +01:00
Ivan Enderlin 4d33fe1c31 chore(sdk): Rename some variable inside FrozenSlidingSyncRoom. 2023-02-22 19:59:57 +01:00
Ivan Enderlin e80713e933 chore(sdk): SlidingSyncRoom::update takes ownership of room_data.
First off, it's not necessary for `SlidingSyncRoom::update` to take a reference
to `room_data: v4::SlidingSyncRoom`. When `update` is called, the iterator owns
its items.

Second, by taking ownership of `room_data`, we no longer need to clone all the
data we need to assign to `self.inner`.
2023-02-22 19:59:57 +01:00
Ivan Enderlin 5d356ca1b5 feat(sdk): Avoid locking prev_batch in SlidingSyncRoom::timeline_builder. 2023-02-22 19:59:57 +01:00
Ivan Enderlin 56daa6cb8f chore(sdk): Rename SlidingSyncRoom pub(crate) from to pub(super) new.
First off, `SlidingSyncRoom.from` doesn't need to be visible to the entire
crate, only to `crate::sliding_sync.

Second, it's a constructor, so let's call it `new`.
2023-02-22 19:59:43 +01:00
Kévin Commaille bcc04bdf35 feat(sdk): Add conversion from EventTimelineItem and VirtualTimelineItem to TimelineItem
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-02-22 16:59:22 +00:00
Ivan Enderlin ebe8ce3177 feat(sdk): Make SlidingSync.pos already private
feat(sdk): Make SlidingSync.pos already private
2023-02-22 17:42:30 +01:00
Ivan Enderlin 1d02515186 chore(sdk): Re-organizing the code inside sliding_sync::room.
1. Put `FrozenSlidingSyncRoom` at the bottom of the module.
2. Put merge 2 `impl SlidingSyncRoom` together.
3. Remove the `AliveRoomTimeline` type alias.
4. Improve the documentation.
2023-02-22 17:38:37 +01:00
Ivan Enderlin 0abef77408 doc(sdk): Improve documentation of SlidingSyncBuilder. 2023-02-22 17:29:40 +01:00
Jonas Platte fe7f157253 refactor(bindings): Use UniFFI proc-macros for CrossSigningStatus 2023-02-22 17:21:21 +01:00
Ivan Enderlin 5a62ec3fc1 chore(ffi) Rename StoppableSpawn to TaskHandle
chore(ffi) Rename `StoppableSpawn` to `TaskHandle`
2023-02-22 17:11:36 +01:00
Ivan Enderlin 5727726e5d feat(sdk): Make SlidingSync.pos already private.
So far, the `SlidingSync.pos` field was public to the crate. In order to avoid
breaking the internal state of this type, its visibility is now private.

However, we need to be able to change the value when testing the
`SlidingSync` type itself. To achieve that, this patch removes the old
`force_sliding_sync_pos` function, and implements 2 new functions: `set_pos`
and `pos` directly on `SlidingSync` only when `#[cfg(any(test, feature ="testing"))]`.
2023-02-22 17:07:50 +01:00
Ivan Enderlin dec4b2122b doc(sdk): Improve documentation of SlidingSyncMode. 2023-02-22 16:51:42 +01:00
Ivan Enderlin cfcafc8425 chore(ffi) Rename StoppableSpawn to TaskHandle.
Because it is what it is.
2023-02-22 16:48:46 +01:00
valere 42934ea7e4 feature(withheld) ffi bindings 2023-02-22 15:46:56 +01:00
kegsay 7e64c15145 fix: look for the right list when waiting for updates
Otherwise it will time out after 30s and then continue executing,
causing a slow test.
2023-02-22 14:42:32 +00:00
valere e56d380f65 fix store after rebase 2023-02-22 14:28:20 +01:00
ganfra f72d9c2016 Merge branch 'main' into ganfra/kotlin_binding_scripts 2023-02-22 13:31:56 +01:00
Jonas Platte 95f1867816 chore: Delete sled-state-inspector
The sled store is on its way out and nobody is using this.
2023-02-22 13:17:01 +01:00
Jonas Platte b1062a67e0 fix(sdk): Rewrite decryption retrying to fix invalid index bug
Previously, it was possible for us to use invalid indices when:

- We retried decrypting multiple events at once
- One of them (not the last) was an edit or reaction

This lead to a situation where we would remove the UTD item once
decryption for it was successfully retried, but not account for the
resulting index shift for all later timeline items.
2023-02-22 12:44:11 +01:00
Janne Heß 02a213c1b5 feat(sdk): Add support to change display names of devices
Signed-off-by: Janne Heß <janne.hess@helsinki-systems.de>
2023-02-22 10:55:54 +00:00
Archit Bhonsle 64ec5ec561 feat(crypto): Expose and re-expose the version of the matrix-sdk-crypto crate 2023-02-22 10:21:48 +00:00
ganfra 953d4c0ef7 Remove kotlin bindings for now 2023-02-22 11:00:05 +01:00
Ivan Enderlin 1469e9033c feat(crypto-nodejs): OlmMachine.initialize takes a new optional store type
feat(crypto-nodejs): `OlmMachine.initialize` takes a new optional store type
2023-02-22 10:33:26 +01:00
ganfra 260e7c2d5e Update kotlin xtask to not build aar 2023-02-22 10:28:08 +01:00
Archit Bhonsle ae4ed2e7c8 feat(crypto): Re-expose the version of vodozemac 2023-02-22 09:45:25 +01:00
valere 28fadb875a Post rebase fix 2023-02-21 17:48:05 +01:00
valere 3dbad4229a feat(withheld): sql store support 2023-02-21 15:05:14 +01:00
valere c497efc27a feat(withheld): handle incoming withheld + report error 2023-02-21 15:04:58 +01:00
valere 0154cccd4b feat(withheld) Remember no_olm and implement in memory store 2023-02-21 15:03:04 +01:00
valere 99232f2340 refactor(withheld) 2023-02-21 15:00:34 +01:00
valere 592be5bd57 feat(withheld) basic no_olm 2023-02-21 15:00:34 +01:00
valere dc0fe35103 feat(withheld) balcklist + refactoring 2023-02-21 15:00:34 +01:00
valere 7accfdc2ef feat(withheld) Implement MSC2399 2023-02-21 15:00:34 +01:00
Damir Jelić 655d7d00d0 chore(crypto): Add support for encrypted m.dummy events
This mostly just silences an incorrect log warning that we received an unsupported event.

Co-authored-by: Jonas Platte <jplatte@matrix.org>
2023-02-21 14:33:14 +01:00
Jonas Platte ac5b439249 chore(sdk): Add an extra trace event to TimelineEventHandler::add 2023-02-21 12:11:03 +01:00
Jonas Platte f76bc16a10 fix(sdk): Lock timeline state once for decryption retrying
Before, we were releasing the lock and re-obtaining it between obtaining
item indices and using them for decryption retrying.
2023-02-21 12:11:03 +01:00
Jonas Platte a89a12701a refactor(sdk): Remove unneeded Arc around MutableVec 2023-02-21 10:20:11 +01:00
Jonas Platte 843fe6a239 refactor(sdk): Remove derive_builder 2023-02-21 10:20:11 +01:00
Jonas Platte cb06feea22 refactor(sled): Remove derive_builder
… and use owned Builder pattern like for Client.
2023-02-21 10:20:11 +01:00
Jonas Platte b0e7f3d031 refactor(indexeddb): Remove derive_builder
… and use owned Builder pattern like for Client.
2023-02-21 10:20:11 +01:00
Jonas Platte b96532878b refactor(sdk): Replace futures-signals with eyeball-im in the timeline 2023-02-20 18:01:31 +01:00
Ivan Enderlin b439d60b1f feat(sdk): SlidingSyncView.state, .rooms_list and .rooms_count are now private
feat(sdk): `SlidingSyncView.state`, `.rooms_list` and `.rooms_count` are now private
2023-02-20 16:25:02 +01:00
Ivan Enderlin e8af3e2d60 chore(clippy): Make Clippy happy. 2023-02-20 15:39:23 +01:00
Ivan Enderlin 1f3b8048c7 chore(jack-in): Use the latest SS API. 2023-02-20 15:39:23 +01:00
Ivan Enderlin 48257ac7cd test(sdk): SS integration test suites use the new API. 2023-02-20 15:39:23 +01:00
Matteo Ludwig dffc65007c feat(bindings): Add AudioInfo & AudioMessageContent to matrix-sdk-ffi
Signed-off-by: Matteo Ludwig <ludwig@silpion.de>
2023-02-20 14:01:06 +00:00
Ivan Enderlin 3796469a29 doc(sdk): Fix Sliding Sync examples. 2023-02-20 14:24:38 +01:00
Ivan Enderlin d49ceddfd5 feat(sdk): SlidingSyncView.state, .rooms_list and .rooms_count are now private.
Before this patch, `SlidingSyncView` has the following fields that were public:
`state`, `rooms_list` and `rooms_count`. Since they are `Mutable`, they can be
changed from the outside, and then will break the internal state of the view.
This problem is mentioned in https://github.com/matrix-org/matrix-rust-sdk/
issues/1474.

This patch solves this by making them prviate. Phew. That was simple!

But wait, we have a problem now. `matrix-sdk-ffi` was relying on them. So
this patch adds “helpers” methods on `SlidingSyncView`, like `state_stream`,
`rooms_list`, `rooms_list_stream`, `rooms_count` and `rooms_count_stream`.
Let's add new ones when it's necessary.
2023-02-20 14:22:42 +01:00
Ivan Enderlin 03c3f66c9a doc(sdk): Fix Sliding Sync examples. 2023-02-20 14:20:22 +01:00
Ivan Enderlin 7b06822687 chore(sdk): Group impl blocks for the same SlidingSyncView in a single impl block. 2023-02-20 14:15:20 +01:00
Jonas Platte 1f128c1dd6 refactor(sdk): Remove Mutable<_> around SlidingSyncView#sync_mode 2023-02-20 13:20:33 +01:00
Jonas Platte e92841d6bc refactor(sdk): Inline Mutable type aliases 2023-02-20 13:20:33 +01:00
Jonas Platte a112076664 refactor(sdk): Remove usage of MutableBTreeMap
No instance was ever subscribed to, so we can just use a regular shared RwLock.
2023-02-20 13:20:33 +01:00
Jonas Platte 2f9106a6d0 refactor(sdk): Make SlidingSync fields private 2023-02-20 13:20:33 +01:00
Ivan Enderlin 8a70df80b2 doc(sdk): Fix Sliding Sync module documentation.
doc(sdk): Fix Sliding Sync module documentation.
2023-02-20 12:23:10 +01:00
Jonas Platte cbcfd5d531 refactor(bindings): Fix SlidingSyncRoom timeline listener return type
It's an error if the room was not found, so it should be surfaced as such.
2023-02-20 12:10:13 +01:00
Ivan Enderlin b451460d8d doc(sdk): Improve Sliding Sync documentation
Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
2023-02-20 12:06:20 +01:00
Ivan Enderlin 772a94cc8c doc(sdk): Fix Sliding Sync module documentation. 2023-02-20 11:49:35 +01:00
Jonas Platte 0f077ffcd3 fix(sdk): Don't overwrite parallel updates when fetching reply details 2023-02-20 11:15:23 +01:00
Jonas Platte 9eefe9377e refactor(sdk): Move timeline functionality into TimelineInner 2023-02-20 11:15:23 +01:00
Ivan Enderlin b35f2669d2 chore(sdk): Split the sliding_sync module into smaller ones
chore(sdk): Split the `sliding_sync` module into smaller ones
2023-02-20 11:09:05 +01:00
Ivan Enderlin 4102d25ebe chore(sdk): Split the sliding_sync module into smaller ones.
It's an strict copy-paste. Nothing has changed, except the
`SlidingSyncConfigBuilder::subscriptions` method that is now public within
the crate.
2023-02-20 10:43:05 +01:00
Ivan Enderlin 177fa140fc fix(sdk): FrozenSlidingSyncRoom.timeline_queue must serialize to timeline
fix(sdk): `FrozenSlidingSyncRoom.timeline_queue` must serialize to `timeline`
2023-02-17 19:46:50 +01:00
Ivan Enderlin e0eeba21ff fix(sdk): FrozenSlidingSyncRoom.timeline_queue must serialize to timeline.
In https://github.com/matrix-org/matrix-rust-sdk/pull/1478, I've introduced
a regression. The FrozenSlidingSyncRoom.timeline` field has been renamed to
`timeline_queue`.

I didn't notice that this type can be serialized and deserialized. That's
actually a breaking change because this type is stored somewhere once
serialized. So with #1478, it was impossible to deserialize them!

This patch fixes that. It also adds a test to ensure the serialization form of
`FrozenSlidingSyncRoom` doesn't change.
2023-02-17 19:24:39 +01:00
Jonas Platte e4f94f3174 chore: Fix warnings 2023-02-17 11:30:13 +01:00
Jonas Platte c2f529ed71 chore: Run cargo update
To pull in the latest Ruma release with a bugfix for content reporting.
2023-02-17 11:30:13 +01:00
Jonas Platte 0b91ec29a4 Allow to get or send any type of receipt 2023-02-17 10:54:03 +01:00
Kévin Commaille 362a394a11 feat(sdk)!: Allow to send private read receipts and receipts in threads
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-02-17 10:33:09 +01:00
Kévin Commaille 6ddb22d6ab feat(sdk): Expose methods to get a user or an event's receipts
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-02-17 10:29:22 +01:00
Kévin Commaille a3f289c6fc feat(base)!: Allow to get any receipt type for a user or event
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-02-17 10:29:21 +01:00
Jonas Platte 44d8f99bc4 docs(sdk): Remove outdated documentation 2023-02-17 09:56:29 +01:00
Ivan Enderlin eb3fb6986d doc(sdk): Fix links to examples and to matrix_sdk_base
doc(sdk): Fix links to examples and to `matrix_sdk_base`
2023-02-17 08:53:00 +01:00
Ivan Enderlin b6fb25fdfa test(sliding-sync): ensure unknown pos does recover the room subscription properly
test(sliding-sync): ensure unknown pos does recover the room subscription properly
2023-02-16 18:24:17 +01:00
Mauro 679d3084aa feat(bindings): Add Room::report_content 2023-02-16 17:18:18 +00:00
Ivan Enderlin 94b60f915f test(sdk): Address feedbacks. 2023-02-16 17:54:28 +01:00
Ivan Enderlin 3bf1060705 Merge branch 'main' into ben-fix-resubscribe-problem 2023-02-16 17:44:26 +01:00
Ivan Enderlin d600af7c0e feat(crypto-nodejs): OlmMachine.initialize takes a new optional store type.
This patch allows an `OlmMachine` to use a different store than Sled, like SQLite.

A new enum is introduced: `StoreType` which 2 variants: `Sled` (the default), and `Sqlite`.

The `OlmMachine.initialize` constructor now takes a new optional `store_type:
Option<StoreType>` argument. If no value is passed, the default `StoreType`
variant will be used (as mentioned: `StoreType.Sled`).

The code has been rewritten a little bit to make the type system happy without
introducing too much type indirections.

This patch finally adds a parameterized tests that exhaustively test: no store
type, `Sled` and `Sqlite`.
2023-02-16 16:26:06 +01:00
Damir Jelić 9649100adb feat(sdk): Add a root span to our client 2023-02-16 15:31:38 +01:00
Damir Jelić 292a9831f5 refactor(crypto): Move the usage specific cross signing types into the types module 2023-02-16 14:39:07 +01:00
Damir Jelić 04d8348477 refactor(crypto): Split out the cross signing key handling method 2023-02-16 14:39:07 +01:00
Ivan Enderlin 7049bd9183 doc(sdk): Improve Sliding Sync documentation
Sliding Sync API docs & minor fixes around API accessibility
2023-02-16 14:12:45 +01:00
Ivan Enderlin 1c7ffedf1a Merge branch 'main' into ben-sliding-sync-docs 2023-02-16 14:00:56 +01:00
Ivan Enderlin 7cc06cb76d chore(sdk): Small cleans up when reading the Sliding Sync code
chore(sdk): Small cleans up when reading the Sliding Sync code
2023-02-16 13:38:04 +01:00
Ivan Enderlin 9479f23f4b fix(sdk): Reconciliate events in the timeline queue in Sliding Sync when new updates arrive
fix(sdk): Reconciliate events in the timeline queue in Sliding Sync when new updates arrive
2023-02-16 12:35:35 +01:00
Ivan Enderlin c719d6d22e doc(sdk): Fix links to examples and to matrix_sdk_base. 2023-02-16 12:08:42 +01:00
Ivan Enderlin 6aa766efd0 chore(sdk): Address PR feedback. 2023-02-16 11:58:07 +01:00
Richard van der Hoff a0807cb337 crypto-js: support npm run build:dev (#1510)
Building the crypto-js bindings in release mode is very slow and not really
necessary for local development.

`--release` is the default, so there is no need to specify it
explicitly. Instead, allow `wasm-pack` args to be specified by an env var, and
add a `build:debug` npm script which will build in debug mode.
2023-02-16 10:51:37 +00:00
Richard van der Hoff 480800b996 crypto-js: have share_room_key return ToDeviceRequests (#1516)
We already have support for proper `ToDeviceRequest` objects in
`outgoing_requests`, so let's use it in `share_room_key` as well. It's much
easier for the application to work with the proper object than an untyped json
blob.
2023-02-16 10:51:15 +00:00
Ivan Enderlin 1c0288e42b chore(sdk): Simplify code by removing a map.
In the code `if let Some(global_data) = account_data.as_ref().map(|a|
&a.global)`, the `map` is not purely necessary. This patch simplifies the code
to remove the `map` and read the `global` field later on.
2023-02-16 11:49:21 +01:00
Ivan Enderlin 0a97ac8316 chore(sdk): Address PR feedback. 2023-02-16 11:45:10 +01:00
Ivan Enderlin 46006cf108 chore(sdk): Address PR feedback. 2023-02-16 11:43:25 +01:00
Ivan Enderlin 10adb6d26b chore(sdk): Use appropriate type to remove the need of a comment.
By using `Default::default` for the parameter value, we don't know which type
we are passing to the function. Hence the useful comment `room_info.ephemeral`.
This patch changes this to `Ephemeral::default`, so that we now know what we
pass without the need of a comment.
2023-02-16 11:23:05 +01:00
Richard van der Hoff 5abab932db ci: Fail coverage job if the coverage report can't be uploaded (#1515) 2023-02-16 09:36:43 +00:00
Damir Jelić abef9fae1a chore(bindings): Use tracing-android instead of android-logger 2023-02-16 09:59:16 +01:00
Ivan Enderlin b05d6874c0 test(sdk): Update the timeline inspection when the timeline_limit is modified. 2023-02-16 09:49:36 +01:00
Jonas Platte 3f2b12c996 chore(base): Remove unused futures-channel dependency 2023-02-16 08:59:41 +01:00
Ivan Enderlin 838488702f Merge branch 'main' into test-sliding-sync-timeline-limit-duplication 2023-02-16 08:45:22 +01:00
Ivan Enderlin 6c62b5f637 test(sdk): Restore the sliding-sync Docker image to v0.99.0. 2023-02-16 08:16:03 +01:00
Richard van der Hoff 826dc46ddf Merge pull request #1511 from matrix-org/rav/trace-to-debug
crypto-js: log trace messages at debug
2023-02-15 18:13:06 +00:00
Richard van der Hoff d9e455ab82 crypto-nodejs, crypto-js: prettify the javascript codebase (#1509) 2023-02-15 17:47:32 +00:00
kegsay 19b8ab409d test: Add depends_on block for the sliding sync proxy
This prevents the proxy starting before postgres is ready, which
causes the proxy to panic.
2023-02-15 17:32:57 +00:00
Richard van der Hoff 99b61ef660 Remove redundant log_trace 2023-02-15 17:06:46 +00:00
kegsay fb467b75e0 ci: Update sliding sync integration tests job 2023-02-15 17:03:29 +00:00
Jonas Platte 9e2fa13b9c fix(sdk): Respect new server ordering when receiving duplicate events 2023-02-15 17:40:16 +01:00
Jonas Platte 38e2d0bdcd fix(sdk): Fix day divider removal logic in timeline 2023-02-15 17:40:16 +01:00
Jonas Platte e8d5d29d2c chore(sdk): Improve tracing in TimelineEventHandler::add 2023-02-15 17:40:16 +01:00
Jonas Platte 88376e85cd test(sdk): Remove TestTimeline::with_initial_events
It's not general enough for further inital event tests.
2023-02-15 17:40:16 +01:00
Ivan Enderlin b1bfb868ab chore(sdk): Make Clippy happy. 2023-02-15 17:15:03 +01:00
Ivan Enderlin 6b3a550b22 chore(sdk): Fix lints. 2023-02-15 17:08:30 +01:00
Ivan Enderlin d9f9ed9d68 fix(sdk): Reconciliate timeline queue in SlidingSync when new updates arrive.
The code is self-documented. Please read it.
2023-02-15 16:50:40 +01:00
Jonas Platte 188aaecde3 feat(sdk): Keep Timeline event handlers around longer
… if the Timeline object itself is dropped, but something is still
subscribed to its changes.
2023-02-15 15:29:04 +01:00
Richard van der Hoff d41753ea17 crypto-js: log trace messages at debug
Javascript's `console.trace` is not a good equivalent for Rust's
`Level::TRACE`.

In particular:
 * `console.trace` causes a stacktrace to be written with each message
 * Under nodejs, `console.trace` writes the message to `stderr`, while
   `console.debug` writes to stdout

`console.trace` is therefore somewhat analogous to `console.error`.

Since we already include the log level in the message, we might as well just
send trace messages to `console.debug` rather than `console.trace`.
2023-02-15 12:50:42 +00:00
Richard van der Hoff e16c113db0 crypto-js, crypto-nodejs: Run prettier in CI 2023-02-15 12:39:54 +00:00
Richard van der Hoff 3f8590f86d crypto-nodejs, crypto-js: Run prettier on source code 2023-02-15 12:39:54 +00:00
Ivan Enderlin a0bd88aefc feat(crypto-nodejs) Implement OlmMachine.close
feat(crypto-nodejs) Implement `OlmMachine.close`
2023-02-15 12:48:45 +01:00
Jonas Platte 74056de8d7 fix(sdk): Deduplicate events coming from back-pagination 2023-02-15 12:41:26 +01:00
Jonas Platte 4f14728c91 chore(sdk): Add more spans and trace events to the timeline 2023-02-15 11:08:20 +01:00
Ivan Enderlin 57b810d70c test(sdk): Test changing the sliding sync limit on-the-fly. 2023-02-15 10:13:03 +01:00
Ivan Enderlin b3fedda90c chore(sdk): Clean up useless code.
The `experimental-timeline` feature is always enabled by `experimental-sliding-
sync`. Thus we can clean up the code.
2023-02-15 10:12:56 +01:00
Jonas Platte 20e082d416 refactor(sdk): Add a Date type for day divider logic 2023-02-15 10:08:05 +01:00
Jonas Platte 9e0ff4b9a9 fix(sdk): Handle remote echo on the first message of the day correctly 2023-02-15 10:08:05 +01:00
Jonas Platte b57bd55204 refactor(sdk): Use .rev().find_map() instead of .rfind().and_then() 2023-02-15 10:08:05 +01:00
Jonas Platte 4cad934a6b refactor(sdk): Simplify day divider timestamp conversion 2023-02-15 10:08:05 +01:00
Jonas Platte aa2b2dfff4 test(sdk): Fix reference to renamed test case 2023-02-15 09:31:42 +01:00
Jonas Platte 6c2a9dae55 test(sdk): Use u64 instead of u32 for next_ts
It seems weird to artificially limit the number range to 32 bits there,
panicking inside a test on too large values is fine.
2023-02-15 09:31:42 +01:00
Jonas Platte 360864841e test(sdk): Allow tests to set the next TS, use for day divider test 2023-02-15 09:31:42 +01:00
Jonas Platte 563ba884eb test(sdk): Make next_ts part of TestTimeline 2023-02-15 09:31:42 +01:00
Jonas Platte 13ffadc32a test(sdk): Add handle_live_redacted_message_event 2023-02-15 09:31:42 +01:00
Jonas Platte e246735866 test(sdk): Shorten some method names 2023-02-15 09:31:42 +01:00
Ivan Enderlin 6593f61556 doc(crypto-nodejs): Add safety comment for OlmMachine.close. 2023-02-15 09:15:31 +01:00
Jonas Platte 423d6ace83 fix(sdk): Attempt to EX-android crash with more hacks 2023-02-14 17:53:21 +01:00
Jonas Platte ce315a5229 chore: Use fully-qualified Docker image names
This brings us closer to being able to use our Docker setup with podman too.
2023-02-14 10:19:06 +01:00
Jonas Platte ca1163c9cc test: Remove trailing spaces from docker-compose.yml 2023-02-14 10:19:06 +01:00
Jonas Platte e576af8267 test: Fix docker-compose.yml error
Seems to be accepted by some older versions of docker-compose, but not
by current ones.
2023-02-14 10:19:06 +01:00
Jonas Platte 118497f9ec test: Remove unused dependency 2023-02-13 16:59:45 +01:00
Jonas Platte ac06172cf2 test(sdk): Add timeline items accessor 2023-02-13 16:21:30 +01:00
Damir Jelić 2654e909be feat(store-encryption): Add support to export/import the cipher using a key
This is useful for platforms which might want to avoid the cost of
password based key-derivation and have the ability to securely store an
encryption key.

Co-authored-by: Denis Kasak <dkasak@termina.org.uk>
2023-02-13 14:08:45 +00:00
Damir Jelić a1b1862479 docs(crypto): Explain a bit better what it means that a Device owns a room key
Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
2023-02-13 15:00:15 +01:00
Ivan Enderlin 5001cef372 Merge pull request #1375 from Hywan/feat-crypto-nodejs-requests-more-types 2023-02-13 14:46:47 +01:00
Kévin Commaille a6f74fa22c fix(sled): Use proper table name for encoding key when redacting
Contrary to other tables that use their own name to encode their keys,
the `ROOM_INFO` table uses the `ROOM` table name to encode its keys.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-02-13 14:07:06 +01:00
Damir Jelić 56cfa8f4f9 fix(crypto): Always mark your own device as verified 2023-02-13 14:01:31 +01:00
Richard van der Hoff 8d642784bb fix: remove dependency on broken wasm_timer crate
`wasm_timer` doesn't work outside the browser, which prevents it being used in
tests.

We can replace it with `gloo-timers` wich uses the standard Javascript
`setTimeout`.
2023-02-13 12:41:36 +01:00
enterprisey e45bf9f9bd docs(sdk): Improve read receipt/marker explanation 2023-02-13 12:05:35 +01:00
Jonas Platte 3a516a5fce refactor(sqlite): Use internal Error in CryptoStore impl 2023-02-13 12:05:04 +01:00
Jonas Platte 9fc7d1c78b refactor(indexeddb): Use IndexeddbCryptoStoreError in CryptoStore impl 2023-02-13 12:05:04 +01:00
Jonas Platte c6f0e47077 refactor(crypto)!: Add an error type to the CryptoStore trait
This makes it easier to implement it. However, using a different error
type than CryptoStoreError is a non-trivial change, so left for the
coming commits for all stores except the memory store.
2023-02-13 12:05:04 +01:00
Kévin Commaille 96c796bb0e ci: Silence clippy::extra_unused_type_parameters in affected crates
Triggers false positives.
See discussion in https://github.com/rust-lang/rust-clippy/issues/10319.
Possibly fixed in https://github.com/rust-lang/rust-clippy/pull/10321.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-02-13 11:57:05 +01:00
Kévin Commaille 63fa645cea fix(indexeddb): Fix implementation of SafeEncode for tuple of 5 elements
Regression introduced by merging commit 9707d73 after efdeba7

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-02-13 11:57:05 +01:00
Kévin Commaille 0d4fac5962 test(base): Test collision between threaded and unthreaded receipts in store
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-02-12 11:04:26 +01:00
Kévin Commaille 2e497198f8 fix(stores): Separate receipts by thread
The key encoding in key-value stores is backwards-compatible so
old receipts are counted as unthreaded receipts.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-02-12 11:04:26 +01:00
Kévin Commaille 9707d73ead fix(indexeddb): Fix broken raw redacted state events
A fix for (de)serialization of redacted state events in Ruma made
old events undeserializable.
Bump the DB version.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-02-11 22:54:38 +01:00
Kévin Commaille 5ae84a9a80 fix(sled): Fix broken raw redacted state events
A fix for (de)serialization of redacted state events in Ruma made
old events undeserializable.
Bump the DB version.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-02-11 22:54:38 +01:00
Jonas Platte 57c3224b6b ci: Work around not being able to use matrix variables inside uses 2023-02-10 13:58:41 +01:00
Jonas Platte 4a5a0293a9 ci: Replace unmaintained actions-rs/cargo action
… we really didn't need it and can use run instead.
2023-02-10 13:58:41 +01:00
Jonas Platte 3f16b324d7 ci: Use taiki-e/install-action to install cargo-tarpaulin 2023-02-10 13:58:41 +01:00
Jonas Platte a5bfab1d55 ci: Replace unmaintained actions-rs/toolchain action
… with dtolnay/rust-toolchain.
2023-02-10 13:58:41 +01:00
Jonas Platte e430f65ce8 ci: Exclude Debug implementations from coverage reports
We don't really want to check for exact representations, and otherwise
they are really just invoked in tests that fail.
2023-02-10 13:46:00 +01:00
Jonas Platte 441626bf68 ci: Exclude uniffi-bindgen from coverage checks 2023-02-10 13:02:31 +01:00
Jonas Platte 02e51a9cb9 ci: Test sqlite crypto store in coverage check 2023-02-10 13:02:31 +01:00
Jonas Platte 4492df6fc6 test(sdk): Add a test for retrying edit decryption 2023-02-10 12:41:05 +01:00
Jonas Platte 573b672470 fix(sdk): Fix handling of UTD "insivible" events
(ones which don't produce a timeline item on their own)
2023-02-10 12:41:05 +01:00
Jonas Platte fe3c73602f refactor(sdk): Always add UTD events to the timeline
… as currently this is the only way decryption can be retried.
2023-02-10 12:41:05 +01:00
Jonas Platte fd2dc18746 refactor(sdk): Retry event decryption in timeline item order
This works better for relations.
2023-02-10 12:41:05 +01:00
Jonas Platte 55549f61be test(sdk): Split timeline tests into smaller modules 2023-02-10 12:41:05 +01:00
Jonas Platte cf359dede5 chore: Upgrade rust-cache GitHub action 2023-02-10 12:16:06 +01:00
Ivan Enderlin 13f50fbf6c fix(sdk): Remove Deref impl for SlidingSyncRoom
fix(sdk): Remove `Deref` impl for `SlidingSyncRoom`
2023-02-09 16:32:31 +01:00
Ivan Enderlin 0f7646ade1 chore: Make Clippy happy. 2023-02-09 16:16:31 +01:00
Ivan Enderlin 4e1fe3bec4 chore: Fix a function renaming. 2023-02-09 15:49:55 +01:00
Ivan Enderlin c6d99305d5 fix(labs): Fix jack-in. 2023-02-09 15:46:08 +01:00
Ivan Enderlin c86ebaddd2 Update crates/matrix-sdk/src/sliding_sync.rs
Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
2023-02-09 15:36:13 +01:00
Benjamin Kampmann 048d6a774c docs(sliding-sync): improved language
Co-authored-by: Ivan Enderlin <ivan@mnt.io>
2023-02-09 14:13:41 +01:00
Ivan Enderlin 43f2f60bfd fix(sdk): Remove Deref impl for SlidingSyncRoom.
This implementation is wrong in the sense of its semantics is not about
dereferencing a thin pointer to something, but just to give access to one
specific field of the entire structure. That's not how `Deref` is supposed to
be used.

Moreover, it creates conflict between the `SlidingSyncRoom.timeline` field,
and `SlidingSyncRoom.inner.timeline` field, which both exist, but not for the
same purposes. It creates confusion in the code.

Finally, it's better to expose proper getters to the outside world, so that we
control _and_ test _and_ know exactly what API we provide.
2023-02-09 13:09:22 +01:00
Gabriel Féron 12cbff2688 refactor(sdk): Use spawn_blocking when generating attachment thumbnails 2023-02-09 09:54:43 +01:00
Jonas Platte bdab40a772 refactor: Fix clippy lint str_to_string in sliding sync tests 2023-02-08 17:52:31 +01:00
Jonas Platte 87de9c7453 refactor(sled): Remove unused re-export 2023-02-08 17:52:31 +01:00
Benjamin Kampmann 765959758b docs(sliding-sync): Document cold-cache, reactive-api and bot-mode 2023-02-08 16:54:06 +01:00
Jonas Platte efdeba79f9 chore: Upgrade workspace dependencies 2023-02-08 16:04:29 +01:00
Jonas Platte e25061f8cb refactor(crypto)!: Unwrap unused Result 2023-02-08 16:04:29 +01:00
Jonas Platte 345f4f39f4 refactor(sqlite): Make Error more precise / useful 2023-02-08 15:44:17 +01:00
Jonas Platte e12b9e3027 refactor(sqlite): Encode olm hashes with rmp instead of serde_json
… like everything else in the sqlite crypto store.
2023-02-08 15:44:17 +01:00
Jonas Platte a22529344a refactor(sqlite): Inline inherent methods that duplicate trait methods 2023-02-08 15:44:17 +01:00
Jonas Platte 64b7c4eb59 refactor(sqlite): Make OpenStoreError more precise / useful 2023-02-08 15:44:17 +01:00
Jonas Platte 1988d1e9a3 refactor(sqlite): Move sqlite extension traits to utils module 2023-02-08 15:44:17 +01:00
Jonas Platte efc2397267 refactor(sqlite): Always use rusqlite::Error for sqlite extension traits 2023-02-08 15:44:17 +01:00
Jonas Platte ecb521205f refactor(sqlite): Move error types into new error module 2023-02-08 15:44:17 +01:00
Jonas Platte 7db40746bb refactor(sqlite): Start cleaning up cfg attributes 2023-02-08 15:44:17 +01:00
Benjamin Kampmann 3639215d53 docs(sliding-sync): long polling and quick refreshing explained 2023-02-08 13:29:38 +01:00
Benjamin Kampmann d51e9694f6 fix(sliding-sync): Set as default view mode 2023-02-08 12:43:32 +01:00
Jonas Platte ae21a56be2 chore: Add missing copyright headers 2023-02-08 11:15:02 +01:00
Kévin Commaille c252b984e0 refactor(sdk): Use a builder pattern to construct Timeline
`Timeline::with_fully_read_tracking` was public although all public
Timeline constructors enable it by default.
It is also meant to be called when constructing the timeline so
using a builder pattern makes sense.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-02-08 10:46:59 +01:00
Benjamin Kampmann 300fdec83f docs(sliding-sync): First half of sliding sync API docs 2023-02-07 22:41:58 +01:00
Jonas Platte ee9d47f647 refactor(crypto): Remove confusing explicit Sized bound
The bound is there by default, no need to put it in explicitly.
2023-02-07 18:45:32 +01:00
Jonas Platte 2e80073f28 refactor(crypto): Use IntoCryptoStore for OlmMachine::with_store 2023-02-07 18:45:32 +01:00
Jonas Platte c3d5932a0f refactor(crypto): Move store::{CryptoStoreError, Result} into new module 2023-02-07 18:45:32 +01:00
Doug 7fdccfcea4 chore(bindings): Rename property and use feature flag. 2023-02-07 15:22:39 +00:00
Doug 630836b3c7 chore(bindings): Store the proxy URL directly in Client. 2023-02-07 15:22:39 +00:00
Doug 3705925a22 chore(bindings): Persist the sliding sync proxy.
Added to the Session for automatic restoration.
2023-02-07 15:22:39 +00:00
Doug b7a3ab7c5b feat(ffi): Sliding sync proxy discovery. 2023-02-07 15:22:39 +00:00
Jonas Platte 5692480112 refactor(crypto): Remove unused method 2023-02-07 15:59:19 +01:00
Jonas Platte 5b63bd4cf1 refactor(crypto): Reduce direct visibility of some internal types
They weren't being exported from any public modules before.
This helps human readers as well as some compiler lints.
2023-02-07 15:59:19 +01:00
Jonas Platte 9711e1b2f5 refactor(crypto): Move (Into)CryptoStore traits into a new module 2023-02-07 15:59:19 +01:00
Damir Jelić a17346158f docs(sdk): Fix the sliding sync builder example 2023-02-07 14:26:33 +01:00
Damir Jelić 30ddbab686 refactor(sdk): Move the bulk of the sliding sync logic into a sync_once method 2023-02-07 14:26:33 +01:00
Jonas Platte b436918cb3 fix(sqlite): Fix Debug output for SqliteCryptoStore 2023-02-06 17:08:21 +01:00
Jonas Platte b20424b8b5 chore(sqlite): Undo weird formatting of TOML file 2023-02-06 17:08:21 +01:00
Ivan Enderlin 5f933b1033 feat(sdk): Simplify code by using std::cmp::min
feat(sdk): Simplify code by using `std::cmp::min`
2023-02-06 14:46:46 +01:00
Ivan Enderlin 5e8224f19c feat(sdk): Simplify code by using std::cmp::min. 2023-02-06 13:43:01 +01:00
Damir Jelić e68134dd53 chore(crypto): Improve the logs for the OlmMachine constructor 2023-02-06 13:31:00 +01:00
Damir Jelić 945c16a7fb feat(crypto): Throw an error if our user/device pair isn't what we have in the store 2023-02-06 13:31:00 +01:00
dependabot[bot] fc8cd2e7e5 chore(deps): bump tokio from 1.24.1 to 1.24.2
Bumps [tokio](https://github.com/tokio-rs/tokio) from 1.24.1 to 1.24.2.
- [Release notes](https://github.com/tokio-rs/tokio/releases)
- [Commits](https://github.com/tokio-rs/tokio/commits)

---
updated-dependencies:
- dependency-name: tokio
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-02-04 08:27:50 +01:00
Damir Jelić 4115975135 fix(bindings): Expose the OpenTelemetry logging for other platforms as well 2023-02-03 22:30:11 +01:00
Damir Jelić 35a26be7b0 chore(sdk): Record the sliding sync pos in our logs 2023-02-03 16:51:33 +01:00
Jonas Platte 052832b4d3 fix: Don't log raw events that fail deserialization
… but do log relevant parts to allow debugging.
2023-02-03 14:35:10 +01:00
Richard van der Hoff e516e15d2b matrix-sdk-crypto-js v0.1.0-alpha.4
Release `crypto-js` / Publish 🕸 [m]-crypto-js (push) Failing after 31s
2023-02-03 12:17:37 +01:00
Ivan Enderlin 2bc9407563 feat(sdk): Remove SlidingSyncView.rooms
feat(sdk): Remove `SlidingSyncView.rooms`
2023-02-03 11:51:25 +01:00
Jonas Platte 47f8b6cb79 feat(ffi): Add Room::fetch_members 2023-02-02 17:48:26 +01:00
Jonas Platte e11dd099d8 feat(sdk): Add Timeline::fetch_members 2023-02-02 17:48:26 +01:00
Jonas Platte c294a376e8 refactor(sdk): Use TimelineDetails for sender profile 2023-02-02 17:48:26 +01:00
Jonas Platte ffa0190517 refactor(sdk): Add missing feature-gate
… for fn that is only used from sliding-sync.
2023-02-02 17:48:26 +01:00
Jonas Platte 3a863fa8fb refactor(sdk): Remove unnecessary inner block in function 2023-02-02 17:48:26 +01:00
ganfra 75d396e2ec Merge branch 'main' into ganfra/kotlin_binding_scripts 2023-02-02 17:10:34 +01:00
Ivan Enderlin 672a640854 chore(labs): Update to later changes. 2023-02-02 15:27:18 +01:00
Ivan Enderlin 40010cd511 Merge branch 'main' into feat-sliding-sync-view-rooms 2023-02-02 15:26:30 +01:00
Ivan Enderlin a6d33fcd16 feat(labs): Update jack-in to the new sliding sync room API. 2023-02-02 15:22:41 +01:00
Ivan Enderlin d08606e3b9 feat(sdk): SlidingSync::get_room now takes a ref to OwnedRoomId
feat(sdk): `SlidingSync::get_room` now takes a ref to `OwnedRoomId`.
2023-02-02 14:06:14 +01:00
Ivan Enderlin ae8a8c6cc3 feat(sdk): SldingSync::get_room takes a &RoomId. 2023-02-02 13:36:32 +01:00
Ivan Enderlin 0d87d0f786 feat(sdk): Remove SlidingSyncView.rooms.
`SlidingSyncView` exposes a `room` field. Problem: It's not updated
correctly and leads to error. The canonical way to get a room is by using
`SlidingSync::get_room`. This patch thus removes `SlidingSyncView.rooms`
entirely.
2023-02-02 13:31:46 +01:00
Ivan Enderlin a9ba2dd546 feat(sdk): SlidingSync::get_room now takes a ref to OwnedRoomId.
Before this patch, `SlidingSync::get_room` was taking ownership of an
`OwnedRoomId`, to only use it as a reference. Thus, calling this method was
creating useless clones.

This patch updates `SlidingSync::get_room` to receive a reference to
`OwnedRoomId`.
2023-02-02 13:25:36 +01:00
Kévin Commaille 00638ba74c feat(sdk): Allow to fetch replied to messages
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-02-02 13:06:11 +01:00
ganfra 6a7b28c085 Merge branch 'main' into ganfra/kotlin_binding_scripts 2023-02-02 11:52:32 +01:00
ganfra 1bcd8c7aae Comment remove gradle_build 2023-02-02 11:50:47 +01:00
Jonas Platte ce973b35e9 chore: Upgrade uniffi to 0.23.0 2023-02-02 10:15:05 +01:00
Jonas Platte 8a1b1eccd6 doc(sdk): Fix docs that refer to TimelineKey 2023-02-02 10:15:05 +01:00
Jonas Platte e068b4987e doc(sdk): Document what happens when timeline event sending fails 2023-02-02 10:14:23 +01:00
Jonas Platte 3a1eb62c38 refactor(sdk): Expose event sending errors through timeline item
… instead of through the return value of Timeline::send.
2023-02-02 10:14:23 +01:00
Jonas Platte c8021cf2ba refactor(sdk): Move LocalEventTimelineItem#event_id into send_state 2023-02-02 10:14:23 +01:00
Jonas Platte a48fd77c4a refactor(sdk): Rename LocalEventTimelineItemSendState => EventSendState 2023-02-02 10:14:23 +01:00
Damir Jelić ab0e27622e feat(bindings): Add support to setup a OpenTracing based logger 2023-02-01 22:55:47 +01:00
Damir Jelić 7b044ef5dd fix(crypto): Ignore the usage and signatures when comparing cross signing keys
Co-authored-by: Denis Kasak <dkasak@termina.org.uk>
2023-02-01 18:25:48 +01:00
Benjamin Kampmann 8a9b72ae6c test(sliding-sync): ensure unknown pos does recover the room subscription properly 2023-02-01 17:37:16 +01:00
Anderas e9cef35f99 Add matrix-sdk-sqlite with a CryptoStore implementation
Note about "Write-Ahead Log" (WAL) mode: The SQLite WAL mode has a
bunch of advantages that are quite nice to have:

1. WAL is significantly faster in most scenarios.
2. WAL provides more concurrency as readers do not block writers and a
   writer does not block readers. Reading and writing can proceed
   concurrently.
3. Disk I/O operations tends to be more sequential using WAL.
4. WAL uses many fewer fsync() operations and is thus less vulnerable
   to problems on systems where the fsync() system call is broken.

The downsides of WAL mode don't really affect us. So let's turn it on.

More info: https://www.sqlite.org/wal.html

Co-authored-by: Jonas Platte <jplatte@matrix.org>
Co-authored-by: Damir Jelić <poljar@termina.org.uk>
2023-02-01 15:06:59 +01:00
Damir Jelić 3a183b4c22 chore(sdk): Tweak the instrumentation for some encryption related methods 2023-02-01 10:16:14 +01:00
Richard van der Hoff 5dbee7dcdc fix(indexeddb): correctly encode Olm session keys
When we store an Olm session in the database, we encode the sender key and
session ID using the store cipher. That means that we also need to encode them
when we look them up, otherwise we won't find them.
2023-01-31 16:59:22 +01:00
Benjamin Kampmann b9b00743c9 fix(sliding-sync): catching up on new count for full-sync views 2023-01-31 15:02:19 +00:00
Benjamin Kampmann 14be1f888a test(sliding-sync): integration test for UnknownPos 2023-01-31 15:02:19 +00:00
Benjamin Kampmann a77295120a fix(sliding-sync): fixing restarting growing view 2023-01-31 15:02:19 +00:00
Benjamin Kampmann a6ad0e35b3 style(sliding-sync): improved style and docs 2023-01-31 14:03:43 +00:00
Benjamin Kampmann 5b3ec33ddc chore: Update to specific, supported ruma and sliding-sync-proxy-version. 2023-01-31 14:03:43 +00:00
Benjamin Kampmann aa10e70851 feat(sliding-sync): enable gzip when enabling sliding-sync 2023-01-31 14:03:43 +00:00
Benjamin Kampmann 826b2874ec ffi: expose sliding sync extension enabling 2023-01-31 14:03:43 +00:00
Benjamin Kampmann 8f17b6c38d feat(sliding-sync): add Receipt and Typing extension config 2023-01-31 14:03:43 +00:00
Benjamin Kampmann 9ae9c98340 test(sliding-sync): activate live views test 2023-01-31 14:03:43 +00:00
Benjamin Kampmann f6da282557 feat(sliding-sync): add delta-token support 2023-01-31 14:03:43 +00:00
Benjamin Kampmann 9ad34e8565 chore(sliding-sync): update to latest sliding-sync JSON layout 2023-01-31 14:03:43 +00:00
Benjamin Kampmann a973c372e6 chore: use local volumes for testing server 2023-01-31 14:03:43 +00:00
Ivan Enderlin 00e93e08e7 feat(sdk): Add EventTimelineItem::unique_identifier. 2023-01-31 13:21:19 +01:00
Kévin Commaille 75a2d2d92c fix(sdk): Aggregate reactions locally
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-01-31 12:11:44 +00:00
Jonas Platte e066346b16 feat(bindings): Clear the timeline when sliding-sync loop is reset 2023-01-31 11:49:25 +01:00
Jonas Platte 754453c135 refactor: Import tracing macros instead of using qualified paths 2023-01-31 11:49:25 +01:00
Jonas Platte c481caf060 refactor: Clean up format strings 2023-01-31 11:49:25 +01:00
Jonas Platte 6d868908cb refactor(sdk): Remove unused Result 2023-01-31 11:49:25 +01:00
Jonas Platte d2678e2f01 refactor(sdk): Remove unused async 2023-01-31 11:49:25 +01:00
Jonas Platte c24316e5e3 refactor(sdk): Remove unused lifetime parameter 2023-01-31 11:49:25 +01:00
Jonas Platte 48bc5b9b7e refactor(sdk): Work around receiving event with txn-id multiple times 2023-01-30 20:12:44 +01:00
Jonas Platte 01c828ed4b chore(sdk): Remove weird space 2023-01-30 20:12:44 +01:00
Benjamin Kampmann 102994b030 feat(sliding-sync): allow updating the timeline limit at runtime 2023-01-30 16:05:19 +00:00
Ivan Enderlin 38dfa90441 feat(sdk): LocalEventTimelineItem has a new send_state field
feat(sdk): `LocalEventTimelineItem` has a new `send_state` field
2023-01-30 14:08:47 +01:00
Ivan Enderlin 274bc20603 doc(sdk): Fix typos. 2023-01-30 13:58:00 +01:00
Ivan Enderlin c8d561d17d feat(ffi): Add LocalEventTimelineItemSendState + EventTimelineItem::local_send_state. 2023-01-30 13:51:29 +01:00
Ivan Enderlin 8ea2cef55d feat(sdk): LocalEventTimelineItem has a new send_state field.
This patch is trying to resolve the following issue:

When a local event is sent to the server, in case of an error, the
`Timeline::send` method just returned the error but it wasn't reflected inside
the `LocalEventTimelineItem` type itself. It's easy to loss this information.

So now, there is a new enum: `LocalEventTimelineItemSendState` with 3 states:

1. `NotSentYet`, when the local event has not been sent yet, it's theorically
   the initial state,
2. `SendingFailed`, when the local event has been sent but it's failed!
3. `Sent`, when the local event has been sent successfully.

Therefore, the `LocalEventTimelineItem` struct has a new field: `send_state`.

The send state is managed by its `with_event_id` method which now receives an
`Option<OwnedEventId>` (prev. `OwnedEventId` directly):

* If it's `Some(_)`, then it means we got a successful response from the server
  after the sending, so the send state is set to `Sent`,
* If it's `None`, then it means we got an error response from the server, so
  the send state is set to `SentFailed`.

(A small change: The method `TimelineInner::add_event_id` has been renamed
`TimelineInner::update_event_id_of_local_event`.)

The `Timeline::send` still returns a `Result`, but the server's response is
passed to a new method: `TimelinerInner::handle_local_event_send_response`
(it's logically named after the `handle_local_event` method), which is
responsible to call `TimelineInner:update_event_id_of_local_event` (which was
previously called directly by `Timeline::send`).

And `TimelineInner::update_event_id_of_local_event` was already calling
`LocalEventTimelineItem::with_event_id`. So everything works like a charm here.

The local send state is closely managed by `LocalEventTimelineItem`, I hope it
will avoid state breakage as much as possible.
2023-01-30 11:47:38 +01:00
Ivan Enderlin 4086492ef9 feat(sdk): EventTimelineItem is now an enum … { Local(…), Remote(…) }
feat(sdk): `EventTimelineItem` is now an `enum … { Local(…), Remote(…) }`
2023-01-30 11:03:49 +01:00
Ivan Enderlin 6bfa3df691 chore(sdk): Replace ref by &. 2023-01-30 10:20:44 +01:00
Ivan Enderlin f4607146e2 chore(sdk): Replace ref by &. 2023-01-30 10:13:54 +01:00
Ivan Enderlin 0a7193de62 chore(sdk): Remove useless custom Debug impl. 2023-01-30 09:30:12 +01:00
Ivan Enderlin 5c2e6b2743 chore(sdk): Simplify code. 2023-01-30 08:58:26 +01:00
Ivan Enderlin 47256eb4f9 chore(sdk): Remove a warning for an unused variable. 2023-01-30 08:50:47 +01:00
Ivan Enderlin 1c8d57321c chore(sdk): Remove Flow.timestamp and .raw_event. 2023-01-30 08:50:08 +01:00
Ivan Enderlin 322aa776f2 feat(sdk): Remove LocalEventTimelineItem.encryption_info and .raw, and Remote….raw is no more an Option. 2023-01-30 08:49:48 +01:00
ganfra 517b71cb06 kotlin bindings: replace shell by xtask scripts 2023-01-27 16:29:44 +01:00
Ivan Enderlin 17a9c4829d chore(sdk): Make Clippy happy. 2023-01-27 15:25:37 +01:00
Ivan Enderlin 59a5805af7 chore(sdk): Remove commented code. 2023-01-27 15:14:10 +01:00
Ivan Enderlin 882f3cad25 chore(sdk): Simplify code by using Into<EventTimelineItem> for LocalEventTimelineItem`. 2023-01-27 15:12:38 +01:00
Ivan Enderlin 5ce3c45637 chore(sdk): Simplify code by importing a type. 2023-01-27 15:07:42 +01:00
Ivan Enderlin ab617ddda0 chore(sdk): Fix a typo in an error message. 2023-01-27 15:05:27 +01:00
Ivan Enderlin 3a1c5580e7 chore(sdk): Fix a typo in an error message. 2023-01-27 15:03:49 +01:00
Ivan Enderlin 8486976804 feat(ffi): Update EventTimelineItem::reactions to return an Option. 2023-01-27 14:59:47 +01:00
Ivan Enderlin 8f13bb5ca5 feat(ffi): Add the EventTimelineItem::is_local and is_remote method. 2023-01-27 14:59:27 +01:00
Ivan Enderlin 7257cff5fe docs: Add the ffi scope. 2023-01-27 14:58:54 +01:00
Ivan Enderlin eb47869a45 feat(ffi): Remote TimelineKey. 2023-01-27 14:58:34 +01:00
Ivan Enderlin 636f4f8f8d feat(sdk): Remove the TimelineKey type. 2023-01-27 14:41:01 +01:00
Damir Jelić 819f962419 fix(sdk): Retry decryption if you initialize a Timeline with some events
The sliding sync logic has another room type called `SlidingSyncRoom`.

This room type stores a limited amount of events in something called
`AliveRoomTimeline` in a in-memory cache. This room also gets persisted
to the store via another room type called `FrozenSyncRoom`.

These types are used when clients restore their view of the room, i.e.
when the user enters the room to look at messages.

When the client enters a room, a `Timeline` object will be created, but
it will be initially populated with events coming from
`AliveRoomTimeline`.

In a hot potato contest of who should be responsible to decrypt injected
events, everybody claims to be allergic to potatoes.

This patch modifies the `Timeline` constructor that populates the
timeline with events from the `AliveTimeline` to retry decryption on the
events that the `AliveTimeline` pushes into the `Timeline`.

Note that, because the `AliveRoomTimeline` never replaces encrypted
events with decrypted ones, every time the client enters/exits the room
events well get re-decrypted.
2023-01-27 14:07:41 +01:00
Ivan Enderlin 3c9e84397a test(sdk): Update tests since the new EventTimelineItem type. 2023-01-27 14:00:41 +01:00
Ivan Enderlin f7bf6ba220 feat(sdk): Rewrite EventTimelineItem as an enum: Local and Remote. 2023-01-27 13:26:31 +01:00
Denis Kasak 539cbee087 test(crypto): Test failure when deserializing cross-signing keys with incorrect usage. 2023-01-26 17:01:00 +01:00
Damir Jelić d442cac936 refactor!(crypto): Directly deserialize into per usage cross signing key type
This moves the usage checking directly into our deserialization path.
2023-01-26 17:01:00 +01:00
Damir Jelić 72ed024303 fix(crypto): Make sure the master key self-signs as well
This is an omission from the spec where the subkeys are supposed to be
signed by the master key, but signing the master key wasn't mentioned.

This is still fine, since we always treated the master key and their
subkeys as a whole and never accepted one without the others.
2023-01-26 17:01:00 +01:00
Damir Jelić 148c4907b5 fix(crypto): Inspect the key usage when receiving cross signing keys 2023-01-26 17:01:00 +01:00
Ivan Enderlin 8c91314b58 feat(sdk): Move EventTimelineItem.event_id into TimelineKey::TransactionId
feat(sdk): Move `EventTimelineItem.event_id` into `TimelineKey::TransactionId`
2023-01-26 15:07:40 +01:00
Ivan Enderlin 9006bd1bba chore(sdk): Address review feedback. 2023-01-26 14:55:16 +01:00
Kévin Commaille 32e7209c66 refactor(sdk): Split room member events between membership and profile change
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-01-26 14:24:59 +01:00
Ivan Enderlin 4dfa41ce8f doc(sdk): Simplify if let into let
doc(sdk): Simplify `if let` into `let`
2023-01-26 14:24:35 +01:00
Ivan Enderlin 1a5ead58f6 feat(sdk): Move EventTimelineItem.event_id into TimelineKey::TransactionId.
To create an event next to the server, the event must be accompanied by
a transaction ID. When the server receives the event creation request, it
responds with a new event ID (which we will name `event_id_1`). Later on, when
a sync is done to the server, the server may respond with the transaction ID
and a new event ID (which we will name `event_id_2`).

The transaction ID is used to update the state of the local event. The event
ID received from the sync may ideally be the same as the one received by the
creation request's response.

Knowing that…

`EventTimelineItem` had a field: `event_id: Option<OwnedEventId>`. It was
`Some(event_id)` where `event_id` is the event ID responded by the server when
an event was created, i.e. it's `event_id_1`; otherwise it was `None`. This is
never `event_id_2`. Why?

Because `EventTimelineItem` has an other field: `key: TimelineKey`, which
represents the following states:

* `TimelineKey::TransactionId(OwnedTransactionId)`,
* `TimelineKey::EventId(OwnedEventId)`, where the event ID is `event_id_2`!

So it becomes obvious that `event_id_1` should be part of `TimelineKey`, not
`EventTimelineItem`. `TimelineKey` is where this transaction ID and event ID
logic is managed.

This patch updates `TimelineyKey::TransactionId` to be defined as:

* `TimelineKey::TransactionId { txn_id: OwnedTransactionId, event_id: Option<OwnedEventId> }`.

Why an `Option`? Because before receiving `event_id_1`, we may still want to
create a `TimelineKey`, the API must reflect that state.

So basically, `EventTimelineItem.event_id` is moved inside
`TimelineyKey::TransactionId`.
2023-01-26 11:36:42 +01:00
Jonas Platte 220617fd04 fix(sdk): Update add_event_id logs to make more sense 2023-01-26 10:59:28 +01:00
Jonas Platte a37ce68eae fix(sdk): Only look for local echoes for events appended to the timeline
… rather than prepended, or added at a specific point as replacement for
an existing timeline item.
Previously, we would log lots of useless tracing events when retrying to
decrypt UTD items.
2023-01-26 10:55:41 +01:00
Ivan Enderlin 0c4ca84eec test(sdk): Improve m.fully_read test coverage and documentation
test(sdk): Improve `m.fully_read` test coverage and documentation
2023-01-26 10:16:48 +01:00
Ivan Enderlin 77b7451f59 doc(sdk): Fix a typo. 2023-01-26 10:06:11 +01:00
Ivan Enderlin bac105a9aa doc(crypto-nodejs): Fix a typo. 2023-01-26 09:59:15 +01:00
Ivan Enderlin 832bba8a2b test(sdk): Improve m.fully_read test coverage and documentation. 2023-01-26 09:46:47 +01:00
Jonas Platte 0e39a7cbf2 chore: Upgrade Ruma 2023-01-25 18:01:12 +01:00
Jonas Platte db11940f8f test(sdk): Fix clippy warning 2023-01-25 18:01:12 +01:00
Damir Jelić 4ef654f1d1 chore: Bump the Ruma version 2023-01-25 18:01:12 +01:00
Ivan Enderlin 793e18e44f Merge pull request #1388 from matrix-org/release-matrix-sdk-crypto-js-v0.1.0-alpha.3
Release matrix-sdk-crypto-js v0.1.0-alpha.3
2023-01-25 12:56:41 +01:00
Ivan Enderlin 578b446ea4 chore(sdk): Rename a variable to clarify its content. 2023-01-25 11:00:03 +01:00
Ivan Enderlin 3fe5f13df4 doc(sdk): Simplify if let into let. 2023-01-25 10:58:46 +01:00
Ivan Enderlin 54f00dc05a feat(crypto-nodejs) Implement OlmMachine.close.
This patch fixes https://github.com/matrix-org/matrix-rust-sdk/issues/1379/.

This is similar to https://github.com/matrix-org/matrix-rust-sdk/pull/1197/.
We need to close the `OlmMachine`. Problem, `napi-rs` doesn't allow methods to
take ownership of `self`, so the following code:

```rs
fn close(self) {}
````

isn't allowed. There an [`ObjectFinalize`](https://docs.rs/napi/latest/napi/bindgen_prelude/trait.ObjectFinalize.html)
trait, but it's only called when the JS value is being collected by the GC.
It's not possible to force call `finalize` here.

This patch then introduces a new type:

```rs
enum OlmMachineInner {
  Opened(matrix_sdk_crypto::OlmMachine),
  Closed
}
```

that derefs to `matrix_sdk_crypto::OlmMachine` when its variant is `Opened`,
otherwise it panics. Calling the new `OlmMachine::close` method will change the
inner state from `Opened` to `Closed`.

Ideally, I wanted to throw an error instead of panicking, but `napi_env`
(used to build an `Env`, used to throw an error) is neither `Sync` nor `Send`.
Honestly, my knowledge of NodeJS and NAPI is too weak to implement `Sync`
and `Send` for `*mut napi_env__` safely. Especially because it can be executed
from various threads within `async fn` functions, that are driven by Tokio in
`napi-rs`. So, yeah, for the moment, it panics!
2023-01-25 09:56:21 +01:00
Benjamin Kampmann 464e40bc32 fix(ffi): add erroneously removed loop 2023-01-24 15:41:12 +00:00
Benjamin Kampmann f22660d5e9 chore(sliding-sync): more logging information 2023-01-24 15:41:12 +00:00
Andy Uhnak 2db1bc75c1 Expose MissingRoomKey decryption error 2023-01-24 16:27:02 +01:00
Damir Jelić 18ec101719 refactor!(crypto): Move some caches out of the CryptoStore implementations
This moves the caches we have for tracked users out of the Sled, and
IndexedDB, CryptoStore into the Store struct. The Store struct is a
wrapper for the CryptoStore trait, so this is the natural place where
these caches should live.

Co-authored-by: Jonas Platte <jplatte@matrix.org>
2023-01-24 15:26:33 +00:00
Doug a762b2027f feat(bindings): Expose aliases to the FFI. 2023-01-24 16:12:39 +01:00
Jonas Platte 934181be44 refactor(sdk): Update confusing variable names 2023-01-24 13:43:55 +01:00
Jonas Platte 3d34743ae9 fix(sdk): Respect server ordering for remote echoes 2023-01-24 13:43:55 +01:00
Kévin Commaille 718864bfdd refactor(sdk): Provide day divider as a timestamp
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-01-24 12:29:15 +01:00
Benjamin Kampmann 24ac5b9f16 feat(sliding-sync): add configuration to inform about room changes without positional update 2023-01-24 10:30:07 +00:00
Benjamin Kampmann cc835da347 fix(sliding-sync): refresh timeline if server told us we are limited 2023-01-24 10:30:07 +00:00
Benjamin Kampmann 933eec2d1d fix(sliding-sync): switch Atomic Ordering from Relaxed to SeqCst 2023-01-24 10:30:07 +00:00
Benjamin Kampmann de4a8e3e7a chore(base): additional tracing information for sliding sync responses 2023-01-24 10:30:07 +00:00
Benjamin Kampmann b08c740181 fix(ffi): don't cancel the actual spawn, instead ensure it finishes processing before stopping the loop 2023-01-24 10:30:07 +00:00
Benjamin Kampmann 950bb83f8d style: use trace! instead of tracing::trace! 2023-01-24 10:30:07 +00:00
Benjamin Kampmann a06aa43dd1 feat(sliding-sync): cache room data next to view for selective unfreezing 2023-01-24 10:30:07 +00:00
Benjamin Kampmann a572f61edf tests: additional ignored tests for future scenarios 2023-01-24 10:30:07 +00:00
Benjamin Kampmann a964585e35 fix(sliding-sync): have views go live right at response processing 2023-01-24 10:30:07 +00:00
Benjamin Kampmann 71407a636c fix(sliding-sync): use single replace on cold and empty views
Before we'd push one empty entry at a time, which lead to a lot of vecdiff updates pushed. With this
we now only push one  event after the entire operation set has been applied on the fresh
or cold view.
2023-01-24 10:30:07 +00:00
Benjamin Kampmann b7a8a93a73 chore(sliding-sync): additional tracing around unfreezing from cold cache 2023-01-24 10:30:07 +00:00
Damir Jelić 600fd62dc5 crypto(fix): Fail to decrypt if there's a key mismatch
A mismatch between the recorded Ed25519 and Curve25519 keys of the room
key and the identity keys of a Device used to be just a warning.

Considering that many clients will aggressively try to hide E2EE related
warnings let's upgrade this clear error into a full blown decryption
failure.

Co-authored-by: Denis Kasak <dkasak@termina.org.uk>
2023-01-24 09:14:42 +01:00
Damir Jelić 00d1437e5a chore(crypto): Log the full error messages when decrypting room events 2023-01-23 15:03:03 +01:00
Damir Jelić f774159e15 chore(crypto): Record the event id when decrypting a room event 2023-01-23 15:03:03 +01:00
Damir Jelić a1fba86f75 chore(crypto): Log the session id when we receive a room key 2023-01-23 15:03:03 +01:00
Damir Jelić 3c4d1cfb47 fix(sled): Don't load the tracked users with the Account
We might have a lot of tracked users, clients will usually have 1-10
thousand tracked users. This might slow down client startup if there are
so many tracked users.

We don't need the tracked users until we sync or try to send a message,
so load them lazily when they are first needed.
2023-01-23 13:35:51 +01:00
Damir Jelić 3ab95c74c7 refactor!(crypto): Make the methods related to tracked users async 2023-01-23 13:35:51 +01:00
Damir Jelić 8c1a81eebc chore: Fix the conventional commit type for documentation
The conventional commit specification recommends the "docs" type for
documentation related changes. This also matches the initial usage of
this type in our commit history.

While the default git-cliff config does specify a regex "^doc", where I
suspect our types have been taken from, this regex actually allows "doc"
as well as "docs" for the type.

Nevertheless, let's specify that we're using the one recommended in the
spec.
2023-01-20 20:30:06 +01:00
Richard van der Hoff acfa8a4190 docs(bindings): Fix return type documentation for get_missing_sessions 2023-01-20 20:09:42 +01:00
Richard van der Hoff 0771d73543 matrix-sdk-crypto-js v0.1.0-alpha.3
Release `crypto-js` / Publish 🕸 [m]-crypto-js (push) Failing after 46s
2023-01-20 17:37:49 +00:00
Richard van der Hoff 92546acc85 chore(crypto-js): configuration for 'yarn version' 2023-01-20 17:37:40 +00:00
Richard van der Hoff c7f258d8b0 doc: Improve the documentation of "tracked users"
I had no idea what a tracked user was, so I've attempted to clarify this
somewhat for future readers.

Co-authored-by: Damir Jelić <poljar@termina.org.uk>
2023-01-20 14:02:02 +01:00
Jonas Platte 1e2fd02478 doc(base): Explain purpose of BaseClient#crypto_store 2023-01-20 10:56:09 +01:00
Stefan Ceriu b0c70dc606 chore(bindings): Exclude the target folder from the debug swift package
… to improve package loading time.
2023-01-20 09:00:36 +00:00
Benjamin Kampmann 0fea33de4d feat(ffi): expose server_versions on ClientBuilder 2023-01-19 21:31:57 +00:00
Damir Jelić 053b609899 chore(sdk): Add a prefix to the request id to make it easier to grep for them 2023-01-19 15:47:08 +01:00
Damir Jelić a54a421f91 chore(sdk): Log the response/request sizes as well 2023-01-19 15:46:49 +01:00
Ivan Enderlin 78147e0d33 doc(crypto-js): Fix wording. 2023-01-18 17:22:02 +01:00
Ivan Enderlin 430c573494 feat(crypto-nodejs): Request types have more fields.
Instead of putting all request fields inside a single `body` JSON-
encoded string  field, there is now more types. There is less need to call
`JSON.parse`, and the type system will be able to catch more things.

For example, `ToDeviceRequest` now has 2 more fields: `event_type` and
`txn_id`.
2023-01-18 17:21:52 +01:00
Ivan Enderlin 9db09e22b2 feat(crypto-js): Request types have fields extracted from their “body” directly
feat(crypto-js): Request types have fields extracted from their “body” directly
2023-01-18 13:41:14 +01:00
Ivan Enderlin 94fadf74b9 feat(crypto-js): Rename RoomMessageRequest.content to .body. 2023-01-18 13:31:26 +01:00
Ivan Enderlin 7c01f8490f test(crypto-js): Test `RoomMessageRequest.content. 2023-01-18 13:14:06 +01:00
Ivan Enderlin ca00112804 test(crypto-js): Add test for in-room verification (w/ RoomMessageRequest). 2023-01-18 11:42:34 +01:00
Benjamin Kampmann 6c0ef2db51 refactor(ffi): refactor stoppable spawn to be more token-oriented 2023-01-18 10:08:58 +00:00
Benjamin Kampmann 938a03867b feat(ffi): add subscribe_and_add_timeline_listener helper fn
re-applying the fixes from ##1346
2023-01-18 10:08:58 +00:00
Ivan Enderlin 90cce1a47c chore(crypto-js): Improve documentation, and do a little clean up. 2023-01-18 10:58:59 +01:00
Ivan Enderlin c427caf473 feat(crypto-js): Rename requests extra field to body. 2023-01-18 10:58:59 +01:00
Ivan Enderlin 3ad675db5c feat(crypto-js): Extract RoomMessageRequest.event_type from EventContent. 2023-01-18 10:58:59 +01:00
Ivan Enderlin efde81646b feat(crypto-js): Extract RoomMessageRequest.content as a JSON-encoded string. 2023-01-18 10:58:59 +01:00
Ivan Enderlin 8f9859c41c feat(crypto-js): Rename the body fields to extra to avoid confusion with HTTP terminology. 2023-01-18 10:58:58 +01:00
Ivan Enderlin 6248e2bc68 test(crypto-js): Update tests according to previous commit. 2023-01-18 10:58:58 +01:00
Ivan Enderlin c0ccd55df8 feat(crypto-js): request! differentiates “extracted” and “grouped” fields. 2023-01-18 10:58:58 +01:00
Ivan Enderlin b125b2e9da test(crypto-js): Update tests according to previous commit. 2023-01-18 10:58:58 +01:00
Ivan Enderlin 3c838b2f4a feat(crypto-js): Request types have fields from their “body” directly. 2023-01-18 10:58:58 +01:00
Jonas Platte f4fba3efb7 fix(bindings): Add user_id to RoomMembership
Without that, it is useless.
2023-01-18 09:58:36 +01:00
Jonas Platte e64b2f65da Revert "refactor(bindings): Fetch latest event earlier"
This reverts commit 7d1372195cf2af56c3d8ef95ac1b183ace8a5eec.
2023-01-18 09:31:45 +01:00
Doug 9e12a88e03 feat(bindings): Allow setting the store passphrase in the bindings
Co-authored-by: Damir Jelić <poljar@termina.org.uk>
2023-01-18 06:45:21 +00:00
Anderas 0af38d9a76 fix(crypto): Mark our own identity as verified if we have the private part of the identity
Co-authored-by: Denis Kasak <dkasak@termina.org.uk>
Co-authored-by: Damir Jelić <poljar@termina.org.uk>
2023-01-17 18:41:00 +00:00
Damir Jelić ade3a09848 chore(base): Remove a leftover unwrap 2023-01-17 19:13:29 +01:00
Damir Jelić 3641e0d540 docs(crypto): Note that the in-room verification events need to be decrypted 2023-01-17 18:11:53 +01:00
Damir Jelić e1d8c72d3a chore(crypto): Improve some docs
Co-authored-by: Jonas Platte <jplatte@matrix.org>
2023-01-17 18:11:53 +01:00
Damir Jelić c8d9581f8b refactor!(crypto): Don't process in-room verification implicitly 2023-01-17 18:11:53 +01:00
Kévin Commaille 8cc632ffd1 feat(sdk): Add support for state events in the timeline
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-01-17 12:10:19 +01:00
Kévin Commaille 1b7f4b4b42 fix(test): Fix position of prev_content in JSON
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-01-17 12:10:19 +01:00
Damir Jelić 928871d16e chore(sdk): Log the request body for sliding sync requests 2023-01-16 17:02:46 +01:00
Damir Jelić 87f5b251f5 chore(sdk): Add a request id counter to our HTTP client
This solves the issue of correlating different log lines that are talking
about the same request/response cycle. Plaintext logs would show this as
a flat structure, while something like Jaeger would show you a nice
tree. This allows you to reconstruct the tree in plaintext logs.
2023-01-16 17:02:46 +01:00
Damir Jelić e76272a68b chore(sdk): Improve the HTTP request sending logs 2023-01-16 17:02:46 +01:00
Damir Jelić b30c74cb01 chore(crypto): Bump the to-device event logging to debug 2023-01-16 16:23:58 +01:00
Jonas Platte 686541155f feat(sdk): Add display_name_ambiguous to timeline::Profile 2023-01-16 15:35:29 +01:00
Jonas Platte b256b6f625 refactor(bindings): Fetch latest event earlier
Does this crash?
2023-01-16 15:35:29 +01:00
Jonas Platte 7b913a0759 feat(bindings): Add EventTimelineItem::sender_profile 2023-01-16 15:35:29 +01:00
Jonas Platte 9e60a9dd3f feat(sdk): Attach profile information to timeline items 2023-01-16 15:35:29 +01:00
Jonas Platte 00bdb08973 refactor(sdk): Move locking of timeline_items into handle_remote_event 2023-01-16 15:35:29 +01:00
Jonas Platte ed70ccb988 refactor(sdk): Add trait ProfileProvider for use in TimelineInner 2023-01-16 15:35:29 +01:00
Jonas Platte e52af8a315 refactor(sdk): Make TimelineInner fields private 2023-01-16 15:35:29 +01:00
Jonas Platte b5450ee5ad test(sdk): Simplify TestTimeline construction 2023-01-16 15:35:29 +01:00
Jonas Platte b105b34cf6 refactor(sdk): Use regular struct update syntax for EventTimelineItem
The previous solution was annoying to maintain and only more efficient
without compiler optimizations.
2023-01-16 15:35:29 +01:00
Jonas Platte e0b0b632ec chore: Fix a typo 2023-01-16 11:31:03 +01:00
Jonas Platte 4febe45364 refactor(base): Make AmbiguityChange(s) non-exhaustive
They are meant to be consumed, but not created, by other crates.
2023-01-16 11:31:03 +01:00
Jonas Platte 70de11a73a refactor: Remove unused Deserialize, Serialize implementations 2023-01-16 11:31:03 +01:00
Jonas Platte 58f2d53293 doc(sdk): Update spec link 2023-01-16 11:31:03 +01:00
Doug 6540b9bb49 feat(bindings): Expose read receipts to FFI 2023-01-16 10:58:40 +01:00
Jonas Platte 6c53842599 chore: Bump ruma, vodozemac 2023-01-16 10:34:06 +01:00
Jonas Platte 663d043abb refactor: Always use Debug for logging enum or identifier values 2023-01-16 10:34:06 +01:00
Damir Jelić 386cbce344 Revert "feat(ffi): add subscribe_and_add_timeline_listener helper fn"
This reverts commit ba4e304cad.
2023-01-13 14:55:39 +01:00
Damir Jelić ece9252a3d chore(crypto): Add the sender and event type to the to-device handling span 2023-01-13 12:46:07 +01:00
Damir Jelić c13cb4957e chore(crypto): Don't use a JsOption needlessly. 2023-01-13 12:46:07 +01:00
Damir Jelić 1f34a016e5 chore(crypto): Add the to-device message id to the logs if there is one 2023-01-13 11:58:42 +01:00
Damir Jelić b8dd704658 refactor(crypto): Move the to-device event handling into a separate method 2023-01-13 11:58:42 +01:00
Benjamin Kampmann 273e96265f Merge pull request #1335 from gnunicorn/ben-sliding-sync-integration-test
Various smaller fixes on sliding-sync for elem-x:

 - Infrastructure and smoke test only for integration testing sliding-sync
 - Expose Pop and Clear on VecDiff
 - Expose adding views during sliding sync live runtime incl integration tests
 - bug fix on replacing only in-window-items in the insert-code (was leading to a wrong list setting), including integration test
2023-01-13 10:11:30 +00:00
Jonas Platte 0e3ea58aa4 Revert unrelated change 2023-01-13 10:51:52 +01:00
Benjamin Kampmann ba4e304cad feat(ffi): add subscribe_and_add_timeline_listener helper fn 2023-01-13 08:09:10 +00:00
Benjamin Kampmann 723e3a3135 tests(sliding-sync): minor style improvements 2023-01-12 19:53:57 +01:00
Kévin Commaille 1c754e663d fix(sdk): Make pagination strategy implement Send
Required when `PaginationOptions` must implement `Send`,
e.g. with `tokio::runtime::Runtime::spawn`.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-01-12 19:24:47 +01:00
Damir Jelić 846844e67b fixup! chore(sdk): Re-export the AmbiguityChange type 2023-01-12 19:12:01 +01:00
Damir Jelić 51d96213ba chore(sdk): Re-export the AmbiguityChange type
This was forgotten to be re-exposed after it was moved to the base
crate.
2023-01-12 19:12:01 +01:00
Damir Jelić 80868919ae fix(crypto): Make the device update logic a bit more strict and obvious
When updating a device after we receive new device keys from a
/keys/query call we implicitly check that the user and device id match
since we need to fetch the device using the mentioned ids.

This moves the check into the update method as well to make it more
explicit. We also prevent upgrades of the Ed25519 key since we don't
support any different key type anyways.
2023-01-12 17:55:06 +01:00
Damir Jelić e3e9898f88 fixup! test(crypto): Check that we sign and verify fallback keys properly 2023-01-12 17:53:22 +01:00
Damir Jelić f2055f8069 test(crypto): Check that we sign and verify fallback keys properly 2023-01-12 17:53:22 +01:00
Damir Jelić 151f87a417 chore(crypto): Improve some docs
Co-authored-by: Denis Kasak <dkasak@termina.org.uk>
2023-01-12 17:37:06 +01:00
Damir Jelić 0e4f4d69b8 feat(crypto): Handle the failures field in the /keys/claim response 2023-01-12 17:37:06 +01:00
Damir Jelić 8db84a3c9e feat(crypto): Handle the failures field in the /keys/query response 2023-01-12 17:37:06 +01:00
Damir Jelić 1b18402707 feat(crypto): Add a TTL-cache that will handle failures for some requests 2023-01-12 17:37:06 +01:00
Benjamin Kampmann 6ec8ff6363 ci(coverage): ignore new sliding-sync-integration-tests for now 2023-01-12 13:51:59 +01:00
Benjamin Kampmann 906c09987f style(sliding-sync): minor style refinements 2023-01-12 13:24:16 +01:00
Benjamin Kampmann c93a9ef9a3 fix(sliding-sync): Simply room_range checking
Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
2023-01-12 13:24:16 +01:00
Benjamin Kampmann 51f2e773a0 fix(ffi): add Pop and Clear to VecDiff for sliding-sync 2023-01-12 13:24:16 +01:00
Benjamin Kampmann 3c6c5f4fae ci: disable broken sliding-sync-integration-test-runs 2023-01-12 13:24:16 +01:00
Benjamin Kampmann a8d49b86df feat(sliding-sync): adding views on live sliding-sync 2023-01-12 13:24:16 +01:00
Benjamin Kampmann 2949dcc773 docs: Add a Readme to explain usage 2023-01-12 13:24:16 +01:00
Benjamin Kampmann b790bf9397 test(sliding-sync): add integration test covering #1333 2023-01-12 13:24:16 +01:00
Benjamin Kampmann 91941a5360 fix(sliding-sync): ensure we are only replacing items in the requested range 2023-01-12 13:24:16 +01:00
Benjamin Kampmann fabf0d40bc test: add test for moving window and rooms 2023-01-12 13:24:16 +01:00
Benjamin Kampmann 08bec243ff ci(sliding-sync): add sliding sync integration test 2023-01-12 13:24:16 +01:00
Benjamin Kampmann 60d82fde38 test: add sliding-sync integration-testing facilities 2023-01-12 13:24:16 +01:00
Jonas Platte 866158f6ff chore(sdk): Add logging for when timeline events are not handled 2023-01-11 17:14:09 +01:00
Kévin Commaille f883293168 chore: Update Ruma
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-01-11 16:05:02 +01:00
Damir Jelić c6e883da68 fix(sdk): Pass in to-device events to the OlmMachine unconditionally
The sliding sync proxy seems to have started to omit the e2ee extension
completely if no changes happened to the one-time key counts.

Our sync response processing assumed that, if there are some to-device
events that need to be passed to the OlmMachine, then we'll have some
data in the e2ee extension of the response as well. In other words, it
wouldn't pass in the to-device events to the OlmMachine if the e2ee
field of the sync response is `None`.

Since the assumption isn't true, we're going to pass in default values
for the one-time key counts when the e2ee extension field of the
response is `None`.
2023-01-11 14:18:40 +01:00
Damir Jelić cdfb51a606 refactor!(sdk): Add the experimental prefix to the sliding-sync feature 2023-01-11 11:54:32 +01:00
Damir Jelić 3e88905518 chore(sdk): Make the timeline feature a dependency of the sliding sync one 2023-01-11 11:54:32 +01:00
Damir Jelić 156c351023 chore(crypto): Instrument the receive_sync_changes method
This is mainly done so we create a span with the name of the function,
since we can filter logs by the name of the span we're now able to
enable logs for this method only.
2023-01-11 11:17:58 +01:00
Jonas Platte a98c1fd00d chore: Update Cargo.lock 2023-01-10 10:19:02 +01:00
Jonas Platte f4bfbdf97d chore: Upgrade base64 2023-01-10 10:19:02 +01:00
Jonas Platte 2e30e11101 refactor: Use workspace dependencies for more crates 2023-01-10 10:19:02 +01:00
Jonas Platte 3af6ba245c refactor: Fully replace matches crate with assert_matches 2023-01-10 10:19:02 +01:00
Benjamin Kampmann db1d31c9cc fix(sliding-sync): Do not implictly activate to-device extension upon unfreeze
Previously, when we found a since-token in the frozen state, we'd always activate the to-device extensions
regardless of whether the user had activated it in their builder or didn't. With this change we are only
setting the since parameter from cache if the user actually activated the to-device extension.
2023-01-10 10:04:31 +01:00
Jonas Platte 444a82fd9e fix(sdk): Small documentation update 2023-01-10 10:01:26 +01:00
Jonas Platte 6e218bdebc feat(sdk): Make pagination more flexible and smarter
- Don't actually fire off a request when the top of the timeline has
  already been reached
- Allow making multiple requests without removing the loading indicator
  in between
2023-01-10 10:01:26 +01:00
Jonas Platte 9b3bf5a4fa feat(sdk): Add TimelineStart virtual timeline item 2023-01-10 10:01:26 +01:00
Jonas Platte 237edcd747 refactor(sdk): Move day_divider constructor to TimelineItem 2023-01-10 10:01:26 +01:00
Jonas Platte 271e925adc refactor(sdk): Add and use TimelineItem::{read_marker, is_read_marker} 2023-01-10 10:01:26 +01:00
Benjamin Kampmann 514530c19a fix(sliding-sync): ensure last index is also invalidated
Index ranges are inclusive, but our loop would stop one short. This particuarly
tricky when the selective view is moved, as we didn't properly invalidate all items.
2023-01-09 22:48:57 +00:00
Benjamin Kampmann 58aec0d126 feat(uniffi): Add support to set list filters on sliding sync view builders (#1296)
* feat(uniffi): Add support to set list filters on sliding sync view builders
* fix: expose SlidingSyncRequestListFilters via proc-macros
2023-01-09 14:45:35 +00:00
dependabot[bot] 63c8696cac chore(deps): bump tokio from 1.22.0 to 1.23.1
Bumps [tokio](https://github.com/tokio-rs/tokio) from 1.22.0 to 1.23.1.
- [Release notes](https://github.com/tokio-rs/tokio/releases)
- [Commits](https://github.com/tokio-rs/tokio/compare/tokio-1.22.0...tokio-1.23.1)

---
updated-dependencies:
- dependency-name: tokio
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-01-07 14:06:32 +01:00
Damir Jelić 6aff4fc2c0 Update the bindings to use the SAS signalling (#1300)
* feat(bindings): Expose support for manually starting SAS verifications

Co-authored-by: Stefan Ceriu <stefanc@matrix.org>
2023-01-06 10:20:40 +01:00
Jonas Platte 8375c47f42 feat(sdk): Add pagination loading indicator as a virtual timeline item 2023-01-06 09:48:44 +01:00
Jonas Platte 1b2387bcb2 refactor(sdk): Enforce no pagination overlap in timeline
… by locking the pagination token for the entire duration of the API call.
2023-01-06 09:48:44 +01:00
Jonas Platte 1e71036b19 refactor(sdk): Simplify day divider matching 2023-01-06 09:48:44 +01:00
Jonas Platte e0f5dc97a5 refactor(bindings): Avoid single letter type aliases 2023-01-05 10:53:56 +01:00
Jonas Platte 64f367d474 feat(bindings): Expose all TimelineItemContent variants 2023-01-05 10:53:56 +01:00
Jonas Platte bb39c2aa9d feat(sdk): Persist sliding-sync to-device extension since value 2023-01-04 19:05:37 +01:00
Jonas Platte b82cd7fa5a refactor(common): Simplify wasm timeout implementation
… and remove an infinitely-recursive From impl in the process.
2023-01-04 18:59:11 +01:00
Jonas Platte 6780dc0312 refactor(sdk): Increase default request timeout to 30s 2023-01-04 17:55:18 +01:00
Damir Jelić 72519b7386 chore(labs): Use clap instead of structopt for jack-in
Update to clap v4 in jack-in
2023-01-04 12:49:50 +01:00
Jonas Platte c7b41e3fca test(sdk): Add a test for TimelineInner::add_initial_events 2023-01-04 12:44:51 +01:00
Marcel Kräml 5852d751bd Updated jack-in README.md for full-sync-mode lowercase options
Signed-off-by: Marcel Kräml <m.kraeml@kraeml.it>
2023-01-04 12:38:54 +01:00
Marcel Kräml cda596ebed Changed full_sync_mode to lowercase
Signed-off-by: Marcel Kräml <m.kraeml@kraeml.it>
2023-01-04 12:21:14 +01:00
Jonas Platte a5e17be3a1 refactor(bindings): Only create a timeline for SlidingSyncRoom if needed 2023-01-04 11:44:07 +01:00
Jonas Platte 33cdc108b5 chore(sdk): Log number of events in add_initial_events 2023-01-04 11:44:07 +01:00
Jonas Platte c3dfd2e744 refactor(sdk): Only lock timeline items if needed in add_initial_events 2023-01-04 11:44:07 +01:00
Jonas Platte 8ab5bb7fca refactor(sdk): Use HttpError::client_api_error_kind 2023-01-04 11:44:07 +01:00
Jonas Platte 80d8a8f41f refactor: Import tracing macros 2023-01-04 11:44:07 +01:00
Jonas Platte 46fe998a33 refactor(crypto): Improve logging 2023-01-03 13:09:09 +01:00
Jonas Platte 7efbba5d8b refactor(sdk): Improve logging in timeline::event_handler 2023-01-03 13:09:09 +01:00
Jonas Platte 907d50f773 refactor(sdk): Move TimelineInnerMetadata definition to timeline::inner 2023-01-03 13:09:09 +01:00
Jonas Platte 9cba98ae1b feat(sdk): Add num_updates to timeline PaginationOutcome 2023-01-03 09:44:23 +01:00
Jonas Platte 108950c706 refactor(sdk): Remove update_timeline_item
… inlining it into its only call site.
2023-01-03 09:44:23 +01:00
Jonas Platte 4452e15489 refactor(sdk): Rename TimelineEventHandler#event_added to item_created 2023-01-03 09:44:23 +01:00
Matthew Hodgson b026d90bcf fix(sdk): Handle to-device sliding sync extension correctly
Co-authored-by: Jonas Platte <jplatte@matrix.org>
2023-01-02 18:00:38 +00:00
Jonas Platte aa5f74ffb1 fix(sdk): Fix clippy lint 2023-01-02 12:45:50 +01:00
Jonas Platte 469c6cf104 fix(sdk): Don't log raw JSON which can contain personal data 2023-01-02 12:45:50 +01:00
Jonas Platte 3c5b005aae fix(sdk): Remove message contents from TimelineItem debug string 2023-01-02 12:45:50 +01:00
Marcel Kräml eef0bf4b91 Fixed clap for jack-in and update README.md
Signed-off-by: Marcel Kräml <m.kraeml@kraeml.it>
2022-12-23 11:29:21 +01:00
Marcel Kräml ad1011ec53 Replace structopt with clap in jack-in
Signed-off-by: Marcel Kräml <m.kraeml@kraeml.it>
2022-12-23 11:17:02 +01:00
Jonas Platte c215ac1f4b ci: Specify which version of wasm-pack we want 2022-12-22 16:06:48 +01:00
Jonas Platte 187696aa62 ci: Use latest version of wasm-pack-action 2022-12-22 16:06:48 +01:00
Jonas Platte e1e094f2f4 chore(sdk): Lower log level of event ID duplication event 2022-12-22 14:45:41 +01:00
Damir Jelić e2d4be2050 chore: Fix our build badge 2022-12-22 11:26:29 +01:00
Jonas Platte 7dc4d47d3c refactor(sdk): Store timeline event handler handles in a Vec
… instead of individual EventHandlerDropGuard's that each individually
hold a copy of Client.
2022-12-22 10:32:03 +01:00
Jonas Platte 9bad6faedd feat(sdk): Retry event decryption on forwarded room keys 2022-12-22 08:37:17 +01:00
Jonas Platte 3a715ea822 refactor(sdk): Move timeline m.room_key handler into new module 2022-12-22 08:37:17 +01:00
Jonas Platte f58f3fe055 chore(sdk): Add more logging to decryption retrying 2022-12-22 08:37:17 +01:00
Benjamin Kampmann 6eda742fff style(sliding-sync): explain why we limit the timeline items in freeze 2022-12-21 12:51:12 +00:00
Jonas Platte 14f451c6dd feat(bindings): Add decryption retrying to matrix-sdk-ffi 2022-12-21 13:35:27 +01:00
Benjamin Kampmann 562087a70e fix(sliding-sync): properly handle rooms_count == 1. fixes #1285 2022-12-21 10:13:39 +00:00
Benjamin Kampmann e3e0eb9144 fix(sliding-sync): sync view state for selective views.
Fixes ##1284
2022-12-21 10:13:39 +00:00
Benjamin Kampmann b6d48cb31a fix(sliding-sync): limit cold storage of timeline items to 10 and drop prev-batch token in case we'd store too many 2022-12-21 10:13:39 +00:00
Ivan Enderlin e4257f9aff feat(crypto-js): Make our promises reject with Error.
feat(crypto-js): Make our promises reject with `Error`.
2022-12-21 09:49:30 +01:00
Richard van der Hoff 6b871b0a48 matrix-sdk-crypto-js: Make our promises reject with Error
It's not a hard-and-fast-rule that Javascript exceptions should be `Error`
instances, but it's certainly a convention, and one that is going to reduce
surprises if we follow.
2022-12-20 22:36:42 +00:00
Jonas Platte 561fb97a7b feat(bindings): Add virtual timeline items to matrix-sdk-ffi 2022-12-19 13:54:55 +01:00
Jonas Platte a5080b6ed9 chore: Upgrade Ruma 2022-12-19 13:50:02 +01:00
Jonas Platte 8034ac20f9 refactor(base): Keep redaction events as Raw inside StateChanges 2022-12-19 13:50:02 +01:00
Jonas Platte f5c0ea4605 doc(bindings): Update docs for Apple platforms 2022-12-19 13:44:00 +01:00
Doug ddf448aa02 doc(bindings): Update docs for Apple platforms.
Remove old bash scripts now we have the xtask.
2022-12-19 12:31:29 +00:00
Kévin Commaille b960c372ac feat(sdk): Add support for stickers in the timeline 2022-12-19 08:39:07 +00:00
Jonas Platte 05e4bc0557 refactor: Don't reserialize member events before storing them 2022-12-15 18:19:35 +01:00
Jonathan de Jong d79c70177b Lab: The Setup Pattern 2022-12-15 16:48:55 +01:00
Kateřina Churanová db7eafb7d0 fix(doc): Fix unresolved link in documentation
Signed-off-by: Kateřina Churanová <k.churanova@famedly.com>
2022-12-14 22:00:25 +01:00
Anderas 9239470c1c feat(crypto): Add signalling to the verification requests and qr code verification 2022-12-14 19:15:22 +01:00
Benjamin Kampmann dab20638f9 fix(sliding-sync): new limit should default to None in builder 2022-12-14 14:06:31 +01:00
Benjamin Kampmann 273d0a0edf feat(sliding-sync): Growing window and limit count full sync (#1270)
Add a second full-sync-up mode to sliding sync. Previously - and still the default for backwards compatibility, but now named `PagingFullSync` - was to page through the list by the page-size, de-validating the previous page of items. The newly added `GrowingFullSync` instead grows the window by the given number `batch_size` per request, starting and keeping it from `0`. In the latter we might be pushing more data over the connection and are slightly slower, but the top always stays active and thus reactive to changes.

Furthermore the developer can now configure an optional maximum number to grow/paginate the full-sync up to (so stopping before actually having reached `count` whatever is smaller). This is already exposed via FFI, too.

- [x] add new full-sync-mode
- [x] add limited sync-up mode (similar to full sync but only to a limit `n`)
- [x] implement sync-up in jack-in
2022-12-14 13:50:35 +01:00
Jonas Platte 1c12b23e4c refactor(sdk): Move PaginationOutcome out of event_item module 2022-12-14 12:38:48 +01:00
Kévin Commaille 37bea19ab5 feat(sdk): Add day dividers to the experimental timeline 2022-12-14 12:29:24 +01:00
Jonas Platte eb0c3449fa refactor(bindings): Use proc-macro frontend more in sdk-ffi 2022-12-14 12:03:13 +01:00
Jonas Platte b3f146c932 refactor(bindings): Use proc-macro frontend more in crypto-ffi 2022-12-14 12:03:13 +01:00
Jonas Platte 34d458d3a3 chore: Upgrade UniFFI 2022-12-14 12:03:13 +01:00
Benjamin Kampmann 1c55565403 Merge pull request #1255 from gnunicorn/ben-update-jack-in
Sliding Sync updates

- expose timeline listener via FFI on slidingsyncroom, too - returning a stoppable spawn
- connect room timeline and sliding-sync-room timeline together
- increase HTTP timeout on jack-in
- add jack-in support for actual timeline items.
2022-12-13 15:14:57 +00:00
Richard van der Hoff c8da05125e Merge remote-tracking branch 'origin/main' 2022-12-12 18:41:30 +00:00
Richard van der Hoff 9ec9a59509 Release 0.1.0-alpha.2
Release `crypto-js` / Publish 🕸 [m]-crypto-js (push) Failing after 34s
2022-12-12 18:02:21 +00:00
Richard van der Hoff 4f9452c9b0 Fix yet another typo in package.json 2022-12-12 17:51:10 +00:00
Richard van der Hoff dfed2f1b3a Bump version
Release `crypto-js` / Publish 🕸 [m]-crypto-js (push) Failing after 36s
2022-12-12 17:35:54 +00:00
Richard van der Hoff 5850ff4cfc Fix filenames in package.json 2022-12-12 17:31:54 +00:00
Doug e64a8113e9 feat(bindings): Generate a Package.swift in xtask 2022-12-12 18:04:15 +01:00
Richard van der Hoff 2a4b83b5e6 Switch to npm-publish GHA script
Release `crypto-js` / Publish 🕸 [m]-crypto-js (push) Failing after 57s
Mostly because, as of #1167, we no longer have a `publish` script.
2022-12-12 16:17:32 +00:00
Benjamin Kampmann 799447f481 Merge remote-tracking branch 'origin/main' into ben-update-jack-in 2022-12-12 15:15:14 +01:00
Benjamin Kampmann 1a0b90291c fix(jack-in): rendering formatting improvements 2022-12-12 15:14:18 +01:00
Valere 9a058b9ea0 feat(crypto): Request room keys if the decryption failure is an unknown message index
We automatically request room keys to be forwarded from our other trusted devices if a decryption failure happens because the room key is missing.

This patch introduces automatic room key requests for decryption failures if the room key is available but has been ratcheted forward. In other words, we will now request a better version of the given room key automatically as well.

Co-authored-by: Damir Jelić <poljar@termina.org.uk>
2022-12-12 13:09:45 +01:00
Erwan Bousse 1ef645d285 feat(bindings): Use HTTPS proxy when provided as environment variable 2022-12-09 16:01:02 +01:00
valere 57e09c07dc Git Ignore generated files from kotlin bindings 2022-12-09 13:12:50 +01:00
Benjamin Kampmann 1e4c16b9a9 Merge remote-tracking branch 'origin/main' into ben-update-jack-in 2022-12-07 16:31:32 +01:00
Benjamin Kampmann 26486fc905 feat: add kotlin bindings
Merge pull request #1239 from matrix-org/ganfra/kotlin_bindings
2022-12-07 14:50:38 +00:00
Benjamin Kampmann c4884887ef fix(sliding-sync): set views to preload if we've recovered from frozen 2022-12-07 13:59:50 +00:00
Jonas Platte ddde87f14b fix(sdk): Fix remote echo event_id check
The send-event response sets the event_id field, not the timeline key.
The previous error branch wasn't actually reachable.
2022-12-07 12:32:44 +01:00
Jonas Platte 3e1fddccfd fix(sdk): De-duplicate local echoes with remote echoes without txn ID 2022-12-07 12:32:44 +01:00
Jonas Platte c1949e3fc6 refactor(sdk): Move timeline::add_event_id to TimelineInner 2022-12-07 12:32:44 +01:00
Juliette 63bc004e26 feat(bindings): Add uploading media and setting display name to FFI
Co-authored-by: Jonas Platte <jplatte@matrix.org>
2022-12-07 10:40:15 +00:00
Jonas Platte e99341df69 chore(bindings): Move bindings around to work around rustfmt bug 2022-12-07 11:16:25 +01:00
Jonas Platte 7667f0c429 refactor(sled): Use open_with_database for SledCryptoStore::open 2022-12-07 11:16:25 +01:00
Jonas Platte d0609822bc refactor(sled)!: Rename SledCryptoStore::{open_with_passphrase => open}
`open_with_db` also has the passphrase parameter without mentioning it
in its name. The old name also sounded like the passphrase was required
when it's actually optional.
2022-12-07 11:16:25 +01:00
Jonas Platte 262fe5630f feat(sdk): Implement IntoFuture for LoginBuilder and SsoLoginBuilder 2022-12-07 11:13:44 +01:00
Andrew Ferrazzutti 2176b7ee39 Revise example of machine.receiveSyncChanges
Clarify that the JSON-encoded `toDeviceEvents` passed to
`OlmMachine.receiveSyncChanges` must be the list of events themselves,
instead of a wrapper object that contains the event list.

Signed-off-by: Andrew Ferrazzutti <andrewf@element.io>
2022-12-07 11:00:22 +01:00
Benjamin Kampmann 2bc738be8c feat(jack-in): sending messages via timeline API 2022-12-06 14:28:34 +01:00
Jonas Platte f5b59c3de2 refactor(sdk)!: Remove impl Into<_> around Ruma request types
The SDK used to have builder types for these request types, but they
were removed long ago.
2022-12-06 14:00:33 +01:00
ismailgulek 31e5d4d663 feat(bindings): Add members accessor to Room
Co-authored-by: Doug <douglase@element.io>
2022-12-06 12:58:30 +00:00
Jonas Platte 6a386ca5fb feat(bindings): Add sending of reactions to matrix-sdk-ffi 2022-12-06 12:48:06 +01:00
Jonas Platte a18919bf50 chore: Add a PR template 2022-12-05 14:58:33 +01:00
Jonas Platte f92153757b chore: Add CONTRIBUTING.md
… and move the testing section from README.md into it.
2022-12-05 14:58:33 +01:00
Benjamin Kampmann 83d0abc6d7 feat(sliding-sync): properly handle all timeline event types 2022-12-05 14:52:38 +01:00
Benjamin Kampmann f919ee3b7d fix(ffi): clean up sliding sync timeline API 2022-12-05 14:52:38 +01:00
Benjamin Kampmann 0bfa63b31e fix(sliding-sync): return a stoppable spawn to allow listener cancellation 2022-12-05 14:52:38 +01:00
Benjamin Kampmann 229e6b28a5 fix(ffi): connect timelines together 2022-12-05 14:52:38 +01:00
Benjamin Kampmann fee9d52dde feat(ffi): expose sliding-sync timeline 2022-12-05 14:52:38 +01:00
Benjamin Kampmann d4890807f9 fix(jack-in): bump http timeout to 90seconds 2022-12-05 14:52:38 +01:00
Damir Jelić 58f92e59fe fix(bindings): Change the is_syncing method to read the correct value 2022-12-05 14:16:01 +01:00
Damir Jelić 1f38becdd9 chore: Fix a clippy warning 2022-12-05 14:16:01 +01:00
Ivan Enderlin 2d9e8170fe feat(indexeddb): Update to indexed_db_futures 0.3.0.
It removes the fork we have introduced in https://github.com/matrix-org/matrix-rust-sdk/pull/1068
(all our patches have been merged and are part of this 0.3.0 release).
2022-12-05 14:16:01 +01:00
Kévin Commaille aeb419207a refactor(sdk): Split restore_session into two parts at the Client level (#1246)
Tokens are not necessary for the restoration of the crypto/store, only
the meta. Required for OpenID Connect support where we need the tokens to get the
meta.
2022-12-05 13:19:35 +01:00
Flix ee713d42ae chore: Bump axum 2022-12-01 13:26:07 +01:00
ganfra 97578e418c Merge branch 'main' into ganfra/kotlin_bindings 2022-11-30 20:39:42 +01:00
Benjamin Kampmann 7d69fb2314 fix(sliding-sync): fallback to invite-room if regular room can't be found (#1249)
Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
2022-11-30 13:59:25 +00:00
Jonas Platte 32cc477f54 refactor(sdk): Remove media caching from in-memory state store 2022-11-30 10:21:24 +01:00
Andy Uhnak 457c5f4fa3 Add cancel methods and rename callback method 2022-11-30 10:18:47 +01:00
Damir Jelić c604e59dcc feat(bindings): Expose the Sas::changes method over the FFI 2022-11-30 10:18:47 +01:00
Damir Jelić 026659ef68 refactor!(bindings): Return objects for the verification support
When the verification support was initially bound, Uniffi did not
support objects (the OlmMachine) returning other objects (our
verification objects). Instead we converted all the verification objects
into pure data structs which the other side had to poll for changes.

Now that Uniffi supports returning objects we can refactor this and make
the API on the other side the same as on the Rust side.
2022-11-30 10:18:47 +01:00
Jonas Platte 195ade911e refactor(sdk): Simplify signature of handle_back_paginated_event 2022-11-29 23:55:33 +01:00
Jonas Platte a881dad529 refactor(sdk): Make Timeline construction non-async 2022-11-29 23:55:33 +01:00
Jonas Platte 090b4495ea refactor(sdk): Simplify signature of handle_remote_event 2022-11-29 23:55:33 +01:00
Jonas Platte 3dfc60506f feat(sdk): Add SlidingSyncRoom::latest_event 2022-11-29 23:55:33 +01:00
Jonas Platte d4b67de9c3 refactor: Replace Timeline::latest with Timeline::latest_event 2022-11-29 23:55:33 +01:00
Jonas Platte 78e621010d refactor(sdk): Make tracking of fully-read marker in Timeline optional 2022-11-29 23:55:33 +01:00
Jonas Platte 1b0849a20c refactor(sdk): Move TimelineInner into its own module 2022-11-29 23:55:33 +01:00
Jonas Platte 32bf3143c7 doc: Hint towards test execution 2022-11-29 23:38:31 +01:00
Jonas Platte 3d22b6d5a4 chore: Upgrade Ruma 2022-11-29 15:37:18 +01:00
Flix bc29bcef38 doc: Hint towards test execution 2022-11-29 15:29:41 +01:00
Jonas Platte 859b12fca9 feat(sdk): Add debug logs for aggregated event handler execution times 2022-11-29 09:46:43 +01:00
Jonas Platte c564696a8a feat(sdk): Add tracing info to call_event_handlers 2022-11-29 09:46:43 +01:00
Benjamin Kampmann d3ff402813 feat(sliding-sync): Offline caching for Sliding Sync & session recovery (#1193)
With these changes, the user of sliding sync can configure the SlidingSync-Builder to store and recover the state from storage. For that they should call cold_cache("my-sliding-sync-key") with their preferred storage location during setup time on SlidingSyncBuilder. If a cached version is found under that key, the internal state of the rooms-list as well as each view found (identified by their name) will be set from storage immediately - allowing the user to show the last cached state. The Builder then also uses the same key to store its latest state after every update received from remote.

👉 Note on room list:
As we store a disconnected state, we are saving all RoomList entries as either Empty or Invalidated. This allows for an easier updating when the server comes back with results, as we don't track the ranges in cache - in the view of the server, we haven't seen anything yet.

👉 Note on timeline events:
This does store all existing timeline events - initial and seen during the session (as we keep track of them right now) - and will recover that state. However, as we can't be sure wether we have gaps in the timeline, the timeline items are reset upon receiving updates for them from the server.

👉 Note on (full-sync-)view:
While we are caching the server returned results (view list, room count and room info) as is, we are not caching the internal state (whether we are catching up) nor the ranges (as they are likely to be out of date) - those will be acting the same way you configured them, just with preloaded results. So for a full-sync-view, it will still do requests in batches and replace the corresponding set of rooms. Which could mean you might see the same room appear twice, though the cached one would be marked as invalidated. This might be problematic if the list the UI shows is longer than the batches fetched, but would be resolved quickly when catching up.

👉 On recovery:
When the sliding sync receives a M_UNKNOWN_POS, indicating the server has expired our session, sliding sync now transparently retries with up to three times to restart the sliding sync with full set of extensions and the latest views at their existing windows, the current room state is held. For full sync this starts a new sync-up with the existing room list staying intact. This also works from the offline at start.
2022-11-28 18:01:04 +00:00
Kateřina Churanová 08951e1c56 fix(ci): Fix unused import warnings on macos 2022-11-28 15:08:01 +01:00
Jonas Platte afda63f9e2 fix(sdk): Only retry requests on M_LIMIT_EXCEEDED or HTTP 5xx 2022-11-28 14:13:03 +01:00
Jonas Platte d7e6dd22e6 refactor(sdk): Simplify RumaApiError again
by folding Uiaa(UiaaResponse::MatrixError) into RumaApiError::ClientApi.
2022-11-28 14:13:03 +01:00
ganfra 68a6d2707f Fix naming of generated crypto .so files 2022-11-28 11:47:59 +01:00
ganfra 6666cd7a79 Use the generate .a file from cargo build as it's not stripped (instead of new target) 2022-11-25 19:20:54 +01:00
ganfra 75bb44bebf Add script to generate only crypto-ffi crate 2022-11-25 11:59:27 +01:00
ganfra 0504240878 Merge branch 'main' into ganfra/kotlin_bindings 2022-11-25 10:19:19 +01:00
Jonas Platte c0910a3693 chore: Fix a typo, upgrade typo check action 2022-11-24 22:36:46 +01:00
Kévin Commaille 183d4595aa fix(sdk): Make sure read marker can't go backwards 2022-11-24 22:15:36 +01:00
Kévin Commaille 580861cd1c fix(sdk): Rename read marker functions and variables for clarity 2022-11-24 22:15:36 +01:00
Kévin Commaille 1f761f3c13 test(sdk): Add read marker case when fully read event wasn't found 2022-11-24 18:17:43 +01:00
Kévin Commaille 5dc6416a76 fix(sdk): Fix logic if read marker event was not in the timeline 2022-11-24 18:17:43 +01:00
Jonas Platte c808a72914 feat(sdk): Add FailedToParse timeline items 2022-11-24 14:35:49 +01:00
Jonas Platte 6a1edf133d refactor(sdk): Add NewEventTimelineItem::from_content 2022-11-24 14:35:49 +01:00
Jonas Platte d0f0b650bd chore: Move impl for type after its definition 2022-11-24 14:35:49 +01:00
Jonas Platte d027005e87 chore(sdk): Rewrap info! invocation 2022-11-24 14:35:49 +01:00
Jonas Platte 43f0ba7711 chore: Appease clippy 2022-11-24 13:43:09 +01:00
Jonas Platte 8ce216974f test(sdk): Add a regression test for read marker updates 2022-11-24 13:43:09 +01:00
Jonas Platte f7d4129607 fix(sdk): Fix logic for updating an existing read marker 2022-11-24 13:43:09 +01:00
Stefan Ceriu 1107f27c3d fix(ffi): Use the right path for generated source files and only copy the generated folder contents (#1226) 2022-11-22 14:21:58 +00:00
Damir Jelić 3113f6698f chore: Don't use the term check for signature verification 2022-11-22 13:21:33 +01:00
Damir Jelić 38c38bc9f0 feat!(bindings): Expose the improved result of the verify_backup method 2022-11-22 13:21:33 +01:00
Jonas Platte de71d7e434 refactor(base): Simplify default memory store initialization 2022-11-22 11:03:45 +01:00
Jonas Platte 57a1743566 chore: Update Cargo.lock 2022-11-22 11:01:23 +01:00
Stefan Ceriu 1025d42624 fix(ffi): Fix xcframework release script, add missing module map 2022-11-22 09:55:46 +01:00
Jonas Platte fcb37b6962 feat: Support creating Timeline with initial items from sliding sync
Co-authored-by: Benjamin Kampmann <ben@gnunicorn.org>
2022-11-21 14:52:02 +01:00
bitfriend 2ab697328f fix(sdk): Make handle_back_paginated_event future Send 2022-11-18 20:57:36 +00:00
Damir Jelić eb20abe7b8 chore: The encryption feature was renamed 2022-11-18 19:53:07 +01:00
Jonas Platte fa71122e7d ci: Add sliding-sync and experimental-timeline to clippy check 2022-11-18 15:05:48 +01:00
Jonas Platte 785a3349ab refactor(sdk)!: Make sync_token accessor private 2022-11-18 14:02:41 +01:00
Jonas Platte 6329dbe6c2 refactor!: Split SyncResponse into two types
- matrix_sdk_base::sync::SyncResponse is the internal representation that
  we can update to account for sliding sync
- matrix_sdk::sync::SyncResponse is `/v3/`-specific and should not change
2022-11-18 14:02:41 +01:00
Jonas Platte ec5306978e refactor(sdk): Simplify signature of handle_sync_response 2022-11-18 14:02:41 +01:00
Jonas Platte 6b363120ef fix(sdk): Fix errors & warnings w/ experimental-timeline, w/o e2e-encryption 2022-11-18 13:39:51 +01:00
Jonas Platte 4bafb3818b feat(sdk): Add Timeline::retry_decryption 2022-11-18 13:39:51 +01:00
Jonas Platte 317965995a test(sdk): Add a test for retrying decryption of timeline items 2022-11-18 13:39:51 +01:00
Jonas Platte 74e9209e95 feat(sdk): Retry decryption of UTD timeline items 2022-11-18 13:39:51 +01:00
Jonas Platte da76a2700d refactor(sdk): Use an async lock for TimelineInnerMetadata 2022-11-18 13:39:51 +01:00
Jonas Platte ac33ca5fa0 refactor(sdk): Hold locks for the full lifetime of TimelineEventHandler
Not really necessary now, but required for thread-safe bulk updates like
we want for retrying decryption.
2022-11-18 13:39:51 +01:00
Jonas Platte 2bc0ac8fd7 refactor(sdk): Merge mutexes in TimelineInner into one 2022-11-18 13:39:51 +01:00
Damir Jelić 5a108f53cc refactor(crypto): Only use the Mutable for the inner SAS object
This patch makes the SAS signalling more robust, it ensures that we
can't forget to signal changes to the state.
2022-11-18 09:26:20 +01:00
Damir Jelić 1f2cdfc601 chore(contrib): Mitmproxy 9 has removed the HTTP prefix from the Response type 2022-11-17 12:43:56 +01:00
Jonas Platte 02165f7a05 refactor(sdk)!: Move retrying out of HttpSend trait 2022-11-17 12:32:45 +01:00
Benjamin Kampmann 98600e4c1e feat(jack-in): sending messages (#1156) 2022-11-17 11:18:27 +00:00
Jonas Platte bb6145d581 refactor!: Move large parts of deserialized_responses to matrix-sdk-base 2022-11-17 11:33:37 +01:00
Jonas Platte 975626a4f8 refactor(common)!: Remove unused TimelineSlice type 2022-11-17 11:33:37 +01:00
Jonas Platte c3aa03e486 chore: Add reldbg profile and use it for matrix-sdk-ffi iOS builds 2022-11-16 09:59:06 +01:00
Jonas Platte 51798e90bd chore: Add dbg profile and improve profile comments 2022-11-16 09:59:06 +01:00
Jonas Platte 5fa6f34e41 refactor(sdk): Use ErrorKind for get_state_events_for_key response check 2022-11-15 16:06:21 +01:00
Jonas Platte f9d2d32337 fix(xtask): Fix clippy warning 2022-11-15 16:06:21 +01:00
Jonas Platte 2dd2763d39 refactor(base): Unify identical branches and erase empty branches 2022-11-15 16:06:21 +01:00
Johannes Becker bb6cf83a39 refactor(appservice)!: Rename virtual user to appservice user 2022-11-15 15:57:31 +01:00
Damir Jelić a7dd690189 refactor(crypto): Split out the room key forwarding logic into a separate method 2022-11-15 14:57:46 +01:00
Jonas Platte e060606331 refactor(crypto): Move some code into a new method 2022-11-15 14:57:46 +01:00
Jonas Platte a30e40ed3a refactor: Introduce more early returns to reduce rightwards drift 2022-11-15 14:57:46 +01:00
Jonas Platte e59acfe28c refactor: Use let-else to remove boilerplate code 2022-11-15 14:57:46 +01:00
Jonas Platte d312aaecec refactor(crypto): Replace ? on if-else by early return 2022-11-15 14:57:46 +01:00
Jonas Platte 2528a5501b refactor(crypto): Remove unnecessary ref mut in patterns 2022-11-15 14:57:46 +01:00
Jonas Platte cf241d8c32 refactor(crypto): Merge matches and reflow comments in accept_secret 2022-11-15 14:57:46 +01:00
Jonas Platte db5d34e385 refactor(crypto): Reduce rightwards drift in test_device_signatures 2022-11-15 14:57:46 +01:00
Jonas Platte 7d2865f004 refactor(bindings): Shorten is_transaction_id_valid method 2022-11-15 14:57:46 +01:00
Jonas Platte 826705c174 chore: Bump MSRV to 1.65 2022-11-15 14:57:46 +01:00
Jonas Platte 5a1e347333 ci: Install stable toolchain for test-uniffi-codegen
The xtask is explicitly using the stable, and there is no reason to use
a less stable toolchain for this job.
2022-11-15 14:57:46 +01:00
Benjamin Kampmann 882b206144 feat(xtask): build xcframework
* Move swift build scripts into xtask (#1201)
* fix(ffi): use target_path from `cargo metadata` rather than guessing
* ci(ffi): install necessary target arch for build-framework test
* feat(xtask): copy to target without rsync.
2022-11-15 13:06:33 +01:00
Flix 8d89037296 fix: Missing ServerError after ruma update 2022-11-15 12:32:20 +01:00
Flix deb8ef801b fix: Remove the condition to only set new members in get_members 2022-11-15 12:32:20 +01:00
Flix 0a45e401e3 test: Use MemoryStore to fix problems in coverage tests 2022-11-15 12:32:20 +01:00
Flix 456e00e953 fix: Add missing not_found errors 2022-11-15 12:32:20 +01:00
Flix ab846f79f1 test: Add encryption state mock to tests where it is needed 2022-11-15 12:32:20 +01:00
Flix b1c2da9a68 fix: Don't mark encryption state to be synced on sync
As it appears, the first sync for a room might not include the
encryption state, so we cannot set the encryption state to be synced on
incoming syncs. That way, we always fetch the encryption state manually.
2022-11-15 12:32:20 +01:00
Flix 1ab33a28c9 fix: Make sure room.sync_up works under all conditions 2022-11-15 12:32:20 +01:00
Flix a3a9858bf4 refactor: Make if branches instead of early return 2022-11-15 12:32:20 +01:00
Flix 6951f7f5bf fix: Review comments 2022-11-15 12:32:20 +01:00
Flix fb8045b254 fix: Fix UDL or is_encrypted 2022-11-15 12:32:20 +01:00
Flix be7c3239a8 refactor: Adjust create_dm_room to new room API 2022-11-15 12:32:20 +01:00
Flix 956e270941 feat: Implement room sync_up method 2022-11-15 12:32:20 +01:00
Flix 65721aafb9 fix: Lock syncing to the store to avoid races 2022-11-15 12:32:20 +01:00
Flix 9d150e5cc6 fix: Adjust repeated_join test to new changes 2022-11-15 12:32:20 +01:00
Flix 43dd4452cd fix: Check encryption state in intermediate rooms 2022-11-15 12:32:20 +01:00
Flix 4abb08c4a1 feat!: Make intermediate rooms available right after joining/leaving
Co-Authored-By: Jonas Platte <jplatte@matrix.org>
Co-Authored-By: Benjamin Kampmann <ben@gnunicorn.org>
2022-11-15 12:32:20 +01:00
Jonas Platte 544da0d324 fix(sdk): Fix broken intra-doc link 2022-11-15 11:54:53 +01:00
ismailgulek 29aa9a78c3 feat(ffi): Expose file messages
Expose file messages (#1203)
2022-11-14 15:56:38 +00:00
Jonas Platte 4dc0e0ef3c chore: Upgrade Ruma 2022-11-14 15:01:53 +01:00
Gabriel Féron 680ef6b93a feat(sdk): Allow using an existing sled::Db with SledStateStore 2022-11-12 13:04:34 +00:00
Benjamin Kampmann 078855b4c9 feat(ffi): logging support for android (#1199)
* split logger into platform specific implementations
* logging support for android
* use platform independent wrapper for uniffi:exports
* activate colors for ansi-terminals
2022-11-11 12:20:19 +00:00
Damir Jelić 0d80c0e3fe chore(crypto): Improve the log for the one-time key signature error 2022-11-10 19:03:14 +01:00
ganfra 0901243440 Merge branch 'main' into ganfra/kotlin_bindings 2022-11-10 15:34:32 +01:00
ganfra fc76cc443e Fix build script 2022-11-10 15:34:00 +01:00
Jonas Platte 45cf32dfab test(sdk): Add a test for an undecryptable event 2022-11-10 13:43:46 +01:00
Jonas Platte aa4dbe4bc6 test(sdk): Add a test for editing a redacted event 2022-11-10 13:43:46 +01:00
Jonas Platte b550e9ba14 test(sdk): Add a test for an invalid edit 2022-11-10 13:43:46 +01:00
Jonas Platte 79db05cffb test(sdk): Add a unit test for redacting a reaction 2022-11-10 13:43:46 +01:00
Richard van der Hoff e45c57d8fe feat(crypto-js): allow async load of webassembly (#1198)
It turns out that Google Chrome refuses to initialise the wasm via the
synchronous `WebAssembly.Module` constructor, complaining that it is too
big. To be fair, it has a point.

Anyway, that means we need to provide a way to load the wasm
asynchronously. So, we introduce an `initAsync()` function which applications
can call before they do anything else, to load the wasm in the background.

If the app *doesn't* call `initAsync()`, then we load the wasm synchronously
the first time a function that accesses the wasm is called.
2022-11-10 11:51:37 +00:00
Ivan Enderlin 2eefb3a090 fix(indexeddb) + feat(crypto-js): Releasing IDBDatabase so that we can delete them
fix(indexeddb) + feat(crypto-js): Releasing `IDBDatabase` so that we can delete them
2022-11-10 10:40:16 +01:00
Ivan Enderlin 6754defb9b doc(crypto-js): Improve documentation of OlmMachine.close. 2022-11-10 10:21:48 +01:00
Damir Jelić 078a75ea27 chore(crypto): Log the protocols we accepted for a SAS verification 2022-11-09 16:56:23 +01:00
Damir Jelić 0d74189cde feat(crypto): Implement MSC3783
This commit adds support for the message authentication code calculation
that is using valid base64 when encoding the MAC.
2022-11-09 16:56:23 +01:00
Ivan Enderlin 196dfaea03 test(crypto-js): Test OlmMachine.close + IndexedDB clean up. 2022-11-09 14:48:37 +01:00
Ivan Enderlin f6496d01c7 feat(crypto-js): Add OlmMachine.close.
This new `OlmMachine.close` forces to drop/close the `OlmMachine` without
waiting on the JavaScript garbage collector to collect it.

`wasm-bindgen` generates the following JS glue code:

```js
close() {
    const ptr = this.__destroy_into_raw();
    wasm.olmachine_close(ptr);
}
```

And, `__destroy_into_raw` looks like this:

```js
__destroy_into_raw() {
    const ptr = this.ptr;
    this.ptr = 0;
    OlmMachineFinalization.unregister(this);
    return ptr;
}
```

It unregisters itself from the `FinalizationRegistry` correctly. We are
protected from a double-free.
2022-11-09 14:48:37 +01:00
Jonas Platte ca515997f1 feat(bindings): Expose video messages in matrix-sdk-ffi 2022-11-09 14:45:31 +01:00
Ivan Enderlin 3fe63c328f fix(indexeddb): Call IDBDatabase.close manually.
Surprisingly, `indexed_db_futures::IdbDatabase` is not closed when dropped.
Hopefully, there is a [`IdbDatabase::close(&self)`][close] method, which calls
`web_sys::IdbDatabase.close`, aka [`IDBDatabase.close`][websys-close], so let's
use it!

`IDBDatabase.close` returns immediately and closes the connection in a separate
thread. The connection isn't actually closed until all transactions created
using this connection are complete. No new transactions can be created for this
connection once this method is called. Methods that create transactions throw
an exception if a closing operation is pending.

[close]: https://github.com/Alorel/rust-indexed-db/blob/8c106eb418aecdba2f3fde80d91a4673a875fdf6/src/idb_database.rs#L73-L77
[websys-close]: https://developer.mozilla.org/en-US/docs/Web/API/IDBDatabase/close
2022-11-09 14:45:00 +01:00
ismailgulek 26d690a21c Fix clippy 2022-11-09 16:34:41 +03:00
ismailgulek 045d6647b2 feat(bindings): Add support for editing messages 2022-11-09 14:15:19 +01:00
ismailgulek 7f54e4592f Expose video messages 2022-11-09 16:02:40 +03:00
ganfra 4899f98f7f Merge main into ganfra/kotlin_bindings 2022-11-08 17:25:57 +01:00
Kévin Commaille 93be96c85c feat(sdk): Add read marker logic to the timeline API 2022-11-08 13:16:09 +01:00
Jonas Platte c014f980cb chore(sdk): Remove invalid comment
I have tried for hours and have concluded it is probably not possible
even with GATs to have RawEvent borrow its inner value.
It is also not a commonly-used feature, so removing the unnecessary
clones is not that important.
2022-11-04 15:17:01 +01:00
Jonas Platte 5601435449 refactor(sdk): Simplify bounds on event handler registration methods
… by introducing a hidden trait that constrains the output type of the
associated type EventHandler::Future.
2022-11-04 15:17:01 +01:00
Jonas Platte 5b919fc9df refactor: Fix clippy lints 2022-11-04 15:17:01 +01:00
Stefan Ceriu d57666c0b8 fix(sliding_sync): remove server versions fetch
before being able to use the sliding sync builder; the versions are still fetched but at a later date (#1183)
2022-11-04 12:03:17 +00:00
Jonas Platte ce966ed6ce chore: Upgrade criterion, pprof 2022-11-04 11:14:13 +01:00
Jonas Platte 3a6d048b9f refactor(sdk)!: Rename uiaa_response methods to as_uiaa_response 2022-11-03 18:05:04 +01:00
Jonas Platte cf779822fe refactor(sdk): Merge impl blocks 2022-11-03 18:05:04 +01:00
Jonas Platte c8dd5c42e9 docs(sdk): Add more doc links to as_ruma_api_error methods 2022-11-03 18:05:04 +01:00
Jonas Platte 128c74ace5 refactor(sdk): Use server-supplied retry time when when available 2022-11-03 18:05:04 +01:00
Jonas Platte 85ea9554e5 feat(sdk): Add {RumaApiError,HttpError,Error}::as_client_api_error 2022-11-03 18:05:04 +01:00
Ivan Enderlin 5b25b8967c feat(crypto-js): Encode the WASM as base64 for portability
feat(crypto-js): Encode the WASM as base64 for portability
2022-11-03 16:44:16 +01:00
Damir Jelić 3b755fc15e chore(crypto): Fix some spelling
Co-authored-by: Jonas Platte <jplatte@matrix.org>
2022-11-03 16:18:15 +01:00
Damir Jelić da61005ee4 chore(crypto): Improve the logs for the SAS state transitions 2022-11-03 16:18:15 +01:00
Damir Jelić 7a263433c7 refactor!(crypto): Add a new SAS state that waits for a key to be sent
This patch adds a couple more states to the SAS verification state
machine. Namely we add the following states:

* KeySent
* KeysExchanged

This prevents users from confirming that the short auth string matches
before they have sent out a m.key.verification.key event, which is
necessary for the other side to present the short auth string.

The KeysExchanged state functionally replaces the KeyReceived state.
Meaning that the short auth string can only presented once we
transitioned into the KeysExchanged state.

We can transition into the KeysExchanged state from the KeyReceived
state or from the KeySent state, depending on if we first receive a
m.key.verification.key event or if we first send out our own
m.key.verification.key event.

This means that, if the transition into the KeysExchanged state happens
through the KeySent state, users won't be able to tell if the transition
happened. In other words, listening to `m.key.verification` events
doesn't work anymore, users will need to use the new `Sas::changes()`
API to listen to a stream of state changes.
2022-11-03 16:18:15 +01:00
Ivan Enderlin ee27c19bf7 chore: Removing trailing spaces. 2022-11-03 15:57:20 +01:00
Ivan Enderlin 6d21df6d29 !debug off 2022-11-03 15:37:54 +01:00
Ivan Enderlin e989bc2377 fix(crypto-js): scan_qr_code takes a reference to QrCodeScan. 2022-11-03 15:37:21 +01:00
Jonas Platte 28b44a7f03 refactor!: Rename restore_login to restore_session 2022-11-03 15:34:31 +01:00
Ivan Enderlin 265ac1f97b chore(crypto-js): Configure a profiling profile for wasm-pack. 2022-11-03 14:59:22 +01:00
Ivan Enderlin d044565caa test(crypto-js): Keep qr.toBytes() local, to avoid weird GC collection. 2022-11-03 14:57:07 +01:00
Ivan Enderlin aa7d225867 feat(crypto-js): Qr.to_bytes returns a Uint8ClampedArray. 2022-11-03 13:58:17 +01:00
Stefan Ceriu af2de2d8ef chore(ffi): Reduce the log level for some not so useful logs 2022-11-03 13:26:32 +01:00
Jonas Platte a28a664302 refactor(bindings)!: Replace RestoreToken string with Session dictionary 2022-11-03 12:58:34 +01:00
Jonas Platte c1423e9326 refactor(bindings)!: Remove is_guest
It's not used by anything and should be re-introduced in the main Rust
first if it's needed.
2022-11-03 12:58:34 +01:00
Jonas Platte 8bfc186595 feat(bindings): Add TimelineItemContent::as_unable_to_decrypt 2022-11-03 12:03:33 +01:00
Jonas Platte 0cf5356f15 feat(sdk): Add UnableToDecrypt as a variant of TimelineItemContent 2022-11-03 12:03:33 +01:00
Jonas Platte c03940e6d5 chore(sdk): Reword log messages 2022-11-03 12:03:33 +01:00
Jonas Platte f93170323b refactor(sdk): Remove unnecessary pub(crate) 2022-11-03 12:03:33 +01:00
Ivan Enderlin a3cdd31713 fix(crypto-nodejs): Pass secrets to the release workflow
fix(crypto-nodejs): Pass secrets to the release workflow
2022-11-03 11:58:59 +01:00
Ivan Enderlin fb89de8267 fix(crypto-nodejs): Pass secrets to the release workflow.
See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idsecrets.
2022-11-03 11:30:10 +01:00
Ivan Enderlin 223e65fc26 !debug 2022-11-03 11:08:52 +01:00
Jonas Platte b5b2eafbec refactor(base): Remove unused Error variants 2022-11-03 10:52:11 +01:00
Jonas Platte 27b0ea1aa0 refactor(crypto): Move EncryptionNotEnabled out of MegolmError
… into matrix_sdk_base::Error because it is never constructed in the
matrix_sdk_crypto crate that defines MegolmError.
2022-11-03 10:52:11 +01:00
Jonas Platte 4c4b1f3abc refactor(bindings): Use uniffi proc-macros more in sdk-ffi 2022-11-03 09:48:41 +01:00
Jonas Platte 99e621a82b chore: Upgrade UniFFI 2022-11-03 09:48:41 +01:00
ganfra 4eedbfbc11 Merge branch 'main' into ganfra/kotlin_bindings 2022-11-02 19:06:07 +01:00
Richard van der Hoff 898265b257 Clean up build script 2022-11-02 17:22:00 +00:00
Richard van der Hoff 9d400a7494 fix JS syntax 2022-11-02 17:13:58 +00:00
Ivan Enderlin a4ca6dbf38 !debug 2022-11-02 17:25:13 +01:00
Ivan Enderlin b23d30c951 fix(indexeddb): Fix wasm_bindgen::JsValue::(from|to)_serde warnings
fix(indexeddb): Fix `wasm_bindgen::JsValue::(from|to)_serde` warnings
2022-11-02 16:58:09 +01:00
Ivan Enderlin bb96ab89f8 fix(crypto-js): Make build.sh cross-platform-ish. 2022-11-02 16:57:26 +01:00
Ivan Enderlin 4cd8a8400f chore: Reorder dep names. 2022-11-02 16:38:01 +01:00
Ivan Enderlin 28d4a69552 !fixup 2022-11-02 16:32:20 +01:00
Jonas Platte a6ca114bac chore: Upgrade UniFFI 2022-11-02 16:21:16 +01:00
Ivan Enderlin 6497d6d676 feat(crypto-js): Make scripts/build.sh compatible with macOS.
This patch also improves the “phrasing”, simplifies the code a little bit etc.
Small stuff.
2022-11-02 16:19:17 +01:00
Ivan Enderlin da93cf7dc4 fix(indexeddb): Fix wasm_bindgen::JsValue::(from|to)_serde warnings.
`wasm_bindgen::JsValue::(from|to)_serde` now emit warnings because of a
circular dependency. To solve this problem, this patch now uses `gloo-utils`,
see https://rustwasm.github.io/wasm-bindgen/reference/arbitrary-data-with-serde.html#an-alternative-approach---using-json.

Ideally, we would like to use `serde_wasm_bindgen` but the behaviour isn't
the same. `gloo-utils` serializes and deserialized through JSON, whilst
`serde_wasm_bindgen` manipulates the `JsValue` directly which can be better or
worst dependending of the case. This patch conserves the JSON approach as it
was the previous and tested one.
2022-11-02 08:59:37 +01:00
Ivan Enderlin 2b4f4b17c3 chore: Update wasm-bindgen's ecosystem to latest versions. 2022-11-02 08:59:21 +01:00
Richard van der Hoff 0f104c7433 Fix unbase64 loading 2022-11-01 13:47:44 +00:00
Jonas Platte 726e4b9aa0 fix(appservice): Fix nesting of AppServiceRouter in axum::Router 2022-11-01 11:37:16 +01:00
Jonas Platte f227f583e0 chore: Upgrade ruma-client-api 2022-11-01 11:34:05 +01:00
Jonas Platte 36444cd3a0 chore: Clean up TOML formatting 2022-11-01 11:34:05 +01:00
Jonas Platte 9c489b398d chore: Upgrade clap dependency of xtask 2022-11-01 11:34:05 +01:00
Richard van der Hoff ce03f016b9 Copy unbase64.js into the right place 2022-11-01 10:19:13 +00:00
Richard van der Hoff 4557494da6 Optimise unbase64
Use a lookup table instead of a function with if statements
2022-11-01 10:18:44 +00:00
Richard van der Hoff 093856671a Encode the WASM as base64
Some nasty hackery to get around the nastiness of the JS ecosystem
2022-10-31 22:39:44 +00:00
Ivan Enderlin 471ac07c88 fix(crypto-nodejs): Set KeepAlive to false since Node.js v19
Disable keepAlive in download-lib.js, allowing node bindings to work on Node.JS 19
2022-10-31 14:35:57 +01:00
Will Hunt f4f3ca4b25 A newline 2022-10-31 13:18:16 +00:00
Will Hunt c009f54ba9 Tidy 2022-10-31 13:17:48 +00:00
Will Hunt 546dc9a652 Run CI against 19 2022-10-31 13:04:05 +00:00
Will Hunt 717f86332f Disable keepalive to prevent hanging connections 2022-10-31 12:39:23 +00:00
Jonas Platte 6c975b01b5 Revert #1151
This reverts the commits

- cacb20e3ef
- 01cc896dab
2022-10-31 12:03:23 +01:00
Ivan Enderlin 182733e984 feat(crypto-js): OlmMachine.initialize is the new constructor
feat(crypto-js): `OlmMachine.initialize` is the new constructor
2022-10-31 11:41:50 +01:00
Andy Uhnak e4964b92a2 Local trust 2022-10-31 11:14:04 +01:00
Ivan Enderlin bdf460cd91 doc(crypto-js): Rephase something.
Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
2022-10-31 11:07:21 +01:00
Ivan Enderlin 0276552c72 feat(crypto-js): Use WeakRef to avoid calling free manually
feat(crypto-js): Use `WeakRef` to avoid calling `free` manually
2022-10-31 11:06:45 +01:00
Ivan Enderlin 3441c6cf9a feat(crypto-js): Use WeakRef to avoid calling free manually.
By asking `wasm-bindgen` to generate JS glue code for `WeakRef` support,
it removes the need to call `free` manually to free objects, thus we reduce
potential memory leaks inside Rust. See https:// rustwasm.github.io/docs/wasm-
bindgen/reference/weak-references.html to learn more.

It uses [`FinalizationRegistry`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/FinalizationRegistry)
under the hood, I reckon it's quite common and fits into Matrix's clients needs
in terms of browser support.
2022-10-28 21:02:35 +02:00
Ivan Enderlin a07f89e340 feat(crypto-js): OlmMachine.initialize is the new constructor.
While technically a type constructor can return a `Promise`, it's not
considered as idiomatic JavaScript to do that. We are changing `new OlmMachine`
to `OlmMachine.initialize`. The rest of the code is strictly the same.
2022-10-28 20:37:46 +02:00
Benjamin Kampmann cacb20e3ef fix(ffi): Remove duplicate RequireState definition, left over after #1151 (#1155) 2022-10-28 13:38:21 +02:00
Benjamin Kampmann 255d3b7a18 Merge pull request #1154 from matrix-org/stefan/sessionVerificationFixes
Sliding Sync FFI and DevEx fixes
2022-10-28 11:40:33 +02:00
Jonas Platte 6ad7d29364 refactor(sdk): When processing remote events, check for duplicates 2022-10-28 11:30:32 +02:00
Jonas Platte 333c4f0644 refactor(sdk): Move timeline event origin_server_ts and raw_event fields
… from TimelineEventMetadata to Flow because they always exist for
remote events, and never for local echoes.
2022-10-28 11:30:32 +02:00
Jonas Platte 6ce23b17a6 refactor(sdk): Update tracing event for local echo not being found 2022-10-28 11:30:32 +02:00
Benjamin Kampmann 0cb34f7c86 fix: style fixes 2022-10-28 11:01:54 +02:00
Jonas Platte 0d84cf7b74 refactor(sdk): Make Debug format of EventTimelineItem less noisy 2022-10-28 10:56:28 +02:00
Jonas Platte f2ea72224d feat(bindings): Add {TimelineItem,EventTimelineItem}::fmt_debug 2022-10-28 10:56:28 +02:00
Jonas Platte 01cc896dab refactor(bindings): Use uniffi proc-macros a little more in sdk-ffi 2022-10-28 10:55:46 +02:00
Benjamin Kampmann 278c6059ae perf(sliding-sync): run outgoing e2ee requests and sync in parallel.
And continue the loop if even we hit an error in between
2022-10-27 15:59:02 +01:00
Benjamin Kampmann d164165c7c fix(ffi): remove extra to-device processing 2022-10-27 15:57:36 +01:00
ganfra 5a9b75c3ff kotlin-bindings: remove sample 2022-10-27 14:38:17 +02:00
ganfra c7c63fa41c Merge branch 'main' into ganfra/kotlin_bindings 2022-10-27 14:37:53 +02:00
Benjamin Kampmann 0e59078211 fix(ffi): call process_sync_error of client for sliding-sync errors. break if wnated 2022-10-27 12:32:49 +01:00
Benjamin Kampmann 120d5edb03 feat(sliding-sync): Replace anyhow with proper Error type 2022-10-27 12:32:05 +01:00
Benjamin Kampmann afc33e616c revert start_sync removal 2022-10-27 12:06:06 +01:00
Jonas Platte 324411201e fix(sdk): Enable required ruma features for experimental-timeline 2022-10-27 12:56:51 +02:00
Jonas Platte e1ecc9de0d chore: Bump versions of matrix-sdk, matrix-sdk-base
… to bring them up to the released ones from the v0.6.x branch.
All changes from those versions are already present on main.
2022-10-27 12:56:37 +02:00
Jonas Platte c9c4473cd4 ci: Cache xtask for bindings checks 2022-10-27 11:58:42 +02:00
Jonas Platte 41be4c5209 ci: Test bindings generation 2022-10-27 11:58:42 +02:00
Jonas Platte 426f60a6a2 ci: Add bindings check to xtask 2022-10-27 11:58:42 +02:00
Jonas Platte eddf202a76 chore: Upgrade UniFFI 2022-10-27 11:27:28 +02:00
Stefan Ceriu d4cd8710a4 Refactor the SessionVerification flows and get them working through sliding sync 2022-10-27 10:45:05 +03:00
Benjamin Kampmann a443e7277d feat: Add sliding sync timeline events and extensions (#1054)
Add general extension framework for sliding sync, implementing the e2ee, to-device and account-data extensions as per existing proxy implementation. Add a new (ffi exposed) function to use activate the extensions.

Also extends jack-in to have permanent login and storage support now, rather than posting an access token and expose messages inside the sliding-sync layer to actually use the decrypted messages if given. Contains a lot of fixes around these aspects, too, like uploading any remaining messages from the olm-machine on every sliding-sync-request or processing even if no room data is present (which can happen now as processing only extensions might takes place).
2022-10-25 13:42:43 +02:00
Jonas Platte 2232092f11 refactor(sdk): Move timeline event handling fns to TimelineInner 2022-10-25 13:03:52 +02:00
Damir Jelić 2547d6ed64 fix(crypto): Don't create an infinite amount of streams in the SAS examples 2022-10-25 13:00:27 +02:00
Damir Jelić 6cb37520ce docs(bindings): Document the EncryptionSettings a bit better 2022-10-25 12:44:18 +02:00
Jonas Platte 50a5ec89e9 chore: Fix more clippy lints 2022-10-25 12:20:07 +02:00
Jonas Platte 285dc129c3 chore(crypto): Clean up SecretInfo::as_key implementation 2022-10-25 12:20:07 +02:00
Jonas Platte a59fdc08bb chore: Fix clippy lints
Automated with cargo clippy --fix.
2022-10-25 12:20:07 +02:00
Jonas Platte 9de98dfa65 fix(sdk): Remove token field from SyncSettings Debug output 2022-10-24 13:14:30 +02:00
Damir Jelić c03c90c1cf feat(bindings)!: Allow passing the E2EE settings when sharing a room key 2022-10-24 09:50:57 +02:00
Damir Jelić 4a6208f808 feat(crypto): Add signaling to the SAS verification
This patch adds a way for users to listen to changes in the state of a
SAS verification.

This makes it much more pleasant to go through the verification flow and
incidentally easier to document it.
2022-10-24 09:50:17 +02:00
Jonas Platte 1aa48beca9 Revert "refactor(bindings): Use new uniffi::Enum derive macro in crypto-ffi"
This reverts commit 6b9075aa42.
2022-10-20 17:41:16 +02:00
Jonas Platte e05444554d chore: Fix typo in comment 2022-10-20 14:14:18 +02:00
Jonas Platte 411095425c refactor(sdk): Make ClientBuilder::{sled_store, indexeddb_store} simple setters 2022-10-20 13:35:06 +02:00
Jonas Platte 6b9075aa42 refactor(bindings): Use new uniffi::Enum derive macro in crypto-ffi 2022-10-20 12:53:09 +02:00
Jonas Platte 01dc166293 chore: Upgrade UniFFI 2022-10-20 12:53:09 +02:00
Jonas Platte 584a82b19b fix(sdk): Remove Debug implementation for SessionTokens 2022-10-20 11:25:54 +02:00
Jonas Platte 0aba22855b fix(sdk): Don't include access and refresh token in Debug output of Session 2022-10-20 11:25:54 +02:00
Jonas Platte a50743874f chore(base): Merge consecutive impls for the same type 2022-10-20 11:25:54 +02:00
Flix 7851eefb61 refactor(base)!: Get rid of String in StoreError 2022-10-19 16:28:27 +02:00
Stefan Ceriu 8470b494f4 chore(bindings): Replace various expectations with anyhow contexts 2022-10-19 13:18:19 +02:00
Andy Uhnak c92d946777 Set local trust 2022-10-19 09:38:16 +02:00
Jonas Platte 0cfc7540cf refactor: Use workspace dependencies for tracing 2022-10-18 19:24:22 +02:00
Jonas Platte 6990c1ca5c test(base): Use tracing-subscriber for test debugging
… same as in our other crates.
2022-10-18 19:24:22 +02:00
Jonas Platte 0ee63344da chore(base): Sort dev-dependencies 2022-10-18 19:24:22 +02:00
Jonas Platte 3daaa457e1 fix(bindings): Make tracing dependency for crypto-js optional 2022-10-18 19:24:22 +02:00
Jonas Platte 7a826fb7d6 ci: Cancel all CI jobs for old commits when pushing to a PR branch 2022-10-18 17:06:42 +02:00
Jonas Platte 95dfedb70a Another test commit 2022-10-18 16:52:01 +02:00
Jonas Platte eb58dcc556 Try to make it work 2022-10-18 16:51:07 +02:00
Damir Jelić 57e9b36fac chore(bindings): Don't mention that the OlmMachine is a memory-only one 2022-10-18 15:49:09 +02:00
Damir Jelić 90865e2a0a chore(bindings): Clarify the OlmMachine constructor in the WASM bindings 2022-10-18 15:49:09 +02:00
Damir Jelić 52d96ceb60 fix(bindings): Allow setting the store without a passphrase 2022-10-18 15:49:09 +02:00
Damir Jelić 8a720af215 feat(crypto): Support transitioning from a QR verification into a SAS or scanning QR one 2022-10-18 15:18:51 +02:00
Jonas Platte bac95f4494 ci: Upgrade cancel-workflow-action 2022-10-18 15:00:35 +02:00
Jonas Platte 31293c6c2b Testing with empty commit 2022-10-18 14:39:47 +02:00
Jonas Platte 089f92d238 ci: Cancel all CI jobs for old commits when pushing to a PR branch
(not just jobs from the ci workflow file)
2022-10-18 14:23:21 +02:00
Andy Uhnak 1a466eb667 Add flow_id to logs 2022-10-18 13:09:12 +01:00
Andy Uhnak 8bbdd28a8b Use cfg-if and debug logs 2022-10-18 13:09:11 +01:00
Andy Uhnak 61452ad190 Replace QR with SAS verification 2022-10-18 13:08:47 +01:00
Flix 4816d93e96 docs: Improve documentation for custom event handler context 2022-10-18 13:39:08 +02:00
Jonas Platte f25af209e1 refactor: Use workspace dependencies for zeroize 2022-10-18 13:38:05 +02:00
Jonas Platte e6891addfb refactor: Use workspace dependencies for vodozemac 2022-10-18 13:38:05 +02:00
Jonas Platte f57b7782f4 refactor: Use workspace dependencies for ruma 2022-10-18 13:38:05 +02:00
Jonas Platte e91cee7154 fix(sdk): Always send an access token for get_profile 2022-10-18 13:31:59 +02:00
Jonas Platte 5b46fa73e1 fix(sdk): Always send an access token for get_display_name 2022-10-18 11:19:32 +02:00
Jonas Platte b309441dec fix(sdk): Don't log the access token in HttpClient::send 2022-10-17 20:04:49 +02:00
Jonas Platte 391efcec12 feat(appservice): Return a concrete type from AppService::service 2022-10-17 17:03:37 +02:00
Jonas Platte 4e583bcb8a chore: Exclude xtask from tarpaulin coverage collection 2022-10-17 15:38:42 +01:00
Benjamin Kampmann 5e621b7132 fix!: Switch to uniffi 0.21.0 and workspace-wide dependencies
Upgrade MSRV to 1.64, the first stable release to support workspace-wide depenendencies:
https://blog.rust-lang.org/2022/09/22/Rust-1.64.0.html#cargo-improvements-workspace-inheritance-and-multi-target-builds
2022-10-17 15:38:04 +01:00
Benjamin Kampmann ab796cb32c ci(xtask): switch to using uniffi as a lib rather than globally installed binary 2022-10-17 15:38:04 +01:00
Richard van der Hoff dd82e0b8fc chore: Update bindings/README 2022-10-17 13:24:09 +00:00
Doug 7125730917 ci(xtask): Switch to xtask for swift; run swift tasks on macOS
Merge pull request #1023 from matrix-org/doug/swift-linux: Run Swift tests on macOS
2022-10-17 14:12:43 +02:00
Jonas Platte db2771bd17 feat(bindings): New timeline API 2022-10-17 13:40:35 +02:00
Jonas Platte 95face4aa4 chore(bindings): Delete unused code left over from old timeline API 2022-10-17 13:40:35 +02:00
Jonas Platte a7cb80df1b refactor(appservice): Clean up implementation of user_id_is_in_namespace 2022-10-13 12:13:56 +02:00
ganfra e7d5b44343 Kotlin bindings: add matrix-rust-sdk.aar file to sample 2022-10-12 18:24:30 +02:00
ganfra 47478702b2 Kotlin bindings: create build_sdk script 2022-10-12 18:24:30 +02:00
ganfra 648895e2b0 Kotlin bindings: add uniffi.toml 2022-10-12 18:24:30 +02:00
ganfra c8bddea6e1 Kotlin bindings: update Cargo.toml for kotlin generation 2022-10-12 18:24:30 +02:00
ganfra f42215180e Kotlin bindings: create project with sample, crypto and sdk modules 2022-10-12 18:24:12 +02:00
Jonas Platte 1e77e91ec4 refactor(appservice): Replace warp with axum 2022-10-12 17:32:31 +02:00
Jonas Platte 95613be6c9 chore: Remove redundant cfg attribute 2022-10-12 17:32:31 +02:00
Jonas Platte b83e6be01e refactor(sdk): Use lower-level libraries for builtin SSO server 2022-10-12 17:32:31 +02:00
Damir Jelić 086b6127e2 feat: Improve the timeline example 2022-10-12 16:12:06 +02:00
Jonas Platte 54fd40d8f5 feat(sdk): Add new timeline API 2022-10-12 16:12:06 +02:00
Damir Jelić 67d968d4fa refactor(crypto): Remove the device ID from the megolm v2 m.room.encrypted content 2022-10-12 14:37:05 +02:00
Damir Jelić 7e14857239 test(crypto): Test that megolm v2 key forwards work 2022-10-12 14:37:05 +02:00
Damir Jelić 2425cd99cf fix(crypto): Introduce the proper megolm v2 forwarded room key content 2022-10-12 14:37:05 +02:00
Damir Jelić 7c97c27441 feat(crypto): Start sending out megolm v2 room key requests 2022-10-12 14:37:05 +02:00
Damir Jelić cbadd90eff feat(crypto): Start responding to megolm v2 room key requests 2022-10-12 14:37:05 +02:00
Jonas Platte d18b57dcdd refactor: Make use of as_ruma_api_error internally 2022-10-12 12:34:09 +02:00
Jonas Platte 23c5929cfa feat(sdk): Add Error::as_ruma_api_error 2022-10-12 12:34:09 +02:00
Jonas Platte 7bfa622a57 feat(sdk): Add HttpError::as_ruma_api_error 2022-10-12 12:34:09 +02:00
Jonas Platte f4e0cab11f feat(sdk)!: Merge HttpError::UiaaError into HttpError::Api 2022-10-12 12:34:09 +02:00
Jonas Platte f07735291e Fix warnings from generated code 2022-10-10 19:24:56 +02:00
Anderas d4e7076e1d Compile Crypto FFI for MacOS 2022-10-10 18:59:25 +02:00
Jonas Platte 61e95abaf2 refactor: Use Box::default
… as suggested by clippy.
2022-10-10 18:52:59 +02:00
Damir Jelić 8763a2468c fix(crypto): Take more data into account when comparing sessions 2022-10-10 15:20:25 +02:00
Damir Jelić 8f6e3033e3 fix(crypto): Check for existing room keys when receiving a new one.
Now that we're not scoping the room keys by the Curve25519 sender key
we're opening the door of multiple devices trying to insert the same
room key into our store.

This patch changes our logic so we only store room keys from an
m.room_key event if we don't have one already or if the new key is
a better version of the one we already have.

This mostly assumes that the first room key with a given session id
is coming from the creator of the room key.
2022-10-10 15:20:25 +02:00
Damir Jelić 2f94886663 refactor(crypto)!: Don't use the Curve25519 sender key to store room keys 2022-10-10 15:20:25 +02:00
Jonas Platte 8b728d4ada ci: Pin typos version
Currently, master is broken: https://github.com/crate-ci/typos/issues/590
2022-10-06 17:27:55 +02:00
Jonas Platte 26faf0d4c0 feat(bindings): Add custom kotlin package name for crypto-ffi 2022-10-06 17:27:55 +02:00
Jonas Platte a3113bd125 refactor(bindings): Start using #[uniffi::export] for matrix-sdk-crypto-ffi 2022-10-06 17:27:55 +02:00
Jonas Platte a75d7171f8 refactor(bindings): Rename crypto-ffi UniFFI namespace
… from olm to matrix_crypto_ffi to match the lib name.
Names need to match for integration of UniFFI's proc-macro frontend.
2022-10-06 17:27:55 +02:00
Jonas Platte c3eaa864dd refactor(bindings): Unset custom lib name for crypto-ffi 2022-10-06 17:27:55 +02:00
Jonas Platte 6a561c20e2 refactor(bindings): Use uniffi::export for most of ClientBuilder's API 2022-10-06 10:56:22 +02:00
Jonas Platte 0581b8a884 refactor: Derive Default for enums 2022-10-06 10:55:49 +02:00
Jonas Platte bdfdaeb0ae chore: Upgrade async-once-cell 2022-10-06 10:55:49 +02:00
Jonas Platte c24c20f7f1 Raise MSRV to 1.62 2022-10-06 10:55:49 +02:00
Jonas Platte 6b3acf1bf7 chore(sdk): Use inline tables more in Cargo.toml
Makes the file a little more comprehensible.
2022-10-06 10:55:49 +02:00
Jonas Platte 822cdae8f3 chore(sdk): Only include derive_builder dependency for sliding-sync feature 2022-10-06 10:55:49 +02:00
Jonas Platte 4fcbb61145 refactor!: Delete the store module
It was very confusing that matrix_sdk::store::make_store_config's first
argument was either a path or a database name depending on the build
configuration. ClientBuilder::{sled_store, indexeddb_store} are also
easier to use.
2022-10-05 13:49:12 +02:00
Jonas Platte 4628481d0e refactor(bindings): Use UniFFI proc-macro frontend more 2022-10-05 12:21:44 +02:00
Jonas Platte e05de8d4ce chore: Upgrade UniFFI 2022-10-05 12:21:44 +02:00
Johannes Marbach 6bc79b04cf feat(bindings): Allow clients using matrix-sdk-ffi to set the user agent 2022-10-05 09:18:52 +02:00
Damir Jelić fa88751548 fix(crypto): Ignore duplicate verification requests 2022-10-04 13:38:07 +02:00
Andy Uhnak 09c906b1d7 Debug message 2022-10-04 11:50:16 +01:00
Andy Uhnak 6fab6ef318 Ignore duplicate verification requests 2022-10-04 11:38:08 +01:00
Lautaro Bustos d5728f235d feat(sdk): Allow configuring the presence in the SyncSettings 2022-10-03 11:52:23 +02:00
Johannes Marbach 6827c70886 chore: Ignore Swift's .build folder 2022-09-30 21:54:09 +02:00
Jonas Platte ab1a6a6b37 chore: Remove experimental-timeline Cargo feature 2022-09-30 13:48:17 +02:00
Jonas Platte 3c9c7290ae chore: Remove deprecated functions 2022-09-30 10:40:56 +00:00
Benjamin Kampmann 530f8057cc Merge pull request #1071 from matrix-org/ben-releasing-0.6
chore: crates.io only accepts versioned git deps
2022-09-29 15:02:10 +02:00
Ivan Enderlin 8e0e752f12 Merge pull request #1075 from Hywan/fix-crypto-nodejs-release-script-npm-token
fix(crypto-nodejs): Hopefully it will make `NPM_TOKEN` available in the script
2022-09-29 11:52:30 +02:00
Ivan Enderlin b1493c5217 fix(crypto-nodejs): Hopefully it will make NPM_TOKEN available in the script.
We hope that adding this to the workflow will make `NPM_TOKEN`
available from within the script.
2022-09-29 11:36:29 +02:00
Ivan Enderlin 7988dc6cf3 Mergfix(crypto-nodejs): Fix the prep release script
fix(crypto-nodejs): Fix the prep release script
2022-09-28 17:48:43 +02:00
Ivan Enderlin 180796c747 fix(crypto-nodejs): Fix the prep release script. 2022-09-28 17:46:56 +02:00
Benjamin Kampmann fefd2a6b68 chore: crates.io only accepts versioned git deps 2022-09-28 17:15:09 +02:00
Benjamin Kampmann 269bf3a706 chore: remove old release notes 2022-09-28 17:07:37 +02:00
Benjamin Kampmann 91d1ee9f09 chore: fix typos in Upgrade guide 2022-09-28 17:07:37 +02:00
Benjamin Kampmann b22fe63476 chore: More minor changes of note 2022-09-28 17:07:37 +02:00
Benjamin Kampmann 92467af4a0 docs: Upgrading typo fixes 2022-09-28 17:07:37 +02:00
Benjamin Kampmann f1f1c1bba6 chore: Version bump 2022-09-28 17:07:37 +02:00
Benjamin Kampmann ff82d6420d chore: specify which crates to release and which not 2022-09-28 17:07:37 +02:00
Benjamin Kampmann b9409b7c0f docs: more migrations guide 2022-09-28 17:07:37 +02:00
Benjamin Kampmann ea51935601 docs: Clarifications in the Upgrade guide 2022-09-28 17:07:37 +02:00
Benjamin Kampmann 2fff5d916b docs: More Upgrade guidance 2022-09-28 17:07:37 +02:00
Benjamin Kampmann d16faee68b docs: First outline of upgrades guide 2022-09-28 17:07:37 +02:00
Benjamin Kampmann df9b60a5bc chore: Ignore flaky redaction tests 2022-09-28 17:07:10 +02:00
Damir Jelić 1a57170970 test(crypto): Make sure we don't accept megolm encrypted events over to-device 2022-09-28 16:03:17 +02:00
Damir Jelić 41449d2cc3 test(crypto): Test that we reject forwarded room keys from other users 2022-09-28 16:03:17 +02:00
Damir Jelić 093fb5d0aa fix(crypto): Only accept forwarded room keys from our own trusted devices 2022-09-28 16:03:17 +02:00
Ivan Enderlin 513afa57ef feat(indexeddb): Introduce the experimental-nodejs feature
feat(indexeddb): Introduce the `experimental-nodejs` feature
2022-09-28 14:57:55 +02:00
Ivan Enderlin 25632f04d4 feat(crypto-js): Update to napi-rs 2.9.1
feat(crypto-js): Update to `napi-rs` 2.9.1
2022-09-28 14:52:03 +02:00
Ivan Enderlin 7922786e0c chore: Fix formatting. 2022-09-28 14:34:16 +02:00
Ivan Enderlin 9a006c58f5 feat(crypto-js): Update to napi-rs 2.9.1 2022-09-28 14:30:40 +02:00
Ivan Enderlin 9f4385e639 feat(indexeddb): Introduce the experimental-nodejs feature.
By default, the new `experimental-nodejs` feature is
disabled. However, when enabled, it uses our own fork of
`indexed_db_futures` that make it work on Node.js, and so this entire
`matrix-sdk-indexebdb` crate.
2022-09-28 14:27:37 +02:00
Damir Jelić e79b683560 fix(crypto): Drop the redundant event_type field from ToDeviceEvent<C> 2022-09-28 11:27:44 +02:00
Damir Jelić 27e4675df0 fix(crypto) Fix the zeroizing serialization of to-device events
The crypto crate consumes to-device events, if needed decrypts them, and
in the end reserializes while zeroizing secrets.

It needs to do this reserialization cycle as loslessly as possible, this
is why we have a bunch of BTreeMaps lying in events and contents that
capture unknown fields.

The Deserialize implementation of ToDeviceEvent<C> put the event type
into this BTreeMap but the Serialize implementation figures it out from
the EventType trait of the content.

This patch simplifies things by putting the event type into
ToDeviceEvent<C>, this also means that we can just derive the Serialize
implementation for ToDeviceEvent<C>.
2022-09-27 21:33:06 +02:00
Benjamin Kampmann b5bd6dfee9 fix: Apply redactions to room state events in database, too (#917)
fixes #890
2022-09-27 09:24:53 +02:00
Ivan Enderlin f8b02d1a11 feat(crypto-js): Implement OlmMachine.export_room_keys and .import_room_keys
feat(crypto-js): Implement `OlmMachine.export_room_keys` and `.import_room_keys`
2022-09-27 07:26:51 +02:00
Jonas Platte 0a5ebe4dce feat(sdk): Make EventHandlerDropGuard public (#1055) 2022-09-26 18:18:12 +02:00
Benjamin Kampmann e8278b5d68 feat: add Result return value to sync_* (#1037)
Inspired by the changes in #1013 I was thinking about the use case for `sync_*` and how we handle error cases. Most notably while we give the callback the option to stop the loop, we don't really give an indication to the outside, how to interpret that cancellation: was there a failure? should we restart?

Take e.g. a connectivity issue on the wire, we'd constantly loop and just `warn`, what you might or might not see. Even if you handle that in the `sync_with_result_callback` and thus break the loop, the outer caller now still doesn't know whether everything is honky dory or whether they should restart. 

This Changes reworks that area by having all the `sync` return `Result<(), Error>`, where `()` means it was ended by the inner callback (which in `sync()` never occurs) or `Error` is the error either the inner `result_callback` found or the that was coming from the `send` in the first place. Thus allowing us to e.g. back down to sync as it was a dead wire or restart it if there was only a temporary problem. Making all that a just a bit more "rust-y".
2022-09-26 17:14:15 +02:00
Jonas Platte f054141e66 chore: Revert "feat(sdk): Make room actions return typed room objects" 2022-09-26 14:13:25 +02:00
Jonas Platte 1a6d5e7b26 Revert "feat(sdk): Make room actions return typed room objects"
This reverts commit febfcf9796.
2022-09-26 14:01:52 +02:00
Jonas Platte d3e5a3b7db Revert "test: Add test for repeated joining and leaving"
This partially reverts commit df4ee7db4c.
The changes to logging and ci-start.sh are kept.
2022-09-26 12:31:12 +02:00
Jonas Platte 92809590b1 Revert "feat(examples): Add an example that lets you create rooms"
This reverts commit 01f8ed10aa.
2022-09-26 12:23:08 +02:00
Jonas Platte 00d388f3d3 Revert "feat(sdk): Make room actions return typed room objects"
This reverts commit febfcf9796.
2022-09-26 12:19:36 +02:00
Jonas Platte 59901b6349 Update Cargo.lock 2022-09-26 12:19:36 +02:00
Johannes Becker 914ac5279e chore: Make clippy happy 2022-09-23 17:01:01 +02:00
Johannes Becker c23976f975 refactor(appservice): Move example to top-level 2022-09-23 17:01:01 +02:00
Emelie Graven cb94d60e0e feat(appservice): Add default request config
This adds a default RequestConfig to use when creating new virtual
clients.
2022-09-22 14:25:00 +02:00
Ivan Enderlin df50a5446f test(crypto-js): Test InboundGrounSession.sessionId and .hasBeenImported. 2022-09-22 11:31:28 +02:00
Ivan Enderlin 62ab263d0e test(crypto-js): Test OlmMachine.(en|de)crypt_exported_room_keys. 2022-09-22 11:27:12 +02:00
Emelie Graven 2818551d62 refactor(appservice)!: Use builder pattern 2022-09-22 10:38:17 +02:00
Emelie Graven c29b0f154a chore: Add rust.vim edition workaround 2022-09-22 10:38:17 +02:00
Ivan Enderlin 6fa04a0ba1 feat(crypto-js): Implement OlmMachine.(en|de)crypt_exported_room_keys. 2022-09-21 18:00:15 +02:00
Ivan Enderlin dee14c4ee4 doc(crypto-js): Improve documentation of OlmMachine.import_room_keys. 2022-09-21 17:50:28 +02:00
Ivan Enderlin 5b919dd840 test(crypto-js): Test OlmMachine.import_room_keys. 2022-09-21 17:46:23 +02:00
Ivan Enderlin 406fc58720 feat(crypto-js): Implement OlmMachine.import_room_keys. 2022-09-21 17:37:23 +02:00
Ivan Enderlin b4cec6e1bb feat(crypto-js): Implement OlmMachine.export_room_keys. 2022-09-21 16:03:51 +02:00
Ivan Enderlin 6be0fc1fae feat(sdk): Rename (export|import)_keys to (export|import)_room_keys
feat(sdk): Rename `(export|import)_keys` to `(export|import)_room_keys`
2022-09-21 16:03:29 +02:00
Ivan Enderlin 782b256ea9 test(crypto): Rename OlmMachine.export_keys to OlmMachine.export_room_keys. 2022-09-21 13:43:25 +02:00
Ivan Enderlin 82670022f9 feat(crypto-ffi): Update olm.udl. 2022-09-21 13:24:25 +02:00
Ivan Enderlin b8c41e805b feat(sdk): Rename decrypt_key_export to decrypt_room_key_export. 2022-09-21 13:18:24 +02:00
Ivan Enderlin e3d63c5593 feat(sdk): Rename encrypt_key_export to encrypt_room_key_export. 2022-09-21 13:16:08 +02:00
Ivan Enderlin 0222a8fec2 feat(sdk): Rename OlmMachine.import_keys to .import_room_keys.
Because that's what it does :-).
2022-09-21 13:12:07 +02:00
Ivan Enderlin b442247946 feat(sdk): Rename OlmMachine.export_keys to .export_room_keys.
Because that's what it does :-).
2022-09-21 13:03:42 +02:00
Ivan Enderlin c0ebeee730 feat(crypto-js): Implement OlmMachine.get_identity
feat(crypto-js): Implement `OlmMachine.get_identity`
2022-09-21 10:44:18 +02:00
Stefan Ceriu a46b8f392a Switch ffi layer logs output to stderr instead of stdout 2022-09-21 08:24:09 +02:00
Jonas Platte b12da9d4db refactor!: Move JS-specific functionality behind a Cargo feature
… for matrix-sdk, matrix-sdk-base, matrix-sdk-common and matrix-sdk-crypto.
matrix-sdk-indexeddb as well as the JS bindings and wasm_command_bot are
left as-is because they will likely always require JS.
2022-09-20 14:08:21 +02:00
Stefan Ceriu 6f5681f7c2 feat(bindings): Expose method for fetching media thumbnails 2022-09-19 10:56:22 +00:00
Jonas Platte fee0db03c8 ci: Don't collect coverage for labs 2022-09-19 12:15:13 +02:00
Jonas Platte b2ce906bce ci: Don't report coverage inside test code 2022-09-19 12:15:13 +02:00
Jonas Platte e45d6f45fd refactor: Replace str::to_string with to_owned 2022-09-16 17:45:43 +02:00
Ivan Enderlin 84aa85958c test(crypto-js): Test OlmMachine.getIdentity. 2022-09-16 11:23:32 +02:00
Jonas Platte b941c16b7d chore(sdk): Upgrade derive_builder 2022-09-16 11:17:24 +02:00
Ivan Enderlin 1a5379881e test(crypto-js): Test EventId. 2022-09-16 11:11:06 +02:00
Ivan Enderlin 0c4b85e1f9 feat(crypto-js): Implement OwnUserIdentity and UserIdentity. 2022-09-16 11:02:34 +02:00
Ivan Enderlin 602dbe42f2 doc(crypto): Fix a typo. 2022-09-16 10:57:02 +02:00
Ivan Enderlin d3d316ee6c chore(crypto-js): Add helper to cast from JS Array to Vec<T>. 2022-09-16 10:46:28 +02:00
Jonas Platte 494969ed49 chore: Fix clippy lints 2022-09-15 20:48:22 +02:00
Kévin Commaille 34ed04958f fix(sdk): Export RoomKeyImportError 2022-09-15 18:35:59 +02:00
Jonas Platte 8da456055d refactor: Use event handlers in emoji_verification example 2022-09-15 18:33:58 +02:00
Jonas Platte ef462c786a refactor(sdk): Clean up sync_with_callback implementation 2022-09-15 17:53:32 +02:00
Benjamin Kampmann 1a50f42402 fix(jack-in): limit log4rs features to minimum 2022-09-15 17:08:09 +02:00
Benjamin Kampmann 020a75d55c feat: implement " MSC 3575: sliding sync " behind a feature flag (#728)
* starting with jack-in

* starting by flying tui

* connecting to real server, showing info

* add .env to gitignore

* infrastructure for tests

* display loading time for syncv2

* minor design updates

* initial sync

* finalise first edition of sliding sync

* directly link to sliding sync and show rooms list

* nicer UI, toggle logs

* passing through sliding sync homeserver

* separate syncs and disable v2 autostart

* selecting rooms

* nicer view

* configurable batches and more default needed events

* selecting rooms

* calculate and show status info per room

* precalculated room stats

* restructure code to allow for cancellation of streams

* finish up merge updates

* fix calculation error in room list len

* cleaning up system flow

* fixing sync up

* new multi-view API

* move sliding sync in separate module

* fixing format

* adding and clearning views

* expose filters and timeline limits

* renamed

* adding room subscriptions to sliding sync

* update summary

* live fetching and subscriptions in jack-in

* subscribe to selected room

* starting to switch to tuireal - using example

* status bar and first linkup

* re-adding rooms

* implementing port for customised update event

* showing details and timeline

* fix formatting

* cleaner UI, updating details quickly

* make it green

* implement other Ops

* proper handling of invalidation

* saving sliding sync results to db, too

* saving new prev_batch field if given

* split events and timeline

* cleaning up

* live updates

* upgrading to latest ruma and matrix-sdk

* Update tui-logger to fix the broken build

* fixing latest ruma sliding-sync-branch updates

* feat: first set of ffi sliding sync

* expose sliding sync via FFI

* implement un-/subscribe

* implement view state updates

* updating to latest JSON format and ruma update

* implementing room selecting for new data model

* fixing room selection

* fixing feature flag requirements for sliding-sync

* fixing style, clippy and docs

* style(sliding-sync): fixing rust format styles

* fix(ffi): fixing sliding sync merge failure

* fix(jack-in): update jack-in to latest ruma

* fix(sliding-sync): need to have a version set before polling proxy

* expose sliding sync builder over ffi

* add SlidingSyncViewBuilder

* add forgotten changes on sdk itself

* new file logger feature on jack for deeper logging

* fix(http-client): log the raw request we are sending out

* feat(sliding-sync): better logging

* fix(sliding-sync): switch to full-listen after reaching live state in full-sync and make sure we replace the correct entries

* feat(ffi): expose sliding sync view ranges

* fix(ffi): fixing sliding sync start_sync loop to actually loop

* feat(sliding-sync): allow lookup of room data

* feat(sliding-sync-ffi): fetching name of room

* feat(ffi): expose unread_notifications of rooms

* feat(ffi): stoppable spawn for sliding sync

* fix(ffi): expose has_unread_notifications on room

* feat(sliding-sync): latest room message

* fix(sliding-sync): update to latest ruma layout

* doc(sliding-sync): adding docs to builder fns

* feat(sliding-sync): extra signal on the view to inform about general updates

* fix(sync-v4-ffi): expose new callbacks via ffi

* fix(sliding-sync): reduce default required states to make things faster

* fix(sliding-sync): fix build params

* feat(jack-in): extended instrumentation

* fix(sliding-sync): unbreak faulty feature-gate

* fix(sliding-sync-ffi): mut where mut is due

* fix(sdk): allow separate homeserver on every request to unbreak using send on client while in sliding sync on a proxy

* fix(jack-in): update to latest dependencies, that work

* feat(ffi): helper to patch sliding sync room into regular room

* style(jack-in): cargo fmt

* fix(sliding-sync): Update to latest ruma changes

* fix(sliding-sync): fix missing FFI updates to latest ruma

* feat(sliding-sync)!: simplify stream cancellation, cancel ffi sync if already existing

* fix: timeline backwards pagination must work without synctoken

* fix(sliding-sync): clarify order of messaes in alive TL; pick correct last item

* fix: update view delegate api for clarity

* style(jack-in): fix cargo warnings

* feat(sliding-sync): update room details

* fix(sliding-sync): only update room info selectively when given

* fix(sliding-sync-ffi): convert and store counts as u32, check against 0 for has notificaitons

* style: cargo fmt, file endings and a few other minor style fixes

* docs(jack-in): improving CLI and Readme

* feat(sliding-sync): allow setting of required event_states on viewbuilder

* style(sliding-sync): docs and minor fixes

* style(sliding-sync): various clippy fixes

* style(jack-in): clippy suggestions applied

* fix(sliding-sync): Delegate becomes observer

* test(sdk): adding test for request config

* docs: Fixing copyright header

* style(ffi): Nicer naming of params for observer

* fix(ffi): sliding sync is not optional for now

* fix(sdk): remove superflusous tracing instrumentation

* fix(sdk): use structured logging

* fix(jack-in): removed unneded log import

* fix(jack-in): use server_name rather than deprecated user_id on ClientBuilder

* style: typo and clippy

* style(sliding-sync): clippy and formatting

* fix(sliding-sync): cleaning up minor syntax issues

* fix: remove unneded feature-definition section

* fix(sliding-sync): minor fixes as per review

* fix(sliding-sync): Make Builders owned

* fix(sliding-sync): more minor style improvements

* fix(sliding-sync): minor style improvements

* fix(sliding-sync): remove homeserver from RequestConfig, use specific internal fn instead

Co-authored-by: Stefan Ceriu <stefanc@matrix.org>
2022-09-15 11:45:29 +00:00
Ivan Enderlin f4e0c6e243 feat(crypto-js): Start implementing OlmMachine.get_identity. 2022-09-15 10:32:57 +02:00
Ivan Enderlin 01f1b9b846 feat(crypto-js): Implement EventId. 2022-09-15 10:32:57 +02:00
Ivan Enderlin abcd287496 chore(crypto-js): Simplify code with a lovely macro. 2022-09-15 10:32:57 +02:00
Ivan Enderlin cf96a3ba2e feat(crypto-js): Implement key verification
feat(crypto-js): Implement key verification
2022-09-15 10:13:51 +02:00
Ivan Enderlin 9d2e0fe8ad doc(crypto-js): Fix typos. 2022-09-15 09:59:27 +02:00
Jonas Platte 83d5e567eb feat(bindings): Update send_reply to accept markdown 2022-09-14 22:10:16 +02:00
Benjamin Kampmann a47d8669cd feat: log out facilities
Merge pull request #1013 from matrix-org/ismail/logout

Add logout facilities to `client` and helpers to ffi for tracking the soft-logout issued by a server. Further more this adapts the `sync_with_callback` by adding a new `sync_with_result_callback` that hands the entire `Result` to the callback.
2022-09-14 15:15:47 +02:00
ismailgulek 0643292d76 Fix formatting 2022-09-14 15:07:05 +03:00
ismailgulek 8a26ba8343 Add a warning on sync error 2022-09-14 14:29:30 +03:00
ismailgulek cc1c6aedcb Revert sync_with_callback api call changes 2022-09-14 14:17:30 +03:00
ismailgulek 55cf573142 Implement the new sync with result callback method 2022-09-14 14:10:01 +03:00
Stefan Ceriu c5006081e6 feat(bindings): Add method for sending plain text replies 2022-09-14 10:21:23 +00:00
Ivan Enderlin 4c4fcf91c1 chore(crypto-js): Inline vodozemac dependency. 2022-09-14 10:01:03 +02:00
Ivan Enderlin 6842fb97fd chore(crypto-js): Make Clippy happy. 2022-09-14 09:58:09 +02:00
Ivan Enderlin 8027a3036c test(crypto-js): Remove dependency to canvas. 2022-09-14 09:58:09 +02:00
Ivan Enderlin 1d9ac6e60c chore(crypto-js): Fix typos. 2022-09-14 09:58:09 +02:00
Ivan Enderlin 2f35b2cfc6 feat(crypto-js): QrCodeScan implements Debug. 2022-09-14 09:58:09 +02:00
Ivan Enderlin 7edd6a148c doc(crypto-js): Fix module documentation. 2022-09-14 09:58:09 +02:00
Ivan Enderlin 3b526ea412 doc(crypto-js): Add missing documentation. 2022-09-14 09:58:09 +02:00
Ivan Enderlin 1c50cee5d7 feat(crypto-js): Implement Sas and Qr cancel* methods. 2022-09-14 09:58:09 +02:00
Ivan Enderlin cb95c59194 test(crypto-js): Test m.key.verification.start and .done for QR code. 2022-09-14 09:58:09 +02:00
Ivan Enderlin 792b4581ab feat(crypto-js): Implement Qr.reciprocate and .confirm_scanning. 2022-09-14 09:58:09 +02:00
Ivan Enderlin 58ea598c68 feat(crypto-js): Implement VerificationRequest.scan_qr_code. 2022-09-14 09:58:09 +02:00
Ivan Enderlin 581c537396 test(crypto-js): Properly test `Qr.toQrCode. 2022-09-14 09:58:09 +02:00
Ivan Enderlin 9834b67bd5 feat(crypto-js): QrCode.renderIntoBuffer returns an Uint8ClampedArray. 2022-09-14 09:58:09 +02:00
Ivan Enderlin 6f89d02599 test(crypto-js): Test QrCode.render_into_buffer. 2022-09-14 09:58:09 +02:00
Ivan Enderlin cbb5080837 test(crypto-js): Properly test Qr.toBytes. 2022-09-14 09:58:09 +02:00
Ivan Enderlin 6a05f834a9 test(crypto-js): Test Qr.toBytes. 2022-09-14 09:58:09 +02:00
Ivan Enderlin c7e0b3ee31 test(crypto-js): Testing key verification workflow until QR code generation. 2022-09-14 09:58:09 +02:00
Ivan Enderlin 0d57983e1b feat(crypto-js): Implement VerificationRequest.generate_qr_code. 2022-09-14 09:58:09 +02:00
Ivan Enderlin bbfc076c7f test(crypto-js): Inject bootstrap cross signing keys when setting up machines. 2022-09-14 09:58:09 +02:00
Ivan Enderlin e367d8574d feat(crypto-js): Implement OlmMachine.bootstrap_cross_signing. 2022-09-14 09:58:09 +02:00
Ivan Enderlin 1be17d354d feat(crypto-js): Implement OlmMachine.(export|import)_cross_signing_keys. 2022-09-14 09:58:09 +02:00
Ivan Enderlin e8331cc40c feat(crypto-js): Enable the qrcode feature by default. 2022-09-14 09:58:09 +02:00
Ivan Enderlin 71a2fac46f test(crypto-js): Reorganize the tests a little bit. 2022-09-14 09:58:09 +02:00
Ivan Enderlin 8948333e1e test(crypto-js): Test until m.key.verification.done \o/. 2022-09-14 09:58:09 +02:00
Ivan Enderlin c471a6fb4d test(crypto-js): Split the Key Verification test case into a test suite. 2022-09-14 09:58:09 +02:00
Ivan Enderlin 6239d31bcf test(crypto-js): Test the Emoji and decimals implementations. 2022-09-14 09:58:09 +02:00
Ivan Enderlin b5a8103023 feat(crypto-js): Implement Sas.accept. 2022-09-14 09:58:09 +02:00
Ivan Enderlin 95709bb4b3 test(crypto-js): Test the Sas implementation. 2022-09-14 09:58:09 +02:00
Ivan Enderlin 14f22979c0 feat(crypto-js): Implement VerificationRequest.start_sas. 2022-09-14 09:58:09 +02:00
Ivan Enderlin e6141d8efc test(crypto-js): Continue to test m.key.verification.request and .ready. 2022-09-14 09:58:09 +02:00
Ivan Enderlin 155b187d45 test(crypto-js): Write first tests for key verification. 2022-09-14 09:58:09 +02:00
Ivan Enderlin e659c724cd chore(crypto-js): Some methods have been renamed. 2022-09-14 09:58:09 +02:00
Ivan Enderlin e00b9221b9 feat(crypto-js): Implement Device.request_verification. 2022-09-14 09:58:09 +02:00
Ivan Enderlin b6f01b3cec feat(crypto-js): Implement the Device and UserDevice API. 2022-09-14 09:58:09 +02:00
Ivan Enderlin 53e21e0c26 feat(crypto-js): Start implementation key verification API. 2022-09-14 09:58:06 +02:00
Ivan Enderlin 9155989060 feat(crypto): Simplify code and add documentation. 2022-09-14 09:56:33 +02:00
Doug bb62437369 feat(bindings): Expose redact method to FFI 2022-09-13 23:06:11 +02:00
Damir Jelić 6e6c474bcb chore(base): Bump the lru crate 2022-09-13 16:03:42 +02:00
Damir Jelić 8ba33f6fd3 chore: Bump vodozemac to a released version 2022-09-13 16:03:42 +02:00
ismailgulek 2591bcbca9 Fix PR remarks 2022-09-13 15:47:26 +03:00
ismailgulek 18a8b2f275 Merge branch 'main' into ismail/logout 2022-09-13 13:01:57 +03:00
ismailgulek f4764bbd8a Fix PR comment 2022-09-13 13:01:38 +03:00
Jonas Platte e46e13d1bf chore: Upgrade Ruma 2022-09-13 08:32:59 +00:00
Kévin Commaille 97995b7bf6 fix(sdk): Re-export qrcode encoding and decoding error types 2022-09-12 19:27:30 +02:00
ismailgulek b4f0438c1a Move processing sync errors into a separate method 2022-09-12 18:40:50 +03:00
ismailgulek 076de488e7 Avoid too much indentation 2022-09-12 17:54:55 +03:00
ismailgulek d0d8e38a1d Merge branch 'main' into ismail/logout 2022-09-12 17:38:24 +03:00
Damir Jelić aac41fc82a refactor(crypto): Remove the forwarding chains
These aren't really useful since they can be easily spoofed by any room
key forwarder.
2022-09-12 16:03:05 +02:00
ismailgulek 268ecea7fe Fix new format error 2022-09-12 16:55:03 +03:00
ismailgulek 24be8a8e82 Update tests 2022-09-12 16:29:46 +03:00
ismailgulek 3cc6fe5dea Fix format errors 2022-09-12 15:35:45 +03:00
Ivan Enderlin d1b2bfcaa4 feat(qrcode): Remove decoding QR code from an image
feat(qrcode): Remove decoding QR code from an image
2022-09-12 13:33:42 +02:00
Ivan Enderlin a0edd2f8d8 test(qrcode): Restore image only for one test. 2022-09-12 12:42:18 +02:00
Ivan Enderlin 478529f230 chore: Update Cargo.lock. 2022-09-12 12:28:31 +02:00
Ivan Enderlin 9411801245 feat(qrcode): Remove decoding QR code from an image.
This patch removes the `decode_image` (default) feature for this
`matrix-sdk-qrcode` crate.

First reason is that `rqrr` panics for some particular QR codes, and
we don't want to panic.

Second reason is that it's not a feature that is used. For Element on
iOS and Android, it's very unlikely that every frame from the camera
will be sent to `matrix-sdk-qrcode` to see if it can be decoded. So
it's obvious that an external library is used to read the bytes from
the QR code, that are then sent to `matrix-sdk-qrcode`. For Element on
Web, it's basically the same argument.

This feature is actually used only in our tests to ensure the
generated QR code is valid, but it sometimes fails due to `rqrr`
(cf. First reason).
2022-09-12 12:15:49 +02:00
ismailgulek 361313fbea Merge branch 'main' into ismail/logout 2022-09-12 13:10:21 +03:00
Ivan Enderlin 2a94f575b8 feat(qrcode): Allow VerificationData to receive a flow ID
feat(qrcode): Allow `VerificationData` to receive a flow ID
2022-09-12 12:10:11 +02:00
Ivan Enderlin f9d09b60d5 chore(crypto): Reduce the size of AnyDecryptedOlmEvent.
`AnyDecryptedOlmEvent::Custom` contains at least 440 bytes, while the
second-largest variant (`RoomKey`) contains at least 0 bytes. Let's
box `Custom` so that the size of `AnyDecryptedOlmEvent` stays low.
2022-09-12 11:57:45 +02:00
ismailgulek 03477afb26 Add initial_device_name and device_id parameters to login method 2022-09-12 12:53:28 +03:00
ismailgulek 6b66a1de56 Introduce did_update_restore_token delegate method 2022-09-12 12:52:27 +03:00
ismailgulek 519a005d16 Introduce is_soft_logout flag on Client and did_receive_auth_error delegate method 2022-09-12 12:51:35 +03:00
Ivan Enderlin 7831e0cd89 chore(crypto): Use to_owned instead of to_string. 2022-09-12 09:49:30 +02:00
Ivan Enderlin 70eeffbbb0 doc(qrcode): Update documentation.
Since we have switched to Vodozemac, those values don't need to be
unpadded base64 anymore.
2022-09-12 09:47:38 +02:00
Jonas Platte 831e802dd0 refactor(bindings): Move some more functions and methods out of UDL 2022-09-09 14:30:23 +02:00
Jonas Platte ab0c144f51 chore: Upgrade UniFFI 2022-09-09 14:30:23 +02:00
Jonas Platte dc05c6e2b8 chore: Silence clippy lint 2022-09-09 12:51:57 +02:00
Jonas Platte 3a6397fdba chore: Update Cargo.lock 2022-09-09 12:51:57 +02:00
Jonas Platte 4a481f09d1 fix(base): Make tokio dev-dependency arch-dependent 2022-09-09 12:51:57 +02:00
Ivan Enderlin fa6745bb60 feat(qrcode): DecodingError::Identifier is no longer useful. 2022-09-08 16:14:30 +02:00
Ivan Enderlin cb21d89229 test(qrcode): Removing decode_invalid_room_id.
A room ID can no longer be invalid, it's just a string representing
either a `EventId` (we can validate that but…) or a `TransactionId`
(which is an opaque string, so it can be anything).
2022-09-08 16:12:21 +02:00
Ivan Enderlin 12b1ec5ef9 feat(crypto): VerificationData takes a flow ID, removing a panic.
This patch updates `QrVerification::new_cross`, by passing a flow ID
as an owned `String` to `VerificationData`, thus removing a panic, and
allowing QR code verification to happen outside a room.
2022-09-08 15:43:26 +02:00
Ivan Enderlin aa1a47831a chore(crypto): Use longer variable names. 2022-09-08 15:43:09 +02:00
Ivan Enderlin cc5034f4b9 feat(qrcode): Allow VerificationData to receive a flow ID.
This patch updates `VerificationData` to receive a flow ID,
represented as an owned `String`, instead of an `OwnedEventId`. Why?
Because QR code verification can happen outside a room. In such
scenario, there is no event ID, but a transaction ID, unified behind
the `matrix_sdk_crypto::FlowId` enum. `VerificationData` doesn't
really care about that details. Proof is that `QrVerificationData`
receives an owned `String`, which is then casted into an
`OwnedEventId` to match this API properly; but at the top, it just
receives a string.

This patch brings also a little bit of clean up while editing code
around.
2022-09-08 15:37:01 +02:00
Jonas Platte 3be8c9585d refactor(sdk): Make SyncSettings Debug repr more compact 2022-09-08 12:13:30 +02:00
Jonas Platte d810fa6883 test(sdk): Enable logging for tests 2022-09-08 12:13:30 +02:00
Jonas Platte a744447bb5 test: Respect RUST_LOG in integration-testing 2022-09-08 12:13:30 +02:00
Damir Jelić 9252e2c7a9 refactor(sdk): Fetch the content using the new account data methods
Co-authored-by: Jonas Platte <jplatte@matrix.org>
2022-09-07 13:38:42 +02:00
Damir Jelić 282072b6b0 chore(bindings): Fix a typo 2022-09-07 13:38:42 +02:00
Timothy Hobbs e997da0e72 feat(sdk): Make created_dm_room public 2022-09-07 13:38:42 +02:00
Benjamin Kampmann b3f3d0a95e fix(sdk): proper implementation of stripped info preference
Merge pull request #979 from FlixCoder/cleanup

Fixes a problem, where non-stripped information of the room had predecence in all scenarios of the memory-, sled- and indexeddb-store, thought according to the spec, we prefer the full info only until we've received new stripped info (from another invite). This fixes that to be in line with the spec by removing stripped data when we see a full-event and keep stripped info preferred if found (so, after you joined, stripped data is removed and when you knocked or are invited again, it is preferred), without ever deleting full data. It also adds nice unit- and integration tests to ensure this works as intended.
2022-09-06 15:47:14 +02:00
ismailgulek 42767968ec Implement logout method on Client 2022-09-06 15:56:14 +03:00
Benjamin Kampmann 68a8a214ee Update testing/matrix-sdk-integration-testing/assets/ci-start.sh 2022-09-06 12:42:54 +02:00
Jonas Platte 5adec41b6b test: Use a weak password hash for crypto-store testing
This speeds up the crypto-store tests a lot.
2022-09-05 16:58:12 +02:00
Flix b816307ea9 fix: Listen only to events after sending the request 2022-09-05 16:41:55 +02:00
Flix a182578722 fix: Fix rooms being returned in wrong state and having wrong state 2022-09-05 16:41:55 +02:00
Flix 8b5368ff06 chore: Clean up various mini things 2022-09-05 16:41:52 +02:00
Flix a368caf2b0 test: Add StateStore integration test for stripped/non-stripped 2022-09-05 16:33:31 +02:00
Flix df4ee7db4c test: Add test for repeated joining and leaving 2022-09-05 16:33:31 +02:00
Damir Jelić 321e56cff8 fix(examples): Listen to the done event in the emoji verification example
Nowadays all verifications send a done event, so this is the safer
option.
2022-09-05 15:54:45 +02:00
Damir Jelić a640312503 feat(crypto): Add method to format emojis
This patch adds a method to format a list of emojis in a a terminal
friendly way.

This method was borrowed from weechat-matrix but it's also quite useful
in our own emoji verification example.
2022-09-05 15:54:45 +02:00
Damir Jelić b2452ae92c feat(examples): Add a verbosity flag to the emoji example
Since this example prints out messages to stdout, it becomes quite hard
to see when we ask for user input if all the logging is going on.

This patch adds a standard verbosity flag which disables all logging by
default.
2022-09-05 15:54:45 +02:00
Jonas Platte a25b2d4418 refactor(crypto): Clean up cryptostore_integration_tests macro 2022-09-05 15:44:14 +02:00
Jonas Platte 5f6775f47c ci: Only cancel running CI for previous commits on PRs 2022-09-05 15:01:38 +02:00
Jonas Platte c2a222278d ci: Consistently indent job steps 2022-09-05 15:01:38 +02:00
Jonas Platte 567b230cb7 ci: Cache xtask binary 2022-09-05 15:01:38 +02:00
Jonas Platte 8535c16bc8 ci: Don't require fmt to run before typo check and clippy 2022-09-05 15:01:38 +02:00
Jonas Platte d009d0475e ci: Move appservice and style back into ci workflow
Required for job dependencies.
2022-09-05 15:01:38 +02:00
Jonas Platte 6b8cf3c02a chore: Remove pre-commit configuration and CI job
It was not really being used.
2022-09-05 15:01:38 +02:00
Jonas Platte edfc0cbe20 refactor(sdk): Deprecate ClientBuilder::user_id 2022-09-05 12:43:21 +02:00
Jonas Platte 91186d8a25 doc(sdk): Replace deprecated method in doctest 2022-09-05 11:55:49 +02:00
Jonas Platte 090d67b6ef refactor(sdk): Move module-level documentation inside the module files 2022-09-05 11:55:49 +02:00
Jonas Platte fd4957f533 test(sdk): Address commented-out code in a test 2022-09-05 11:55:49 +02:00
Jonas Platte 08760bd4c0 refactor(sdk): Make base_client field of Client private 2022-09-05 11:55:49 +02:00
Jonas Platte b769827313 refactor(sdk)!: Move media methods from Client to a new type 2022-09-05 11:55:49 +02:00
Jonas Platte 79b5854c83 feat(sdk): Add request_config method to Client 2022-09-05 11:55:49 +02:00
Jonas Platte 38324f6c60 refactor(sdk): Use Client::send in Client::upload 2022-09-05 11:55:49 +02:00
Jonas Platte 33bce0b18d refactor(sdk): Move RoomMember into room module 2022-09-05 11:55:49 +02:00
Jonas Platte 245ecea263 feat(sdk): Add support for AnySyncTimelineEvent in event handlers 2022-09-05 11:55:17 +02:00
Jonas Platte d4ac1bffd0 refactor(sdk): Rename EventKind to HandlerKind
It's somewhat different as MessageLike, OriginalMessageLike and
RedactedMessageLike are not three distinct event kinds in Ruma.
2022-09-05 11:55:17 +02:00
Jonas Platte d6af63e37b refactor(sdk): Run event handlers for the same event concurrently 2022-09-05 11:55:17 +02:00
Jonas Platte 57dde2c4d3 refactor(sdk): Avoid duplicate work and fix event handler call order
Previously, when both a possibly-redacted timeline event handler and a
non-redacted timeline timeline event handler would apply to multiple
events in a sync response, they would individually run for every event
in order. With this change, they will instead both be called
for one event before the next is processed.
2022-09-05 11:55:17 +02:00
Kévin Commaille 6f3813a65f Re-export vodozemac errors in a separate module 2022-09-05 11:44:42 +02:00
Kévin Commaille 433f75ae57 Remove dead error variants 2022-09-05 11:44:42 +02:00
Kévin Commaille 8f0fb08fe7 feat(sdk): Re-export matrix-sdk-crypto errors 2022-09-05 11:44:42 +02:00
Jonas Platte 4f6ff5c0d3 refactor(sdk): Make use of new Default impls from Ruma 2022-09-02 15:03:00 +02:00
Jonas Platte c4d46f233e chore: Upgrade ruma 2022-09-02 15:03:00 +02:00
Damir Jelić faf0ce5007 chore(examples): Remove some empty useless attributes 2022-09-02 14:54:33 +02:00
Damir Jelić c5e6178b70 refactor(examples): Add proxy support to the emoji verification example 2022-09-02 14:54:33 +02:00
Jonas Platte bf9f431e22 refactor(sdk): Use new account_data method internally 2022-09-02 14:09:17 +02:00
Damir Jelić 4b673cfe9c chore: Fix a bunch of clippy warnings 2022-09-02 11:39:06 +02:00
Benjamin Kampmann 0079f1d569 Merge pull request #977 from zecakeh/fix-examples-autojoin
fix(examples): Fix examples that accept invites
2022-09-02 11:14:40 +02:00
Damir Jelić a71292cb16 chore(crypto): Remove a bunch of unnecessary allow deprecated attributes 2022-09-01 17:08:24 +02:00
Damir Jelić cc813b049e fix(crypto): Set the correct algorithm when exporting a room key 2022-09-01 17:08:24 +02:00
Damir Jelić 1b06d8ca51 refactor(crypto): Start using the customized room key request event type 2022-09-01 17:08:24 +02:00
Damir Jelić 4338d5e534 refactor(crypto): Add a customized room key request event type 2022-09-01 17:08:24 +02:00
Jonas Platte 4c98dfb42a feat(bindings): Enable socks proxy support in matrix-sdk-ffi 2022-09-01 15:07:15 +02:00
Jonas Platte dacaef3ddd fix(bindings): Reduce scope of RwLock read lock
Fixes a clippy lint.
2022-09-01 13:40:47 +02:00
Jonas Platte e4267cc4fd refactor(sdk)! Make upload take &[u8] instead of impl Read
The use of `io::Read` wasn't helping since we had to buffer the whole
file in memory anyways, and we are unlikely to get around that in the
near future.
2022-09-01 13:40:47 +02:00
Jonas Platte 16ac69a967 chore: Simplify integration testing macro 2022-09-01 13:11:05 +02:00
Ivan Enderlin 193da88320 feat(crypto): Rename verified and deleted to is_*
feat(crypto): Rename `verified` and `deleted` to `is_*`
2022-09-01 10:50:05 +02:00
Ivan Enderlin 0d6a19e388 chore: verified has been renamed is_verified. 2022-09-01 10:35:51 +02:00
Flix f49e9be905 feat: Expose client of rooms for extensions 2022-09-01 10:01:18 +02:00
Jonas Platte a954518d73 ci: Stop ignoring .lock files in typos config explicitly
Typos now ignores .lock files automatically without any configuration.
2022-09-01 09:33:40 +02:00
Damir Jelić 16d9ed230a chore(examples): Use automatic links for some URLs 2022-08-31 18:43:47 +02:00
Ivan Enderlin 82b647a888 doc(crypto): Fix typos in the documentation
doc(crypto): Fix typos in the documentation
2022-08-31 17:26:56 +02:00
Ivan Enderlin 2e74983c79 chore: Fix other is_verified. 2022-08-31 17:16:05 +02:00
Ivan Enderlin ffebc7c313 doc(crypto): Fix typos in the documentation 2022-08-31 17:09:33 +02:00
Ivan Enderlin 7d1b60a3b1 doc(crypto): Fix a link. 2022-08-31 16:52:00 +02:00
Ivan Enderlin 53c5158eca doc(crypto): Update link to `is_verified. 2022-08-31 16:45:52 +02:00
Ivan Enderlin 3eab9ca8e5 feat(crypto): Rename verified and deleted to is_*. 2022-08-31 16:44:59 +02:00
Doug 36b41ac1c6 chore(bindings): Replace failing test. 2022-08-31 16:22:59 +02:00
Doug 8a8cc5f230 chore(bindings): Use Swift package for tests. 2022-08-31 16:22:59 +02:00
Jonas Platte 96384d9447 feat(bindings): Add account data interaction to sdk-ffi
Co-authored-by: Doug <douglase@element.io>
2022-08-31 14:40:23 +02:00
Stefan Ceriu bb04a1e041 chore(bindings): Fix Xcode project after sdk-ffi namespace change 2022-08-31 10:51:04 +00:00
Jonas Platte d416e64a7e refactor(sdk): Return only content from Account::account_data[_raw]
Since global account data events only consist of the type that is known
to the user anyways, and the content.
2022-08-31 12:19:35 +02:00
Jonas Platte aedf807025 doc(sdk): Add an example for set_account_data 2022-08-31 12:19:35 +02:00
Jonas Platte 77afa26217 feat(sdk): Add account_data[_raw] accessors to Account 2022-08-31 12:19:35 +02:00
Jonas Platte f1a03ececd feat(sdk): Add public set_account_data[_raw] to Account 2022-08-31 12:19:35 +02:00
Jonas Platte f8502720c3 fix(bindings): Pass library file to uniffi-bindgen
… so that functions bridged via #[uniffi::export] are included in the
generated Swift API.
2022-08-31 11:52:37 +02:00
Jonas Platte 84f9414aa4 refactor(bindings): Simplify debug build script 2022-08-31 11:52:37 +02:00
Jonas Platte 9cfddc4c65 refactor(bindings): Update namespace name for matrix-sdk-ffi 2022-08-31 11:52:37 +02:00
Damir Jelić 01f8ed10aa feat(examples): Add an example that lets you create rooms 2022-08-31 11:51:50 +02:00
Damir Jelić 6bb9a7a7d7 docs(crypto): Improve some docs about the forwarded curve chains
Co-authored-by: Denis Kasak <dkasak@termina.org.uk>
2022-08-30 17:14:29 +02:00
Damir Jelić 75fb3b81a7 fix(crypto): Fix the deserialization of exported inbound group sessions 2022-08-30 17:14:29 +02:00
Damir Jelić 504ad39c27 fix(crypto): Fix the deserialization of inbound group group_sessions
Inbound group sessions would fail to be deserialized if there was a
forwarding curve chain, this patch fixes it so we go through base64 when
we deserialize this field.
2022-08-30 17:14:29 +02:00
Benjamin Kampmann d20db7c7c1 Merge pull request #981 from Hywan/fix-crypto-js-npm-publish
chore(crypto-js): Add `npm run pack`
2022-08-30 08:50:39 +02:00
Ivan Enderlin 1bfcc52a1f chore(crypto-js): Add npm run pack.
This patch introduces a new `pack` NPM script, which runs `wasm-pack
pack` behind the scene.

This patch modifies the `publish` NPM script to run the `pack` script
as a pre-script (so… in the `prepublish` script).

Finally, this patch no longer uses `$npm_execpath` as it doesn't work
on Windows. It should be `%npm_execpath%`. It's not obvious to make
scripts interoperable, so we will stick with `npm` for now.
2022-08-29 14:22:39 +02:00
Damir Jelić a8362e389e Document the receive_supported_keys method in the gossiping module 2022-08-29 10:21:04 +02:00
Damir Jelić fe35e7c9fa ci: Test the experimental-algorithms feature of the crypto crate 2022-08-29 10:21:04 +02:00
Damir Jelić 5768188da8 Fix some clippy warnings 2022-08-29 10:21:04 +02:00
Damir Jelić 1e451a92e0 Add some missing docs to the Olm Session 2022-08-29 10:21:04 +02:00
Damir Jelić 12c1b80bc9 Remove a dead code allowed attribute 2022-08-29 10:21:04 +02:00
Damir Jelić 7fda431d5f Remove the usage of the Ruma EventEncryptionAlgorithm 2022-08-29 10:21:04 +02:00
Damir Jelić 337fbb591d Put the new megolm algorithm behind the experimental feature flag 2022-08-29 10:21:04 +02:00
Damir Jelić 8cca01369a Put the new olm algorithm behind a feature flag 2022-08-29 10:21:04 +02:00
Damir Jelić 8cdc609876 Move the EventEncryptionAlgorithm into a more logical place 2022-08-29 10:21:04 +02:00
Damir Jelić 0673ad315f Add support for megolm.v2 forwarded keys 2022-08-29 10:21:04 +02:00
Damir Jelić 3aaf70cb5a Support the new algorithms in the gossiping tests 2022-08-29 10:21:04 +02:00
Damir Jelić b00e963a21 Add support for the new algorithms in the bindings 2022-08-29 10:21:04 +02:00
Damir Jelić 7d98d87c5a Enable the new olm/megolm algorithms 2022-08-29 10:21:04 +02:00
Damir Jelić fb840f73a3 Add support for the m.megolm.v2.aes-sha2 room key content 2022-08-29 10:21:04 +02:00
Damir Jelić e935f59039 Add support for the m.megolm.v2.aes-sha2 algorithm 2022-08-29 10:21:04 +02:00
Damir Jelić 3df6797419 Add support for the m.olm.v1.curve25519-aes-sha2 algorithm 2022-08-29 10:21:04 +02:00
Damir Jelić eaf1f27831 refactor(crypto): Use our own enum for the encryption algorithms 2022-08-29 10:21:04 +02:00
Damir Jelić 748eff40f0 docs(crypto): Improve some docs around event trust states
Co-authored-by: Denis Kasak <dkasak@termina.org.uk>
2022-08-29 09:50:38 +02:00
Damir Jelić 0084117de9 docs(crypto): Fix some spelling and improve a couple of docs
Co-authored-by: Ivan Enderlin <ivan@mnt.io>
2022-08-29 09:50:38 +02:00
Damir Jelić a4af5bf4e1 fix(crypto): Improve the code checking if a decrypted event is trusted
This now takes into account if the room key was imported, i.e. received
as a forward. We also do the check of the Ed25519 key now.
2022-08-29 09:50:38 +02:00
Damir Jelić 27d4228269 fix(crypto): Check the Ed25519 key when we receive an Olm encrypted event 2022-08-29 09:50:38 +02:00
Kévin Commaille dc39c8d96b fix(examples): Fix examples that accept invites
Spawn a task for accepting the invite otherwise the call never returns and sync stops.
2022-08-26 18:15:56 +02:00
Jonas Platte d427632230 chore: Add more backticks in comments 2022-08-25 18:09:13 +02:00
Jonas Platte 6ddc8ba36f refactor!: Rename [Sync]RoomEvent to [Sync]TimelineEvent 2022-08-25 18:09:13 +02:00
Jonas Platte 4be2f3aa04 chore: Upgrade ruma 2022-08-25 18:09:13 +02:00
Jonas Platte f6c404cb32 feat(sdk): Allow event enums to be used as the first event handler argument 2022-08-25 17:19:44 +02:00
Jonas Platte 20a6a16152 refactor(sdk): Split EventHandlerMap into separate maps
One for room-specific event handlers, one for non-room-specific ones.
2022-08-25 17:19:44 +02:00
Jonas Platte 5a1853b0d5 refactor(sdk): Split event_handler module into more files 2022-08-25 17:19:44 +02:00
Jonas Platte 9183f5d4ef refactor(sdk): Move event handler fields from Client into a new struct 2022-08-25 17:19:44 +02:00
Ivan Enderlin 973833c643 feat(crypto-js): Add store configuration to the OlmMachine constructor
feat(crypto-js): Add store configuration to the `OlmMachine` constructor
2022-08-25 11:37:45 +02:00
Ivan Enderlin ce4f7e2254 Merge branch 'main' into feat-crypto-js-store 2022-08-25 11:22:22 +02:00
Jonas Platte 0018749e15 feat(sdk): Allow Raw<_> to be used as the first event handler argument 2022-08-24 18:35:09 +02:00
Ivan Enderlin 9c414bbe9f feat(crypto-js): Implement OlmMachine.sign and .cross_signing_status
feat(crypto-js): Implement `OlmMachine.sign` and `.cross_signing_status`
2022-08-24 09:48:03 +02:00
Jonas Platte 0b8462423a chore: Reduce indirect dependencies of examples 2022-08-23 18:30:44 +02:00
Jonas Platte 2313c099fa chore(bindings): Replace parking_lot RwLock by std RwLock 2022-08-23 18:30:44 +02:00
Ivan Enderlin 85795a92b6 chore(crypto-js): Make Clippy happy. 2022-08-23 17:38:32 +02:00
Ivan Enderlin ef8207fbaa chore(crypto-js): Make Clippy happy. 2022-08-23 17:06:07 +02:00
Jonas Platte f83292fc75 refactor: Start using UniFFI proc-macro frontend 2022-08-23 16:47:08 +02:00
Jonas Platte 5faed2e635 Upgrade UniFFI 2022-08-23 16:47:08 +02:00
Ivan Enderlin 9722a4c415 chore(crypto-js): Use IndexeddbCryptoStore only for wasm32. 2022-08-23 16:46:09 +02:00
Ivan Enderlin 432449b009 chore(crypto-js): Make cargo fmt happy. 2022-08-23 15:08:51 +02:00
Ivan Enderlin 04634d5f39 chore(crypto-js): Fix a typo in an error message. 2022-08-23 15:04:50 +02:00
Ivan Enderlin ef56f76978 doc(crypto-js): Fix a typo. 2022-08-23 15:03:26 +02:00
Ivan Enderlin 527c727e4a test(crypto-js): Improve test cases. 2022-08-23 15:00:39 +02:00
Ivan Enderlin d947448c64 test(crypto-js): Add more test case when store is not configured correctly. 2022-08-23 15:00:39 +02:00
Ivan Enderlin d497883669 doc(crypto-js): Add more docmuentation and more error messages. 2022-08-23 15:00:39 +02:00
Ivan Enderlin 7f07ac52ef feat(crypto-js): Add store configuration to the OlmMachine constructor.
The `OlmMachine` constructor now has 2 more optional arguments:
`store_name` and `store_passphrase`, to use Indexed DB as the backend
to store the Olm machine keys, rather than having an in-memory Olm
machine.

Node.js is used to test our binding. Indexed DB is absent of
Node.js. So, firstly, we are using the `fake-indexeddb` JavaScript
library to mimic the same API inside Node.js. And, secondly, we use
our own fork of the `indexed_db_futures` Rust crate to provide add
support for Node.js too ([PR is
here](https://github.com/Alorel/rust-indexed-db/pull/11)). It
basically looks in the Node.js global environment if the `indexedDB`
getter is present, just like it is already done for `Window` on any
browser, or `WorkerGlobalScope` for workers.
2022-08-23 15:00:33 +02:00
Jonas Platte 9462061a5a chore: Upgrade ruma 2022-08-23 14:28:21 +02:00
Ivan Enderlin d508237078 chore(crypto-js): Add a release workflow for crypto-js
chore(crypto-js): Add a release workflow for `crypto-js`
2022-08-23 10:49:29 +02:00
Ivan Enderlin 331f8b381f doc(crypto-js): Update documentation for the release workflow. 2022-08-22 15:10:01 +02:00
Ivan Enderlin 2481618608 chore(crypto-js): Create the Github release with the NPM package attached.
This patch updates the `publish` NPM script to explicitly run
`wasm-pack pack` to create the NPM package in the `pkg/`
directory. This patch also updates the Github Action workflow for the
`matrix-sdk-crypto-js` release, to create a new Github Release, with
the NPM package attached as an asset file.
2022-08-22 14:37:09 +02:00
Jonas Platte dd78a8cecd refactor(sdk)!: Make room type constructors private
… and avoid unnecessary clones before calling them.
2022-08-22 13:16:05 +02:00
Ivan Enderlin 39077b185b chore(crypto-js): Add a release workflow for crypto-js.
This patch adds a new `npm run publish` script that:

1. Run `npm run prepublish` (which runs the `build` and `test` scripts),
2. Run `wasm-pack publish`.

Note 1: The `prepublish` script is using the `$npm_execpath`
environment variable instead of just “`npm`”, so that if someone is
using `yarn` or another JavaScript package manager, it _should_ work
(not tested yet).

Note 2: `wasm-pack publish` is run without running `wasm-pack login`
before that. _But_ we are updating the registry URL in the NPM
configuration file in the Github Action workflow, see below.

This patch then creates a new Github Action workflow that is triggered
when a new tag of the form `matrix-sdk-crypto-js-v[0_9]+.*` is
pushed. This workflow runs `npm run publish` basically, but before
that, it updates the NPM configuration file by setting a value for
`//registry.npmjs.org/:_authToken`. Thus, running `wasm-pack login` is
not necessary.
2022-08-22 12:14:44 +02:00
Benjamin Kampmann 68107e6285 Merge pull request #963 from gnunicorn/ben-update-ruma
chore: Update ruma
2022-08-18 16:13:15 +02:00
Benjamin Kampmann 549c829000 chore: Update ruma 2022-08-18 15:52:08 +02:00
Jonas Platte 3581d83389 chore: Upgrade Ruma 2022-08-17 10:15:05 +02:00
Jonas Platte 260b604615 refactor(sdk)!: Split strongly-typed state event functions into two
One for empty state keys under the existing name, one for non-empty
state keys with a `_for_key` suffix.
2022-08-17 10:15:05 +02:00
Ivan Enderlin a1dca23c3c Merge pull request #958 from Hywan/feat-crypto-js-attachment 2022-08-17 10:12:04 +02:00
Benjamin Kampmann 9fd5a8b3b1 Merge pull request #960 from matrix-org/poljar/delete-device-log-improvement
Improve the log line when we think our device has been deleted
2022-08-17 09:46:26 +02:00
Damir Jelić 180822dd18 chore(crypto): Improve the message when we think that we have been deleted 2022-08-16 18:32:14 +02:00
Damir Jelić 20477ab7da chore(crypto): Log our identity keys when we think our device has been deleted 2022-08-16 18:31:30 +02:00
Damir Jelić 06f39696d3 chore(crypto): Improve some logs in the Olm message handling code 2022-08-16 16:18:50 +02:00
Damir Jelić 6f5443f8a0 chore(crypto): Log some info when we try to create an Olm session from a pre-key message 2022-08-16 16:18:50 +02:00
Ivan Enderlin 45a66f3321 doc(crypto-nodejs): Fix a typo. 2022-08-16 16:06:04 +02:00
Ivan Enderlin 7f35691236 feat(crypto-js): Implemented the Attachment API.
Implement the `Attachment.encrypt` and `Attachment.decrypt` methods,
along with its `EncryptedAttachment` companion.

The trick is to avoid copies as much as possible. Instead of dealing
with `Uint8Array` as I've initially done, `&[u8]` and `Vec<u8>` is
passed instead. `wasm-bindgen` is smart enough to do as few copies as
possible (from JavaScript to Wasm's memory is required, and we don't
want to do more), while typing everything as `Uint8Array`.

`EncryptedAttachment.encryptedData` returns a copy of the data
everytime it is called, and that's the last copy I'm not happy with.
2022-08-16 15:56:36 +02:00
Benjamin Kampmann e8d51a4cba Merge pull request #956 from gnunicorn/ben-fix-encode-key
fix(sled): Remove unused `from` on EncodeUnchecked
2022-08-16 15:51:36 +02:00
Benjamin Kampmann 7feffec9c0 fix(sled): feature-gate EncodeUnchecked::from 2022-08-16 15:18:46 +02:00
Ivan Enderlin 8e74834342 doc(crypto-js): Add missing module documentation. 2022-08-16 12:31:19 +02:00
Ivan Enderlin 070637b0ef chore(crypto-js): Fix style. 2022-08-16 12:21:02 +02:00
Ivan Enderlin 2dffe03c8d feat(crypto-js): Implement OlmMachine.sign. 2022-08-16 12:16:01 +02:00
Ivan Enderlin 3f0509e7b1 fix(crypto-js): Add missing Debug impl. 2022-08-16 12:16:01 +02:00
Ivan Enderlin 2275643ea0 chore(crypto-js): Move Vodozemac types into their own Rust module. 2022-08-16 12:16:01 +02:00
Ivan Enderlin 0fa6ff6955 feat(crypto-js): Add DeviceKeyId, DeviceKeyAlgorith and DeviceKeyAlgorithmName. 2022-08-16 12:16:01 +02:00
Ivan Enderlin 997a6ed0ad feat(crypto-js): Implement OlmMachine.cross_signing_status. 2022-08-16 12:16:01 +02:00
Ivan Enderlin fd220f197b doc: Add link to online documentation for crypto-js and crypto-nodejs
doc: Add link to online documentation for crypto-js and crypto-nodejs
2022-08-16 10:21:39 +02:00
Ivan Enderlin 655e62814b doc(crypto-nodejs) Add link to online documentation. 2022-08-16 10:06:22 +02:00
Ivan Enderlin c2468b2f2e doc(crypto-js) Add link to online documentation. 2022-08-16 10:04:54 +02:00
Benjamin Kampmann e0ae4f60e3 docs(examples): update instructions for wasm_command_bot example
Merge pull request #952 from chrisguida/chrisguida/wasm-bot-readme -
2022-08-16 09:48:33 +02:00
Chris Guida 2beb13cc3e update instructions for wasm_command_bot example 2022-08-15 17:56:54 -05:00
Damir Jelić 78dcff9259 chore(crypto): Fix an indentation issue
Co-authored-by: Jonas Platte <jplatte@matrix.org>
2022-08-15 11:39:43 +02:00
Damir Jelić 0bd58a7741 refactor(crypto): Simplify the Curve25519 check when fetching a device
Co-authored-by: Jonas Platte <jplatte@matrix.org>
2022-08-15 11:39:43 +02:00
Damir Jelić 405c3938b7 refactor(crypto): Use the Curve25519 key type in more places 2022-08-15 11:39:43 +02:00
Damir Jelić bd5ea8b0f7 fix(crypto): Fix some error messages 2022-08-15 11:39:43 +02:00
Jonas Platte 24c042e974 refactor(base): Deserialize events at the expected type
… rather than deserializing at an enum type and taking the same branch
for getting a different enum variant¹ as failed deserialization.

¹ which should be impossible anyways
2022-08-15 11:05:22 +02:00
Jonas Platte d236cde0c7 refactor(base): Use StateStoreExt in a few places 2022-08-15 11:05:22 +02:00
Jonas Platte d2f39bc18f feat(base): Add StateStoreExt for statically-typed event retrieval 2022-08-15 11:05:22 +02:00
Jonas Platte 96165f5602 chore(bindings): Use ? operator instead of and_then chaining 2022-08-15 11:05:22 +02:00
Damir Jelić 4a13b8d207 ci: Ignore thead when checking for spelling 2022-08-14 10:20:28 +02:00
Damir Jelić c9c09adb38 chore: Fix some newly detected typos 2022-08-14 10:20:28 +02:00
Jonas Platte aedbbcdde7 fix(sdk)!: Remove SyncEvent implementation for InitialStateEvent
Initial state events aren't actually received through sync, they're sent from
the client to the server when creating a room.

This change makes it impossible to register event handlers for initial state
events. Previously, this was allowed, but the event handler was never called.
2022-08-13 20:21:28 +02:00
Jonas Platte 97f37acb4a chore: Reduce indirect dependencies of sled-state-inspector 2022-08-13 13:08:11 +02:00
Damir Jelić 0b5bfeadea chore(crypto): Add a missing semicolon
Co-authored-by: Jonas Platte <jplatte@matrix.org>
2022-08-13 09:58:57 +02:00
Damir Jelić 6d60acfff4 chore(common): Fix a clippy warning 2022-08-13 09:58:57 +02:00
Damir Jelić 3d56af442d refactor(crypto): Utilize the decrypted Olm event type more
This patch adds some more stronger guarantees that received room key
events and other similarly security critical event types are only
handled if they have been received over a secure Olm channel.
2022-08-13 09:58:57 +02:00
Damir Jelić ae18b01c25 refactor(crypto): Use the SigningKeys collection for inbound group sessions 2022-08-11 16:43:42 +02:00
Damir Jelić 4692a12cd7 refactor(crypto): Create a custom collection type for signed keys 2022-08-11 16:43:42 +02:00
Jonas Platte 344309c1bf chore: Track Cargo.lock to make binding staticlibs reproducible 2022-08-11 13:32:32 +02:00
Jonas Platte 87094a9111 chore: Document dependency upgrade issues 2022-08-11 13:16:10 +02:00
Jonas Platte adf3f9d434 chore(appservice): Upgrade serde_yaml 2022-08-11 13:15:57 +02:00
Jonas Platte 158bd24b40 chore: Bump pprof dependency 2022-08-11 13:09:09 +02:00
Jonas Platte 8e368d86b7 chore: Use the latest git version of UniFFI 2022-08-11 12:56:17 +02:00
Jonas Platte 0fe714df86 chore: Upgrade sled-state-inspector dependencies 2022-08-11 11:59:50 +02:00
Jonas Platte 936f0371de chore: Use once_cell instead of lazy_static in integration test crate 2022-08-11 10:45:04 +02:00
Jonas Platte ecc800a319 chore: Sort dependencies of integration test crate 2022-08-11 10:32:12 +02:00
docweirdo febfcf9796 feat(sdk): Make room actions return typed room objects
… by waiting for the corresponding event confirming the action. Affects:

* Creating a room
* (Re-)Joining a room
* Leaving a room
* Accepting an invitation
* Rejecting an invitation
2022-08-10 17:32:38 +02:00
Damir Jelić 3f0a68082a feat(crypto): Add a setting to only send room keys to trusted devices 2022-08-10 13:31:15 +02:00
Damir Jelić 18861bb595 refactor(crypto): Add a dedicated error for inbound group session exporting 2022-08-10 13:28:54 +02:00
Damir Jelić 329d461a2f feat(crypto): Add customized event type for the forwarded room key 2022-08-10 13:28:54 +02:00
Jonas Platte 4914c595e9 fix(sdk): Further relax event / notification handler bounds on WASM
This allows capturing non-`Send` / -`Sync` values in handler closures.
2022-08-10 12:54:36 +02:00
Jonas Platte ad80839ffd fix(sdk): Make event handler futures non-Send on wasm 2022-08-09 14:25:57 +02:00
Jonas Platte 0701561e45 feat(common): Add SendOutsideWasm, SyncOutsideWasm 2022-08-09 14:25:57 +02:00
Jonas Platte 25030780b0 test(sdk): Run event handler tests on wasm 2022-08-09 14:25:57 +02:00
Jonas Platte 327a404d60 test(sdk): Move test client creation into separate module 2022-08-09 14:25:57 +02:00
Damir Jelić 06e096f6cc fix(examples): Fix the in-room emoji verification example 2022-08-09 14:04:11 +02:00
Damir Jelić a025163dae test(crypto): Test that we correctly preserve relations in an encryption cycle 2022-08-09 14:04:11 +02:00
Damir Jelić 19fcff56de chore(crypto): Make the relation copying code when decrypting a bit simpler 2022-08-09 14:04:11 +02:00
Damir Jelić edf81fb325 fix(crypto): Correctly copy over the relation when encrypting 2022-08-09 14:04:11 +02:00
Damir Jelić 08338acac2 fix(crypto): Fix the deserialization of relations 2022-08-09 14:04:11 +02:00
Kévin Commaille 52e70f1955 refactor(sdk): Don't require the whole session for sending
Allow to send requests when only the access token is available.

Remove the unreachable UserIdRequired error.
2022-08-09 12:26:33 +02:00
Jonas Platte e788ec6b07 ci: Only test one node.js version on macOS 2022-08-08 18:06:54 +02:00
Jonas Platte d3d108deb8 chore: Add missing copyright headers 2022-08-08 16:28:48 +02:00
Jonas Platte bd65d9b7a6 doc(sdk): Remove usage of deprecated function in doctest 2022-08-05 16:16:41 +02:00
Jonas Platte 230bb67763 refactor(sdk): Remove Clone requirement on event handlers 2022-08-05 16:16:41 +02:00
Jonas Platte 10a37f6d51 chore(sdk): Add EventHandlerDropGuard
It isn't used for now, but will be soon.
2022-08-05 16:16:41 +02:00
Jonas Platte 5156fb7dd4 refactor(sdk): Move add_event_handler_impl to event_handler module 2022-08-05 16:16:41 +02:00
Jonas Platte 3b03ad804f refactor(sdk)!: Swap the async lock around event handlers for a sync one 2022-08-05 16:16:41 +02:00
Damir Jelić 603176f521 chore(crypto): Bump vodozemac
Vodozemac got some new knobs to twiddle with. This patch updates
vodozemac and sets the knobs to use the olm/megolm v1 supported
encryption schemes.
2022-08-05 14:06:42 +02:00
Jonas Platte dfec17e6af chore: Disable testing of crates without tests
This reduces the amount of "running 0 tests" spam when testing the whole
workspace and makes testing a little faster overall.
2022-08-05 11:10:31 +02:00
Kévin Commaille 7623f93bb3 fix(sdk)!: Make set_homeserver private
A user shouldn't need to change the homeserver after creating the client.
2022-08-05 09:55:55 +02:00
Jonas Platte a60620306c ci: Update tarpaulin.toml 2022-08-04 23:43:49 +02:00
Jonas Platte 1fea48359d ci: Checkout head ref instead of merge commit for coverage
… this *should* fix bogus coverage change reporting.
2022-08-04 23:43:49 +02:00
Jonas Platte 054dfa98a0 ci: Upgrade checkout action 2022-08-04 23:43:49 +02:00
Damir Jelić 593d4e6062 perf(crypto): Use an RwLock for the OutboundGroupSession 2022-08-04 17:36:03 +02:00
Jonas Platte 5a94ba7b80 refactor(sled)!: Align open_with_database with its documentation
It now takes a passphrase instead of a store cipher as the second argument.
2022-08-04 17:04:31 +02:00
Jonas Platte e1b7f3be05 refactor(sled): Simplify test code 2022-08-04 17:04:31 +02:00
Jonas Platte 6bed51f016 refactor(indexeddb)!: Use &str for name in public API 2022-08-04 17:04:31 +02:00
Jonas Platte 4db162b8a2 chore(indexeddb): Clean up Result usage 2022-08-04 17:04:31 +02:00
Jonas Platte 0b1bdd66f9 refactor(indexeddb): Export error types 2022-08-04 17:04:31 +02:00
Jonas Platte a4f3c3a070 refactor!: Give sled / indexeddb types unique names 2022-08-04 17:04:31 +02:00
Jonas Platte df7895d2c6 chore(indexeddb): Rename cryptostore => crypto_store
… for consistency with state_store.
2022-08-04 17:04:31 +02:00
Jonas Platte 694c36d741 chore(sled): Rename cryptostore => crypto_store
… for consistency with state_store.
2022-08-04 17:04:31 +02:00
Benjamin Kampmann b5329f99f1 Merge pull request #903 from gnunicorn/ben-getting-started-example
Improving examples
2022-08-04 15:41:26 +02:00
Damir Jelić f055e939e7 refactor(crypto): Use the vodozemac method to decide if a session is better
This patch delegates the decision making if a session is better to
vodozemac. Vodozemac has better insights if a group session can be
considered to be better.
2022-08-04 15:09:09 +02:00
Benjamin Kampmann c4c7c2bb23 docs: remove unused import and fix style of custom events example 2022-08-04 15:02:39 +02:00
Benjamin Kampmann efc0556124 doc: follow naming convention and use generated types from ruma 2022-08-04 13:31:16 +02:00
Benjamin Kampmann 9d588f7e00 doc: add example for sending and reacting on custom events 2022-08-04 13:13:48 +02:00
Benjamin Kampmann 323974fe4c Merge remote-tracking branch 'origin/main' into ben-getting-started-example 2022-08-04 12:22:42 +02:00
Benjamin Kampmann 3bdb2f22ea build(crypto-js): Pin yarg-parser to 21.0.1 to prevent upgrade bug
We are effected by https://github.com/yargs/yargs-parser/issues/452
through the transient dependency of jest on yargs
2022-08-04 12:21:18 +02:00
Damir Jelić ddf8577c84 refactor(crypto): Start using our own event types when we encrypt 2022-08-04 11:16:02 +02:00
Benjamin Kampmann 90c2dcdbc0 style: fix clippy lints 2022-08-04 11:02:28 +02:00
Benjamin Kampmann fe4bc0dc75 doc: fix docs of getting started bot 2022-08-03 17:07:59 +02:00
Benjamin Kampmann 69c8cdf304 Revert "fix: limit indexeddb features to target arch to stop clippy from complaining"
This reverts commit d54612b6e2.
2022-08-03 16:40:17 +02:00
Benjamin Kampmann daf92d7745 Merge remote-tracking branch 'origin/main' into ben-getting-started-example 2022-08-03 16:39:50 +02:00
Benjamin Kampmann ccbd9e5712 chore: rename Readme.md to README.md 2022-08-03 16:39:14 +02:00
Jonas Platte 2430d7f267 chore: Remove unneeded docsrs Cargo features 2022-08-03 15:33:53 +02:00
Damir Jelić 3ca3016539 refactor(crypto): Use the curve 25519 key type for inbound group sessions 2022-08-03 15:28:24 +02:00
Jonas Platte bbbd7942b0 fix(indexeddb): Export MigrationConflictStrategy 2022-08-03 15:17:05 +02:00
Jonas Platte 1a5953e01e chore(indexeddb): Appease clippy 2022-08-03 15:17:05 +02:00
Jonas Platte 3a19d8e5bf chore(indexeddb): Reduce target_arch feature gates
This allows smoother development as a regular 'cargo check' will
validate most of the code. It also makes rust-analyzer work for the
crate without any configuration.
2022-08-03 15:17:05 +02:00
Jonas Platte 0b7d0aa780 chore(common): Make timeout tests deterministic
… as well as simpler, and faster.
2022-08-03 14:54:43 +02:00
Jonas Platte 82f4e57a2c feat(sled): Print a clear error message when attempting to build on wasm 2022-08-03 14:48:45 +02:00
Jonas Platte 9714ce9edf refactor(sdk): Check permissible feature configuration in build script
… instead of through `compile_error!` invocations. This helps avoid
unhelpful errors from the unsupported feature configuration by aborting
compilation earlier.
2022-08-03 14:48:45 +02:00
Benjamin Kampmann 9538596fbb doc: Add getting-started example autojoin & command bot with plenty of source docs 2022-08-03 13:05:25 +02:00
Benjamin Kampmann 35be128139 docs: add Readme to examples root 2022-08-03 12:06:50 +02:00
Benjamin Kampmann d54612b6e2 fix: limit indexeddb features to target arch to stop clippy from complaining 2022-08-03 12:00:54 +02:00
Benjamin Kampmann a1bf53a331 Merge remote-tracking branch 'origin/main' into ben-getting-started-example 2022-08-03 11:39:50 +02:00
Kévin Commaille 9064e7b02d feat(sdk): Add support for refresh tokens 2022-08-03 10:42:28 +02:00
Damir Jelić ae261c2091 refactor(crypto): Refactor the key sharing tests a bit 2022-08-02 16:48:05 +02:00
Damir Jelić 968792ea00 refactor(crypto): Split out the forwarded room key accepting method 2022-08-02 16:48:05 +02:00
Benjamin Kampmann 42c88e840f Merge pull request #905 from gnunicorn/ben-fix-integration-test-coverage
ci: add backend server for integration test with tarpaulin
2022-08-02 16:14:26 +02:00
Benjamin Kampmann 38a71972e5 ci: add backend server for integration test with tarpaulin 2022-08-02 15:42:45 +02:00
Benjamin Kampmann d8caaed1ce docs: only document default workspace members, not all 2022-08-02 15:24:48 +02:00
Benjamin Kampmann 67e63c0d35 ci: update xtask, add ci to build examples 2022-08-02 15:13:27 +02:00
Benjamin Kampmann 4c7ddd7512 refactor: move examples from crates/matrix-sdk into separate crates in examples/ 2022-08-02 15:06:04 +02:00
Jonas Platte 9fca639f9b feat(sdk): Add room::Common::add_event_handler 2022-08-02 13:38:30 +02:00
Benjamin Kampmann 6cb87c64b5 Merge pull request #855 from gnunicorn/gnunicorn/issue833
Integration tests against an actual synapse server
2022-08-02 12:22:48 +02:00
Benjamin Kampmann a5875ff75d ci: update codecov config to exclude all testing crates 2022-08-02 10:59:18 +02:00
Benjamin Kampmann 9bb02f2419 fix: fix path to testing crate 2022-08-02 10:58:53 +02:00
Benjamin Kampmann 65be06ebad Merge remote-tracking branch 'origin/main' into gnunicorn/issue833 2022-08-02 10:32:09 +02:00
Damir Jelić 154538c4c9 fix(crypto): Make the secret receiving logic more obvious.
This patch ensures that the received secret has been sent by one of our
verified devices. We already ensure so for the secrets we import, since
we check that the cross signing keys match the public keys of our own
user idenity.

No other secrets get imported by this method but it could quite easily
become an issue if we start accepting more secret types.
2022-08-02 09:35:38 +02:00
Damir Jelić f23c16cf88 refactor(crypto): Split out the methods to receive a secret 2022-08-02 09:35:38 +02:00
Jonas Platte 165973121c fix(sdk): Make remove_event_handler work with room-specific handlers
As part of that, store only the ID, not the whole key in
EventHandlerWrapper, because the key is getting bigger with room_id.
2022-08-01 23:57:00 +02:00
Jonas Platte 31903d3cbc chore(sdk): Simplify remove_event_handler test 2022-08-01 23:55:44 +02:00
Jonas Platte 108f299e92 refactor(sdk): Inline handle_sync_events_wrapped_with into all callers
It was too generic to be readable.
2022-08-01 23:55:44 +02:00
Jonas Platte eb78815be5 refactor(sdk): Create non-generic fn call_event_handlers
Extracted out of handle_sync_events_wrapped_with.
2022-08-01 23:55:44 +02:00
Jonas Platte 0716f6afaa feat(sdk): Add Client::add_room_event_handler 2022-08-01 23:55:44 +02:00
Jonas Platte 78169d516e refactor(sdk): Avoid unnecessary double map lookup 2022-08-01 23:55:44 +02:00
Jonas Platte 061fe104a9 chore(sdk): Move EventHandler{Fut,Fn} into event_handler module 2022-08-01 23:55:43 +02:00
Benjamin Kampmann f91bdb28ba Merge pull request #897 from gnunicorn/ben-fix-documentation-generation
Fix documentation generation
2022-08-01 22:37:21 +02:00
Benjamin Kampmann 14429af511 Update .github/workflows/documentation.yml
Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
2022-08-01 22:19:46 +02:00
Benjamin Kampmann 1e6e00b0c0 ci(integration-testing): split integration test off from regular tests 2022-08-01 18:54:33 +02:00
docweirdo 744bd8d0d2 feat(common): Add a generically usable timeout function 2022-08-01 18:23:30 +02:00
Benjamin Kampmann 06ad079099 Merge pull request #895 from matrix-org/ben-add-editoconfig
build: Adding .editorconfig
2022-08-01 15:23:58 +02:00
Benjamin Kampmann 7dfadd1848 ci(integration-testing): split integration test off from regular tests 2022-08-01 15:20:13 +02:00
Benjamin Kampmann 5089c1a7e9 ci(docs): force npm generated bindings if existing 2022-08-01 14:56:26 +02:00
Benjamin Kampmann c15a4bcdd4 build: Adding .editorconfig 2022-08-01 14:33:05 +02:00
Benjamin Kampmann 729836cf70 Merge pull request #894 from gnunicorn/ben-add-js-docs
ci(js) add npm docs of bindings to pages
2022-08-01 13:35:17 +02:00
Benjamin Kampmann 2d21c30639 Merge remote-tracking branch 'origin/main' into gnunicorn/issue833 2022-08-01 13:28:28 +02:00
Benjamin Kampmann 3842426788 ci: Remove unneeded github action params 2022-08-01 13:27:00 +02:00
Benjamin Kampmann c27016b2e7 testing: fix review grumbles 2022-08-01 13:01:50 +02:00
Benjamin Kampmann d0f58d0879 ci(js) add npm docs of bindings to pages 2022-08-01 12:17:36 +02:00
Kévin Commaille 4cdc91844e chore(ci): Fix new clippy warnings 2022-07-30 12:58:18 +02:00
Jonas Platte fe5d8fb40e refactor: Deprecate ClientBuilder::{crypto_store, state_store} 2022-07-29 17:22:12 +02:00
Jonas Platte ffb4c6d6ef docs: Use new ClientBuilder methods in examples 2022-07-29 17:22:12 +02:00
Jonas Platte 93c4c5d128 feat(sdk): Add ClientBuilder::indexeddb_store 2022-07-29 17:22:12 +02:00
Jonas Platte ec3a6e4b15 feat(sdk): Add ClientBuilder::sled_store 2022-07-29 17:22:12 +02:00
Jonas Platte ecbcf734b9 docs(sled): Clean up make_store_config description 2022-07-29 17:22:12 +02:00
Jonas Platte 75f08aed69 docs(sdk): Fix outdated description of ClientBuilder::store_config 2022-07-29 17:22:12 +02:00
Jonas Platte 255955555d refactor(sdk): Add back register_event_handler[_context] as deprecated methods
… using their original signatures so upgrading matrix-sdk is easier.
2022-07-29 14:39:28 +02:00
Jonas Platte 27b858308c refactor(sdk)!: Rename {register => add}_event_handler[_context]
It's shorter and better fits with the new remove_event_handler method.
2022-07-29 14:39:28 +02:00
Jonas Platte a21ac5d6e4 Disable debug-info for the dev profile 2022-07-29 11:28:47 +02:00
Damir Jelić 4db041ce9a docs(crypto): Improve the wording on the recipient collection method
Co-authored-by: Jonas Platte <jplatte@matrix.org>
2022-07-29 10:20:36 +02:00
Damir Jelić c194e08942 fix(crypto): Rotate the outbound group session if the algorithm changes 2022-07-29 10:20:36 +02:00
Damir Jelić 713e96d3a8 fix(crypto): Store intermediate changes to the outbound group session
This fixes a bug where we would lose already generated to-device
requests carrying an m.room_key when the client gets restarted.

This only happens if the request was generated after the initial
share of the room key. Such requests get generated if a new device
or member join the group.
2022-07-29 10:01:58 +02:00
Jonas Platte b36f79a1bb doc: Make rustfmt format code blocks in documentation 2022-07-28 20:06:12 +02:00
Jonas Platte 504464c1e8 chore: Remove edition from .rustfmt.toml
It will be picked up from Cargo.toml.
2022-07-28 20:06:12 +02:00
Doug b884c5baae chore(bindings/ffi): Print each step when building XCFramework. 2022-07-28 13:37:02 +02:00
Doug c15fb5e5b7 fix(sdk): Reduce retry length on homeserver discovery 2022-07-28 13:37:02 +02:00
Damir Jelić 0555216f37 chore(crypto): Introduce a helper function to convert events in tests 2022-07-28 12:48:12 +02:00
Damir Jelić 03a4814a1a refactor(crypto): Use our own type for megolm 2022-07-28 12:48:12 +02:00
Damir Jelić 80c7f057cc refactor(crypto): Use our own struct for encrypted to-device events 2022-07-28 12:48:12 +02:00
Damir Jelić 7e70997e1c feat(crypto): Add customized m.room.encrypted events 2022-07-28 12:48:12 +02:00
Damir Jelić 2bb7914611 refactor(crypto): Make the event type an associated constant 2022-07-28 12:48:12 +02:00
Benjamin Kampmann c8c793da98 Merge pull request #768 from gnunicorn/gnunicorn/issue756
Bump db version, "upgrade" path to new db in sled and indexeddb
2022-07-28 09:51:27 +02:00
Damir Jelić e501979d92 feat(bindings/ffi): Allow setting the timeline limit for the sync setup 2022-07-27 19:23:10 +02:00
Doug 57c1e68893 Rename limit to timeline_limit.
Use a u16 instead.
2022-07-27 18:03:04 +01:00
Doug a875c4b373 Expose room membership in the FFI. 2022-07-27 17:23:09 +01:00
Doug f6e215dac3 Add limit parameter to start_sync. 2022-07-27 17:22:17 +01:00
Jonas Platte 4415ed9b58 refactor: Improve tracing events
* Use fields more
* Adjust some wording
2022-07-27 17:47:01 +02:00
Benjamin Kampmann 59fc81b957 ci(xtask): bump wasm timeout to make the ci pass 2022-07-27 16:58:20 +02:00
Benjamin Kampmann 770ac193a7 fix(indexeddb): import errors 2022-07-27 15:08:51 +02:00
Benjamin Kampmann fe40b3753a Merge pull request #870 from Hywan/feat-crypto-js-npm-publish
chore: Update or add `git-cliff` config' & prepare `crypto-js` for publishing
2022-07-27 14:28:40 +02:00
Benjamin Kampmann e871114436 docs(crypto-ffi): fixing path 2022-07-27 13:43:39 +02:00
Benjamin Kampmann fb4dd4d875 test(crypto-js): fixing path 2022-07-27 13:32:26 +02:00
Benjamin Kampmann 5806b3fbe9 ci(crypto-js): use a specific node version to run tests 2022-07-27 13:23:44 +02:00
Benjamin Kampmann e1be222558 style: fixing fmt 2022-07-27 13:09:08 +02:00
Benjamin Kampmann 37f0926832 chore: prefer to user Store::builder 2022-07-27 12:59:53 +02:00
Benjamin Kampmann 936731065b fix(indexeddb): specify futures import 2022-07-27 12:53:54 +02:00
Benjamin Kampmann 088699b6a4 docs(xtask): remove comment 2022-07-27 12:20:46 +02:00
Benjamin Kampmann b2da8b7dd7 fix(examples): update to renaming 2022-07-27 12:12:17 +02:00
Benjamin Kampmann b80d3c2f2d Merge remote-tracking branch 'origin/main' into gnunicorn/issue756 2022-07-27 12:04:56 +02:00
Benjamin Kampmann eb1dfd9690 docs(indexeddb): document builder functions 2022-07-27 11:52:13 +02:00
Benjamin Kampmann 54c181a9ad chore: cleaning up builder usage in sled and indexeddb 2022-07-27 11:51:56 +02:00
Benjamin Kampmann 003c946581 chore(sled): ascending order for dependencies 2022-07-27 10:59:02 +02:00
docweirdo 82731a5e89 feat(sdk): Add support for removing event handlers 2022-07-27 05:09:22 +00:00
Damir Jelić 4175e6badf feat(bindings/ffi): Allow clients to be restored using only an access token
This functionality is important to allow clients to log in using an OIDC server. The OIDC server returns only an access token, the client needs to fetch the user ID and device ID from the Matrix server separately.

This lives in the bindings for now since OIDC support in Matrix is being actively developed.
2022-07-26 17:10:50 +02:00
Benjamin Kampmann 008c0f4659 Merge pull request #860 from matrix-org/doug/client-path
Use a consistent store path when logging in through the FFI.
2022-07-26 16:33:32 +02:00
Doug a951a273e7 Rebase and rename method.
Add a device ID parameter to restore_with_access_token
2022-07-26 15:00:02 +01:00
Doug f13f590b7f Add login_access_token to the FFI auth service. 2022-07-26 15:00:02 +01:00
Doug 1eadd0ba2d Revert changes to store path. Use whoami for path. 2022-07-26 14:50:51 +01:00
Doug 3b8a2ca2d7 Add missing path method to IndexeddbStore. 2022-07-26 14:50:51 +01:00
Doug b6b1f904e0 Fix clippy warning. 2022-07-26 14:50:51 +01:00
Doug f31528c926 Allow a client to be built without a store path.
Throw an error on login if it is missing.
2022-07-26 14:50:51 +01:00
Doug 05fab8c394 Add a store_path method on the FFI client. 2022-07-26 14:48:37 +01:00
Jonas Platte e37e62c92c chore(sdk): Fix event handler test
It wasn't actually testing typing and power-levels event handlers before.
2022-07-26 11:11:10 +02:00
Jonas Platte d162dd07d5 refactor(sdk): Split SyncEvent::ID into KIND and TYPE
This should make things slightly easier to read.
2022-07-25 20:33:43 +02:00
Jonas Platte 42d3ebbe87 chore: Remove ugly commas right before closing parentheses 2022-07-25 20:30:13 +02:00
Jonas Platte 4e7bd6760a chore: Replace qualified uses of tracing macros with imports 2022-07-25 20:30:13 +02:00
Jonas Platte ab9476960b chore(sled): Fix line length overflow 2022-07-25 20:30:13 +02:00
Jonas Platte b3092bd1d9 chore(indexeddb): Remove unnecessary .to_string() call in test code 2022-07-25 20:30:13 +02:00
Jonas Platte c2ad4b7d82 fix(appservice): Respond with a non-stringified empty object
warp::reply::json() serializes its argument to JSON, passing it an
already-serialized JSON string doesn't do the right thing.
2022-07-25 20:30:13 +02:00
Jonas Platte f8e729f7f3 chore: Use implicit named arguments for formatting macros more 2022-07-25 20:30:12 +02:00
Jonas Platte 5c88bd1595 refactor(sdk): Remove ID from EventHandler
Turns out it wasn't actually needed.
2022-07-25 20:30:12 +02:00
Damir Jelić 204441f2b3 Fix a formatting issue in a doc example
Co-authored-by: Jonas Platte <jplatte@matrix.org>
2022-07-25 19:06:15 +02:00
Damir Jelić 79d13148fb chore: Remove TryFrom/TryInto imports 2022-07-25 19:06:15 +02:00
Julian Sparber c247de95b6 client: Remove redudant delay after sync error
If the last sync was less then a 1s ago we wait for a 1s, it doesn't
make sense to wait an additional second on an error. Also the stream
sync api returns the error after a delay of 1s, which doesn't make
sense.
2022-07-25 12:01:28 +02:00
Johannes Becker 6d87dd8011 refactor(appservice)!: Make USER_MEMBER const private" 2022-07-22 09:33:42 +02:00
Jonas Platte 4b6a28da0d chore(sdk): Fix line length overflow in common.rs 2022-07-21 19:24:42 +02:00
Benjamin Kampmann bf6e1b594d fix(integration-tests): requires multi-threading feature from tokio 2022-07-21 18:06:48 +02:00
Benjamin Kampmann 59332e46b5 switch to multithreaded tokio test runner 2022-07-21 17:58:50 +02:00
Benjamin Kampmann c070b96a68 Merge remote-tracking branch 'origin/main' into gnunicorn/issue833 2022-07-21 17:37:49 +02:00
Benjamin Kampmann d68d6ead69 chore: let's check the logs 2022-07-21 17:31:58 +02:00
Benjamin Kampmann f34c2f0574 ci: fix typos 2022-07-21 17:28:38 +02:00
Benjamin Kampmann aad167b792 style(indexeddb): fixing rust fmt 2022-07-21 17:25:43 +02:00
Benjamin Kampmann 814a30064f fix(sled-inspector): new builder fn 2022-07-21 17:18:43 +02:00
Ivan Enderlin 6ce5d0b507 chore(crypto-js): Add cliff.toml for git-cliff. 2022-07-21 15:50:11 +02:00
Ivan Enderlin db7824efbd chore(crypto-nodejs): Update Conventional Commits types. 2022-07-21 15:49:26 +02:00
Ivan Enderlin ee4702d04a feat(bindings/crypto-js) Update package name, and use package scope. 2022-07-21 15:47:55 +02:00
Ivan Enderlin d68b6ea64d doc: Fix formatting. 2022-07-21 15:47:00 +02:00
Ivan Enderlin 49bc950fdd doc: Add missing scope for matrix-sdk-crypto. 2022-07-21 15:46:21 +02:00
Ivan Enderlin 7001113877 doc: Propose conventional commits scopes & types
doc: Propose conventional commits scopes & types
2022-07-21 15:44:43 +02:00
Ivan Enderlin c0d3099e2e doc: Propose conventional commits types. 2022-07-21 15:43:31 +02:00
Ivan Enderlin 49e5d73d83 doc: Propose conventional commits scopes. 2022-07-21 13:59:31 +02:00
Benjamin Kampmann 2ffaaeeae2 docs(sled): fixing examples and utils 2022-07-21 13:18:15 +02:00
Benjamin Kampmann 60eef8967f fix(sled-store): apply review requests 2022-07-21 11:52:04 +02:00
Benjamin Kampmann ed893ed5b0 Merge remote-tracking branch 'origin/main' into gnunicorn/issue756 2022-07-21 11:38:10 +02:00
Jonas Platte 4e2bd14a27 chore: Silence buggy clippy lint 2022-07-21 11:30:13 +02:00
Jonas Platte 0b3b757120 refactor: Make Store type internal to base crate 2022-07-21 11:30:13 +02:00
Jonas Platte 63d01dd20e refactor(base): Stop using Store type in store integration tests 2022-07-21 11:30:13 +02:00
Jonas Platte a43005dec2 refactor(base): Add RoomInfo::new constructor 2022-07-21 11:30:13 +02:00
Jonas Platte 4187aa400f refactor: Remove Store type usage from sled-state-inspector
Requires using more explicit syntax for some calls because SledStore has
methods of the same names with different (harder to use) signatures.
2022-07-21 11:30:13 +02:00
Jonas Platte cf8f3bf7cc refactor(sdk)!: Update MessageOptions API once again
… to match the latest changes in Ruma.
2022-07-21 11:18:09 +02:00
Jonas Platte 5b66bed1f0 chore: Remove unused imports from example 2022-07-21 11:18:09 +02:00
Benjamin Kampmann 1668c173e6 Merge pull request #836 from matrix-org/ben-release-crypto-nodes-beta0
Release crypto-nodejs beta1
2022-07-21 10:59:46 +02:00
Jonas Platte 76fd9bd963 fix(sdk): Call to-device handlers 2022-07-21 10:30:13 +02:00
Benjamin Kampmann 6f18e35b72 Merge remote-tracking branch 'origin/main' into ben-release-crypto-nodes-beta0 2022-07-21 10:25:26 +02:00
Johannes Becker 5f7e91c2e7 refactor(appservice)!: Cleanup 2022-07-21 09:01:53 +02:00
Jonas Platte 45829efa7e feat(bindings): Tracing configuration through FFI 2022-07-20 16:38:51 +02:00
Kévin Commaille a6bd7fc82f chore: Update Ruma 2022-07-20 12:18:06 +00:00
Stefan Ceriu 5c53a5f699 chore(bindings/apple): Remove unnecessary +nightly flag from debug builds 2022-07-20 14:53:00 +03:00
Stefan Ceriu 021bf55074 feat(bindings/sdk-ffi): Expose full tracing configuration string through ffi. 2022-07-20 13:39:15 +03:00
Stefan Ceriu 0043de4028 Update bindings/matrix-sdk-ffi/Cargo.toml
Co-authored-by: Jonas Platte <jplatte@matrix.org>
2022-07-20 13:28:58 +03:00
Stefan Ceriu f9bb86c52f feat(bindings/sdk-ffi): Allow ffi users to configure tracing and log levels 2022-07-20 12:56:42 +03:00
Stefan Ceriu 1cd18f49aa chore(bindings/apple): Remove now unnecessary debug script module import following module map rename 2022-07-20 12:29:36 +03:00
Benjamin Kampmann 8b160dfd38 Merge pull request #857 from matrix-org/doug/homeserver-details
Add a `HomeserverLoginDetails` to the FFI's auth service.
2022-07-20 10:27:09 +02:00
Doug 77f7dbbbc8 Support server URLs. Join homeserver details futures. 2022-07-19 16:16:03 +01:00
Ivan Enderlin fe590735c1 fix(bindings/crypto-nodejs): Fix CI typo
fix(bindings/crypto-nodejs): Rrrrr
2022-07-19 16:43:40 +02:00
Ivan Enderlin 0360b13cdb fix(bindings/crypto-nodejs): Rrrrr 2022-07-19 16:12:43 +02:00
Jonas Platte f30419446f refactor(sdk)!: Make from in MessageOptions optional 2022-07-19 15:25:16 +02:00
Doug 93d879f356 Add homeserver_details property. 2022-07-19 12:48:00 +01:00
Benjamin Kampmann c20c23bc19 Merge pull request #856 from matrix-org/fixing-clippy-lint
style(crypto): use matches for legibility
2022-07-19 12:54:44 +02:00
Johannes Becker a174d0f669 sdk: Make from in MessageOptions optional 2022-07-19 12:46:48 +02:00
Doug a10a26a68d Tidy up authentication service.
Add HomeserverLoginDetails
2022-07-19 11:36:34 +01:00
Benjamin Kampmann 1940ebefcb style(crypto): use matches for legibility 2022-07-19 12:22:53 +02:00
Benjamin Kampmann b91217f53b Merge remote-tracking branch 'origin/main' into gnunicorn/issue833 2022-07-19 12:19:20 +02:00
Benjamin Kampmann 3d3db96734 style(integration-tests): minor rust fmt fixes 2022-07-19 12:11:13 +02:00
Benjamin Kampmann b24f7b7ad7 ci(integration-tests): switch to non-docker github action 2022-07-19 12:05:49 +02:00
Benjamin Kampmann 9502d32941 Merge remote-tracking branch 'origin/main' into gnunicorn/issue833 2022-07-19 12:03:47 +02:00
Benjamin Kampmann 9318c2f1e8 ci(crypto-nodejs): switch to main branch 2022-07-19 11:36:30 +02:00
Benjamin Kampmann 2d03cb5c79 Merge pull request #852 from zecakeh/test-bulk-member
test(sdk): Split tests for permalinks
2022-07-19 11:34:48 +02:00
Johannes Becker aa8206d6c8 chore: Bump ruma 2022-07-18 19:32:16 +02:00
Johannes Becker f937d82336 chore: Bump ruma 2022-07-18 16:46:34 +00:00
Benjamin Kampmann 3f71818704 ci(test): switch from docker to compose 2022-07-18 18:10:41 +02:00
Benjamin Kampmann 025db83af3 ci(test): cancel previous calls and fix the docker logs cmd 2022-07-18 18:06:54 +02:00
Benjamin Kampmann 8520976417 style(test): fix styles of integration tests 2022-07-18 17:55:31 +02:00
Benjamin Kampmann 06cab75df3 ci(sdk): Add integration tests to CI 2022-07-18 17:39:51 +02:00
Benjamin Kampmann 47a8c62f44 fix(sdk): fetch invitiation details without sync 2022-07-18 17:39:29 +02:00
Benjamin Kampmann e2f1f01cb2 test(sdk): creating integration tests for invitations 2022-07-18 17:33:09 +02:00
Ivan Enderlin fdef2dd86d feat(bindings/crypto-js): Redirect panics and logs into JavaScript console
feat(bindings/crypto-js): Redirect panics and logs into JavaScript console
2022-07-18 14:59:50 +02:00
Ivan Enderlin c72ec36b3a chore(style) Make cargo fmt happy. 2022-07-18 14:39:39 +02:00
Benjamin Kampmann e3febd6f1f refactore(test): move testing out of regular build environment 2022-07-18 14:37:51 +02:00
Kévin Commaille b98e3d80a0 test(sdk): Split tests for permalinks 2022-07-18 13:39:37 +02:00
Kévin Commaille c0a7b17324 test: Add method to create room member events in bulk 2022-07-18 13:39:37 +02:00
Kévin Commaille 66c5d5311e test: Add methods to add events in bulk 2022-07-18 13:39:36 +02:00
Stefan Ceriu f215c92d0b fix(bindings/apple): Remove briding header as no longer needed after corectly naming the module map 2022-07-18 13:09:39 +02:00
Stefan Ceriu d571ca718d fix(bindings/apple): Allow any platform OS simulator to run the Apple specific unit tests. 2022-07-18 13:09:39 +02:00
Kévin Commaille 37eb058dac test: Reorganize JSON responses and events 2022-07-18 10:46:45 +02:00
Kévin Commaille 45ecd89387 test: Build sync response per room and event type
Allow to have more customizable and complete responses
2022-07-18 10:46:45 +02:00
Kévin Commaille 5d916e4a67 test: Expose default room ID used in sync JSON responses 2022-07-18 10:46:45 +02:00
Ivan Enderlin daa0fc0206 doc(bindings/crypto-js): Fix typos. 2022-07-18 10:05:05 +02:00
Ivan Enderlin 3d1c96fbec feat(bindings/crypto-js): Redirect errors to console.error. 2022-07-18 09:51:44 +02:00
Ivan Enderlin decd3fcb43 feat(bindings/crypto-js) Simplify code for feature = "tracing".
This patch creates one `inner` module for when `feature = "tracing"`,
and one for when `no(feature = "tracing")`. Then, let's expose
everything from `inner::*`.

This patch also replaces `Tracing.install` by `new Tracing`. In case
of `not(feature = "tracing")`, `new Tracing` raises an error.

The goal is to remove all the `#[cfg(…)]` annotations everywhere. Now
there is only 2 of them.
2022-07-18 09:44:42 +02:00
Ivan Enderlin c763ce3f41 feat(bindings/crypto-js): Tracing can be installed more than once. 2022-07-18 09:23:37 +02:00
Johannes Becker 09c56ea057 feat(appservice)!: Allow specifying device id for registration 2022-07-14 15:23:21 +02:00
github-actions 163ce94806 Tagging Crypto-Node.js for release 2022-07-14 10:40:57 +00:00
Benjamin Kampmann ebfa235dab chore(crypto-nodejs): Update changelog for beta.1 2022-07-14 12:31:04 +02:00
Benjamin Kampmann 0112396c99 ci(crypto-nodejs): trigger build for new tag 2022-07-14 12:31:04 +02:00
Benjamin Kampmann 8170d2c996 Merge remote-tracking branch 'origin/main' into ben-release-crypto-nodes-beta-1 2022-07-14 11:40:45 +02:00
Benjamin Kampmann 41de3e0af8 Merge pull request #844 from Hywan/fix-issue-842
fix(bindings/crypto-nodejs): Fix pre-built download link
2022-07-14 11:36:15 +02:00
Benjamin Kampmann 81bf300000 Merge pull request #839 from johannescpk/appservice/virtual-users
feat(appservice): Add method to get virtual user map
2022-07-14 11:31:02 +02:00
Benjamin Kampmann 594e8c04cd Merge pull request #840 from matrix-org/jplatte/optional-dep-features
Remove implicit features for optional dependencies
2022-07-14 11:30:03 +02:00
Benjamin Kampmann b6d94ab7c6 Merge pull request #845 from Hywan/fix-issue-843
fix(bindings/crypto-js): Use `cross-env` to pass envvar on Windows
2022-07-14 11:28:57 +02:00
Ivan Enderlin 283c5ff51e fix(bindings/crypto-js): Let's not deal with Console.group.
Events and spans from `tracing` can happen asynchronously, and could
mess the `Console.group` structure.
2022-07-14 09:04:44 +02:00
Ivan Enderlin bb631f2f79 feat(bindings/crypto-js): Add ability to turn Tracing on and off, and change logger min level.
The patch updates the code to use `tracing_subscriber::reload`, so
that we get a `Handle` that can be used to modify the tracing at
runtime.

This patch also adds a new `tracing` feature.

This patch finally adds a test suite for the `Tracing` API.
2022-07-14 09:04:13 +02:00
Ivan Enderlin d39baf1295 test(bindings/crypto-js): Encrypt and decrypt a valid message. 2022-07-14 09:04:13 +02:00
Ivan Enderlin f5016dbb97 feat(bindings/crypto-js): Define Layer.max_level_hint. 2022-07-14 09:04:13 +02:00
Ivan Enderlin e7d0ee4379 !fixup 2022-07-14 09:04:13 +02:00
Ivan Enderlin 70561f9649 feat(bindings/crypto-js): Add the userLogger function to enable logging into Console. 2022-07-14 09:04:13 +02:00
Ivan Enderlin 8f8bd40e8d feat(bindings/crypto-js): Redirect Rust panics to JavaScript console. 2022-07-14 09:04:13 +02:00
Ivan Enderlin 04d326eec1 doc(bindings/crypto-nodejs): Fix package name in the README.md
Fix package name in readme for nodejs bindings
2022-07-14 08:39:53 +02:00
Ivan Enderlin 3567d19359 fix(bindings/crypto-js): Use cross-env to pass envvar on Windows. 2022-07-14 08:26:57 +02:00
Ivan Enderlin 65b1dfef6f fix(bindings/crypto-nodejs): Fix pre-built download link. 2022-07-14 08:14:45 +02:00
Travis Ralston 4f1718e587 Fix package name in readme for nodejs bindings 2022-07-13 13:45:07 -06:00
Jonas Platte 3c5f30d41e refactor: Remove implicit features for optional dependencies
Consistently use `dep:` syntax for optional dependencies so they don't
implicitly act as features of their own.
2022-07-13 18:55:41 +02:00
Jonas Platte 529bdc8e0a refactor: Remove unused optional dependencies 2022-07-13 18:23:52 +02:00
Johannes Becker f55a86dd66 feat(appservice): Add method to get virtual user map 2022-07-13 17:16:12 +02:00
Benjamin Kampmann f87764fabb ci(ffi-apple): fixing ffi build for apple
Merge pull request #806 from matrix-org/stefan/ffi-workflow-optimization
2022-07-13 11:58:26 +02:00
Stefan Ceriu 65654de7eb chore: sdk-ffi apple - try building the framework on x86_64 outside of Xcode 2022-07-13 11:19:07 +02:00
Stefan Ceriu 399bbc25e9 chore: sdk-ffi apple - run the CI build script from the Xcode project and only for the active architecture 2022-07-13 11:19:06 +02:00
Stefan Ceriu c61dbb657e chore: sdk-ffi apple - drop sample project deployment target to iOS 15 and macOS 12, disable catalyst. 2022-07-13 11:19:06 +02:00
Stefan Ceriu a73b104c59 chore: sdk-ffi apple - rename modulemap to module.modulemap as per xcframework specifications 2022-07-13 11:19:06 +02:00
Stefan Ceriu c10961f068 chore: sdk-ffi apple - remove mac catalyst target support 2022-07-13 11:19:06 +02:00
Benjamin Kampmann 15e22cba47 Merge pull request #837 from johannescpk/appservice/refactor-cleanup
refactor(appservice)!: Improve API and cleanup docs
2022-07-13 11:16:47 +02:00
Johannes Becker ec00af0bca refactor(appservice)!: Improve API and cleanup docs 2022-07-13 10:11:43 +02:00
Benjamin Kampmann a4f1c404f6 ci(crypto-nodejs): set npm publish level to public
Release Crypto-Node.js / Upload prebuilt libraries (gcc-aarch64-linux-gnu g++-aarch64-linux-gnu, ubuntu-latest, aarch64-unknown-linux-gnu) (push) Failing after 45s
Release Crypto-Node.js / Upload prebuilt libraries (gcc-arm-linux-gnueabihf, ubuntu-latest, arm-unknown-linux-gnueabihf) (push) Failing after 41s
Release Crypto-Node.js / Upload prebuilt libraries (gcc-i686-linux-gnu g++-i686-linux-gnu, ubuntu-latest, i686-unknown-linux-gnu) (push) Failing after 30s
Release Crypto-Node.js / Upload prebuilt libraries (ubuntu-latest, x86_64-unknown-linux-gnu) (push) Failing after 42s
Release Crypto-Node.js / Upload prebuilt libraries (ubuntu-latest, x86_64-unknown-linux-musl) (push) Failing after 35s
Release Crypto-Node.js / Upload prebuilt libraries (macos-latest, aarch64-apple-darwin) (push) Has been cancelled
Release Crypto-Node.js / Upload prebuilt libraries (macos-latest, x86_64-apple-darwin) (push) Has been cancelled
Release Crypto-Node.js / Upload prebuilt libraries (windows-latest, aarch64-pc-windows-msvc) (push) Has been cancelled
Release Crypto-Node.js / Upload prebuilt libraries (windows-latest, i686-pc-windows-msvc) (push) Has been cancelled
Release Crypto-Node.js / Upload prebuilt libraries (windows-latest, x86_64-pc-windows-msvc) (push) Has been cancelled
Release Crypto-Node.js / Package nodejs package (push) Has been cancelled
2022-07-12 19:28:59 +02:00
Benjamin Kampmann f69123b0d8 style(indexeddb): rust fmt 2022-07-12 13:11:50 +02:00
Benjamin Kampmann c1f0c73728 fix(indexeddb): New migration didn't create schema for new db 2022-07-11 16:18:29 +02:00
Benjamin Kampmann 54ed1af223 Merge remote-tracking branch 'origin/main' into gnunicorn/issue756 2022-07-11 15:17:03 +02:00
Benjamin Kampmann 6a57461f74 feat(indexeddb)!: Implement StateStoreBuilder pattern to configure migration preferences 2022-07-11 14:28:09 +02:00
Benjamin Kampmann d7b974ac04 build(xtask): indexeddb alias for ci wasm-commands 2022-07-07 18:35:54 +02:00
Benjamin Kampmann aae9b5c6d8 refactor(test)!: More debugging info on errors in async_test macro 2022-07-07 18:35:16 +02:00
Benjamin Kampmann dc40309cbe feat(sled): Introduce SledStoreBuilder, allow migration conflict strategy configuration 2022-07-06 17:51:51 +02:00
Benjamin Kampmann d465b70bea refactor(indexeddb)!: Rename SerializationError to IndexedDBStoreError 2022-07-06 12:18:58 +02:00
Benjamin Kampmann 5316d2e6e7 fix(indexeddb): Upgrade version to latest state store pattern 2022-06-16 13:17:45 +02:00
Benjamin Kampmann 7adef1d24e fix(sled): Upgrade db version to latest changes 2022-06-16 13:17:35 +02:00
847 changed files with 247747 additions and 43723 deletions
+1 -33
View File
@@ -1,41 +1,9 @@
# 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(all())'` 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 --"
[doc.extern-map.registries]
crates-io = "https://docs.rs/"
[target.'cfg(all())']
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",
]
# 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
+4
View File
@@ -0,0 +1,4 @@
[profile.default]
retries = { backoff = "exponential", count = 3, delay = "1s", jitter = true }
# kill the slow tests if they still aren't up after 180s
slow-timeout = { period = "60s", terminate-after = 3 }
+67
View File
@@ -0,0 +1,67 @@
# 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",
# We can release vodozemac whenever we need but let's not block development
# on releases.
"https://github.com/matrix-org/vodozemac",
]
+6
View File
@@ -0,0 +1,6 @@
root = true
# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
+2
View File
@@ -0,0 +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"
+7
View File
@@ -0,0 +1,7 @@
<!-- description of the changes in this PR -->
- [ ] Public API changes documented in changelogs (optional)
<!-- Sign-off, if not part of the commits -->
<!-- See CONTRIBUTING.md if you don't know what this is -->
Signed-off-by:
-54
View File
@@ -1,54 +0,0 @@
name: AppService
on:
push:
branches: [main]
pull_request:
branches: [main]
types:
- opened
- reopened
- synchronize
- ready_for_review
env:
CARGO_TERM_COLOR: always
jobs:
test-appservice:
if: github.event_name == 'push' || !github.event.pull_request.draft
name: ${{ matrix.os-name }} [m]-appservice
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
include:
- os: ubuntu-latest
os-name: 🐧
- os: macos-latest
os-name: 🍏
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true
- name: Load cache
uses: Swatinem/rust-cache@v1
- name: Install nextest
uses: taiki-e/install-action@nextest
- name: Run checks
uses: actions-rs/cargo@v1
with:
command: run
args: -p xtask -- ci test-appservice
-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@v1
- uses: actions-rs/audit-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
+4 -6
View File
@@ -8,19 +8,17 @@ 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@v2
uses: actions/checkout@v4
- name: Install Rust
uses: actions-rs/toolchain@v1
uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly
toolchain: nightly-2024-11-26
components: rustfmt
profile: minimal
override: true
- name: Run Benchmarks
run: cargo bench | tee benchmark-output.txt
+176 -125
View File
@@ -12,162 +12,213 @@ on:
- synchronize
- ready_for_review
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
CARGO_TERM_COLOR: always
MATRIX_SDK_CRYPTO_NODEJS_PATH: bindings/matrix-sdk-crypto-nodejs
MATRIX_SDK_CRYPTO_JS_PATH: bindings/matrix-sdk-crypto-js
jobs:
test-matrix-sdk-crypto-nodejs:
name: ${{ matrix.os-name }} [m]-crypto-nodejs, v${{ matrix.node-version }}
xtask:
uses: ./.github/workflows/xtask.yml
test-uniffi-codegen:
name: Test UniFFI bindings generation
needs: xtask
if: github.event_name == 'push' || !github.event.pull_request.draft
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
os: [ubuntu-latest, macos-latest]
node-version: [14.0, 16.0, 18.0]
include:
- os: ubuntu-latest
os-name: 🐧
- os: macos-latest
os-name: 🍏
- node-version: 18.0
build-doc: true
steps:
- name: Checkout the repo
uses: actions/checkout@v2
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true
- name: Load cache
uses: Swatinem/rust-cache@v1
- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Install NPM dependencies
working-directory: ${{ env.MATRIX_SDK_CRYPTO_NODEJS_PATH }}
run: npm install
- name: Build the Node.js binding
working-directory: ${{ env.MATRIX_SDK_CRYPTO_NODEJS_PATH }}
run: npm run release-build
- name: Test the Node.js binding
working-directory: ${{ env.MATRIX_SDK_CRYPTO_NODEJS_PATH }}
run: npm run test
# Building in dev-mode and copy lib in failure case
- name: Build the Node.js binding in non-release
if: failure()
working-directory: ${{ env.MATRIX_SDK_CRYPTO_NODEJS_PATH }}
run: |
cp *.node release-mode-lib.node
npm run build
- uses: actions/upload-artifact@v3
if: failure()
with:
name: Failure Files
path: |
bindings/matrix-sdk-crypto-nodejs/*.node
/var/crash/*.crash
- if: ${{ matrix.build-doc }}
name: Build the documentation
working-directory: ${{ env.MATRIX_SDK_CRYPTO_NODEJS_PATH }}
run: npm run doc
test-matrix-sdk-crypto-js:
name: 🕸 [m]-crypto-js
if: github.event_name == 'push' || !github.event.pull_request.draft
runs-on: ubuntu-latest
steps:
- name: Checkout the repo
uses: actions/checkout@v2
- name: Checkout
uses: actions/checkout@v4
- name: Install protoc
uses: taiki-e/install-action@v2
with:
tool: protoc@3.20.3
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
target: wasm32-unknown-unknown
profile: minimal
override: true
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@v1
uses: Swatinem/rust-cache@v2
with:
save-if: ${{ github.ref == 'refs/heads/main' }}
- name: Install Node.js
uses: actions/setup-node@v3
- 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 NPM dependencies
working-directory: ${{ env.MATRIX_SDK_CRYPTO_JS_PATH }}
run: npm install
- name: Build library & generate bindings
run: target/debug/xtask ci bindings
- name: Build the WebAssembly + JavaScript binding
working-directory: ${{ env.MATRIX_SDK_CRYPTO_JS_PATH }}
run: npm run build
test-android:
name: matrix-rust-components-kotlin
needs: xtask
runs-on: ubuntu-latest
if: github.event_name == 'push' || !github.event.pull_request.draft
- name: Test the JavaScript binding
working-directory: ${{ env.MATRIX_SDK_CRYPTO_JS_PATH }}
run: npm run test
steps:
- name: Checkout Rust SDK
uses: actions/checkout@v4
- name: Build the documentation
working-directory: ${{ env.MATRIX_SDK_CRYPTO_JS_PATH }}
run: npm run doc
- 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.7
- 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
runs-on: macos-12
needs: xtask
runs-on: macos-15
if: github.event_name == 'push' || !github.event.pull_request.draft
steps:
- name: Checkout
uses: actions/checkout@v1
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: actions-rs/toolchain@v1
with:
toolchain: nightly
profile: minimal
override: true
uses: dtolnay/rust-toolchain@stable
- name: Install targets
run: |
rustup target add aarch64-apple-ios-sim --toolchain nightly
rustup target add x86_64-apple-ios --toolchain nightly
- name: Install aarch64-apple-ios target
run: rustup target install 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@v1
- name: Install Uniffi
uses: actions-rs/cargo@v1
uses: Swatinem/rust-cache@v2
with:
command: install
# keep in sync with uniffi dependency in Cargo.toml's
args: uniffi_bindgen --version ^0.18
save-if: ${{ github.ref == 'refs/heads/main' }}
- name: Generate .xcframework
run: sh bindings/apple/debug_build_xcframework.sh ci
- name: Get xtask
uses: actions/cache/restore@v4
with:
path: target/debug/xtask
key: "${{ needs.xtask.outputs.cachekey-macos }}"
fail-on-cache-miss: true
- name: Build library & bindings
run: target/debug/xtask swift build-library
- name: Run XCTests
working-directory: bindings/apple
run: swift test
- name: Build Framework
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: |
xcodebuild test \
-project bindings/apple/MatrixRustSDK.xcodeproj \
-scheme MatrixRustSDK \
-sdk iphonesimulator \
-destination 'platform=iOS Simulator,name=iPhone 13,OS=15.4'
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"
+269 -75
View File
@@ -12,13 +12,23 @@ on:
- synchronize
- ready_for_review
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
CARGO_TERM_COLOR: always
# Insta.rs is run directly via cargo test. We don't want insta.rs to create new snapshots files.
# Just want it to run the tests (option `no` instead of `auto`).
INSTA_UPDATE: no
jobs:
xtask:
uses: ./.github/workflows/xtask.yml
test-matrix-sdk-features:
name: 🐧 [m], ${{ matrix.name }}
if: github.event_name == 'push' || !github.event.pull_request.draft
needs: xtask
runs-on: ubuntu-latest
strategy:
@@ -26,9 +36,9 @@ jobs:
matrix:
name:
- no-encryption
- no-sled
- no-encryption-and-sled
- sled-cryptostore
- no-sqlite
- no-encryption-and-sqlite
- sqlite-cryptostore
- rustls-tls
- markdown
- socks
@@ -36,58 +46,110 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v1
uses: actions/checkout@v4
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true
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@v1
uses: Swatinem/rust-cache@v2
with:
# use a separate cache for each job to work around
# https://github.com/Swatinem/rust-cache/issues/124
key: "${{ matrix.name }}"
# ... but only save the cache on the main branch
# cf https://github.com/Swatinem/rust-cache/issues/95
save-if: ${{ github.ref == 'refs/heads/main' }}
- name: Install nextest
uses: taiki-e/install-action@nextest
- name: Test
uses: actions-rs/cargo@v1
- name: Get xtask
uses: actions/cache/restore@v4
with:
command: run
args: -p xtask -- ci test-features ${{ matrix.name }}
path: target/debug/xtask
key: "${{ needs.xtask.outputs.cachekey-linux }}"
fail-on-cache-miss: true
- name: Test
run: |
target/debug/xtask ci test-features ${{ matrix.name }}
test-matrix-sdk-examples:
name: 🐧 [m]-examples
needs: xtask
runs-on: ubuntu-latest
steps:
- name: Checkout the repo
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Load cache
uses: Swatinem/rust-cache@v2
with:
save-if: ${{ github.ref == 'refs/heads/main' }}
- name: Install nextest
uses: taiki-e/install-action@nextest
- 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: Test
run: |
target/debug/xtask ci examples
test-matrix-sdk-crypto:
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@v2
- name: Checkout the repo
uses: actions/checkout@v4
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true
- name: Install libsqlite
run: |
sudo apt-get update
sudo apt-get install libsqlite3-dev
- name: Load cache
uses: Swatinem/rust-cache@v1
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Install nextest
uses: taiki-e/install-action@nextest
- name: Load cache
uses: Swatinem/rust-cache@v2
with:
save-if: ${{ github.ref == 'refs/heads/main' }}
- name: Test
uses: actions-rs/cargo@v1
with:
command: run
args: -p xtask -- ci test-crypto
- name: Install nextest
uses: taiki-e/install-action@nextest
- 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: Test
run: |
target/debug/xtask ci test-crypto
test-all-crates:
name: ${{ matrix.name }}
if: github.event_name == 'push' || !github.event.pull_request.draft
runs-on: ${{ matrix.os }}
strategy:
@@ -108,36 +170,44 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v1
uses: actions/checkout@v4
- name: Install Rust
uses: actions-rs/toolchain@v1
- 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:
toolchain: ${{ matrix.rust }}
profile: minimal
override: true
- name: Load cache
uses: Swatinem/rust-cache@v1
uses: Swatinem/rust-cache@v2
with:
save-if: ${{ github.ref == 'refs/heads/main' }}
- name: Install nextest
uses: taiki-e/install-action@nextest
- name: Test
uses: actions-rs/cargo@v1
with:
command: nextest
args: run --workspace
run: |
cargo nextest run --workspace \
--exclude matrix-sdk-integration-testing --features testing
- name: Test documentation
uses: actions-rs/cargo@v1
with:
command: test
args: --doc
run: |
cargo test --doc --features docsrs
test-wasm:
name: 🕸️ ${{ matrix.name }}
if: github.event_name == 'push' || !github.event.pull_request.draft
needs: xtask
runs-on: ubuntu-latest
@@ -154,56 +224,180 @@ 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], no-default, wasm-flags'
- name: '[m], no-default'
cmd: matrix-sdk-no-default
- name: '[m]-ui'
cmd: matrix-sdk-ui
check_only: true
- name: '[m]-indexeddb'
cmd: indexeddb
- name: '[m], indexeddb stores'
cmd: matrix-sdk-indexeddb-stores
- name: '[m], indexeddb stores, no crypto'
cmd: matrix-sdk-indexeddb-stores-no-crypto
- name: '[m], wasm-example'
cmd: matrix-sdk-command-bot
steps:
- name: Checkout the repo
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Install Rust
uses: actions-rs/toolchain@v1
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
target: wasm32-unknown-unknown
targets: wasm32-unknown-unknown
components: clippy
profile: minimal
override: true
- name: Install wasm-pack
uses: jetli/wasm-pack-action@v0.3.0
uses: qmaru/wasm-pack-action@v0.5.0
if: '!matrix.check_only'
with:
version: latest
version: v0.10.3
- name: Load cache
uses: Swatinem/rust-cache@v1
uses: Swatinem/rust-cache@v2
with:
# use a separate cache for each job to work around
# https://github.com/Swatinem/rust-cache/issues/124
key: "${{ matrix.cmd }}"
# ... but only save the cache on the main branch
# cf https://github.com/Swatinem/rust-cache/issues/95
save-if: ${{ github.ref == 'refs/heads/main' }}
- name: Install nextest
uses: taiki-e/install-action@nextest
- name: Rust Check
uses: actions-rs/cargo@v1
- name: Get xtask
uses: actions/cache/restore@v4
with:
command: run
args: -p xtask -- ci wasm ${{ matrix.cmd }}
path: target/debug/xtask
key: "${{ needs.xtask.outputs.cachekey-linux }}"
fail-on-cache-miss: true
- name: Rust Check
run: |
target/debug/xtask ci wasm ${{ matrix.cmd }}
- name: Wasm-Pack test
uses: actions-rs/cargo@v1
if: '!matrix.check_only'
run: |
target/debug/xtask ci wasm-pack ${{ matrix.cmd }}
typos:
name: Spell Check with Typos
runs-on: ubuntu-latest
steps:
- name: Checkout Actions Repository
uses: actions/checkout@v4
- name: Check the spelling of the files in our repo
uses: crate-ci/typos@v1.29.5
lint:
name: Lint
needs: xtask
runs-on: ubuntu-latest
steps:
- name: Checkout the repo
uses: actions/checkout@v4
- name: Install protoc
uses: taiki-e/install-action@v2
with:
command: run
args: -p xtask -- ci wasm-pack ${{ matrix.cmd }}
tool: protoc@3.20.3
- name: Install Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly-2024-11-26
components: clippy, rustfmt
- 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: Check Formatting
run: |
target/debug/xtask ci style
- name: Clippy
run: |
target/debug/xtask ci clippy
integration-tests:
name: Integration test
runs-on: ubuntu-latest
# run several docker containers with the same networking stack so the hostname 'postgres'
# maps to the postgres container, etc.
services:
# synapse needs a postgres container
postgres:
# Docker Hub image
image: postgres
# Provide the password for postgres
env:
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres
POSTGRES_DB: syncv3
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
# Maps tcp port 5432 on service container to the host
- 5432:5432
# 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.117.0 # keep in sync with ./coverage.yml
env:
SYNAPSE_COMPLEMENT_DATABASE: sqlite
SERVER_NAME: synapse
ports:
- 8008:8008
steps:
- name: Checkout the repo
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
- name: Load cache
uses: Swatinem/rust-cache@v2
with:
save-if: ${{ github.ref == 'refs/heads/main' }}
- name: Install nextest
uses: taiki-e/install-action@nextest
- name: Test
env:
RUST_LOG: "info,matrix_sdk=trace"
HOMESERVER_URL: "http://localhost:8008"
HOMESERVER_DOMAIN: "synapse"
SLIDING_SYNC_PROXY_URL: "http://localhost:8118"
run: |
cargo nextest run -p matrix-sdk-integration-testing
+109 -24
View File
@@ -1,45 +1,130 @@
name: Code coverage
name: Code Coverage
on:
push:
branches: [main]
pull_request:
branches: [main]
types:
- opened
- reopened
- synchronize
- ready_for_review
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
CARGO_TERM_COLOR: always
# without matrix_sdk=trace, expressions in `trace!` fields are not evaluated
# when the `trace!` statement is hit, and thus not covered
RUST_LOG: info,matrix_sdk=trace
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:
postgres:
# Docker Hub image
image: postgres
# Provide the password for postgres
env:
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres
POSTGRES_DB: syncv3
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
# Maps tcp port 5432 on service container to the host
- 5432:5432
# 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.117.0 # keep in sync with ./ci.yml
env:
SYNAPSE_COMPLEMENT_DATABASE: sqlite
SERVER_NAME: synapse
ports:
- 8008:8008
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true
- name: Install libsqlite
run: |
sudo apt-get update
sudo apt-get install libsqlite3-dev
- name: Load cache
uses: Swatinem/rust-cache@v1
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Install tarpaulin
uses: actions-rs/cargo@v1
with:
command: install
args: cargo-tarpaulin
# 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: Run tarpaulin
uses: actions-rs/cargo@v1
with:
command: tarpaulin
args: --out Xml
- name: Load cache
uses: Swatinem/rust-cache@v2
with:
save-if: ${{ github.ref == 'refs/heads/main' }}
- name: Upload to codecov.io
uses: codecov/codecov-action@v3
- name: Install tarpaulin
uses: taiki-e/install-action@v2
with:
tool: cargo-tarpaulin
# set up backend for integration tests
- uses: actions/setup-python@v5
with:
python-version: 3.8
- name: Run tarpaulin
run: |
rustup run stable cargo tarpaulin \
--skip-clean --profile cov --out xml \
--features experimental-widgets,testing
env:
CARGO_PROFILE_COV_INHERITS: 'dev'
CARGO_PROFILE_COV_DEBUG: 1
HOMESERVER_URL: "http://localhost:8008"
HOMESERVER_DOMAIN: "synapse"
SLIDING_SYNC_PROXY_URL: "http://localhost:8118"
# 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:
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
+40 -18
View File
@@ -4,42 +4,64 @@ on:
push:
branches: [main]
pull_request:
types:
- opened
- reopened
- synchronize
- ready_for_review
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
pages: write
id-token: write
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@v2
uses: actions/checkout@v4
- name: Install protoc
uses: taiki-e/install-action@v2
with:
tool: protoc@3.20.3
- name: Install Rust
uses: actions-rs/toolchain@v1
uses: dtolnay/rust-toolchain@master
with:
profile: minimal
toolchain: nightly
override: true
toolchain: nightly-2024-11-26
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Load cache
uses: Swatinem/rust-cache@v1
uses: Swatinem/rust-cache@v2
with:
save-if: ${{ github.ref == 'refs/heads/main' }}
# Keep in sync with xtask docs
- name: Build documentation
uses: actions-rs/cargo@v1
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"
with:
command: doc
args: --no-deps --workspace --features docsrs
run:
cargo doc --no-deps --workspace --features docsrs --exclude=xtask
- name: Deploy documentation
- name: Upload artifact
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
uses: peaceiris/actions-gh-pages@v3
uses: actions/upload-pages-artifact@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./target/doc/
force_orphan: true
path: './target/doc/'
- name: Deploy to GitHub Pages
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
id: deployment
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
@@ -1,109 +0,0 @@
name: Prepare Crypto-Node.js Release
#
# This is a helper workflow to craft a new Node.js release, trigger this via
# the Github Workflow UI by dispatching it manually. Provide the version, the
# matrix-sdk-crypto-nodejs npm package should be set to, and a optionally the
# old version (as used in the git tag) this release should be compared to.
#
# This will then:
# 1. bump the npm version to the one you specified
# 2. commit that change together with the changelog (if it changed, see below)
# 3. create the appropriate tag on that commit
# 4. create the Github draft release, including the changes (if given, see below)
# 5. push these to a new branch, including tag, triggering the `release-crypto-nodejs` workflow
# 6. create a PR to merge these back into `main`
#
# Additionally, if you provide a tag to comapare this tag to, this will:
# 1. create a changelog between the two releases, used for the github release
# 2. update the Changelog.md and include it in the commit
#
# The remaining tasks are done by the release-crypto-nodejs workflow.
on:
workflow_dispatch:
inputs:
version:
description: 'New Node.js SemVer version to create'
required: true
type: string
previous_version:
description: 'Create the changelog by comparing to this old SemVer Version (as used in the tag) '
type: string
env:
PKG_PATH: "bindings/matrix-sdk-crypto-nodejs"
TAG_PREFIX: "matrix-sdk-crypto-nodejs-v"
jobs:
prepare-release:
name: "Preparing crypto-nodejs release tag"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
# Generate changelog since last tag, if given
- name: Generate a changelog for upload
if: inputs.previous_version
uses: orhun/git-cliff-action@v1
with:
config: "${{ env.PKG_PATH }}/cliff.toml"
args: --strip header "${{env.TAG_PREFIX}}${{ inputs.previous_version }}..HEAD"
env:
GIT_CLIFF_TAG: "Changes ${{ inputs.previous_version }} -> ${{ inputs.version }}"
GIT_CLIFF_OUTPUT: "${{ env.PKG_PATH }}/CHANGES-${{ inputs.version }}.md"
# Update changelog since last tag, if given
- name: Update existing Changelog
if: inputs.previous_version
uses: orhun/git-cliff-action@v1
with:
config: "${{ env.PKG_PATH }}/cliff.toml"
args: "${{ inputs.previous_version }}..HEAD"
env:
GIT_CLIFF_TAG: "${{ inputs.version }}"
GIT_CLIFF_PREPEND: "${{ env.PKG_PATH }}/CHANGELOG.md"
- name: Set version
id: package_version
working-directory: ${{ env.PKG_PATH }}
run: npm version ${{ inputs.version }}
- uses: EndBug/add-and-commit@v9
with:
default_author: github_actions
message: "Tagging Crypto-Node.js for release"
tag: "${{env.TAG_PREFIX}}${{ inputs.version }}"
new_branch: "gh-action/release-${{ env.TAG_PREFIX }}${{ inputs.version }}"
push: true
add: |
${{ env.PKG_PATH }}/package.json
${{ env.PKG_PATH }}/CHANGELOG.md
# if we have generated changes
- name: Update Github Release notes
if: inputs.previous_version
uses: softprops/action-gh-release@v1
with:
draft: true
tag_name: ${{ env.TAG_PREFIX }}${{ inputs.version }}
body_path: "${{ env.PKG_PATH }}/CHANGES-${{ inputs.version }}.md"
# no changes, use the default changelog for the body
- name: Update Github Release notes
if: ${{!inputs.previous_version}}
uses: softprops/action-gh-release@v1
with:
draft: true
tag_name: ${{ env.TAG_PREFIX }}${{ inputs.version }}
body_path: "${{ env.PKG_PATH }}/CHANGELOG.md"
# finally, let's create a PR for all this, too
- name: Create Pull Request
uses: peter-evans/create-pull-request@v4
with:
branch: "gh-action/release-${{ env.TAG_PREFIX }}${{ inputs.version }}"
base: "main"
title: "Preparing Release ${{ env.TAG_PREFIX }}${{ inputs.version }}"
body: |
Automatic Pull-Request to merge release ${{ env.TAG_PREFIX }}${{ inputs.version }} back into main
-117
View File
@@ -1,117 +0,0 @@
name: Release Crypto-Node.js
#
# This workflow releases the crypto-bindings for nodejs
#
# It is triggered when seeing a tag prefixed matching `matrix-sdk-crypto-nodejs-v[0-9]+.*`,
# which then build the native bindings for linux, mac and windows via the CI and uploads
# them to the corresponding Github Release tag. Once they are finished, this workflow will
# package the npm tar.gz and uploads that to the Github Release tag as well, before publishing
# it to npmjs.com automatically.
#
# The usual way to trigger this is by manually triggering the `prep-crypto-nodejs-release`
# workflow. See its documentation for instructions how to use it.
env:
PKG_PATH: "bindings/matrix-sdk-crypto-nodejs"
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: 'aarch64-linux-gnu-gcc'
CARGO_TARGET_I686_UNKNOWN_LINUX_GNU_LINKER: 'i686-linux-gnu-gcc'
CARGO_TARGET_ARM_UNKNOWN_LINUX_GNUEABIHF_LINKER: 'arm-linux-gnueabihf-gcc'
on:
push:
tags:
- matrix-sdk-crypto-nodejs-v[0-9]+.*
jobs:
upload-assets:
name: "Upload prebuilt libraries"
strategy:
fail-fast: false
matrix:
include:
# ----------------------------------- Linux
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
- target: i686-unknown-linux-gnu
apt_install: gcc-i686-linux-gnu g++-i686-linux-gnu
os: ubuntu-latest
- target: aarch64-unknown-linux-gnu
os: ubuntu-latest
apt_install: gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
- target: arm-unknown-linux-gnueabihf
os: ubuntu-latest
apt_install: gcc-arm-linux-gnueabihf
- target: x86_64-unknown-linux-musl
os: ubuntu-latest
# ----------------------------------- macOS
- target: aarch64-apple-darwin
os: macos-latest
- target: x86_64-apple-darwin
os: macos-latest
# ----------------------------------- Windows
- target: x86_64-pc-windows-msvc
os: windows-latest
- target: i686-pc-windows-msvc
os: windows-latest
- target: aarch64-pc-windows-msvc
os: windows-latest
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
profile: minimal
target: ${{ matrix.target }}
override: true
- name: Install Node.js
uses: actions/setup-node@v3
- name: Load cache
uses: Swatinem/rust-cache@v1
- if: ${{ matrix.apt_install }}
run: |
sudo apt-get update
sudo apt-get install -y ${{ matrix.apt_install }}
- name: Build lib
working-directory: ${{env.PKG_PATH}}
run: |
npm install --ignore-scripts
npx napi build --platform --release --strip --target ${{ matrix.target }}
- name: Upload artifacts to release
uses: softprops/action-gh-release@v1
with:
draft: true
files: ${{env.PKG_PATH}}/*.node
publish-nodejs-package:
name: "Package nodejs package"
runs-on: ubuntu-latest
needs:
- upload-assets
steps:
- uses: actions/checkout@v3
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
profile: minimal
override: true
- name: Install Node.js
uses: actions/setup-node@v3
- name: Build lib
working-directory: ${{env.PKG_PATH}}
run: |
npm install --ignore-scripts
npm run build
npm pack
- name: Upload npm package to release
uses: softprops/action-gh-release@v1
with:
draft: true
files: ${{env.PKG_PATH}}/*tgz
- name: Publish to npmjs.com
uses: JS-DevTools/npm-publish@v1
with:
package: ${{env.PKG_PATH}}/package.json
token: ${{ secrets.NPM_TOKEN }}
-105
View File
@@ -1,105 +0,0 @@
name: Style
on:
workflow_dispatch:
push:
branches: [main]
pull_request:
branches: [main]
types:
- opened
- reopened
- synchronize
- ready_for_review
env:
CARGO_TERM_COLOR: always
jobs:
style:
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@v2
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
components: rustfmt
profile: minimal
override: true
- name: Cargo fmt
uses: actions-rs/cargo@v1
with:
command: fmt
args: -- --check
pre-commit-styles:
name: Check Style
if: github.event_name == 'push' || !github.event.pull_request.draft
runs-on: ubuntu-latest
steps:
- name: Checkout Actions Repository
uses: actions/checkout@v2
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
components: clippy
profile: minimal
override: true
- name: Setup Python Env
uses: actions/setup-python@v2
- name: Check Styles with pre-commit
uses: pre-commit/action@v2.0.3
with:
# only run `commit`-hooks, excludes typos, clippy, etc
extra_args: --show-diff-on-failure --hook-stage commit
typos:
name: Spell Check with Typos
needs: [style]
runs-on: ubuntu-latest
if: github.event_name == 'push' || !github.event.pull_request.draft
steps:
- name: Checkout Actions Repository
uses: actions/checkout@v2
- name: Check the spelling of the files in our repo
uses: crate-ci/typos@master
clippy:
name: Run clippy
needs: [style]
runs-on: ubuntu-latest
if: github.event_name == 'push' || !github.event.pull_request.draft
steps:
- name: Checkout the repo
uses: actions/checkout@v2
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
components: clippy
profile: minimal
override: true
- name: Load cache
uses: Swatinem/rust-cache@v1
- name: Clippy
uses: actions-rs/cargo@v1
with:
command: run
args: -p xtask -- ci clippy
+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 }}
+76
View File
@@ -0,0 +1,76 @@
# A reusable github actions workflow that will build xtask, if it is not
# already cached.
#
# It will create a pair of GHA cache entries, if they do not already exist.
# The cache keys take the form `xtask-{os}-{hash}`, where "{os}" is "linux"
# or "macos", and "{hash}" is the hash of the xtask# directory.
#
# The cache keys are written to output variables named "cachekey-{os}".
#
name: Build xtask if necessary
on:
workflow_call:
outputs:
cachekey-linux:
description: "The cache key for the linux build artifact"
value: "${{ jobs.xtask.outputs.cachekey-linux }}"
cachekey-macos:
description: "The cache key for the macos build artifact"
value: "${{ jobs.xtask.outputs.cachekey-macos }}"
env:
CARGO_TERM_COLOR: always
jobs:
xtask:
name: "xtask-${{ matrix.os-name }}"
strategy:
fail-fast: true
matrix:
include:
- os: ubuntu-latest
os-name: 🐧
cachekey-id: linux
- os: macos-15
os-name: 🍏
cachekey-id: macos
runs-on: "${{ matrix.os }}"
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Calculate cache key
id: cachekey
# set a step output variable "cachekey-{os}" that can be referenced in
# the job outputs below.
run: |
echo "cachekey-${{ matrix.cachekey-id }}=xtask-${{ matrix.cachekey-id }}-${{ hashFiles('Cargo.toml', 'xtask/**') }}" >> $GITHUB_OUTPUT
- name: Check xtask cache
uses: actions/cache@v4
id: xtask-cache
with:
path: target/debug/xtask
# use the cache key calculated in the step above. Bit of an awkward
# syntax
key: |
${{ steps.cachekey.outputs[format('cachekey-{0}', matrix.cachekey-id)] }}
- name: Install Rust stable toolchain
if: steps.xtask-cache.outputs.cache-hit != 'true'
uses: dtolnay/rust-toolchain@stable
- name: Build
if: steps.xtask-cache.outputs.cache-hit != 'true'
run: |
cargo build -p xtask
outputs:
"cachekey-linux": "${{ steps.cachekey.outputs.cachekey-linux }}"
"cachekey-macos": "${{ steps.cachekey.outputs.cachekey-macos }}"
+11 -1
View File
@@ -1,9 +1,14 @@
Cargo.lock
target
generated
master.zip
emsdk-*
.idea/
.env
.build
.swiftpm
/Package.swift
# code coverage report
cobertura.xml
## User settings
xcuserdata/
@@ -11,3 +16,8 @@ xcuserdata/
## OS garbage
.DS_Store
## Kotlin bindings generated files
bindings/kotlin/.gradle/
bindings/kotlin/buildSrc/build/
bindings/kotlin/buildSrc/.gradle/
Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

-41
View File
@@ -1,41 +0,0 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.2.0
hooks:
- id: check-yaml
- id: check-toml
- id: end-of-file-fixer
- id: trailing-whitespace
- id: check-merge-conflict
- id: mixed-line-ending
- repo: local
hooks:
- id: fmt
name: fmt
language: system
types: [file, rust]
entry: cargo fmt -- --check
- id: clippy
name: clippy
stages: [push]
language: system
types: [file, rust]
entry: cargo clippy --all-targets --all
pass_filenames: false
- id: test
name: test
stages: [push]
language: system
files: '\.rs$'
entry: cargo test --lib
pass_filenames: false
- id: typos
name: typos
stages: [push]
language: system
entry: typos
pass_filenames: false
+4 -1
View File
@@ -1,7 +1,10 @@
edition = "2018"
max_width = 100
comment_width = 80
wrap_comments = true
imports_granularity = "Crate"
use_small_heuristics = "Max"
group_imports = "StdExternalCrate"
format_code_in_doc_comments = true
doc_comment_code_block_width = 80
# Workaround for https://github.com/rust-lang/rust.vim/issues/464
edition = "2021"
+36 -8
View File
@@ -1,11 +1,39 @@
[default]
extend-ignore-re = [
# base 58 strings with spaces every four chars.
# this would also match regular sentence parts with eight or more words of
# exactly four characters in row, but that doesn't really happen.
"[1-9A-Za-z]{4}( [1-9A-Za-z]{4}){7,}",
# some heuristics for base64 strings with no false matches found at the
# time of writing.
"[A-Za-z0-9+=]{72,}",
"([A-Za-z0-9+=]|\\\\\\s\\*){72,}",
"[0-9+][A-Za-z0-9+]{30,}[a-z0-9+]",
"\\$[A-Z0-9+][A-Za-z0-9+]{6,}[a-z0-9+]",
"\\b[a-z0-9+/=][A-Za-z0-9+/=]{7,}[a-z0-9+/=][A-Z]\\b",
]
[default.extend-identifiers]
WeeChat = "WeeChat"
# all of these are valid words, but should never appear in this repo
[default.extend-words]
# Remove this once base64 gets correctly ignored by typos
# Or if we're able to ignore certain lines.
Fo = "Fo"
BA = "BA"
UE = "UE"
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 = ["*.json"]
extend-exclude = [
# Our json files contain a bunch of base64 encoded ed25519 keys.
"*.json",
# 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).
+314
View File
@@ -0,0 +1,314 @@
# Contributing to matrix-rust-sdk
## Chat rooms
In addition to our [main Matrix room], we have a development room at
[#matrix-rust-sdk-dev:flipdot.org]. Please use it to discuss potential changes,
the overall direction of development and related topics.
[main Matrix room]: https://matrix.to/#/#matrix-rust-sdk:matrix.org
[#matrix-rust-sdk-dev:flipdot.org]: https://matrix.to/#/#matrix-rust-sdk-dev:flipdot.org
## Testing
You can run most of the tests that also happen in CI also using
`cargo xtask ci`. This needs a few dependencies to be installed, as it also runs
automatic WASM tests:
```bash
rustup component add clippy
cargo install cargo-nextest typos-cli wasm-pack
```
If you want to execute only one part of CI, there are a few sub-commands (see
`cargo xtask ci --help`).
Some tests are not automatically run in `cargo xtask ci`, for example the
integration tests that need a running synapse instance. These tests reside in
`./testing/matrix-sdk-integration-testing`. See its
[README](./testing/matrix-sdk-integration-testing/README.md) to easily set up a
synapse for testing purposes.
### Snapshot Testing
You can add/review snapshot tests using [insta.rs](https://insta.rs)
Every new struct/enum that derives `Serialize` `Deserialise` should have a snapshot test for it.
Any code change that breaks serialisation will then break a test, the author will then have to decide
how to handle migration and test it if needed.
And for an improved review experience it's recommended (but not necessary) to install the cargo-insta tool:
Unix:
```
curl -LsSf https://insta.rs/install.sh | sh
```
Windows:
```
powershell -c "irm https://insta.rs/install.ps1 | iex"
```
Usual flow is to first run the test, then review them.
```
cargo insta test
cargo insta review
```
## 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:
```
Developer Certificate of Origin
Version 1.1
Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
660 York Street, Suite 102,
San Francisco, CA 94110 USA
Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.
Developer's Certificate of Origin 1.1
By making a contribution to this project, I certify that:
(a) The contribution was created in whole or in part by me and I
have the right to submit it under the open source license
indicated in the file; or
(b) The contribution is based upon previous work that, to the best
of my knowledge, is covered under an appropriate open source
license and I have the right under that license to submit that
work with modifications, whether created in whole or in part
by me, under the same open source license (unless I am
permitted to submit under a different license), as indicated
in the file; or
(c) The contribution was provided directly to me by some other
person who certified (a), (b) or (c) and I have not modified
it.
(d) I understand and agree that this project and the contribution
are public and that a record of the contribution (including all
personal information I submit with it, including my sign-off) is
maintained indefinitely and may be redistributed consistent with
this project or the open source license(s) involved.
```
If you agree to this for your contribution, then all that's needed is to
include the line in your commit or pull request comment:
```
Signed-off-by: Your Name <your@email.example.org>
```
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.
If you forgot to sign off your commits before making your pull request and are
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
+7176
View File
File diff suppressed because it is too large Load Diff
+163 -4
View File
@@ -2,22 +2,181 @@
members = [
"benchmarks",
"bindings/matrix-sdk-crypto-ffi",
"bindings/matrix-sdk-crypto-js",
"bindings/matrix-sdk-crypto-nodejs",
"bindings/matrix-sdk-ffi",
"crates/*",
"testing/*",
"examples/*",
"labs/*",
"uniffi-bindgen",
"xtask",
]
# xtask, labs and the bindings should only be built when invoked explicitly.
default-members = ["benchmarks", "crates/*"]
exclude = [
"testing/data",
]
# xtask, testing and the bindings should only be built when invoked explicitly.
default-members = ["benchmarks", "crates/*", "labs/*"]
resolver = "2"
[workspace.package]
rust-version = "1.83"
[workspace.dependencies]
anyhow = "1.0.95"
aquamarine = "0.6.0"
assert-json-diff = "2.0.2"
assert_matches = "1.5.0"
assert_matches2 = "0.1.2"
async-rx = "0.1.3"
async-stream = "0.3.5"
async-trait = "0.1.85"
as_variant = "1.2.0"
base64 = "0.22.1"
byteorder = "1.5.0"
chrono = "0.4.39"
eyeball = { version = "0.8.8", features = ["tracing"] }
eyeball-im = { version = "0.6.0", features = ["tracing"] }
eyeball-im-util = "0.8.0"
futures-core = "0.3.31"
futures-executor = "0.3.31"
futures-util = "0.3.31"
getrandom = { version = "0.2.15", default-features = false }
gloo-timers = "0.3.0"
growable-bloom-filter = "2.1.1"
hkdf = "0.12.4"
hmac = "0.12.1"
http = "1.2.0"
imbl = "4.0.1"
indexmap = "2.7.1"
insta = { version = "1.42.1", features = ["json"] }
itertools = "0.14.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.16"
proptest = { version = "1.6.0", default-features = false, features = ["std"] }
rand = "0.8.5"
reqwest = { version = "0.12.12", default-features = false }
rmp-serde = "1.3.0"
# Be careful to use commits from the https://github.com/ruma/ruma/tree/ruma-0.12
# branch until a proper release with breaking changes happens.
ruma = { version = "0.12.1", 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 = { version = "0.15.1" }
serde = "1.0.217"
serde_html_form = "0.2.7"
serde_json = "1.0.138"
sha2 = "0.10.8"
similar-asserts = "1.6.1"
stream_assert = "0.1.1"
tempfile = "3.16.0"
thiserror = "2.0.11"
tokio = { version = "1.43.0", default-features = false, features = ["sync"] }
tokio-stream = "0.1.17"
tracing = { version = "0.1.40", default-features = false, features = ["std"] }
tracing-core = "0.1.32"
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.12.1"
vodozemac = { version = "0.9.0", 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.10.0", default-features = false }
matrix-sdk-base = { path = "crates/matrix-sdk-base", version = "0.10.0" }
matrix-sdk-common = { path = "crates/matrix-sdk-common", version = "0.10.0" }
matrix-sdk-crypto = { path = "crates/matrix-sdk-crypto", version = "0.10.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.10.0", default-features = false }
matrix-sdk-qrcode = { path = "crates/matrix-sdk-qrcode", version = "0.10.0" }
matrix-sdk-sqlite = { path = "crates/matrix-sdk-sqlite", version = "0.10.0", default-features = false }
matrix-sdk-store-encryption = { path = "crates/matrix-sdk-store-encryption", version = "0.10.0" }
matrix-sdk-test = { path = "testing/matrix-sdk-test", version = "0.10.0" }
matrix-sdk-ui = { path = "crates/matrix-sdk-ui", version = "0.10.0", default-features = false }
# Default release profile, select with `--release`
[profile.release]
lto = true
# Default development profile; default for most Cargo commands, otherwise
# selected with `--debug`
[profile.dev]
# Saves a lot of disk space. If symbols are needed, use the dbg profile.
debug = 0
[profile.dev.package]
# Optimize quote even in debug mode. Speeds up proc-macros enough to account
# for the extra time of optimizing it for a clean build of matrix-sdk-ffi.
quote = { opt-level = 2 }
sha2 = { opt-level = 2 }
# faster runs for insta.rs snapshot testing
insta.opt-level = 3
similar.opt-level = 3
# Custom profile with full debugging info, use `--profile dbg` to select
[profile.dbg]
inherits = "dev"
debug = 2
# Custom profile for use in (debug) builds of the binding crates, use
# `--profile reldbg` to select
[profile.reldbg]
inherits = "dbg"
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"
+3 -9
View File
@@ -1,4 +1,4 @@
![Build Status](https://img.shields.io/github/workflow/status/matrix-org/matrix-rust-sdk/CI?style=flat-square)
![Build Status](https://img.shields.io/github/actions/workflow/status/matrix-org/matrix-rust-sdk/ci.yml?style=flat-square)
[![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)
@@ -24,17 +24,11 @@ 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.60`
## Status
The library is in an alpha state, things that are implemented generally work but
the API will change in breaking ways.
The library is considered production ready and backs multiple client implementations such as Element X [[1]](https://github.com/element-hq/element-x-ios) [[2]](https://github.com/element-hq/element-x-android) and [Fractal](https://gitlab.gnome.org/World/fractal). Client developers should feel confident to build upon it.
If you are interested in using the matrix-sdk now is the time to try it out and
provide feedback.
Development of the SDK has been primarily sponsored by Element though accepts contributions from all.
## Bindings
-43
View File
@@ -1,43 +0,0 @@
# SDK 0.5 - stores and native crypto
The @matrix-org/rust team is happy to present to the wider public version 0.5 of the [`matrix-rust-sdk`][sdk], now available on crates.io for your convenience. This marks an important milestone after over half a year of work since the latest release (0.4) and with many new team members working on it. It comes with many bug fixes, improvements and updates, but a few we'd like to highlight here:
## Better, safer, native-er crypto
One of the biggest improvements under the hood is the replacement of the former crypto core written in C, libolm, with the fully rustic, fully audited [Vodozemac][vodozemac]. [Vodozemac][vodozemac] is a much more robust new implementation of the olm crypto primitives and engines with all the learning included and pitfalls from the previous C implementation avoided in a freshly baked, very robust library. With this release both matrix-sdk-crypto and matrix-sdk (when the `e2e-encryption` is enabled, which it is by default) use vodozemac to handle all crypto needs.
## Stores, stores, stores
This release has also seen a major refactoring around the state and crypto store primitives and implementations. From this release forward, the implementation of the storage layer is truly modular and pluggable, with the default implementation (based on `sled`) even being a separate crate. Furthermore this release has also additional support for the [`indexeddb`-storage][indexeddb] layer for in-browser WASM needs. As before, the base still ships with an in-memory store, but if none of them fits your needs, you are very much invited to build your own - we recommend looking at the implementation of the existing [`matrix-sdk-sled`][sled] to understand what is needed.
We've further extended and cleaned up the storage API and hardened the two existing implementations: both `sled` and `indexeddb` will now encrypt _all metadata_, including all keys, if a passphrase is given. Even a core dump of a database won't show any strings or other identifiable data. Both implementation also hold a database version string now, allowing future migrations of the database schema while we move forward.
## WebAssembly
It already came through in the previous paragraph: we now fully support `wasm` as a primary target for the main sdk and its dependencies (browser for now). While it was already possible to build the SDK for wasm before, if you were lucky and had the specific emscripten setup, even crypto didn't always fail to compile, our move to vodozemac frees us from these problems and our CI now makes sure all our PRs will continue to build on WebAssembly, too. And with the `indexeddb`-store, we also have a fully persistent storage layer implementation for all your in-browser matrix needs built in.
## More features
Of course a lot more has happened over the last few months as we've ramped up our work on the SDK. Most notably, you can now check whether a room has been created as a `space`, and we offer nice automatic thumbnailing and resizing support if you enable `image`. Additionally, there is a very early event-timeline API behind the `experimental-timeline`-feature-flag. Just to name a few. We really recommend you migrate from the older version to this one.
## Process and Workflow
We've also ramped up our CI, parallelized it a lot, while adding more tests. In general we don't merge anything breaking the tests, thus our `main` can also be considered `stable` to build again, though things might be changed without prior notice. We recommend keeping an eye out in our [team chat][chat] to stay current.
### Versions
This and all future releases of matrix-sdk adhere to [semver][semver] and we do our best to stick to it for the default-feature-set. As you will see only the main crate `matrix-sdk` is actually versioned at `0.5`, while other crates - especially newer ones - have different versions attached. We recommend to sticking to the high-level matrix-sdk-crate wherever reasonable as lower level crates might change more often, also in breaking fashion.
With this release all our crates are build with `rust v2021` and need a rust compiler of at least `1.60` (due to our need for weak-dependencies).
### Conventional Commit
We also want to make it easier for external parties to follow changes and stay up to date with what's-what, so, with this release, we are implementing the [conventional commits][cc] standard for our commits and will start putting in automatic changelog generation. Which makes it easier for us to create comprehensive changelogs for releases, but also for anyone following `main` to figure out what changed.
[sdk]: https://crates.io/crates/matrix-sdk/
[vodozemac]: https://github.com/matrix-org/vodozemac
[sled]: https://crates.io/crates/matrix-sdk-sled/
[indexeddb]: https://crates.io/crates/matrix-sdk-indexeddb/
[chat]: https://matrix.to/#/#matrix-rust-sdk:matrix.org
[semver]: https://semver.org/
[cc]: http://conventionalcommits.org/
+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
+25 -9
View File
@@ -3,23 +3,39 @@ name = "benchmarks"
description = "Matrix SDK benchmarks"
edition = "2021"
license = "Apache-2.0"
rust-version = "1.56"
rust-version = { workspace = true }
version = "1.0.0"
publish = false
[dependencies]
criterion = { version = "0.3.5", features = ["async", "async_tokio", "html_reports"] }
matrix-sdk-crypto = { path = "../crates/matrix-sdk-crypto", version = "0.5.0" }
matrix-sdk-sled = { path = "../crates/matrix-sdk-sled", version = "0.1.0", default-features = false, features = ["crypto-store"] }
matrix-sdk-test = { path = "../crates/matrix-sdk-test", version = "0.5.0" }
ruma = { git = "https://github.com/ruma/ruma", rev = "96155915f" }
serde_json = "1.0.79"
criterion = { version = "0.5.1", features = ["async", "async_tokio", "html_reports"] }
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-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.17.0", 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.8.0", features = ["flamegraph", "criterion"] }
pprof = { version = "0.14.0", features = ["flamegraph", "criterion"] }
[[bench]]
name = "crypto_bench"
harness = false
[[bench]]
name = "store_bench"
harness = false
[[bench]]
name = "room_bench"
harness = false
[package.metadata.release]
release = false
+72 -44
View File
@@ -1,16 +1,13 @@
use std::{ops::Deref, sync::Arc};
use criterion::*;
use criterion::{criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion, Throughput};
use matrix_sdk_crypto::{EncryptionSettings, OlmMachine};
use matrix_sdk_sled::CryptoStore as SledCryptoStore;
use matrix_sdk_test::response_from_file;
use matrix_sdk_sqlite::SqliteCryptoStore;
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) {
@@ -63,23 +54,33 @@ pub fn keys_query(c: &mut Criterion) {
let mut group = c.benchmark_group("Keys querying");
group.throughput(Throughput::Elements(count as u64));
let name = format!("{} device and cross signing keys", count);
let name = format!("{count} device and cross signing keys");
// Benchmark memory store.
group.bench_with_input(BenchmarkId::new("memory store", &name), &response, |b, response| {
b.to_async(&runtime)
.iter(|| async { machine.mark_request_as_sent(&txn_id, response).await.unwrap() })
});
let dir = tempfile::tempdir().unwrap();
let store = Arc::new(SledCryptoStore::open_with_passphrase(dir.path(), None).unwrap());
let machine =
runtime.block_on(OlmMachine::with_store(alice_id(), alice_device_id(), store)).unwrap();
// Benchmark sqlite store.
group.bench_with_input(BenchmarkId::new("sled store", &name), &response, |b, response| {
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, None))
.unwrap();
group.bench_with_input(BenchmarkId::new("sqlite store", &name), &response, |b, response| {
b.to_async(&runtime)
.iter(|| async { machine.mark_request_as_sent(&txn_id, response).await.unwrap() })
});
{
let _guard = runtime.enter();
drop(machine);
}
group.finish()
}
@@ -96,7 +97,7 @@ pub fn keys_claiming(c: &mut Criterion) {
let mut group = c.benchmark_group("Olm session creation");
group.throughput(Throughput::Elements(count as u64));
let name = format!("{} one-time keys", count);
let name = format!("{count} one-time keys");
group.bench_with_input(BenchmarkId::new("memory store", &name), &response, |b, response| {
b.iter_batched(
@@ -108,21 +109,24 @@ pub fn keys_claiming(c: &mut Criterion) {
(machine, &runtime, &txn_id)
},
move |(machine, runtime, txn_id)| {
runtime.block_on(machine.mark_request_as_sent(txn_id, response)).unwrap()
runtime.block_on(async {
machine.mark_request_as_sent(txn_id, response).await.unwrap();
drop(machine);
})
},
BatchSize::SmallInput,
)
});
group.bench_with_input(BenchmarkId::new("sled store", &name), &response, |b, response| {
group.bench_with_input(BenchmarkId::new("sqlite store", &name), &response, |b, response| {
b.iter_batched(
|| {
let dir = tempfile::tempdir().unwrap();
let store =
Arc::new(SledCryptoStore::open_with_passphrase(dir.path(), None).unwrap());
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))
@@ -130,7 +134,10 @@ pub fn keys_claiming(c: &mut Criterion) {
(machine, &runtime, &txn_id)
},
move |(machine, runtime, txn_id)| {
runtime.block_on(machine.mark_request_as_sent(txn_id, response)).unwrap()
runtime.block_on(async {
machine.mark_request_as_sent(txn_id, response).await.unwrap();
drop(machine)
})
},
BatchSize::SmallInput,
)
@@ -158,7 +165,9 @@ pub fn room_key_sharing(c: &mut Criterion) {
let mut group = c.benchmark_group("Room key sharing");
group.throughput(Throughput::Elements(count as u64));
let name = format!("{} devices", count);
let name = format!("{count} devices");
// Benchmark memory store.
group.bench_function(BenchmarkId::new("memory store", &name), |b| {
b.to_async(&runtime).iter(|| async {
@@ -177,18 +186,22 @@ 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();
})
});
let dir = tempfile::tempdir().unwrap();
let store = Arc::new(SledCryptoStore::open_with_passphrase(dir.path(), None).unwrap());
let machine =
runtime.block_on(OlmMachine::with_store(alice_id(), alice_device_id(), store)).unwrap();
// Benchmark sqlite store.
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, 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();
group.bench_function(BenchmarkId::new("sled store", &name), |b| {
group.bench_function(BenchmarkId::new("sqlite store", &name), |b| {
b.to_async(&runtime).iter(|| async {
let requests = machine
.share_room_key(
@@ -205,10 +218,15 @@ 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();
})
});
{
let _guard = runtime.enter();
drop(machine);
}
group.finish()
}
@@ -225,30 +243,40 @@ pub fn devices_missing_sessions_collecting(c: &mut Criterion) {
let mut group = c.benchmark_group("Devices missing sessions collecting");
group.throughput(Throughput::Elements(count as u64));
let name = format!("{} devices", count);
let name = format!("{count} devices");
runtime.block_on(machine.mark_request_as_sent(&txn_id, &response)).unwrap();
// Benchmark memory store.
group.bench_function(BenchmarkId::new("memory store", &name), |b| {
b.to_async(&runtime).iter_with_large_drop(|| async {
machine.get_missing_sessions(users.iter().map(Deref::deref)).await.unwrap()
})
});
let dir = tempfile::tempdir().unwrap();
let store = Arc::new(SledCryptoStore::open_with_passphrase(dir.path(), None).unwrap());
// Benchmark sqlite store.
let machine =
runtime.block_on(OlmMachine::with_store(alice_id(), alice_device_id(), store)).unwrap();
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, None))
.unwrap();
runtime.block_on(machine.mark_request_as_sent(&txn_id, &response)).unwrap();
group.bench_function(BenchmarkId::new("sled store", &name), |b| {
group.bench_function(BenchmarkId::new("sqlite store", &name), |b| {
b.to_async(&runtime).iter(|| async {
machine.get_missing_sessions(users.iter().map(Deref::deref)).await.unwrap()
})
});
{
let _guard = runtime.enter();
drop(machine);
}
group.finish()
}
+250
View File
@@ -0,0 +1,250 @@
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};
use matrix_sdk_base::{
store::StoreConfig, BaseClient, RoomInfo, RoomState, SessionMeta, StateChanges, StateStore,
};
use matrix_sdk_sqlite::SqliteStateStore;
use matrix_sdk_test::{
event_factory::EventFactory, JoinedRoomBuilder, StateTestEvent, SyncResponseBuilder,
};
use matrix_sdk_ui::{timeline::TimelineFocus, Timeline};
use ruma::{
api::client::membership::get_member_events,
device_id,
events::room::member::{MembershipState, RoomMemberEvent},
mxc_uri, 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 f = EventFactory::new().room(&room_id);
let mut member_events: Vec<Raw<RoomMemberEvent>> = Vec::with_capacity(MEMBERS_IN_ROOM);
for i in 0..MEMBERS_IN_ROOM {
let user_id = OwnedUserId::try_from(format!("@user_{}:matrix.org", i)).unwrap();
let event = f
.member(&user_id)
.membership(MembershipState::Join)
.avatar_url(mxc_uri!("mxc://example.org/SEsfnsuifSDFSSEF"))
.display_name("Alice Margatroid")
.reason("Looking for support")
.into_raw();
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);
+131
View File
@@ -0,0 +1,131 @@
use std::sync::Arc;
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
use matrix_sdk::{
authentication::matrix::{MatrixSession, MatrixSessionTokens},
config::StoreConfig,
Client, RoomInfo, RoomState, StateChanges,
};
use matrix_sdk_base::{store::MemoryStore, SessionMeta, StateStore as _};
use matrix_sdk_sqlite::SqliteStateStore;
use ruma::{device_id, user_id, RoomId};
use tokio::runtime::Builder;
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
}
/// Number of joined rooms in the benchmark.
const NUM_JOINED_ROOMS: usize = 10000;
/// Number of stripped rooms in the benchmark.
const NUM_STRIPPED_JOINED_ROOMS: usize = 10000;
pub fn restore_session(c: &mut Criterion) {
let runtime = Builder::new_multi_thread().build().expect("Can't create runtime");
// Create a fake list of changes, and a session to recover from.
let mut changes = StateChanges::default();
for i in 0..NUM_JOINED_ROOMS {
let room_id = RoomId::parse(format!("!room{i}:example.com")).unwrap().to_owned();
changes.add_room(RoomInfo::new(&room_id, RoomState::Joined));
}
for i in 0..NUM_STRIPPED_JOINED_ROOMS {
let room_id = RoomId::parse(format!("!strippedroom{i}:example.com")).unwrap().to_owned();
changes.add_room(RoomInfo::new(&room_id, RoomState::Invited));
}
let session = MatrixSession {
meta: SessionMeta {
user_id: user_id!("@somebody:example.com").to_owned(),
device_id: device_id!("DEVICE_ID").to_owned(),
},
tokens: MatrixSessionTokens { access_token: "OHEY".to_owned(), refresh_token: None },
};
// Start the benchmark.
let mut group = c.benchmark_group("Client reload");
group.throughput(Throughput::Elements(100));
const NAME: &str = "restore a session";
// Memory
let mem_store = Arc::new(MemoryStore::new());
runtime.block_on(mem_store.save_changes(&changes)).expect("initial filling of mem failed");
group.bench_with_input(BenchmarkId::new("memory store", NAME), &mem_store, |b, store| {
b.to_async(&runtime).iter(|| async {
let client = Client::builder()
.homeserver_url("https://matrix.example.com")
.store_config(
StoreConfig::new("cross-process-store-locks-holder-name".to_owned())
.state_store(store.clone()),
)
.build()
.await
.expect("Can't build client");
client.restore_session(session.clone()).await.expect("couldn't restore session");
})
});
for encryption_password in [None, Some("hunter2")] {
let encrypted_suffix = if encryption_password.is_some() { "encrypted" } else { "clear" };
// Sqlite
let sqlite_dir = tempfile::tempdir().unwrap();
let sqlite_store = runtime
.block_on(SqliteStateStore::open(sqlite_dir.path(), encryption_password))
.unwrap();
runtime
.block_on(sqlite_store.save_changes(&changes))
.expect("initial filling of sqlite failed");
group.bench_with_input(
BenchmarkId::new(format!("sqlite store {encrypted_suffix}"), NAME),
&sqlite_store,
|b, store| {
b.to_async(&runtime).iter(|| async {
let client = Client::builder()
.homeserver_url("https://matrix.example.com")
.store_config(
StoreConfig::new("cross-process-store-locks-holder-name".to_owned())
.state_store(store.clone()),
)
.build()
.await
.expect("Can't build client");
client
.restore_session(session.clone())
.await
.expect("couldn't restore session");
})
},
);
{
let _guard = runtime.enter();
drop(sqlite_store);
}
}
group.finish()
}
criterion_group! {
name = benches;
config = criterion();
targets = restore_session
}
criterion_main!(benches);
+41
View File
@@ -0,0 +1,41 @@
## Introduction
**matrix-rust-sdk** leverages [UniFFI](https://mozilla.github.io/uniffi-rs/) to generate bindings for host languages (eg. Swift and Kotlin).
Rust code related with bindings live in the [matrix-rust-sdk/bindings](https://github.com/matrix-org/matrix-rust-sdk/tree/main/bindings) folder.
Developers can expose Rust code to UniFFI using two different approaches:
- Using an `.udl` file. When a crate has one, you find it under the `src` folder (an example is [here](https://github.com/matrix-org/matrix-rust-sdk/blob/main/bindings/matrix-sdk-ffi/src/api.udl)).
- Add UniFFI directivies as Rust attributes. In this case Rust source files (`.rs`) contain attributes related to UniFFI (e.g. `#[uniffi::export]`). Attributes are preferred, where applicable.
## Expose Rust definitions to UniFFI
### Check if the API is already on UniFFI
First of all check if the Rust definition you are looking for exists on UniFFI already. Most of exposed matrix definitions are collected in the crate [matrix-sdk-ffi](https://github.com/matrix-org/matrix-rust-sdk/tree/main/bindings/matrix-sdk-ffi).
This crate contains mainly small Rust wrappers around the actual Rust SDK (e.g. the crate [matrix-sdk](https://github.com/matrix-org/matrix-rust-sdk/tree/main/crates/matrix-sdk))
If the Rust definition is on UniFFI already, you either:
- find it in a `.udl` file like [matrix-sdk-ffi/src/api.udl](https://github.com/matrix-org/matrix-rust-sdk/blob/main/bindings/matrix-sdk-ffi/src/api.udl)
- see it marked with a proper UniFFI Rust attribute like this `#[uniffi::export]`
### Adding a missing matrix API
1. Unless you want to contribute on the crypto side, you probably need to add some code in the [matrix-sdk-ffi](https://github.com/matrix-org/matrix-rust-sdk/tree/main/bindings/matrix-sdk-ffi) crate. After you find the crate you need to understand which file is best to contain the new Rust definition. When exposing new matrix API often (but not always) you need to touch the file [client.rs](https://github.com/matrix-org/matrix-rust-sdk/blob/main/bindings/matrix-sdk-ffi/src/client.rs)
2. Identify the API to expose in the target Rust crate (typically in [matrix-sdk](https://github.com/matrix-org/matrix-rust-sdk/tree/main/crates/matrix-sdk). If you cant find it, you probably need to touch the actual Rust SDK as well. In this case you typically just need to write some code around [ruma](https://github.com/ruma/ruma) (a Rust SDKs dependency) which already implements most of the matrix protocol
3. After you got (by finding or writing) the required Rust code, you need to expose to UniFFI. To do that just write a small Rust wrapper in the related UniFFI crate (most of the time is **matrix-sdk-ffi**) you found on step 1.
4. When your new (wrapping) Rust definition is ready, remember to expose it to UniFFI.
Its best to do it using UniFFI Rust attributes (e.g. `#[uniffi::export]`). Otherwise add the new definition in the crates `.udl` file. For the **matrix-sdk-ffi** crate the definition file is [api.udl](https://github.com/matrix-org/matrix-rust-sdk/blob/main/bindings/matrix-sdk-ffi/src/api.udl). **Remember**: the language inside a `.udl` file isnt Rust. To learn more about how map Rust into UDL read [here](https://mozilla.github.io/uniffi-rs/udl_file_spec.html)
## FAQ
**Q**: I wrote my Rust code and exposed it to UniFFI. How can I check if the compiler is happy?\
**A**: Run `cargo build` in the crate you touched (e.g. matrix-sdk-ffi). The compiler will complain if the Rust code and/or the `.udl` is wrong.
**Q**: The compiler is happy with my code but the CI is failing on GitHub. How can I fix it?\
**A**: The CI may fail for different reasons, you need to have a look on the failing GitHub workflow. One common reason though is that the linter ([Clippy](https://github.com/rust-lang/rust-clippy)) isnt happy with your code. If this is the case, you can run `cargo clippy` in the crate you touched to see whats wrong and fix it accordingly.
+14 -6
View File
@@ -5,18 +5,26 @@ maintained by the owners of the Matrix Rust SDK project.
* [`apple`] or `matrix-rust-components-swift`, Swift bindings of the
[`matrix-sdk`] crate via [`matrix-sdk-ffi`],
* [`matrix-sdk-crypto-ffi`], bindings of the [`matrix-sdk-crypto`]
* [`matrix-sdk-crypto-ffi`], UniFFI (Kotlin, Swift, Python, Ruby) bindings of the [`matrix-sdk-crypto`]
crate,
* [`matrix-sdk-crypto-js`], JavaScript bindings of the
* [`matrix-sdk-ffi`], UniFFI bindings of the [`matrix-sdk`] crate.
There are also external bindings in other repositories:
* [`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,
* [`matrix-sdk-ffi`], bindings of the [`matrix-sdk`] crate,
[`matrix-sdk-crypto`] crate
[`apple`]: ./apple
[`matrix-sdk-crypto-ffi`]: ./matrix-sdk-crypto-ffi
[`matrix-sdk-crypto-js`]: ../crates/matrix-sdk-crypto
[`matrix-sdk-crypto-nodejs`]: ../crates/matrix-sdk-crypto
[`matrix-sdk-crypto`]: ../crates/matrix-sdk-crypto
[`matrix-sdk-ffi`]: ./matrix-sdk-ffi
[`matrix-sdk`]: ../crates/matrix-sdk
[`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
To contribute read this [guide](./CONTRIBUTING.md).
+8
View File
@@ -0,0 +1,8 @@
// swift-tools-version:5.6
// A package manifest for local development. This file will be copied
// into the root of the repo when generating an XCFramework.
import PackageDescription
let package = Package()
+25
View File
@@ -0,0 +1,25 @@
// swift-tools-version:5.6
// A package manifest for local development. This file will be copied
// into the root of the repo when generating an XCFramework.
import PackageDescription
let package = Package(
name: "MatrixRustSDK",
platforms: [
.iOS(.v15),
.macOS(.v12)
],
products: [
.library(name: "MatrixRustSDK",
type: .dynamic,
targets: ["MatrixRustSDK"]),
],
targets: [
.binaryTarget(name: "MatrixSDKFFI", path: "bindings/apple/generated/MatrixSDKFFI.xcframework"),
.target(name: "MatrixRustSDK",
dependencies: [.target(name: "MatrixSDKFFI")],
path: "bindings/apple/generated/swift")
]
)
@@ -1,513 +0,0 @@
// !$*UTF8*$!
{
archiveVersion = 1;
classes = {
};
objectVersion = 55;
objects = {
/* Begin PBXBuildFile section */
181AA19B27B52AB40005F102 /* MatrixSDKFFI.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 181AA19A27B52AB40005F102 /* MatrixSDKFFI.xcframework */; };
181AA19C27B52AB40005F102 /* MatrixSDKFFI.xcframework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 181AA19A27B52AB40005F102 /* MatrixSDKFFI.xcframework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
189A89BA27B40BBF0048B0A5 /* sdk.swift in Sources */ = {isa = PBXBuildFile; fileRef = 189A89B927B40BBF0048B0A5 /* sdk.swift */; };
18CE89D827B2939900CA89E1 /* MatrixRustSDKApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 18CE89D727B2939900CA89E1 /* MatrixRustSDKApp.swift */; };
18CE89DA27B2939900CA89E1 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 18CE89D927B2939900CA89E1 /* ContentView.swift */; };
18CE89DC27B2939A00CA89E1 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 18CE89DB27B2939A00CA89E1 /* Assets.xcassets */; };
18CE89E927B2939A00CA89E1 /* MatrixRustSDKTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 18CE89E827B2939A00CA89E1 /* MatrixRustSDKTests.swift */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
18CE89E527B2939A00CA89E1 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 18CE89CC27B2939900CA89E1 /* Project object */;
proxyType = 1;
remoteGlobalIDString = 18CE89D327B2939900CA89E1;
remoteInfo = MatrixRustSDK;
};
/* End PBXContainerItemProxy section */
/* Begin PBXCopyFilesBuildPhase section */
18CE8A1F27B2941600CA89E1 /* Embed Frameworks */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 10;
files = (
181AA19C27B52AB40005F102 /* MatrixSDKFFI.xcframework in Embed Frameworks */,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
181AA19927B52AA60005F102 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
181AA19A27B52AB40005F102 /* MatrixSDKFFI.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = MatrixSDKFFI.xcframework; path = ../../generated/MatrixSDKFFI.xcframework; sourceTree = "<group>"; };
189A89B927B40BBF0048B0A5 /* sdk.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = sdk.swift; path = ../../../generated/swift/sdk.swift; sourceTree = "<group>"; };
189A89C327B417CA0048B0A5 /* MatrixRustSDK-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "MatrixRustSDK-Bridging-Header.h"; sourceTree = "<group>"; };
18CE89D427B2939900CA89E1 /* MatrixRustSDK.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MatrixRustSDK.app; sourceTree = BUILT_PRODUCTS_DIR; };
18CE89D727B2939900CA89E1 /* MatrixRustSDKApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MatrixRustSDKApp.swift; sourceTree = "<group>"; };
18CE89D927B2939900CA89E1 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
18CE89DB27B2939A00CA89E1 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
18CE89E427B2939A00CA89E1 /* MatrixRustSDKTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = MatrixRustSDKTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
18CE89E827B2939A00CA89E1 /* MatrixRustSDKTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MatrixRustSDKTests.swift; sourceTree = "<group>"; };
18CE8A0127B293A900CA89E1 /* MatrixRustSDK.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = MatrixRustSDK.entitlements; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
18CE89D127B2939900CA89E1 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
181AA19B27B52AB40005F102 /* MatrixSDKFFI.xcframework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
18CE89E127B2939A00CA89E1 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
189A89AB27B2E16B0048B0A5 /* Frameworks */ = {
isa = PBXGroup;
children = (
181AA19A27B52AB40005F102 /* MatrixSDKFFI.xcframework */,
);
name = Frameworks;
sourceTree = "<group>";
};
189A89B827B40BB10048B0A5 /* Generated */ = {
isa = PBXGroup;
children = (
189A89B927B40BBF0048B0A5 /* sdk.swift */,
);
name = Generated;
sourceTree = "<group>";
};
18CE89CB27B2939900CA89E1 = {
isa = PBXGroup;
children = (
18CE89D627B2939900CA89E1 /* MatrixRustSDK */,
18CE89E727B2939A00CA89E1 /* MatrixRustSDKTests */,
18CE89D527B2939900CA89E1 /* Products */,
189A89AB27B2E16B0048B0A5 /* Frameworks */,
);
sourceTree = "<group>";
};
18CE89D527B2939900CA89E1 /* Products */ = {
isa = PBXGroup;
children = (
18CE89D427B2939900CA89E1 /* MatrixRustSDK.app */,
18CE89E427B2939A00CA89E1 /* MatrixRustSDKTests.xctest */,
);
name = Products;
sourceTree = "<group>";
};
18CE89D627B2939900CA89E1 /* MatrixRustSDK */ = {
isa = PBXGroup;
children = (
181AA19927B52AA60005F102 /* Info.plist */,
189A89B827B40BB10048B0A5 /* Generated */,
18CE89D727B2939900CA89E1 /* MatrixRustSDKApp.swift */,
18CE89D927B2939900CA89E1 /* ContentView.swift */,
18CE8A0127B293A900CA89E1 /* MatrixRustSDK.entitlements */,
18CE89DB27B2939A00CA89E1 /* Assets.xcassets */,
189A89C327B417CA0048B0A5 /* MatrixRustSDK-Bridging-Header.h */,
);
path = MatrixRustSDK;
sourceTree = "<group>";
};
18CE89E727B2939A00CA89E1 /* MatrixRustSDKTests */ = {
isa = PBXGroup;
children = (
18CE89E827B2939A00CA89E1 /* MatrixRustSDKTests.swift */,
);
path = MatrixRustSDKTests;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
18CE89D327B2939900CA89E1 /* MatrixRustSDK */ = {
isa = PBXNativeTarget;
buildConfigurationList = 18CE89F827B2939A00CA89E1 /* Build configuration list for PBXNativeTarget "MatrixRustSDK" */;
buildPhases = (
18CE89D027B2939900CA89E1 /* Sources */,
18CE89D127B2939900CA89E1 /* Frameworks */,
18CE89D227B2939900CA89E1 /* Resources */,
18CE8A1F27B2941600CA89E1 /* Embed Frameworks */,
);
buildRules = (
);
dependencies = (
);
name = MatrixRustSDK;
productName = MatrixRustSDK;
productReference = 18CE89D427B2939900CA89E1 /* MatrixRustSDK.app */;
productType = "com.apple.product-type.application";
};
18CE89E327B2939A00CA89E1 /* MatrixRustSDKTests */ = {
isa = PBXNativeTarget;
buildConfigurationList = 18CE89FB27B2939A00CA89E1 /* Build configuration list for PBXNativeTarget "MatrixRustSDKTests" */;
buildPhases = (
18CE89E027B2939A00CA89E1 /* Sources */,
18CE89E127B2939A00CA89E1 /* Frameworks */,
18CE89E227B2939A00CA89E1 /* Resources */,
);
buildRules = (
);
dependencies = (
18CE89E627B2939A00CA89E1 /* PBXTargetDependency */,
);
name = MatrixRustSDKTests;
productName = MatrixRustSDKTests;
productReference = 18CE89E427B2939A00CA89E1 /* MatrixRustSDKTests.xctest */;
productType = "com.apple.product-type.bundle.unit-test";
};
/* End PBXNativeTarget section */
/* Begin PBXProject section */
18CE89CC27B2939900CA89E1 /* Project object */ = {
isa = PBXProject;
attributes = {
BuildIndependentTargetsInParallel = 1;
LastSwiftUpdateCheck = 1320;
LastUpgradeCheck = 1320;
TargetAttributes = {
18CE89D327B2939900CA89E1 = {
CreatedOnToolsVersion = 13.2.1;
LastSwiftMigration = 1320;
};
18CE89E327B2939A00CA89E1 = {
CreatedOnToolsVersion = 13.2.1;
TestTargetID = 18CE89D327B2939900CA89E1;
};
};
};
buildConfigurationList = 18CE89CF27B2939900CA89E1 /* Build configuration list for PBXProject "MatrixRustSDK" */;
compatibilityVersion = "Xcode 13.0";
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
en,
Base,
);
mainGroup = 18CE89CB27B2939900CA89E1;
productRefGroup = 18CE89D527B2939900CA89E1 /* Products */;
projectDirPath = "";
projectRoot = "";
targets = (
18CE89D327B2939900CA89E1 /* MatrixRustSDK */,
18CE89E327B2939A00CA89E1 /* MatrixRustSDKTests */,
);
};
/* End PBXProject section */
/* Begin PBXResourcesBuildPhase section */
18CE89D227B2939900CA89E1 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
18CE89DC27B2939A00CA89E1 /* Assets.xcassets in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
18CE89E227B2939A00CA89E1 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXResourcesBuildPhase section */
/* Begin PBXSourcesBuildPhase section */
18CE89D027B2939900CA89E1 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
18CE89DA27B2939900CA89E1 /* ContentView.swift in Sources */,
189A89BA27B40BBF0048B0A5 /* sdk.swift in Sources */,
18CE89D827B2939900CA89E1 /* MatrixRustSDKApp.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
18CE89E027B2939A00CA89E1 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
18CE89E927B2939A00CA89E1 /* MatrixRustSDKTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
/* Begin PBXTargetDependency section */
18CE89E627B2939A00CA89E1 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = 18CE89D327B2939900CA89E1 /* MatrixRustSDK */;
targetProxy = 18CE89E527B2939A00CA89E1 /* PBXContainerItemProxy */;
};
/* End PBXTargetDependency section */
/* Begin XCBuildConfiguration section */
18CE89F627B2939A00CA89E1 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++17";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 15.2;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
};
name = Debug;
};
18CE89F727B2939A00CA89E1 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++17";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 15.2;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
SDKROOT = iphoneos;
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_OPTIMIZATION_LEVEL = "-O";
VALIDATE_PRODUCT = YES;
};
name = Release;
};
18CE89F927B2939A00CA89E1 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = MatrixRustSDK/MatrixRustSDK.entitlements;
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "-";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = MatrixRustSDK/Info.plist;
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = org.matrix.MatrixRustSDK;
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTS_MACCATALYST = YES;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_OBJC_BRIDGING_HEADER = "MatrixRustSDK/MatrixRustSDK-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
};
18CE89FA27B2939A00CA89E1 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = MatrixRustSDK/MatrixRustSDK.entitlements;
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "-";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = MatrixRustSDK/Info.plist;
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = org.matrix.MatrixRustSDK;
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTS_MACCATALYST = YES;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_OBJC_BRIDGING_HEADER = "MatrixRustSDK/MatrixRustSDK-Bridging-Header.h";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
};
18CE89FC27B2939A00CA89E1 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
BUNDLE_LOADER = "$(TEST_HOST)";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
GENERATE_INFOPLIST_FILE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 15.2;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = org.matrix.MatrixRustSDKTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = NO;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/MatrixRustSDK.app/MatrixRustSDK";
};
name = Debug;
};
18CE89FD27B2939A00CA89E1 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
BUNDLE_LOADER = "$(TEST_HOST)";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
GENERATE_INFOPLIST_FILE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 15.2;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = org.matrix.MatrixRustSDKTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = NO;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/MatrixRustSDK.app/MatrixRustSDK";
};
name = Release;
};
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
18CE89CF27B2939900CA89E1 /* Build configuration list for PBXProject "MatrixRustSDK" */ = {
isa = XCConfigurationList;
buildConfigurations = (
18CE89F627B2939A00CA89E1 /* Debug */,
18CE89F727B2939A00CA89E1 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
18CE89F827B2939A00CA89E1 /* Build configuration list for PBXNativeTarget "MatrixRustSDK" */ = {
isa = XCConfigurationList;
buildConfigurations = (
18CE89F927B2939A00CA89E1 /* Debug */,
18CE89FA27B2939A00CA89E1 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
18CE89FB27B2939A00CA89E1 /* Build configuration list for PBXNativeTarget "MatrixRustSDKTests" */ = {
isa = XCConfigurationList;
buildConfigurations = (
18CE89FC27B2939A00CA89E1 /* Debug */,
18CE89FD27B2939A00CA89E1 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
rootObject = 18CE89CC27B2939900CA89E1 /* Project object */;
}
@@ -1,7 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "self:">
</FileRef>
</Workspace>
@@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
@@ -1,98 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1320"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "18CE89D327B2939900CA89E1"
BuildableName = "MatrixRustSDK.app"
BlueprintName = "MatrixRustSDK"
ReferencedContainer = "container:MatrixRustSDK.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "18CE89E327B2939A00CA89E1"
BuildableName = "MatrixRustSDKTests.xctest"
BlueprintName = "MatrixRustSDKTests"
ReferencedContainer = "container:MatrixRustSDK.xcodeproj">
</BuildableReference>
</TestableReference>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "18CE89ED27B2939A00CA89E1"
BuildableName = "MatrixRustSDKUITests.xctest"
BlueprintName = "MatrixRustSDKUITests"
ReferencedContainer = "container:MatrixRustSDK.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "18CE89D327B2939900CA89E1"
BuildableName = "MatrixRustSDK.app"
BlueprintName = "MatrixRustSDK"
ReferencedContainer = "container:MatrixRustSDK.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "18CE89D327B2939900CA89E1"
BuildableName = "MatrixRustSDK.app"
BlueprintName = "MatrixRustSDK"
ReferencedContainer = "container:MatrixRustSDK.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
@@ -1,11 +0,0 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
@@ -1,98 +0,0 @@
{
"images" : [
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "20x20"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "20x20"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "29x29"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "29x29"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "40x40"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "40x40"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "60x60"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "60x60"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "20x20"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "20x20"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "29x29"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "29x29"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "40x40"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "40x40"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "76x76"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "76x76"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "83.5x83.5"
},
{
"idiom" : "ios-marketing",
"scale" : "1x",
"size" : "1024x1024"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
@@ -1,6 +0,0 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
@@ -1,21 +0,0 @@
//
// ContentView.swift
// MatrixRustSDK
//
// Created by Stefan Ceriu on 08.02.2022.
//
import SwiftUI
struct ContentView: View {
var body: some View {
Text("Hello, Rust!")
.padding()
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
-5
View File
@@ -1,5 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict/>
</plist>
@@ -1,5 +0,0 @@
//
// Use this file to import your target's public headers that you would like to expose to Swift.
//
#import "sdkFFI.h"
@@ -1,10 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.network.client</key>
<true/>
</dict>
</plist>
@@ -1,17 +0,0 @@
//
// MatrixRustSDKApp.swift
// MatrixRustSDK
//
// Created by Stefan Ceriu on 08.02.2022.
//
import SwiftUI
@main
struct MatrixRustSDKApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
@@ -1,39 +0,0 @@
//
// MatrixRustSDKTests.swift
// MatrixRustSDKTests
//
// Created by Stefan Ceriu on 08.02.2022.
//
import XCTest
@testable import MatrixRustSDK
class MatrixRustSDKTests: XCTestCase {
func testReadOnlyFileSystemError() {
do {
let client = try ClientBuilder()
.basePath(path: "")
.username(username: "@test:domain")
.build()
try client.login(username: "@test:domain", password: "test")
} catch ClientError.Generic(let message) {
XCTAssertNotNil(message.range(of: "Read-only file system"))
} catch {
XCTFail("Not expecting any other kind of exception")
}
}
// MARK: - Private
static private var basePath: String {
guard let url = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first else {
fatalError("Should always be able to retrieve the caches directory")
}
try? FileManager.default.createDirectory(at: url, withIntermediateDirectories: false, attributes: nil)
return url.path
}
}
@@ -0,0 +1,21 @@
# Podspec file for local-development only, which points to local version of generated framework instead of github release
# To use this, the file needs to be copied to the root of `matrix-rust-sdk` in order to have access to the source files.`
Pod::Spec.new do |s|
s.name = "MatrixSDKCrypto"
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 = "13.0"
s.osx.deployment_target = "10.15"
s.swift_versions = ['5.1', '5.2']
s.source = { :git => "Not Published", :tag => "Cocoapods/#{s.name}/#{s.version}" }
s.vendored_frameworks = "generated/MatrixSDKCryptoFFI.xcframework"
s.source_files = "generated/Sources/**/*.{swift}"
s.resources = ["bindings/matrix-sdk-crypto-ffi/src/**/*.rs", "crates/matrix-sdk-crypto/src/**/*.rs"]
end
+5 -3
View File
@@ -1,14 +1,16 @@
Pod::Spec.new do |s|
s.name = "MatrixSDKCrypto"
s.version = "0.1.0"
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.swift_versions = ['5.0']
s.ios.deployment_target = "13.0"
s.osx.deployment_target = "10.15"
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"
+33
View File
@@ -0,0 +1,33 @@
// swift-tools-version: 5.6
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "MatrixRustSDK",
platforms: [
.iOS(.v15),
.macOS(.v12)
],
products: [
.library(name: "MatrixRustSDK",
targets: ["MatrixRustSDK"]),
],
targets: [
.target(name: "MatrixRustSDK",
path: "generated/swift",
swiftSettings: [
.unsafeFlags(["-I", "./generated/matrix_sdk_ffi"])
]),
.testTarget(name: "MatrixRustSDKTests",
dependencies: ["MatrixRustSDK"],
swiftSettings: [
.unsafeFlags(["-I", "./generated/matrix_sdk_ffi"])
],
linkerSettings: [
.linkedLibrary("matrix_sdk_ffi", .when(platforms: [.macOS])),
.linkedLibrary("matrix_sdk_ffiFFI", .when(platforms: [.linux])),
.unsafeFlags(["-L./generated/matrix_sdk_ffi"])
])
]
)
+40 -20
View File
@@ -2,32 +2,37 @@
This project and build script demonstrate how to create an XCFramework that can be imported into an Xcode project and run on Apple platforms. It can compile and bundle an [entire SDK](#Building-the-SDK), or only a smaller [Crypto module](#Building-only-the-Crypto-SDK) that provides end-to-end encryption for clients that already depend on an SDK (e.g. [Matrix iOS SDK](https://github.com/matrix-org/matrix-ios-sdk))
## Prerequisites for building universal frameworks
## Building
* the Rust toolchain
* UniFFI - `cargo install uniffi_bindgen`
* Apple targets (e.g. `rustup target add aarch64-apple-ios`)
* `xcodebuild` command line tool from [Apple](https://developer.apple.com/library/archive/technotes/tn2339/_index.html)
* `lipo` for creating the fat static libs
### Prerequisites for building universal frameworks
## Building the SDK
- the Rust toolchain
- Apple targets (e.g. `rustup target add aarch64-apple-ios aarch64-apple-ios-sim x86_64-apple-ios aarch64-apple-darwin x86_64-apple-darwin`)
- `xcodebuild` command line tool from [Apple](https://developer.apple.com/library/archive/technotes/tn2339/_index.html)
- `lipo` for creating the fat static libs
### Building the SDK
```
sh build_xcframework.sh
cargo xtask swift build-framework
```
The `build_xcframework.sh` script will go through all the steps required to generate a fully usable `.xcframework`:
The `build-framework` task will go through all the steps required to generate a fully usable `.xcframework`:
1. compile `matrix-sdk-ffi` libraries for iOS, the iOS simulator, MacOS, and Mac Catalyst under `/target`. Some targets are not part of the standard library and they will be built using the nightly toolchain.
1. compile `matrix-sdk-ffi` libraries for iOS, the iOS simulator and macOS under `/target`. Some targets are not part of the standard library and they will be built using the nightly toolchain.
2. `lipo` together the libraries for the same platform under `/generated`
3. run `uniffi` and generate the C header, module map and swift files
4. `xcodebuild` an `xcframework` from the fat static libs and the original iOS one, and add the header and module map to it under `generated/MatrixSDKFFI.xcframework`
5. cleanup and delete the generated files except the .xcframework and the swift sources (that aren't part of the framework)
## Building only the Crypto SDK
For development purposes, it will additionally generate a `Package.swift` file in the root of the repo that can be used to add the framework to your project and enable debugging through the use of [rust-xcode-plugin](https://github.com/BrainiumLLC/rust-xcode-plugin) (make sure to run the task with the argument `--profile=reldbg`).
When building the SDK for release you should pass the `--release` argument to the task, which will strip away any symbols and optimise the created binary.
### Building only the Crypto SDK
```
sh build_crypto_xcframework.sh
build_crypto_xcframework.sh
```
The `build_crypto_xcframework.sh` script will go through all the steps required to generate a fully usable `.xcframework`:
@@ -38,16 +43,31 @@ The `build_crypto_xcframework.sh` script will go through all the steps required
4. `xcodebuild` an `xcframework` from the fat static libs and the original iOS one, and add the header and module map to it under `generated/MatrixSDKCryptoFFI.xcframework`
5. cleanup and delete the generated files except the .xcframework and the swift sources (that aren't part of the framework)
## Running the Xcode project
### Building & testing the Swift package
The Xcode project is meant to provide a simple example on how to integrate everything together but also a place to run unit and integration tests from.
The `Package.swift` file in this directory provides a simple example on how to integrate everything together but also a place to run unit and integration tests from.
It's pre-configured to link to the generated .xcframework and .swift files so successfully running the script first is necessary for it to compile.
It makes the compiled code available to swift by importing the C header through its bridging header.
Once all the generated components are available running it should be as easy as choosing a platform and clicking run.
It's pre-configured to link to the generated static lib and .swift files so successfully running `cargo xtask swift build-library` first is necessary for it to compile. Afterwards you can execute the tests with `swift test`. Note that for the moment this only works on macOS but we're planning to add Linux support in the future.
## Distribution
The generated framework and Swift code can be distributed and integrated directly but in order to make things simpler we bundle them together as a Swift package available [TBD](here) in the case of SDK, and as CocoaPods podspec in the case of Crypto SDK.
The generated framework and Swift code can be distributed and integrated directly but in order to make things simpler we bundle them together as a [Swift package](https://github.com/matrix-org/matrix-rust-components-swift/) in the case of SDK, and as a CocoaPods podspec in the case of Crypto SDK.
### Publishing MatrixSDKCrypto
1. Navigate into `bindings/apple` and run [`build_crypto_xcframework.sh`](#building-only-the-crypto-sdk) script which generates a .zip file with the framework in `./generated` folder
Note that whilst you can run this command from any git branch, if you want to make a public release, ensure you are building from latest `main`
2. Tag the commit you just used to build the release and push the tag to GitHub
Use `matrix-sdk-crypto-ffi-<major>.<minor>.<patch>` tag name
3. Create a new [GitHub release](https://github.com/matrix-org/matrix-rust-sdk/releases) using this tag (see [example](https://github.com/matrix-org/matrix-rust-sdk/releases/tag/matrix-sdk-crypto-ffi-0.3.4))
4. Upload the previously generated .zip file to this release
5. Increment the version in [`MatrixSDKCrypto.podspec`](./MatrixSDKCrypto.podspec)
Note that this is not automated and is a local-only change. To determine the most recent published version, run `pod repo update && pod search MatrixSDKCrypto`
or check git tags via `git tag | grep matrix-sdk-crypto-ffi`
6. Push new Podspec version to Cocoapods via `pod trunk push MatrixSDKCrypto.podspec --allow-warnings`
@@ -0,0 +1,51 @@
import XCTest
@testable import MatrixRustSDK
final class ClientTests: XCTestCase {
func testBuildingWithHomeserverURL() async {
do {
_ = try await ClientBuilder()
.homeserverUrl(url: "https://localhost:8008")
.build()
} catch {
XCTFail("The client should build successfully when given a homeserver.")
}
}
func testBuildingWithHomeserverURLAndUserAgent() async {
do {
_ = try await ClientBuilder()
.homeserverUrl(url: "https://localhost:8008")
.userAgent(userAgent: "golden-eye/007")
.build()
} catch {
XCTFail("The client should build successfully when given a homeserver and user agent.")
}
}
func testBuildingWithInvalidUsername() async {
do {
_ = try await ClientBuilder()
.username(username: "@test:invalid")
.build()
XCTFail("The client should not build when given an invalid username.")
} 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")
}
}
// MARK: - Private
static private var basePath: String {
guard let url = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first else {
fatalError("Should always be able to retrieve the caches directory")
}
try? FileManager.default.createDirectory(at: url, withIntermediateDirectories: false, attributes: nil)
return url.path
}
}
+85 -24
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
@@ -10,7 +26,7 @@ TARGET_DIR="${SRC_ROOT}/target"
GENERATED_DIR="${SRC_ROOT}/generated"
if [ -d "${GENERATED_DIR}" ]; then rm -rf "${GENERATED_DIR}"; fi
mkdir -p ${GENERATED_DIR}
mkdir -p ${GENERATED_DIR}/{macos,simulator}
REL_FLAG="--release"
REL_TYPE_DIR="release"
@@ -19,31 +35,66 @@ TARGET_CRATE=matrix-sdk-crypto-ffi
# Build static libs for all the different architectures
# iOS
cargo build -p ${TARGET_CRATE} ${REL_FLAG} --target "aarch64-apple-ios"
# Required by olm-sys crate
export IOS_SDK_PATH=`xcrun --show-sdk-path --sdk iphoneos`
# iOS Simulator
cargo build -p ${TARGET_CRATE} ${REL_FLAG} --target "aarch64-apple-ios-sim"
cargo build -p ${TARGET_CRATE} ${REL_FLAG} --target "x86_64-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"
# 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
# iOS Simulator
lipo -create \
"${TARGET_DIR}/x86_64-apple-ios/${REL_TYPE_DIR}/libmatrix_crypto_ffi.a" \
"${TARGET_DIR}/aarch64-apple-ios-sim/${REL_TYPE_DIR}/libmatrix_crypto_ffi.a" \
-output "${GENERATED_DIR}/libmatrix_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"
fi
# Generate uniffi files
uniffi-bindgen generate "${SRC_ROOT}/bindings/${TARGET_CRATE}/src/olm.udl" --language swift --config "${SRC_ROOT}/bindings/${TARGET_CRATE}/uniffi.toml" --out-dir ${GENERATED_DIR}
cd ../matrix-sdk-crypto-ffi && cargo run --bin matrix_sdk_crypto_ffi generate \
--language swift \
--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"
@@ -53,21 +104,31 @@ 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_crypto_ffi.a" \
-headers ${HEADERS_DIR} \
-library "${GENERATED_DIR}/libmatrix_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 [ -f "${TARGET_DIR}/aarch64-apple-ios-sim/${REL_TYPE_DIR}/libmatrix_crypto_ffi.a" ]; then rm -rf "${TARGET_DIR}/aarch64-apple-ios-sim/${REL_TYPE_DIR}/libmatrix_crypto_ffi.a"; fi
if [ -f "${GENERATED_DIR}/libmatrix_crypto_ffi.a" ]; then rm -rf "${GENERATED_DIR}/libmatrix_crypto_ffi.a"; fi
if [ -d "${GENERATED_DIR}/macos" ]; then rm -rf "${GENERATED_DIR}/macos"; fi
if [ -d "${GENERATED_DIR}/simulator" ]; then rm -rf "${GENERATED_DIR}/simulator"; fi
if [ -d ${HEADERS_DIR} ]; then rm -rf ${HEADERS_DIR}; fi
# Zip up framework, sources and LICENSE, ready to be uploaded to GitHub Releases and used by MatrixSDKCrypto.podspec
cp ${SRC_ROOT}/LICENSE $GENERATED_DIR
cd $GENERATED_DIR
zip -r MatrixSDKCryptoFFI.zip MatrixSDKCryptoFFI.xcframework Sources LICENSE
rm LICENSE
echo "XCFramework is ready 🚀"
-89
View File
@@ -1,89 +0,0 @@
#!/usr/bin/env bash
set -eEu
cd "$(dirname "$0")"
# Path to the repo root
SRC_ROOT=../..
TARGET_DIR="${SRC_ROOT}/target"
GENERATED_DIR="${SRC_ROOT}/generated"
mkdir -p ${GENERATED_DIR}
REL_FLAG="--release"
REL_TYPE_DIR="release"
# Build static libs for all the different architectures
# iOS
cargo build -p matrix-sdk-ffi ${REL_FLAG} --target "aarch64-apple-ios"
# MacOS
cargo build -p matrix-sdk-ffi ${REL_FLAG} --target "aarch64-apple-darwin"
cargo build -p matrix-sdk-ffi ${REL_FLAG} --target "x86_64-apple-darwin"
# iOS Simulator
cargo build -p matrix-sdk-ffi ${REL_FLAG} --target "aarch64-apple-ios-sim"
cargo build -p matrix-sdk-ffi ${REL_FLAG} --target "x86_64-apple-ios"
# Mac Catalyst
cargo +nightly build -Z build-std -p matrix-sdk-ffi ${REL_FLAG} --target "aarch64-apple-ios-macabi"
cargo +nightly build -Z build-std -p matrix-sdk-ffi ${REL_FLAG} --target "x86_64-apple-ios-macabi"
# Lipo together the libraries for the same platform
# MacOS
lipo -create \
"${TARGET_DIR}/x86_64-apple-darwin/${REL_TYPE_DIR}/libmatrix_sdk_ffi.a" \
"${TARGET_DIR}/aarch64-apple-darwin/${REL_TYPE_DIR}/libmatrix_sdk_ffi.a" \
-output "${GENERATED_DIR}/libmatrix_sdk_ffi_macos.a"
# iOS Simulator
lipo -create \
"${TARGET_DIR}/x86_64-apple-ios/${REL_TYPE_DIR}/libmatrix_sdk_ffi.a" \
"${TARGET_DIR}/aarch64-apple-ios-sim/${REL_TYPE_DIR}/libmatrix_sdk_ffi.a" \
-output "${GENERATED_DIR}/libmatrix_sdk_ffi_iossimulator.a"
# Mac Catalyst
lipo -create \
"${TARGET_DIR}/x86_64-apple-ios-macabi/${REL_TYPE_DIR}/libmatrix_sdk_ffi.a" \
"${TARGET_DIR}/aarch64-apple-ios-macabi/${REL_TYPE_DIR}/libmatrix_sdk_ffi.a" \
-output "${GENERATED_DIR}/libmatrix_sdk_ffi_maccatalyst.a"
# Generate uniffi files
uniffi-bindgen generate "${SRC_ROOT}/bindings/matrix-sdk-ffi/src/api.udl" --language swift --out-dir ${GENERATED_DIR}
# Move them to the right place
HEADERS_DIR=${GENERATED_DIR}/headers
mkdir -p ${HEADERS_DIR}
mv ${GENERATED_DIR}/*.h ${GENERATED_DIR}/*.modulemap ${HEADERS_DIR}
SWIFT_DIR="${GENERATED_DIR}/swift"
mkdir -p ${SWIFT_DIR}
mv ${GENERATED_DIR}/*.swift ${SWIFT_DIR}
# Build the xcframework
if [ -d "${GENERATED_DIR}/MatrixSDKFFI.xcframework" ]; then rm -rf "${GENERATED_DIR}/MatrixSDKFFI.xcframework"; fi
xcodebuild -create-xcframework \
-library "${GENERATED_DIR}/libmatrix_sdk_ffi_macos.a" \
-headers ${HEADERS_DIR} \
-library "${GENERATED_DIR}/libmatrix_sdk_ffi_iossimulator.a" \
-headers ${HEADERS_DIR} \
-library "${GENERATED_DIR}/libmatrix_sdk_ffi_maccatalyst.a" \
-headers ${HEADERS_DIR} \
-library "${TARGET_DIR}/aarch64-apple-ios/${REL_TYPE_DIR}/libmatrix_sdk_ffi.a" \
-headers ${HEADERS_DIR} \
-output "${GENERATED_DIR}/MatrixSDKFFI.xcframework"
# Cleanup
if [ -f "${GENERATED_DIR}/libmatrix_sdk_ffi_macos.a" ]; then rm -rf "${GENERATED_DIR}/libmatrix_sdk_ffi_macos.a"; fi
if [ -f "${GENERATED_DIR}/libmatrix_sdk_ffi_iossimulator.a" ]; then rm -rf "${GENERATED_DIR}/libmatrix_sdk_ffi_iossimulator.a"; fi
if [ -f "${GENERATED_DIR}/libmatrix_sdk_ffi_maccatalyst.a" ]; then rm -rf "${GENERATED_DIR}/libmatrix_sdk_ffi_maccatalyst.a"; fi
if [ -d ${HEADERS_DIR} ]; then rm -rf ${HEADERS_DIR}; fi
-71
View File
@@ -1,71 +0,0 @@
#!/usr/bin/env bash
set -eEu
cd "$(dirname "$0")"
IS_CI=false
if [ $# -eq 1 ]; then
IS_CI=true
echo "Running CI build"
else
echo "Running debug build"
fi
# Path to the repo root
SRC_ROOT=../..
TARGET_DIR="${SRC_ROOT}/target"
GENERATED_DIR="${SRC_ROOT}/generated"
mkdir -p ${GENERATED_DIR}
REL_FLAG=""
REL_TYPE_DIR="debug"
# iOS Simulator
cargo +nightly build -p matrix-sdk-ffi ${REL_FLAG} --target "aarch64-apple-ios-sim"
cargo +nightly build -p matrix-sdk-ffi ${REL_FLAG} --target "x86_64-apple-ios"
lipo -create \
"${TARGET_DIR}/x86_64-apple-ios/${REL_TYPE_DIR}/libmatrix_sdk_ffi.a" \
"${TARGET_DIR}/aarch64-apple-ios-sim/${REL_TYPE_DIR}/libmatrix_sdk_ffi.a" \
-output "${GENERATED_DIR}/libmatrix_sdk_ffi_iossimulator.a"
# Generate uniffi files
uniffi-bindgen generate "${SRC_ROOT}/bindings/matrix-sdk-ffi/src/api.udl" --language swift --out-dir ${GENERATED_DIR}
# Move them to the right place
HEADERS_DIR=${GENERATED_DIR}/headers
mkdir -p ${HEADERS_DIR}
mv ${GENERATED_DIR}/*.h ${GENERATED_DIR}/*.modulemap ${HEADERS_DIR}
SWIFT_DIR="${GENERATED_DIR}/swift"
mkdir -p ${SWIFT_DIR}
mv ${GENERATED_DIR}/*.swift ${SWIFT_DIR}
# Build the xcframework
if [ -d "${GENERATED_DIR}/MatrixSDKFFI.xcframework" ]; then rm -rf "${GENERATED_DIR}/MatrixSDKFFI.xcframework"; fi
xcodebuild -create-xcframework \
-library "${GENERATED_DIR}/libmatrix_sdk_ffi_iossimulator.a" \
-headers ${HEADERS_DIR} \
-output "${GENERATED_DIR}/MatrixSDKFFI.xcframework"
# Cleanup
# if [ -f "${GENERATED_DIR}/libmatrix_sdk_ffi_iossimulator.a" ]; then rm -rf "${GENERATED_DIR}/libmatrix_sdk_ffi_iossimulator.a"; fi
# if [ -d ${HEADERS_DIR} ]; then rm -rf ${HEADERS_DIR}; fi
if [ "$IS_CI" = false ] ; then
echo "Preparing matrix-rust-components-swift"
# Debug -> Copy generated files over to ../../../matrix-rust-components-swift
echo "$(printf "import MatrixSDKFFIWrapper\n\n"; cat "${SWIFT_DIR}/sdk.swift")" > "${SWIFT_DIR}/sdk.swift"
rsync -a --delete "${GENERATED_DIR}/MatrixSDKFFI.xcframework" "${SRC_ROOT}/../matrix-rust-components-swift/"
rsync -a --delete "${GENERATED_DIR}/swift/" "${SRC_ROOT}/../matrix-rust-components-swift/Sources/MatrixRustSDK"
fi
+42 -36
View File
@@ -2,8 +2,8 @@
name = "matrix-sdk-crypto-ffi"
version = "0.1.0"
authors = ["Damir Jelić <poljar@termina.org.uk>"]
edition = "2018"
rust-version = "1.60"
edition = "2021"
rust-version = { workspace = true }
description = "Uniffi based bindings for the Rust SDK crypto crate"
repository = "https://github.com/matrix-org/matrix-rust-sdk"
license = "Apache-2.0"
@@ -11,56 +11,62 @@ publish = false
[lib]
crate-type = ["cdylib", "staticlib"]
name = "matrix_crypto_ffi"
[[bin]]
name = "matrix_sdk_crypto_ffi"
path = "uniffi-bindgen.rs"
[features]
default = ["bundled-sqlite"]
bundled-sqlite = ["matrix-sdk-sqlite/bundled"]
[dependencies]
anyhow = "1.0.57"
base64 = "0.13.0"
anyhow = { workspace = true }
futures-util = { workspace = true }
hmac = "0.12.1"
http = "0.2.6"
pbkdf2 = "0.11.0"
rand = "0.8.5"
ruma = { git = "https://github.com/ruma/ruma", rev = "96155915f", features = ["client-api-c"] }
serde = "1.0.136"
serde_json = "1.0.79"
sha2 = "0.10.2"
thiserror = "1.0.30"
tracing = "0.1.34"
tracing-subscriber = { version = "0.3.11", features = ["env-filter"] }
http = { 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 }
serde = { workspace = true }
serde_json = { workspace = true }
sha2 = { workspace = true }
thiserror = { workspace = true }
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 = "0.18.0"
zeroize = { version = "1.3.0", features = ["zeroize_derive"] }
uniffi = { workspace = true, features = ["cli"] }
vodozemac = { workspace = true }
zeroize = { workspace = true, features = ["zeroize_derive"] }
[dependencies.js_int]
version = "0.2.2"
features = ["lax_deserialize"]
[dependencies.matrix-sdk-common]
path = "../../crates/matrix-sdk-common"
version = "0.5.0"
[dependencies.matrix-sdk-crypto]
path = "../../crates/matrix-sdk-crypto"
version = "0.5.0"
features = ["qrcode", "backups_v1"]
workspace = true
features = ["qrcode", "automatic-room-key-forwarding", "uniffi"]
[dependencies.matrix-sdk-sled]
path = "../../crates/matrix-sdk-sled"
version = "0.1.0"
default_features = false
[dependencies.matrix-sdk-sqlite]
workspace = true
features = ["crypto-store"]
[dependencies.tokio]
version = "1.17.0"
default_features = false
version = "1.33.0"
default-features = false
features = ["rt-multi-thread"]
[dependencies.vodozemac]
git = "https://github.com/matrix-org/vodozemac/"
rev = "2404f83f7d3a3779c1f518e4d949f7da9677c3dd"
[build-dependencies]
uniffi_build = { version = "0.18.0", features = ["builtin-bindgen"] }
vergen = { version = "8.2.5", features = ["build", "git", "gitcl"] }
uniffi = { workspace = true, features = ["build"] }
[dev-dependencies]
tempfile = "3.3.0"
tempfile = "3.8.0"
assert_matches2 = { workspace = true }
[lints]
workspace = true
[package.metadata.release]
release = false
+2 -4
View File
@@ -5,6 +5,8 @@ README mainly describes how to build and integrate the bindings into a Kotlin
based Android project, but the Android specific bits can be skipped if you are
targeting an x86 Linux project.
To build and distribute bindings for iOS projects, see a [dedicated page](../apple/README.md)
## Prerequisites
### Rust
@@ -69,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.60`.
## License
[Apache-2.0](https://www.apache.org/licenses/LICENSE-2.0)
+64 -2
View File
@@ -1,3 +1,65 @@
fn main() {
uniffi_build::generate_scaffolding("./src/olm.udl").unwrap();
use std::{
env,
error::Error,
path::{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 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" {
// 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"),
);
// 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: &Path) -> 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();
EmitBuilder::builder().git_sha(true).git_describe(true, false, None).emit()?;
Ok(())
}
@@ -1,9 +1,9 @@
use std::{collections::HashMap, iter, ops::DerefMut};
use std::{collections::HashMap, iter, ops::DerefMut, sync::Arc};
use hmac::Hmac;
use matrix_sdk_crypto::{
backups::OlmPkDecryptionError,
store::{CryptoStoreError as InnerStoreError, RecoveryKey},
backups::DecryptionError,
store::{BackupDecryptionKey, CryptoStoreError as InnerStoreError},
};
use pbkdf2::pbkdf2;
use rand::{distributions::Alphanumeric, thread_rng, Rng};
@@ -12,21 +12,24 @@ use thiserror::Error;
use zeroize::Zeroize;
/// The private part of the backup key, the one used for recovery.
#[derive(uniffi::Object)]
pub struct BackupRecoveryKey {
pub(crate) inner: RecoveryKey,
pub(crate) inner: BackupDecryptionKey,
pub(crate) passphrase_info: Option<PassphraseInfo>,
}
/// Error type for the decryption of backed up room keys.
#[derive(Debug, Error)]
#[derive(Debug, Error, uniffi::Error)]
#[uniffi(flat_error)]
pub enum PkDecryptionError {
/// An internal libolm error happened during decryption.
#[error("Error decryption a PkMessage {0}")]
Olm(#[from] OlmPkDecryptionError),
Olm(#[from] DecryptionError),
}
/// Error type for the decoding and storing of the backup key.
#[derive(Debug, Error)]
#[derive(Debug, Error, uniffi::Error)]
#[uniffi(flat_error)]
pub enum DecodeError {
/// An error happened while decoding the recovery key.
#[error(transparent)]
@@ -39,7 +42,7 @@ pub enum DecodeError {
/// Struct containing info about the way the backup key got derived from a
/// passphrase.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, uniffi::Record)]
pub struct PassphraseInfo {
/// The salt that was used during key derivation.
pub private_key_salt: String,
@@ -48,6 +51,7 @@ pub struct PassphraseInfo {
}
/// The public part of the backup key.
#[derive(uniffi::Record)]
pub struct MegolmV1BackupKey {
/// The actual base64 encoded public key.
pub public_key: String,
@@ -63,29 +67,36 @@ impl BackupRecoveryKey {
const KEY_SIZE: usize = 32;
const SALT_SIZE: usize = 32;
const PBKDF_ROUNDS: i32 = 500_000;
}
#[matrix_sdk_ffi_macros::export]
impl BackupRecoveryKey {
/// Create a new random [`BackupRecoveryKey`].
#[allow(clippy::new_without_default)]
pub fn new() -> Self {
Self {
inner: RecoveryKey::new()
#[uniffi::constructor]
pub fn new() -> Arc<Self> {
Arc::new(Self {
inner: BackupDecryptionKey::new()
.expect("Can't gather enough randomness to create a recovery key"),
passphrase_info: None,
}
})
}
/// Try to create a [`BackupRecoveryKey`] from a base 64 encoded string.
pub fn from_base64(key: String) -> Result<Self, DecodeError> {
Ok(Self { inner: RecoveryKey::from_base64(&key)?, passphrase_info: None })
#[uniffi::constructor]
pub fn from_base64(key: String) -> Result<Arc<Self>, DecodeError> {
Ok(Arc::new(Self { inner: BackupDecryptionKey::from_base64(&key)?, passphrase_info: None }))
}
/// Try to create a [`BackupRecoveryKey`] from a base 58 encoded string.
pub fn from_base58(key: String) -> Result<Self, DecodeError> {
Ok(Self { inner: RecoveryKey::from_base58(&key)?, passphrase_info: None })
#[uniffi::constructor]
pub fn from_base58(key: String) -> Result<Arc<Self>, DecodeError> {
Ok(Arc::new(Self { inner: BackupDecryptionKey::from_base58(&key)?, passphrase_info: None }))
}
/// Create a new [`BackupRecoveryKey`] from the given passphrase.
pub fn new_from_passphrase(passphrase: String) -> Self {
#[uniffi::constructor]
pub fn new_from_passphrase(passphrase: String) -> Arc<Self> {
let mut rng = thread_rng();
let salt: String = iter::repeat(())
.map(|()| rng.sample(Alphanumeric))
@@ -97,41 +108,28 @@ impl BackupRecoveryKey {
}
/// Restore a [`BackupRecoveryKey`] from the given passphrase.
pub fn from_passphrase(passphrase: String, salt: String, rounds: i32) -> Self {
#[uniffi::constructor]
pub fn from_passphrase(passphrase: String, salt: String, rounds: i32) -> Arc<Self> {
let mut key = Box::new([0u8; Self::KEY_SIZE]);
let rounds = rounds as u32;
pbkdf2::<Hmac<Sha512>>(passphrase.as_bytes(), salt.as_bytes(), rounds, key.deref_mut());
pbkdf2::<Hmac<Sha512>>(passphrase.as_bytes(), salt.as_bytes(), rounds, key.deref_mut())
.expect(
"We should be able to expand a passphrase of any length due to \
HMAC being able to be initialized with any input size",
);
let recovery_key = RecoveryKey::from_bytes(&key);
let backup_decryption_key = BackupDecryptionKey::from_bytes(&key);
key.zeroize();
Self {
inner: recovery_key,
Arc::new(Self {
inner: backup_decryption_key,
passphrase_info: Some(PassphraseInfo {
private_key_salt: salt,
private_key_iterations: rounds as i32,
}),
}
}
/// Get the public part of the backup key.
pub fn megolm_v1_public_key(&self) -> MegolmV1BackupKey {
let public_key = self.inner.megolm_v1_public_key();
let signatures: HashMap<String, HashMap<String, String>> = public_key
.signatures()
.into_iter()
.map(|(k, v)| (k.to_string(), v.into_iter().map(|(k, v)| (k.to_string(), v)).collect()))
.collect();
MegolmV1BackupKey {
public_key: public_key.to_base64(),
signatures,
passphrase_info: self.passphrase_info.clone(),
backup_algorithm: public_key.backup_algorithm().to_owned(),
}
})
}
/// Convert the recovery key to a base 58 encoded string.
@@ -144,6 +142,39 @@ impl BackupRecoveryKey {
self.inner.to_base64()
}
/// Get the public part of the backup key.
pub fn megolm_v1_public_key(&self) -> MegolmV1BackupKey {
let public_key = self.inner.megolm_v1_public_key();
let signatures: HashMap<String, HashMap<String, String>> = public_key
.signatures()
.into_iter()
.map(|(k, v)| {
(
k.to_string(),
v.into_iter()
.map(|(k, v)| {
(
k.to_string(),
match v {
Ok(s) => s.to_base64(),
Err(s) => s.source,
},
)
})
.collect(),
)
})
.collect();
MegolmV1BackupKey {
public_key: public_key.to_base64(),
signatures,
passphrase_info: self.passphrase_info.clone(),
backup_algorithm: public_key.backup_algorithm().to_owned(),
}
}
/// Try to decrypt a message that was encrypted using the public part of the
/// backup key.
pub fn decrypt_v1(
@@ -152,6 +183,51 @@ impl BackupRecoveryKey {
mac: String,
ciphertext: String,
) -> Result<String, PkDecryptionError> {
self.inner.decrypt_v1(ephemeral_key, mac, ciphertext).map_err(|e| e.into())
self.inner.decrypt_v1(&ephemeral_key, &mac, &ciphertext).map_err(|e| e.into())
}
}
#[cfg(test)]
mod tests {
use ruma::api::client::backup::KeyBackupData;
use serde_json::json;
use super::BackupRecoveryKey;
#[test]
fn test_decrypt_key() {
let recovery_key = BackupRecoveryKey::from_base64(
"Ha9cklU/9NqFo9WKdVfGzmqUL/9wlkdxfEitbSIPVXw".to_owned(),
)
.unwrap();
let data = json!({
"first_message_index": 0,
"forwarded_count": 0,
"is_verified": false,
"session_data": {
"ephemeral": "HlLi76oV6wxHz3PCqE/bxJi6yF1HnYz5Dq3T+d/KpRw",
"ciphertext": "MuM8E3Yc6TSAvhVGb77rQ++jE6p9dRepx63/3YPD2wACKAppkZHeFrnTH6wJ/HSyrmzo\
7HfwqVl6tKNpfooSTHqUf6x1LHz+h4B/Id5ITO1WYt16AaI40LOnZqTkJZCfSPuE2oxa\
lwEHnCS3biWybutcnrBFPR3LMtaeHvvkb+k3ny9l5ZpsU9G7vCm3XoeYkWfLekWXvDhb\
qWrylXD0+CNUuaQJ/S527TzLd4XKctqVjjO/cCH7q+9utt9WJAfK8LGaWT/mZ3AeWjf5\
kiqOpKKf5Cn4n5SSil5p/pvGYmjnURvZSEeQIzHgvunIBEPtzK/MYEPOXe/P5achNGlC\
x+5N19Ftyp9TFaTFlTWCTi0mpD7ePfCNISrwpozAz9HZc0OhA8+1aSc7rhYFIeAYXFU3\
26NuFIFHI5pvpSxjzPQlOA+mavIKmiRAtjlLw11IVKTxgrdT4N8lXeMr4ndCSmvIkAzF\
Mo1uZA4fzjiAdQJE4/2WeXFNNpvdfoYmX8Zl9CAYjpSO5HvpwkAbk4/iLEH3hDfCVUwD\
fMh05PdGLnxeRpiEFWSMSsJNp+OWAA+5JsF41BoRGrxoXXT+VKqlUDONd+O296Psu8Q+\
d8/S618",
"mac": "GtMrurhDTwo"
}
});
let key_backup_data: KeyBackupData = serde_json::from_value(data).unwrap();
let ephemeral = key_backup_data.session_data.ephemeral.encode();
let ciphertext = key_backup_data.session_data.ciphertext.encode();
let mac = key_backup_data.session_data.mac.encode();
let _ = recovery_key
.decrypt_v1(ephemeral, mac, ciphertext)
.expect("The backed up key should be decrypted successfully");
}
}
@@ -0,0 +1,255 @@
use std::{mem::ManuallyDrop, sync::Arc};
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 crate::{CryptoStoreError, DehydratedDeviceKey};
#[derive(Debug, thiserror::Error, uniffi::Error)]
#[uniffi(flat_error)]
pub enum DehydrationError {
#[error(transparent)]
Pickle(#[from] matrix_sdk_crypto::vodozemac::DehydratedDeviceError),
#[error(transparent)]
LegacyPickle(#[from] matrix_sdk_crypto::vodozemac::LibolmPickleError),
#[error(transparent)]
MissingSigningKey(#[from] matrix_sdk_crypto::SignatureError),
#[error(transparent)]
Json(#[from] serde_json::Error),
#[error(transparent)]
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 {
fn from(value: matrix_sdk_crypto::dehydrated_devices::DehydrationError) -> Self {
match value {
matrix_sdk_crypto::dehydrated_devices::DehydrationError::Json(e) => Self::Json(e),
matrix_sdk_crypto::dehydrated_devices::DehydrationError::Pickle(e) => Self::Pickle(e),
matrix_sdk_crypto::dehydrated_devices::DehydrationError::LegacyPickle(e) => {
Self::LegacyPickle(e)
}
matrix_sdk_crypto::dehydrated_devices::DehydrationError::MissingSigningKey(e) => {
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)
}
}
}
}
#[derive(uniffi::Object)]
pub struct DehydratedDevices {
pub(crate) runtime: Handle,
pub(crate) inner: ManuallyDrop<InnerDehydratedDevices>,
}
impl Drop for DehydratedDevices {
fn drop(&mut self) {
// See the drop implementation for the `crate::OlmMachine` for an explanation.
let _guard = self.runtime.enter();
unsafe {
ManuallyDrop::drop(&mut self.inner);
}
}
}
#[matrix_sdk_ffi_macros::export]
impl DehydratedDevices {
pub fn create(&self) -> Result<Arc<DehydratedDevice>, DehydrationError> {
let inner = self.runtime.block_on(self.inner.create())?;
Ok(Arc::new(DehydratedDevice {
inner: ManuallyDrop::new(inner),
runtime: self.runtime.to_owned(),
}))
}
pub fn rehydrate(
&self,
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 key = InnerDehydratedDeviceKey::from_slice(&pickle_key.inner)?;
let ret = RehydratedDevice {
runtime: self.runtime.to_owned(),
inner: ManuallyDrop::new(self.runtime.block_on(self.inner.rehydrate(
&key,
&device_id,
device_data,
))?),
}
.into();
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)]
pub struct RehydratedDevice {
inner: ManuallyDrop<InnerRehydratedDevice>,
runtime: Handle,
}
impl Drop for RehydratedDevice {
fn drop(&mut self) {
// See the drop implementation for the `crate::OlmMachine` for an explanation.
let _guard = self.runtime.enter();
unsafe {
ManuallyDrop::drop(&mut self.inner);
}
}
}
#[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)?;
self.runtime.block_on(self.inner.receive_events(events))?;
Ok(())
}
}
#[derive(uniffi::Object)]
pub struct DehydratedDevice {
pub(crate) runtime: Handle,
pub(crate) inner: ManuallyDrop<InnerDehydratedDevice>,
}
impl Drop for DehydratedDevice {
fn drop(&mut self) {
// See the drop implementation for the `crate::OlmMachine` for an explanation.
let _guard = self.runtime.enter();
unsafe {
ManuallyDrop::drop(&mut self.inner);
}
}
}
#[matrix_sdk_ffi_macros::export]
impl DehydratedDevice {
pub fn keys_for_upload(
&self,
device_display_name: String,
pickle_key: &DehydratedDeviceKey,
) -> Result<UploadDehydratedDeviceRequest, DehydrationError> {
let key = InnerDehydratedDeviceKey::from_slice(&pickle_key.inner)?;
let request =
self.runtime.block_on(self.inner.keys_for_upload(device_display_name, &key))?;
Ok(request.into())
}
}
#[derive(Debug, uniffi::Record)]
pub struct UploadDehydratedDeviceRequest {
/// The serialized JSON body of the request.
body: String,
}
impl From<dehydrated_device::put_dehydrated_device::unstable::Request>
for UploadDehydratedDeviceRequest
{
fn from(value: dehydrated_device::put_dehydrated_device::unstable::Request) -> Self {
let body = json!({
"device_id": value.device_id,
"device_data": value.device_data,
"initial_device_display_name": value.initial_device_display_name,
"device_keys": value.device_keys,
"one_time_keys": value.one_time_keys,
"fallback_keys": value.fallback_keys,
});
let body = serde_json::to_string(&body)
.expect("We should be able to serialize the PUT dehydrated devices request body");
Self { body }
}
}
#[cfg(test)]
mod tests {
use crate::{dehydrated_devices::DehydrationError, DehydratedDeviceKey};
#[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;
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!"),
}
}
}
@@ -3,6 +3,7 @@ use std::collections::HashMap;
use matrix_sdk_crypto::Device as InnerDevice;
/// An E2EE capable Matrix device.
#[derive(uniffi::Record)]
pub struct Device {
/// The device owner.
pub user_id: String,
@@ -24,6 +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, 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 {
@@ -37,6 +43,8 @@ impl From<InnerDevice> for Device {
is_blocked: d.is_blacklisted(),
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(),
}
}
}
+79 -13
View File
@@ -1,12 +1,15 @@
#![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};
#[derive(Debug, thiserror::Error)]
#[derive(Debug, thiserror::Error, uniffi::Error)]
#[uniffi(flat_error)]
pub enum KeyImportError {
#[error(transparent)]
Export(#[from] KeyExportError),
@@ -16,7 +19,8 @@ pub enum KeyImportError {
Json(#[from] serde_json::Error),
}
#[derive(Debug, thiserror::Error)]
#[derive(Debug, thiserror::Error, uniffi::Error)]
#[uniffi(flat_error)]
pub enum SecretImportError {
#[error(transparent)]
CryptoStore(#[from] InnerStoreError),
@@ -24,7 +28,8 @@ pub enum SecretImportError {
Import(#[from] RustSecretImportError),
}
#[derive(Debug, thiserror::Error)]
#[derive(Debug, thiserror::Error, uniffi::Error)]
#[uniffi(flat_error)]
pub enum SignatureError {
#[error(transparent)]
Signature(#[from] InnerSignatureError),
@@ -38,8 +43,11 @@ pub enum SignatureError {
UnknownUserIdentity(String),
}
#[derive(Debug, thiserror::Error)]
#[derive(Debug, thiserror::Error, uniffi::Error)]
#[uniffi(flat_error)]
pub enum CryptoStoreError {
#[error("Failed to open the store")]
OpenStore(#[from] OpenStoreError),
#[error(transparent)]
CryptoStore(#[from] InnerStoreError),
#[error(transparent)]
@@ -50,14 +58,72 @@ pub enum CryptoStoreError {
InvalidUserId(String, IdParseError),
#[error(transparent)]
Identifier(#[from] IdParseError),
#[error(transparent)]
DehydrationError(#[from] InnerDehydrationError),
}
#[derive(Debug, thiserror::Error)]
#[derive(Debug, thiserror::Error, uniffi::Error)]
pub enum DecryptionError {
#[error(transparent)]
Serialization(#[from] serde_json::Error),
#[error(transparent)]
Identifier(#[from] IdParseError),
#[error(transparent)]
Megolm(#[from] MegolmError),
#[error("serialization error: {error}")]
Serialization { error: String },
#[error("identifier parsing error: {error}")]
Identifier { error: String },
#[error("megolm error: {error}")]
Megolm { error: String },
#[error("missing room key: {error}")]
MissingRoomKey { error: String, withheld_code: Option<String> },
#[error("store error: {error}")]
Store { error: String },
}
impl From<MegolmError> for DecryptionError {
fn from(value: MegolmError) -> Self {
match value {
MegolmError::MissingRoomKey(withheld_code) => Self::MissingRoomKey {
error: "Withheld Inbound group session".to_owned(),
withheld_code: withheld_code.map(|w| w.as_str().to_owned()),
},
_ => Self::Megolm { error: value.to_string() },
}
}
}
impl From<serde_json::Error> for DecryptionError {
fn from(err: serde_json::Error) -> Self {
Self::Serialization { error: err.to_string() }
}
}
impl From<IdParseError> for DecryptionError {
fn from(err: IdParseError) -> Self {
Self::Identifier { error: err.to_string() }
}
}
impl From<InnerStoreError> for DecryptionError {
fn from(err: InnerStoreError) -> Self {
Self::Store { error: err.to_string() }
}
}
#[cfg(test)]
mod tests {
use assert_matches2::assert_let;
use matrix_sdk_crypto::MegolmError;
use super::DecryptionError;
#[test]
fn test_withheld_error_mapping() {
use matrix_sdk_common::deserialized_responses::WithheldCode;
let inner_error = MegolmError::MissingRoomKey(Some(WithheldCode::Unverified));
let binding_error: DecryptionError = inner_error.into();
assert_let!(
DecryptionError::MissingRoomKey { error: _, withheld_code: Some(code) } = binding_error
);
assert_eq!("m.unverified", code)
}
}
File diff suppressed because it is too large Load Diff
+10 -3
View File
@@ -7,6 +7,7 @@ use tracing_subscriber::{fmt::MakeWriter, EnvFilter};
/// Trait that can be used to forward Rust logs over FFI to a language specific
/// logger.
#[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);
@@ -41,16 +42,22 @@ pub struct LoggerWrapper {
}
/// Set the logger that should be used to forward Rust logs over FFI.
#[matrix_sdk_ffi_macros::export]
pub fn set_logger(logger: Box<dyn Logger>) {
let logger = LoggerWrapper { inner: Arc::new(Mutex::new(logger)) };
let filter = EnvFilter::from_default_env().add_directive(
"matrix_sdk_crypto=trace".parse().expect("Can't parse logging filter directive"),
);
let filter = EnvFilter::from_default_env()
.add_directive(
"matrix_sdk_crypto=trace".parse().expect("Can't parse logging filter directive"),
)
.add_directive(
"matrix_sdk_sqlite=debug".parse().expect("Can't parse logging filter directive"),
);
let _ = tracing_subscriber::fmt()
.with_writer(logger)
.with_env_filter(filter)
.with_ansi(false)
.without_time()
.try_init();
}
File diff suppressed because it is too large Load Diff
-483
View File
@@ -1,483 +0,0 @@
namespace olm {
void set_logger(Logger logger);
[Throws=MigrationError]
void migrate(
MigrationData data,
[ByRef] string path,
string? passphrase,
ProgressListener progress_listener
);
};
[Error]
interface MigrationError {
Generic(string error_message);
};
callback interface Logger {
void log(string logLine);
};
callback interface ProgressListener {
void on_progress(i32 progress, i32 total);
};
[Error]
enum PkDecryptionError {
"Olm",
};
[Error]
enum KeyImportError {
"Export",
"CryptoStore",
"Json",
};
[Error]
enum SignatureError {
"Signature",
"Identifier",
"CryptoStore",
"UnknownDevice",
"UnknownUserIdentity",
};
[Error]
enum SecretImportError {
"Import",
"CryptoStore",
};
[Error]
enum CryptoStoreError {
"CryptoStore",
"OlmError",
"Serialization",
"Identifier",
"InvalidUserId",
};
[Error]
enum DecryptionError {
"Identifier",
"Serialization",
"Megolm",
};
dictionary DeviceLists {
sequence<string> changed;
sequence<string> left;
};
dictionary KeysImportResult {
i64 imported;
i64 total;
record<DOMString, record<DOMString, sequence<string>>> keys;
};
dictionary DecryptedEvent {
string clear_event;
string sender_curve25519_key;
string? claimed_ed25519_key;
sequence<string> forwarding_curve25519_chain;
};
dictionary Device {
string user_id;
string device_id;
record<DOMString, string> keys;
sequence<string> algorithms;
string? display_name;
boolean is_blocked;
boolean locally_trusted;
boolean cross_signing_trusted;
};
[Enum]
interface UserIdentity {
Own(
string user_id,
boolean trusts_our_own_device,
string master_key,
string self_signing_key,
string user_signing_key
);
Other(
string user_id,
string master_key,
string self_signing_key
);
};
dictionary CrossSigningStatus {
boolean has_master;
boolean has_self_signing;
boolean has_user_signing;
};
dictionary CrossSigningKeyExport {
string? master_key;
string? self_signing_key;
string? user_signing_key;
};
dictionary UploadSigningKeysRequest {
string master_key;
string self_signing_key;
string user_signing_key;
};
dictionary BootstrapCrossSigningResult {
UploadSigningKeysRequest upload_signing_keys_request;
SignatureUploadRequest signature_request;
};
dictionary CancelInfo {
string cancel_code;
string reason;
boolean cancelled_by_us;
};
dictionary StartSasResult {
Sas sas;
OutgoingVerificationRequest request;
};
dictionary Sas {
string other_user_id;
string other_device_id;
string flow_id;
string? room_id;
boolean we_started;
boolean has_been_accepted;
boolean can_be_presented;
boolean supports_emoji;
boolean have_we_confirmed;
boolean is_done;
boolean is_cancelled;
CancelInfo? cancel_info;
};
dictionary ScanResult {
QrCode qr;
OutgoingVerificationRequest request;
};
dictionary QrCode {
string other_user_id;
string other_device_id;
string flow_id;
string? room_id;
boolean we_started;
boolean other_side_scanned;
boolean has_been_confirmed;
boolean reciprocated;
boolean is_done;
boolean is_cancelled;
CancelInfo? cancel_info;
};
dictionary VerificationRequest {
string other_user_id;
string? other_device_id;
string flow_id;
string? room_id;
boolean we_started;
boolean is_ready;
boolean is_passive;
boolean is_done;
boolean is_cancelled;
CancelInfo? cancel_info;
sequence<string>? their_methods;
sequence<string>? our_methods;
};
dictionary RequestVerificationResult {
VerificationRequest verification;
OutgoingVerificationRequest request;
};
dictionary ConfirmVerificationResult {
sequence<OutgoingVerificationRequest> requests;
SignatureUploadRequest? signature_request;
};
[Enum]
interface Verification {
SasV1(Sas sas);
QrCodeV1(QrCode qrcode);
};
dictionary KeyRequestPair {
Request? cancellation;
Request key_request;
};
[Enum]
interface OutgoingVerificationRequest {
ToDevice(string request_id, string event_type, string body);
InRoom(string request_id, string room_id, string event_type, string content);
};
[Enum]
interface Request {
ToDevice(string request_id, string event_type, string body);
KeysUpload(string request_id, string body);
KeysQuery(string request_id, sequence<string> users);
KeysClaim(string request_id, record<DOMString, record<DOMString, string>> one_time_keys);
KeysBackup(string request_id, string version, string rooms);
RoomMessage(string request_id, string room_id, string event_type, string content);
SignatureUpload(string request_id, string body);
};
dictionary SignatureUploadRequest {
string body;
};
enum RequestType {
"KeysQuery",
"KeysClaim",
"KeysUpload",
"ToDevice",
"SignatureUpload",
"KeysBackup",
"RoomMessage",
};
interface OlmMachine {
[Throws=CryptoStoreError]
constructor(
[ByRef] string user_id,
[ByRef] string device_id,
[ByRef] string path,
string? passphrase
);
record<DOMString, string> identity_keys();
string user_id();
string device_id();
[Throws=CryptoStoreError]
string receive_sync_changes([ByRef] string events,
DeviceLists device_changes,
record<DOMString, i32> key_counts,
sequence<string>? unused_fallback_keys);
[Throws=CryptoStoreError]
sequence<Request> outgoing_requests();
[Throws=CryptoStoreError]
void mark_request_as_sent(
[ByRef] string request_id,
RequestType request_type,
[ByRef] string response
);
[Throws=DecryptionError]
DecryptedEvent decrypt_room_event([ByRef] string event, [ByRef] string room_id);
[Throws=CryptoStoreError]
string encrypt([ByRef] string room_id, [ByRef] string event_type, [ByRef] string content);
[Throws=CryptoStoreError]
UserIdentity? get_identity([ByRef] string user_id, u32 timeout);
[Throws=SignatureError]
SignatureUploadRequest verify_identity([ByRef] string user_id);
[Throws=CryptoStoreError]
Device? get_device([ByRef] string user_id, [ByRef] string device_id, u32 timeout);
[Throws=CryptoStoreError]
void mark_device_as_trusted([ByRef] string user_id, [ByRef] string device_id);
[Throws=SignatureError]
SignatureUploadRequest verify_device([ByRef] string user_id, [ByRef] string device_id);
[Throws=CryptoStoreError]
sequence<Device> get_user_devices([ByRef] string user_id, u32 timeout);
[Throws=CryptoStoreError]
boolean is_user_tracked([ByRef] string user_id);
void update_tracked_users(sequence<string> users);
[Throws=CryptoStoreError]
Request? get_missing_sessions(sequence<string> users);
[Throws=CryptoStoreError]
sequence<Request> share_room_key([ByRef] string room_id, sequence<string> users);
[Throws=CryptoStoreError]
void receive_unencrypted_verification_event([ByRef] string event, [ByRef] string room_id);
sequence<VerificationRequest> get_verification_requests([ByRef] string user_id);
VerificationRequest? get_verification_request([ByRef] string user_id, [ByRef] string flow_id);
Verification? get_verification([ByRef] string user_id, [ByRef] string flow_id);
[Throws=CryptoStoreError]
VerificationRequest? request_verification(
[ByRef] string user_id,
[ByRef] string room_id,
[ByRef] string event_id,
sequence<string> methods
);
[Throws=CryptoStoreError]
string? verification_request_content(
[ByRef] string user_id,
sequence<string> methods
);
[Throws=CryptoStoreError]
RequestVerificationResult? request_self_verification(sequence<string> methods);
[Throws=CryptoStoreError]
RequestVerificationResult? request_verification_with_device(
[ByRef] string user_id,
[ByRef] string device_id,
sequence<string> methods
);
OutgoingVerificationRequest? accept_verification_request(
[ByRef] string user_id,
[ByRef] string flow_id,
sequence<string> methods
);
[Throws=CryptoStoreError]
ConfirmVerificationResult? confirm_verification([ByRef] string user_id, [ByRef] string flow_id);
OutgoingVerificationRequest? cancel_verification(
[ByRef] string user_id,
[ByRef] string flow_id,
[ByRef] string cancel_code
);
[Throws=CryptoStoreError]
StartSasResult? start_sas_with_device([ByRef] string user_id, [ByRef] string device_id);
[Throws=CryptoStoreError]
StartSasResult? start_sas_verification([ByRef] string user_id, [ByRef] string flow_id);
OutgoingVerificationRequest? accept_sas_verification([ByRef] string user_id, [ByRef] string flow_id);
sequence<i32>? get_emoji_index([ByRef] string user_id, [ByRef] string flow_id);
sequence<i32>? get_decimals([ByRef] string user_id, [ByRef] string flow_id);
[Throws=CryptoStoreError]
QrCode? start_qr_verification([ByRef] string user_id, [ByRef] string flow_id);
ScanResult? scan_qr_code([ByRef] string user_id, [ByRef] string flow_id, [ByRef] string data);
string? generate_qr_code([ByRef] string user_id, [ByRef] string flow_id);
[Throws=DecryptionError]
KeyRequestPair request_room_key([ByRef] string event, [ByRef] string room_id);
[Throws=CryptoStoreError]
string export_keys([ByRef] string passphrase, i32 rounds);
[Throws=KeyImportError]
KeysImportResult import_keys(
[ByRef] string keys,
[ByRef] string passphrase,
ProgressListener progress_listener
);
[Throws=KeyImportError]
KeysImportResult import_decrypted_keys(
[ByRef] string keys,
ProgressListener progress_listener
);
[Throws=CryptoStoreError]
void discard_room_key([ByRef] string room_id);
CrossSigningStatus cross_signing_status();
[Throws=CryptoStoreError]
BootstrapCrossSigningResult bootstrap_cross_signing();
CrossSigningKeyExport? export_cross_signing_keys();
[Throws=SecretImportError]
void import_cross_signing_keys(CrossSigningKeyExport export);
[Throws=CryptoStoreError]
boolean is_identity_verified([ByRef] string user_id);
record<DOMString, record<DOMString, string>> sign([ByRef] string message);
[Throws=DecodeError]
void enable_backup_v1(MegolmV1BackupKey key, string version);
[Throws=CryptoStoreError]
void disable_backup();
[Throws=CryptoStoreError]
Request? backup_room_keys();
[Throws=CryptoStoreError]
void save_recovery_key(BackupRecoveryKey? key, string? version);
[Throws=CryptoStoreError]
RoomKeyCounts room_key_counts();
[Throws=CryptoStoreError]
BackupKeys? get_backup_keys();
boolean backup_enabled();
[Throws=CryptoStoreError]
boolean verify_backup([ByRef] string auth_data);
};
dictionary PassphraseInfo {
string private_key_salt;
i32 private_key_iterations;
};
dictionary MegolmV1BackupKey {
string public_key;
record<DOMString, record<DOMString, string>> signatures;
PassphraseInfo? passphrase_info;
string backup_algorithm;
};
interface BackupKeys {
BackupRecoveryKey recovery_key();
string backup_version();
};
dictionary RoomKeyCounts {
i64 total;
i64 backed_up;
};
[Error]
enum DecodeError {
"Decode",
"CryptoStore",
};
interface BackupRecoveryKey {
constructor();
[Name=from_passphrase]
constructor(string passphrase, string salt, i32 rounds);
[Name=new_from_passphrase]
constructor(string passphrase);
[Name=from_base64, Throws=DecodeError]
constructor(string key);
[Name=from_base58, Throws=DecodeError]
constructor(string key);
string to_base58();
string to_base64();
MegolmV1BackupKey megolm_v1_public_key();
[Throws=PkDecryptionError]
string decrypt_v1(string ephemeral_key, string mac, string ciphertext);
};
dictionary MigrationData {
PickledAccount account;
sequence<PickledSession> sessions;
sequence<PickledInboundGroupSession> inbound_group_sessions;
string? backup_version;
string? backup_recovery_key;
sequence<u8> pickle_key;
CrossSigningKeyExport cross_signing;
sequence<string> tracked_users;
};
dictionary PickledAccount {
string user_id;
string device_id;
string pickle;
boolean shared;
i64 uploaded_signed_key_count;
};
dictionary PickledSession {
string pickle;
string sender_key;
boolean created_using_fallback_key;
string creation_time;
string last_use_time;
};
dictionary PickledInboundGroupSession {
string pickle;
string sender_key;
record<DOMString, string> signing_key;
string room_id;
sequence<string> forwarding_chains;
boolean imported;
boolean backed_up;
};
+52 -28
View File
@@ -4,8 +4,12 @@ use std::collections::HashMap;
use http::Response;
use matrix_sdk_crypto::{
IncomingResponse, 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::{
@@ -19,7 +23,7 @@ use ruma::{
},
},
message::send_message_event::v3::Response as RoomMessageResponse,
sync::sync_events::v3::DeviceLists as RumaDeviceLists,
sync::sync_events::DeviceLists as RumaDeviceLists,
to_device::send_event_to_device::v3::Response as ToDeviceResponse,
},
assign,
@@ -28,6 +32,7 @@ use ruma::{
};
use serde_json::json;
#[derive(uniffi::Record)]
pub struct SignatureUploadRequest {
pub body: String,
}
@@ -41,6 +46,7 @@ impl From<RustSignatureUploadRequest> for SignatureUploadRequest {
}
}
#[derive(uniffi::Record)]
pub struct UploadSigningKeysRequest {
pub master_key: String,
pub self_signing_key: String,
@@ -66,22 +72,30 @@ impl From<RustUploadSigningKeysRequest> for UploadSigningKeysRequest {
}
}
#[derive(uniffi::Record)]
pub struct BootstrapCrossSigningResult {
/// Optional request to upload some device keys alongside.
///
/// Must be sent first if present, and marked with `mark_request_as_sent`.
pub upload_keys_request: Option<Request>,
/// Request to upload the signing keys. Must be sent second.
pub upload_signing_keys_request: UploadSigningKeysRequest,
pub signature_request: SignatureUploadRequest,
/// Request to upload the keys signatures, including for the signing keys
/// and optionally for the device keys. Must be sent last.
pub upload_signature_request: SignatureUploadRequest,
}
impl From<(RustUploadSigningKeysRequest, RustSignatureUploadRequest)>
for BootstrapCrossSigningResult
{
fn from(requests: (RustUploadSigningKeysRequest, RustSignatureUploadRequest)) -> Self {
impl From<CrossSigningBootstrapRequests> for BootstrapCrossSigningResult {
fn from(requests: CrossSigningBootstrapRequests) -> Self {
Self {
upload_signing_keys_request: requests.0.into(),
signature_request: requests.1.into(),
upload_signing_keys_request: requests.upload_signing_keys_req.into(),
upload_keys_request: requests.upload_keys_req.map(Request::from),
upload_signature_request: requests.upload_signatures_req.into(),
}
}
}
#[derive(uniffi::Enum)]
pub enum OutgoingVerificationRequest {
ToDevice { request_id: String, event_type: String, body: String },
InRoom { request_id: String, room_id: String, event_type: String, content: String },
@@ -112,20 +126,20 @@ impl From<ToDeviceRequest> for OutgoingVerificationRequest {
}
}
#[derive(Debug)]
#[derive(Debug, uniffi::Enum)]
pub enum Request {
ToDevice { request_id: String, event_type: String, body: String },
KeysUpload { request_id: String, body: String },
KeysQuery { request_id: String, users: Vec<String> },
KeysClaim { request_id: String, one_time_keys: HashMap<String, HashMap<String, String>> },
KeysBackup { request_id: String, version: String, rooms: String },
RoomMessage { request_id: String, room_id: String, event_type: String, content: String },
SignatureUpload { request_id: String, body: String },
KeysBackup { request_id: String, version: String, rooms: String },
}
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) => {
@@ -138,7 +152,7 @@ impl From<OutgoingRequest> for Request {
Request::KeysUpload {
request_id: r.request_id().to_string(),
body: serde_json::to_string(&body)
.expect("Can't serialize keys upload request"),
.expect("Can't serialize `/keys/upload` request"),
}
}
KeysQuery(k) => {
@@ -153,12 +167,6 @@ impl From<OutgoingRequest> for Request {
},
RoomMessage(r) => Request::from(r),
KeysClaim(c) => (r.request_id().to_owned(), c.clone()).into(),
KeysBackup(b) => Request::KeysBackup {
request_id: r.request_id().to_string(),
version: b.version.to_owned(),
rooms: serde_json::to_string(&b.rooms)
.expect("Can't serialize keys backup request"),
},
}
}
}
@@ -193,6 +201,19 @@ impl From<(OwnedTransactionId, KeysClaimRequest)> for Request {
}
}
impl From<(OwnedTransactionId, KeysBackupRequest)> for Request {
fn from(request_tuple: (OwnedTransactionId, KeysBackupRequest)) -> Self {
let (request_id, request) = request_tuple;
Request::KeysBackup {
request_id: request_id.to_string(),
version: request.version.to_owned(),
rooms: serde_json::to_string(&request.rooms)
.expect("Can't serialize keys backup request"),
}
}
}
impl From<&ToDeviceRequest> for Request {
fn from(r: &ToDeviceRequest) -> Self {
Request::ToDevice {
@@ -221,6 +242,7 @@ pub(crate) fn response_from_string(body: &str) -> Response<Vec<u8>> {
.expect("Can't create HTTP response")
}
#[derive(uniffi::Enum)]
pub enum RequestType {
KeysQuery,
KeysClaim,
@@ -231,6 +253,7 @@ pub enum RequestType {
RoomMessage,
}
#[derive(uniffi::Record)]
pub struct DeviceLists {
pub changed: Vec<String>,
pub left: Vec<String>,
@@ -253,6 +276,7 @@ impl From<DeviceLists> for RumaDeviceLists {
}
}
#[derive(uniffi::Record)]
pub struct KeysImportResult {
/// The number of room keys that were imported.
pub imported: i64,
@@ -317,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),
}
}
}
+12 -5
View File
@@ -1,9 +1,10 @@
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 {
/// Our own user identity.
Own {
@@ -17,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 {
@@ -26,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();
@@ -43,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();
@@ -53,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(),
}
}
})
+726 -152
View File
@@ -1,105 +1,465 @@
use std::sync::Arc;
use futures_util::{Stream, StreamExt};
use matrix_sdk_crypto::{
CancelInfo as RustCancelInfo, QrVerification as InnerQr, Sas as InnerSas,
VerificationRequest as InnerVerificationRequest,
matrix_sdk_qrcode::QrVerificationData, CancelInfo as RustCancelInfo, QrVerification as InnerQr,
QrVerificationState, Sas as InnerSas, SasState as RustSasState,
Verification as InnerVerification, VerificationRequest as InnerVerificationRequest,
VerificationRequestState as RustVerificationRequestState,
};
use ruma::events::key::verification::VerificationMethod;
use tokio::runtime::Handle;
use vodozemac::{base64_decode, base64_encode};
use crate::{OutgoingVerificationRequest, SignatureUploadRequest};
use crate::{CryptoStoreError, OutgoingVerificationRequest, SignatureUploadRequest};
/// Enum representing the different verification flows we support.
pub enum Verification {
/// The `m.sas.v1` verification flow.
SasV1 {
#[allow(missing_docs)]
sas: Sas,
/// Listener that will be passed over the FFI to report changes to a SAS
/// verification.
#[matrix_sdk_ffi_macros::export(callback_interface)]
pub trait SasListener: Send {
/// The callback that should be called on the Rust side
///
/// # Arguments
///
/// * `state` - The current state of the SAS verification.
fn on_change(&self, state: SasState);
}
/// An Enum describing the state the SAS verification is in.
#[derive(uniffi::Enum)]
pub enum SasState {
/// 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.
Accepted,
/// The public keys have been exchanged and the short auth string can be
/// presented to the user.
KeysExchanged {
/// The emojis that represent the short auth string, will be `None` if
/// the emoji SAS method wasn't one of accepted protocols.
emojis: Option<Vec<i32>>,
/// The list of decimals that represent the short auth string.
decimals: Vec<i32>,
},
/// The `m.qr_code.scan.v1`, `m.qr_code.show.v1`, and `m.reciprocate.v1`
/// verification flow.
QrCodeV1 {
#[allow(missing_docs)]
qrcode: QrCode,
/// The verification process has been confirmed from our side, we're waiting
/// for the other side to confirm as well.
Confirmed,
/// The verification process has been successfully concluded.
Done,
/// The verification process has been cancelled.
Cancelled {
/// Information about the reason of the cancellation.
cancel_info: CancelInfo,
},
}
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 {
emojis: emojis.map(|e| e.indices.map(|i| i as i32).to_vec()),
decimals: [decimals.0.into(), decimals.1.into(), decimals.2.into()].to_vec(),
},
RustSasState::Confirmed => Self::Confirmed,
RustSasState::Done { .. } => Self::Done,
RustSasState::Cancelled(c) => Self::Cancelled { cancel_info: c.into() },
}
}
}
/// Enum representing the different verification flows we support.
#[derive(uniffi::Object)]
pub struct Verification {
pub(crate) inner: InnerVerification,
pub(crate) runtime: Handle,
}
#[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.
pub fn as_sas(&self) -> Option<Arc<Sas>> {
if let InnerVerification::SasV1(sas) = &self.inner {
Some(Sas { inner: sas.to_owned(), runtime: self.runtime.to_owned() }.into())
} else {
None
}
}
/// Try to represent the `Verification` as an `QrCode` verification object,
/// returns `None` if the verification is not a `QrCode` verification.
pub fn as_qr(&self) -> Option<Arc<QrCode>> {
if let InnerVerification::QrV1(qr) = &self.inner {
Some(QrCode { inner: qr.to_owned(), runtime: self.runtime.to_owned() }.into())
} else {
None
}
}
}
/// The `m.sas.v1` verification flow.
#[derive(uniffi::Object)]
pub struct Sas {
/// The other user that is participating in the verification flow
pub other_user_id: String,
/// The other user's device that is participating in the verification flow
pub other_device_id: String,
/// The unique ID of this verification flow, will be a random string for
/// to-device events or a event ID for in-room events.
pub flow_id: String,
/// The room ID where this verification is happening, will be `None` if the
/// verification is going through to-device messages
pub room_id: Option<String>,
/// Did we initiate the verification flow
pub we_started: bool,
/// Has the non-initiating side accepted the verification flow
pub has_been_accepted: bool,
/// Can the short auth string be presented
pub can_be_presented: bool,
/// Does the flow support the emoji representation of the short auth string
pub supports_emoji: bool,
/// Have we confirmed that the short auth strings match
pub have_we_confirmed: bool,
/// Has the verification completed successfully
pub is_done: bool,
/// Has the flow been cancelled
pub is_cancelled: bool,
/// Information about the cancellation of the flow, will be `None` if the
/// flow hasn't been cancelled
pub cancel_info: Option<CancelInfo>,
pub(crate) inner: InnerSas,
pub(crate) runtime: Handle,
}
#[matrix_sdk_ffi_macros::export]
impl Sas {
/// Get the user id of the other side.
pub fn other_user_id(&self) -> String {
self.inner.other_user_id().to_string()
}
/// Get the device ID of the other side.
pub fn other_device_id(&self) -> String {
self.inner.other_device_id().to_string()
}
/// Get the unique ID that identifies this SAS verification flow.
pub fn flow_id(&self) -> String {
self.inner.flow_id().as_str().to_owned()
}
/// Get the room id if the verification is happening inside a room.
pub fn room_id(&self) -> Option<String> {
self.inner.room_id().map(|r| r.to_string())
}
/// Is the SAS flow done.
pub fn is_done(&self) -> bool {
self.inner.is_done()
}
/// Did we initiate the verification flow.
pub fn we_started(&self) -> bool {
self.inner.we_started()
}
/// Accept that we're going forward with the short auth string verification.
pub fn accept(&self) -> Option<OutgoingVerificationRequest> {
self.inner.accept().map(|r| r.into())
}
/// Confirm a verification was successful.
///
/// This method should be called if a short auth string should be confirmed
/// as matching.
pub fn confirm(&self) -> Result<Option<ConfirmVerificationResult>, CryptoStoreError> {
let (requests, signature_request) = self.runtime.block_on(self.inner.confirm())?;
let requests = requests.into_iter().map(|r| r.into()).collect();
Ok(Some(ConfirmVerificationResult {
requests,
signature_request: signature_request.map(|s| s.into()),
}))
}
/// Cancel the SAS verification using the given cancel code.
///
/// # 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]
///
/// [spec]: https://spec.matrix.org/unstable/client-server-api/#mkeyverificationcancel
pub fn cancel(&self, cancel_code: String) -> Option<OutgoingVerificationRequest> {
self.inner.cancel_with_code(cancel_code.into()).map(|r| r.into())
}
/// Get a list of emoji indices of the emoji representation of the short
/// auth string.
///
/// *Note*: A SAS verification needs to be started and in the presentable
/// state for this to return the list of emoji indices, otherwise returns
/// `None`.
pub fn get_emoji_indices(&self) -> Option<Vec<i32>> {
self.inner.emoji_index().map(|v| v.iter().map(|i| (*i).into()).collect())
}
/// Get the decimal representation of the short auth string.
///
/// *Note*: A SAS verification needs to be started and in the presentable
/// state for this to return the list of decimals, otherwise returns
/// `None`.
pub fn get_decimals(&self) -> Option<Vec<i32>> {
self.inner.decimals().map(|v| [v.0.into(), v.1.into(), v.2.into()].to_vec())
}
/// Set a listener for changes in the SAS verification process.
///
/// The given callback will be called whenever the state changes.
///
/// This method can be used to react to changes in the state of the
/// verification process, or rather the method can be used to handle
/// each step of the verification process.
///
/// This method will spawn a tokio task on the Rust side, once we reach the
/// Done or Cancelled state, the task will stop listening for changes.
///
/// # Flowchart
///
/// The flow of the verification process is pictured bellow. Please note
/// that the process can be cancelled at each step of the process.
/// Either side can cancel the process.
///
/// ```text
/// ┌───────┐
/// │Started│
/// └───┬───┘
/// │
/// ┌────⌄───┐
/// │Accepted│
/// └────┬───┘
/// │
/// ┌───────⌄──────┐
/// │Keys Exchanged│
/// └───────┬──────┘
/// │
/// ________⌄________
/// ╲ ┌─────────┐
/// Does the short ╲______│Cancelled│
/// ╲ auth string match no └─────────┘
/// ╲_________________
/// │yes
/// │
/// ┌────⌄────┐
/// │Confirmed│
/// └────┬────┘
/// │
/// ┌───⌄───┐
/// │ Done │
/// └───────┘
/// ```
pub fn set_changes_listener(&self, listener: Box<dyn SasListener>) {
let stream = self.inner.changes();
self.runtime.spawn(Self::changes_listener(stream, listener));
}
/// Get the current state of the SAS verification process.
pub fn state(&self) -> SasState {
self.inner.state().into()
}
}
impl Sas {
async fn changes_listener(
mut stream: impl Stream<Item = RustSasState> + std::marker::Unpin,
listener: Box<dyn SasListener>,
) {
while let Some(state) = stream.next().await {
// If we receive a done or a cancelled state we're at the end of our road, we
// break out of the loop to deallocate the stream and finish the
// task.
let should_break =
matches!(state, RustSasState::Done { .. } | RustSasState::Cancelled { .. });
listener.on_change(state.into());
if should_break {
break;
}
}
}
}
/// Listener that will be passed over the FFI to report changes to a QrCode
/// verification.
#[matrix_sdk_ffi_macros::export(callback_interface)]
pub trait QrCodeListener: Send {
/// The callback that should be called on the Rust side
///
/// # Arguments
///
/// * `state` - The current state of the QrCode verification.
fn on_change(&self, state: QrCodeState);
}
/// An Enum describing the state the QrCode verification is in.
#[derive(uniffi::Enum)]
pub enum QrCodeState {
/// The QR verification has been started.
Started,
/// The QR verification has been scanned by the other side.
Scanned,
/// The scanning of the QR code has been confirmed by us.
Confirmed,
/// We have successfully scanned the QR code and are able to send a
/// reciprocation event.
Reciprocated,
/// The verification process has been successfully concluded.
Done,
/// The verification process has been cancelled.
Cancelled {
/// Information about the reason of the cancellation.
cancel_info: CancelInfo,
},
}
impl From<QrVerificationState> for QrCodeState {
fn from(value: QrVerificationState) -> Self {
match value {
QrVerificationState::Started => Self::Started,
QrVerificationState::Scanned => Self::Scanned,
QrVerificationState::Confirmed => Self::Confirmed,
QrVerificationState::Reciprocated => Self::Reciprocated,
QrVerificationState::Done { .. } => Self::Done,
QrVerificationState::Cancelled(c) => Self::Cancelled { cancel_info: c.into() },
}
}
}
/// The `m.qr_code.scan.v1`, `m.qr_code.show.v1`, and `m.reciprocate.v1`
/// verification flow.
#[derive(uniffi::Object)]
pub struct QrCode {
/// The other user that is participating in the verification flow
pub other_user_id: String,
/// The other user's device that is participating in the verification flow
pub other_device_id: String,
/// The unique ID of this verification flow, will be a random string for
/// to-device events or a event ID for in-room events.
pub flow_id: String,
/// The room ID where this verification is happening, will be `None` if the
/// verification is going through to-device messages
pub room_id: Option<String>,
/// Did we initiate the verification flow
pub we_started: bool,
/// Has the QR code been scanned by the other side
pub other_side_scanned: bool,
/// Has the scanning of the QR code been confirmed by us
pub has_been_confirmed: bool,
/// Did we scan the QR code and sent out a reciprocation
pub reciprocated: bool,
/// Has the verification completed successfully
pub is_done: bool,
/// Has the flow been cancelled
pub is_cancelled: bool,
/// Information about the cancellation of the flow, will be `None` if the
/// flow hasn't been cancelled
pub cancel_info: Option<CancelInfo>,
pub(crate) inner: InnerQr,
pub(crate) runtime: Handle,
}
impl From<InnerQr> for QrCode {
fn from(qr: InnerQr) -> Self {
Self {
other_user_id: qr.other_user_id().to_string(),
flow_id: qr.flow_id().as_str().to_owned(),
is_cancelled: qr.is_cancelled(),
is_done: qr.is_done(),
cancel_info: qr.cancel_info().map(|c| c.into()),
reciprocated: qr.reciprocated(),
we_started: qr.we_started(),
other_side_scanned: qr.has_been_scanned(),
has_been_confirmed: qr.has_been_confirmed(),
other_device_id: qr.other_device_id().to_string(),
room_id: qr.room_id().map(|r| r.to_string()),
#[matrix_sdk_ffi_macros::export]
impl QrCode {
/// Get the user id of the other side.
pub fn other_user_id(&self) -> String {
self.inner.other_user_id().to_string()
}
/// Get the device ID of the other side.
pub fn other_device_id(&self) -> String {
self.inner.other_device_id().to_string()
}
/// Get the unique ID that identifies this QR code verification flow.
pub fn flow_id(&self) -> String {
self.inner.flow_id().as_str().to_owned()
}
/// Get the room id if the verification is happening inside a room.
pub fn room_id(&self) -> Option<String> {
self.inner.room_id().map(|r| r.to_string())
}
/// Is the QR code verification done.
pub fn is_done(&self) -> bool {
self.inner.is_done()
}
/// Has the verification flow been cancelled.
pub fn is_cancelled(&self) -> bool {
self.inner.is_cancelled()
}
/// Did we initiate the verification flow.
pub fn we_started(&self) -> bool {
self.inner.we_started()
}
/// Get the CancelInfo of this QR code verification object.
///
/// Will be `None` if the flow has not been cancelled.
pub fn cancel_info(&self) -> Option<CancelInfo> {
self.inner.cancel_info().map(|c| c.into())
}
/// Has the QR verification been scanned by the other side.
///
/// When the verification object is in this state it's required that the
/// user confirms that the other side has scanned the QR code.
pub fn has_been_scanned(&self) -> bool {
self.inner.has_been_scanned()
}
/// Have we successfully scanned the QR code and are able to send a
/// reciprocation event.
pub fn reciprocated(&self) -> bool {
self.inner.reciprocated()
}
/// Cancel the QR code verification using the given cancel code.
///
/// # 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]
///
/// [spec]: https://spec.matrix.org/unstable/client-server-api/#mkeyverificationcancel
pub fn cancel(&self, cancel_code: String) -> Option<OutgoingVerificationRequest> {
self.inner.cancel_with_code(cancel_code.into()).map(|r| r.into())
}
/// Confirm a verification was successful.
///
/// This method should be called if we want to confirm that the other side
/// has scanned our QR code.
pub fn confirm(&self) -> Option<ConfirmVerificationResult> {
self.inner.confirm_scanning().map(|r| ConfirmVerificationResult {
requests: vec![r.into()],
signature_request: None,
})
}
/// Generate data that should be encoded as a QR code.
///
/// This method should be called right before a QR code should be displayed,
/// the returned data is base64 encoded (without padding) and needs to be
/// decoded on the other side before it can be put through a QR code
/// generator.
pub fn generate_qr_code(&self) -> Option<String> {
self.inner.to_bytes().map(base64_encode).ok()
}
/// Set a listener for changes in the QrCode verification process.
///
/// The given callback will be called whenever the state changes.
pub fn set_changes_listener(&self, listener: Box<dyn QrCodeListener>) {
let stream = self.inner.changes();
self.runtime.spawn(Self::changes_listener(stream, listener));
}
/// Get the current state of the QrCode verification process.
pub fn state(&self) -> QrCodeState {
self.inner.state().into()
}
}
impl QrCode {
async fn changes_listener(
mut stream: impl Stream<Item = QrVerificationState> + std::marker::Unpin,
listener: Box<dyn QrCodeListener>,
) {
while let Some(state) = stream.next().await {
// If we receive a done or a cancelled state we're at the end of our road, we
// break out of the loop to deallocate the stream and finish the
// task.
let should_break = matches!(
state,
QrVerificationState::Done { .. } | QrVerificationState::Cancelled { .. }
);
listener.on_change(state.into());
if should_break {
break;
}
}
}
}
/// Information on why a verification flow has been cancelled and by whom.
#[derive(uniffi::Record)]
pub struct CancelInfo {
/// The textual representation of the cancel reason
pub reason: String,
@@ -120,52 +480,37 @@ impl From<RustCancelInfo> for CancelInfo {
}
/// A result type for starting SAS verifications.
#[derive(uniffi::Record)]
pub struct StartSasResult {
/// The SAS verification object that got created.
pub sas: Sas,
pub sas: Arc<Sas>,
/// The request that needs to be sent out to notify the other side that a
/// SAS verification should start.
pub request: OutgoingVerificationRequest,
}
/// A result type for scanning QR codes.
#[derive(uniffi::Record)]
pub struct ScanResult {
/// The QR code verification object that got created.
pub qr: QrCode,
pub qr: Arc<QrCode>,
/// The request that needs to be sent out to notify the other side that a
/// QR code verification should start.
pub request: OutgoingVerificationRequest,
}
impl From<InnerSas> for Sas {
fn from(sas: InnerSas) -> Self {
Self {
other_user_id: sas.other_user_id().to_string(),
other_device_id: sas.other_device_id().to_string(),
flow_id: sas.flow_id().as_str().to_owned(),
is_cancelled: sas.is_cancelled(),
is_done: sas.is_done(),
can_be_presented: sas.can_be_presented(),
supports_emoji: sas.supports_emoji(),
have_we_confirmed: sas.have_we_confirmed(),
we_started: sas.we_started(),
room_id: sas.room_id().map(|r| r.to_string()),
has_been_accepted: sas.has_been_accepted(),
cancel_info: sas.cancel_info().map(|c| c.into()),
}
}
}
/// A result type for requesting verifications.
#[derive(uniffi::Record)]
pub struct RequestVerificationResult {
/// The verification request object that got created.
pub verification: VerificationRequest,
pub verification: Arc<VerificationRequest>,
/// The request that needs to be sent out to notify the other side that
/// we're requesting verification to begin.
pub request: OutgoingVerificationRequest,
}
/// A result type for confirming verifications.
#[derive(uniffi::Record)]
pub struct ConfirmVerificationResult {
/// The requests that needs to be sent out to notify the other side that we
/// confirmed the verification.
@@ -175,58 +520,287 @@ pub struct ConfirmVerificationResult {
pub signature_request: Option<SignatureUploadRequest>,
}
/// The verificatoin request object which then can transition into some concrete
/// verification method
pub struct VerificationRequest {
/// The other user that is participating in the verification flow
pub other_user_id: String,
/// The other user's device that is participating in the verification flow
pub other_device_id: Option<String>,
/// The unique ID of this verification flow, will be a random string for
/// to-device events or a event ID for in-room events.
pub flow_id: String,
/// The room ID where this verification is happening, will be `None` if the
/// verification is going through to-device messages
pub room_id: Option<String>,
/// Did we initiate the verification flow
pub we_started: bool,
/// Did both parties aggree to verification
pub is_ready: bool,
/// Did another device respond to the verification request
pub is_passive: bool,
/// Has the verification completed successfully
pub is_done: bool,
/// Has the flow been cancelled
pub is_cancelled: bool,
/// The list of verification methods that the other side advertised as
/// supported
pub their_methods: Option<Vec<String>>,
/// The list of verification methods that we advertised as supported
pub our_methods: Option<Vec<String>>,
/// Information about the cancellation of the flow, will be `None` if the
/// flow hasn't been cancelled
pub cancel_info: Option<CancelInfo>,
/// Listener that will be passed over the FFI to report changes to a
/// verification request.
#[matrix_sdk_ffi_macros::export(callback_interface)]
pub trait VerificationRequestListener: Send {
/// The callback that should be called on the Rust side
///
/// # Arguments
///
/// * `state` - The current state of the verification request.
fn on_change(&self, state: VerificationRequestState);
}
impl From<InnerVerificationRequest> for VerificationRequest {
fn from(v: InnerVerificationRequest) -> Self {
Self {
other_user_id: v.other_user().to_string(),
other_device_id: v.other_device_id().map(|d| d.to_string()),
flow_id: v.flow_id().as_str().to_owned(),
is_cancelled: v.is_cancelled(),
is_done: v.is_done(),
is_ready: v.is_ready(),
room_id: v.room_id().map(|r| r.to_string()),
we_started: v.we_started(),
is_passive: v.is_passive(),
cancel_info: v.cancel_info().map(|c| c.into()),
their_methods: v
.their_supported_methods()
.map(|v| v.into_iter().map(|m| m.to_string()).collect()),
our_methods: v
.our_supported_methods()
.map(|v| v.into_iter().map(|m| m.to_string()).collect()),
/// An Enum describing the state the QrCode verification is in.
#[derive(uniffi::Enum)]
pub enum VerificationRequestState {
/// The verification request was sent
Requested,
/// The verification request is ready to start a verification flow.
Ready {
/// The verification methods supported by the other side.
their_methods: Vec<String>,
/// The verification methods supported by the us.
our_methods: Vec<String>,
},
/// The verification flow that was started with this request has finished.
Done,
/// The verification process has been cancelled.
Cancelled {
/// Information about the reason of the cancellation.
cancel_info: CancelInfo,
},
}
/// The verificatoin request object which then can transition into some concrete
/// verification method
#[derive(uniffi::Object)]
pub struct VerificationRequest {
pub(crate) inner: InnerVerificationRequest,
pub(crate) runtime: Handle,
}
#[matrix_sdk_ffi_macros::export]
impl VerificationRequest {
/// The id of the other user that is participating in this verification
/// request.
pub fn other_user_id(&self) -> String {
self.inner.other_user().to_string()
}
/// The id of the other device that is participating in this verification.
pub fn other_device_id(&self) -> Option<String> {
self.inner.other_device_id().map(|d| d.to_string())
}
/// Get the unique ID of this verification request
pub fn flow_id(&self) -> String {
self.inner.flow_id().as_str().to_owned()
}
/// Get the room id if the verification is happening inside a room.
pub fn room_id(&self) -> Option<String> {
self.inner.room_id().map(|r| r.to_string())
}
/// Has the verification flow that was started with this request finished.
pub fn is_done(&self) -> bool {
self.inner.is_done()
}
/// Is the verification request ready to start a verification flow.
pub fn is_ready(&self) -> bool {
self.inner.is_ready()
}
/// Did we initiate the verification request
pub fn we_started(&self) -> bool {
self.inner.we_started()
}
/// Has the verification request been answered by another device.
pub fn is_passive(&self) -> bool {
self.inner.is_passive()
}
/// Has the verification flow that been cancelled.
pub fn is_cancelled(&self) -> bool {
self.inner.is_cancelled()
}
/// Get info about the cancellation if the verification request has been
/// cancelled.
pub fn cancel_info(&self) -> Option<CancelInfo> {
self.inner.cancel_info().map(|v| v.into())
}
/// Get the supported verification methods of the other side.
///
/// Will be present only if the other side requested the verification or if
/// we're in the ready state.
pub fn their_supported_methods(&self) -> Option<Vec<String>> {
self.inner.their_supported_methods().map(|m| m.iter().map(|m| m.to_string()).collect())
}
/// Get our own supported verification methods that we advertised.
///
/// Will be present only we requested the verification or if we're in the
/// ready state.
pub fn our_supported_methods(&self) -> Option<Vec<String>> {
self.inner.our_supported_methods().map(|m| m.iter().map(|m| m.to_string()).collect())
}
/// Accept a verification requests that we share with the given user with
/// the given flow id.
///
/// This will move the verification request into the ready state.
///
/// # Arguments
///
/// * `user_id` - The ID of the user for which we would like to accept the
/// 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.
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())
}
/// Cancel a verification for the given user with the given flow id using
/// the given cancel code.
pub fn cancel(&self) -> Option<OutgoingVerificationRequest> {
self.inner.cancel().map(|r| r.into())
}
/// Transition from a verification request into short auth string based
/// verification.
///
/// # Arguments
///
/// * `user_id` - The ID of the user for which we would like to start the
/// SAS verification.
///
/// * `flow_id` - The ID of the verification request that initiated the
/// 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() }),
request: r.into(),
}))
}
/// Transition from a verification request into QR code verification.
///
/// This method should be called when one wants to display a QR code so the
/// other side can scan it and move the QR code verification forward.
///
/// # Arguments
///
/// * `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.
pub fn start_qr_verification(&self) -> Result<Option<Arc<QrCode>>, CryptoStoreError> {
Ok(self
.runtime
.block_on(self.inner.generate_qr_code())?
.map(|qr| QrCode { inner: qr, runtime: self.runtime.clone() }.into()))
}
/// Pass data from a scanned QR code to an active verification request and
/// transition into QR code verification.
///
/// This requires an active `VerificationRequest` to succeed, returns `None`
/// if no `VerificationRequest` is found or if the QR code data is invalid.
///
/// # Arguments
///
/// * `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.
///
/// * `data` - The data that was extracted from the scanned QR code as an
/// 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()?;
if let Some(qr) = self.runtime.block_on(self.inner.scan_qr_code(data)).ok()? {
let request = qr.reciprocate()?;
Some(ScanResult {
qr: QrCode { inner: qr, runtime: self.runtime.clone() }.into(),
request: request.into(),
})
} else {
None
}
}
/// Set a listener for changes in the verification request
///
/// The given callback will be called whenever the state changes.
pub fn set_changes_listener(&self, listener: Box<dyn VerificationRequestListener>) {
let stream = self.inner.changes();
self.runtime.spawn(Self::changes_listener(self.inner.to_owned(), stream, listener));
}
/// Get the current state of the verification request.
pub fn state(&self) -> VerificationRequestState {
Self::convert_verification_request(&self.inner, self.inner.state())
}
}
impl VerificationRequest {
fn convert_verification_request(
request: &InnerVerificationRequest,
value: RustVerificationRequestState,
) -> VerificationRequestState {
match value {
// The clients do not need to distinguish `Created` and `Requested` state
RustVerificationRequestState::Created { .. } => VerificationRequestState::Requested,
RustVerificationRequestState::Requested { .. } => VerificationRequestState::Requested,
RustVerificationRequestState::Ready {
their_methods,
our_methods,
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(),
},
RustVerificationRequestState::Done => VerificationRequestState::Done,
RustVerificationRequestState::Transitioned { .. } => {
let their_methods = request
.their_supported_methods()
.expect("The transitioned state should know the other side's methods")
.into_iter()
.map(|m| m.to_string())
.collect();
let our_methods = request
.our_supported_methods()
.expect("The transitioned state should know our own supported methods")
.iter()
.map(|m| m.to_string())
.collect();
VerificationRequestState::Ready { their_methods, our_methods }
}
RustVerificationRequestState::Cancelled(c) => {
VerificationRequestState::Cancelled { cancel_info: c.into() }
}
}
}
async fn changes_listener(
request: InnerVerificationRequest,
mut stream: impl Stream<Item = RustVerificationRequestState> + std::marker::Unpin,
listener: Box<dyn VerificationRequestListener>,
) {
while let Some(state) = stream.next().await {
// If we receive a done or a cancelled state we're at the end of our road, we
// break out of the loop to deallocate the stream and finish the
// task.
let should_break = matches!(
state,
RustVerificationRequestState::Done | RustVerificationRequestState::Cancelled { .. }
);
let state = Self::convert_verification_request(&request, state);
listener.on_change(state);
if should_break {
break;
}
}
}
}
@@ -0,0 +1,3 @@
fn main() {
uniffi::uniffi_bindgen_main()
}
@@ -1,2 +1,6 @@
[bindings.kotlin]
package_name = "org.matrix.rustcomponents.sdk.crypto"
cdylib_name = "matrix_sdk_crypto_ffi"
[bindings.swift]
module_name = "MatrixSDKCrypto"
@@ -1,2 +0,0 @@
[build]
target = "wasm32-unknown-unknown"
-3
View File
@@ -1,3 +0,0 @@
/docs
/node_modules
/package-lock.json
-39
View File
@@ -1,39 +0,0 @@
[package]
authors = ["Ivan Enderlin <ivane@element.io>"]
description = "Matrix encryption library, for JavaScript"
edition = "2021"
homepage = "https://github.com/matrix-org/matrix-rust-sdk"
keywords = ["matrix", "chat", "messaging", "ruma", "nio"]
license = "Apache-2.0"
name = "matrix-sdk-crypto-js"
readme = "README.md"
repository = "https://github.com/matrix-org/matrix-rust-sdk"
rust-version = "1.60"
version = "0.5.0"
[package.metadata.docs.rs]
features = ["docsrs"]
rustdoc-args = ["--cfg", "docsrs"]
[package.metadata.wasm-pack.profile.release]
wasm-opt = ['-Oz']
[lib]
crate-type = ["cdylib"]
[features]
default = []
qrcode = ["matrix-sdk-crypto/qrcode"]
docsrs = []
[dependencies]
matrix-sdk-common = { version = "0.5.0", path = "../../crates/matrix-sdk-common" }
matrix-sdk-crypto = { version = "0.5.0", path = "../../crates/matrix-sdk-crypto" }
ruma = { git = "https://github.com/ruma/ruma", rev = "96155915f", features = ["client-api-c", "js", "rand", "unstable-msc2676", "unstable-msc2677"] }
vodozemac = { git = "https://github.com/matrix-org/vodozemac/", rev = "2404f83f7d3a3779c1f518e4d949f7da9677c3dd", features = ["js"] }
wasm-bindgen = "0.2.80"
wasm-bindgen-futures = "0.4.30"
js-sys = "0.3.49"
serde_json = "1.0.79"
http = "0.2.6"
anyhow = "1.0"
-55
View File
@@ -1,55 +0,0 @@
# `matrix-sdk-crypto-js`
Welcome to the [WebAssembly] + JavaScript binding for the Rust
[`matrix-sdk-crypto`] library! WebAssembly can run anywhere, but these
bindings are designed to run on a JavaScript host. These bindings are
part of the [`matrix-rust-sdk`] project, which is a library
implementation of a [Matrix] client-server.
`matrix-sdk-crypto` is a no-network-IO implementation of a state
machine, named `OlmMachine`, that handles E2EE ([End-to-End
Encryption](https://en.wikipedia.org/wiki/End-to-end_encryption)) for
[Matrix] clients.
## Usage
These WebAssembly bindings are written in [Rust]. To build them, you
need to install the Rust compiler, see [the Install Rust
Page](https://www.rust-lang.org/tools/install). Then, the workflow is
pretty classical by using [npm], see [the Downloading and installing
Node.js and npm
Page](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm).
Once the Rust compiler, Node.js and npm are installed, you can run the
following commands:
```sh
$ npm install
$ npm run build
$ npm run test
```
A `matrix_sdk_crypto.js`, `matrix_sdk_crypto.d.ts` and a
`matrix_sdk_crypto_bg.wasm` files should be generated in the `pkg/`
directory.
TBD
## Documentation
To generate the documentation, please run the following command:
```sh
$ npm run doc
```
The documentation is generated in the `./docs` directory.
[WebAssembly]: https://webassembly.org/
[`matrix-sdk-crypto`]: https://github.com/matrix-org/matrix-rust-sdk/tree/main/crates/matrix-sdk-crypto
[`matrix-rust-sdk`]: https://github.com/matrix-org/matrix-rust-sdk
[Matrix]: https://matrix.org/
[Rust]: https://www.rust-lang.org/
[npm]: https://www.npmjs.com/
@@ -1,41 +0,0 @@
{
"name": "@matrix-org/matrix-sdk-crypto-js",
"version": "0.5.0",
"homepage": "https://github.com/matrix-org/matrix-rust-sdk",
"description": "Matrix encryption library, for JavaScript",
"license": "Apache-2.0",
"collaborators": [
"Ivan Enderlin <ivane@element.io>"
],
"repository": {
"type": "git",
"url": "https://github.com/matrix-org/matrix-rust-sdk"
},
"keywords": [
"matrix",
"chat",
"messaging",
"ruma",
"nio"
],
"main": "matrix_sdk_crypto.js",
"types": "pkg/matrix_sdk_crypto.d.ts",
"files": [
"pkg/matrix_sdk_crypto_bg.wasm",
"pkg/matrix_sdk_crypto.js",
"pkg/matrix_sdk_crypto.d.ts"
],
"devDependencies": {
"wasm-pack": "^0.10.2",
"jest": "^28.1.0",
"typedoc": "^0.22.17"
},
"engines": {
"node": ">= 10"
},
"scripts": {
"build": "RUSTFLAGS='-C opt-level=z' wasm-pack build --release --target nodejs --out-name matrix_sdk_crypto --out-dir ./pkg",
"test": "jest --verbose",
"doc": "typedoc --tsconfig ."
}
}
@@ -1,126 +0,0 @@
//! Encryption types & siblings.
use std::time::Duration;
use wasm_bindgen::prelude::*;
use crate::events;
/// Settings for an encrypted room.
///
/// This determines the algorithm and rotation periods of a group
/// session.
#[wasm_bindgen(getter_with_clone)]
#[derive(Debug, Clone)]
pub struct EncryptionSettings {
/// The encryption algorithm that should be used in the room.
pub algorithm: EncryptionAlgorithm,
/// How long the session should be used before changing it,
/// expressed in microseconds.
#[wasm_bindgen(js_name = "rotationPeriod")]
pub rotation_period: u64,
/// How many messages should be sent before changing the session.
#[wasm_bindgen(js_name = "rotationPeriodMessages")]
pub rotation_period_messages: u64,
/// The history visibility of the room when the session was
/// created.
#[wasm_bindgen(js_name = "historyVisibility")]
pub history_visibility: events::HistoryVisibility,
}
impl Default for EncryptionSettings {
fn default() -> Self {
let default = matrix_sdk_crypto::olm::EncryptionSettings::default();
Self {
algorithm: default.algorithm.into(),
rotation_period: default.rotation_period.as_micros().try_into().unwrap(),
rotation_period_messages: default.rotation_period_msgs,
history_visibility: default.history_visibility.into(),
}
}
}
#[wasm_bindgen]
impl EncryptionSettings {
/// Create a new `EncryptionSettings` with default values.
#[wasm_bindgen(constructor)]
pub fn new() -> EncryptionSettings {
Self::default()
}
}
impl From<&EncryptionSettings> for matrix_sdk_crypto::olm::EncryptionSettings {
fn from(value: &EncryptionSettings) -> Self {
Self {
algorithm: value.algorithm.clone().into(),
rotation_period: Duration::from_micros(value.rotation_period),
rotation_period_msgs: value.rotation_period_messages,
history_visibility: value.history_visibility.clone().into(),
}
}
}
/// An encryption algorithm to be used to encrypt messages sent to a
/// room.
#[wasm_bindgen]
#[derive(Debug, Clone)]
pub enum EncryptionAlgorithm {
/// Olm version 1 using Curve25519, AES-256, and SHA-256.
OlmV1Curve25519AesSha2,
/// Megolm version 1 using AES-256 and SHA-256.
MegolmV1AesSha2,
}
impl From<EncryptionAlgorithm> for ruma::EventEncryptionAlgorithm {
fn from(value: EncryptionAlgorithm) -> Self {
use EncryptionAlgorithm::*;
match value {
OlmV1Curve25519AesSha2 => Self::OlmV1Curve25519AesSha2,
MegolmV1AesSha2 => Self::MegolmV1AesSha2,
}
}
}
impl From<ruma::EventEncryptionAlgorithm> for EncryptionAlgorithm {
fn from(value: ruma::EventEncryptionAlgorithm) -> Self {
use ruma::EventEncryptionAlgorithm::*;
match value {
OlmV1Curve25519AesSha2 => Self::OlmV1Curve25519AesSha2,
MegolmV1AesSha2 => Self::MegolmV1AesSha2,
_ => unreachable!("Unknown variant"),
}
}
}
/// The verification state of the device that sent an event to us.
#[wasm_bindgen]
#[derive(Debug)]
pub enum VerificationState {
/// The device is trusted.
Trusted,
/// The device is not trusted.
Untrusted,
/// The device is not known to us.
UnknownDevice,
}
impl From<&matrix_sdk_common::deserialized_responses::VerificationState> for VerificationState {
fn from(value: &matrix_sdk_common::deserialized_responses::VerificationState) -> Self {
use matrix_sdk_common::deserialized_responses::VerificationState::*;
match value {
Trusted => Self::Trusted,
Untrusted => Self::Untrusted,
UnknownDevice => Self::UnknownDevice,
}
}
}
@@ -1,61 +0,0 @@
//! Types related to events.
use ruma::events::room::history_visibility::HistoryVisibility as RumaHistoryVisibility;
use wasm_bindgen::prelude::*;
/// Who can see a room's history.
#[wasm_bindgen]
#[derive(Debug, Clone)]
pub enum HistoryVisibility {
/// Previous events are accessible to newly joined members from
/// the point they were invited onwards.
///
/// Events stop being accessible when the member's state changes
/// to something other than *invite* or *join*.
Invited,
/// Previous events are accessible to newly joined members from
/// the point they joined the room onwards.
///
/// Events stop being accessible when the member's state changes
/// to something other than *join*.
Joined,
/// Previous events are always accessible to newly joined members.
///
/// All events in the room are accessible, even those sent when
/// the member was not a part of the room.
Shared,
/// All events while this is the `HistoryVisibility` value may be
/// shared by any participating homeserver with anyone, regardless
/// of whether they have ever joined the room.
WorldReadable,
}
impl From<HistoryVisibility> for RumaHistoryVisibility {
fn from(value: HistoryVisibility) -> Self {
use HistoryVisibility::*;
match value {
Invited => Self::Invited,
Joined => Self::Joined,
Shared => Self::Shared,
WorldReadable => Self::WorldReadable,
}
}
}
impl From<RumaHistoryVisibility> for HistoryVisibility {
fn from(value: RumaHistoryVisibility) -> Self {
use RumaHistoryVisibility::*;
match value {
Invited => Self::Invited,
Joined => Self::Joined,
Shared => Self::Shared,
WorldReadable => Self::WorldReadable,
_ => unreachable!("Unknown variant"),
}
}
}
@@ -1,26 +0,0 @@
use std::future::Future;
use js_sys::Promise;
use wasm_bindgen::{JsValue, UnwrapThrowExt};
use wasm_bindgen_futures::spawn_local;
pub(crate) fn future_to_promise<F, T>(future: F) -> Promise
where
F: Future<Output = Result<T, anyhow::Error>> + 'static,
T: Into<JsValue>,
{
let mut future = Some(future);
Promise::new(&mut |resolve, reject| {
let future = future.take().unwrap_throw();
spawn_local(async move {
match future.await {
Ok(value) => resolve.call1(&JsValue::UNDEFINED, &value.into()).unwrap_throw(),
Err(value) => {
reject.call1(&JsValue::UNDEFINED, &value.to_string().into()).unwrap_throw()
}
};
});
})
}
@@ -1,175 +0,0 @@
//! Types for [Matrix](https://matrix.org/) identifiers for devices,
//! events, keys, rooms, servers, users and URIs.
use wasm_bindgen::prelude::*;
/// A Matrix [user ID].
///
/// [user ID]: https://spec.matrix.org/v1.2/appendices/#user-identifiers
#[wasm_bindgen]
#[derive(Debug, Clone)]
pub struct UserId {
pub(crate) inner: ruma::OwnedUserId,
}
impl From<ruma::OwnedUserId> for UserId {
fn from(inner: ruma::OwnedUserId) -> Self {
Self { inner }
}
}
#[wasm_bindgen]
impl UserId {
/// Parse/validate and create a new `UserId`.
#[wasm_bindgen(constructor)]
pub fn new(id: &str) -> Result<UserId, JsError> {
Ok(Self::from(ruma::UserId::parse(id)?))
}
/// Returns the user's localpart.
#[wasm_bindgen(getter)]
pub fn localpart(&self) -> String {
self.inner.localpart().to_owned()
}
/// Returns the server name of the user ID.
#[wasm_bindgen(getter, js_name = "serverName")]
pub fn server_name(&self) -> ServerName {
ServerName { inner: self.inner.server_name().to_owned() }
}
/// Whether this user ID is a historical one.
///
/// A historical user ID is one that doesn't conform to the latest
/// specification of the user ID grammar but is still accepted
/// because it was previously allowed.
#[wasm_bindgen(js_name = "isHistorical")]
pub fn is_historical(&self) -> bool {
self.inner.is_historical()
}
/// Return the user ID as a string.
#[wasm_bindgen(js_name = "toString")]
#[allow(clippy::inherent_to_string)]
pub fn to_string(&self) -> String {
self.inner.as_str().to_owned()
}
}
/// A Matrix key ID.
///
/// Device identifiers in Matrix are completely opaque character
/// sequences. This type is provided simply for its semantic value.
#[wasm_bindgen]
#[derive(Debug, Clone)]
pub struct DeviceId {
pub(crate) inner: ruma::OwnedDeviceId,
}
impl From<ruma::OwnedDeviceId> for DeviceId {
fn from(inner: ruma::OwnedDeviceId) -> Self {
Self { inner }
}
}
#[wasm_bindgen]
impl DeviceId {
/// Create a new `DeviceId`.
#[wasm_bindgen(constructor)]
pub fn new(id: &str) -> DeviceId {
Self::from(ruma::OwnedDeviceId::from(id))
}
/// Return the device ID as a string.
#[wasm_bindgen(js_name = "toString")]
#[allow(clippy::inherent_to_string)]
pub fn to_string(&self) -> String {
self.inner.as_str().to_owned()
}
}
/// A Matrix [room ID].
///
/// [room ID]: https://spec.matrix.org/v1.2/appendices/#room-ids-and-event-ids
#[wasm_bindgen]
#[derive(Debug, Clone)]
pub struct RoomId {
pub(crate) inner: ruma::OwnedRoomId,
}
impl From<ruma::OwnedRoomId> for RoomId {
fn from(inner: ruma::OwnedRoomId) -> Self {
Self { inner }
}
}
#[wasm_bindgen]
impl RoomId {
/// Parse/validate and create a new `RoomId`.
#[wasm_bindgen(constructor)]
pub fn new(id: &str) -> Result<RoomId, JsError> {
Ok(Self::from(ruma::RoomId::parse(id)?))
}
/// Returns the user's localpart.
#[wasm_bindgen(getter)]
pub fn localpart(&self) -> String {
self.inner.localpart().to_owned()
}
/// Returns the server name of the room ID.
#[wasm_bindgen(getter, js_name = "serverName")]
pub fn server_name(&self) -> ServerName {
ServerName { inner: self.inner.server_name().to_owned() }
}
/// Return the room ID as a string.
#[wasm_bindgen(js_name = "toString")]
#[allow(clippy::inherent_to_string)]
pub fn to_string(&self) -> String {
self.inner.as_str().to_owned()
}
}
/// A Matrix-spec compliant [server name].
///
/// It consists of a host and an optional port (separated by a colon if
/// present).
///
/// [server name]: https://spec.matrix.org/v1.2/appendices/#server-name
#[wasm_bindgen]
#[derive(Debug)]
pub struct ServerName {
inner: ruma::OwnedServerName,
}
#[wasm_bindgen]
impl ServerName {
/// Parse/validate and create a new `ServerName`.
#[wasm_bindgen(constructor)]
pub fn new(name: &str) -> Result<ServerName, JsError> {
Ok(Self { inner: ruma::ServerName::parse(name)? })
}
/// Returns the host of the server name.
///
/// That is: Return the part of the server before `:<port>` or the
/// full server name if there is no port.
#[wasm_bindgen(getter)]
pub fn host(&self) -> String {
self.inner.host().to_owned()
}
/// Returns the port of the server name if any.
#[wasm_bindgen(getter)]
pub fn port(&self) -> Option<u16> {
self.inner.port()
}
/// Returns true if and only if the server name is an IPv4 or IPv6
/// address.
#[wasm_bindgen(js_name = "isIpLiteral")]
pub fn is_ip_literal(&self) -> bool {
self.inner.is_ip_literal()
}
}
-58
View File
@@ -1,58 +0,0 @@
// Copyright 2022 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.
#![doc = include_str!("../README.md")]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![warn(missing_docs, missing_debug_implementations)]
#![allow(clippy::drop_non_drop)] // triggered by wasm_bindgen code
pub mod encryption;
pub mod events;
mod future;
pub mod identifiers;
pub mod machine;
pub mod requests;
pub mod responses;
pub mod sync_events;
use js_sys::{Object, Reflect};
use wasm_bindgen::{convert::RefFromWasmAbi, prelude::*};
/// A really hacky and dirty code to downcast a `JsValue` to `T:
/// RefFromWasmAbi`, inspired by
/// https://github.com/rustwasm/wasm-bindgen/issues/2231#issuecomment-656293288.
///
/// The returned value is likely to be a `wasm_bindgen::__ref::Ref<T>`.
fn downcast<T>(value: &JsValue, classname: &str) -> Result<T::Anchor, JsError>
where
T: RefFromWasmAbi<Abi = u32>,
{
let constructor_name = Object::get_prototype_of(value).constructor().name();
if constructor_name == classname {
let pointer = Reflect::get(value, &JsValue::from_str("ptr"))
.map_err(|_| JsError::new("Failed to read the `JsValue` pointer"))?;
let pointer = pointer
.as_f64()
.ok_or_else(|| JsError::new("Failed to read the `JsValue` pointer as a `f64`"))?
as u32;
Ok(unsafe { T::ref_from_abi(pointer) })
} else {
Err(JsError::new(&format!(
"Expect an `{}` instance, received `{}` instead",
classname, constructor_name,
)))
}
}
@@ -1,446 +0,0 @@
//! The crypto specific Olm objects.
use std::collections::BTreeMap;
use js_sys::{Array, Map, Promise, Set};
use ruma::{
events::room::encrypted::OriginalSyncRoomEncryptedEvent, DeviceKeyAlgorithm,
OwnedTransactionId, UInt,
};
use serde_json::Value as JsonValue;
use wasm_bindgen::prelude::*;
use crate::{
downcast, encryption,
future::future_to_promise,
identifiers, requests,
requests::OutgoingRequest,
responses::{self, response_from_string},
sync_events,
};
/// State machine implementation of the Olm/Megolm encryption protocol
/// used for Matrix end to end encryption.
#[wasm_bindgen]
#[derive(Debug, Clone)]
pub struct OlmMachine {
inner: matrix_sdk_crypto::OlmMachine,
}
#[wasm_bindgen]
impl OlmMachine {
/// Create a new memory based `OlmMachine`.
///
/// The created machine will keep the encryption keys only in
/// memory and once the objects is dropped, the keys will be lost.
///
/// `user_id` represents the unique ID of the user that owns this
/// machine. `device_id` represents the unique ID of the device
/// that owns this machine.
#[wasm_bindgen(constructor)]
#[allow(clippy::new_ret_no_self)]
pub fn new(user_id: &identifiers::UserId, device_id: &identifiers::DeviceId) -> Promise {
let user_id = user_id.inner.clone();
let device_id = device_id.inner.clone();
future_to_promise(async move {
Ok(OlmMachine {
inner: matrix_sdk_crypto::OlmMachine::new(user_id.as_ref(), device_id.as_ref())
.await,
})
})
}
/// The unique user ID that owns this `OlmMachine` instance.
#[wasm_bindgen(getter, js_name = "userId")]
pub fn user_id(&self) -> identifiers::UserId {
identifiers::UserId::from(self.inner.user_id().to_owned())
}
/// The unique device ID that identifies this `OlmMachine`.
#[wasm_bindgen(getter, js_name = "deviceId")]
pub fn device_id(&self) -> identifiers::DeviceId {
identifiers::DeviceId::from(self.inner.device_id().to_owned())
}
/// Get the public parts of our Olm identity keys.
#[wasm_bindgen(getter, js_name = "identityKeys")]
pub fn identity_keys(&self) -> IdentityKeys {
self.inner.identity_keys().into()
}
/// Get the display name of our own device.
#[wasm_bindgen(getter, js_name = "displayName")]
pub fn display_name(&self) -> Promise {
let me = self.inner.clone();
future_to_promise(async move { Ok(me.display_name().await?) })
}
/// Get all the tracked users of our own device.
///
/// Returns a `Set<UserId>`.
#[wasm_bindgen(js_name = "trackedUsers")]
pub fn tracked_users(&self) -> Set {
let set = Set::new(&JsValue::UNDEFINED);
for user in self.inner.tracked_users() {
set.add(&identifiers::UserId::from(user).into());
}
set
}
/// Update the tracked users.
///
/// `users` is an iterator over user IDs that should be marked for
/// tracking.
///
/// This will mark users that weren't seen before for a key query
/// and tracking.
///
/// If the user is already known to the Olm machine, it will not
/// be considered for a key query.
#[wasm_bindgen(js_name = "updateTrackedUsers")]
pub fn update_tracked_users(&self, users: &Array) -> Result<Promise, JsError> {
let users = users
.iter()
.map(|user| Ok(downcast::<identifiers::UserId>(&user, "UserId")?.inner.clone()))
.collect::<Result<Vec<ruma::OwnedUserId>, JsError>>()?;
let me = self.inner.clone();
Ok(future_to_promise(async move {
me.update_tracked_users(users.iter().map(AsRef::as_ref)).await;
Ok(JsValue::UNDEFINED)
}))
}
/// Handle to-device events and one-time key counts from a sync
/// response.
///
/// This will decrypt and handle to-device events returning the
/// decrypted versions of them.
///
/// To decrypt an event from the room timeline call
/// `decrypt_room_event`.
#[wasm_bindgen(js_name = "receiveSyncChanges")]
pub fn receive_sync_changes(
&self,
to_device_events: &str,
changed_devices: &sync_events::DeviceLists,
one_time_key_counts: &Map,
unused_fallback_keys: &Set,
) -> Result<Promise, JsError> {
let to_device_events = serde_json::from_str(to_device_events)?;
let changed_devices = changed_devices.inner.clone();
let one_time_key_counts: BTreeMap<DeviceKeyAlgorithm, UInt> = one_time_key_counts
.entries()
.into_iter()
.filter_map(|js_value| {
let pair = Array::from(&js_value.ok()?);
let (key, value) = (
DeviceKeyAlgorithm::from(pair.at(0).as_string()?),
UInt::new(pair.at(1).as_f64()? as u64)?,
);
Some((key, value))
})
.collect();
let unused_fallback_keys: Option<Vec<DeviceKeyAlgorithm>> = Some(
unused_fallback_keys
.values()
.into_iter()
.filter_map(|js_value| Some(DeviceKeyAlgorithm::from(js_value.ok()?.as_string()?)))
.collect(),
);
let me = self.inner.clone();
Ok(future_to_promise(async move {
Ok(serde_json::to_string(
&me.receive_sync_changes(
to_device_events,
&changed_devices,
&one_time_key_counts,
unused_fallback_keys.as_deref(),
)
.await?,
)?)
}))
}
/// Get the outgoing requests that need to be sent out.
///
/// This returns a list of `JsValue` to represent either:
/// * `KeysUploadRequest`,
/// * `KeysQueryRequest`,
/// * `KeysClaimRequest`,
/// * `ToDeviceRequest`,
/// * `SignatureUploadRequest`,
/// * `RoomMessageRequest` or
/// * `KeysBackupRequest`.
///
/// Those requests need to be sent out to the server and the
/// responses need to be passed back to the state machine using
/// `mark_request_as_sent`.
#[wasm_bindgen(js_name = "outgoingRequests")]
pub fn outgoing_requests(&self) -> Promise {
let me = self.inner.clone();
future_to_promise(async move {
Ok(me
.outgoing_requests()
.await?
.into_iter()
.map(OutgoingRequest)
.map(TryFrom::try_from)
.collect::<Result<Vec<JsValue>, _>>()?
.into_iter()
.collect::<Array>())
})
}
/// Mark the request with the given request ID as sent (see
/// `outgoing_requests`).
///
/// Arguments are:
///
/// * `request_id` represents the unique ID of the request that was sent
/// out. This is needed to couple the response with the now sent out
/// request.
/// * `response_type` represents the type of the request that was sent out.
/// * `response` represents the response that was received from the server
/// after the outgoing request was sent out.
#[wasm_bindgen(js_name = "markRequestAsSent")]
pub fn mark_request_as_sent(
&self,
request_id: &str,
request_type: requests::RequestType,
response: &str,
) -> Result<Promise, JsError> {
let transaction_id = OwnedTransactionId::from(request_id);
let response = response_from_string(response)?;
let incoming_response = responses::OwnedResponse::try_from((request_type, response))?;
let me = self.inner.clone();
Ok(future_to_promise(async move {
Ok(me.mark_request_as_sent(&transaction_id, &incoming_response).await.map(|_| true)?)
}))
}
/// Encrypt a room message for the given room.
///
/// Beware that a room key needs to be shared before this
/// method can be called using the `share_room_key` method.
///
/// `room_id` is the ID of the room for which the message should
/// be encrypted. `event_type` is the type of the event. `content`
/// is the plaintext content of the message that should be
/// encrypted.
///
/// # Panics
///
/// Panics if a group session for the given room wasn't shared
/// beforehand.
#[wasm_bindgen(js_name = "encryptRoomEvent")]
pub fn encrypt_room_event(
&self,
room_id: &identifiers::RoomId,
event_type: String,
content: &str,
) -> Result<Promise, JsError> {
let room_id = room_id.inner.clone();
let content: JsonValue = serde_json::from_str(content)?;
let me = self.inner.clone();
Ok(future_to_promise(async move {
Ok(serde_json::to_string(
&me.encrypt_room_event_raw(&room_id, content, event_type.as_ref()).await?,
)?)
}))
}
/// Decrypt an event from a room timeline.
///
/// # Arguments
///
/// * `event`, the event that should be decrypted.
/// * `room_id`, the ID of the room where the event was sent to.
#[wasm_bindgen(js_name = "decryptRoomEvent")]
pub fn decrypt_room_event(
&self,
event: &str,
room_id: &identifiers::RoomId,
) -> Result<Promise, JsError> {
let event: OriginalSyncRoomEncryptedEvent = serde_json::from_str(event)?;
let room_id = room_id.inner.clone();
let me = self.inner.clone();
Ok(future_to_promise(async move {
let room_event = me.decrypt_room_event(&event, room_id.as_ref()).await?;
Ok(responses::DecryptedRoomEvent::from(room_event))
}))
}
/// Invalidate the currently active outbound group session for the
/// given room.
///
/// Returns true if a session was invalidated, false if there was
/// no session to invalidate.
#[wasm_bindgen(js_name = "invalidateGroupSession")]
pub fn invalidate_group_session(&self, room_id: &identifiers::RoomId) -> Promise {
let room_id = room_id.inner.clone();
let me = self.inner.clone();
future_to_promise(async move { Ok(me.invalidate_group_session(&room_id).await?) })
}
/// Get to-device requests to share a room key with users in a room.
///
/// `room_id` is the room ID. `users` is an array of `UserId`
/// objects. `encryption_settings` are an `EncryptionSettings`
/// object.
#[wasm_bindgen(js_name = "shareRoomKey")]
pub fn share_room_key(
&self,
room_id: &identifiers::RoomId,
users: &Array,
encryption_settings: &encryption::EncryptionSettings,
) -> Result<Promise, JsError> {
let room_id = room_id.inner.clone();
let users = users
.iter()
.map(|user| Ok(downcast::<identifiers::UserId>(&user, "UserId")?.inner.clone()))
.collect::<Result<Vec<ruma::OwnedUserId>, JsError>>()?;
let encryption_settings =
matrix_sdk_crypto::olm::EncryptionSettings::from(encryption_settings);
let me = self.inner.clone();
Ok(future_to_promise(async move {
Ok(serde_json::to_string(
&me.share_room_key(&room_id, users.iter().map(AsRef::as_ref), encryption_settings)
.await?,
)?)
}))
}
/// Get the a key claiming request for the user/device pairs that
/// we are missing Olm sessions for.
///
/// Returns `NULL` if no key claiming request needs to be sent
/// out, otherwise it returns an `Array` where the first key is
/// the transaction ID as a string, and the second key is the keys
/// claim request serialized to JSON.
///
/// Sessions need to be established between devices so group
/// sessions for a room can be shared with them.
///
/// This should be called every time a group session needs to be
/// shared as well as between sync calls. After a sync some
/// devices may request room keys without us having a valid Olm
/// session with them, making it impossible to server the room key
/// request, thus its necessary to check for missing sessions
/// between sync as well.
///
/// Note: Care should be taken that only one such request at a
/// time is in flight, e.g. using a lock.
///
/// The response of a successful key claiming requests needs to be
/// passed to the `OlmMachine` with the `mark_request_as_sent`.
///
/// `users` represents the list of users that we should check if
/// we lack a session with one of their devices. This can be an
/// empty iterator when calling this method between sync requests.
#[wasm_bindgen(js_name = "getMissingSessions")]
pub fn get_missing_sessions(&self, users: &Array) -> Result<Promise, JsError> {
let users = users
.iter()
.map(|user| Ok(downcast::<identifiers::UserId>(&user, "UserId")?.inner.clone()))
.collect::<Result<Vec<ruma::OwnedUserId>, JsError>>()?;
let me = self.inner.clone();
Ok(future_to_promise(async move {
match me.get_missing_sessions(users.iter().map(AsRef::as_ref)).await? {
Some((transaction_id, keys_claim_request)) => {
Ok(JsValue::from(requests::KeysClaimRequest::try_from((
transaction_id.to_string(),
&keys_claim_request,
))?))
}
None => Ok(JsValue::NULL),
}
}))
}
}
/// An Ed25519 public key, used to verify digital signatures.
#[wasm_bindgen]
#[derive(Debug, Clone)]
pub struct Ed25519PublicKey {
inner: vodozemac::Ed25519PublicKey,
}
#[wasm_bindgen]
impl Ed25519PublicKey {
/// The number of bytes an Ed25519 public key has.
#[wasm_bindgen(getter)]
pub fn length(&self) -> usize {
vodozemac::Ed25519PublicKey::LENGTH
}
/// Serialize an Ed25519 public key to an unpadded base64
/// representation.
#[wasm_bindgen(js_name = "toBase64")]
pub fn to_base64(&self) -> String {
self.inner.to_base64()
}
}
/// A Curve25519 public key.
#[wasm_bindgen]
#[derive(Debug, Clone)]
pub struct Curve25519PublicKey {
inner: vodozemac::Curve25519PublicKey,
}
#[wasm_bindgen]
impl Curve25519PublicKey {
/// The number of bytes a Curve25519 public key has.
#[wasm_bindgen(getter)]
pub fn length(&self) -> usize {
vodozemac::Curve25519PublicKey::LENGTH
}
/// Serialize an Curve25519 public key to an unpadded base64
/// representation.
#[wasm_bindgen(js_name = "toBase64")]
pub fn to_base64(&self) -> String {
self.inner.to_base64()
}
}
/// Struct holding the two public identity keys of an account.
#[wasm_bindgen(getter_with_clone)]
#[derive(Debug)]
pub struct IdentityKeys {
/// The Ed25519 public key, used for signing.
pub ed25519: Ed25519PublicKey,
/// The Curve25519 public key, used for establish shared secrets.
pub curve25519: Curve25519PublicKey,
}
impl From<matrix_sdk_crypto::olm::IdentityKeys> for IdentityKeys {
fn from(value: matrix_sdk_crypto::olm::IdentityKeys) -> Self {
Self {
ed25519: Ed25519PublicKey { inner: value.ed25519 },
curve25519: Curve25519PublicKey { inner: value.curve25519 },
}
}
}
@@ -1,372 +0,0 @@
//! Types to handle requests.
use js_sys::JsString;
use matrix_sdk_crypto::{
requests::{
KeysBackupRequest as RumaKeysBackupRequest, KeysQueryRequest as RumaKeysQueryRequest,
RoomMessageRequest as RumaRoomMessageRequest, ToDeviceRequest as RumaToDeviceRequest,
},
OutgoingRequests,
};
use ruma::api::client::keys::{
claim_keys::v3::Request as RumaKeysClaimRequest,
upload_keys::v3::Request as RumaKeysUploadRequest,
upload_signatures::v3::Request as RumaSignatureUploadRequest,
};
use wasm_bindgen::prelude::*;
/// Data for a request to the `/keys/upload` API endpoint
/// ([specification]).
///
/// Publishes end-to-end encryption keys for the device.
///
/// [specification]: https://spec.matrix.org/unstable/client-server-api/#post_matrixclientv3keysupload
#[derive(Debug)]
#[wasm_bindgen(getter_with_clone)]
pub struct KeysUploadRequest {
/// The request ID.
#[wasm_bindgen(readonly)]
pub id: JsString,
/// A JSON-encoded object of form:
///
/// ```json
/// {"device_keys": …, "one_time_keys": …, "fallback_keys": …}
/// ```
#[wasm_bindgen(readonly)]
pub body: JsString,
}
#[wasm_bindgen]
impl KeysUploadRequest {
/// Create a new `KeysUploadRequest`.
#[wasm_bindgen(constructor)]
pub fn new(id: JsString, body: JsString) -> KeysUploadRequest {
Self { id, body }
}
/// Get its request type.
#[wasm_bindgen(getter, js_name = "type")]
pub fn request_type(&self) -> RequestType {
RequestType::KeysUpload
}
}
/// Data for a request to the `/keys/query` API endpoint
/// ([specification]).
///
/// Returns the current devices and identity keys for the given users.
///
/// [specification]: https://spec.matrix.org/unstable/client-server-api/#post_matrixclientv3keysquery
#[derive(Debug)]
#[wasm_bindgen(getter_with_clone)]
pub struct KeysQueryRequest {
/// The request ID.
#[wasm_bindgen(readonly)]
pub id: JsString,
/// A JSON-encoded object of form:
///
/// ```json
/// {"timeout": …, "device_keys": …, "token": …}
/// ```
#[wasm_bindgen(readonly)]
pub body: JsString,
}
#[wasm_bindgen]
impl KeysQueryRequest {
/// Create a new `KeysQueryRequest`.
#[wasm_bindgen(constructor)]
pub fn new(id: JsString, body: JsString) -> KeysQueryRequest {
Self { id, body }
}
/// Get its request type.
#[wasm_bindgen(getter, js_name = "type")]
pub fn request_type(&self) -> RequestType {
RequestType::KeysQuery
}
}
/// Data for a request to the `/keys/claim` API endpoint
/// ([specification]).
///
/// Claims one-time keys that can be used to establish 1-to-1 E2EE
/// sessions.
///
/// [specification]: https://spec.matrix.org/unstable/client-server-api/#post_matrixclientv3keysclaim
#[derive(Debug)]
#[wasm_bindgen(getter_with_clone)]
pub struct KeysClaimRequest {
/// The request ID.
#[wasm_bindgen(readonly)]
pub id: JsString,
/// A JSON-encoded object of form:
///
/// ```json
/// {"timeout": …, "one_time_keys": …}
/// ```
#[wasm_bindgen(readonly)]
pub body: JsString,
}
#[wasm_bindgen]
impl KeysClaimRequest {
/// Create a new `KeysClaimRequest`.
#[wasm_bindgen(constructor)]
pub fn new(id: JsString, body: JsString) -> KeysClaimRequest {
Self { id, body }
}
/// Get its request type.
#[wasm_bindgen(getter, js_name = "type")]
pub fn request_type(&self) -> RequestType {
RequestType::KeysClaim
}
}
/// Data for a request to the `/sendToDevice` API endpoint
/// ([specification]).
///
/// Send an event to a single device or to a group of devices.
///
/// [specification]: https://spec.matrix.org/unstable/client-server-api/#put_matrixclientv3sendtodeviceeventtypetxnid
#[derive(Debug)]
#[wasm_bindgen(getter_with_clone)]
pub struct ToDeviceRequest {
/// The request ID.
#[wasm_bindgen(readonly)]
pub id: JsString,
/// A JSON-encoded object of form:
///
/// ```json
/// {"event_type": …, "txn_id": …, "messages": …}
/// ```
#[wasm_bindgen(readonly)]
pub body: JsString,
}
#[wasm_bindgen]
impl ToDeviceRequest {
/// Create a new `ToDeviceRequest`.
#[wasm_bindgen(constructor)]
pub fn new(id: JsString, body: JsString) -> ToDeviceRequest {
Self { id, body }
}
/// Get its request type.
#[wasm_bindgen(getter, js_name = "type")]
pub fn request_type(&self) -> RequestType {
RequestType::ToDevice
}
}
/// Data for a request to the `/keys/signatures/upload` API endpoint
/// ([specification]).
///
/// Publishes cross-signing signatures for the user.
///
/// [specification]: https://spec.matrix.org/unstable/client-server-api/#post_matrixclientv3keyssignaturesupload
#[derive(Debug)]
#[wasm_bindgen(getter_with_clone)]
pub struct SignatureUploadRequest {
/// The request ID.
#[wasm_bindgen(readonly)]
pub id: JsString,
/// A JSON-encoded object of form:
///
/// ```json
/// {"signed_keys": …, "txn_id": …, "messages": …}
/// ```
#[wasm_bindgen(readonly)]
pub body: JsString,
}
#[wasm_bindgen]
impl SignatureUploadRequest {
/// Create a new `SignatureUploadRequest`.
#[wasm_bindgen(constructor)]
pub fn new(id: JsString, body: JsString) -> SignatureUploadRequest {
Self { id, body }
}
/// Get its request type.
#[wasm_bindgen(getter, js_name = "type")]
pub fn request_type(&self) -> RequestType {
RequestType::SignatureUpload
}
}
/// A customized owned request type for sending out room messages
/// ([specification]).
///
/// [specification]: https://spec.matrix.org/unstable/client-server-api/#put_matrixclientv3roomsroomidsendeventtypetxnid
#[derive(Debug)]
#[wasm_bindgen(getter_with_clone)]
pub struct RoomMessageRequest {
/// The request ID.
#[wasm_bindgen(readonly)]
pub id: JsString,
/// A JSON-encoded object of form:
///
/// ```json
/// {"room_id": …, "txn_id": …, "content": …}
/// ```
#[wasm_bindgen(readonly)]
pub body: JsString,
}
#[wasm_bindgen]
impl RoomMessageRequest {
/// Create a new `RoomMessageRequest`.
#[wasm_bindgen(constructor)]
pub fn new(id: JsString, body: JsString) -> RoomMessageRequest {
Self { id, body }
}
/// Get its request type.
#[wasm_bindgen(getter, js_name = "type")]
pub fn request_type(&self) -> RequestType {
RequestType::RoomMessage
}
}
/// A request that will back up a batch of room keys to the server
/// ([specification]).
///
/// [specification]: https://spec.matrix.org/unstable/client-server-api/#put_matrixclientv3room_keyskeys
#[derive(Debug)]
#[wasm_bindgen(getter_with_clone)]
pub struct KeysBackupRequest {
/// The request ID.
#[wasm_bindgen(readonly)]
pub id: JsString,
/// A JSON-encoded object of form:
///
/// ```json
/// {"rooms": …}
/// ```
#[wasm_bindgen(readonly)]
pub body: JsString,
}
#[wasm_bindgen]
impl KeysBackupRequest {
/// Create a new `KeysBackupRequest`.
#[wasm_bindgen(constructor)]
pub fn new(id: JsString, body: JsString) -> KeysBackupRequest {
Self { id, body }
}
/// Get its request type.
#[wasm_bindgen(getter, js_name = "type")]
pub fn request_type(&self) -> RequestType {
RequestType::KeysBackup
}
}
macro_rules! request {
($request:ident from $ruma_request:ident maps fields $( $field:ident ),+ $(,)? ) => {
impl TryFrom<(String, &$ruma_request)> for $request {
type Error = serde_json::Error;
fn try_from(
(request_id, request): (String, &$ruma_request),
) -> Result<Self, Self::Error> {
let mut map = serde_json::Map::new();
$(
map.insert(stringify!($field).to_owned(), serde_json::to_value(&request.$field).unwrap());
)+
let value = serde_json::Value::Object(map);
Ok($request {
id: request_id.into(),
body: serde_json::to_string(&value)?.into(),
})
}
}
};
}
request!(KeysUploadRequest from RumaKeysUploadRequest maps fields device_keys, one_time_keys, fallback_keys);
request!(KeysQueryRequest from RumaKeysQueryRequest maps fields timeout, device_keys, token);
request!(KeysClaimRequest from RumaKeysClaimRequest maps fields timeout, one_time_keys);
request!(ToDeviceRequest from RumaToDeviceRequest maps fields event_type, txn_id, messages);
request!(SignatureUploadRequest from RumaSignatureUploadRequest maps fields signed_keys);
request!(RoomMessageRequest from RumaRoomMessageRequest maps fields room_id, txn_id, content);
request!(KeysBackupRequest from RumaKeysBackupRequest maps fields rooms);
// JavaScript has no complex enums like Rust. To return structs of
// different types, we have no choice that hiding everything behind a
// `JsValue`.
pub(crate) struct OutgoingRequest(pub(crate) matrix_sdk_crypto::OutgoingRequest);
impl TryFrom<OutgoingRequest> for JsValue {
type Error = serde_json::Error;
fn try_from(outgoing_request: OutgoingRequest) -> Result<Self, Self::Error> {
let request_id = outgoing_request.0.request_id().to_string();
Ok(match outgoing_request.0.request() {
OutgoingRequests::KeysUpload(request) => {
JsValue::from(KeysUploadRequest::try_from((request_id, request))?)
}
OutgoingRequests::KeysQuery(request) => {
JsValue::from(KeysQueryRequest::try_from((request_id, request))?)
}
OutgoingRequests::KeysClaim(request) => {
JsValue::from(KeysClaimRequest::try_from((request_id, request))?)
}
OutgoingRequests::ToDeviceRequest(request) => {
JsValue::from(ToDeviceRequest::try_from((request_id, request))?)
}
OutgoingRequests::SignatureUpload(request) => {
JsValue::from(SignatureUploadRequest::try_from((request_id, request))?)
}
OutgoingRequests::RoomMessage(request) => {
JsValue::from(RoomMessageRequest::try_from((request_id, request))?)
}
OutgoingRequests::KeysBackup(request) => {
JsValue::from(KeysBackupRequest::try_from((request_id, request))?)
}
})
}
}
/// Represent the type of a request.
#[wasm_bindgen]
#[derive(Debug)]
pub enum RequestType {
/// Represents a `KeysUploadRequest`.
KeysUpload,
/// Represents a `KeysQueryRequest`.
KeysQuery,
/// Represents a `KeysClaimRequest`.
KeysClaim,
/// Represents a `ToDeviceRequest`.
ToDevice,
/// Represents a `SignatureUploadRequest`.
SignatureUpload,
/// Represents a `RoomMessageRequest`.
RoomMessage,
/// Represents a `KeysBackupRequest`.
KeysBackup,
}
@@ -1,210 +0,0 @@
//! Types related to responses.
use std::borrow::Borrow;
use js_sys::{Array, JsString};
use matrix_sdk_common::deserialized_responses::{AlgorithmInfo, EncryptionInfo};
use matrix_sdk_crypto::IncomingResponse;
pub(crate) use ruma::api::client::{
backup::add_backup_keys::v3::Response as KeysBackupResponse,
keys::{
claim_keys::v3::Response as KeysClaimResponse, get_keys::v3::Response as KeysQueryResponse,
upload_keys::v3::Response as KeysUploadResponse,
upload_signatures::v3::Response as SignatureUploadResponse,
},
message::send_message_event::v3::Response as RoomMessageResponse,
to_device::send_event_to_device::v3::Response as ToDeviceResponse,
};
use ruma::api::IncomingResponse as RumaIncomingResponse;
use wasm_bindgen::prelude::*;
use crate::{encryption, identifiers, requests::RequestType};
pub(crate) fn response_from_string(body: &str) -> http::Result<http::Response<Vec<u8>>> {
http::Response::builder().status(200).body(body.as_bytes().to_vec())
}
/// Intermediate private type to store an incoming owned response,
/// without the need to manage lifetime.
pub(crate) enum OwnedResponse {
KeysUpload(KeysUploadResponse),
KeysQuery(KeysQueryResponse),
KeysClaim(KeysClaimResponse),
ToDevice(ToDeviceResponse),
SignatureUpload(SignatureUploadResponse),
RoomMessage(RoomMessageResponse),
KeysBackup(KeysBackupResponse),
}
impl From<KeysUploadResponse> for OwnedResponse {
fn from(response: KeysUploadResponse) -> Self {
OwnedResponse::KeysUpload(response)
}
}
impl From<KeysQueryResponse> for OwnedResponse {
fn from(response: KeysQueryResponse) -> Self {
OwnedResponse::KeysQuery(response)
}
}
impl From<KeysClaimResponse> for OwnedResponse {
fn from(response: KeysClaimResponse) -> Self {
OwnedResponse::KeysClaim(response)
}
}
impl From<ToDeviceResponse> for OwnedResponse {
fn from(response: ToDeviceResponse) -> Self {
OwnedResponse::ToDevice(response)
}
}
impl From<SignatureUploadResponse> for OwnedResponse {
fn from(response: SignatureUploadResponse) -> Self {
Self::SignatureUpload(response)
}
}
impl From<RoomMessageResponse> for OwnedResponse {
fn from(response: RoomMessageResponse) -> Self {
OwnedResponse::RoomMessage(response)
}
}
impl From<KeysBackupResponse> for OwnedResponse {
fn from(r: KeysBackupResponse) -> Self {
Self::KeysBackup(r)
}
}
impl TryFrom<(RequestType, http::Response<Vec<u8>>)> for OwnedResponse {
type Error = JsError;
fn try_from(
(request_type, response): (RequestType, http::Response<Vec<u8>>),
) -> Result<Self, Self::Error> {
match request_type {
RequestType::KeysUpload => {
KeysUploadResponse::try_from_http_response(response).map(Into::into)
}
RequestType::KeysQuery => {
KeysQueryResponse::try_from_http_response(response).map(Into::into)
}
RequestType::KeysClaim => {
KeysClaimResponse::try_from_http_response(response).map(Into::into)
}
RequestType::ToDevice => {
ToDeviceResponse::try_from_http_response(response).map(Into::into)
}
RequestType::SignatureUpload => {
SignatureUploadResponse::try_from_http_response(response).map(Into::into)
}
RequestType::RoomMessage => {
RoomMessageResponse::try_from_http_response(response).map(Into::into)
}
RequestType::KeysBackup => {
KeysBackupResponse::try_from_http_response(response).map(Into::into)
}
}
.map_err(JsError::from)
}
}
impl<'a> From<&'a OwnedResponse> for IncomingResponse<'a> {
fn from(response: &'a OwnedResponse) -> Self {
match response {
OwnedResponse::KeysUpload(response) => IncomingResponse::KeysUpload(response),
OwnedResponse::KeysQuery(response) => IncomingResponse::KeysQuery(response),
OwnedResponse::KeysClaim(response) => IncomingResponse::KeysClaim(response),
OwnedResponse::ToDevice(response) => IncomingResponse::ToDevice(response),
OwnedResponse::SignatureUpload(response) => IncomingResponse::SignatureUpload(response),
OwnedResponse::RoomMessage(response) => IncomingResponse::RoomMessage(response),
OwnedResponse::KeysBackup(response) => IncomingResponse::KeysBackup(response),
}
}
}
/// A decrypted room event.
#[wasm_bindgen(getter_with_clone)]
#[derive(Debug)]
pub struct DecryptedRoomEvent {
/// The JSON-encoded decrypted event.
#[wasm_bindgen(readonly)]
pub event: JsString,
encryption_info: Option<EncryptionInfo>,
}
#[wasm_bindgen]
impl DecryptedRoomEvent {
/// The user ID of the event sender, note this is untrusted data
/// unless the `verification_state` is as well trusted.
#[wasm_bindgen(getter)]
pub fn sender(&self) -> Option<identifiers::UserId> {
Some(identifiers::UserId::from(self.encryption_info.as_ref()?.sender.clone()))
}
/// The device ID of the device that sent us the event, note this
/// is untrusted data unless `verification_state` is as well
/// trusted.
#[wasm_bindgen(getter, js_name = "senderDevice")]
pub fn sender_device(&self) -> Option<identifiers::DeviceId> {
Some(identifiers::DeviceId::from(self.encryption_info.as_ref()?.sender_device.clone()))
}
/// The Curve25519 key of the device that created the megolm
/// decryption key originally.
#[wasm_bindgen(getter, js_name = "senderCurve25519Key")]
pub fn sender_curve25519_key(&self) -> Option<JsString> {
Some(match &self.encryption_info.as_ref()?.algorithm_info {
AlgorithmInfo::MegolmV1AesSha2 { curve25519_key, .. } => curve25519_key.clone().into(),
})
}
/// The signing Ed25519 key that have created the megolm key that
/// was used to decrypt this session.
#[wasm_bindgen(getter, js_name = "senderClaimedEd25519Key")]
pub fn sender_claimed_ed25519_key(&self) -> Option<JsString> {
match &self.encryption_info.as_ref()?.algorithm_info {
AlgorithmInfo::MegolmV1AesSha2 { sender_claimed_keys, .. } => {
sender_claimed_keys.get(&ruma::DeviceKeyAlgorithm::Ed25519).cloned().map(Into::into)
}
}
}
/// Chain of Curve25519 keys through which this session was
/// forwarded, via `m.forwarded_room_key` events.
#[wasm_bindgen(getter, js_name = "forwardingCurve25519KeyChain")]
pub fn forwarding_curve25519_key_chain(&self) -> Option<Array> {
Some(match &self.encryption_info.as_ref()?.algorithm_info {
AlgorithmInfo::MegolmV1AesSha2 { forwarding_curve25519_key_chain, .. } => {
forwarding_curve25519_key_chain.iter().map(JsValue::from).collect()
}
})
}
/// The verification state of the device that sent us the event,
/// note this is the state of the device at the time of
/// decryption. It may change in the future if a device gets
/// verified or deleted.
#[wasm_bindgen(getter, js_name = "verificationState")]
pub fn verification_state(&self) -> Option<encryption::VerificationState> {
Some((self.encryption_info.as_ref()?.verification_state.borrow()).into())
}
}
impl From<matrix_sdk_common::deserialized_responses::RoomEvent> for DecryptedRoomEvent {
fn from(value: matrix_sdk_common::deserialized_responses::RoomEvent) -> Self {
Self {
event: value.event.json().get().to_owned().into(),
encryption_info: value.encryption_info,
}
}
}
@@ -1,69 +0,0 @@
//! `GET /_matrix/client/*/sync`
use js_sys::Array;
use wasm_bindgen::prelude::*;
use crate::{downcast, identifiers};
/// Information on E2E device updates.
#[wasm_bindgen]
#[derive(Debug)]
pub struct DeviceLists {
pub(crate) inner: ruma::api::client::sync::sync_events::v3::DeviceLists,
}
#[wasm_bindgen]
impl DeviceLists {
/// Create an empty `DeviceLists`.
///
/// `changed` and `left` must be an array of `UserId`.
#[wasm_bindgen(constructor)]
pub fn new(changed: Option<Array>, left: Option<Array>) -> Result<DeviceLists, JsError> {
let mut inner = ruma::api::client::sync::sync_events::v3::DeviceLists::default();
inner.changed = changed
.unwrap_or_default()
.iter()
.map(|user| Ok(downcast::<identifiers::UserId>(&user, "UserId")?.inner.clone()))
.collect::<Result<Vec<ruma::OwnedUserId>, JsError>>()?;
inner.left = left
.unwrap_or_default()
.iter()
.map(|user| Ok(downcast::<identifiers::UserId>(&user, "UserId")?.inner.clone()))
.collect::<Result<Vec<ruma::OwnedUserId>, JsError>>()?;
Ok(Self { inner })
}
/// Returns true if there are no device list updates.
#[wasm_bindgen(js_name = "isEmpty")]
pub fn is_empty(&self) -> bool {
self.inner.is_empty()
}
/// List of users who have updated their device identity keys or
/// who now share an encrypted room with the client since the
/// previous sync
#[wasm_bindgen(getter)]
pub fn changed(&self) -> Array {
self.inner
.changed
.iter()
.map(|user| identifiers::UserId::from(user.clone()))
.map(JsValue::from)
.collect()
}
/// List of users who no longer share encrypted rooms since the
/// previous sync response.
#[wasm_bindgen(getter)]
pub fn left(&self) -> Array {
self.inner
.left
.iter()
.map(|user| identifiers::UserId::from(user.clone()))
.map(JsValue::from)
.collect()
}
}
@@ -1,36 +0,0 @@
const { EncryptionAlgorithm, EncryptionSettings, HistoryVisibility, VerificationState } = require('../pkg/matrix_sdk_crypto');
describe('EncryptionAlgorithm', () => {
test('has the correct variant values', () => {
expect(EncryptionAlgorithm.OlmV1Curve25519AesSha2).toStrictEqual(0);
expect(EncryptionAlgorithm.MegolmV1AesSha2).toStrictEqual(1);
});
});
describe(EncryptionSettings.name, () => {
test('can be instantiated with default values', () => {
const es = new EncryptionSettings();
expect(es.algorithm).toStrictEqual(EncryptionAlgorithm.MegolmV1AesSha2);
expect(es.rotationPeriod).toStrictEqual(604800000000n);
expect(es.rotationPeriodMessages).toStrictEqual(100n);
expect(es.historyVisibility).toStrictEqual(HistoryVisibility.Shared);
});
test('checks the history visibility values', () => {
const es = new EncryptionSettings();
es.historyVisibility = HistoryVisibility.Invited;
expect(es.historyVisibility).toStrictEqual(HistoryVisibility.Invited);
expect(() => { es.historyVisibility = 42 }).toThrow();
});
});
describe('VerificationState', () => {
test('has the correct variant values', () => {
expect(VerificationState.Trusted).toStrictEqual(0);
expect(VerificationState.Untrusted).toStrictEqual(1);
expect(VerificationState.UnknownDevice).toStrictEqual(2);
});
});
@@ -1,10 +0,0 @@
const { HistoryVisibility } = require('../pkg/matrix_sdk_crypto');
describe('HistoryVisibility', () => {
test('has the correct variant values', () => {
expect(HistoryVisibility.Invited).toStrictEqual(0);
expect(HistoryVisibility.Joined).toStrictEqual(1);
expect(HistoryVisibility.Shared).toStrictEqual(2);
expect(HistoryVisibility.WorldReadable).toStrictEqual(3);
});
});
@@ -1,72 +0,0 @@
const { UserId, DeviceId, RoomId, ServerName } = require('../pkg/matrix_sdk_crypto');
describe(UserId.name, () => {
test('cannot be invalid', () => {
expect(() => { new UserId('@foobar') }).toThrow();
});
const user = new UserId('@foo:bar.org');
test('localpart is present', () => {
expect(user.localpart).toStrictEqual('foo');
});
test('server name is present', () => {
expect(user.serverName).toBeInstanceOf(ServerName);
});
test('user ID is not historical', () => {
expect(user.isHistorical()).toStrictEqual(false);
});
test('can read the user ID as a string', () => {
expect(user.toString()).toStrictEqual('@foo:bar.org');
})
});
describe(DeviceId.name, () => {
const device = new DeviceId('foo');
test('can read the device ID as a string', () => {
expect(device.toString()).toStrictEqual('foo');
})
});
describe(RoomId.name, () => {
test('cannot be invalid', () => {
expect(() => { new RoomId('!foo') }).toThrow();
});
const room = new RoomId('!foo:bar.org');
test('localpart is present', () => {
expect(room.localpart).toStrictEqual('foo');
});
test('server name is present', () => {
expect(room.serverName).toBeInstanceOf(ServerName);
});
test('can read the room ID as string', () => {
expect(room.toString()).toStrictEqual('!foo:bar.org');
});
});
describe(ServerName.name, () => {
test('cannot be invalid', () => {
expect(() => { new ServerName('@foobar') }).toThrow()
});
test('host is present', () => {
expect(new ServerName('foo.org').host).toStrictEqual('foo.org');
});
test('port can be optional', () => {
expect(new ServerName('foo.org').port).toStrictEqual(undefined);
expect(new ServerName('foo.org:1234').port).toStrictEqual(1234);
});
test('server is not an IP literal', () => {
expect(new ServerName('foo.org').isIpLiteral()).toStrictEqual(false);
});
});
@@ -1,341 +0,0 @@
const { OlmMachine, UserId, DeviceId, RoomId, DeviceLists, RequestType, KeysUploadRequest, KeysQueryRequest, KeysClaimRequest, EncryptionSettings, DecryptedRoomEvent, VerificationState } = require('../pkg/matrix_sdk_crypto');
describe(OlmMachine.name, () => {
test('can be instantiated with the async initializer', async () => {
expect(await new OlmMachine(new UserId('@foo:bar.org'), new DeviceId('baz'))).toBeInstanceOf(OlmMachine);
});
const user = new UserId('@alice:example.org');
const device = new DeviceId('foobar');
const room = new RoomId('!baz:matrix.org');
function machine(new_user, new_device) {
return new OlmMachine(new_user || user, new_device || device);
}
test('can read user ID', async () => {
expect((await machine()).userId.toString()).toStrictEqual(user.toString());
});
test('can read device ID', async () => {
expect((await machine()).deviceId.toString()).toStrictEqual(device.toString());
});
test('can read identity keys', async () => {
const identityKeys = (await machine()).identityKeys;
expect(identityKeys.ed25519.toBase64()).toMatch(/^[A-Za-z0-9+/]+$/);
expect(identityKeys.curve25519.toBase64()).toMatch(/^[A-Za-z0-9+/]+$/);
});
test('can read display name', async () => {
expect(await machine().displayName).toBeUndefined();
});
test('can read tracked users', async () => {
const trackedUsers = (await machine()).trackedUsers();
expect(trackedUsers).toBeInstanceOf(Set);
expect(trackedUsers.size).toStrictEqual(0);
});
test('can update tracked users', async () => {
const m = await machine();
expect(await m.updateTrackedUsers([user])).toStrictEqual(undefined);
});
test('can receive sync changes', async () => {
const m = await machine();
const toDeviceEvents = JSON.stringify({});
const changedDevices = new DeviceLists();
const oneTimeKeyCounts = new Map();
const unusedFallbackKeys = new Set();
const receiveSyncChanges = JSON.parse(await m.receiveSyncChanges(toDeviceEvents, changedDevices, oneTimeKeyCounts, unusedFallbackKeys));
expect(receiveSyncChanges).toEqual({});
});
test('can get the outgoing requests that need to be send out', async () => {
const m = await machine();
const toDeviceEvents = JSON.stringify({});
const changedDevices = new DeviceLists();
const oneTimeKeyCounts = new Map();
const unusedFallbackKeys = new Set();
const receiveSyncChanges = JSON.parse(await m.receiveSyncChanges(toDeviceEvents, changedDevices, oneTimeKeyCounts, unusedFallbackKeys));
expect(receiveSyncChanges).toEqual({});
const outgoingRequests = await m.outgoingRequests();
expect(outgoingRequests).toHaveLength(2);
{
expect(outgoingRequests[0]).toBeInstanceOf(KeysUploadRequest);
expect(outgoingRequests[0].id).toBeDefined();
expect(outgoingRequests[0].type).toStrictEqual(RequestType.KeysUpload);
const body = JSON.parse(outgoingRequests[0].body);
expect(body.device_keys).toBeDefined();
expect(body.one_time_keys).toBeDefined();
}
{
expect(outgoingRequests[1]).toBeInstanceOf(KeysQueryRequest);
expect(outgoingRequests[1].id).toBeDefined();
expect(outgoingRequests[1].type).toStrictEqual(RequestType.KeysQuery);
const body = JSON.parse(outgoingRequests[1].body);
expect(body.timeout).toBeDefined();
expect(body.device_keys).toBeDefined();
expect(body.token).toBeDefined();
}
});
describe('setup workflow to mark requests as sent', () => {
let m;
let ougoingRequests;
beforeAll(async () => {
m = await machine(new UserId('@alice:example.org'), new DeviceId('DEVICEID'));
const toDeviceEvents = JSON.stringify({});
const changedDevices = new DeviceLists();
const oneTimeKeyCounts = new Map();
const unusedFallbackKeys = new Set();
const receiveSyncChanges = await m.receiveSyncChanges(toDeviceEvents, changedDevices, oneTimeKeyCounts, unusedFallbackKeys);
outgoingRequests = await m.outgoingRequests();
expect(outgoingRequests).toHaveLength(2);
});
test('can mark requests as sent', async () => {
{
const request = outgoingRequests[0];
expect(request).toBeInstanceOf(KeysUploadRequest);
// https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3keysupload
const hypothetical_response = JSON.stringify({
"one_time_key_counts": {
"curve25519": 10,
"signed_curve25519": 20
}
});
const marked = await m.markRequestAsSent(request.id, request.type, hypothetical_response);
expect(marked).toStrictEqual(true);
}
{
const request = outgoingRequests[1];
expect(request).toBeInstanceOf(KeysQueryRequest);
// https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3keysquery
const hypothetical_response = JSON.stringify({
"device_keys": {
"@alice:example.org": {
"JLAFKJWSCS": {
"algorithms": [
"m.olm.v1.curve25519-aes-sha2",
"m.megolm.v1.aes-sha2"
],
"device_id": "JLAFKJWSCS",
"keys": {
"curve25519:JLAFKJWSCS": "wjLpTLRqbqBzLs63aYaEv2Boi6cFEbbM/sSRQ2oAKk4",
"ed25519:JLAFKJWSCS": "nE6W2fCblxDcOFmeEtCHNl8/l8bXcu7GKyAswA4r3mM"
},
"signatures": {
"@alice:example.org": {
"ed25519:JLAFKJWSCS": "m53Wkbh2HXkc3vFApZvCrfXcX3AI51GsDHustMhKwlv3TuOJMj4wistcOTM8q2+e/Ro7rWFUb9ZfnNbwptSUBA"
}
},
"unsigned": {
"device_display_name": "Alice's mobile phone"
},
"user_id": "@alice:example.org"
}
}
},
"failures": {}
});
const marked = await m.markRequestAsSent(request.id, request.type, hypothetical_response);
expect(marked).toStrictEqual(true);
}
});
});
describe('setup workflow to encrypt/decrypt events', () => {
let m;
const user = new UserId('@alice:example.org');
const device = new DeviceId('JLAFKJWSCS');
const room = new RoomId('!test:localhost');
beforeAll(async () => {
m = await machine(user, device);
});
test('can pass keysquery and keysclaim requests directly', async () => {
{
// derived from https://github.com/matrix-org/matrix-rust-sdk/blob/7f49618d350fab66b7e1dc4eaf64ec25ceafd658/benchmarks/benches/crypto_bench/keys_query.json
const hypothetical_response = JSON.stringify({
"device_keys": {
"@example:localhost": {
"AFGUOBTZWM": {
"algorithms": [
"m.olm.v1.curve25519-aes-sha2",
"m.megolm.v1.aes-sha2"
],
"device_id": "AFGUOBTZWM",
"keys": {
"curve25519:AFGUOBTZWM": "boYjDpaC+7NkECQEeMh5dC+I1+AfriX0VXG2UV7EUQo",
"ed25519:AFGUOBTZWM": "NayrMQ33ObqMRqz6R9GosmHdT6HQ6b/RX/3QlZ2yiec"
},
"signatures": {
"@example:localhost": {
"ed25519:AFGUOBTZWM": "RoSWvru1jj6fs2arnTedWsyIyBmKHMdOu7r9gDi0BZ61h9SbCK2zLXzuJ9ZFLao2VvA0yEd7CASCmDHDLYpXCA"
}
},
"user_id": "@example:localhost",
"unsigned": {
"device_display_name": "rust-sdk"
}
},
}
},
"failures": {},
"master_keys": {
"@example:localhost": {
"user_id": "@example:localhost",
"usage": [
"master"
],
"keys": {
"ed25519:n2lpJGx0LiKnuNE1IucZP3QExrD4SeRP0veBHPe3XUU": "n2lpJGx0LiKnuNE1IucZP3QExrD4SeRP0veBHPe3XUU"
},
"signatures": {
"@example:localhost": {
"ed25519:TCSJXPWGVS": "+j9G3L41I1fe0++wwusTTQvbboYW0yDtRWUEujhwZz4MAltjLSfJvY0hxhnz+wHHmuEXvQDen39XOpr1p29sAg"
}
}
}
},
"self_signing_keys": {
"@example:localhost": {
"user_id": "@example:localhost",
"usage": [
"self_signing"
],
"keys": {
"ed25519:kQXOuy639Yt47mvNTdrIluoC6DMvfbZLYbxAmwiDyhI": "kQXOuy639Yt47mvNTdrIluoC6DMvfbZLYbxAmwiDyhI"
},
"signatures": {
"@example:localhost": {
"ed25519:n2lpJGx0LiKnuNE1IucZP3QExrD4SeRP0veBHPe3XUU": "q32ifix/qyRpvmegw2BEJklwoBCAJldDNkcX+fp+lBA4Rpyqtycxge6BA4hcJdxYsy3oV0IHRuugS8rJMMFyAA"
}
}
}
},
"user_signing_keys": {
"@example:localhost": {
"user_id": "@example:localhost",
"usage": [
"user_signing"
],
"keys": {
"ed25519:g4ED07Fnqf3GzVWNN1pZ0IFrPQVdqQf+PYoJNH4eE0s": "g4ED07Fnqf3GzVWNN1pZ0IFrPQVdqQf+PYoJNH4eE0s"
},
"signatures": {
"@example:localhost": {
"ed25519:n2lpJGx0LiKnuNE1IucZP3QExrD4SeRP0veBHPe3XUU": "nKQu8alQKDefNbZz9luYPcNj+Z+ouQSot4fU/A23ELl1xrI06QVBku/SmDx0sIW1ytso0Cqwy1a+3PzCa1XABg"
}
}
}
}
});
const marked = await m.markRequestAsSent('foo', RequestType.KeysQuery, hypothetical_response);
}
{
// derived from https://github.com/matrix-org/matrix-rust-sdk/blob/7f49618d350fab66b7e1dc4eaf64ec25ceafd658/benchmarks/benches/crypto_bench/keys_claim.json
const hypothetical_response = JSON.stringify({
"one_time_keys": {
"@example:localhost": {
"AFGUOBTZWM": {
"signed_curve25519:AAAABQ": {
"key": "9IGouMnkB6c6HOd4xUsNv4i3Dulb4IS96TzDordzOws",
"signatures": {
"@example:localhost": {
"ed25519:AFGUOBTZWM": "2bvUbbmJegrV0eVP/vcJKuIWC3kud+V8+C0dZtg4dVovOSJdTP/iF36tQn2bh5+rb9xLlSeztXBdhy4c+LiOAg"
}
}
}
},
}
},
"failures": {}
});
const marked = await m.markRequestAsSent('bar', RequestType.KeysClaim, hypothetical_response);
}
});
test('can share a room key', async () => {
const other_users = [new UserId('@example:localhost')];
const requests = JSON.parse(await m.shareRoomKey(room, other_users, new EncryptionSettings()));
expect(requests).toHaveLength(1);
expect(requests[0].event_type).toBeDefined();
expect(requests[0].txn_id).toBeDefined();
expect(requests[0].messages).toBeDefined();
expect(requests[0].messages['@example:localhost']).toBeDefined();
});
let encrypted;
test('can encrypt an event', async () => {
encrypted = JSON.parse(await m.encryptRoomEvent(
room,
'm.room.message',
JSON.stringify({
"hello": "world"
}),
));
expect(encrypted.algorithm).toBeDefined();
expect(encrypted.ciphertext).toBeDefined();
expect(encrypted.sender_key).toBeDefined();
expect(encrypted.device_id).toStrictEqual(device.toString());
expect(encrypted.session_id).toBeDefined();
});
test('can decrypt an event', async () => {
const decrypted = await m.decryptRoomEvent(
JSON.stringify({
"type": "m.room.encrypted",
"event_id": "$xxxxx:example.org",
"origin_server_ts": Date.now(),
"sender": user.toString(),
content: encrypted,
unsigned: {
"age": 1234
}
}),
room,
);
expect(decrypted).toBeInstanceOf(DecryptedRoomEvent);
const event = JSON.parse(decrypted.event);
expect(event.content.hello).toStrictEqual("world");
expect(decrypted.sender.toString()).toStrictEqual(user.toString());
expect(decrypted.senderDevice.toString()).toStrictEqual(device.toString());
expect(decrypted.senderCurve25519Key).toBeDefined();
expect(decrypted.senderClaimedEd25519Key).toBeDefined();
expect(decrypted.forwardingCurve25519KeyChain).toHaveLength(0);
expect(decrypted.verificationState).toStrictEqual(VerificationState.Trusted);
});
});
});
@@ -1,35 +0,0 @@
const { RequestType, KeysUploadRequest, KeysQueryRequest, KeysClaimRequest, ToDeviceRequest, SignatureUploadRequest, RoomMessageRequest, KeysBackupRequest } = require('../pkg/matrix_sdk_crypto');
describe('RequestType', () => {
test('has the correct variant values', () => {
expect(RequestType.KeysUpload).toStrictEqual(0);
expect(RequestType.KeysQuery).toStrictEqual(1);
expect(RequestType.KeysClaim).toStrictEqual(2);
expect(RequestType.ToDevice).toStrictEqual(3);
expect(RequestType.SignatureUpload).toStrictEqual(4);
expect(RequestType.RoomMessage).toStrictEqual(5);
expect(RequestType.KeysBackup).toStrictEqual(6);
});
});
for (const [request, request_type] of [
[KeysUploadRequest, RequestType.KeysUpload],
[KeysQueryRequest, RequestType.KeysQuery],
[KeysClaimRequest, RequestType.KeysClaim],
[ToDeviceRequest, RequestType.ToDevice],
[SignatureUploadRequest, RequestType.SignatureUpload],
[RoomMessageRequest, RequestType.RoomMessage],
[KeysBackupRequest, RequestType.KeysBackup],
]) {
describe(request.name, () => {
test('can be instantiated', () => {
const r = new (request)('foo', '{"bar": "baz"}');
expect(r).toBeInstanceOf(request);
expect(r.id).toStrictEqual('foo');
expect(r.body).toStrictEqual('{"bar": "baz"}');
expect(r.type).toStrictEqual(request_type);
});
})
}
@@ -1,31 +0,0 @@
const { DeviceLists, UserId } = require('../pkg/matrix_sdk_crypto');
describe(DeviceLists.name, () => {
test('can be empty', () => {
const empty = new DeviceLists();
expect(empty.isEmpty()).toStrictEqual(true);
expect(empty.changed).toHaveLength(0);
expect(empty.left).toHaveLength(0);
});
test('can be coerced empty', () => {
const empty = new DeviceLists([], []);
expect(empty.isEmpty()).toStrictEqual(true);
expect(empty.changed).toHaveLength(0);
expect(empty.left).toHaveLength(0);
});
test('returns the correct `changed` and `left`', () => {
const list = new DeviceLists([new UserId('@foo:bar.org')], [new UserId('@baz:qux.org')]);
expect(list.isEmpty()).toStrictEqual(false);
expect(list.changed).toHaveLength(1);
expect(list.changed[0].toString()).toStrictEqual('@foo:bar.org');
expect(list.left).toHaveLength(1);
expect(list.left[0].toString()).toStrictEqual('@baz:qux.org');
});
});

Some files were not shown because too many files have changed in this diff Show More