Commit Graph

1425 Commits

Author SHA1 Message Date
Nashwan Azhari
cb9690ecba doc: change matrix.org/docs/spec links to spec.matrix.org 2026-02-02 10:24:11 +01:00
Ivan Enderlin
d348fe62f2 refactor(base): Use Iterator::find and Iterator::any. 2026-01-30 15:34:48 +01:00
Ivan Enderlin
1dc1d2a3f0 feat(sdk): Add LatestEventValue::RemoteInvite.
This patch adds the `LatestEventValue::RemoteInvite` variant. The goal
of this is to be able to compute a `LatestEventValue` for an invite to
a room. Using `LatestEventValue::Remote` isn't possible because it's
usually built from the `RoomEventCache`. However, the `EventCache`
doesn't handle invites for one reason: invites only manipulate stripped
state-events, whist the `EventCache` manipulates non-stripped (state)
events.

The `LatestEvents` API receives a stream of `RoomInfoNotableUpdate`. It
reacts to update from the `RoomInfo`. It filters out all reasons except
`MEMBERSHIP`. When the `MEMBERSHIP` is updated, and the room' state is
`Invited`, then a `RemoteInvite` is computed.

The `Invite` type is updated to include the `inviter_id` in case the
`inviter` is missing. Indeed, we always know the user ID of the inviter,
this information isn't optional.
2026-01-30 15:34:48 +01:00
Ivan Enderlin
99b83b98b6 fix(base): Emit RoomInfoNotableUpdateReasons for invited and knocked rooms creation. 2026-01-30 15:34:48 +01:00
Kévin Commaille
4feaa0ba49 Upgrade Ruma
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2026-01-30 10:16:06 +01:00
Kévin Commaille
3852129612 refactor(base): Improve logs
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2026-01-23 16:24:47 +01:00
Kévin Commaille
e77e2ae18f fix(base): Handle sync state events that fail to deserialize
If the homeserver provides a state event to a client, it means that it
considers the event to be valid. If a state event is valid, it always
updates the state map of the room. So ignoring events that fail to
deserialize means that the local state map is different than the one
from the server.

In some cases the Matrix spec even explicitly says that if a required
field is missing from the content of a state event, it should be treated
as if the event is missing from the state map. And if a required field
is missing, the event will fail to deserialize.

So this handles state events very closely to how a server would we only
deserialize the event type and the state key first to make sure that a
valid state event always updates the local state map. Then we only
deserialize the events lazily when we encounter an event type that
updates the `RoomInfo`. Because we deserialize the event lazily and some
methods might edit parts of an event before passing it to `RoomInfo`,
the (possibly edited) deserialized event is cached alongside the raw
event and its keys to be able to pass it further down the chain.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2026-01-23 16:24:47 +01:00
Kévin Commaille
9590b3c683 refactor(base): Move state event decryption logic in separate function
To simplify the match arms of `dispatch`.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2026-01-23 16:24:47 +01:00
Kévin Commaille
e69f9e4f89 refactor(base): Remove unused beacons from BaseRoomInfo
This field was added already unused in the initial PR
https://github.com/matrix-org/matrix-rust-sdk/pull/3741 for live
location sharing.

The follow up live location PRs didn't make use of it either:

- https://github.com/matrix-org/matrix-rust-sdk/pull/3771
- https://github.com/matrix-org/matrix-rust-sdk/pull/3794
- https://github.com/matrix-org/matrix-rust-sdk/pull/4025

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2026-01-22 18:25:48 +02:00
Benjamin Bouvier
32666e4c24 feat(send queue): cache a thumbnail as such for the media that we just uploaded
Before: after uploading a media and a thumbnail with the send queue, the
thumbnail would be cached only as a "file", and not as a thumbnail. This
is wasteful, if the embedder is interested in getting a thumbnail of the
exact same dimensions, for the file they've updated; there's no good
reason to wait for the server to return it back.

However, there were good reasons to store it as a file in the past. So,
we're choosing here to duplicate the thumbnail in the media store:
- it's saved as a file for its own MXC URI (which preserves the previous
behavior)
- it's also saved as a thumbnail for the media MXC URI (which implements
the desired behavior).

Tests are updated to reflect this.
2026-01-22 13:31:49 +01:00
Benjamin Bouvier
5b8ff8a76d refactor(state store): remove StateStore::upsert_thread_subscription
There is `StateStore::upsert_thread_subscriptions` as a proper
replacement these days.
2026-01-16 17:01:03 +01:00
Skye Elliot
cd9f433358 Merge pull request #5945 from matrix-org/kaylendog/history-sharing/encryption-info
feat: Add `forwarder: ForwarderInfo` to `EncryptionInfo`.

