fn extendable(&self) -> bool { true }
}
-struct SingletonSource {}
+struct SingletonSource {
+ id: String,
+}
+
+impl SingletonSource {
+ fn new(id: String) -> Self { SingletonSource { id } }
+}
impl FileDataSource for SingletonSource {
fn get(&self, _client: &mut Client) -> (Vec<String>, isize) {
- (vec! { "".to_owned() }, 0)
+ (vec! { self.id.clone() }, 0)
}
fn init(&self, _client: &mut Client) -> Result<(), ClientError> { Ok(()) }
fn try_extend(&self, _client: &mut Client) -> Result<bool, ClientError> {
}
}
-struct ExamineUserFileType {}
-impl FileType for ExamineUserFileType {
- type Item = EditorHeaderSeparator; // FIXME
-
- fn get_from_client(_id: &str, _client: &mut Client) ->
- Result<Self::Item, ClientError>
- {
- Ok(EditorHeaderSeparator::new())
- }
-}
-
struct FileContents<Type: FileType, Source: FileDataSource> {
source: Source,
header: FileHeader,
Ok(Box::new(file))
}
+struct ExamineUserFileType {}
+impl FileType for ExamineUserFileType {
+ type Item = ExamineUserDisplay;
+
+ fn get_from_client(id: &str, client: &mut Client) ->
+ Result<Self::Item, ClientError>
+ {
+ let ac = client.account_by_id(id)?;
+ Ok(ExamineUserDisplay::new(ac, client)?)
+ }
+}
+
pub fn examine_user(client: &mut Client, account_id: &str) ->
Result<Box<dyn ActivityState>, ClientError>
{
+ let ac = client.account_by_id(account_id)?;
+ let username = client.fq(&ac.acct);
+ let title = ColouredString::uniform(
+ &format!("Information about user {username}"), 'H');
+
let file = File::<ExamineUserFileType, _>::new(
- client, SingletonSource{}, ColouredString::uniform(account_id, '!'))?;
+ client, SingletonSource::new(ac.id), title)?;
Ok(Box::new(file))
}
use unicode_width::UnicodeWidthStr;
use super::html;
-use super::client::Client;
+use super::client::{Client, ClientError};
use super::types::*;
use super::tui::OurKey;
use super::coloured_string::{ColouredString, ColouredStringSlice};
lines
}
}
+
+pub struct ExamineUserDisplay {
+ name: Paragraph,
+}
+
+impl ExamineUserDisplay {
+ pub fn new(ac: Account, client: &mut Client) -> Result<Self, ClientError> {
+ let name = Paragraph::new()
+ .add(&ColouredString::plain("Account name: "))
+ .add(&ColouredString::uniform(&client.fq(&ac.acct), 'f'));
+
+ Ok(ExamineUserDisplay {
+ name,
+ })
+ }
+}
+
+impl TextFragment for ExamineUserDisplay {
+ fn render(&self, width: usize) -> Vec<ColouredString> {
+ let mut lines = Vec::new();
+
+ push_fragment(&mut lines, self.name.render(width));
+
+ lines
+ }
+}