Ok(ac)
}
+ pub fn account_relationship_by_id(&mut self, id: &str) ->
+ Result<Relationship, ClientError>
+ {
+ let (url, req) = self.api_request(
+ Req::get("accounts/relationships").param("id", id))?;
+ let rsp = req.send()?;
+ let rspstatus = rsp.status();
+ let rels: Vec<Relationship> = if !rspstatus.is_success() {
+ Err(ClientError::UrlError(url.clone(), rspstatus.to_string()))
+ } else {
+ match serde_json::from_str(dbg!(&rsp.text()?)) {
+ Ok(ac) => Ok(ac),
+ Err(e) => Err(ClientError::UrlError(
+ url.clone(), e.to_string())),
+ }
+ }?;
+ for rel in rels {
+ if rel.id == id {
+ return Ok(rel);
+ }
+ }
+ Err(ClientError::UrlError(
+ url.clone(), format!(
+ "request did not return expected account id {}", id)))
+ }
+
pub fn status_by_id(&mut self, id: &str) -> Result<Status, ClientError> {
if let Some(st) = self.statuses.get(id) {
let mut st = st.clone();
post_count: Paragraph,
followers_count: Paragraph,
following_count: Paragraph,
+ relationships: Vec<Paragraph>,
blank: BlankLine,
}
.add(&ColouredString::plain(
&format!("Number of users followed: {}", ac.following_count)));
+ let mut relationships = Vec::new();
+ if ac.id == client.our_account_id() {
+ relationships.push(Paragraph::new().set_indent(2, 2).add(
+ &ColouredString::general("You are this user!",
+ " ___ ")));
+ }
+ match client.account_relationship_by_id(&ac.id) {
+ Ok(rs) => {
+ if rs.following && rs.showing_reblogs {
+ relationships.push(Paragraph::new().set_indent(2, 2).add(
+ &ColouredString::uniform(
+ "You follow this user.", 'f')));
+ } else if rs.following {
+ relationships.push(Paragraph::new().set_indent(2, 2).add(
+ &ColouredString::uniform(
+ "You follow this user (but without boosts).",
+ 'f')));
+ }
+ if rs.followed_by {
+ relationships.push(Paragraph::new().set_indent(2, 2).add(
+ &ColouredString::uniform(
+ "This user follows you.", 'f')));
+ }
+ if rs.requested {
+ relationships.push(Paragraph::new().set_indent(2, 2).add(
+ &ColouredString::uniform(
+ "This user has requested to follow you!", 'F')));
+ }
+ if rs.notifying {
+ relationships.push(Paragraph::new().set_indent(2, 2).add(
+ &ColouredString::plain(
+ "You have enabled notifications for this user.")));
+ }
+ if rs.blocking {
+ relationships.push(Paragraph::new().set_indent(2, 2).add(
+ &ColouredString::uniform(
+ "You have blocked this user.", 'r')));
+ }
+ if rs.blocked_by {
+ relationships.push(Paragraph::new().set_indent(2, 2).add(
+ &ColouredString::uniform(
+ "This user has blocked you.", 'r')));
+ }
+ if rs.muting {
+ relationships.push(Paragraph::new().set_indent(2, 2).add(
+ &ColouredString::uniform(
+ "You have muted this user.", 'r')));
+ }
+ if rs.muting_notifications {
+ relationships.push(Paragraph::new().set_indent(2, 2).add(
+ &ColouredString::uniform(
+ "You have muted notifications from this user.",
+ 'r')));
+ }
+ if rs.domain_blocking {
+ relationships.push(Paragraph::new().set_indent(2, 2).add(
+ &ColouredString::uniform(
+ "You have blocked this user's domain.",
+ 'r')));
+ }
+ }
+ Err(e) => relationships.push(Paragraph::new().set_indent(2, 2).add(
+ &ColouredString::uniform(
+ &format!("Unable to retrieve relationships: {}", e),
+ '!'))),
+ }
+ if relationships.len() > 0 {
+ relationships.insert(0, Paragraph::new().add(
+ &ColouredString::plain("Relationships to this user:")));
+ }
+
Ok(ExamineUserDisplay {
name,
webaccount,
post_count,
followers_count,
following_count,
+ relationships,
blank: BlankLine::new(),
})
}
push_fragment(&mut lines, self.blank.render(width));
}
- // FIXME: relationships list
+ // FIXME: flags
+
+ if !self.relationships.is_empty() {
+ for para in &self.relationships {
+ push_fragment(&mut lines, para.render(width));
+ }
+ push_fragment(&mut lines, self.blank.render(width));
+ }
push_fragment(&mut lines, self.id.render(width));
push_fragment(&mut lines, self.creation.render(width));