Commit Graph

14300 Commits

Author SHA1 Message Date
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
matrix-sdk-crypto-ffi-0.4.1
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