statuses: HashMap<String, Status>,
notifications: HashMap<String, Notification>,
feeds: HashMap<FeedId, Feed>,
+ instance: Option<Instance>,
permit_write: bool,
}
statuses: HashMap::new(),
notifications: HashMap::new(),
feeds: HashMap::new(),
+ instance: None,
permit_write: false,
})
}
self.api_request_cl(&self.client, req)
}
- pub fn cache_account(&mut self, ac: &Account) {
+ pub fn instance(&mut self) -> Result<Instance, ClientError> {
+ if let Some(ref inst) = self.instance {
+ return Ok(inst.clone());
+ }
+
+ let (url, req) = self.api_request(Req::get("instance"))?;
+ let rsp = req.send()?;
+ let rspstatus = rsp.status();
+ let inst: Instance = if !rspstatus.is_success() {
+ Err(ClientError::UrlError(url.clone(), rspstatus.to_string()))
+ } else {
+ match serde_json::from_str(&rsp.text()?) {
+ Ok(ac) => Ok(ac),
+ Err(e) => Err(ClientError::UrlError(
+ url.clone(), e.to_string())),
+ }
+ }?;
+ self.instance = Some(inst.clone());
+ Ok(inst)
+ }
+
+ fn cache_account(&mut self, ac: &Account) {
self.accounts.insert(ac.id.to_string(), ac.clone());
}
- pub fn cache_status(&mut self, st: &Status) {
+ fn cache_status(&mut self, st: &Status) {
self.cache_account(&st.account);
self.statuses.insert(st.id.to_string(), st.clone());
}
- pub fn cache_notification(&mut self, n: &Notification) {
+ fn cache_notification(&mut self, n: &Notification) {
self.cache_account(&n.account);
if let Some(st) = &n.status {
self.cache_status(&st);
pub endorsed: bool,
pub note: String,
}
+
+#[derive(Deserialize, Debug, Clone)]
+pub struct InstanceStatusConfig {
+ pub max_characters: usize,
+ pub max_media_attachments: usize,
+ pub characters_reserved_per_url: usize,
+}
+
+#[derive(Deserialize, Debug, Clone)]
+pub struct InstanceConfig {
+ pub statuses: InstanceStatusConfig,
+}
+
+#[derive(Deserialize, Debug, Clone)]
+pub struct Instance {
+ // At least one major live instance (hachyderm.io) uses the key
+ // "uri" for its instance domain. But the Mastodon test instance
+ // uses "domain". Bah.
+ #[serde(alias="uri")] pub domain: Option<String>,
+
+ pub configuration: InstanceConfig,
+
+ // FIXME: lots of things are missing from here!
+}