Skip to content

Commit 2710510

Browse files
committed
refactor(base): use let chains where the comment said to do so \o/
1 parent 35a8528 commit 2710510

File tree

1 file changed

+38
-35
lines changed

1 file changed

+38
-35
lines changed

crates/matrix-sdk-base/src/room/room_info.rs

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ use ruma::{
2828
api::client::sync::sync_events::v3::RoomSummary as RumaSummary,
2929
assign,
3030
events::{
31-
AnyStrippedStateEvent, AnySyncStateEvent, AnySyncTimelineEvent, RedactContent,
32-
RedactedStateEventContent, StateEventType, StaticStateEventContent, SyncStateEvent,
31+
AnyStrippedStateEvent, AnySyncStateEvent, AnySyncTimelineEvent, StateEventType,
32+
SyncStateEvent,
3333
beacon_info::BeaconInfoEventContent,
3434
call::member::{CallMemberEventContent, CallMemberStateKey, MembershipData},
3535
direct::OwnedDirectUserIdentifier,
@@ -331,25 +331,42 @@ impl BaseRoomInfo {
331331
.unwrap_or(ROOM_VERSION_RULES_FALLBACK)
332332
.redaction;
333333

334-
// FIXME: Use let chains once available to get rid of unwrap()s
335-
if self.avatar.has_event_id(redacts) {
336-
self.avatar.as_mut().unwrap().redact(&redaction_rules);
337-
} else if self.canonical_alias.has_event_id(redacts) {
338-
self.canonical_alias.as_mut().unwrap().redact(&redaction_rules);
339-
} else if self.create.has_event_id(redacts) {
340-
self.create.as_mut().unwrap().redact(&redaction_rules);
341-
} else if self.guest_access.has_event_id(redacts) {
342-
self.guest_access.as_mut().unwrap().redact(&redaction_rules);
343-
} else if self.history_visibility.has_event_id(redacts) {
344-
self.history_visibility.as_mut().unwrap().redact(&redaction_rules);
345-
} else if self.join_rules.has_event_id(redacts) {
346-
self.join_rules.as_mut().unwrap().redact(&redaction_rules);
347-
} else if self.name.has_event_id(redacts) {
348-
self.name.as_mut().unwrap().redact(&redaction_rules);
349-
} else if self.tombstone.has_event_id(redacts) {
350-
self.tombstone.as_mut().unwrap().redact(&redaction_rules);
351-
} else if self.topic.has_event_id(redacts) {
352-
self.topic.as_mut().unwrap().redact(&redaction_rules);
334+
if let Some(ev) = &mut self.avatar
335+
&& ev.event_id() == Some(redacts)
336+
{
337+
ev.redact(&redaction_rules);
338+
} else if let Some(ev) = &mut self.canonical_alias
339+
&& ev.event_id() == Some(redacts)
340+
{
341+
ev.redact(&redaction_rules);
342+
} else if let Some(ev) = &mut self.create
343+
&& ev.event_id() == Some(redacts)
344+
{
345+
ev.redact(&redaction_rules);
346+
} else if let Some(ev) = &mut self.guest_access
347+
&& ev.event_id() == Some(redacts)
348+
{
349+
ev.redact(&redaction_rules);
350+
} else if let Some(ev) = &mut self.history_visibility
351+
&& ev.event_id() == Some(redacts)
352+
{
353+
ev.redact(&redaction_rules);
354+
} else if let Some(ev) = &mut self.join_rules
355+
&& ev.event_id() == Some(redacts)
356+
{
357+
ev.redact(&redaction_rules);
358+
} else if let Some(ev) = &mut self.name
359+
&& ev.event_id() == Some(redacts)
360+
{
361+
ev.redact(&redaction_rules);
362+
} else if let Some(ev) = &mut self.tombstone
363+
&& ev.event_id() == Some(redacts)
364+
{
365+
ev.redact(&redaction_rules);
366+
} else if let Some(ev) = &mut self.topic
367+
&& ev.event_id() == Some(redacts)
368+
{
369+
ev.redact(&redaction_rules);
353370
} else {
354371
self.rtc_member_events
355372
.retain(|_, member_event| member_event.event_id() != Some(redacts));
@@ -396,20 +413,6 @@ impl Default for BaseRoomInfo {
396413
}
397414
}
398415

399-
trait OptionExt {
400-
fn has_event_id(&self, ev_id: &EventId) -> bool;
401-
}
402-
403-
impl<C> OptionExt for Option<MinimalStateEvent<C>>
404-
where
405-
C: StaticStateEventContent + RedactContent,
406-
C::Redacted: RedactedStateEventContent,
407-
{
408-
fn has_event_id(&self, ev_id: &EventId) -> bool {
409-
self.as_ref().is_some_and(|ev| ev.event_id() == Some(ev_id))
410-
}
411-
}
412-
413416
/// The underlying pure data structure for joined and left rooms.
414417
///
415418
/// Holds all the info needed to persist a room into the state store.

0 commit comments

Comments
 (0)