Signal for updating EmailFlags. Closes #4478

This commit is contained in:
Eric Gregory 2011-12-13 16:13:20 -08:00
parent fe099d9fb9
commit e784d1b9b3
19 changed files with 443 additions and 132 deletions

View file

@ -471,21 +471,24 @@ private class Geary.Sqlite.Folder : Geary.AbstractFolder, Geary.LocalFolder, Gea
notify_message_removed(id);
}
public override async void mark_email_async(Gee.List<Geary.EmailIdentifier> to_mark,
Geary.EmailProperties.EmailFlags flags_to_add, Geary.EmailProperties.EmailFlags
flags_to_remove, Cancellable? cancellable = null) throws Error {
// This isn't implemented yet since it was simpler to replace the flags for a message wholesale
// rather than adding and removing flags.
// Use set_email_flags_async() instead.
public override async Gee.Map<Geary.EmailIdentifier, Geary.EmailFlags> mark_email_async(
Gee.List<Geary.EmailIdentifier> to_mark, Geary.EmailFlags? flags_to_add,
Geary.EmailFlags? flags_to_remove, Cancellable? cancellable = null) throws Error {
assert_not_reached();
}
public async void set_email_flags_async(Gee.Map<Geary.EmailIdentifier,
Geary.EmailFlags> map, Cancellable? cancellable) throws Error {
check_open();
Transaction transaction = yield db.begin_transaction_async("Folder.mark_email_async",
cancellable);
Gee.List<Geary.Imap.MessageFlag> msg_flags_add = new Gee.ArrayList<Geary.Imap.MessageFlag>();
Gee.List<Geary.Imap.MessageFlag> msg_flags_remove =
new Gee.ArrayList<Geary.Imap.MessageFlag>();
Geary.Imap.MessageFlag.from_email_flags(flags_to_add, flags_to_remove, out msg_flags_add,
out msg_flags_remove);
foreach (Geary.EmailIdentifier id in to_mark) {
foreach (Geary.EmailIdentifier id in map.keys) {
MessageLocationRow? location_row = yield location_table.fetch_by_ordering_async(
transaction, folder_row.id, ((Geary.Imap.EmailIdentifier) id).uid.value, cancellable);
if (location_row == null) {
@ -493,25 +496,10 @@ private class Geary.Sqlite.Folder : Geary.AbstractFolder, Geary.LocalFolder, Gea
to_string());
}
ImapMessagePropertiesRow? row = yield imap_message_properties_table.fetch_async(
transaction, location_row.id, cancellable);
if (row == null) {
warning("Message not found in database: %lld", location_row.id);
continue;
}
// Create new set of message flags with the appropriate flags added and/or removed.
Gee.HashSet<Geary.Imap.MessageFlag> mutable_copy =
new Gee.HashSet<Geary.Imap.MessageFlag>();
mutable_copy.add_all(Geary.Imap.MessageFlags.deserialize(row.flags).get_all());
mutable_copy.remove_all(msg_flags_remove);
mutable_copy.add_all(msg_flags_add);
Geary.Imap.MessageFlags new_flags = new Geary.Imap.MessageFlags(mutable_copy);
Geary.Imap.MessageFlags flags = ((Geary.Imap.EmailFlags) map.get(id)).message_flags;
yield imap_message_properties_table.update_flags_async(transaction, location_row.id,
new_flags.serialize(), cancellable);
flags.serialize(), cancellable);
}
yield transaction.commit_async(cancellable);
@ -566,7 +554,7 @@ private class Geary.Sqlite.Folder : Geary.AbstractFolder, Geary.LocalFolder, Gea
(properties.rfc822_size != null) ? properties.rfc822_size.value : -1;
yield imap_message_properties_table.update_async(transaction, message_id,
properties.flags.serialize(), internaldate, rfc822_size, cancellable);
properties.get_message_flags().serialize(), internaldate, rfc822_size, cancellable);
}
}
}