Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ui): Reset Timeline when a user is ignored/unignored #2467

Conversation

Hywan
Copy link
Member

@Hywan Hywan commented Aug 28, 2023

This PR can be reviewed commit-by-commit for more comfort.

The global idea is that the Timeline is cleared when a user is ignored/unignored.

This PR also splits TimelineInnerState::lock to ::read and ::write, and the lock release observer is notified only for the write lock.


Hywan added 7 commits August 30, 2023 17:26
This patch updates the `RoomDataProvider` trait to add a new `client`
method. This is going to be useful for what's coming next.
This patch updates `TimelineInner::subscribe` as follows:

* It's no longer `async`,
* It returns `impl Stream` instead of `(Vector<_>, impl Stream)`,
* The first item returns by the `Stream` is `VectorDiff::Reset`, which
  replaces the initial `Vector<_>` from the tuple,
* The `Stream` is a “switched stream”, it is reset to
  `VectorDiff::Reset` every time `BaseClient::ignore_user_list_changes`
  receives a new value, i.e. every time a user is ignored or unignored,
  the `Timeline` stream is reset.

Consequently, `TimelineInner::subscribe_batched` is no longer `async`
too. This propagates to `Timeline` where `subscribe` and
`subscribe_batched` are no longer `async` too.
This patch updates `TimelineInner::subscribe` to clear the entire
timeline when a user is ignored/unignored.
@Hywan Hywan force-pushed the feat-base-ignore-user-list-changes-reset-timeline branch from 1a9b926 to 301d8fd Compare August 30, 2023 15:31
@Hywan Hywan marked this pull request as ready for review August 30, 2023 15:31
@Hywan Hywan requested a review from a team as a code owner August 30, 2023 15:31
@Hywan Hywan requested review from jplatte and removed request for a team August 30, 2023 15:31
@Hywan Hywan force-pushed the feat-base-ignore-user-list-changes-reset-timeline branch from d4d924c to 95e0414 Compare August 31, 2023 11:47
@codecov
Copy link

codecov bot commented Aug 31, 2023

Codecov Report

Patch coverage: 92.59% and project coverage change: +0.05% 🎉

Comparison is base (06a19f0) 77.33% compared to head (6278bc0) 77.39%.
Report is 9 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2467      +/-   ##
==========================================
+ Coverage   77.33%   77.39%   +0.05%     
==========================================
  Files         184      184              
  Lines       19447    19456       +9     
==========================================
+ Hits        15039    15057      +18     
+ Misses       4408     4399       -9     
Files Changed Coverage Δ
...rates/matrix-sdk-ui/src/timeline/event_item/mod.rs 76.51% <ø> (ø)
crates/matrix-sdk-ui/src/timeline/inner/mod.rs 72.00% <90.24%> (+0.30%) ⬆️
crates/matrix-sdk-ui/src/timeline/inner/state.rs 91.42% <100.00%> (+0.67%) ⬆️
crates/matrix-sdk-ui/src/timeline/mod.rs 81.50% <100.00%> (-0.42%) ⬇️
crates/matrix-sdk-ui/src/timeline/traits.rs 55.10% <100.00%> (+1.91%) ⬆️

... and 3 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Hywan
Copy link
Member Author

Hywan commented Aug 31, 2023

@jplatte Ready to review!

@Hywan Hywan force-pushed the feat-base-ignore-user-list-changes-reset-timeline branch from 138221c to 2a6aae2 Compare August 31, 2023 12:51
…rite`.

This patch splits the `TimelineInnerStateLock::lock` method into
`::read` and `::write`. The idea is that a read-only lock doesn't
hold a clone of the lock release observer (`lock_release_ob:
SharedObservable<()>`), it will not notify the observer. Then it's only
the write lock that holds a clone of the lock release observer, and will
notify it.

This patch updates the code accordingly as best as possible.
@Hywan Hywan force-pushed the feat-base-ignore-user-list-changes-reset-timeline branch from 2a6aae2 to 6278bc0 Compare August 31, 2023 13:15
@Hywan Hywan enabled auto-merge August 31, 2023 13:50
Comment on lines +153 to +181
let state = self.state.clone();
let ignore_user_list_stream = self.client.subscribe_to_ignore_user_list_changes();

stream! {
pin_mut!(ignore_user_list_stream);

loop {
let (timeline_items, timeline_stream) = {
let state = state.read().await;

(state.items.clone(), state.items.subscribe())
};

yield stream::once(
// Reset the stream with all its items.
ready(VectorDiff::Reset { values: timeline_items } ),
)
.chain(
timeline_stream
);

// When this is fired, let's loop.
let _ = ignore_user_list_stream.next().await;

// A user has been ignored/unignored? Let's clear the timeline.
state.write().await.clear();
}
}
.switch()
Copy link
Collaborator

@jplatte jplatte Aug 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this should be part of the "inner" bits of the timeline. Can you revert all the changes in this file and the unit tests please, and move the listening for the ignore user list changes one level higher, into the timeline module? Then we don't need to touch the RoomDataProvider trait either. (also, I think the RwLock thing should be a separate PR, if we want to do it at all – if we do the eyeball-im changes discussed today we probably don't need it)

@jplatte
Copy link
Collaborator

jplatte commented Sep 4, 2023

This has been implemented in a different way in #2504.

@jplatte jplatte closed this Sep 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants