Commit Graph

8227 Commits

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