Commit Graph

13223 Commits

Author SHA1 Message Date
Ivan Enderlin 873bc6b2a4 Just to trigger the CI, after Github issues. 2023-05-11 09:01:32 +02:00
Jonas Platte 9842645377 Fix struct name for DebugNotification output 2023-05-10 23:42:32 +02:00
Jonas Platte 176934e359 Fix debug output for raw events
It was looking for an "event_type" field rather than just "type".
The code was also more complex than necessary.
2023-05-10 21:50:12 +02:00
Ivan Enderlin 75f3bbcf63 chore(ffi): Update according to last commit. 2023-05-10 15:57:43 +02:00
Ivan Enderlin 02cfee68c4 feat(sdk): SlidingSyncRoom is cheap to clone.
This patch changes `SlidingSyncRoom` to move all its fields inside an
inner type `SlidingSyncRoom` behind an `Arc`, so that cloning is cheap,
and all clones are sharing the same state.
2023-05-10 15:53:21 +02:00
Ivan Enderlin 09bb0fcdd3 test(sdk): Testing FrozenSlidingSyncRoom receives a subset of the timeline queue. 2023-05-10 14:42:00 +02:00
Ivan Enderlin 54bc774d62 test(sdk): Clarify a test with json! instead of a string. 2023-05-10 14:15:07 +02:00
Ivan Enderlin e2af4ccfe6 fix(ffi): Fix types. 2023-05-10 14:01:29 +02:00
Ivan Enderlin 1a50afe167 feat(sdk): Rethink the SlidingSyncList::state after a reset
feat(sdk): Rethink the `SlidingSyncList::state` after a reset
2023-05-10 13:56:57 +02:00
Ivan Enderlin 3a25608a6e feat(sdk): Rethink the SlidingSyncList::state after a reset.
A `SlidingSyncList` has a state, which can be either `NotLoaded`,
`Preloaded`, `PartiallyLoaded`, or `FullyLoaded`.

A `SlidingSyncList` can be reset, either manually when
`SlidingSyncList::reset` is called, or when a range is updated for
example.

Resetting a list is modifying its state. Prior to this patch, the state
was set to `NotLoaded`. However, it's not entirely true. This patch
updates this behavior to the following rules:

* When the state is `NotLoaded`, it's kept at this state as nothing has
  happened yet,
* When the state is `Preloaded`, the list is restored from the cache,
  but nothing has happened yet too, so it's kept at this state,
* When the state is `PartiallyLoaded` or `FullyLoaded`, it means some
  (or all) updates have been done, so the new state is `PartiallyLoaded`
  after the reset.

The list' state is used mostly by the client to know whether a loader
should be prompted to the users. The ranges are modified when the
users scroll inside the room list for example: scrolling in the room
list doesn't imply the state should go to `NotLoaded`. Some data
have potentially be loaded, so changing the ranges should result in a
`PartiallyLoaded` state. It seems more logical once explained like this.
2023-05-10 13:31:52 +02:00
Ivan Enderlin 22b2e54aca test(sdk): Test SlidingSyncRoom::update, esp. the timeline_queue. 2023-05-10 13:17:09 +02:00
Ivan Enderlin 7c21f8851c test(sdk): Test SlidingSyncRoom::state. 2023-05-10 09:35:45 +02:00
Ivan Enderlin c00b2db51b test(sdk): Test SlidingSyncRoom::prev_batch. 2023-05-10 09:35:45 +02:00
Ivan Enderlin e7e66dc17e test(sdk): Test SlidingSyncRoom::required_state. 2023-05-10 09:35:45 +02:00
Ivan Enderlin d688918036 feat(sdk): Don't update invite_state in SlidingSyncRoom.
`invite_state` is managed when the Sliding Sync response is processed/
handled by the `Client`. Inside `SlidingSyncRoom`, it's not necessary to
maintain it.
2023-05-10 09:35:45 +02:00
Ivan Enderlin bafcaa9c85 test(sdk): Test SlidingSyncRoom::*unread_notifications. 2023-05-10 09:35:45 +02:00
Ivan Enderlin 379c9d6520 test(sdk): Test SlidingSyncRoom::is_dm and ::is_initial_response. 2023-05-10 09:35:45 +02:00
Ivan Enderlin 04feb7a2a2 test(sdk): Test SlidingSyncRoom::name. 2023-05-10 09:35:45 +02:00
Ivan Enderlin de373c07a6 feat(sdk): Add a constant to represent the max number of timeline events to put in the cache.
This patch creates a constant to represent the
maximum number of timeline event to put in the cache:
`NUMBER_OF_TIMELINE_EVENTS_TO_KEEP_FOR_THE_CACHE`. Verbose, but easily
understandable.

