From 29fe24728c456f0d352b17f15d78757882e83ee6 Mon Sep 17 00:00:00 2001 From: bunnie Date: Sun, 29 Oct 2023 19:15:11 +0800 Subject: [PATCH] add more wait states around long-run ops --- apps/mtxchat/locales/i18n.json | 16 ++++++++++++---- apps/mtxchat/src/lib.rs | 23 ++++++++++++++++++----- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/apps/mtxchat/locales/i18n.json b/apps/mtxchat/locales/i18n.json index d5d3edfea..304ecb736 100644 --- a/apps/mtxchat/locales/i18n.json +++ b/apps/mtxchat/locales/i18n.json @@ -11,6 +11,18 @@ "en": "Sending...", "en-tts": "Sending..." }, + "mtxchat.busy.room_id": { + "en": "Getting room ID...", + "en-tts": "Getting room ID..." + }, + "mtxchat.busy.login": { + "en": "Logging in...", + "en-tts": "Logging in..." + }, + "mtxchat.busy.new_listen": { + "en": "Syncing all events from server...", + "en-tts": "Syncing all events from server..." + }, "mtxchat.clock.warning": { "en": "WARNING: clock not set", "en-tts": "WARNING: clock not set", @@ -245,10 +257,6 @@ "en": "No connection! Read-only.", "en-tts": "No connection! Read-only." }, - "mtxchat.listen.patience": { - "en": "It takes a while to get new events from the [matrix] server.\nPlease be patient :-)", - "en-tts": "It takes a while to get new events from the [matrix] server.\nPlease be patient." - }, "mtxchat.close.item": { "en": "Close menu", "en-tts": "Close menu" diff --git a/apps/mtxchat/src/lib.rs b/apps/mtxchat/src/lib.rs index 3bf47b132..f537d3dce 100644 --- a/apps/mtxchat/src/lib.rs +++ b/apps/mtxchat/src/lib.rs @@ -38,6 +38,7 @@ const DOMAIN_MATRIX: &str = "matrix.org"; const MTX_LONG_TIMEOUT_MS: i32 = 60000; // ms const WIFI_TIMEOUT_MS: u32 = 30_000; // ms +const SEND_RETRIES: usize = 3; pub const CLOCK_NOT_SET_ID: usize = 1; pub const PDDB_NOT_MOUNTED_ID: usize = 2; @@ -255,9 +256,8 @@ impl<'a> MtxChat<'a> { self.listen(); if self.new_room { self.new_room = false; - self.modals - .show_notification(t!("mtxchat.listen.patience", locales::LANG), None) - .expect("notification failed"); + self.chat.set_status_text(t!("mtxchat.busy.new_listen", locales::LANG)); + self.chat.set_busy_state(true); } return true; } else { @@ -284,7 +284,7 @@ impl<'a> MtxChat<'a> { } pub fn login(&mut self) -> bool { - self.chat.set_status_text(t!("mtxchat.busy.connecting", locales::LANG)); + self.chat.set_status_text(t!("mtxchat.busy.login", locales::LANG)); self.chat.set_busy_state(true); self.token = self.get(TOKEN_KEY).unwrap_or(None); self.logged_in = false; @@ -444,12 +444,18 @@ impl<'a> MtxChat<'a> { (true, Some(token), Some(user_domain), Some(room_alias)) => { let mut url = Url::parse("https://matrix.org").unwrap(); url.set_host(Some(user_domain)).expect("failed to set host"); + self.chat.set_status_text(t!("mtxchat.busy.room_id", locales::LANG)); + self.chat.set_busy_state(true); if let Some(room_id) = web::get_room_id(&mut url, &room_alias, &token, &mut self.agent) { self.set_debug(ROOM_ID_KEY, &room_id); + self.chat.set_status_text(&self.status); + self.chat.set_busy_state(false); return Some(room_id); } else { + self.chat.set_status_text(&self.status); + self.chat.set_busy_state(false); "failed to get room_id" } } @@ -642,7 +648,14 @@ impl<'a> MtxChat<'a> { log::info!("txn_id = {}", txn_id); let mut url = Url::parse("https://matrix.org").unwrap(); url.set_host(Some(user_domain)).expect("failed to set host"); - let r = if web::send_message(&mut url, &room_id, &text, &txn_id, token, &mut self.agent) { + let mut success = false; + for _ in 0..SEND_RETRIES { + if web::send_message(&mut url, &room_id, &text, &txn_id, token, &mut self.agent) { + success = true; + break; + } + } + let r = if success { "SENT" } else { "FAILED TO SEND"