Skip to content

Commit

Permalink
Fix empty folder/no matching search UI not showing up.
Browse files Browse the repository at this point in the history
This fixes a regression introduced by commit 0ea1fe6.

* src/engine/app/app-conversation-monitor.vala (ConversationMonitor):
  Signal scan_complete from the same method call that we signal
  scan_started, so that a) we know it will get fired, even if no messages
  are loaded (the issue introduced by 0ea1fe6) and b) so we can get rid
  of the inside_scan complexity.
  • Loading branch information
mjog committed Jul 8, 2018
1 parent b2bc4e3 commit 4cc7cf1
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 18 deletions.
44 changes: 26 additions & 18 deletions src/engine/app/app-conversation-monitor.vala
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ public class Geary.App.ConversationMonitor : BaseObject {
Geary.Email.Field.FLAGS | Geary.Email.Field.DATE;


private class ProcessJobContext : BaseObject {
public Gee.HashMap<Geary.EmailIdentifier, Geary.Email> emails
= new Gee.HashMap<Geary.EmailIdentifier, Geary.Email>();
private struct ProcessJobContext {

public bool inside_scan;
public Gee.Map<Geary.EmailIdentifier,Geary.Email> emails;

public ProcessJobContext(bool inside_scan) {
this.inside_scan = inside_scan;

public ProcessJobContext() {
this.emails = new Gee.HashMap<Geary.EmailIdentifier,Geary.Email>();
}

}


Expand Down Expand Up @@ -402,6 +402,7 @@ public class Geary.App.ConversationMonitor : BaseObject {
}

int load_count = 0;
GLib.Error? scan_error = null;
try {
Gee.Collection<Geary.Email>? messages =
yield this.base_folder.list_email_by_id_async(
Expand All @@ -416,12 +417,16 @@ public class Geary.App.ConversationMonitor : BaseObject {
this.window.add(email.id);
}

yield process_email_async(messages, new ProcessJobContext(true));
yield process_email_async(messages, ProcessJobContext());
}
} catch (GLib.Error err) {
scan_error = err;
}

} catch (Error err) {
notify_scan_completed();
throw err;
notify_scan_completed();

if (scan_error != null) {
throw scan_error;
}

return load_count;
Expand All @@ -437,6 +442,7 @@ public class Geary.App.ConversationMonitor : BaseObject {
flags |= Folder.ListFlags.LOCAL_ONLY;
}

GLib.Error? scan_error = null;
try {
Gee.Collection<Geary.Email>? messages =
yield this.base_folder.list_email_by_sparse_id_async(
Expand All @@ -448,11 +454,16 @@ public class Geary.App.ConversationMonitor : BaseObject {
this.window.add(email.id);
}

yield process_email_async(messages, new ProcessJobContext(true));
yield process_email_async(messages, ProcessJobContext());
}
} catch (Error err) {
notify_scan_completed();
throw err;
} catch (GLib.Error err) {
scan_error = err;
}

notify_scan_completed();

if (scan_error != null) {
throw scan_error;
}
}

Expand Down Expand Up @@ -524,7 +535,7 @@ public class Geary.App.ConversationMonitor : BaseObject {

if (emails != null && !emails.is_empty) {
debug("Fetched %d relevant emails locally", emails.size);
yield process_email_async(emails, new ProcessJobContext(false));
yield process_email_async(emails, ProcessJobContext());
}
}

Expand Down Expand Up @@ -727,9 +738,6 @@ public class Geary.App.ConversationMonitor : BaseObject {
foreach (Conversation conversation in appended.get_keys())
notify_conversation_appended(conversation, appended.get(conversation));
}

if (job.inside_scan)
notify_scan_completed();
}

private async void expand_conversations_async(Gee.Set<RFC822.MessageID> needed_message_ids,
Expand Down
13 changes: 13 additions & 0 deletions test/engine/app/app-conversation-monitor-test.vala
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ class Geary.App.ConversationMonitorTest : TestCase {
);
Cancellable test_cancellable = new Cancellable();

bool saw_scan_started = false;
bool saw_scan_completed = false;
monitor.scan_started.connect(() => { saw_scan_started = true; });
monitor.scan_completed.connect(() => { saw_scan_completed = true; });

this.base_folder.expect_call(
"open_async",
{ MockObject.int_arg(Folder.OpenFlags.NONE), test_cancellable }
Expand All @@ -68,11 +73,19 @@ class Geary.App.ConversationMonitorTest : TestCase {
);
monitor.start_monitoring_async.end(async_result());

// Process all of the async tasks arising from the open
while (this.main_loop.pending()) {
this.main_loop.iteration(true);
}

monitor.stop_monitoring_async.begin(
test_cancellable, (obj, res) => { async_complete(res); }
);
monitor.stop_monitoring_async.end(async_result());

assert_true(saw_scan_started, "scan_started not fired");
assert_true(saw_scan_completed, "scan_completed not fired");

this.base_folder.assert_expectations();
}

Expand Down

0 comments on commit 4cc7cf1

Please sign in to comment.