Page MenuHomePhabricator

D11523.diff
No OneTemporary

D11523.diff

diff --git a/native/native_rust_library/src/identity.rs b/native/native_rust_library/src/identity.rs
--- a/native/native_rust_library/src/identity.rs
+++ b/native/native_rust_library/src/identity.rs
@@ -9,6 +9,7 @@
use crate::{CODE_VERSION, DEVICE_TYPE, IDENTITY_SOCKET_ADDR};
pub mod account_actions;
+pub mod device_list;
pub mod exact_user_search;
pub mod farcaster;
pub mod login;
@@ -19,6 +20,7 @@
use super::*;
pub use account_actions::ffi::*;
+ pub use device_list::ffi::*;
pub use exact_user_search::ffi::*;
pub use farcaster::ffi::*;
pub use login::ffi::*;
diff --git a/native/native_rust_library/src/identity/device_list.rs b/native/native_rust_library/src/identity/device_list.rs
new file mode 100644
--- /dev/null
+++ b/native/native_rust_library/src/identity/device_list.rs
@@ -0,0 +1,104 @@
+use grpc_clients::identity::get_auth_client;
+use grpc_clients::identity::protos::auth::{
+ GetDeviceListRequest, UpdateDeviceListRequest,
+};
+
+use crate::identity::AuthInfo;
+use crate::utils::jsi_callbacks::{
+ handle_string_result_as_callback, handle_void_result_as_callback,
+};
+use crate::{Error, CODE_VERSION, DEVICE_TYPE, IDENTITY_SOCKET_ADDR, RUNTIME};
+
+pub mod ffi {
+ use super::*;
+
+ pub fn get_device_list_for_user(
+ auth_user_id: String,
+ auth_device_id: String,
+ auth_access_token: String,
+ user_id: String,
+ since_timestamp: i64,
+ promise_id: u32,
+ ) {
+ RUNTIME.spawn(async move {
+ let auth_info = AuthInfo {
+ access_token: auth_access_token,
+ user_id: auth_user_id,
+ device_id: auth_device_id,
+ };
+ let since_timestamp = Option::from(since_timestamp).filter(|&t| t > 0);
+ let result =
+ get_device_list_for_user_helper(auth_info, user_id, since_timestamp)
+ .await;
+ handle_string_result_as_callback(result, promise_id);
+ });
+ }
+
+ pub fn update_device_list(
+ auth_user_id: String,
+ auth_device_id: String,
+ auth_access_token: String,
+ update_payload: String,
+ promise_id: u32,
+ ) {
+ RUNTIME.spawn(async move {
+ let auth_info = AuthInfo {
+ access_token: auth_access_token,
+ user_id: auth_user_id,
+ device_id: auth_device_id,
+ };
+ let result = update_device_list_helper(auth_info, update_payload).await;
+ handle_void_result_as_callback(result, promise_id);
+ });
+ }
+}
+
+async fn get_device_list_for_user_helper(
+ auth_info: AuthInfo,
+ user_id: String,
+ since_timestamp: Option<i64>,
+) -> Result<String, Error> {
+ let mut identity_client = get_auth_client(
+ IDENTITY_SOCKET_ADDR,
+ auth_info.user_id,
+ auth_info.device_id,
+ auth_info.access_token,
+ CODE_VERSION,
+ DEVICE_TYPE.as_str_name().to_lowercase(),
+ )
+ .await?;
+
+ let response = identity_client
+ .get_device_list_for_user(GetDeviceListRequest {
+ user_id,
+ since_timestamp,
+ })
+ .await?
+ .into_inner();
+
+ let payload = serde_json::to_string(&response.device_list_updates)?;
+ Ok(payload)
+}
+
+async fn update_device_list_helper(
+ auth_info: AuthInfo,
+ update_payload: String,
+) -> Result<(), Error> {
+ let mut identity_client = get_auth_client(
+ IDENTITY_SOCKET_ADDR,
+ auth_info.user_id,
+ auth_info.device_id,
+ auth_info.access_token,
+ CODE_VERSION,
+ DEVICE_TYPE.as_str_name().to_lowercase(),
+ )
+ .await?;
+
+ let update_request = UpdateDeviceListRequest {
+ new_device_list: update_payload,
+ };
+
+ identity_client.update_device_list(update_request).await?;
+
+ Ok(())
+}
diff --git a/native/native_rust_library/src/lib.rs b/native/native_rust_library/src/lib.rs
--- a/native/native_rust_library/src/lib.rs
+++ b/native/native_rust_library/src/lib.rs
@@ -1,12 +1,9 @@
use comm_opaque2::grpc::opaque_error_to_grpc_status as handle_error;
-use grpc_clients::identity::protos::auth::{
- GetDeviceListRequest, UpdateDeviceListRequest,
-};
+use grpc_clients::identity::get_unauthenticated_client;
use grpc_clients::identity::protos::unauth::{
DeviceKeyUpload, DeviceType, ExistingDeviceLoginRequest, IdentityKeyInfo,
Prekey, SecondaryDeviceKeysUploadRequest,
};
-use grpc_clients::identity::{get_auth_client, get_unauthenticated_client};
use lazy_static::lazy_static;
use std::sync::Arc;
use tokio::runtime::{Builder, Runtime};
@@ -19,7 +16,7 @@
mod utils;
use crate::argon2_tools::compute_backup_key_str;
-use crate::identity::{AuthInfo, UserIDAndDeviceAccessToken};
+use crate::identity::UserIDAndDeviceAccessToken;
use crate::utils::jsi_callbacks::{
handle_string_result_as_callback, handle_void_result_as_callback,
};
@@ -421,96 +418,6 @@
}
}
-fn get_device_list_for_user(
- auth_user_id: String,
- auth_device_id: String,
- auth_access_token: String,
- user_id: String,
- since_timestamp: i64,
- promise_id: u32,
-) {
- RUNTIME.spawn(async move {
- let auth_info = AuthInfo {
- access_token: auth_access_token,
- user_id: auth_user_id,
- device_id: auth_device_id,
- };
- let since_timestamp = Option::from(since_timestamp).filter(|&t| t > 0);
- let result =
- get_device_list_for_user_helper(auth_info, user_id, since_timestamp)
- .await;
- handle_string_result_as_callback(result, promise_id);
- });
-}
-
-async fn get_device_list_for_user_helper(
- auth_info: AuthInfo,
- user_id: String,
- since_timestamp: Option<i64>,
-) -> Result<String, Error> {
- let mut identity_client = get_auth_client(
- IDENTITY_SOCKET_ADDR,
- auth_info.user_id,
- auth_info.device_id,
- auth_info.access_token,
- CODE_VERSION,
- DEVICE_TYPE.as_str_name().to_lowercase(),
- )
- .await?;
-
- let response = identity_client
- .get_device_list_for_user(GetDeviceListRequest {
- user_id,
- since_timestamp,
- })
- .await?
- .into_inner();
-
- let payload = serde_json::to_string(&response.device_list_updates)?;
- Ok(payload)
-}
-
-fn update_device_list(
- auth_user_id: String,
- auth_device_id: String,
- auth_access_token: String,
- update_payload: String,
- promise_id: u32,
-) {
- RUNTIME.spawn(async move {
- let auth_info = AuthInfo {
- access_token: auth_access_token,
- user_id: auth_user_id,
- device_id: auth_device_id,
- };
- let result = update_device_list_helper(auth_info, update_payload).await;
- handle_void_result_as_callback(result, promise_id);
- });
-}
-
-async fn update_device_list_helper(
- auth_info: AuthInfo,
- update_payload: String,
-) -> Result<(), Error> {
- let mut identity_client = get_auth_client(
- IDENTITY_SOCKET_ADDR,
- auth_info.user_id,
- auth_info.device_id,
- auth_info.access_token,
- CODE_VERSION,
- DEVICE_TYPE.as_str_name().to_lowercase(),
- )
- .await?;
-
- let update_request = UpdateDeviceListRequest {
- new_device_list: update_payload,
- };
-
- identity_client.update_device_list(update_request).await?;
-
- Ok(())
-}
-
fn upload_secondary_device_keys_and_log_in(
user_id: String,
challenge_response: String,

File Metadata

Mime Type
text/plain
Expires
Wed, Dec 25, 8:04 PM (12 h, 27 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2703049
Default Alt Text
D11523.diff (6 KB)

Event Timeline