diff --git a/deltachat-jsonrpc/src/api/types/events.rs b/deltachat-jsonrpc/src/api/types/events.rs index beeee4334..b4391ce16 100644 --- a/deltachat-jsonrpc/src/api/types/events.rs +++ b/deltachat-jsonrpc/src/api/types/events.rs @@ -271,7 +271,7 @@ pub enum EventType { /// Progress. /// /// 0=error, 1-999=progress in permille, 1000=success and done - progress: usize, + progress: u16, /// Progress comment or error, something to display to the user. comment: Option, @@ -282,7 +282,7 @@ pub enum EventType { #[serde(rename_all = "camelCase")] ImexProgress { /// 0=error, 1-999=progress in permille, 1000=success and done - progress: usize, + progress: u16, }, /// A file has been exported. A file has been written by imex(). @@ -313,7 +313,7 @@ pub enum EventType { chat_id: u32, /// Progress, always 1000. - progress: usize, + progress: u16, }, /// Progress information of a secure-join handshake from the view of the joiner @@ -329,7 +329,7 @@ pub enum EventType { /// 400=vg-/vc-request-with-auth sent, typically shown as "alice@addr verified, introducing myself." /// (Bob has verified alice and waits until Alice does the same for him) /// 1000=vg-member-added/vc-contact-confirm received - progress: usize, + progress: u16, }, /// The connectivity to the server changed. diff --git a/src/events/payload.rs b/src/events/payload.rs index f2540bce1..5578f9841 100644 --- a/src/events/payload.rs +++ b/src/events/payload.rs @@ -243,7 +243,7 @@ pub enum EventType { /// Progress. /// /// 0=error, 1-999=progress in permille, 1000=success and done - progress: usize, + progress: u16, /// Progress comment or error, something to display to the user. comment: Option, @@ -253,7 +253,7 @@ pub enum EventType { /// /// @param data1 (usize) 0=error, 1-999=progress in permille, 1000=success and done /// @param data2 0 - ImexProgress(usize), + ImexProgress(u16), /// A file has been exported. A file has been written by imex(). /// This event may be sent multiple times by a single call to imex(). @@ -280,7 +280,7 @@ pub enum EventType { chat_type: Chattype, /// Progress, always 1000. - progress: usize, + progress: u16, }, /// Progress information of a secure-join handshake from the view of the joiner @@ -295,7 +295,7 @@ pub enum EventType { /// 400=vg-/vc-request-with-auth sent, typically shown as "alice@addr verified, introducing myself." /// (Bob has verified alice and waits until Alice does the same for him) /// 1000=vg-member-added/vc-contact-confirm received - progress: usize, + progress: u16, }, /// The connectivity to the server changed. diff --git a/src/imex.rs b/src/imex.rs index 30b74ecff..261e76c27 100644 --- a/src/imex.rs +++ b/src/imex.rs @@ -271,7 +271,7 @@ struct ProgressReader { file_size: u64, /// Last progress emitted to avoid emitting the same progress value twice. - last_progress: usize, + last_progress: u16, /// Context for emitting progress events. context: Context, @@ -306,7 +306,7 @@ where .read .saturating_add(usize_to_u64(buf.filled().len() - before)); - let progress = std::cmp::min(1000 * *this.read / *this.file_size, 999) as usize; + let progress = std::cmp::min(1000 * *this.read / *this.file_size, 999) as u16; if progress > *this.last_progress { this.context.emit_event(EventType::ImexProgress(progress)); *this.last_progress = progress; @@ -500,7 +500,7 @@ struct ProgressWriter { file_size: u64, /// Last progress emitted to avoid emitting the same progress value twice. - last_progress: usize, + last_progress: u16, /// Context for emitting progress events. context: Context, @@ -532,7 +532,7 @@ where if let std::task::Poll::Ready(Ok(written)) = res { *this.written = this.written.saturating_add(usize_to_u64(written)); - let progress = std::cmp::min(1000 * *this.written / *this.file_size, 999) as usize; + let progress = std::cmp::min(1000 * *this.written / *this.file_size, 999) as u16; if progress > *this.last_progress { this.context.emit_event(EventType::ImexProgress(progress)); *this.last_progress = progress; diff --git a/src/securejoin.rs b/src/securejoin.rs index 4b2b35ad1..dcf418708 100644 --- a/src/securejoin.rs +++ b/src/securejoin.rs @@ -567,7 +567,7 @@ pub(crate) async fn handle_securejoin_handshake( "vc-contact-confirm" => { context.emit_event(EventType::SecurejoinJoinerProgress { contact_id, - progress: JoinerProgress::Succeeded.to_usize(), + progress: JoinerProgress::Succeeded.into_u16(), }); Ok(HandshakeMessage::Ignore) } @@ -590,7 +590,7 @@ pub(crate) async fn handle_securejoin_handshake( context.emit_event(EventType::SecurejoinJoinerProgress { contact_id, - progress: JoinerProgress::Succeeded.to_usize(), + progress: JoinerProgress::Succeeded.into_u16(), }); Ok(HandshakeMessage::Propagate) } diff --git a/src/securejoin/bob.rs b/src/securejoin/bob.rs index 7318d1e7a..40bde884a 100644 --- a/src/securejoin/bob.rs +++ b/src/securejoin/bob.rs @@ -94,7 +94,7 @@ pub(super) async fn start_protocol(context: &Context, invite: QrInvite) -> Resul // Even if Alice is not verified, we don't send anything. context.emit_event(EventType::SecurejoinJoinerProgress { contact_id: invite.contact_id(), - progress: JoinerProgress::Succeeded.to_usize(), + progress: JoinerProgress::Succeeded.into_u16(), }); return Ok(joining_chat_id); } else if has_key @@ -113,7 +113,7 @@ pub(super) async fn start_protocol(context: &Context, invite: QrInvite) -> Resul context.emit_event(EventType::SecurejoinJoinerProgress { contact_id: invite.contact_id(), - progress: JoinerProgress::RequestWithAuthSent.to_usize(), + progress: JoinerProgress::RequestWithAuthSent.into_u16(), }); } else { send_handshake_message(context, &invite, private_chat_id, BobHandshakeMsg::Request) @@ -240,7 +240,7 @@ pub(super) async fn handle_auth_required( context.emit_event(EventType::SecurejoinJoinerProgress { contact_id: invite.contact_id(), - progress: JoinerProgress::RequestWithAuthSent.to_usize(), + progress: JoinerProgress::RequestWithAuthSent.into_u16(), }); auth_sent = true; @@ -406,8 +406,7 @@ pub(crate) enum JoinerProgress { } impl JoinerProgress { - #[expect(clippy::wrong_self_convention)] - pub(crate) fn to_usize(self) -> usize { + pub(crate) fn into_u16(self) -> u16 { match self { JoinerProgress::RequestWithAuthSent => 400, JoinerProgress::Succeeded => 1000,