chore: rename quicproquo → quicprochat in Rust workspace
Rename all crate directories, package names, binary names, proto package/module paths, ALPN strings, env var prefixes, config filenames, mDNS service names, and plugin ABI symbols from quicproquo/qpq to quicprochat/qpc.
This commit is contained in:
50
crates/quicprochat-sdk/src/users.rs
Normal file
50
crates/quicprochat-sdk/src/users.rs
Normal file
@@ -0,0 +1,50 @@
|
||||
//! User resolution — username <-> identity key lookups.
|
||||
|
||||
use quicprochat_proto::bytes::Bytes;
|
||||
use quicprochat_proto::prost::Message;
|
||||
use quicprochat_proto::{method_ids, qpc::v1};
|
||||
use quicprochat_rpc::client::RpcClient;
|
||||
|
||||
use crate::error::SdkError;
|
||||
|
||||
/// Resolve a username to its identity key.
|
||||
/// Returns `None` if the username is not registered.
|
||||
pub async fn resolve_user(
|
||||
rpc: &RpcClient,
|
||||
username: &str,
|
||||
) -> Result<Option<Vec<u8>>, SdkError> {
|
||||
let req = v1::ResolveUserRequest {
|
||||
username: username.to_string(),
|
||||
};
|
||||
let resp_bytes = rpc
|
||||
.call(method_ids::RESOLVE_USER, Bytes::from(req.encode_to_vec()))
|
||||
.await?;
|
||||
let resp = v1::ResolveUserResponse::decode(resp_bytes)
|
||||
.map_err(|e| SdkError::Other(anyhow::anyhow!("decode ResolveUserResponse: {e}")))?;
|
||||
if resp.identity_key.is_empty() {
|
||||
Ok(None)
|
||||
} else {
|
||||
Ok(Some(resp.identity_key))
|
||||
}
|
||||
}
|
||||
|
||||
/// Reverse lookup: identity key to username.
|
||||
/// Returns `None` if no username is associated with the key.
|
||||
pub async fn resolve_identity(
|
||||
rpc: &RpcClient,
|
||||
identity_key: &[u8],
|
||||
) -> Result<Option<String>, SdkError> {
|
||||
let req = v1::ResolveIdentityRequest {
|
||||
identity_key: identity_key.to_vec(),
|
||||
};
|
||||
let resp_bytes = rpc
|
||||
.call(method_ids::RESOLVE_IDENTITY, Bytes::from(req.encode_to_vec()))
|
||||
.await?;
|
||||
let resp = v1::ResolveIdentityResponse::decode(resp_bytes)
|
||||
.map_err(|e| SdkError::Other(anyhow::anyhow!("decode ResolveIdentityResponse: {e}")))?;
|
||||
if resp.username.is_empty() {
|
||||
Ok(None)
|
||||
} else {
|
||||
Ok(Some(resp.username))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user