mirror of
https://github.com/chatmail/core.git
synced 2026-05-20 23:36:30 +03:00
refactor: use u16 instead of usize to represent progress bar
This commit is contained in:
@@ -271,7 +271,7 @@ pub enum EventType {
|
|||||||
/// Progress.
|
/// Progress.
|
||||||
///
|
///
|
||||||
/// 0=error, 1-999=progress in permille, 1000=success and done
|
/// 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.
|
/// Progress comment or error, something to display to the user.
|
||||||
comment: Option<String>,
|
comment: Option<String>,
|
||||||
@@ -282,7 +282,7 @@ pub enum EventType {
|
|||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
ImexProgress {
|
ImexProgress {
|
||||||
/// 0=error, 1-999=progress in permille, 1000=success and done
|
/// 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().
|
/// A file has been exported. A file has been written by imex().
|
||||||
@@ -313,7 +313,7 @@ pub enum EventType {
|
|||||||
chat_id: u32,
|
chat_id: u32,
|
||||||
|
|
||||||
/// Progress, always 1000.
|
/// Progress, always 1000.
|
||||||
progress: usize,
|
progress: u16,
|
||||||
},
|
},
|
||||||
|
|
||||||
/// Progress information of a secure-join handshake from the view of the joiner
|
/// 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."
|
/// 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)
|
/// (Bob has verified alice and waits until Alice does the same for him)
|
||||||
/// 1000=vg-member-added/vc-contact-confirm received
|
/// 1000=vg-member-added/vc-contact-confirm received
|
||||||
progress: usize,
|
progress: u16,
|
||||||
},
|
},
|
||||||
|
|
||||||
/// The connectivity to the server changed.
|
/// The connectivity to the server changed.
|
||||||
|
|||||||
@@ -243,7 +243,7 @@ pub enum EventType {
|
|||||||
/// Progress.
|
/// Progress.
|
||||||
///
|
///
|
||||||
/// 0=error, 1-999=progress in permille, 1000=success and done
|
/// 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.
|
/// Progress comment or error, something to display to the user.
|
||||||
comment: Option<String>,
|
comment: Option<String>,
|
||||||
@@ -253,7 +253,7 @@ pub enum EventType {
|
|||||||
///
|
///
|
||||||
/// @param data1 (usize) 0=error, 1-999=progress in permille, 1000=success and done
|
/// @param data1 (usize) 0=error, 1-999=progress in permille, 1000=success and done
|
||||||
/// @param data2 0
|
/// @param data2 0
|
||||||
ImexProgress(usize),
|
ImexProgress(u16),
|
||||||
|
|
||||||
/// A file has been exported. A file has been written by imex().
|
/// 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().
|
/// This event may be sent multiple times by a single call to imex().
|
||||||
@@ -280,7 +280,7 @@ pub enum EventType {
|
|||||||
chat_type: Chattype,
|
chat_type: Chattype,
|
||||||
|
|
||||||
/// Progress, always 1000.
|
/// Progress, always 1000.
|
||||||
progress: usize,
|
progress: u16,
|
||||||
},
|
},
|
||||||
|
|
||||||
/// Progress information of a secure-join handshake from the view of the joiner
|
/// 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."
|
/// 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)
|
/// (Bob has verified alice and waits until Alice does the same for him)
|
||||||
/// 1000=vg-member-added/vc-contact-confirm received
|
/// 1000=vg-member-added/vc-contact-confirm received
|
||||||
progress: usize,
|
progress: u16,
|
||||||
},
|
},
|
||||||
|
|
||||||
/// The connectivity to the server changed.
|
/// The connectivity to the server changed.
|
||||||
|
|||||||
@@ -271,7 +271,7 @@ struct ProgressReader<R> {
|
|||||||
file_size: u64,
|
file_size: u64,
|
||||||
|
|
||||||
/// Last progress emitted to avoid emitting the same progress value twice.
|
/// Last progress emitted to avoid emitting the same progress value twice.
|
||||||
last_progress: usize,
|
last_progress: u16,
|
||||||
|
|
||||||
/// Context for emitting progress events.
|
/// Context for emitting progress events.
|
||||||
context: Context,
|
context: Context,
|
||||||
@@ -306,7 +306,7 @@ where
|
|||||||
.read
|
.read
|
||||||
.saturating_add(usize_to_u64(buf.filled().len() - before));
|
.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 {
|
if progress > *this.last_progress {
|
||||||
this.context.emit_event(EventType::ImexProgress(progress));
|
this.context.emit_event(EventType::ImexProgress(progress));
|
||||||
*this.last_progress = progress;
|
*this.last_progress = progress;
|
||||||
@@ -500,7 +500,7 @@ struct ProgressWriter<W> {
|
|||||||
file_size: u64,
|
file_size: u64,
|
||||||
|
|
||||||
/// Last progress emitted to avoid emitting the same progress value twice.
|
/// Last progress emitted to avoid emitting the same progress value twice.
|
||||||
last_progress: usize,
|
last_progress: u16,
|
||||||
|
|
||||||
/// Context for emitting progress events.
|
/// Context for emitting progress events.
|
||||||
context: Context,
|
context: Context,
|
||||||
@@ -532,7 +532,7 @@ where
|
|||||||
if let std::task::Poll::Ready(Ok(written)) = res {
|
if let std::task::Poll::Ready(Ok(written)) = res {
|
||||||
*this.written = this.written.saturating_add(usize_to_u64(written));
|
*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 {
|
if progress > *this.last_progress {
|
||||||
this.context.emit_event(EventType::ImexProgress(progress));
|
this.context.emit_event(EventType::ImexProgress(progress));
|
||||||
*this.last_progress = progress;
|
*this.last_progress = progress;
|
||||||
|
|||||||
@@ -567,7 +567,7 @@ pub(crate) async fn handle_securejoin_handshake(
|
|||||||
"vc-contact-confirm" => {
|
"vc-contact-confirm" => {
|
||||||
context.emit_event(EventType::SecurejoinJoinerProgress {
|
context.emit_event(EventType::SecurejoinJoinerProgress {
|
||||||
contact_id,
|
contact_id,
|
||||||
progress: JoinerProgress::Succeeded.to_usize(),
|
progress: JoinerProgress::Succeeded.into_u16(),
|
||||||
});
|
});
|
||||||
Ok(HandshakeMessage::Ignore)
|
Ok(HandshakeMessage::Ignore)
|
||||||
}
|
}
|
||||||
@@ -590,7 +590,7 @@ pub(crate) async fn handle_securejoin_handshake(
|
|||||||
|
|
||||||
context.emit_event(EventType::SecurejoinJoinerProgress {
|
context.emit_event(EventType::SecurejoinJoinerProgress {
|
||||||
contact_id,
|
contact_id,
|
||||||
progress: JoinerProgress::Succeeded.to_usize(),
|
progress: JoinerProgress::Succeeded.into_u16(),
|
||||||
});
|
});
|
||||||
Ok(HandshakeMessage::Propagate)
|
Ok(HandshakeMessage::Propagate)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.
|
// Even if Alice is not verified, we don't send anything.
|
||||||
context.emit_event(EventType::SecurejoinJoinerProgress {
|
context.emit_event(EventType::SecurejoinJoinerProgress {
|
||||||
contact_id: invite.contact_id(),
|
contact_id: invite.contact_id(),
|
||||||
progress: JoinerProgress::Succeeded.to_usize(),
|
progress: JoinerProgress::Succeeded.into_u16(),
|
||||||
});
|
});
|
||||||
return Ok(joining_chat_id);
|
return Ok(joining_chat_id);
|
||||||
} else if has_key
|
} else if has_key
|
||||||
@@ -113,7 +113,7 @@ pub(super) async fn start_protocol(context: &Context, invite: QrInvite) -> Resul
|
|||||||
|
|
||||||
context.emit_event(EventType::SecurejoinJoinerProgress {
|
context.emit_event(EventType::SecurejoinJoinerProgress {
|
||||||
contact_id: invite.contact_id(),
|
contact_id: invite.contact_id(),
|
||||||
progress: JoinerProgress::RequestWithAuthSent.to_usize(),
|
progress: JoinerProgress::RequestWithAuthSent.into_u16(),
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
send_handshake_message(context, &invite, private_chat_id, BobHandshakeMsg::Request)
|
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 {
|
context.emit_event(EventType::SecurejoinJoinerProgress {
|
||||||
contact_id: invite.contact_id(),
|
contact_id: invite.contact_id(),
|
||||||
progress: JoinerProgress::RequestWithAuthSent.to_usize(),
|
progress: JoinerProgress::RequestWithAuthSent.into_u16(),
|
||||||
});
|
});
|
||||||
|
|
||||||
auth_sent = true;
|
auth_sent = true;
|
||||||
@@ -406,8 +406,7 @@ pub(crate) enum JoinerProgress {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl JoinerProgress {
|
impl JoinerProgress {
|
||||||
#[expect(clippy::wrong_self_convention)]
|
pub(crate) fn into_u16(self) -> u16 {
|
||||||
pub(crate) fn to_usize(self) -> usize {
|
|
||||||
match self {
|
match self {
|
||||||
JoinerProgress::RequestWithAuthSent => 400,
|
JoinerProgress::RequestWithAuthSent => 400,
|
||||||
JoinerProgress::Succeeded => 1000,
|
JoinerProgress::Succeeded => 1000,
|
||||||
|
|||||||
Reference in New Issue
Block a user