}
fn cache_account(&mut self, ac: &Account) {
- self.accounts.insert(ac.id.to_string(), ac.clone());
+ let mut ac = ac.clone();
+ // Don't overwrite a cached account with a 'source' to one
+ // without.
+ if !ac.source.is_some() {
+ if let Some(source) = self.accounts.get(&ac.id)
+ .and_then(|ac| ac.source.as_ref())
+ {
+ ac.source = Some(source.clone());
+ }
+ }
+ self.accounts.insert(ac.id.to_string(), ac);
}
fn cache_status(&mut self, st: &Status) {
}
pub fn account_by_id(&mut self, id: &str) -> Result<Account, ClientError> {
- if let Some(st) = self.accounts.get(id) {
- return Ok(st.clone());
+ // If we're fetching our own account, we do it via the
+ // verify_credentials request, which gets the extra
+ // information. This also means we must repeat the request if
+ // we've already received a copy of our own account details
+ // via some other API and it doesn't contain the extra
+ // information.
+
+ if let Some(ac) = self.accounts.get(id) {
+ if ac.id != self.auth.account_id || ac.source.is_some() {
+ return Ok(ac.clone());
+ }
}
- let (url, rsp) = self.api_request(Req::get(
- &("v1/accounts/".to_owned() + id)))?;
+ let req = if id == self.auth.account_id {
+ Req::get(&format!("v1/accounts/verify_credentials"))
+ } else {
+ Req::get(&format!("v1/accounts/{id}"))
+ };
+ let (url, rsp) = self.api_request(req)?;
let rspstatus = rsp.status();
let ac: Account = if !rspstatus.is_success() {
Err(ClientError::UrlError(url.clone(), rspstatus.to_string()))
pub statuses_count: u64,
pub followers_count: u64,
pub following_count: u64,
+
+ // In the wire protocol, 'CredentialAccount' is a subclass of
+ // 'Account' containing this extra field, only available from some
+ // requests, and only for your own account. We regard it as an
+ // optional field of Account in general.
+ pub source: Option<AccountSourceDetails>,
+}
+
+#[derive(Deserialize, Debug, Clone)]
+pub struct AccountSourceDetails {
+ pub privacy: Visibility,
+ pub sensitive: bool,
+ pub language: Option<String>,
+ pub follow_requests_count: usize,
+ pub hide_collections: Option<bool>,
+ pub discoverable: Option<bool>,
+ pub indexable: Option<bool>,
+ // 'fields' and 'note' here differ from the ones in the main
+ // Account in that the bio, and the 'value' of each field, are in
+ // the source text form rather than renderable HTML.
+ pub note: String,
+ pub fields: Vec<AccountField>,
}
#[derive(Deserialize, Debug, Clone)]