feat: ensure user have inbox relays
This commit is contained in:
@@ -36,7 +36,7 @@ pub fn set_bootstrap_relays(relays: String, app: tauri::AppHandle) -> Result<(),
|
||||
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
pub async fn collect_inbox_relays(
|
||||
pub async fn get_inbox_relays(
|
||||
user_id: String,
|
||||
state: State<'_, Nostr>,
|
||||
) -> Result<Vec<String>, String> {
|
||||
@@ -69,6 +69,27 @@ pub async fn collect_inbox_relays(
|
||||
}
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
pub async fn ensure_inbox_relays(
|
||||
user_id: String,
|
||||
state: State<'_, Nostr>,
|
||||
) -> Result<Vec<String>, String> {
|
||||
let public_key = PublicKey::parse(user_id).map_err(|e| e.to_string())?;
|
||||
let relays = state.inbox_relays.lock().await;
|
||||
|
||||
match relays.get(&public_key) {
|
||||
Some(relays) => {
|
||||
if relays.is_empty() {
|
||||
Err("404".into())
|
||||
} else {
|
||||
Ok(relays.to_owned())
|
||||
}
|
||||
}
|
||||
None => Err("404".into()),
|
||||
}
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
pub async fn set_inbox_relays(relays: Vec<String>, state: State<'_, Nostr>) -> Result<(), String> {
|
||||
|
||||
@@ -35,8 +35,9 @@ fn main() {
|
||||
let builder = Builder::<tauri::Wry>::new().commands(collect_commands![
|
||||
get_bootstrap_relays,
|
||||
set_bootstrap_relays,
|
||||
collect_inbox_relays,
|
||||
get_inbox_relays,
|
||||
set_inbox_relays,
|
||||
ensure_inbox_relays,
|
||||
connect_inbox_relays,
|
||||
disconnect_inbox_relays,
|
||||
login,
|
||||
|
||||
Reference in New Issue
Block a user