-
Notifications
You must be signed in to change notification settings - Fork 289
timeline: add event focus mode for permalinks #3329
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7856dab
timeline: add support for a focus mode in the timeline
bnjbvr a6c4240
tests: add integration tests for the new timeline focus mode
bnjbvr 397a26e
ffi: add bindings for the timeline focus mode and associated functions
bnjbvr 25f893b
Merge branch 'main' into bnjbvr/permalink-mvp
Hywan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,11 +16,7 @@ use std::{collections::BTreeSet, sync::Arc}; | |
|
||
use eyeball::SharedObservable; | ||
use futures_util::{pin_mut, StreamExt}; | ||
use matrix_sdk::{ | ||
event_cache::{self, RoomEventCacheUpdate}, | ||
executor::spawn, | ||
Room, | ||
}; | ||
use matrix_sdk::{event_cache::RoomEventCacheUpdate, executor::spawn, Room}; | ||
use ruma::{events::AnySyncTimelineEvent, RoomVersionId}; | ||
use tokio::sync::{broadcast, mpsc}; | ||
use tracing::{info, info_span, trace, warn, Instrument, Span}; | ||
|
@@ -30,9 +26,12 @@ use super::to_device::{handle_forwarded_room_key_event, handle_room_key_event}; | |
use super::{ | ||
inner::{TimelineInner, TimelineInnerSettings}, | ||
queue::send_queued_messages, | ||
BackPaginationStatus, Timeline, TimelineDropHandle, | ||
Error, Timeline, TimelineDropHandle, TimelineFocus, | ||
}; | ||
use crate::{ | ||
timeline::{event_item::RemoteEventOrigin, PaginationStatus}, | ||
unable_to_decrypt_hook::UtdHookManager, | ||
}; | ||
use crate::unable_to_decrypt_hook::UtdHookManager; | ||
|
||
/// Builder that allows creating and configuring various parts of a | ||
/// [`Timeline`]. | ||
|
@@ -41,6 +40,7 @@ use crate::unable_to_decrypt_hook::UtdHookManager; | |
pub struct TimelineBuilder { | ||
room: Room, | ||
settings: TimelineInnerSettings, | ||
focus: TimelineFocus, | ||
|
||
/// An optional hook to call whenever we run into an unable-to-decrypt or a | ||
/// late-decryption event. | ||
|
@@ -56,10 +56,19 @@ impl TimelineBuilder { | |
room: room.clone(), | ||
settings: TimelineInnerSettings::default(), | ||
unable_to_decrypt_hook: None, | ||
focus: TimelineFocus::Live, | ||
internal_id_prefix: None, | ||
} | ||
} | ||
|
||
/// Sets up the initial focus for this timeline. | ||
/// | ||
/// This can be changed later on while the timeline is alive. | ||
pub fn with_focus(mut self, focus: TimelineFocus) -> Self { | ||
self.focus = focus; | ||
self | ||
} | ||
|
||
/// Sets up a hook to catch unable-to-decrypt (UTD) events for the timeline | ||
/// we're building. | ||
/// | ||
|
@@ -134,8 +143,8 @@ impl TimelineBuilder { | |
track_read_receipts = self.settings.track_read_receipts, | ||
) | ||
)] | ||
pub async fn build(self) -> event_cache::Result<Timeline> { | ||
let Self { room, settings, unable_to_decrypt_hook, internal_id_prefix } = self; | ||
pub async fn build(self) -> Result<Timeline, Error> { | ||
let Self { room, settings, unable_to_decrypt_hook, focus, internal_id_prefix } = self; | ||
|
||
let client = room.client(); | ||
let event_cache = client.event_cache(); | ||
|
@@ -144,14 +153,12 @@ impl TimelineBuilder { | |
event_cache.subscribe()?; | ||
|
||
let (room_event_cache, event_cache_drop) = room.event_cache().await?; | ||
let (events, mut event_subscriber) = room_event_cache.subscribe().await?; | ||
|
||
let has_events = !events.is_empty(); | ||
let (_, mut event_subscriber) = room_event_cache.subscribe().await?; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we explain why we drop events here? |
||
|
||
let inner = TimelineInner::new(room, internal_id_prefix, unable_to_decrypt_hook) | ||
let inner = TimelineInner::new(room, focus, internal_id_prefix, unable_to_decrypt_hook) | ||
.with_settings(settings); | ||
|
||
inner.replace_with_initial_events(events).await; | ||
let has_events = inner.init_focus(&room_event_cache).await?; | ||
|
||
let room = inner.room(); | ||
let client = room.client(); | ||
|
@@ -165,10 +172,10 @@ impl TimelineBuilder { | |
span.follows_from(Span::current()); | ||
|
||
async move { | ||
trace!("Spawned the event subscriber task"); | ||
trace!("Spawned the event subscriber task."); | ||
|
||
loop { | ||
trace!("Waiting for an event"); | ||
trace!("Waiting for an event."); | ||
|
||
let update = match event_subscriber.recv().await { | ||
Ok(up) => up, | ||
|
@@ -187,7 +194,7 @@ impl TimelineBuilder { | |
// current timeline. | ||
match room_event_cache.subscribe().await { | ||
Ok((events, _)) => { | ||
inner.replace_with_initial_events(events).await; | ||
inner.replace_with_initial_events(events, RemoteEventOrigin::Sync).await; | ||
} | ||
Err(err) => { | ||
warn!("Error when re-inserting initial events into the timeline: {err}"); | ||
|
@@ -200,18 +207,25 @@ impl TimelineBuilder { | |
}; | ||
|
||
match update { | ||
RoomEventCacheUpdate::Clear => { | ||
trace!("Clearing the timeline."); | ||
inner.clear().await; | ||
} | ||
|
||
RoomEventCacheUpdate::UpdateReadMarker { event_id } => { | ||
trace!(target = %event_id, "Handling fully read marker."); | ||
inner.handle_fully_read_marker(event_id).await; | ||
} | ||
|
||
RoomEventCacheUpdate::Clear => { | ||
if !inner.is_live().await { | ||
// Ignore a clear for a timeline not in the live mode; the | ||
// focused-on-event mode doesn't add any new items to the timeline | ||
// anyways. | ||
continue; | ||
} | ||
|
||
trace!("Clearing the timeline."); | ||
inner.clear().await; | ||
} | ||
|
||
RoomEventCacheUpdate::Append { events, ephemeral, ambiguity_changes } => { | ||
trace!("Received new events"); | ||
trace!("Received new events from sync."); | ||
|
||
// TODO: (bnjbvr) ephemeral should be handled by the event cache, and | ||
// we should replace this with a simple `add_events_at`. | ||
|
@@ -300,7 +314,7 @@ impl TimelineBuilder { | |
|
||
let timeline = Timeline { | ||
inner, | ||
back_pagination_status: SharedObservable::new(BackPaginationStatus::Idle), | ||
back_pagination_status: SharedObservable::new(PaginationStatus::Idle), | ||
msg_sender, | ||
event_cache: room_event_cache, | ||
drop_handle: Arc::new(TimelineDropHandle { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should it be simply
paginate_forwards
?