Skip to content

Commit 35a8528

Browse files
committed
chore(base): clippy fixes
1 parent f9735c7 commit 35a8528

File tree

7 files changed

+99
-105
lines changed

7 files changed

+99
-105
lines changed

crates/matrix-sdk-base/src/client.rs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -492,14 +492,14 @@ impl BaseClient {
492492
// key bundle shortly after, we might accept it. If we don't do
493493
// this, the homeserver could trick us into accepting any historic room key
494494
// bundle.
495-
if previous_state == RoomState::Invited {
496-
if let Some(inviter) = inviter {
497-
let details = InviteAcceptanceDetails {
498-
invite_accepted_at: MilliSecondsSinceUnixEpoch::now(),
499-
inviter,
500-
};
501-
room_info.set_invite_acceptance_details(details);
502-
}
495+
if previous_state == RoomState::Invited
496+
&& let Some(inviter) = inviter
497+
{
498+
let details = InviteAcceptanceDetails {
499+
invite_accepted_at: MilliSecondsSinceUnixEpoch::now(),
500+
inviter,
501+
};
502+
room_info.set_invite_acceptance_details(details);
503503
}
504504

505505
let mut changes = StateChanges::default();
@@ -861,14 +861,11 @@ impl BaseClient {
861861
_ => (),
862862
}
863863

864-
if let StateEvent::Original(e) = &member {
865-
if let Some(d) = &e.content.displayname {
866-
let display_name = DisplayName::new(d);
867-
ambiguity_map
868-
.entry(display_name)
869-
.or_default()
870-
.insert(member.state_key().clone());
871-
}
864+
if let StateEvent::Original(e) = &member
865+
&& let Some(d) = &e.content.displayname
866+
{
867+
let display_name = DisplayName::new(d);
868+
ambiguity_map.entry(display_name).or_default().insert(member.state_key().clone());
872869
}
873870

874871
let sync_member: SyncRoomMemberEvent = member.clone().into();

crates/matrix-sdk-base/src/latest_event.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -125,21 +125,21 @@ pub fn is_suitable_for_latest_event<'a>(
125125
AnySyncTimelineEvent::State(state) => {
126126
// But we make an exception for knocked state events *if* the current user
127127
// can either accept or decline them
128-
if let AnySyncStateEvent::RoomMember(member) = state {
129-
if matches!(member.membership(), MembershipState::Knock) {
130-
let can_accept_or_decline_knocks = match power_levels_info {
131-
Some((own_user_id, room_power_levels)) => {
132-
room_power_levels.user_can_invite(own_user_id)
133-
|| room_power_levels.user_can_kick(own_user_id)
134-
}
135-
_ => false,
136-
};
137-
138-
// The current user can act on the knock changes, so they should be
139-
// displayed
140-
if can_accept_or_decline_knocks {
141-
return PossibleLatestEvent::YesKnockedStateEvent(member);
128+
if let AnySyncStateEvent::RoomMember(member) = state
129+
&& matches!(member.membership(), MembershipState::Knock)
130+
{
131+
let can_accept_or_decline_knocks = match power_levels_info {
132+
Some((own_user_id, room_power_levels)) => {
133+
room_power_levels.user_can_invite(own_user_id)
134+
|| room_power_levels.user_can_kick(own_user_id)
142135
}
136+
_ => false,
137+
};
138+
139+
// The current user can act on the knock changes, so they should be
140+
// displayed
141+
if can_accept_or_decline_knocks {
142+
return PossibleLatestEvent::YesKnockedStateEvent(member);
143143
}
144144
}
145145
PossibleLatestEvent::NoUnsupportedEventType

crates/matrix-sdk-base/src/read_receipts.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -264,15 +264,15 @@ impl RoomReadReceipts {
264264
// Sliding sync sometimes sends the same event multiple times, so it can be at
265265
// the beginning and end of a batch, for instance. In that case, just reset
266266
// every time we see the event matching the receipt.
267-
if let Some(event_id) = event.event_id() {
268-
if event_id == receipt_event_id {
269-
// Bingo! Switch over to the counting state, after resetting the
270-
// previous counts.
271-
trace!("Found the event the receipt was referring to! Starting to count.");
272-
self.reset();
273-
counting_receipts = true;
274-
continue;
275-
}
267+
if let Some(event_id) = event.event_id()
268+
&& event_id == receipt_event_id
269+
{
270+
// Bingo! Switch over to the counting state, after resetting the
271+
// previous counts.
272+
trace!("Found the event the receipt was referring to! Starting to count.");
273+
self.reset();
274+
counting_receipts = true;
275+
continue;
276276
}
277277

278278
if counting_receipts {
@@ -387,17 +387,17 @@ impl ReceiptSelector {
387387
// Now consider new receipts.
388388
for (event_id, receipts) in &receipt_event.0 {
389389
for ty in [ReceiptType::Read, ReceiptType::ReadPrivate] {
390-
if let Some(receipt) = receipts.get(&ty).and_then(|receipts| receipts.get(user_id))
390+
if let Some(receipts) = receipts.get(&ty)
391+
&& let Some(receipt) = receipts.get(user_id)
392+
&& matches!(receipt.thread, ReceiptThread::Main | ReceiptThread::Unthreaded)
391393
{
392-
if matches!(receipt.thread, ReceiptThread::Main | ReceiptThread::Unthreaded) {
393-
trace!(%event_id, "found new candidate");
394-
if let Some(event_pos) = self.event_id_to_pos.get(event_id) {
395-
self.try_select_later(event_id, *event_pos);
396-
} else {
397-
// It's a new pending receipt.
398-
trace!(%event_id, "stashed as pending");
399-
pending.push(event_id.clone());
400-
}
394+
trace!(%event_id, "found new candidate");
395+
if let Some(event_pos) = self.event_id_to_pos.get(event_id) {
396+
self.try_select_later(event_id, *event_pos);
397+
} else {
398+
// It's a new pending receipt.
399+
trace!(%event_id, "stashed as pending");
400+
pending.push(event_id.clone());
401401
}
402402
}
403403
}

crates/matrix-sdk-base/src/response_processors/account_data/global.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ impl Global {
102102

103103
// Update the direct targets of rooms if they changed.
104104
for (room_id, new_direct_targets) in new_dms {
105-
if let Some(old_direct_targets) = old_dms.remove(&room_id) {
106-
if old_direct_targets == new_direct_targets {
107-
continue;
108-
}
105+
if let Some(old_direct_targets) = old_dms.remove(&room_id)
106+
&& old_direct_targets == new_direct_targets
107+
{
108+
continue;
109109
}
110110
trace!(?room_id, targets = ?new_direct_targets, "Marking room as direct room");
111111
map_info(room_id, state_changes, state_store, |info| {

crates/matrix-sdk-base/src/response_processors/e2ee/tracked_users.rs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,11 @@ pub async fn update(
2525
room_encryption_state: EncryptionState,
2626
user_ids_to_track: &BTreeSet<OwnedUserId>,
2727
) -> Result<()> {
28-
if room_encryption_state.is_encrypted() {
29-
if let Some(olm) = olm_machine {
30-
if !user_ids_to_track.is_empty() {
31-
olm.update_tracked_users(user_ids_to_track.iter().map(AsRef::as_ref)).await?
32-
}
33-
}
28+
if room_encryption_state.is_encrypted()
29+
&& let Some(olm) = olm_machine
30+
&& !user_ids_to_track.is_empty()
31+
{
32+
olm.update_tracked_users(user_ids_to_track.iter().map(AsRef::as_ref)).await?
3433
}
3534

3635
Ok(())
@@ -46,19 +45,19 @@ pub async fn update_or_set_if_room_is_newly_encrypted(
4645
room_id: &RoomId,
4746
state_store: &BaseStateStore,
4847
) -> Result<()> {
49-
if new_room_encryption_state.is_encrypted() {
50-
if let Some(olm) = olm_machine {
51-
if !previous_room_encryption_state.is_encrypted() {
52-
// The room turned on encryption in this sync, we need
53-
// to also get all the existing users and mark them for
54-
// tracking.
55-
let user_ids = state_store.get_user_ids(room_id, RoomMemberships::ACTIVE).await?;
56-
olm.update_tracked_users(user_ids.iter().map(AsRef::as_ref)).await?
57-
}
48+
if new_room_encryption_state.is_encrypted()
49+
&& let Some(olm) = olm_machine
50+
{
51+
if !previous_room_encryption_state.is_encrypted() {
52+
// The room turned on encryption in this sync, we need
53+
// to also get all the existing users and mark them for
54+
// tracking.
55+
let user_ids = state_store.get_user_ids(room_id, RoomMemberships::ACTIVE).await?;
56+
olm.update_tracked_users(user_ids.iter().map(AsRef::as_ref)).await?
57+
}
5858

59-
if !user_ids_to_track.is_empty() {
60-
olm.update_tracked_users(user_ids_to_track.iter().map(AsRef::as_ref)).await?;
61-
}
59+
if !user_ids_to_track.is_empty() {
60+
olm.update_tracked_users(user_ids_to_track.iter().map(AsRef::as_ref)).await?;
6261
}
6362
}
6463

crates/matrix-sdk-base/src/response_processors/room/msc4186/mod.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,10 @@ fn membership(
241241
// We need to find the membership event since it could be for either an invited
242242
// or knocked room.
243243
let membership_event = state_events.1.iter().find_map(|event| {
244-
if let AnyStrippedStateEvent::RoomMember(membership_event) = event {
245-
if membership_event.state_key == user_id {
246-
return Some(membership_event.content.clone());
247-
}
244+
if let AnyStrippedStateEvent::RoomMember(membership_event) = event
245+
&& membership_event.state_key == user_id
246+
{
247+
return Some(membership_event.content.clone());
248248
}
249249
None
250250
});
@@ -497,17 +497,17 @@ pub(crate) async fn cache_latest_events(
497497
}
498498

499499
// Otherwise, look up the sender's profile from the `Store`.
500-
if sender_profile.is_none() {
501-
if let Some(store) = store {
502-
sender_profile = store
503-
.get_profile(room.room_id(), timeline_event.sender())
504-
.await
505-
.ok()
506-
.flatten();
507-
508-
// TODO: need to update `sender_name_is_ambiguous`,
509-
// but how?
510-
}
500+
if sender_profile.is_none()
501+
&& let Some(store) = store
502+
{
503+
sender_profile = store
504+
.get_profile(room.room_id(), timeline_event.sender())
505+
.await
506+
.ok()
507+
.flatten();
508+
509+
// TODO: need to update `sender_name_is_ambiguous`,
510+
// but how?
511511
}
512512

513513
let latest_event = Box::new(LatestEvent::new_with_sender_details(

crates/matrix-sdk-base/src/store/memory_store.rs

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -415,14 +415,12 @@ impl StateStore for MemoryStore {
415415
.insert(user_id.clone(), (event_id.clone(), receipt.clone()))
416416
{
417417
// Remove the old receipt from the room event receipts
418-
if let Some(receipt_map) = inner.room_event_receipts.get_mut(room) {
419-
if let Some(event_map) =
418+
if let Some(receipt_map) = inner.room_event_receipts.get_mut(room)
419+
&& let Some(event_map) =
420420
receipt_map.get_mut(&(receipt_type.to_string(), thread.clone()))
421-
{
422-
if let Some(user_map) = event_map.get_mut(&old_event) {
423-
user_map.remove(user_id);
424-
}
425-
}
421+
&& let Some(user_map) = event_map.get_mut(&old_event)
422+
{
423+
user_map.remove(user_id);
426424
}
427425
}
428426

@@ -458,18 +456,18 @@ impl StateStore for MemoryStore {
458456
if let Some(room) = inner.room_state.get_mut(room_id) {
459457
for ref_room_mu in room.values_mut() {
460458
for raw_evt in ref_room_mu.values_mut() {
461-
if let Ok(Some(event_id)) = raw_evt.get_field::<OwnedEventId>("event_id") {
462-
if let Some(redaction) = redactions.get(&event_id) {
463-
let redacted = redact(
464-
raw_evt.deserialize_as::<CanonicalJsonObject>()?,
465-
redaction_rules.get_or_insert_with(|| {
466-
make_redaction_rules(&inner.room_info, room_id)
467-
}),
468-
Some(RedactedBecause::from_raw_event(redaction)?),
469-
)
470-
.map_err(StoreError::Redaction)?;
471-
*raw_evt = Raw::new(&redacted)?.cast_unchecked();
472-
}
459+
if let Ok(Some(event_id)) = raw_evt.get_field::<OwnedEventId>("event_id")
460+
&& let Some(redaction) = redactions.get(&event_id)
461+
{
462+
let redacted = redact(
463+
raw_evt.deserialize_as::<CanonicalJsonObject>()?,
464+
redaction_rules.get_or_insert_with(|| {
465+
make_redaction_rules(&inner.room_info, room_id)
466+
}),
467+
Some(RedactedBecause::from_raw_event(redaction)?),
468+
)
469+
.map_err(StoreError::Redaction)?;
470+
*raw_evt = Raw::new(&redacted)?.cast_unchecked();
473471
}
474472
}
475473
}

0 commit comments

Comments
 (0)