Introduces `ForwarderInfo` which which exposes information about the forwarder of the  keys with which an event was encrypted if they were shared as part of an [MSC4268](https://github.com/matrix-org/matrix-spec-proposals/pull/4268) room key bundle.
2025-12-19 17:29:22 +00:00
Ivan Enderlin
d5898a64ab feat(base): Add LatestEventValue::event_id.
This patch adds the `event_id` method on `LatestEventValue`, along with
the tests.
2025-12-19 14:03:11 +01:00
Ivan Enderlin
42b79d7d8a feat(base): LatestEventValue::LocalHasBeenSent gains an event_id field.
This patch adds the `event_id: OwnedEventId` field to
`LatestEventValue::LocalHasBeenSent`.
2025-12-19 14:03:11 +01:00
razvp
67b1de613c feat(state-stores): Add StateStore::upsert_thread_subscriptions() method for bulk upsert 2025-12-17 11:03:50 +01:00
Ivan Enderlin
ccf11ad041 feat(ui): latest_event sorter handles LatestEventValue::LocalHasBeenSent.
This patch changes the semantics of the Room List `latest_event`
sorter by changing “is local” to “is remote like”, to include the new
`LatestEventValue::LocalHasBeenSent` variant.
2025-12-16 13:45:00 +01:00
Ivan Enderlin
631671fb1c fix(sdk): Introduce LatestEventValue::LocalHasBeenSent.
The problem we are trying to solve is the following:

- a local event is being sent,
- the `LatestEventValue` is `LocalIsSending`,
- the local event is finally sent,
- the `LatestEventValue` is still `LocalIsSending` purposely, with the
  hope that an update from the Event Cache will replace it.

But sometimes, this update from the Event Cache comes **before** the
update from the Send Queue. Why is it problem? Because updates from the
Event Cache are ignored until the buffer of local `LatestEventValue`s
aren't empty, which means that if an update from the Event Cache is
received before `RoomSendQueueUpdate::SentEvent`, it is ignored, and the
`LatestEventValue` stays in the `LocalIsSending` state. That's annoying.

The idea is to introduce a new state: `LocalHasBeenSent` which mimics
`Remote`, but for a local event. It clarifies the state of a sent event,
without relying on the Event Cache.
2025-12-16 13:45:00 +01:00
Ivan Enderlin
a630904b41 perf(sdk): Do not replace a LatestEventValue::None by itself.
Replacing a `LatestEventValue::None` by a `LatestEventValue::None` is
ignored. It reduces the number of (useless) updates in the system.
2025-12-16 12:33:04 +01:00
Damir Jelić
3a63838cdb test: Disable the lease lock tests for the memory store on wasm
This test for one reason or the other sporadically panics with an:
    > RuntimeError: unreachable

Let's disable this test on Wasm for now since the memory store isn't
that relevant anyways, especially not on Wasm.
2025-12-15 13:56:11 +01:00
Ivan Enderlin
37c516f7f9 refactor: Rename new_latest_event to latest_event.
This patch removes the “new_” prefix to the latest event API.
2025-12-05 09:40:47 +01:00
Ivan Enderlin
81a8aa063b chore(base): Remove the old latest event API. 2025-12-05 09:40:47 +01:00
Damir Jelić
4ea0418abe fix: Don't attempt to serialize custom join rules (#5924)
This is not supported by Ruma. The join_rule field, despite being
defined as a pure string, can have associated data to it based on the
join rule variant.

This means that custom and unknown enum variants might lose data when
reserializing.

Let's just skip the serialization of custom join rules in the RoomInfo,
the concrete value is still available in the state store, it's just not
kept at hand in the RoomInfo.

Signed-off-by: Damir Jelić <poljar@termina.org.uk>
Co-authored-by: Ivan Enderlin <ivan@mnt.io>
2025-12-03 16:54:58 +01:00
Jorge Martín
bc45457d0e feat: add Client::get_store_sizes
This method will retrieve the database sizes if available and expose it in the client.

Note: the actual database size measuring is only implemented for the SQLite based stores
2025-12-03 15:41:42 +01:00
Jorge Martín
76651aec69 refactor: don't use full namespace for std::Result 2025-12-03 15:41:42 +01:00
Jorge Martín
94e5dbea0c refactor: hide optimize_store methods, add warnings to not use them in production
Also fix lint issue
2025-12-03 15:41:42 +01:00
Jorge Martín
b04cc9fe27 feat: Implement the new Store::optimize method added in the store traits
Only SQLite based stores will implement it for now, calling the `SqliteAsyncConnExt::vacuum` method
2025-12-03 15:41:42 +01:00
Jorge Martín
054dc31ce4 feat(sdk): Add Client::optimize_stores
This method should trigger any optimization/maintenance behaviours available to the stores, like `VACUUM` in SQLite
2025-12-03 15:41:42 +01:00
Ivan Enderlin
aaff9c5d72 test: Update tests according to last patches. 2025-12-03 13:11:40 +01:00
Ivan Enderlin
045eb3486b test: Use SerializableEventContent::new instead of from_raw.
This patch replaces calls to `SerializableEventContent::from_raw` by
`new`: it's simpler and safer as it's not possible to use an invalid
event type.
2025-12-03 13:11:40 +01:00
Ivan Enderlin
40738ae119 feat(sdk): The Send Queue stores the sent event in the Event Cache.
The event has been sent to the server and the server has received it.
Yepee! Now, we usually wait on the server to give us back the event via
the sync.

Problem: sometimes the network lags, can be down, or the server may be
slow; well, anything can happen. It results in a weird situation where
the user sees its event being sent, then disappears before it's received
again from the server.

To avoid this situation, this patch eagerly saves the event in the Event
Cache. It's similar to what would happen if the event was echoed back
from the server via the sync, but we avoid any network issues. The Event
Cache is smart enought to deduplicate events based on the event ID, so
it's safe to do that.
2025-12-03 13:11:40 +01:00
Kévin Commaille
e47867f232 refactor(sdk): Split supported versions and well-known cache
The supported versions are necessary for querying almost all endpoints,
but after homeserver auto-discovery the well-known info is only
necessary to get the MatrixRTC foci advertised by the homeserver. So it
shouldn't be necessary to always request both at the same time.

Besides:

- Not all clients support MatrixRTC, so they don't need the well-known
  info.
- The well-known info is only supposed to be used for homeserver
  auto-discovery before login. In fact, the MatrixRTC MSC was changed to
  use a new endpoint for this.
- We don't have access to the server name after restoring the Client, so
  the well-known lookup is more likely to fail.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-12-01 15:22:48 +00:00
Kévin Commaille
4411274b12 refactor(base): Split TTL store logic from ServerInfo into new type
To make it reusable.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-12-01 15:22:48 +00:00
Ivan Enderlin
478df4af33 test(sdk): Ensure EventCacheStoreLockGuard::clear_dirty is called!
This patch ensures that the `EventCacheStoreLockGuard::clear_dirty`
method is correctly called.
2025-11-25 15:41:27 +01:00
Ivan Enderlin
9e6a6c0e71 fix(base): Use the EventCacheStoreLockState. 2025-11-25 15:41:27 +01:00
Ivan Enderlin
d1633f2a78 feat(base): EventCacheStoreLockGuard can be cloned.
This patch implements `Clone` for `EventCacheStoreLockGuard`.
2025-11-25 15:41:27 +01:00
Ivan Enderlin
997f992d15 refactor(base): EventCacheStoreLockState owns a clone of the inner store.
This patch changes `EventCacheStoreLockState` to own a clone of
the inner store. It helps to remove the `'a` lifetime, and so it
“disconnects” from the lifetime of the store.
2025-11-25 15:41:27 +01:00
Ivan Enderlin
3d5b32494e feat(base): Add EventCacheStoreLockGuard::clear_dirty. 2025-11-25 15:41:27 +01:00
Ivan Enderlin
c5893f882c feat(common): Add CrossProcessLockGuard::is_dirty and ::clear_dirty.
This patch replicates the `is_dirty` and `clear_dirty` methods from
`CrossProcessLock` to `CrossProcessLockGuard`. It allows to get an
access to this API from a guard when one doesn't have the cross-process
lock at hand.
2025-11-25 15:41:27 +01:00
Ivan Enderlin
c98d9db185 feat(base) Create the EventCacheStoreLockState type.
This patch updates `EventCacheStoreLock::lock()` to return an
`EventCacheStoreLockState` instead of an `EventCacheStoreLockGuard`, so
that the caller has to handle dirty locks.
2025-11-25 15:41:27 +01:00
Ivan Enderlin
80decaebf4 chore(common) Rename CrossProcessLockKind to CrossProcessLockState.
This patch renames the `CrossProcessLockKind` type to
`CrossProcessLockState`.
2025-11-25 15:41:27 +01:00
Ivan Enderlin
a3424a7c4a feat(base): Explicitly handle the CrossProcessLockKind::Dirty case in MediaStore.
This patch replaces the `into_guard()` call by a `match` over
`CrossProcessLockKind` so that the `Dirty` case is explicitly handled.

The mid-term idea is to remove the `into_guard()` method because it
is “dangerous” as it hides the `Dirty` case.
2025-11-11 15:12:27 +01:00
Ivan Enderlin
46d05d877b fix(base): Remove a panic in a log.
We must not panic if the event has no event ID.
2025-11-11 11:15:59 +01:00
Ivan Enderlin
3f3f6c2fc6 refactor(common): Revisit CrossProcessLock::try_lock_once and spin_lock's outputs.
This patch changes the signature of `CrossProcessLock::try_lock_once`.
It was returning a:

```rust
Result<CrossProcessLockResult, CrossProcessLockError>
```

Now it returns a:

```rust
Result<Result<CrossProcessLockKind, CrossProcessLockUnobtained>, L::LockError>
```

We will explain these new types in a moment.

This patch also changes the signature of `CrossProcessLock::spin_lock`.
It was returning a:

```rust
Result<CrossProcessLockGuard, CrossProcessLockError>
```

Now it returns a:

```rust
Result<Result<CrossProcessLockKind, CrossProcessLockUnobtained>, L::LockError>
```

First off, we notice that the returned types are now unified. The
`CrossProcessLockResult` type has been renamed `CrossProcessLockKind`
and lives in a `Result::Ok`. The `CrossProcessLockResult::Unobtained`
variant has been removed, but `CrossProcessLockUnobtainedReason`
has been renamed to `CrossProcessLockUnobtained` and lives in a
`Result::Err`.

Second, the `CrossProcessLockError` now is a union type between
`CrossProcessLockUnobtained` and `TryLock::LockError`. It's not used
by `try_lock_once` or `spin_lock`, but only by the code using the
cross-process lock to provide a unified error type.

The ideas behind these changes are:

- it's easy to forward an error from the `TryLock`,
- it's difficult to ignore the `Clean` vs. `Dirty` state of the lock
  guard,
- unified API with clearly separated responsibility (the first `Result`
  vs. the second `Result`).

Note: the `CrossProcessLockKind::into_guard` method aims at being
removed. It's useful now to maintain compatibility but it's “dangerous”
as it makes trivial to skip `Clean` vs. `Dirty` states. We ultimately
don't want that.
2025-11-07 16:13:03 +01:00
Ivan Enderlin
6c922e69d0 feat(common): Add a cross-process lock generation.
This patch adds `CrossProcessLockGeneration`. A lock generation is an
integer incremented each time the lock is taken by another holder. If
the generation changes, it means the lock is _dirtied_. This _dirtying_
aspect is going to be expanded in the next patches. This patch focuses
on the introduction of this _generation_.

The `CrossProcessLock::try_lock_once` method, and
the `TryLock::try_lock` method, both returns a
`Option<CrossProcessLockGeneration>` instead of a `bool`: `true` is
replaced by `Some(_)`, `false` by `None`.
2025-11-07 11:26:09 +01:00
Jorge Martín
fa6d18b55f refactor(sdk): Make the deserialization of the ignored users happen in parallel too 2025-11-06 11:13:23 +01:00
Jorge Martín
17de97e98e refactor(sdk): Fetch member data concurrently
Creating a `RoomMember` takes a lot of store queries, and previously all of them were done sequentially. I've tried to make this process run as much in parallel as I can.
2025-11-06 11:13:23 +01:00
Damir Jelić
49db60d951 feat: Allow events to be fetched by event type 2025-11-04 13:58:49 +01:00
Johannes Marbach
34d71b0392 feat(composer): add support for attachments in drafts
Signed-off-by: Johannes Marbach <n0-0ne+github@mailbox.org>
2025-10-21 11:00:24 +01:00
Jorge Martin Espinosa
dcd8aa13f0 fix: NotificationSettings::unmute_room didn't clear the cached notification mode 2025-10-17 12:02:38 +02:00
Stefan Ceriu
fc892564d8 fix(spaces): handle empty string room names when computing the display names
Fixes #5762
2025-10-09 12:59:06 +03:00