summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorManos Pitsidianakis <el13635@mail.ntua.gr>2020-01-18 05:21:41 +0200
committerManos Pitsidianakis <el13635@mail.ntua.gr>2020-01-20 16:03:29 +0200
commit63ff25b36ae87b0c4f901d8adfb8a62a83212f83 (patch)
treef90b7cd1e9eaab31b393e8faa58b360f38af7191 /ui
parente07b5faf6edabf5e6455805b70884aef75ba7157 (diff)
ui/listings: add folder_hash field
No reason not to have it stored and discover it whenever it's needed.
Diffstat (limited to 'ui')
-rw-r--r--ui/src/components/mail/listing/compact.rs55
-rw-r--r--ui/src/components/mail/listing/conversations.rs60
-rw-r--r--ui/src/components/mail/listing/plain.rs44
-rw-r--r--ui/src/components/mail/listing/thread.rs23
4 files changed, 60 insertions, 122 deletions
diff --git a/ui/src/components/mail/listing/compact.rs b/ui/src/components/mail/listing/compact.rs
index 7825320a..9c5ea6d3 100644
--- a/ui/src/components/mail/listing/compact.rs
+++ b/ui/src/components/mail/listing/compact.rs
@@ -51,6 +51,7 @@ pub struct CompactListing {
/// (x, y, z): x is accounts, y is folders, z is index inside a folder.
cursor_pos: (usize, usize, usize),
new_cursor_pos: (usize, usize, usize),
+ folder_hash: FolderHash,
length: usize,
sort: (SortField, SortOrder),
subsort: (SortField, SortOrder),
@@ -121,8 +122,7 @@ impl ListingTrait for CompactListing {
let thread_hash = self.get_thread_under_cursor(idx, context);
let account = &context.accounts[self.cursor_pos.0];
- let folder_hash = account[self.cursor_pos.1].unwrap().folder.hash();
- let threads = &account.collection.threads[&folder_hash];
+ let threads = &account.collection.threads[&self.folder_hash];
let thread = threads.thread_ref(thread_hash);
let fg_color = if thread.unseen() > 0 {
@@ -432,19 +432,15 @@ impl ListingTrait for CompactListing {
}
let account = &context.accounts[self.cursor_pos.0];
- let folder_hash = account[self.cursor_pos.1].unwrap().folder.hash();
- match account.search(&self.filter_term, self.sort, folder_hash) {
+ match account.search(&self.filter_term, self.sort, self.folder_hash) {
Ok(results) => {
- let threads = &account.collection.threads[&folder_hash];
+ let threads = &account.collection.threads[&self.folder_hash];
for env_hash in results {
if !account.collection.contains_key(&env_hash) {
continue;
}
let env_thread_node_hash = account.collection.get_env(env_hash).thread();
- if !threads
- .thread_nodes
- .contains_key(&env_thread_node_hash)
- {
+ if !threads.thread_nodes.contains_key(&env_thread_node_hash) {
continue;
}
let thread =
@@ -526,6 +522,7 @@ impl CompactListing {
CompactListing {
cursor_pos: (0, 1, 0),
new_cursor_pos: (0, 0, 0),
+ folder_hash: 0,
length: 0,
sort: (Default::default(), Default::default()),
subsort: (SortField::Date, SortOrder::Desc),
@@ -554,11 +551,7 @@ impl CompactListing {
hash: ThreadHash,
) -> EntryStrings {
let thread = threads.thread_ref(hash);
- let folder_hash = &context.accounts[self.cursor_pos.0][self.cursor_pos.1]
- .unwrap()
- .folder
- .hash();
- let folder = &context.accounts[self.cursor_pos.0].folder_confs[&folder_hash];
+ let folder = &context.accounts[self.cursor_pos.0].folder_confs[&self.folder_hash];
let mut tags = String::new();
let mut colors: SmallVec<[_; 8]> = SmallVec::new();
let backend_lck = context.accounts[self.cursor_pos.0].backend.read().unwrap();
@@ -635,7 +628,7 @@ impl CompactListing {
}
self.cursor_pos.1 = self.new_cursor_pos.1;
self.cursor_pos.0 = self.new_cursor_pos.0;
- let folder_hash = if let Some(h) = context.accounts[self.cursor_pos.0]
+ self.folder_hash = if let Some(h) = context.accounts[self.cursor_pos.0]
.folders_order
.get(self.cursor_pos.1)
{
@@ -648,10 +641,11 @@ impl CompactListing {
// Get mailbox as a reference.
//
- match context.accounts[self.cursor_pos.0].status(folder_hash) {
+ match context.accounts[self.cursor_pos.0].status(self.folder_hash) {
Ok(()) => {}
Err(_) => {
- let message: String = context.accounts[self.cursor_pos.0][folder_hash].to_string();
+ let message: String =
+ context.accounts[self.cursor_pos.0][self.folder_hash].to_string();
self.data_columns.columns[0] =
CellBuffer::new_with_context(message.len(), 1, Cell::with_char(' '), context);
self.length = 0;
@@ -668,7 +662,7 @@ impl CompactListing {
}
}
- let threads = &context.accounts[self.cursor_pos.0].collection.threads[&folder_hash];
+ let threads = &context.accounts[self.cursor_pos.0].collection.threads[&self.folder_hash];
self.all_threads.clear();
let mut roots = threads.roots();
threads.group_inner_sort_by(
@@ -961,8 +955,6 @@ impl CompactListing {
}
fn get_thread_under_cursor(&self, cursor: usize, context: &Context) -> ThreadHash {
- //let account = &context.accounts[self.cursor_pos.0];
- //let folder_hash = account[self.cursor_pos.1].unwrap().folder.hash();
if self.filter_term.is_empty() {
*self
.order
@@ -980,8 +972,7 @@ impl CompactListing {
fn update_line(&mut self, context: &Context, thread_hash: ThreadHash) {
let account = &context.accounts[self.cursor_pos.0];
- let folder_hash = account[self.cursor_pos.1].unwrap().folder.hash();
- let threads = &account.collection.threads[&folder_hash];
+ let threads = &account.collection.threads[&self.folder_hash];
let thread = threads.thread_ref(thread_hash);
let thread_node_hash = threads.thread_group_iter(thread_hash).next().unwrap().1;
if let Some(env_hash) = threads.thread_nodes()[&thread_node_hash].message() {
@@ -1266,11 +1257,10 @@ impl Component for CompactListing {
Action::ToggleThreadSnooze if !self.unfocused => {
let thread = self.get_thread_under_cursor(self.cursor_pos.2, context);
let account = &mut context.accounts[self.cursor_pos.0];
- let folder_hash = account[self.cursor_pos.1].unwrap().folder.hash();
account
.collection
.threads
- .entry(folder_hash)
+ .entry(self.folder_hash)
.and_modify(|threads| {
let is_snoozed = threads.thread_ref(thread).snoozed();
threads.thread_ref_mut(thread).set_snoozed(!is_snoozed);
@@ -1288,29 +1278,18 @@ impl Component for CompactListing {
}
match *event {
UIEvent::MailboxUpdate((ref idxa, ref idxf))
- if context.accounts[self.new_cursor_pos.0]
- .folders_order
- .get(self.new_cursor_pos.1)
- .map(|&folder_hash| (*idxa, *idxf) == (self.new_cursor_pos.0, folder_hash))
- .unwrap_or(false) =>
+ if (*idxa, *idxf) == (self.new_cursor_pos.0, self.folder_hash) =>
{
self.refresh_mailbox(context);
self.set_dirty(true);
}
- UIEvent::StartupCheck(ref f)
- if context.accounts[self.new_cursor_pos.0]
- .folders_order
- .get(self.new_cursor_pos.1)
- .map(|&folder_hash| *f == folder_hash)
- .unwrap_or(false) =>
- {
+ UIEvent::StartupCheck(ref f) if *f == self.folder_hash => {
self.refresh_mailbox(context);
self.set_dirty(true);
}
UIEvent::EnvelopeRename(ref old_hash, ref new_hash) => {
let account = &context.accounts[self.cursor_pos.0];
- let folder_hash = account[self.cursor_pos.1].unwrap().folder.hash();
- let threads = &account.collection.threads[&folder_hash];
+ let threads = &account.collection.threads[&self.folder_hash];
if !account.collection.contains_key(&new_hash) {
return false;
}
diff --git a/ui/src/components/mail/listing/conversations.rs b/ui/src/components/mail/listing/conversations.rs
index c9c7cc8d..36aa5bd3 100644
--- a/ui/src/components/mail/listing/conversations.rs
+++ b/ui/src/components/mail/listing/conversations.rs
@@ -82,6 +82,7 @@ pub struct ConversationsListing {
/// (x, y, z): x is accounts, y is folders, z is index inside a folder.
cursor_pos: (usize, usize, usize),
new_cursor_pos: (usize, usize, usize),
+ folder_hash: FolderHash,
length: usize,
sort: (SortField, SortOrder),
subsort: (SortField, SortOrder),
@@ -152,8 +153,7 @@ impl ListingTrait for ConversationsListing {
let thread_hash = self.get_thread_under_cursor(idx, context);
let account = &context.accounts[self.cursor_pos.0];
- let folder_hash = account[self.cursor_pos.1].unwrap().folder.hash();
- let threads = &account.collection.threads[&folder_hash];
+ let threads = &account.collection.threads[&self.folder_hash];
let thread = threads.thread_ref(thread_hash);
let fg_color = if thread.unseen() > 0 {
@@ -404,10 +404,9 @@ impl ListingTrait for ConversationsListing {
}
let account = &context.accounts[self.cursor_pos.0];
- let folder_hash = account[self.cursor_pos.1].unwrap().folder.hash();
- match account.search(&self.filter_term, self.sort, folder_hash) {
+ match account.search(&self.filter_term, self.sort, self.folder_hash) {
Ok(results) => {
- let threads = &account.collection.threads[&folder_hash];
+ let threads = &account.collection.threads[&self.folder_hash];
for env_hash in results {
if !account.collection.contains_key(&env_hash) {
continue;
@@ -495,6 +494,7 @@ impl ConversationsListing {
ConversationsListing {
cursor_pos: (0, 1, 0),
new_cursor_pos: (0, 0, 0),
+ folder_hash: 0,
length: 0,
sort: (Default::default(), Default::default()),
subsort: (SortField::Date, SortOrder::Desc),
@@ -524,11 +524,7 @@ impl ConversationsListing {
hash: ThreadHash,
) -> EntryStrings {
let thread = threads.thread_ref(hash);
- let folder_hash = &context.accounts[self.cursor_pos.0][self.cursor_pos.1]
- .unwrap()
- .folder
- .hash();
- let folder = &context.accounts[self.cursor_pos.0].folder_confs[&folder_hash];
+ let folder = &context.accounts[self.cursor_pos.0].folder_confs[&self.folder_hash];
let mut tags = String::new();
let mut colors = SmallVec::new();
let backend_lck = context.accounts[self.cursor_pos.0].backend.read().unwrap();
@@ -605,7 +601,7 @@ impl ConversationsListing {
}
self.cursor_pos.1 = self.new_cursor_pos.1;
self.cursor_pos.0 = self.new_cursor_pos.0;
- let folder_hash = if let Some(h) = context.accounts[self.cursor_pos.0]
+ self.folder_hash = if let Some(h) = context.accounts[self.cursor_pos.0]
.folders_order
.get(self.cursor_pos.1)
{
@@ -618,10 +614,11 @@ impl ConversationsListing {
// Get mailbox as a reference.
//
- match context.accounts[self.cursor_pos.0].status(folder_hash) {
+ match context.accounts[self.cursor_pos.0].status(self.folder_hash) {
Ok(()) => {}
Err(_) => {
- let message: String = context.accounts[self.cursor_pos.0][folder_hash].to_string();
+ let message: String =
+ context.accounts[self.cursor_pos.0][self.folder_hash].to_string();
self.content =
CellBuffer::new_with_context(message.len(), 1, Cell::with_char(' '), context);
self.length = 0;
@@ -638,7 +635,7 @@ impl ConversationsListing {
}
}
- let threads = &context.accounts[self.cursor_pos.0].collection.threads[&folder_hash];
+ let threads = &context.accounts[self.cursor_pos.0].collection.threads[&self.folder_hash];
self.all_threads.clear();
let mut roots = threads.roots();
threads.group_inner_sort_by(
@@ -898,9 +895,6 @@ impl ConversationsListing {
}
fn get_thread_under_cursor(&self, cursor: usize, context: &Context) -> ThreadHash {
- //let account = &context.accounts[self.cursor_pos.0];
- //let folder_hash = account[self.cursor_pos.1].unwrap().folder.hash();
- //let threads = &account.collection.threads[&folder_hash];
if self.filter_term.is_empty() {
*self
.order
@@ -919,8 +913,7 @@ impl ConversationsListing {
fn update_line(&mut self, context: &Context, thread_hash: ThreadHash) {
let account = &context.accounts[self.cursor_pos.0];
- let folder_hash = account[self.cursor_pos.1].unwrap().folder.hash();
- let threads = &account.collection.threads[&folder_hash];
+ let threads = &account.collection.threads[&self.folder_hash];
let thread = threads.thread_ref(thread_hash);
let thread_node_hash = threads.thread_group_iter(thread_hash).next().unwrap().1;
let idx: usize = self.order[&thread_hash];
@@ -1202,8 +1195,7 @@ impl Component for ConversationsListing {
}
UIEvent::EnvelopeRename(ref old_hash, ref new_hash) => {
let account = &context.accounts[self.cursor_pos.0];
- let folder_hash = account[self.cursor_pos.1].unwrap().folder.hash();
- let threads = &account.collection.threads[&folder_hash];
+ let threads = &account.collection.threads[&self.folder_hash];
if !account.collection.contains_key(&new_hash) {
return false;
}
@@ -1228,7 +1220,7 @@ impl Component for ConversationsListing {
self.subsort = (*field, *order);
// FIXME subsort
//if !self.filtered_selection.is_empty() {
- // let threads = &account.collection.threads[&folder_hash];
+ // let threads = &account.collection.threads[&self.folder_hash];
// threads.vec_inner_sort_by(&mut self.filtered_selection, self.sort, &account.collection);
//} else {
// self.refresh_mailbox(context);
@@ -1241,13 +1233,8 @@ impl Component for ConversationsListing {
/*
self.sort = (*field, *order);
if !self.filtered_selection.is_empty() {
- let folder_hash = context.accounts[self.cursor_pos.0]
- [self.cursor_pos.1]
- .unwrap()
- .folder
- .hash();
let threads = &context.accounts[self.cursor_pos.0].collection.threads
- [&folder_hash];
+ [&self.folder_hash];
threads.vec_inner_sort_by(
&mut self.filtered_selection,
self.sort,
@@ -1263,11 +1250,10 @@ impl Component for ConversationsListing {
Action::ToggleThreadSnooze if !self.unfocused => {
let thread = self.get_thread_under_cursor(self.cursor_pos.2, context);
let account = &mut context.accounts[self.cursor_pos.0];
- let folder_hash = account[self.cursor_pos.1].unwrap().folder.hash();
account
.collection
.threads
- .entry(folder_hash)
+ .entry(self.folder_hash)
.and_modify(|threads| {
let is_snoozed = threads.thread_ref(thread).snoozed();
threads.thread_ref_mut(thread).set_snoozed(!is_snoozed);
@@ -1283,22 +1269,12 @@ impl Component for ConversationsListing {
}
match *event {
UIEvent::MailboxUpdate((ref idxa, ref idxf))
- if context.accounts[self.new_cursor_pos.0]
- .folders_order
- .get(self.new_cursor_pos.1)
- .map(|&folder_hash| (*idxa, *idxf) == (self.new_cursor_pos.0, folder_hash))
- .unwrap_or(false) =>
+ if (*idxa, *idxf) == (self.new_cursor_pos.0, self.folder_hash) =>
{
self.refresh_mailbox(context);
self.set_dirty(true);
}
- UIEvent::StartupCheck(ref f)
- if context.accounts[self.new_cursor_pos.0]
- .folders_order
- .get(self.new_cursor_pos.1)
- .map(|&folder_hash| *f == folder_hash)
- .unwrap_or(false) =>
- {
+ UIEvent::StartupCheck(ref f) if *f == self.folder_hash => {
self.refresh_mailbox(context);
self.set_dirty(true);
}
diff --git a/ui/src/components/mail/listing/plain.rs b/ui/src/components/mail/listing/plain.rs
index 060e093f..d1572cb2 100644
--- a/ui/src/components/mail/listing/plain.rs
+++ b/ui/src/components/mail/listing/plain.rs
@@ -50,6 +50,7 @@ pub struct PlainListing {
/// (x, y, z): x is accounts, y is folders, z is index inside a folder.
cursor_pos: (usize, usize, usize),
new_cursor_pos: (usize, usize, usize),
+ folder_hash: FolderHash,
length: usize,
sort: (SortField, SortOrder),
subsort: (SortField, SortOrder),
@@ -401,8 +402,7 @@ impl ListingTrait for PlainListing {
}
let account = &context.accounts[self.cursor_pos.0];
- let folder_hash = account[self.cursor_pos.1].unwrap().folder.hash();
- match account.search(&self.filter_term, self.sort, folder_hash) {
+ match account.search(&self.filter_term, self.sort, self.folder_hash) {
Ok(results) => {
for env_hash in results {
if !account.collection.contains_key(&env_hash) {
@@ -476,6 +476,7 @@ impl PlainListing {
PlainListing {
cursor_pos: (0, 1, 0),
new_cursor_pos: (0, 0, 0),
+ folder_hash: 0,
length: 0,
sort: (Default::default(), Default::default()),
subsort: (SortField::Date, SortOrder::Desc),
@@ -500,11 +501,7 @@ impl PlainListing {
}
}
fn make_entry_string(&self, e: EnvelopeRef, context: &Context) -> EntryStrings {
- let folder_hash = &context.accounts[self.cursor_pos.0][self.cursor_pos.1]
- .unwrap()
- .folder
- .hash();
- let folder = &context.accounts[self.cursor_pos.0].folder_confs[&folder_hash];
+ let folder = &context.accounts[self.cursor_pos.0].folder_confs[&self.folder_hash];
let mut tags = String::new();
let mut colors = SmallVec::new();
let backend_lck = context.accounts[self.cursor_pos.0].backend.read().unwrap();
@@ -563,7 +560,7 @@ impl PlainListing {
}
self.cursor_pos.1 = self.new_cursor_pos.1;
self.cursor_pos.0 = self.new_cursor_pos.0;
- let folder_hash = if let Some(h) = context.accounts[self.cursor_pos.0]
+ self.folder_hash = if let Some(h) = context.accounts[self.cursor_pos.0]
.folders_order
.get(self.cursor_pos.1)
{
@@ -576,10 +573,11 @@ impl PlainListing {
// Get mailbox as a reference.
//
- match context.accounts[self.cursor_pos.0].status(folder_hash) {
+ match context.accounts[self.cursor_pos.0].status(self.folder_hash) {
Ok(()) => {}
Err(_) => {
- let message: String = context.accounts[self.cursor_pos.0][folder_hash].to_string();
+ let message: String =
+ context.accounts[self.cursor_pos.0][self.folder_hash].to_string();
self.data_columns.columns[0] =
CellBuffer::new_with_context(message.len(), 1, Cell::with_char(' '), context);
self.length = 0;
@@ -595,7 +593,7 @@ impl PlainListing {
return;
}
}
- self.local_collection = context.accounts[self.cursor_pos.0][folder_hash]
+ self.local_collection = context.accounts[self.cursor_pos.0][self.folder_hash]
.unwrap()
.envelopes
.iter()
@@ -606,7 +604,7 @@ impl PlainListing {
.envelopes
.read()
.unwrap();
- self.thread_node_hashes = context.accounts[self.cursor_pos.0][folder_hash]
+ self.thread_node_hashes = context.accounts[self.cursor_pos.0][self.folder_hash]
.unwrap()
.envelopes
.iter()
@@ -1056,7 +1054,7 @@ impl Component for PlainListing {
debug!("SubSort {:?} , {:?}", field, order);
self.subsort = (*field, *order);
//if !self.filtered_selection.is_empty() {
- // let threads = &account.collection.threads[&folder_hash];
+ // let threads = &account.collection.threads[&self.folder_hash];
// threads.vec_inner_sort_by(&mut self.filtered_selection, self.sort, &account.collection);
//} else {
// self.refresh_mailbox(context);
@@ -1107,30 +1105,22 @@ impl Component for PlainListing {
}
match *event {
UIEvent::MailboxUpdate((ref idxa, ref idxf))
- if context.accounts[self.new_cursor_pos.0]
- .folders_order
- .get(self.new_cursor_pos.1)
- .map(|&folder_hash| (*idxa, *idxf) == (self.new_cursor_pos.0, folder_hash))
- .unwrap_or(false) =>
+ if (*idxa, *idxf) == (self.new_cursor_pos.0, self.folder_hash) =>
{
self.refresh_mailbox(context);
self.set_dirty(true);
}
- UIEvent::StartupCheck(ref f)
- if context.accounts[self.new_cursor_pos.0]
- .folders_order
- .get(self.new_cursor_pos.1)
- .map(|&folder_hash| *f == folder_hash)
- .unwrap_or(false) =>
- {
+ UIEvent::StartupCheck(ref f) if *f == self.folder_hash => {
self.refresh_mailbox(context);
self.set_dirty(true);
}
UIEvent::EnvelopeRename(ref old_hash, ref new_hash) => {
let account = &context.accounts[self.cursor_pos.0];
- let folder_hash = account[self.cursor_pos.1].unwrap().folder.hash();
if !account.collection.contains_key(new_hash)
- || !account[folder_hash].unwrap().envelopes.contains(new_hash)
+ || !account[self.folder_hash]
+ .unwrap()
+ .envelopes
+ .contains(new_hash)
{
return false;
}
diff --git a/ui/src/components/mail/listing/thread.rs b/ui/src/components/mail/listing/thread.rs
index 2cd52d93..f5e0ee16 100644
--- a/ui/src/components/mail/listing/thread.rs
+++ b/ui/src/components/mail/listing/thread.rs
@@ -31,6 +31,7 @@ pub struct ThreadListing {
/// (x, y, z): x is accounts, y is folders, z is index inside a folder.
cursor_pos: (usize, usize, usize),
new_cursor_pos: (usize, usize, usize),
+ folder_hash: FolderHash,
length: usize,
sort: (SortField, SortOrder),
subsort: (SortField, SortOrder),
@@ -238,6 +239,7 @@ impl ThreadListing {
ThreadListing {
cursor_pos: (0, 1, 0),
new_cursor_pos: (0, 0, 0),
+ folder_hash: 0,
length: 0,
sort: (Default::default(), Default::default()),
subsort: (Default::default(), Default::default()),
@@ -264,7 +266,7 @@ impl ThreadListing {
}
self.cursor_pos.1 = self.new_cursor_pos.1;
self.cursor_pos.0 = self.new_cursor_pos.0;
- let folder_hash = if let Some(h) = context.accounts[self.cursor_pos.0]
+ self.folder_hash = if let Some(h) = context.accounts[self.cursor_pos.0]
.folders_order
.get(self.cursor_pos.1)
{
@@ -275,10 +277,11 @@ impl ThreadListing {
// Get mailbox as a reference.
//
- match context.accounts[self.cursor_pos.0].status(folder_hash) {
+ match context.accounts[self.cursor_pos.0].status(self.folder_hash) {
Ok(_) => {}
Err(_) => {
- let message: String = context.accounts[self.cursor_pos.0][folder_hash].to_string();
+ let message: String =
+ context.accounts[self.cursor_pos.0][self.folder_hash].to_string();
self.content = CellBuffer::new(message.len(), 1, Cell::with_char(' '));
self.length = 0;
write_string_to_grid(
@@ -619,22 +622,12 @@ impl Component for ThreadListing {
return true;
}
UIEvent::MailboxUpdate((ref idxa, ref idxf))
- if context.accounts[self.new_cursor_pos.0]
- .folders_order
- .get(self.new_cursor_pos.1)
- .map(|&folder_hash| (*idxa, *idxf) == (self.new_cursor_pos.0, folder_hash))
- .unwrap_or(false) =>
+ if (*idxa, *idxf) == (self.new_cursor_pos.0, self.folder_hash) =>
{
self.refresh_mailbox(context);
self.set_dirty(true);
}
- UIEvent::StartupCheck(ref f)
- if context.accounts[self.new_cursor_pos.0]
- .folders_order
- .get(self.new_cursor_pos.1)
- .map(|&folder_hash| *f == folder_hash)
- .unwrap_or(false) =>
- {
+ UIEvent::StartupCheck(ref f) if *f == self.folder_hash => {
self.refresh_mailbox(context);
self.set_dirty(true);
}