Skip to content

Commit 13b5413

Browse files
committed
refactor: Batch of unrelated changes
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
1 parent b3413c7 commit 13b5413

File tree

13 files changed

+60
-53
lines changed

13 files changed

+60
-53
lines changed

bindings/matrix-sdk-ffi/src/client.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2402,9 +2402,7 @@ impl TryFrom<AllowRule> for RumaAllowRule {
24022402
match value {
24032403
AllowRule::RoomMembership { room_id } => {
24042404
let room_id = RoomId::parse(room_id)?;
2405-
Ok(Self::RoomMembership(ruma::events::room::join_rules::RoomMembership::new(
2406-
room_id,
2407-
)))
2405+
Ok(Self::RoomMembership(ruma::room::RoomMembership::new(room_id)))
24082406
}
24092407
AllowRule::Custom { json } => Ok(Self::_Custom(Box::new(serde_json::from_str(&json)?))),
24102408
}

bindings/matrix-sdk-ffi/src/room/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ impl Room {
484484
/// # Errors
485485
///
486486
/// Returns an error if the room is not found or on rate limit
487-
pub async fn report_room(&self, reason: Option<String>) -> Result<(), ClientError> {
487+
pub async fn report_room(&self, reason: String) -> Result<(), ClientError> {
488488
self.inner.report_room(reason).await?;
489489

490490
Ok(())

crates/matrix-sdk-base/src/response_processors/timeline.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use matrix_sdk_common::deserialized_responses::TimelineEvent;
1616
#[cfg(feature = "e2e-encryption")]
1717
use ruma::events::SyncMessageLikeEvent;
1818
use ruma::{
19+
assign,
1920
events::{
2021
room::power_levels::{
2122
RoomPowerLevelsEvent, RoomPowerLevelsEventContent, StrippedRoomPowerLevelsEvent,
@@ -294,11 +295,13 @@ pub async fn get_push_room_context(
294295
.map(|event| event.power_levels().into())
295296
};
296297

297-
Ok(Some(PushConditionRoomCtx {
298-
user_id: user_id.to_owned(),
299-
room_id: room_id.to_owned(),
300-
member_count: UInt::new(member_count).unwrap_or(UInt::MAX),
301-
user_display_name,
302-
power_levels,
303-
}))
298+
Ok(Some(assign!(
299+
PushConditionRoomCtx::new(
300+
room_id.to_owned(),
301+
UInt::new(member_count).unwrap_or(UInt::MAX),
302+
user_id.to_owned(),
303+
user_display_name
304+
),
305+
{ power_levels }
306+
)))
304307
}

crates/matrix-sdk-crypto/src/file_encryption/attachments.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,20 +136,19 @@ impl<'a, R: Read + 'a> AttachmentDecryptor<'a, R> {
136136

137137
let hash =
138138
info.hashes.get("sha256").ok_or(DecryptorError::MissingHash)?.as_bytes().to_owned();
139-
let mut key = info.key.k.into_inner();
139+
let key = info.key.k.as_bytes();
140140
let iv = info.iv.into_inner();
141141

142142
if key.len() != KEY_SIZE {
143143
return Err(DecryptorError::KeyNonceLength);
144144
}
145145

146-
let key_array = GenericArray::from_slice(&key);
146+
let key_array = GenericArray::from_slice(key);
147147
let iv = GenericArray::from_exact_iter(iv).ok_or(DecryptorError::KeyNonceLength)?;
148148

149149
let sha = Sha256::default();
150150

151151
let aes = Aes256Ctr::new(key_array, &iv);
152-
key.zeroize();
153152

154153
Ok(AttachmentDecryptor { inner: input, expected_hash: hash, sha, aes })
155154
}

crates/matrix-sdk-crypto/src/machine/test_helpers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ pub fn bootstrap_requests_to_keys_query_response(
334334
/// Helper for [`create_signed_device_of_unverified_user`] and
335335
/// [`create_unsigned_device`].
336336
fn dummy_verification_machine() -> VerificationMachine {
337-
let account = Account::new(user_id!("@TEST_USER:example.com"));
337+
let account = Account::new(user_id!("@test_user:example.com"));
338338
VerificationMachine::new(
339339
account.deref().clone(),
340340
Arc::new(Mutex::new(PrivateCrossSigningIdentity::new(account.user_id().to_owned()))),

crates/matrix-sdk-crypto/src/machine/tests/mod.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ use ruma::{
3636
room::message::{
3737
AddMentions, MessageType, Relation, ReplyWithinThread, RoomMessageEventContent,
3838
},
39-
AnyMessageLikeEvent, AnyMessageLikeEventContent, AnyToDeviceEvent, MessageLikeEvent,
40-
OriginalMessageLikeEvent, ToDeviceEventType,
39+
AnyMessageLikeEvent, AnyMessageLikeEventContent, AnySyncMessageLikeEvent, AnyToDeviceEvent,
40+
MessageLikeEvent, OriginalMessageLikeEvent, ToDeviceEventType,
4141
},
4242
room_id,
4343
serde::Raw,
@@ -1442,8 +1442,8 @@ async fn test_unsigned_decryption() {
14421442

14431443
// Encrypt a second message, an edit.
14441444
let second_message_text = "This is the ~~original~~ edited message";
1445-
let second_message_content = RoomMessageEventContent::text_plain(second_message_text)
1446-
.make_replacement(first_message, None);
1445+
let second_message_content =
1446+
RoomMessageEventContent::text_plain(second_message_text).make_replacement(first_message);
14471447
let second_message_encrypted_content =
14481448
alice.encrypt_room_event(room_id, second_message_content).await.unwrap();
14491449

@@ -1579,7 +1579,10 @@ async fn test_unsigned_decryption() {
15791579
assert!(first_message.unsigned.relations.replace.is_some());
15801580
// Deserialization of the thread event succeeded, but it is still encrypted.
15811581
let thread = first_message.unsigned.relations.thread.as_ref().unwrap();
1582-
assert_matches!(thread.latest_event.deserialize(), Ok(AnyMessageLikeEvent::RoomEncrypted(_)));
1582+
assert_matches!(
1583+
thread.latest_event.deserialize(),
1584+
Ok(AnySyncMessageLikeEvent::RoomEncrypted(_))
1585+
);
15831586

15841587
let unsigned_encryption_info = raw_decrypted_event.unsigned_encryption_info.unwrap();
15851588
assert_eq!(unsigned_encryption_info.len(), 2);
@@ -1625,7 +1628,7 @@ async fn test_unsigned_decryption() {
16251628
let thread = &first_message.unsigned.relations.thread.as_ref().unwrap();
16261629
assert_matches!(
16271630
thread.latest_event.deserialize(),
1628-
Ok(AnyMessageLikeEvent::RoomMessage(third_message))
1631+
Ok(AnySyncMessageLikeEvent::RoomMessage(third_message))
16291632
);
16301633
let third_message = third_message.as_original().unwrap();
16311634
assert_eq!(third_message.content.body(), third_message_text);

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

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ use matrix_sdk_base::{
4040
};
4141
use matrix_sdk_test::{event_factory::EventFactory, ALICE, DEFAULT_TEST_ROOM_ID};
4242
use ruma::{
43+
assign,
4344
events::{
4445
reaction::ReactionEventContent,
4546
receipt::{Receipt, ReceiptThread, ReceiptType},
@@ -399,18 +400,20 @@ impl RoomDataProvider for TestRoomDataProvider {
399400

400401
async fn push_context(&self) -> Option<PushContext> {
401402
let push_rules = Ruleset::server_default(&ALICE);
402-
let power_levels = PushConditionPowerLevelsCtx {
403-
users: BTreeMap::new(),
404-
users_default: int!(0),
405-
notifications: NotificationPowerLevels::new(),
406-
};
407-
let push_condition_room_ctx = PushConditionRoomCtx {
408-
room_id: room_id!("!my_room:server.name").to_owned(),
409-
member_count: uint!(2),
410-
user_id: ALICE.to_owned(),
411-
user_display_name: "Alice".to_owned(),
412-
power_levels: Some(power_levels),
413-
};
403+
let power_levels = PushConditionPowerLevelsCtx::new(
404+
BTreeMap::new(),
405+
int!(0),
406+
NotificationPowerLevels::new(),
407+
);
408+
let push_condition_room_ctx = assign!(
409+
PushConditionRoomCtx::new(
410+
room_id!("!my_room:server.name").to_owned(),
411+
uint!(2),
412+
ALICE.to_owned(),
413+
"Alice".to_owned(),
414+
),
415+
{ power_levels: Some(power_levels) }
416+
);
414417
Some(PushContext::new(push_condition_room_ctx, push_rules))
415418
}
416419

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ use ruma::{
4848
directory::{get_public_rooms, get_public_rooms_filtered},
4949
discovery::{
5050
discover_homeserver::{self, RtcFocusInfo},
51-
get_capabilities::{self, Capabilities},
51+
get_capabilities::{self, v3::Capabilities},
5252
get_supported_versions,
5353
},
5454
error::ErrorKind,

crates/matrix-sdk/src/encryption/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,9 @@ pub struct OAuthCrossSigningResetInfo {
348348

349349
impl OAuthCrossSigningResetInfo {
350350
fn from_auth_info(auth_info: &UiaaInfo) -> Result<Self> {
351-
let parameters =
352-
serde_json::from_str::<OAuthCrossSigningResetUiaaParameters>(auth_info.params.get())?;
351+
let parameters = serde_json::from_str::<OAuthCrossSigningResetUiaaParameters>(
352+
auth_info.params.as_ref().map(|value| value.get()).unwrap_or_default(),
353+
)?;
353354

354355
Ok(OAuthCrossSigningResetInfo { approval_url: parameters.reset.url })
355356
}

crates/matrix-sdk/src/event_handler/static_events.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@
1616

1717
use ruma::{
1818
events::{
19-
self,
20-
presence::{PresenceEvent, PresenceEventContent},
21-
AnyGlobalAccountDataEvent, AnyRoomAccountDataEvent, AnyStrippedStateEvent,
22-
AnySyncEphemeralRoomEvent, AnySyncMessageLikeEvent, AnySyncStateEvent,
23-
AnySyncTimelineEvent, AnyToDeviceEvent, EphemeralRoomEventContent,
19+
self, presence::PresenceEvent, AnyGlobalAccountDataEvent, AnyRoomAccountDataEvent,
20+
AnyStrippedStateEvent, AnySyncEphemeralRoomEvent, AnySyncMessageLikeEvent,
21+
AnySyncStateEvent, AnySyncTimelineEvent, AnyToDeviceEvent, EphemeralRoomEventContent,
2422
GlobalAccountDataEventContent, MessageLikeEventContent, PossiblyRedactedStateEventContent,
2523
RedactContent, RedactedMessageLikeEventContent, RedactedStateEventContent,
2624
RoomAccountDataEventContent, StaticEventContent, StaticStateEventContent,
@@ -141,7 +139,7 @@ where
141139

142140
impl SyncEvent for PresenceEvent {
143141
const KIND: HandlerKind = HandlerKind::Presence;
144-
const TYPE: Option<&'static str> = Some(PresenceEventContent::TYPE);
142+
const TYPE: Option<&'static str> = None;
145143
}
146144

147145
impl SyncEvent for AnyGlobalAccountDataEvent {

0 commit comments

Comments
 (0)