This patch also renames a few variables.
2023-05-10 09:35:45 +02:00
Ivan Enderlin 39590c4e07 chore(sdk): Re-order methods on SlidingSyncRoom. 2023-05-10 09:35:45 +02:00
Ivan Enderlin 3a0ebbd271 doc(sdk): Update documentation. 2023-05-10 09:35:45 +02:00
Ivan Enderlin 32ef2f7c61 feat(sdk): Simplify SlidingSyncRoom::timeline_queue.
This patch simplifies `SlidingSyncRoom::timeline_queue` from

```rust
Arc<RwLock<ObservableVector<SyncTimelineEvent>>>
```

to

```rust
Vector<SyncTimelineEvent>
```

First, we don't need to be observable. It's never observed since
it's private, and even privately, it's never observed, there is no
subscriber.

Second, no lock is required as updates happen synchronously.

Third, `Arc` is not necessary. We want each clone of `SlidingSyncRoom`
to not share any state across them.

Finally, this patch simplifies the iterator + `.push_back` by a simple
`.extend` to update the `timeline_queue`. Behind the scene, `impl Extend
for Vector` actually does an iterate + `.push_back`; let's keep our code
simple though.
2023-05-10 09:35:45 +02:00
Ivan Enderlin 6afca5367d feat(sdk): Replace SlidingSyncRoom::is_cold by a real state enum.
`SlidingSyncRoom::is_cold` is not well-named. This patch introduces an
enum, named `SlidingSyncRoomState` which contains more detailed state:
`NotLoaded`, `Preloaded`, and `Loaded`.

The use of `AtomicBool` is also removed. Thus, we no longer need an
`Arc` for the state, which makes `Clone` more obvious: the state is not
shared across clones anymore.
2023-05-10 09:35:45 +02:00
Ivan Enderlin ef9bf87d89 chore(sdk): Write imports at the correct place. 2023-05-10 09:35:41 +02:00
Ivan Enderlin 349c7c3f68 feat(sdk): Remove SlidingSyncRoom::prev_batch.
A `SlidingSyncRoom` receives an Ruma
`api::client::sync::sync_events::v4:SlidingSyncRoom`. This value is
stored in the `SlidingSyncRoom::inner` field. From here, some getters
like `name()`, `is_dm()` etc. are using the `inner` field to compute a
result. There was one exception though: `prev_batch`. This value is part
of `v4::SlidingSyncRoom` but it was copied and updated in its own field:
`SlidingSyncRoom::prev_batch`.

I was wondering why. Turns out, there is no reason. Its getter
`prev_batch()` is public, but it's not used by the FFI bindings, so
basically nobody uses it (as this project is experimental as the time of
writing, we know our users).

This patch removes the `SlidingSyncRoom::prev_batch` field.

This patch also removes the `SlidingSyncRoom::prev_batch()` getter.

This patch finally removes the `FrozenSlidingSyncRoom::prev_batch` field
too.
2023-05-10 09:34:39 +02:00
Ivan Enderlin cb2bb84d88 fix(sdk): Remove SlidingSyncRoom::is_loading_more.
First, this field is not used by ElementX.

