collection: add update_flags() method

On NewFlags events, the threads in Collection were not being updated, so
if an envelope's seen status was toggled the thread's unseen count was
  not updated, and thus not reflected in the UI even though the
  envelope's new flags event was registered properly.
memfd
Manos Pitsidianakis 2020-06-23 12:27:10 +03:00
parent cac21a279b
commit eca1921a8a
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
2 changed files with 39 additions and 0 deletions

View File

@ -351,6 +351,43 @@ impl Collection {
}
}
pub fn update_flags(&mut self, env_hash: EnvelopeHash, mailbox_hash: MailboxHash) {
if self
.sent_mailbox
.map(|f| f == mailbox_hash)
.unwrap_or(false)
{
for (_, t) in self.threads.iter_mut() {
t.update_envelope(&self.envelopes, env_hash, env_hash)
.unwrap_or(());
}
}
{
if self
.threads
.entry(mailbox_hash)
.or_default()
.update_envelope(&self.envelopes, env_hash, env_hash)
.is_ok()
{
return;
}
}
/* envelope is not in threads, so insert it */
self.threads
.entry(mailbox_hash)
.or_default()
.insert(&mut self.envelopes, env_hash);
for (h, t) in self.threads.iter_mut() {
if *h == mailbox_hash {
continue;
}
t.update_envelope(&self.envelopes, env_hash, env_hash)
.ok()
.take();
}
}
pub fn insert(&mut self, envelope: Envelope, mailbox_hash: MailboxHash) -> bool {
let hash = envelope.hash();
if self.message_ids.contains_key(envelope.message_id().raw()) {

View File

@ -530,6 +530,8 @@ impl Account {
);
}
}
drop(envelopes);
self.collection.update_flags(env_hash, mailbox_hash);
return Some(EnvelopeUpdate(env_hash));
}
RefreshEventKind::Rename(old_hash, new_hash) => {