1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
// zotapi - Rust wrapper for the Zot API as implemented by Hubzilla
// Copyright (C) 2023 Harald Eilertsen <haraldei@anduin.net>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// 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, XChan};
use serde::Deserialize;
use std::convert::TryFrom;
#[derive(Deserialize, Debug)]
pub struct Channel {
#[serde(alias = "channel_id")]
pub id: u32,
#[serde(alias = "channel_account_id")]
pub account_id: u32,
#[serde(alias = "channel_primary")]
pub primary: char,
#[serde(alias = "channel_name")]
pub name: String,
#[serde(alias = "channel_address")]
pub address: String,
#[serde(alias = "channel_guid")]
pub guid: String,
#[serde(alias = "channel_guid_sig")]
pub guid_sig: String,
#[serde(alias = "channel_hash")]
pub hash: String,
#[serde(alias = "channel_timezone")]
pub timezone: String,
#[serde(alias = "channel_location")]
pub location: String,
#[serde(alias = "channel_theme")]
pub theme: String,
#[serde(alias = "channel_startpage")]
pub startpage: String,
#[serde(alias = "channel_pubkey")]
pub pubkey: String,
#[serde(alias = "channel_prvkey")]
pub prvkey: String,
#[serde(alias = "channel_notifyflags")]
pub notifyflags: u32,
#[serde(alias = "channel_pageflags")]
pub pageflags: u32,
#[serde(alias = "channel_dirdate")]
pub dirdate: String,
#[serde(alias = "channel_lastpost")]
pub lastpost: String,
#[serde(alias = "channel_deleted")]
pub deleted: String,
#[serde(alias = "channel_active")]
pub active: String,
#[serde(alias = "channel_max_anon_mail")]
pub max_anon_mail: u32,
#[serde(alias = "channel_max_friend_req")]
pub max_friend_req: u32,
#[serde(alias = "channel_expire_days")]
pub expire_days: u32,
#[serde(alias = "channel_passwd_reset")]
pub passwd_reset: String,
#[serde(alias = "channel_default_group")]
pub default_group: String,
#[serde(alias = "channel_allow_cid")]
pub allow_cid: String,
#[serde(alias = "channel_allow_gid")]
pub allow_gid: String,
#[serde(alias = "channel_deny_cid")]
pub deny_cid: String,
#[serde(alias = "channel_deny_gid")]
pub deny_gid: String,
#[serde(alias = "channel_removed")]
pub removed: u32,
#[serde(alias = "channel_system")]
pub system: u32,
#[serde(alias = "channel_moved")]
pub moved: String,
#[serde(alias = "channel_password")]
pub password: String,
#[serde(alias = "channel_salt")]
pub salt: String,
#[serde(alias = "channel_portable_id")]
pub portable_id: String,
#[serde(alias = "channel_xchan", skip)]
pub xchan: XChan,
}
impl Channel {
pub fn z() -> ChannelRequest {
ChannelRequest::default()
}
}
impl<'a> TryFrom<&'a str> for Channel {
type Error = Error;
fn try_from(s: &'a str) -> Result<Self, Self::Error> {
Ok(serde_json::from_str(s)?)
}
}
#[derive(Default)]
pub struct ChannelRequest;
impl ChannelRequest {
pub async fn fetch_raw(&self, client: &Client) -> Result<String, Error> {
Ok(client.get("verify").send().await?.text().await?)
}
pub async fn fetch(&self, client: &Client) -> Result<Channel, Error> {
let raw = self.fetch_raw(&client).await?;
let mut channel: Channel = serde_json::from_str(&raw)?;
channel.xchan = serde_json::from_str(&raw)?;
Ok(channel)
}
}
|