impl<Type: FileType, Source: FileDataSource> FileContents<Type,Source> {
fn update_items(&mut self, client: &mut Client) {
// FIXME: if the feed has been extended rather than created,
- // we should be able to make less effort than this
+ // we should be able to make less effort than this. But we
+ // still need to regenerate any item derived from something we
+ // _know_ has changed on the server side - in particular, a
+ // post we just changed fave/boost status on.
let (ids, origin) = self.source.get(client);
self.origin = origin;
enum SelectionPurpose {
ExamineUser,
StatusInfo,
+ Favourite,
+ Boost,
}
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
last_size: Option<(usize, usize)>,
ui_mode: UIMode,
selection: Option<(isize, usize)>,
+ select_aux: Option<bool>, // distinguishes fave from unfave, etc
}
impl<Type: FileType, Source: FileDataSource> File<Type, Source> {
last_size: None,
ui_mode: UIMode::Normal,
selection: None,
+ select_aux: None,
};
Ok(ff)
}
}
fn start_selection(&mut self, htype: HighlightType,
- purpose: SelectionPurpose) -> LogicalAction
+ purpose: SelectionPurpose, client: &mut Client)
+ -> LogicalAction
{
let item = self.pos.item();
let selection =
if selection.is_some() {
self.ui_mode = UIMode::Select(htype, purpose);
- self.change_selection_to(selection, false);
+ self.change_selection_to(selection, false, client);
LogicalAction::Nothing
} else {
LogicalAction::Beep
}
fn change_selection_to(&mut self, new_selection: Option<(isize, usize)>,
- none_ok: bool) -> LogicalAction
+ none_ok: bool, client: &mut Client) -> LogicalAction
{
let result = if new_selection.is_some() {
self.rerender_selected_item();
}
};
+ self.select_aux = match self.ui_mode {
+ UIMode::Select(_, SelectionPurpose::Favourite) => {
+ match self.selected_id(self.selection) {
+ Some(id) => {
+ match client.status_by_id(&id) {
+ Ok(st) => Some(st.favourited == Some(true)),
+ Err(_) => Some(false),
+ }
+ },
+ None => Some(false),
+ }
+ },
+ UIMode::Select(_, SelectionPurpose::Boost) => {
+ match self.selected_id(self.selection) {
+ Some(id) => {
+ match client.status_by_id(&id) {
+ Ok(st) => Some(st.reblogged == Some(true)),
+ Err(_) => Some(false),
+ }
+ },
+ None => Some(false),
+ }
+ },
+ _ => None,
+ };
+
result
}
- fn selection_up(&mut self) -> LogicalAction {
+ fn selection_up(&mut self, client: &mut Client) -> LogicalAction {
let htype = match self.ui_mode {
UIMode::Select(htype, _purpose) => htype,
_ => return LogicalAction::Beep,
}
};
- self.change_selection_to(new_selection, false)
+ self.change_selection_to(new_selection, false, client)
}
- fn selection_down(&mut self) -> LogicalAction {
+ fn selection_down(&mut self, client: &mut Client) -> LogicalAction {
let htype = match self.ui_mode {
UIMode::Select(htype, _purpose) => htype,
_ => return LogicalAction::Beep,
}
};
- self.change_selection_to(new_selection, false)
+ self.change_selection_to(new_selection, false, client)
}
fn end_selection(&mut self) {
}
}
- fn complete_selection(&mut self) -> LogicalAction {
+ fn complete_selection(&mut self, client: &mut Client, alt: bool)
+ -> LogicalAction
+ {
let (_htype, purpose) = match self.ui_mode {
UIMode::Select(htype, purpose) => (htype, purpose),
_ => return LogicalAction::Beep,
};
+ match purpose {
+ SelectionPurpose::Favourite | SelectionPurpose::Boost => {
+ // alt means unfave; select_aux = Some(already faved?)
+ if self.select_aux == Some(!alt) {
+ return LogicalAction::Nothing;
+ }
+ }
+ _ => (),
+ }
+
let result = if let Some(id) = self.selected_id(self.selection) {
match purpose {
SelectionPurpose::ExamineUser => LogicalAction::Goto(
UtilityActivity::ExamineUser(id).into()),
SelectionPurpose::StatusInfo => LogicalAction::Goto(
UtilityActivity::InfoStatus(id).into()),
+ SelectionPurpose::Favourite => {
+ match client.favourite_post(&id, !alt) {
+ Ok(_) => {
+ self.contents.update_items(client);
+ LogicalAction::Nothing
+ }
+ Err(_) => LogicalAction::Beep,
+ }
+ }
+ SelectionPurpose::Boost => {
+ match client.boost_post(&id, !alt) {
+ Ok(_) => {
+ self.contents.update_items(client);
+ LogicalAction::Nothing
+ }
+ Err(_) => LogicalAction::Beep,
+ }
+ }
}
} else {
LogicalAction::Beep
fs.add(Space, "Examine", 98),
SelectionPurpose::StatusInfo =>
fs.add(Space, "Info", 98),
+ SelectionPurpose::Favourite => {
+ if self.select_aux == Some(true) {
+ fs.add(Pr('D'), "Unfave", 98)
+ } else {
+ fs.add(Space, "Fave", 98)
+ }
+ }
+ SelectionPurpose::Boost => {
+ if self.select_aux == Some(true) {
+ fs.add(Pr('D'), "Unboost", 98)
+ } else {
+ fs.add(Space, "Boost", 98)
+ }
+ }
};
fs.add(Pr('+'), "Down", 99)
.add(Pr('-'), "Up", 99)
Pr('e') | Pr('E') => {
if Type::Item::can_highlight(HighlightType::User) {
self.start_selection(HighlightType::User,
- SelectionPurpose::ExamineUser)
+ SelectionPurpose::ExamineUser,
+ client)
} else {
LogicalAction::Nothing
}
Pr('i') | Pr('I') => {
if Type::Item::can_highlight(HighlightType::Status) {
self.start_selection(HighlightType::Status,
- SelectionPurpose::StatusInfo)
+ SelectionPurpose::StatusInfo,
+ client)
+ } else {
+ LogicalAction::Nothing
+ }
+ }
+
+ Pr('f') | Pr('F') => {
+ if Type::Item::can_highlight(HighlightType::WholeStatus) {
+ self.start_selection(HighlightType::WholeStatus,
+ SelectionPurpose::Favourite,
+ client)
+ } else {
+ LogicalAction::Nothing
+ }
+ }
+
+ Ctrl('B') => {
+ if Type::Item::can_highlight(HighlightType::WholeStatus) {
+ self.start_selection(HighlightType::WholeStatus,
+ SelectionPurpose::Boost,
+ client)
} else {
LogicalAction::Nothing
}
_ => LogicalAction::Nothing,
}
- UIMode::Select(..) => match key {
- Space => self.complete_selection(),
- Pr('-') | Up => self.selection_up(),
- Pr('+') | Down => self.selection_down(),
+ UIMode::Select(_, purpose) => match key {
+ Space => self.complete_selection(client, false),
+ Pr('d') | Pr('D') => match purpose {
+ SelectionPurpose::Favourite | SelectionPurpose::Boost =>
+ self.complete_selection(client, true),
+ _ => LogicalAction::Nothing,
+ }
+ Pr('-') | Up => self.selection_up(client),
+ Pr('+') | Down => self.selection_down(client),
Pr('q') | Pr('Q') => self.abort_selection(),
_ => LogicalAction::Nothing,
}