-
Notifications
You must be signed in to change notification settings - Fork 29
[Feature] Summary/Show all of small events #469
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
base: main
Are you sure you want to change the base?
[Feature] Summary/Show all of small events #469
Conversation
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.
Pull Request Overview
This PR implements a feature to collapse adjacent small events into a summarized view in the room timeline, improving vertical space usage and focusing the UI on more prominent messages. Key changes include updating imports to support new grouping logic, adding the live design element "SmallStateEventSummary", and refactoring the timeline population logic to handle grouped small events.
src/home/room_screen.rs
Outdated
populate_message_view( | ||
match group { | ||
GroupedTimelineItem::Single(timeline_item) => { | ||
let tl_idx = tl_items.iter().position(|x| Arc::ptr_eq(x, timeline_item)); |
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.
The use of an iterative search (position on tl_items) for each grouped single event may introduce performance issues for large timelines. Consider caching or maintaining an index map to improve lookup efficiency.
Copilot uses AI. Check for mistakes.
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.
Timeline item uses paged loading, so no this performance issue.
src/home/room_screen.rs
Outdated
buffer.push(item.clone()); | ||
} | ||
_ => { | ||
if buffer.len() >= 3 { |
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.
The grouping threshold of 3 is a magic number; consider defining it as a named constant to improve readability and facilitate future adjustments.
if buffer.len() >= 3 { | |
if buffer.len() >= GROUPING_THRESHOLD { |
Copilot uses AI. Check for mistakes.
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.
Agree.
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.
Pull Request Overview
This PR collapses sequences of adjacent small state events into a compact summary view with a “Show all” button instead of rendering each event individually.
- Defined a
<SmallStateEventSummary>
layout and “Show all” button in the live design. - Added
group_small_state_events
andsummarize_small_events
to cluster and describe adjacent small events. - Updated the main timeline loop to render grouped summaries (
GroupedTimelineItem::GroupedSmallEvents
) instead of single items.
Comments suppressed due to low confidence (1)
src/home/room_screen.rs:4123
- Consider adding unit tests for
group_small_state_events
andsummarize_small_events
to verify that grouping and summary text are correct across event types.
fn group_small_state_events(
src/home/room_screen.rs
Outdated
buffer.push(item.clone()); | ||
} | ||
_ => { | ||
if buffer.len() >= 3 { |
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.
The PR description specifies collapsing two or more adjacent small events, but this condition uses >= 3
. Change it to >= 2
to match the intended behavior.
if buffer.len() >= 3 { | |
if buffer.len() >= 2 { |
Copilot uses AI. Check for mistakes.
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.
Two small event is still easy to read.
Let's reguard 3
as the dividing corner to collapse.
src/home/room_screen.rs
Outdated
} | ||
|
||
// handle any remaining items in the buffer | ||
if buffer.len() >= 3 { |
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.
This second threshold also uses >= 3
. It should be >= 2
so that runs of two small events are grouped as per spec.
if buffer.len() >= 3 { | |
if buffer.len() >= 2 { |
Copilot uses AI. Check for mistakes.
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.
same
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.
Exactly.
src/home/room_screen.rs
Outdated
|
||
#[derive(Clone, Debug)] | ||
enum GroupedTimelineItem { | ||
Single(Arc<TimelineItem>), | ||
GroupedSmallEvents(Vec<Arc<TimelineItem>>), | ||
} | ||
|
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.
[nitpick] Add doc comments to GroupedTimelineItem
, group_small_state_events
, and summarize_small_events
to explain their roles and grouping logic.
#[derive(Clone, Debug)] | |
enum GroupedTimelineItem { | |
Single(Arc<TimelineItem>), | |
GroupedSmallEvents(Vec<Arc<TimelineItem>>), | |
} | |
/// Represents a timeline item that can either be a single item or a group of small events. | |
/// | |
/// - `Single`: A single timeline item. | |
/// - `GroupedSmallEvents`: A collection of small events grouped together for display purposes. | |
#[derive(Clone, Debug)] | |
enum GroupedTimelineItem { | |
Single(Arc<TimelineItem>), | |
GroupedSmallEvents(Vec<Arc<TimelineItem>>), | |
} | |
/// Groups small state events from a list of timeline items into `GroupedTimelineItem` variants. | |
/// | |
/// This function iterates through the provided timeline items and groups small state events | |
/// (e.g., membership changes, profile changes, redacted messages, and other state events) | |
/// into a `GroupedSmallEvents` variant if there are three or more consecutive small events. | |
/// Otherwise, it keeps them as individual `Single` items. | |
/// | |
/// # Parameters | |
/// - `tl_items`: A vector of timeline items to be grouped. | |
/// | |
/// # Returns | |
/// A vector of `GroupedTimelineItem` representing the grouped and individual timeline items. |
Copilot uses AI. Check for mistakes.
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.
@tyreseluo , How do you like copilot's doc?
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.
Yep, I will keep it and make some small modifications.
src/home/room_screen.rs
Outdated
parts.push(text); | ||
} | ||
if redacted > 0 { | ||
parts.push(format!("{} message(s) were redacted", redacted)); |
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.
The text message(s)
is ambiguous for singular vs. plural. Consider branching to message was redacted
when redacted == 1
and messages were redacted
otherwise.
parts.push(format!("{} message(s) were redacted", redacted)); | |
if redacted == 1 { | |
parts.push("1 message was redacted".to_string()); | |
} else { | |
parts.push(format!("{} messages were redacted", redacted)); | |
} |
Copilot uses AI. Check for mistakes.
src/home/room_screen.rs
Outdated
parts.push(format!("{} message(s) were redacted", redacted)); | ||
} | ||
if state_changed > 0 { | ||
parts.push(format!("{} state change(s)", state_changed)); |
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.
Similar to the redacted count, state change(s)
should handle singular/plural correctly (e.g., 1 state change
vs. n state changes
).
parts.push(format!("{} state change(s)", state_changed)); | |
parts.push(format!( | |
"{} state change{}", | |
state_changed, | |
if state_changed == 1 { "" } else { "s" } | |
)); |
Copilot uses AI. Check for mistakes.
4e9ddef
to
c0ef539
Compare
PR content
By default, a series of two or more adjacent small events should be collapsed into an abbreviated view that takes up much less vertical space. This will make it easier for the user to focus on important content like text and image messages from other users, rather than less important metadata.
Related PR