add device message if quota is exceeding (#2621)

* resultify update_recent_quota()

* add a device-message if quota exceeds QUOTA_WARN_THRESHOLD_PERCENTAGE

* check if a quota warning should be added during housekeeping, this is at least once a day

* dc_get_config("quota_exceeding") is useful for bots

* make clippy happy

* reword QuotaExceedingMsgBody message

* avoid lots of warnings if quota jitters around the warning threshold

* allow clippy::assertions_on_constants

these constants depend on each other, it makes sense to check that they are not changed in an incompatible way
This commit is contained in:
bjoern
2021-08-26 15:31:25 +02:00
committed by GitHub
parent 3aa2b57ac1
commit 71e0493c4a
7 changed files with 136 additions and 5 deletions

View File

@@ -258,6 +258,15 @@ pub enum StockMessage {
#[strum(props(fallback = "Forwarded"))]
Forwarded = 97,
#[strum(props(
fallback = "⚠️ Your provider's storage is about to exceed, already %1$s%% are used.\n\n\
You may not be able to receive message when the storage is 100%% used.\n\n\
👉 Please check if you can delete old data in the provider's webinterface \
and consider to enable \"Settings / Delete Old Messages\". \
You can check your current storage usage anytime at \"Settings / Connectivity\"."
))]
QuotaExceedingMsgBody = 98,
}
impl StockMessage {
@@ -840,6 +849,14 @@ pub(crate) async fn forwarded(context: &Context) -> String {
translated(context, StockMessage::Forwarded).await
}
/// Stock string: `⚠️ Your provider's storage is about to exceed...`.
pub(crate) async fn quota_exceeding(context: &Context, highest_usage: u64) -> String {
translated(context, StockMessage::QuotaExceedingMsgBody)
.await
.replace1(format!("{}", highest_usage))
.replace("%%", "%")
}
impl Context {
/// Set the stock string for the [StockMessage].
///
@@ -1023,6 +1040,16 @@ mod tests {
);
}
#[async_std::test]
async fn test_quota_exceeding_stock_str() -> anyhow::Result<()> {
let t = TestContext::new().await;
let str = quota_exceeding(&t, 81).await;
assert!(str.contains("81% "));
assert!(str.contains("100% "));
assert!(!str.contains("%%"));
Ok(())
}
#[async_std::test]
async fn test_update_device_chats() {
let t = TestContext::new().await;