Get delta contexts chugging
This commit is contained in:
@@ -7,7 +7,6 @@ use crate::messages::{
|
|||||||
};
|
};
|
||||||
// use crate::{Handle, ChatInfo};
|
// use crate::{Handle, ChatInfo};
|
||||||
use async_std::channel::{self, Receiver};
|
use async_std::channel::{self, Receiver};
|
||||||
|
|
||||||
use deltachat::accounts::Accounts;
|
use deltachat::accounts::Accounts;
|
||||||
|
|
||||||
const CHANNEL_CAPACITY: usize = 1024;
|
const CHANNEL_CAPACITY: usize = 1024;
|
||||||
@@ -32,19 +31,27 @@ pub fn spawn() -> DeltaSystemHandle {
|
|||||||
pub fn run(tx: FdSender<SystemMessage>, rx: Receiver<PurpleMessage>) {
|
pub fn run(tx: FdSender<SystemMessage>, rx: Receiver<PurpleMessage>) {
|
||||||
logging::set_thread_logger(logging::RemoteLogger(tx.clone()));
|
logging::set_thread_logger(logging::RemoteLogger(tx.clone()));
|
||||||
log::info!("Starting Delta system");
|
log::info!("Starting Delta system");
|
||||||
let mut system = DeltaSystem::new(tx, rx);
|
log::debug!("Performing delta accounts setup");
|
||||||
|
|
||||||
|
let mut config_dir = DeltaSystem::user_dir();
|
||||||
|
config_dir.push("purple-plugin-delta");
|
||||||
|
|
||||||
|
let accounts =
|
||||||
|
async_std::task::block_on(Accounts::new("purple-plugin-delta".into(), config_dir)).unwrap();
|
||||||
|
|
||||||
|
let mut system = DeltaSystem::new(tx, rx, accounts);
|
||||||
async_std::task::block_on(system.run());
|
async_std::task::block_on(system.run());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct DeltaSystem {
|
pub struct DeltaSystem {
|
||||||
tx: FdSender<SystemMessage>,
|
tx: FdSender<SystemMessage>,
|
||||||
rx: Receiver<PurpleMessage>,
|
rx: Receiver<PurpleMessage>,
|
||||||
accounts: Option<Accounts>,
|
accounts: Accounts,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DeltaSystem {
|
impl DeltaSystem {
|
||||||
fn new(tx: FdSender<SystemMessage>, rx: Receiver<PurpleMessage>) -> Self {
|
fn new(tx: FdSender<SystemMessage>, rx: Receiver<PurpleMessage>, accounts: Accounts) -> Self {
|
||||||
Self { tx, rx, accounts: None }
|
Self { tx, rx, accounts }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn user_dir() -> async_std::path::PathBuf {
|
fn user_dir() -> async_std::path::PathBuf {
|
||||||
@@ -59,12 +66,6 @@ impl DeltaSystem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn run(&mut self) {
|
async fn run(&mut self) {
|
||||||
log::debug!("Performing delta accounts setup");
|
|
||||||
let mut config_dir = DeltaSystem::user_dir();
|
|
||||||
config_dir.push("purple-plugin-delta");
|
|
||||||
|
|
||||||
self.accounts = Some(Accounts::new("purple-plugin-delta".into(), config_dir).await.unwrap());
|
|
||||||
|
|
||||||
log::info!("Looping on messages");
|
log::info!("Looping on messages");
|
||||||
loop {
|
loop {
|
||||||
let purple_message = match self.rx.recv().await {
|
let purple_message = match self.rx.recv().await {
|
||||||
@@ -92,13 +93,34 @@ impl DeltaSystem {
|
|||||||
|
|
||||||
async fn login(&mut self, account_info: AccountInfo) -> std::result::Result<(), String> {
|
async fn login(&mut self, account_info: AccountInfo) -> std::result::Result<(), String> {
|
||||||
log::debug!("login");
|
log::debug!("login");
|
||||||
/*
|
let email_address = { account_info.protocol_data.email_address.clone() };
|
||||||
let phone_number = { account_info.protocol_data.phone_number.clone() };
|
let password = { account_info.protocol_data.imap_pass.clone() };
|
||||||
let handle = &account_info.handle;
|
let handle = &account_info.handle;
|
||||||
|
|
||||||
|
// TODO: make this properly async
|
||||||
|
let ctx = match self.accounts.get_all().await.into_iter()
|
||||||
|
.map( |id| async_std::task::block_on(self.accounts.get_account(id)).unwrap() )
|
||||||
|
.find( |ctx| async_std::task::block_on(ctx.is_self_addr(&email_address)).unwrap() ) {
|
||||||
|
None => {
|
||||||
|
let id = self.accounts.add_account().await.unwrap();
|
||||||
|
self.accounts.get_account(id).await.unwrap()
|
||||||
|
},
|
||||||
|
Some(ctx) => ctx
|
||||||
|
};
|
||||||
|
|
||||||
|
// Now transpose config into ctx. TODO: rest of the fields
|
||||||
|
ctx.set_config(deltachat::config::Config::Addr, Some(&email_address)).await.unwrap();
|
||||||
|
ctx.set_config(deltachat::config::Config::MailPw, Some(&password)).await.unwrap();
|
||||||
|
|
||||||
|
ctx.configure().await.unwrap();
|
||||||
|
ctx.start_io(); // TODO: what to do with this future?
|
||||||
|
// TODO: set off event emitter
|
||||||
|
|
||||||
|
/*
|
||||||
let mut registered_account_info = {
|
let mut registered_account_info = {
|
||||||
self.tx
|
self.tx
|
||||||
.account_proxy(&handle)
|
.account_proxy(&handle)
|
||||||
.exec(|account| {
|
.exec(|purple_account| {
|
||||||
let token =
|
let token =
|
||||||
account.get_string(protocol::RegistrationData::TOKEN_SETTING_KEY, "");
|
account.get_string(protocol::RegistrationData::TOKEN_SETTING_KEY, "");
|
||||||
if token.is_empty() {
|
if token.is_empty() {
|
||||||
|
@@ -76,6 +76,7 @@ pub struct MsgInfo {
|
|||||||
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
pub struct AccountData {
|
pub struct AccountData {
|
||||||
|
email_address: String,
|
||||||
display_name: String,
|
display_name: String,
|
||||||
imap_host: String,
|
imap_host: String,
|
||||||
imap_port: String,
|
imap_port: String,
|
||||||
@@ -139,7 +140,8 @@ impl purple::PrplPlugin for PurpleDelta {
|
|||||||
.with_string_option("Display Name".into(), "displayname".into(), "".into())
|
.with_string_option("Display Name".into(), "displayname".into(), "".into())
|
||||||
.with_string_option("IMAP server host".into(), "mail_server".into(), "".into())
|
.with_string_option("IMAP server host".into(), "mail_server".into(), "".into())
|
||||||
.with_string_option("IMAP server port".into(), "mail_port".into(), "".into())
|
.with_string_option("IMAP server port".into(), "mail_port".into(), "".into())
|
||||||
// Username and password are mail_user and mail_pw
|
.with_string_option("IMAP server username".into(), "mail_user".into(), "".into())
|
||||||
|
// Password is account password
|
||||||
.with_string_option("SMTP server host".into(), "send_server".into(), "".into())
|
.with_string_option("SMTP server host".into(), "send_server".into(), "".into())
|
||||||
.with_string_option("SMTP server port".into(), "send_port".into(), "".into())
|
.with_string_option("SMTP server port".into(), "send_port".into(), "".into())
|
||||||
.with_string_option("SMTP server username".into(), "send_user".into(), "".into())
|
.with_string_option("SMTP server username".into(), "send_user".into(), "".into())
|
||||||
@@ -163,11 +165,12 @@ impl purple::PrplPlugin for PurpleDelta {
|
|||||||
|
|
||||||
impl purple::LoginHandler for PurpleDelta {
|
impl purple::LoginHandler for PurpleDelta {
|
||||||
fn login(&mut self, account: &mut Account) {
|
fn login(&mut self, account: &mut Account) {
|
||||||
|
let email_address = account.get_username().unwrap().into();
|
||||||
let display_name = account.get_string("displayname", "");
|
let display_name = account.get_string("displayname", "");
|
||||||
|
|
||||||
let imap_host = account.get_string("mail_server", "");
|
let imap_host = account.get_string("mail_server", "");
|
||||||
let imap_port = account.get_string("mail_port", "");
|
let imap_port = account.get_string("mail_port", "");
|
||||||
let imap_user = account.get_username().unwrap().into();
|
let imap_user = account.get_string("mail_user", "");
|
||||||
let imap_pass = account.get_password().unwrap().into();
|
let imap_pass = account.get_password().unwrap().into();
|
||||||
|
|
||||||
let smtp_host = account.get_string("send_server", "");
|
let smtp_host = account.get_string("send_server", "");
|
||||||
@@ -178,6 +181,7 @@ impl purple::LoginHandler for PurpleDelta {
|
|||||||
let bcc_self = account.get_bool("bcc_self", false);
|
let bcc_self = account.get_bool("bcc_self", false);
|
||||||
|
|
||||||
let protocol_data: AccountDataBox = Arc::new(AccountData {
|
let protocol_data: AccountDataBox = Arc::new(AccountData {
|
||||||
|
email_address,
|
||||||
display_name,
|
display_name,
|
||||||
|
|
||||||
imap_host,
|
imap_host,
|
||||||
|
Reference in New Issue
Block a user