termux_gui/components/
space.rs1use serde_json::json;
4use crate::activity::Activity;
5use crate::view::View;
6use crate::error::Result;
7
8pub struct Space {
13 view: View,
14 aid: i64,
15}
16
17impl Space {
18 pub fn new(activity: &mut Activity, parent: Option<i64>) -> Result<Self> {
20 let mut params = json!({
21 "aid": activity.id()
22 });
23
24 if let Some(parent_id) = parent {
26 params["parent"] = json!(parent_id);
27 }
28
29 let response = activity.send_read(&json!({
30 "method": "createSpace",
31 "params": params
32 }))?;
33
34 let id = response
35 .as_i64()
36 .ok_or_else(|| crate::error::GuiError::InvalidResponse("Invalid id".to_string()))?;
37
38 Ok(Space {
39 view: View::new(id),
40 aid: activity.id(),
41 })
42 }
43
44 pub fn id(&self) -> i64 {
46 self.view.id()
47 }
48
49 pub fn view(&self) -> &View {
51 &self.view
52 }
53}