Commit Graph

11887 Commits

Author SHA1 Message Date
Ivan Enderlin
b59c0b671e refactor(ui): TimelineMetadata works on the _remotes_ region.
This patch updates `TimelineMetadata` to work on the _remotes_ region
only, excluding the _start_ and the _locals_ regions. It helps to reduce
the risk of inserting items in an incorrect regions.

This patch also removes on more `rfind_event_by_id` usage, which is
nice.
2025-05-12 17:15:43 +02:00
Ivan Enderlin
c6453a4cb3 refactor(ui): ReadReceiptTimelineUpdate works on _remotes_ region.
This patch updates `ReadReceiptTimelineUpdate` to work on the _remotes_
region only, excluding the _start_ and the _lcoals_ regions. It helps
to reduce the risk of inserting a `ReadMarker` inside the _start_ or the
_locals_ regions.
2025-05-12 17:15:43 +02:00
Ivan Enderlin
74bf699615 refactor(ui): DateDividerAdjuster works on _remotes_ and _locals_ regions.
This patch updates `DateDividerAdjuster` to work on _remotes_ and
_locals_ regions only, excluding the _start_ region. It helps to reduce
the risk of inserting a `DateDivider` inside the _start_ region.

This patch also uses the new `push_date_divider` method, which provides
a couple of invariants.
2025-05-12 17:15:43 +02:00
Ivan Enderlin
e1f94bf9c4 feat(ui): Define _regions_ in the Timeline.
This patch defines a new concept in the `Timeline`: Regions.

The `ObservableItems` holds all the invariants about the _position_ of the
items. It defines three regions where items can live:

1. the _start_ region, which can only contain a single `TimelineStart`,
2. the _remotes_ region, which can only contain many `Remote` timeline
   items with their decorations (only `DateDivider`s and `ReadMarker`s),
3. the _locals_ region, which can only contain many `Local` timeline items
   with their decorations (only `DateDivider`s).

The `iter_all_regions` method allows to iterate over all regions.
`iter_remotes_region` will restrict the iterator over the _remotes_
region, and so on. These iterators provide the absolute indices of the
items, so that it's harder to make mistakes when manipulating the indices of
items with operations like `insert`, `remove`, `replace` etc.

Other methods like `push_local` or `push_date_divider` insert the items
in the correct region, and check a couple of invariants.
2025-05-12 17:15:43 +02:00
Ivan Enderlin
44a0745110 chore(base): Move the bitflags dependency in the workspace. 2025-05-12 17:15:43 +02:00
Ivan Enderlin
94b76168e8 refactor(ui): Add ObservableItemsTransaction::has_local.
This patch implements the `has_local` method on
`ObservableItemsTransaction`, which is way faster than the previous the
previous solution which was to iterate over all items to find at least
one local timeline item.
2025-05-12 17:15:43 +02:00
Ivan Enderlin
55ea80b485 refactor(ui): Add ObservableItemsTransaction::push_local.
This patch adds the `push_local` method on `ObservableItemsTransaction`
to add semantics and hardcode the invariant in a single place for the
different timeline items.
2025-05-12 17:15:43 +02:00
Ivan Enderlin
4e501e88ee refactor(ui): Add ObservableItemsTransaction::push_timeline_start_if_missing.
This patch adds the `push_timeline_start_if_missing` method on
`ObservableItemsTransaction` to add semantics and hardcode the
invariant in a single place for the different timeline items.
2025-05-12 17:15:43 +02:00
Ivan Enderlin
afc02781e9 test(ui): Add a regression test.
This patch adds a regression test ensuring [this bug][4976] cannot
happen anymore.

