Compare commits

...

2 Commits

Author SHA1 Message Date
Lonami Exo 7bfbcc955c Add env var to support connecting to test servers 2022-10-20 21:18:56 +02:00
Lonami Exo 0f412f7334 Load API ID and hash from env 2022-10-20 21:18:33 +02:00
1 changed files with 25 additions and 4 deletions

View File

@ -4,7 +4,7 @@
mod db;
use grammers_client::types::{Dialog, LoginToken};
use grammers_client::{Client, Config};
use grammers_client::{Client, Config, InitParams};
use grammers_session::{PackedChat, Session, UpdateState};
use jni::objects::{JObject, JString};
use jni::sys::{jboolean, jint, jlong, jstring};
@ -25,8 +25,22 @@ type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
const LOG_MIN_LEVEL: Level = Level::Trace;
const LOG_TAG: &str = ".native.talari";
const API_ID: i32 = 0;
const API_HASH: &str = "";
const API_ID: i32 = {
let mut index = 0;
let mut value = 0;
let api_id = env!("TALARIA_API_ID");
let bytes = api_id.as_bytes();
while index < bytes.len() {
match bytes[index] {
b @ b'0'..=b'9' => value = value * 10 + (b - b'0') as i32,
_ => panic!("non-digit character found in API ID"),
}
index += 1
}
value
};
const API_HASH: &str = env!("TALARIA_API_HASH");
const SERVER_ADDR: &str = env!("TALARIA_SERVER_ADDR");
static RUNTIME: OnceCell<Runtime> = OnceCell::new();
static CLIENT: OnceCell<Client> = OnceCell::new();
@ -101,7 +115,14 @@ async fn init_client() -> Result<()> {
session,
api_id: API_ID,
api_hash: API_HASH.to_string(),
params: Default::default(),
params: InitParams {
server_addr: if SERVER_ADDR.is_empty() {
None
} else {
Some(SERVER_ADDR.parse().unwrap())
},
..Default::default()
},
})
.await?;