feat: ensure user have inbox relays

This commit is contained in:
2024-09-18 13:19:28 +07:00
parent 768b78b530
commit 0ff3c7c76f
21 changed files with 1315 additions and 1155 deletions

View File

@@ -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> {

View File

@@ -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,