qualia_client_core/api/
profile.rs1#![allow(non_snake_case)]
4
5use super::*;
6
7pub fn get_user_profile() -> Result<serde_json::Value, String> {
9 let profile = crate::user_profile::load_profile();
10 serde_json::to_value(profile).map_err(|e| e.to_string())
11}
12
13pub fn save_user_profile(profile_json: String) -> Result<serde_json::Value, String> {
15 let patch: serde_json::Value =
19 serde_json::from_str(&profile_json).map_err(|e| format!("invalid profile json: {e}"))?;
20 let base = crate::user_profile::load_profile();
21 let mut profile = crate::user_profile::apply_profile_patch(&base, &patch)?;
22 profile.public_did = crate::user_profile::resolve_public_did(&profile);
23 crate::user_profile::save_profile(&profile)?;
24 serde_json::to_value(profile).map_err(|e| e.to_string())
25}
26
27pub fn generate_connect_invite(front_door_id: Option<String>) -> Result<serde_json::Value, String> {
29 let invite = crate::social_connect::generate_connect_invite(front_door_id)?;
30 serde_json::to_value(invite).map_err(|e| e.to_string())
31}
32
33pub fn accept_connect_invite(input: String) -> Result<serde_json::Value, String> {
35 let contact = crate::social_connect::accept_connect_invite(&input)?;
36 serde_json::to_value(contact).map_err(|e| e.to_string())
37}
38
39pub fn list_chat_contacts() -> Result<serde_json::Value, String> {
41 let contacts = crate::social_connect::list_chat_contacts();
42 serde_json::to_value(contacts).map_err(|e| e.to_string())
43}
44
45pub fn list_directory() -> Result<serde_json::Value, String> {
51 let actors = get_directory_actors()?;
52 let contacts = crate::social_connect::list_chat_contacts();
53 let view = crate::directory::build_view(&actors, &contacts);
54 serde_json::to_value(view).map_err(|e| e.to_string())
55}
56
57pub fn list_directory_categories() -> Result<serde_json::Value, String> {
59 serde_json::to_value(crate::directory::list_categories()).map_err(|e| e.to_string())
60}
61
62pub fn create_directory_category(label: String) -> Result<serde_json::Value, String> {
64 let cat = crate::directory::create_category(&label)?;
65 serde_json::to_value(cat).map_err(|e| e.to_string())
66}
67
68pub fn set_directory_entry_categories(
70 did: String,
71 categories: Vec<String>,
72) -> Result<serde_json::Value, String> {
73 crate::directory::set_entry_categories(&did, categories)?;
74 list_directory()
75}
76
77pub fn search_directory(query: String, facets_json: String) -> Result<serde_json::Value, String> {
82 let selected: std::collections::BTreeMap<String, Vec<String>> = if facets_json.trim().is_empty()
83 {
84 std::collections::BTreeMap::new()
85 } else {
86 serde_json::from_str(&facets_json).map_err(|e| format!("bad facets json: {e}"))?
87 };
88 let actors = get_directory_actors()?;
89 let contacts = crate::social_connect::list_chat_contacts();
90 let result = crate::directory::search(&actors, &contacts, &query, &selected);
91 serde_json::to_value(result).map_err(|e| e.to_string())
92}