mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-04-24 17:18:23 -04:00
refactor(ffi): Fix new clippy lints
This commit is contained in:
committed by
Damir Jelić
parent
3a14b73258
commit
12cd1effdc
@@ -913,22 +913,19 @@ impl OlmMachine {
|
||||
&decryption_settings,
|
||||
))?;
|
||||
|
||||
if handle_verification_events {
|
||||
if let Ok(AnyTimelineEvent::MessageLike(e)) = decrypted.event.deserialize() {
|
||||
match &e {
|
||||
AnyMessageLikeEvent::RoomMessage(MessageLikeEvent::Original(
|
||||
original_event,
|
||||
)) => {
|
||||
if let MessageType::VerificationRequest(_) = &original_event.content.msgtype
|
||||
{
|
||||
self.runtime.block_on(self.inner.receive_verification_event(&e))?;
|
||||
}
|
||||
}
|
||||
_ if e.event_type().to_string().starts_with("m.key.verification") => {
|
||||
if handle_verification_events
|
||||
&& let Ok(AnyTimelineEvent::MessageLike(e)) = decrypted.event.deserialize()
|
||||
{
|
||||
match &e {
|
||||
AnyMessageLikeEvent::RoomMessage(MessageLikeEvent::Original(original_event)) => {
|
||||
if let MessageType::VerificationRequest(_) = &original_event.content.msgtype {
|
||||
self.runtime.block_on(self.inner.receive_verification_event(&e))?;
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
_ if e.event_type().to_string().starts_with("m.key.verification") => {
|
||||
self.runtime.block_on(self.inner.receive_verification_event(&e))?;
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,18 +27,18 @@ pub fn export(attr: TokenStream, item: TokenStream) -> TokenStream {
|
||||
}
|
||||
} else if let Item::Impl(blk) = &item {
|
||||
for item in &blk.items {
|
||||
if let ImplItem::Fn(fun) = item {
|
||||
if fun.sig.asyncness.is_some() {
|
||||
return true;
|
||||
}
|
||||
if let ImplItem::Fn(fun) = item
|
||||
&& fun.sig.asyncness.is_some()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else if let Item::Trait(blk) = &item {
|
||||
for item in &blk.items {
|
||||
if let TraitItem::Fn(fun) = item {
|
||||
if fun.sig.asyncness.is_some() {
|
||||
return true;
|
||||
}
|
||||
if let TraitItem::Fn(fun) = item
|
||||
&& fun.sig.asyncness.is_some()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -367,12 +367,12 @@ impl Client {
|
||||
|
||||
let controller = session_verification_controller.clone();
|
||||
sdk_client.add_event_handler(move |event: OriginalSyncRoomMessageEvent| async move {
|
||||
if let MessageType::VerificationRequest(_) = &event.content.msgtype {
|
||||
if let Some(session_verification_controller) = &*controller.clone().read().await {
|
||||
session_verification_controller
|
||||
.process_incoming_verification_request(&event.sender, event.event_id)
|
||||
.await;
|
||||
}
|
||||
if let MessageType::VerificationRequest(_) = &event.content.msgtype
|
||||
&& let Some(session_verification_controller) = &*controller.clone().read().await
|
||||
{
|
||||
session_verification_controller
|
||||
.process_incoming_verification_request(&event.sender, event.event_id)
|
||||
.await;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -2132,10 +2132,10 @@ impl Client {
|
||||
let room_id = RoomId::parse(room_id)?;
|
||||
|
||||
// Emit the initial event, if present
|
||||
if let Some(room) = self.inner.get_room(&room_id) {
|
||||
if let Ok(room_info) = RoomInfo::new(&room).await {
|
||||
listener.call(room_info);
|
||||
}
|
||||
if let Some(room) = self.inner.get_room(&room_id)
|
||||
&& let Ok(room_info) = RoomInfo::new(&room).await
|
||||
{
|
||||
listener.call(room_info);
|
||||
}
|
||||
|
||||
Ok(Arc::new(TaskHandle::new(get_runtime_handle().spawn({
|
||||
@@ -2147,10 +2147,10 @@ impl Client {
|
||||
continue;
|
||||
}
|
||||
|
||||
if let Some(room) = client.get_room(&room_id) {
|
||||
if let Ok(room_info) = RoomInfo::new(&room).await {
|
||||
listener.call(room_info);
|
||||
}
|
||||
if let Some(room) = client.get_room(&room_id)
|
||||
&& let Ok(room_info) = RoomInfo::new(&room).await
|
||||
{
|
||||
listener.call(room_info);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -490,12 +490,11 @@ impl ClientBuilder {
|
||||
updated_config = updated_config.timeout(Duration::from_millis(timeout));
|
||||
}
|
||||
updated_config = updated_config.read_timeout(DEFAULT_READ_TIMEOUT);
|
||||
if let Some(max_concurrent_requests) = config.max_concurrent_requests {
|
||||
if max_concurrent_requests > 0 {
|
||||
updated_config = updated_config.max_concurrent_requests(NonZeroUsize::new(
|
||||
max_concurrent_requests as usize,
|
||||
));
|
||||
}
|
||||
if let Some(max_concurrent_requests) = config.max_concurrent_requests
|
||||
&& max_concurrent_requests > 0
|
||||
{
|
||||
updated_config = updated_config
|
||||
.max_concurrent_requests(NonZeroUsize::new(max_concurrent_requests as usize));
|
||||
}
|
||||
if let Some(max_retry_time) = config.max_retry_time {
|
||||
updated_config =
|
||||
|
||||
@@ -77,22 +77,21 @@ impl From<matrix_sdk::Error> for ClientError {
|
||||
fn from(e: matrix_sdk::Error) -> Self {
|
||||
match e {
|
||||
matrix_sdk::Error::Http(http_error) => {
|
||||
if let Some(api_error) = http_error.as_client_api_error() {
|
||||
if let ErrorBody::Standard(StandardErrorBody { kind, message, .. }) =
|
||||
if let Some(api_error) = http_error.as_client_api_error()
|
||||
&& let ErrorBody::Standard(StandardErrorBody { kind, message, .. }) =
|
||||
&api_error.body
|
||||
{
|
||||
let code = kind.errcode().to_string();
|
||||
let Ok(kind) = kind.to_owned().try_into() else {
|
||||
// We couldn't parse the API error, so we return a generic one instead
|
||||
return (*http_error).into();
|
||||
};
|
||||
return Self::MatrixApi {
|
||||
kind,
|
||||
code,
|
||||
msg: message.to_owned(),
|
||||
details: Some(format!("{api_error:?}")),
|
||||
};
|
||||
}
|
||||
{
|
||||
let code = kind.errcode().to_string();
|
||||
let Ok(kind) = kind.to_owned().try_into() else {
|
||||
// We couldn't parse the API error, so we return a generic one instead
|
||||
return (*http_error).into();
|
||||
};
|
||||
return Self::MatrixApi {
|
||||
kind,
|
||||
code,
|
||||
msg: message.to_owned(),
|
||||
details: Some(format!("{api_error:?}")),
|
||||
};
|
||||
}
|
||||
(*http_error).into()
|
||||
}
|
||||
|
||||
@@ -149,10 +149,10 @@ where
|
||||
|
||||
write!(writer, "{}", span.name())?;
|
||||
|
||||
if let Some(fields) = &span.extensions().get::<FormattedFields<N>>() {
|
||||
if !fields.is_empty() {
|
||||
write!(writer, "{{{fields}}}")?;
|
||||
}
|
||||
if let Some(fields) = &span.extensions().get::<FormattedFields<N>>()
|
||||
&& !fields.is_empty()
|
||||
{
|
||||
write!(writer, "{{{fields}}}")?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -237,12 +237,11 @@ impl SizeAndDateRollingWriter {
|
||||
check_conditions: bool,
|
||||
) -> io::Result<()> {
|
||||
// Check if rotation is needed (skip for uninitialized state)
|
||||
if check_conditions {
|
||||
if let Some(state) = state.as_ref() {
|
||||
if !Self::should_rotate_by_time(config, &state.current_path) {
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
if check_conditions
|
||||
&& let Some(state) = state.as_ref()
|
||||
&& !Self::should_rotate_by_time(config, &state.current_path)
|
||||
{
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let time_str = Self::format_rotation_timestamp(config);
|
||||
@@ -312,10 +311,10 @@ impl SizeAndDateRollingWriter {
|
||||
}
|
||||
|
||||
// Check if file is older than max age
|
||||
if let Ok(duration) = now.duration_since(modified) {
|
||||
if duration.as_secs() > config.max_age_seconds {
|
||||
let _ = fs::remove_file(path);
|
||||
}
|
||||
if let Ok(duration) = now.duration_since(modified)
|
||||
&& duration.as_secs() > config.max_age_seconds
|
||||
{
|
||||
let _ = fs::remove_file(path);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -868,10 +867,10 @@ mod tests {
|
||||
std::fs::read_dir(log_path)
|
||||
.unwrap()
|
||||
.filter(|entry| {
|
||||
if let Ok(entry) = entry {
|
||||
if let Some(name) = entry.file_name().to_str() {
|
||||
return name.starts_with("multi");
|
||||
}
|
||||
if let Ok(entry) = entry
|
||||
&& let Some(name) = entry.file_name().to_str()
|
||||
{
|
||||
return name.starts_with("multi");
|
||||
}
|
||||
false
|
||||
})
|
||||
|
||||
@@ -1212,12 +1212,11 @@ impl Room {
|
||||
|
||||
// If no server names are provided and the room's membership is invited,
|
||||
// add the server name from the sender's user id as a fallback value
|
||||
if server_names.is_empty() {
|
||||
if let Ok(invite_details) = self.inner.invite_details().await {
|
||||
if let Some(inviter) = invite_details.inviter {
|
||||
server_names.push(inviter.user_id().server_name().to_owned());
|
||||
}
|
||||
}
|
||||
if server_names.is_empty()
|
||||
&& let Ok(invite_details) = self.inner.invite_details().await
|
||||
&& let Some(inviter) = invite_details.inviter
|
||||
{
|
||||
server_names.push(inviter.user_id().server_name().to_owned());
|
||||
}
|
||||
|
||||
let room_preview = client.get_room_preview(&room_or_alias_id, server_names).await?;
|
||||
|
||||
@@ -246,16 +246,15 @@ impl SessionVerificationController {
|
||||
sender: &UserId,
|
||||
flow_id: impl AsRef<str>,
|
||||
) {
|
||||
if sender != self.user_identity.user_id() {
|
||||
if let Some(status) = self.encryption.cross_signing_status().await {
|
||||
if !status.is_complete() {
|
||||
warn!(
|
||||
"Cannot verify other users until our own device's cross-signing status \
|
||||
is complete: {status:?}"
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if sender != self.user_identity.user_id()
|
||||
&& let Some(status) = self.encryption.cross_signing_status().await
|
||||
&& !status.is_complete()
|
||||
{
|
||||
warn!(
|
||||
"Cannot verify other users until our own device's cross-signing status \
|
||||
is complete: {status:?}"
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
let Some(request) = self.encryption.get_verification_request(sender, flow_id).await else {
|
||||
@@ -290,15 +289,10 @@ impl SessionVerificationController {
|
||||
) -> Result<(), ClientError> {
|
||||
if let Some(ongoing_verification_request) =
|
||||
self.verification_request.read().unwrap().clone()
|
||||
&& !ongoing_verification_request.is_done()
|
||||
&& !ongoing_verification_request.is_cancelled()
|
||||
{
|
||||
if !ongoing_verification_request.is_done()
|
||||
&& !ongoing_verification_request.is_cancelled()
|
||||
{
|
||||
return Err(ClientError::from_str(
|
||||
"There is another verification flow ongoing.",
|
||||
None,
|
||||
));
|
||||
}
|
||||
return Err(ClientError::from_str("There is another verification flow ongoing.", None));
|
||||
}
|
||||
|
||||
*self.verification_request.write().unwrap() = Some(verification_request.clone());
|
||||
|
||||
@@ -41,10 +41,10 @@ impl UnableToDecryptHook for UtdHook {
|
||||
|
||||
// UTDs that have been decrypted in the `IGNORE_UTD_PERIOD` are just ignored and
|
||||
// not considered UTDs.
|
||||
if let Some(duration) = &info.time_to_decrypt {
|
||||
if *duration < IGNORE_UTD_PERIOD {
|
||||
return;
|
||||
}
|
||||
if let Some(duration) = &info.time_to_decrypt
|
||||
&& *duration < IGNORE_UTD_PERIOD
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Report the UTD to the client.
|
||||
|
||||
Reference in New Issue
Block a user