diff options
-rw-r--r-- | src/abook.rs | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/abook.rs b/src/abook.rs index b6cd59b..d7d38cd 100644 --- a/src/abook.rs +++ b/src/abook.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see <https://www.gnu.org/licenses/>. -use crate::{client::Client, error::Error}; +use crate::{client::Client, error::Error, XChan}; use serde::Deserialize; use std::convert::TryFrom; @@ -30,7 +30,10 @@ pub struct Abook { pub channel: u32, #[serde(rename = "abook_xchan")] - pub xchan: String, + pub xchan_id: String, + + #[serde(skip)] + pub xchan: XChan, #[serde(rename = "abook_my_perms")] pub my_perms: u16, @@ -142,6 +145,16 @@ impl AbookRequest { } pub async fn fetch(&self, client: &Client) -> Result<Vec<Abook>, Error> { - Ok(serde_json::from_str(&self.fetch_raw(&client).await?)?) + let json: serde_json::Value = serde_json::from_str(&self.fetch_raw(&client).await?)?; + let arr = json.as_array().ok_or("Abook: Not an array")?; + let res: Vec<Abook> = arr.iter() + .map(|v| { + let mut abook: Abook = serde_json::from_value(v.clone()).unwrap(); + abook.xchan = serde_json::from_value(v.clone()).unwrap(); + abook + }) + .collect::<_>(); + + Ok(res) } } |