forked from Lonami/Talaria
Use snake_case in UDL
uniffi automatically converts to camelCase for Kotlin, but it won't convert to snake_case for Rust.
This commit is contained in:
parent
1574ce683c
commit
912949a079
|
@ -83,7 +83,7 @@ pub struct MessagePreview {
|
|||
pub struct Dialog {
|
||||
id: String,
|
||||
title: String,
|
||||
lastMessage: Option<MessagePreview>,
|
||||
last_message: Option<MessagePreview>,
|
||||
pinned: bool,
|
||||
}
|
||||
|
||||
|
@ -104,7 +104,7 @@ fn block_on<F: Future>(future: F) -> F::Output {
|
|||
RUNTIME.get().unwrap().block_on(future)
|
||||
}
|
||||
|
||||
pub fn initDatabase(path: String) -> Result<()> {
|
||||
pub fn init_database(path: String) -> Result<()> {
|
||||
let mut guard = DATABASE.lock().unwrap();
|
||||
if guard.is_some() {
|
||||
info!("Database is already initialized");
|
||||
|
@ -119,7 +119,7 @@ pub fn initDatabase(path: String) -> Result<()> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn initClient() -> Result<()> {
|
||||
pub fn init_client() -> Result<()> {
|
||||
android_logger::init_once(
|
||||
android_logger::Config::default()
|
||||
.with_min_level(LOG_MIN_LEVEL)
|
||||
|
@ -194,19 +194,19 @@ pub fn initClient() -> Result<()> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn needLogin() -> Result<bool> {
|
||||
pub fn need_login() -> Result<bool> {
|
||||
let client = CLIENT.get().ok_or(NativeError::Initialization)?;
|
||||
block_on(client.is_authorized()).map_err(|_| NativeError::Network)
|
||||
}
|
||||
|
||||
pub fn requestLoginCode(phone: String) -> Result<u64> {
|
||||
pub fn request_login_code(phone: String) -> Result<u64> {
|
||||
let client = CLIENT.get().ok_or(NativeError::Initialization)?;
|
||||
block_on(client.request_login_code(&phone, API_ID, API_HASH))
|
||||
.map(|token| Box::into_raw(Box::new(token)) as u64)
|
||||
.map_err(|_| NativeError::Network)
|
||||
}
|
||||
|
||||
pub fn signIn(token_ptr: u64, code: String) -> Result<()> {
|
||||
pub fn sign_in(token_ptr: u64, code: String) -> Result<()> {
|
||||
let token = unsafe { *Box::from_raw(token_ptr as *mut LoginToken) };
|
||||
let client = CLIENT.get().ok_or(NativeError::Initialization)?;
|
||||
|
||||
|
@ -256,7 +256,7 @@ pub fn signIn(token_ptr: u64, code: String) -> Result<()> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn getDialogs() -> Result<Vec<Dialog>> {
|
||||
pub fn get_dialogs() -> Result<Vec<Dialog>> {
|
||||
let client = CLIENT.get().ok_or(NativeError::Initialization)?;
|
||||
|
||||
block_on(async {
|
||||
|
@ -273,7 +273,7 @@ pub fn getDialogs() -> Result<Vec<Dialog>> {
|
|||
.map(|d| Dialog {
|
||||
id: d.chat().pack().to_hex(),
|
||||
title: d.chat().name().to_string(),
|
||||
lastMessage: d.last_message.map(|m| MessagePreview {
|
||||
last_message: d.last_message.map(|m| MessagePreview {
|
||||
sender: if let Some(sender) = m.sender() {
|
||||
sender.name().to_string()
|
||||
} else {
|
||||
|
@ -305,7 +305,7 @@ pub fn getDialogs() -> Result<Vec<Dialog>> {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn sendMessage(packed: String, text: String) -> Result<()> {
|
||||
pub fn send_message(packed: String, text: String) -> Result<()> {
|
||||
let chat = PackedChat::from_hex(&packed).unwrap();
|
||||
let client = CLIENT.get().ok_or(NativeError::Initialization)?;
|
||||
block_on(client.send_message(chat, text)).map_err(|_| NativeError::Network)?;
|
||||
|
|
|
@ -21,23 +21,23 @@ dictionary MessagePreview {
|
|||
dictionary Dialog {
|
||||
string id;
|
||||
string title;
|
||||
MessagePreview? lastMessage;
|
||||
MessagePreview? last_message;
|
||||
boolean pinned;
|
||||
};
|
||||
|
||||
namespace talaria {
|
||||
[Throws=NativeError]
|
||||
void initDatabase(string path);
|
||||
void init_database(string path);
|
||||
[Throws=NativeError]
|
||||
void initClient();
|
||||
void init_client();
|
||||
[Throws=NativeError]
|
||||
boolean needLogin();
|
||||
boolean need_login();
|
||||
[Throws=NativeError]
|
||||
u64 requestLoginCode(string phone);
|
||||
u64 request_login_code(string phone);
|
||||
[Throws=NativeError]
|
||||
void signIn(u64 tokenPtr, string code);
|
||||
void sign_in(u64 tokenPtr, string code);
|
||||
[Throws=NativeError]
|
||||
sequence<Dialog> getDialogs();
|
||||
sequence<Dialog> get_dialogs();
|
||||
[Throws=NativeError]
|
||||
void sendMessage(string packed, string text);
|
||||
void send_message(string packed, string text);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue