summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManos Pitsidianakis <el13635@mail.ntua.gr>2019-06-06 00:27:40 +0300
committerManos Pitsidianakis <el13635@mail.ntua.gr>2019-06-10 19:40:51 +0300
commitb6c0236d24a6252aad0e6f14b5a5f41052ed854d (patch)
treef14408b0c2fd4a52539f89808da2248085b952ec
parent85d1aaaa69f4b37343998088f89f306c83af117f (diff)
ui: make EnvelopeRename event not folder specific
And pass EnvelopeRename events to subviews
-rw-r--r--ui/src/components/mail/listing/compact.rs9
-rw-r--r--ui/src/components/mail/view.rs32
-rw-r--r--ui/src/components/mail/view/thread.rs21
-rw-r--r--ui/src/conf/accounts.rs2
-rw-r--r--ui/src/types.rs2
5 files changed, 36 insertions, 30 deletions
diff --git a/ui/src/components/mail/listing/compact.rs b/ui/src/components/mail/listing/compact.rs
index d43a08d3..dad12fde 100644
--- a/ui/src/components/mail/listing/compact.rs
+++ b/ui/src/components/mail/listing/compact.rs
@@ -646,10 +646,7 @@ impl Component for MailboxView {
self.refresh_mailbox(context);
self.set_dirty();
}
- UIEvent::EnvelopeRename(ref folder_hash, ref old_hash, ref new_hash)
- if *folder_hash
- == context.accounts[self.cursor_pos.0].folders_order[self.new_cursor_pos.1] =>
- {
+ UIEvent::EnvelopeRename(ref old_hash, ref new_hash) => {
if let Some(row) = self.order.remove(old_hash) {
self.order.insert(*new_hash, row);
self.highlight_line(None, ((0, row), (MAX_COLS - 1, row)), row, context);
@@ -658,6 +655,8 @@ impl Component for MailboxView {
} else {
/* Listing has was updated in time before the event */
}
+ self.view
+ .process_event(&mut UIEvent::EnvelopeRename(*old_hash, *new_hash), context);
}
UIEvent::ChangeMode(UIMode::Normal) => {
self.dirty = true;
@@ -872,7 +871,7 @@ impl Component for CompactListing {
| UIEvent::ComponentKill(_)
| UIEvent::StartupCheck(_)
| UIEvent::EnvelopeUpdate(_)
- | UIEvent::EnvelopeRename(_, _, _)
+ | UIEvent::EnvelopeRename(_, _)
| UIEvent::EnvelopeRemove(_) => {
return self.views[self.cursor].process_event(event, context)
}
diff --git a/ui/src/components/mail/view.rs b/ui/src/components/mail/view.rs
index 461586a7..c787aae0 100644
--- a/ui/src/components/mail/view.rs
+++ b/ui/src/components/mail/view.rs
@@ -88,23 +88,6 @@ impl MailView {
subview: Option<Box<Component>>,
context: &mut Context,
) -> Self {
- let account = &mut context.accounts[coordinates.0];
- let (hash, is_seen) = {
- let envelope: &Envelope = &account.get_env(&coordinates.2);
- (envelope.hash(), envelope.is_seen())
- };
- if !is_seen {
- let folder_hash = {
- let mailbox = &mut account[coordinates.1].as_mut().unwrap();
- mailbox.folder.hash()
- };
- let op = {
- let backend = &account.backend;
- backend.operation(hash, folder_hash)
- };
- let envelope: &mut Envelope = &mut account.get_env_mut(&coordinates.2);
- envelope.set_seen(op).unwrap();
- }
MailView {
coordinates,
pager,
@@ -304,6 +287,19 @@ impl Component for MailView {
* arrive */
return;
}
+ let (hash, is_seen) = {
+ let envelope: &Envelope = &account.get_env(&self.coordinates.2);
+ (envelope.hash(), envelope.is_seen())
+ };
+ if !is_seen {
+ let folder_hash = {
+ let mailbox = &mut account[self.coordinates.1].as_mut().unwrap();
+ mailbox.folder.hash()
+ };
+ let op = account.operation(&hash);
+ let envelope: &mut Envelope = &mut account.get_env_mut(&self.coordinates.2);
+ envelope.set_seen(op).unwrap();
+ }
let envelope: &Envelope = &account.get_env(&self.coordinates.2);
if self.mode == ViewMode::Raw {
@@ -746,7 +742,7 @@ impl Component for MailView {
}
self.dirty = true;
}
- UIEvent::EnvelopeRename(_, old_hash, new_hash) if old_hash == self.coordinates.2 => {
+ UIEvent::EnvelopeRename(old_hash, new_hash) => {
self.coordinates.2 = new_hash;
}
_ => {
diff --git a/ui/src/components/mail/view/thread.rs b/ui/src/components/mail/view/thread.rs
index 4b8be368..7b1fca8c 100644
--- a/ui/src/components/mail/view/thread.rs
+++ b/ui/src/components/mail/view/thread.rs
@@ -291,8 +291,7 @@ impl ThreadView {
/* Box character drawing stuff */
let mut x = 0;
for i in 0..e.index.0 {
- let color =
- INDENTATION_COLORS[(i).wrapping_rem(INDENTATION_COLORS.len())];
+ let color = INDENTATION_COLORS[(i).wrapping_rem(INDENTATION_COLORS.len())];
change_colors(
&mut content,
((x, 2 * y), (x + 3, 2 * y + 1)),
@@ -408,6 +407,7 @@ impl ThreadView {
/// draw the list
fn draw_list(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) {
+ /* Make space on the left for the scrollbar */
let mut upper_left = pos_inc(upper_left!(area), (1, 0));
let bottom_right = bottom_right!(area);
let (width, height) = self.content.size();
@@ -613,9 +613,11 @@ impl ThreadView {
let i = if let Some(i) = thread_node.message() {
i
} else {
- threads.thread_nodes()[&thread_node.children()[0]]
- .message()
- .unwrap()
+ 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()
};
let envelope: &Envelope = account.get_env(&i);
@@ -1013,6 +1015,15 @@ impl Component for ThreadView {
UIEvent::Resize => {
self.set_dirty();
}
+ UIEvent::EnvelopeRename(ref old_hash, ref new_hash) => {
+ for e in self.entries.iter_mut() {
+ if e.msg_hash == *old_hash {
+ e.msg_hash = *new_hash;
+ }
+ }
+ self.mailview
+ .process_event(&mut UIEvent::EnvelopeRename(*old_hash, *new_hash), context);
+ }
_ => {
if self.mailview.process_event(event, context) {
return true;
diff --git a/ui/src/conf/accounts.rs b/ui/src/conf/accounts.rs
index 83d64ec0..8d6a2b2c 100644
--- a/ui/src/conf/accounts.rs
+++ b/ui/src/conf/accounts.rs
@@ -314,7 +314,7 @@ impl Account {
let mailbox = mailbox!(&folder_hash, self.folders);
mailbox.rename(old_hash, new_hash);
self.collection.rename(old_hash, new_hash, folder_hash);
- return Some(EnvelopeRename(mailbox.folder.hash(), old_hash, new_hash));
+ return Some(EnvelopeRename(old_hash, new_hash));
}
RefreshEventKind::Create(envelope) => {
let env_hash = envelope.hash();
diff --git a/ui/src/types.rs b/ui/src/types.rs
index b1a6c431..75413e42 100644
--- a/ui/src/types.rs
+++ b/ui/src/types.rs
@@ -87,7 +87,7 @@ pub enum UIEvent {
StartupCheck(FolderHash),
RefreshEvent(Box<RefreshEvent>),
EnvelopeUpdate(EnvelopeHash),
- EnvelopeRename(FolderHash, EnvelopeHash, EnvelopeHash), // folder_hash, old_hash, new_hash
+ EnvelopeRename(EnvelopeHash, EnvelopeHash), // old_hash, new_hash
EnvelopeRemove(EnvelopeHash),
}