Second, this field is never updated, so it always returns `false`, which
seems… buggy and useless.
2023-05-10 09:34:38 +02:00
Ivan Enderlin 4132571270 doc(sdk): Write documentation for SlidingSyncRoom. 2023-05-10 09:34:38 +02:00
Ivan Enderlin 0038a0389a chore(sdk): Create one block for rooms, one block for lists.
This patch moves the code into dedicated blocks: one for updating the
rooms, one for updating the lists.
2023-05-10 09:34:27 +02:00
Ivan Enderlin 3e6dd1cecb feat(sdk): Don't remove and re-insert a room when it exists.
Prior to this patch, to check a room exists, it was removed from the
collection, then re-added if it exists. Instead of doing this `remove`
+ `insert` dance, we can simply use `get_mut`, which also returns an
`Option`. This patch does that, in addition to rewrite the code to use a
`match` instead of a `if` + `else`.
2023-05-10 09:21:20 +02:00
Mauro 6eeee8ee53 ffi: Expose EventTimelineItem::read_receipts and the NotificationItem#room_canonical_alias 2023-05-09 15:26:07 +00:00
Jonas Platte 2de786c516 Rename fetch_event_details to fetch_details_for_event 2023-05-09 17:25:39 +02:00
Jonas Platte 159b999485 Update call_event_handlers span to default level of info 2023-05-09 16:53:17 +02:00
Jonas Platte b6453772c3 Fix remaining sync response Debug event content leaks 2023-05-09 16:51:08 +02:00
Jonas Platte 0aa1f599c5 common: Make debug module public
… and remove re-exports of its contents from crate root.
2023-05-09 16:51:08 +02:00
Jonas Platte 1f01555e4e sdk: Add more logging and a new branch to fetch_in_reply_to_details 2023-05-09 16:26:52 +02:00
Jonas Platte c9d35a8fe5 sdk: Clean up spans for sliding sync_once 2023-05-09 12:49:43 +02:00
Benjamin Bouvier b257d0dacd chore: add the --workspace flag back in the documentation CI task
Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-05-09 10:21:48 +02:00
Benjamin Bouvier 1aff90a96f chore: fix doc comments in code and READMEs
Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-05-09 10:21:48 +02:00
Jonas Platte 1380e9c4ec Inline sync response structs with a single field 2023-05-09 10:08:34 +02:00
Jonas Platte 40c0f0896e Add some missing copyright headers 2023-05-09 10:08:34 +02:00
Jonas Platte aa3b2d4698 base: Don't log raw event for notifications 2023-05-09 10:08:34 +02:00
Jonas Platte 935dc6ec41 base: Remove presence events from debug output
We shouldn't be logging raw events, and there's not really a useful
subset we could include.
2023-05-09 10:08:34 +02:00
Jonas Platte ae4518c1a7 base: Remove unused Deserialize, Serialize impls 2023-05-09 10:08:34 +02:00
Jonas Platte 2d1f514a13 Box fields to reduce stack size of structs 2023-05-08 18:47:01 +02:00
Jonas Platte ce3c818156 Box futures to reduce composed future's sizes 2023-05-08 18:47:01 +02:00
Jonas Platte 1bc99a62a5 Make Store::save_changes non-lazy 2023-05-08 18:47:01 +02:00
Jonas Platte 3a74e8647b Reduce amount of local variables before .await in async fn 2023-05-08 18:47:01 +02:00
Jonas Platte c3d7a0704a A little bit of cleanup 2023-05-08 18:47:01 +02:00
Jonas Platte a8fb54ee67 Replace qualified name with use 2023-05-08 18:47:01 +02:00
Jonas Platte c5decd2294 crypto: Pass AnyToDeviceEventContent by reference
… in a few places where it doesn't need to be moved.
2023-05-08 18:47:01 +02:00