Skip to content

Commit f4451b5

Browse files
committed
refactor(timeline): TimelineAction::from_content always returns Something now
1 parent 59b7da2 commit f4451b5

File tree

3 files changed

+20
-21
lines changed

3 files changed

+20
-21
lines changed

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -190,14 +190,11 @@ impl<P: RoomDataProvider> TimelineState<P> {
190190
should_add_new_items,
191191
};
192192

193-
if let Some(timeline_action) =
194-
TimelineAction::from_content(content, in_reply_to, thread_root, None)
195-
{
196-
TimelineEventHandler::new(&mut txn, ctx)
197-
.handle_event(&mut date_divider_adjuster, timeline_action)
198-
.await;
199-
txn.adjust_date_dividers(date_divider_adjuster);
200-
}
193+
let timeline_action = TimelineAction::from_content(content, in_reply_to, thread_root, None);
194+
TimelineEventHandler::new(&mut txn, ctx)
195+
.handle_event(&mut date_divider_adjuster, timeline_action)
196+
.await;
197+
txn.adjust_date_dividers(date_divider_adjuster);
201198

202199
txn.commit();
203200
}

crates/matrix-sdk-ui/src/timeline/event_handler.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -245,17 +245,17 @@ impl TimelineAction {
245245
// `TimelineEvent` containing an `m.room.encrypted` event without
246246
// decrypting it. Possibly this means that encryption has not been
247247
// configured. We treat it the same as any other message-like event.
248-
return Self::from_content(
248+
Self::from_content(
249249
AnyMessageLikeEventContent::RoomEncrypted(content),
250250
in_reply_to,
251251
thread_root,
252252
thread_summary,
253-
);
253+
)
254254
}
255255
}
256256

257257
Some(content) => {
258-
return Self::from_content(content, in_reply_to, thread_root, thread_summary);
258+
Self::from_content(content, in_reply_to, thread_root, thread_summary)
259259
}
260260

261261
None => Self::add_item(redacted_message_or_none(ev.event_type())?),
@@ -302,8 +302,8 @@ impl TimelineAction {
302302
in_reply_to: Option<InReplyToDetails>,
303303
thread_root: Option<OwnedEventId>,
304304
thread_summary: Option<ThreadSummary>,
305-
) -> Option<Self> {
306-
Some(match content {
305+
) -> Self {
306+
match content {
307307
AnyMessageLikeEventContent::Reaction(c) => {
308308
// This is a reaction to a message.
309309
Self::HandleAggregation {
@@ -395,7 +395,7 @@ impl TimelineAction {
395395
}),
396396
}
397397
}
398-
})
398+
}
399399
}
400400

401401
pub(super) fn failed_to_parse(event: FailedToParseEvent, error: serde_json::Error) -> Self {

crates/matrix-sdk-ui/src/timeline/latest_event.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,15 @@ impl LatestEventValue {
115115

116116
let is_sending = matches!(value, BaseLatestEventValue::LocalIsSending(_));
117117

118-
let Some(TimelineAction::AddItem { content }) =
119-
TimelineAction::from_content(message_like_event_content, None, None, None)
120-
else {
121-
return Self::None;
122-
};
123-
124-
Self::Local { timestamp, content, is_sending }
118+
match TimelineAction::from_content(message_like_event_content, None, None, None) {
119+
TimelineAction::AddItem { content } => {
120+
Self::Local { timestamp, content, is_sending }
121+
}
122+
123+
TimelineAction::HandleAggregation { kind, .. } => {
124+
Self::None
125+
}
126+
}
125127
}
126128
}
127129
}

0 commit comments

Comments
 (0)