Skip to content

Commit 0071fef

Browse files
committed
refactor(timeline): simplify lightly computation of should_add_new_items for local events
1 parent 63369a9 commit 0071fef

File tree

3 files changed

+8
-15
lines changed

3 files changed

+8
-15
lines changed

crates/matrix-sdk-ui/src/timeline/controller/mod.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -786,22 +786,11 @@ impl<P: RoomDataProvider, D: Decryptor> TimelineController<P, D> {
786786
let sender = self.room_data_provider.own_user_id().to_owned();
787787
let profile = self.room_data_provider.profile_from_user_id(&sender).await;
788788

789-
// Only add new items if the timeline is live.
790-
let should_add_new_items = self.is_live().await;
791-
792789
let date_divider_mode = self.settings.date_divider_mode.clone();
793790

794791
let mut state = self.state.write().await;
795792
state
796-
.handle_local_event(
797-
sender,
798-
profile,
799-
should_add_new_items,
800-
date_divider_mode,
801-
txn_id,
802-
send_handle,
803-
content,
804-
)
793+
.handle_local_event(sender, profile, date_divider_mode, txn_id, send_handle, content)
805794
.await;
806795
}
807796

crates/matrix-sdk-ui/src/timeline/controller/state.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,17 @@ impl TimelineState {
142142
&mut self,
143143
own_user_id: OwnedUserId,
144144
own_profile: Option<Profile>,
145-
should_add_new_items: bool,
146145
date_divider_mode: DateDividerMode,
147146
txn_id: OwnedTransactionId,
148147
send_handle: Option<SendHandle>,
149148
content: AnyMessageLikeEventContent,
150149
) {
150+
// Only add new items if the timeline is live.
151+
let should_add_new_items = match self.timeline_focus {
152+
TimelineFocusKind::Live => true,
153+
TimelineFocusKind::Event | TimelineFocusKind::PinnedEvents => false,
154+
};
155+
151156
let ctx = TimelineEventContext {
152157
sender: own_user_id,
153158
sender_profile: own_profile,

crates/matrix-sdk-ui/src/timeline/controller/state_transaction.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,7 @@ impl<'a> TimelineStateTransaction<'a> {
270270
TimelineItemPosition::UpdateAt { timeline_item_index: idx } => self
271271
.items
272272
.get(idx)
273-
.and_then(|item| item.as_event())
274-
.and_then(|item| item.as_remote())
273+
.and_then(|item| item.as_event()?.as_remote())
275274
.map_or(RemoteEventOrigin::Unknown, |item| item.origin),
276275
};
277276

0 commit comments

Comments
 (0)