Commit Graph

8509 Commits

Author SHA1 Message Date
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