mirror of
https://github.com/chatmail/core.git
synced 2026-04-06 07:32:12 +03:00
See https://support.delta.chat/t/discussion-how-to-show-error-states/1363/10 <!-- comment --> It turns out that it's pretty easy to distinguish between lots of states (currently Error/NotConnected, Connecting…, Getting new messages… and Connected). What's not that easy is distinguishing between an actual error and no network, because if the server just doesn't respond, it could mean that we don't have network or that we are trying ipv6, but only ipv4 works. **WRT debouncing:** Sending of EVENT_CONNECTIVITY_CHANGED is not debounced, but emitted every time one of the 3 threads (Inbox, Mvbox and Sentbox) has a network error, starts fetching data, or is done fetching data. This means that it is emitted: - 9 times when dc_maybe_network() is called or we get network connection - 12 times when we lose network connection Some measurements: dc_get_connectivity() takes a little more than 1ms (in my measurements back in March), dc_get_connectivity_html() takes 10-20ms. This means that it's no immmediate problem to call them very often, might increase battery drain though. For the UI it may be a lot of work to update the title everytime; at least Android is smart enough to update the title only once. Possible problems (we don't have to worry about them now I think): - Due to the scan_folders feature, if the user has lots of folders, the state could be "Connecting..." for quite a long time, generally DC seemed a little unresponsive to me because it took so long for "Connecting..." to go away. Telegram has a state "Updating..." that sometimes comes after "Connecting...". To be done in other PRs: - Better handle the case that the password was changed on the server and authenticating fails, see https://github.com/deltachat/deltachat-core-rust/issues/1923 and https://github.com/deltachat/deltachat-core-rust/issues/1768 - maybe event debouncing (except for "Connected" connectivity events) fix https://github.com/deltachat/deltachat-android/issues/1760
101 lines
2.8 KiB
Rust
101 lines
2.8 KiB
Rust
use tempfile::tempdir;
|
|
|
|
use deltachat::chat::{self, ChatId};
|
|
use deltachat::chatlist::*;
|
|
use deltachat::config;
|
|
use deltachat::contact::*;
|
|
use deltachat::context::*;
|
|
use deltachat::message::Message;
|
|
use deltachat::EventType;
|
|
|
|
fn cb(event: EventType) {
|
|
match event {
|
|
EventType::ConfigureProgress { progress, .. } => {
|
|
log::info!("progress: {}", progress);
|
|
}
|
|
EventType::Info(msg) => {
|
|
log::info!("{}", msg);
|
|
}
|
|
EventType::Warning(msg) => {
|
|
log::warn!("{}", msg);
|
|
}
|
|
EventType::Error(msg) => {
|
|
log::error!("{}", msg);
|
|
}
|
|
event => {
|
|
log::info!("{:?}", event);
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Run with `RUST_LOG=simple=info cargo run --release --example simple --features repl -- email pw`.
|
|
#[async_std::main]
|
|
async fn main() {
|
|
pretty_env_logger::try_init_timed().ok();
|
|
|
|
let dir = tempdir().unwrap();
|
|
let dbfile = dir.path().join("db.sqlite");
|
|
log::info!("creating database {:?}", dbfile);
|
|
let ctx = Context::new("FakeOs".into(), dbfile.into(), 0)
|
|
.await
|
|
.expect("Failed to create context");
|
|
let info = ctx.get_info().await;
|
|
log::info!("info: {:#?}", info);
|
|
|
|
let events = ctx.get_event_emitter();
|
|
let events_spawn = async_std::task::spawn(async move {
|
|
while let Some(event) = events.recv().await {
|
|
cb(event.typ);
|
|
}
|
|
});
|
|
|
|
log::info!("configuring");
|
|
let args = std::env::args().collect::<Vec<String>>();
|
|
assert_eq!(args.len(), 3, "requires email password");
|
|
let email = args[1].clone();
|
|
let pw = args[2].clone();
|
|
ctx.set_config(config::Config::Addr, Some(&email))
|
|
.await
|
|
.unwrap();
|
|
ctx.set_config(config::Config::MailPw, Some(&pw))
|
|
.await
|
|
.unwrap();
|
|
|
|
ctx.configure().await.unwrap();
|
|
|
|
log::info!("------ RUN ------");
|
|
ctx.start_io().await;
|
|
log::info!("--- SENDING A MESSAGE ---");
|
|
|
|
let contact_id = Contact::create(&ctx, "dignifiedquire", "dignifiedquire@gmail.com")
|
|
.await
|
|
.unwrap();
|
|
let chat_id = ChatId::create_for_contact(&ctx, contact_id).await.unwrap();
|
|
|
|
for i in 0..1 {
|
|
log::info!("sending message {}", i);
|
|
chat::send_text_msg(&ctx, chat_id, format!("Hi, here is my {}nth message!", i))
|
|
.await
|
|
.unwrap();
|
|
}
|
|
|
|
// wait for the message to be sent out
|
|
async_std::task::sleep(std::time::Duration::from_secs(1)).await;
|
|
|
|
log::info!("fetching chats..");
|
|
let chats = Chatlist::try_load(&ctx, 0, None, None).await.unwrap();
|
|
|
|
for i in 0..chats.len() {
|
|
let msg = Message::load_from_db(&ctx, chats.get_msg_id(i).unwrap().unwrap())
|
|
.await
|
|
.unwrap();
|
|
log::info!("[{}] msg: {:?}", i, msg);
|
|
}
|
|
|
|
log::info!("stopping");
|
|
ctx.stop_io().await;
|
|
log::info!("closing");
|
|
drop(ctx);
|
|
events_spawn.await;
|
|
}
|