[4976]: https://github.com/matrix-org/matrix-rust-sdk/issues/4976
2025-05-12 17:15:43 +02:00
Ivan Enderlin
c2072e1cc2 test(ui): Support index [$nth] --- date divider --- in assert_timeline_stream!. 2025-05-12 17:15:43 +02:00
Ivan Enderlin
eef99b2679 test: Add assert messages in the assert_timeline_stream macro.
This patch improves the `assert_timeline_stream` macro by adding a bunch
of assert messages in case it fails.
2025-05-12 17:15:43 +02:00
Ivan Enderlin
581d54f65f fix(ui): Offset the timeline index in the presence of a TimelineStart.
This patch fixes the insertion of a new `TimelineItem` in the presence
of a `TimelineStart` that shifts/offsets the timeline index of 1.
2025-05-12 17:15:43 +02:00
dependabot[bot]
5f5ea69a32 chore(deps): Bump tj-actions/changed-files
Bumps [tj-actions/changed-files](https://github.com/tj-actions/changed-files) from 4168bb487d5b82227665ab4ec90b67ce02691741 to 480f49412651059a414a6a5c96887abb1877de8a.
- [Release notes](https://github.com/tj-actions/changed-files/releases)
- [Changelog](https://github.com/tj-actions/changed-files/blob/main/HISTORY.md)
- [Commits](4168bb487d...480f494126)

---
updated-dependencies:
- dependency-name: tj-actions/changed-files
  dependency-version: 480f49412651059a414a6a5c96887abb1877de8a
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-05-12 17:00:46 +02:00
Johannes Marbach
08800f7d60 Reduce boilerplate further 2025-05-12 10:56:57 +02:00
Johannes Marbach
eb51a7f145 Use macros to reduce boilerplate 2025-05-12 10:56:57 +02:00
Johannes Marbach
8cf09217d6 Switch to structs in yet more places 2025-05-12 10:56:57 +02:00
Johannes Marbach
f81945ad7e Fix build error 2025-05-12 10:56:57 +02:00
Johannes Marbach
c21f97274c Switch to struct 2025-05-12 10:56:57 +02:00
Johannes Marbach
da67bacfbf Add changelog 2025-05-12 10:56:57 +02:00
Johannes Marbach
175d854a9b feat(ffi): Add methods for observing account data changes
Signed-off-by: Johannes Marbach <n0-0ne+github@mailbox.org>
2025-05-12 10:56:57 +02:00
Ivan Enderlin
afabfb97b6 task(ui): Log when the room name is empty when filtering the room list. 2025-05-12 10:24:52 +02:00
Yousef Moazzam
8e4554d3c0 test: create room server ACL event with EventFactory 2025-05-12 09:30:36 +02:00
Yousef Moazzam
f1ea47f0b6 test: add room server ACL event method to EventFactory 2025-05-12 09:30:36 +02:00
Yousef Moazzam
26f1282c6a test: create room power level events with EventFactory 2025-05-10 20:35:57 +02:00
Yousef Moazzam
4053321cd0 test: add room power levels event method to EventFactory 2025-05-10 20:35:57 +02:00
Robin
561158c7bb fix(tests): Avoid depending on the local time zone in tests
This test fails when run in the Americas, because over here the Unix epoch took place in 1969 =D
2025-05-09 20:47:48 +02:00
Mauro Romito
c023745dcf crates: update Ruma to support MSC 4278
This will later be handled once the account data observation PR is ready
2025-05-09 14:41:17 +02:00
Yousef Moazzam
6ba68fe87e test: add timeline events in bulk to room builder 2025-05-09 11:51:45 +02:00
Yousef Moazzam
7afb46cc0c test: create room create event with EventFactory 2025-05-09 11:51:45 +02:00
Yousef Moazzam
93dcd07073 test: add room create event method to EventFactory 2025-05-09 11:51:45 +02:00
Yousef Moazzam
cf2f507951 test: create member event with EventFactory 2025-05-09 11:51:45 +02:00
Damir Jelić
35a2ce97d8 refactor(widget): Use streams to streamline the action processing logic 2025-05-09 11:07:41 +02:00
Ivan Enderlin
f042084bd2 doc: Generate doc with --generate-link-to-definition.
This patch adds the `--generate-link-to-definition`
argument to `rustdoc` for `docs.rs`. This is using
https://github.com/rust-lang/rust/pull/84176 to add links in the source
code page.
2025-05-08 13:08:32 +02:00
Doug
be6d5f9bd9 ffi: Add support for the login hints with OIDC. 2025-05-08 12:10:16 +02:00
Doug
506060f23d sdk: Add support for generic OAuth login hints.
See https://github.com/element-hq/matrix-authentication-service/pull/4512
2025-05-08 12:10:16 +02:00
Richard van der Hoff
55d475df04 Merge pull request #4988 from matrix-org/rav/history_sharing/better_sender_data
crypto: improve SenderData stored with room key bundle data
2025-05-07 22:31:48 +01:00
Richard van der Hoff
f349a66292 crypto: improve SenderData stored with room key bundle data
If we already have cross-signing details for the owner of the device at the
point we receive the to-device message, we should store that rather than just
the device info.
2025-05-07 22:16:57 +01:00
Richard van der Hoff
3742bdc7cf crypto: move some logic from SenderDataFinder to SenderData
create a new method `SenderData::from_device` which does the last few steps of
`SenderDataFinder`: turns out we want it elsewhere. Add some tests to test that
functionality in isolation.
2025-05-07 22:16:57 +01:00
Doug
b5b2450eac ffi: Expose the QrCodeData server name. matrix-sdk-ffi/20250507 2025-05-07 13:40:29 +02:00
Denis Kasak
fc071bafb2 docs: Various fixes for store-related comments.
- Doc comment for the SQLite-based state store incorrectly referred to
  it as a "cryptostore".
- Consistent capitalisation of SQLite.
- Consistent use of indefinite article "an" before SQLite.
- Fix line length.
2025-05-06 13:55:03 +02:00
Yousef Moazzam
e4ce1790cd test: replace sync_timeline_event! with EventFactory in notification test 2025-05-06 13:34:00 +02:00
Ivan Enderlin
3461b13ec7 doc(sqlite): Add entry in the CHANGELOG.md. 2025-05-06 09:17:54 +02:00
Ivan Enderlin
83e4314645 fix(sqlite): Fix a UNIQUE constraint violation with Update::RemoveItem.
Imagine we have the following events:

| event_id | room_id | chunk_id | position |
|----------|---------|----------|----------|
| $ev0     | !r0     | 42       | 0        |
| $ev1     | !r0     | 42       | 1        |
| $ev2     | !r0     | 42       | 2        |
| $ev3     | !r0     | 42       | 3        |
| $ev4     | !r0     | 42       | 4        |

`$ev2` has been removed, then we end up in this state:

| event_id | room_id | chunk_id | position |
|----------|---------|----------|----------|
| $ev0     | !r0     | 42       | 0        |
| $ev1     | !r0     | 42       | 1        |
|          |         |          |          | <- no more `$ev2`
| $ev3     | !r0     | 42       | 3        |
| $ev4     | !r0     | 42       | 4        |

We need to shift the `position` of `$ev3` and `$ev4` to `position - 1`,
like so:

| event_id | room_id | chunk_id | position |
|----------|---------|----------|----------|
| $ev0     | !r0     | 42       | 0        |
| $ev1     | !r0     | 42       | 1        |
| $ev3     | !r0     | 42       | 2        |
| $ev4     | !r0     | 42       | 3        |

Usually, it boils down to run the following query:

```sql
UPDATE event_chunks
SET position = position - 1
WHERE position > 2 AND …
```

Okay. But `UPDATE` runs on rows in no particular order. It means that
it can update `$ev4` before `$ev3` for example. What happens in this
particular case? The `position` of `$ev4` becomes `3`, however `$ev3`
already has `position = 3`. Because there is a `UNIQUE` constraint
on `(room_id, chunk_id, position)`, it will result in a constraint
violation.

There is **no way** to control the execution order of `UPDATE` in
SQLite. To persuade yourself, try:

```sql
UPDATE event_chunks
SET position = position - 1
FROM (
    SELECT event_id
    FROM event_chunks
    WHERE position > 2 AND …
    ORDER BY position ASC
) as ordered
WHERE event_chunks.event_id = ordered.event_id
```

It will fail the same way.

Thus, we have 2 solutions:

1. Remove the `UNIQUE` constraint,
2. Be creative.

The `UNIQUE` constraint is a safe belt. Normally, we have
`event_cache::Deduplicator` that is responsible to ensure there is no
duplicated event. However, relying on this is “fragile” in the sense it
can contain bugs. Relying on the `UNIQUE` constraint from SQLite is more
robust. It's “braces and belt” as we say here.

So. We need to be creative.

Many solutions exist. Amongst the most popular, we see _dropping and
re-creating the index_, which is no-go for us, it's too expensive. I
(@hywan) have adopted the following one:

- Do `position = position - 1` but in the negative space, so
 `position = -(position - 1)`. A position cannot be negative; we are
  sure it is unique!
- Once all candidate rows are updated, do `position = -position` to move
  back to the positive space.

'told you it's gonna be creative.

This solution is a hack, **but** it is a small number of operations, and
we can keep the `UNIQUE` constraint in place.

This patch updates the `test_linked_chunk_remove_item` to handle
6 events. On _my_ system, with _my_ SQLite version, it triggers the
`UNIQUE` constraint violation without the bug fix.
2025-05-06 09:17:54 +02:00
dependabot[bot]
c726bc5904 chore(deps): Bump tj-actions/changed-files
Bumps [tj-actions/changed-files](https://github.com/tj-actions/changed-files) from 5426ecc3f5c2b10effaefbd374f0abdc6a571b2f to 4168bb487d5b82227665ab4ec90b67ce02691741.
- [Release notes](https://github.com/tj-actions/changed-files/releases)
- [Changelog](https://github.com/tj-actions/changed-files/blob/main/HISTORY.md)
- [Commits](5426ecc3f5...4168bb487d)

---
updated-dependencies:
- dependency-name: tj-actions/changed-files
  dependency-version: 4168bb487d5b82227665ab4ec90b67ce02691741
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-05-05 18:35:37 +03:00
dependabot[bot]
970af0de7c chore(deps): Bump crate-ci/typos from 1.31.2 to 1.32.0
Bumps [crate-ci/typos](https://github.com/crate-ci/typos) from 1.31.2 to 1.32.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.31.2...v1.32.0)

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

Signed-off-by: dependabot[bot] <support@github.com>
2025-05-05 17:31:29 +02:00
mpeter50
8be0a7df95 Update logging of device verification request timestamp valdiation
In element-hq/element-web#29625 it was found to be useful to give more visibility to this kind of verification error.

Signed-off-by: mpeter50 <83356418+mpeter50@users.noreply.github.com>
2025-05-05 09:46:29 +03:00
Michael Goldenberg
8fd122c431 style(indexeddb): cargo fmt
Signed-off-by: Michael Goldenberg <m@mgoldenberg.net>
2025-05-05 08:44:54 +02:00
Michael Goldenberg
f661b82f18 refactor(indexeddb): rename module (indexeddb_serializer -> serializer)
Signed-off-by: Michael Goldenberg <m@mgoldenberg.net>
2025-05-05 08:44:54 +02:00
Michael Goldenberg
77ee7f1d19 refactor(indexeddb): change indexeddb_serializer::Result to use IndexeddbSerializerError
Signed-off-by: Michael Goldenberg <m@mgoldenberg.net>
2025-05-05 08:44:54 +02:00
Michael Goldenberg
af90b7ac4e refactor(indexeddb): add conversions into IndexeddbSerializerError
Signed-off-by: Michael Goldenberg <m@mgoldenberg.net>
2025-05-05 08:44:54 +02:00