LogsMenu2,
EgoLog,
ExitMenu,
- ExamineUser(String),
+ ExamineUser(String), // the account _id_, not its name
ListUserFollowers(String),
ListUserFollowees(String),
InfoStatus(String),
Ok(updates)
}
+
+ pub fn account_by_name(&mut self, name: &str) ->
+ Result<Account, ClientError>
+ {
+ let (url, req) = self.api_request(
+ Req::get("accounts/lookup").param("acct", name))?;
+ let rsp = req.send()?;
+ let rspstatus = rsp.status();
+ let ac: Account = 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())),
+ }
+ }?;
+ if ac.acct != name && self.fq(&ac.acct) != name {
+ return Err(ClientError::UrlError(
+ url.clone(), format!("request returned wrong account name {}",
+ &ac.acct)));
+ }
+ self.cache_account(&ac);
+ Ok(ac)
+ }
}
prompt: ColouredString,
promptwidth: usize,
ed: SingleLineEditor,
- result: Box<dyn Fn(&str) -> LogicalAction>,
+ result: Box<dyn Fn(&str, &mut Client) -> LogicalAction>,
}
impl BottomLineEditorOverlay {
- fn new(prompt: ColouredString, result: Box<dyn Fn(&str) -> LogicalAction>)
- -> Self
+ fn new(prompt: ColouredString,
+ result: Box<dyn Fn(&str, &mut Client) -> LogicalAction>) -> Self
{
let promptwidth = prompt.width();
BottomLineEditorOverlay {
(vec! { &self.prompt + buffer }, cursorpos)
}
- fn handle_keypress(&mut self, key: OurKey, _client: &mut Client) ->
+ fn handle_keypress(&mut self, key: OurKey, client: &mut Client) ->
LogicalAction
{
if self.ed.handle_keypress(key) {
- (self.result)(&self.ed.core.text)
+ (self.result)(&self.ed.core.text, client)
} else {
LogicalAction::Nothing
}
pub fn get_user_to_examine() -> Box<dyn ActivityState> {
Box::new(BottomLineEditorOverlay::new(
ColouredString::plain("Examine User: "),
- Box::new(move |s| {
+ Box::new(move |s, client| {
+ let s = s.trim();
+ let s = s.strip_prefix("@").unwrap_or(s);
if s.is_empty() {
LogicalAction::PopOverlaySilent
} else {
- LogicalAction::Goto(
- UtilityActivity::ExamineUser(s.to_owned()).into())
+ match dbg!(client.account_by_name(s)) {
+ Ok(account) => LogicalAction::Goto(
+ UtilityActivity::ExamineUser(account.id).into()),
+
+ // FIXME: it would be nice to discriminate errors
+ // better here, and maybe return anything worse
+ // than 'user not found' to the Error Log
+ Err(_) => LogicalAction::PopOverlayBeep,
+ }
}
})
))
fn extendable(&self) -> bool { true }
}
+struct SingletonSource {}
+
+impl FileDataSource for SingletonSource {
+ fn get(&self, _client: &mut Client) -> (Vec<String>, isize) {
+ (vec! { "".to_owned() }, 0)
+ }
+ fn init(&self, _client: &mut Client) -> Result<(), ClientError> { Ok(()) }
+ fn try_extend(&self, _client: &mut Client) -> Result<bool, ClientError> {
+ Ok(false)
+ }
+ fn updated(&self, _feeds_updated: &HashSet<FeedId>) -> bool { false }
+ fn extendable(&self) -> bool { false }
+}
+
trait FileType {
type Item: TextFragment + Sized;
}
}
+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,
"HHHHHHHHHHHKKKHHKHHKHHKH"))?;
Ok(Box::new(file))
}
+
+pub fn examine_user(client: &mut Client, account_id: &str) ->
+ Result<Box<dyn ActivityState>, ClientError>
+{
+ let file = File::<ExamineUserFileType, _>::new(
+ client, SingletonSource{}, ColouredString::uniform(account_id, '!'))?;
+ Ok(Box::new(file))
+}
ego_log(client),
Activity::Overlay(OverlayActivity::GetUserToExamine) =>
Ok(get_user_to_examine()),
+ Activity::Util(UtilityActivity::ExamineUser(ref name)) =>
+ examine_user(client, name),
_ => todo!(),
};