mirror of
https://github.com/chatmail/core.git
synced 2026-05-07 17:06:35 +03:00
Compare commits
1 Commits
iequidoo/r
...
iequidoo/d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e2ce3587ff |
@@ -66,7 +66,7 @@ impl WebxdcMessageInfo {
|
||||
self_addr,
|
||||
is_app_sender,
|
||||
is_broadcast,
|
||||
send_update_interval_ms,
|
||||
send_update_interval,
|
||||
send_update_max_size,
|
||||
} = message.get_webxdc_info(context).await?;
|
||||
|
||||
@@ -80,7 +80,7 @@ impl WebxdcMessageInfo {
|
||||
self_addr,
|
||||
is_app_sender,
|
||||
is_broadcast,
|
||||
send_update_interval: send_update_interval_ms,
|
||||
send_update_interval,
|
||||
send_update_max_size,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -91,9 +91,9 @@ impl Ratelimit {
|
||||
self.until_can_send_at(SystemTime::now())
|
||||
}
|
||||
|
||||
/// Returns the minimum possible sending interval.
|
||||
pub fn min_send_interval(&self) -> Duration {
|
||||
self.window.div_f64(self.quota)
|
||||
/// Returns minimum possible update interval in milliseconds.
|
||||
pub fn update_interval(&self) -> usize {
|
||||
(self.window.as_millis() as f64 / self.quota) as usize
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ mod tests {
|
||||
|
||||
let mut ratelimit = Ratelimit::new_at(Duration::new(60, 0), 3.0, now);
|
||||
assert!(ratelimit.can_send_at(now));
|
||||
assert_eq!(ratelimit.min_send_interval(), Duration::new(20, 0));
|
||||
assert_eq!(ratelimit.update_interval(), 20_000);
|
||||
|
||||
// Send burst of 3 messages.
|
||||
ratelimit.send_at(now);
|
||||
|
||||
@@ -66,12 +66,6 @@ impl Context {
|
||||
|
||||
/// Updates `quota.recent`, sets `quota.modified` to the current time
|
||||
/// and emits an event to let the UIs update connectivity view.
|
||||
///
|
||||
/// Moreover, once each time quota gets larger than `QUOTA_WARN_THRESHOLD_PERCENTAGE`,
|
||||
/// a device message is added.
|
||||
/// As the message is added only once, the user is not spammed
|
||||
/// in case for some providers the quota is always at ~100%
|
||||
/// and new space is allocated as needed.
|
||||
pub(crate) async fn update_recent_quota(
|
||||
&self,
|
||||
session: &mut ImapSession,
|
||||
|
||||
@@ -21,7 +21,6 @@ mod maps_integration;
|
||||
use std::cmp::max;
|
||||
use std::collections::HashMap;
|
||||
use std::path::Path;
|
||||
use std::time::Duration;
|
||||
|
||||
use anyhow::{Context as _, Result, anyhow, bail, ensure, format_err};
|
||||
|
||||
@@ -120,7 +119,7 @@ pub struct WebxdcInfo {
|
||||
|
||||
/// Milliseconds to wait before calling `sendUpdate()` again since the last call.
|
||||
/// Should be exposed to `window.sendUpdateInterval` in JS land.
|
||||
pub send_update_interval_ms: usize,
|
||||
pub send_update_interval: usize,
|
||||
|
||||
/// Maximum number of bytes accepted for a serialized update object.
|
||||
/// Should be exposed to `window.sendUpdateMaxSize` in JS land.
|
||||
@@ -975,16 +974,7 @@ impl Message {
|
||||
self_addr,
|
||||
is_app_sender,
|
||||
is_broadcast,
|
||||
send_update_interval_ms: context
|
||||
.ratelimit
|
||||
.read()
|
||||
.await
|
||||
.min_send_interval()
|
||||
// Round the value up so that it's not 0 at least.
|
||||
.checked_add(Duration::from_nanos(999_999))
|
||||
.context("Overflow occurred")?
|
||||
.as_millis()
|
||||
.try_into()?,
|
||||
send_update_interval: context.ratelimit.read().await.update_interval(),
|
||||
send_update_max_size: RECOMMENDED_FILE_SIZE as usize,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1226,7 +1226,7 @@ async fn test_get_webxdc_info() -> Result<()> {
|
||||
let info = instance.get_webxdc_info(&t).await?;
|
||||
assert_eq!(info.name, "minimal.xdc");
|
||||
assert_eq!(info.icon, WEBXDC_DEFAULT_ICON.to_string());
|
||||
assert_eq!(info.send_update_interval_ms, 1000);
|
||||
assert_eq!(info.send_update_interval, 1000);
|
||||
assert_eq!(info.send_update_max_size, RECOMMENDED_FILE_SIZE as usize);
|
||||
|
||||
let mut instance = create_webxdc_instance(
|
||||
|
||||
Reference in New Issue
Block a user