Browse Source

ui: add set as read/unread, delete actions

Implemented only in compact listing for now.
tags/pre-alpha-0.0
Manos Pitsidianakis 2 years ago
parent
commit
8c97336307
Signed by untrusted user: epilys GPG Key ID: 73627C2F690DF710
  1. 5
      melib/src/email.rs
  2. 57
      ui/src/components/mail/listing/compact.rs
  3. 19
      ui/src/execute.rs
  4. 3
      ui/src/execute/actions.rs

5
melib/src/email.rs

@ -771,8 +771,8 @@ impl Envelope {
self.timestamp = new_val.timestamp() as UnixTimestamp;
}
pub fn set_flag(&mut self, f: Flag, mut operation: Box<BackendOp>) -> Result<()> {
self.flags.toggle(f);
operation.set_flag(self, f)?;
self.flags |= f;
Ok(())
}
pub fn flags(&self) -> Flag {
@ -781,6 +781,9 @@ impl Envelope {
pub fn set_seen(&mut self, operation: Box<BackendOp>) -> Result<()> {
self.set_flag(Flag::SEEN, operation)
}
pub fn set_unseen(&mut self, operation: Box<BackendOp>) -> Result<()> {
self.set_flag(Flag::SEEN, operation)
}
pub fn is_seen(&self) -> bool {
self.flags.contains(Flag::SEEN)
}

57
ui/src/components/mail/listing/compact.rs

@ -1145,6 +1145,63 @@ impl Component for CompactListing {
self.filter(filter_term, context);
self.dirty = true;
}
Action::Listing(a @ SetRead)
| Action::Listing(a @ SetUnread)
| Action::Listing(a @ Delete) => {
let account = &mut context.accounts[self.cursor_pos.0];
let folder_hash = account[self.cursor_pos.1]
.as_ref()
.map(|m| m.folder.hash())
.unwrap();
let threads = &account.collection.threads[&folder_hash];
let i = if self.filtered_selection.is_empty() {
let thread_node = threads.root_set(self.cursor_pos.2);
let thread_node = &threads.thread_nodes()[&thread_node];
if let Some(i) = thread_node.message() {
i
} else {
let mut iter_ptr = thread_node.children()[0];
while threads.thread_nodes()[&iter_ptr].message().is_none() {
iter_ptr = threads.thread_nodes()[&iter_ptr].children()[0];
}
threads.thread_nodes()[&iter_ptr].message().unwrap()
}
} else {
self.filtered_selection[self.cursor_pos.2]
};
if !account.contains_key(i) {
/* The envelope has been renamed or removed, so wait for the appropriate event to
* arrive */
return true;
}
match a {
SetRead => {
let (hash, is_seen) = {
let envelope: &Envelope = &account.get_env(&i);
(envelope.hash(), envelope.is_seen())
};
if !is_seen {
let op = account.operation(hash);
let envelope: &mut Envelope = &mut account.get_env_mut(&i);
envelope.set_seen(op).unwrap();
}
}
SetUnread => {
let (hash, is_seen) = {
let envelope: &Envelope = &account.get_env(&i);
(envelope.hash(), envelope.is_seen())
};
if is_seen {
let op = account.operation(hash);
let envelope: &mut Envelope = &mut account.get_env_mut(&i);
envelope.set_unseen(op).unwrap();
}
}
Delete => { /* do nothing */ }
_ => unreachable!(),
}
}
_ => {}
},
UIEvent::Input(Key::Esc) => {

19
ui/src/execute.rs

@ -90,6 +90,10 @@ named!(
toggle<Action>,
preceded!(tag!("set "), alt_complete!(threaded | plain | compact))
);
named!(
listing_action<Action>,
alt_complete!(toggle | envelope_action | filter | toggle_thread_snooze)
);
named!(
toggle_thread_snooze<Action>,
@ -118,6 +122,19 @@ named!(
)
);
named!(
envelope_action<Action>,
alt_complete!(
preceded!(
ws!(tag!("set")),
alt_complete!(
map!(ws!(tag!("read")), |_| Listing(SetRead))
| map!(ws!(tag!("unread")), |_| Listing(SetUnread))
)
) | map!(ws!(tag!("delete")), |_| Listing(Delete))
)
);
named!(pub parse_command<Action>,
alt_complete!( goto | toggle | sort | subsort | close | toggle_thread_snooze | mailinglist |filter)
alt_complete!( goto | listing_action | sort | subsort | close | mailinglist)
);

3
ui/src/execute/actions.rs

@ -37,6 +37,9 @@ pub enum ListingAction {
SetThreaded,
SetCompact,
Filter(String),
SetRead,
SetUnread,
Delete,
}
#[derive(Debug)]

Loading…
Cancel
Save