Skip to content

Commit f3d59eb

Browse files
committed
accounts: add force: bool arg to load()
Sometimes watch futures from backends send refresh events for mailboxes that have not been fetched yet. That'd trigger fetching them in the background, which is bad when the mailboxes are big and not wanted by the user in the first place. This commit adds a force parameter that specifies whether the loading must be forced (e.g. when wanting to display the mailbox) or not. Signed-off-by: Manos Pitsidianakis <[email protected]>
1 parent a83b417 commit f3d59eb

File tree

6 files changed

+7
-7
lines changed

6 files changed

+7
-7
lines changed

meli/src/accounts.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,7 @@ impl Account {
896896
self.hash
897897
}
898898

899-
pub fn load(&mut self, mailbox_hash: MailboxHash) -> result::Result<(), usize> {
899+
pub fn load(&mut self, mailbox_hash: MailboxHash, force: bool) -> result::Result<(), usize> {
900900
if mailbox_hash.is_null() {
901901
return Err(0);
902902
}
@@ -912,7 +912,7 @@ impl Account {
912912
Ok(())
913913
}
914914
MailboxStatus::None => {
915-
if !self.active_jobs.values().any(|j| j.is_fetch(mailbox_hash)) {
915+
if force && !self.active_jobs.values().any(|j| j.is_fetch(mailbox_hash)) {
916916
let mailbox_job = self.backend.write().unwrap().fetch(mailbox_hash);
917917
match mailbox_job {
918918
Ok(mailbox_job) => {

meli/src/mail/listing/compact.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ impl MailListingTrait for CompactListing {
227227

228228
// Get mailbox as a reference.
229229
//
230-
match context.accounts[&self.cursor_pos.0].load(self.cursor_pos.1) {
230+
match context.accounts[&self.cursor_pos.0].load(self.cursor_pos.1, true) {
231231
Ok(()) => {}
232232
Err(_) => {
233233
self.length = 0;

meli/src/mail/listing/conversations.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ impl MailListingTrait for ConversationsListing {
198198

199199
// Get mailbox as a reference.
200200
//
201-
match context.accounts[&self.cursor_pos.0].load(self.cursor_pos.1) {
201+
match context.accounts[&self.cursor_pos.0].load(self.cursor_pos.1, true) {
202202
Ok(()) => {}
203203
Err(_) => {
204204
let message: String =

meli/src/mail/listing/plain.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ impl MailListingTrait for PlainListing {
211211

212212
// Get mailbox as a reference.
213213
//
214-
match context.accounts[&self.cursor_pos.0].load(self.cursor_pos.1) {
214+
match context.accounts[&self.cursor_pos.0].load(self.cursor_pos.1, true) {
215215
Ok(()) => {}
216216
Err(_) => {
217217
self.length = 0;

meli/src/mail/listing/thread.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ impl MailListingTrait for ThreadListing {
212212

213213
// Get mailbox as a reference.
214214
//
215-
match context.accounts[&self.cursor_pos.0].load(self.cursor_pos.1) {
215+
match context.accounts[&self.cursor_pos.0].load(self.cursor_pos.1, true) {
216216
Ok(_) => {}
217217
Err(_) => {
218218
self.length = 0;

meli/src/state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ impl State {
510510
.contains_key(&mailbox_hash)
511511
{
512512
if self.context.accounts[&account_hash]
513-
.load(mailbox_hash)
513+
.load(mailbox_hash, false)
514514
.is_err()
515515
{
516516
self.context.replies.push_back(UIEvent::from(event));

0 commit comments

Comments
 (0)