mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 09:26:29 +03:00
improve simple example
This commit is contained in:
@@ -40,16 +40,21 @@ async fn main() {
|
|||||||
|
|
||||||
let ctx1 = ctx.clone();
|
let ctx1 = ctx.clone();
|
||||||
std::thread::spawn(move || loop {
|
std::thread::spawn(move || loop {
|
||||||
if let Ok(event) = ctx1.get_next_event() {
|
if ctx1.has_next_event() {
|
||||||
cb(event);
|
if let Ok(event) = ctx1.get_next_event() {
|
||||||
|
cb(event);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
std::thread::sleep(time::Duration::from_millis(50));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
println!("configuring");
|
println!("configuring");
|
||||||
let args = std::env::args().collect::<Vec<String>>();
|
let args = std::env::args().collect::<Vec<String>>();
|
||||||
assert_eq!(args.len(), 2, "missing password");
|
assert_eq!(args.len(), 3, "requires email password");
|
||||||
let pw = args[1].clone();
|
let email = args[1].clone();
|
||||||
ctx.set_config(config::Config::Addr, Some("d@testrun.org"))
|
let pw = args[2].clone();
|
||||||
|
ctx.set_config(config::Config::Addr, Some(&email))
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
ctx.set_config(config::Config::MailPw, Some(&pw))
|
ctx.set_config(config::Config::MailPw, Some(&pw))
|
||||||
@@ -66,9 +71,12 @@ async fn main() {
|
|||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let chat_id = chat::create_by_contact_id(&ctx, contact_id).await.unwrap();
|
let chat_id = chat::create_by_contact_id(&ctx, contact_id).await.unwrap();
|
||||||
chat::send_text_msg(&ctx, chat_id, "Hi, here is my first message!".into())
|
|
||||||
.await
|
for i in 0..2 {
|
||||||
.unwrap();
|
chat::send_text_msg(&ctx, chat_id, format!("Hi, here is my {}nth message!", i))
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
println!("fetching chats..");
|
println!("fetching chats..");
|
||||||
let chats = Chatlist::try_load(&ctx, 0, None, None).await.unwrap();
|
let chats = Chatlist::try_load(&ctx, 0, None, None).await.unwrap();
|
||||||
|
|||||||
Reference in New Issue
Block a user