diff options
author | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2019-12-08 10:57:36 +0200 |
---|---|---|
committer | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2019-12-08 11:25:54 +0200 |
commit | 0eaf17871a79278d56bac0ba83cdae85f8e5ce03 (patch) | |
tree | 3aebf024a8bce3079eb915316437272bc6751b8f /ui/src/components/mail/listing.rs | |
parent | f632bc4c08b7a9d4630b34c446863f2126716316 (diff) |
melib: add set_tags command in BackendOp
Diffstat (limited to 'ui/src/components/mail/listing.rs')
-rw-r--r-- | ui/src/components/mail/listing.rs | 45 |
1 files changed, 15 insertions, 30 deletions
diff --git a/ui/src/components/mail/listing.rs b/ui/src/components/mail/listing.rs index ad53231a..4b737087 100644 --- a/ui/src/components/mail/listing.rs +++ b/ui/src/components/mail/listing.rs @@ -105,42 +105,27 @@ pub trait MailListingTrait: ListingTrait { continue; } ListingAction::Tag(Remove(ref tag_str)) => { - use std::collections::hash_map::DefaultHasher; - use std::hash::Hasher; - let h = { - let mut hasher = DefaultHasher::new(); - hasher.write(tag_str.as_bytes()); - hasher.finish() - }; let backend_lck = account.backend.write().unwrap(); - if let Some(t) = backend_lck.tags() { - let mut tags_lck = t.write().unwrap(); - if !tags_lck.contains_key(&h) { - tags_lck.insert(h, tag_str.to_string()); - } - if let Some(pos) = envelope.labels().iter().position(|&el| el == h) { - envelope.labels_mut().remove(pos); - } - } else { + let mut op = backend_lck.operation(envelope.hash()); + if let Err(err) = op.set_tag(&mut envelope, tag_str.to_string(), false) { + context.replies.push_back(UIEvent::Notification( + Some("Could not set tag.".to_string()), + err.to_string(), + Some(NotificationType::ERROR), + )); return; } } ListingAction::Tag(Add(ref tag_str)) => { - use std::collections::hash_map::DefaultHasher; - use std::hash::Hasher; - let h = { - let mut hasher = DefaultHasher::new(); - hasher.write(tag_str.as_bytes()); - hasher.finish() - }; let backend_lck = account.backend.write().unwrap(); - if let Some(t) = backend_lck.tags() { - let mut tags_lck = t.write().unwrap(); - if !tags_lck.contains_key(&h) { - tags_lck.insert(h, tag_str.to_string()); - } - envelope.labels_mut().push(h); - } else { + let mut op = backend_lck.operation(envelope.hash()); + + if let Err(err) = op.set_tag(&mut envelope, tag_str.to_string(), true) { + context.replies.push_back(UIEvent::Notification( + Some("Could not set tag.".to_string()), + err.to_string(), + Some(NotificationType::ERROR), + )); return; } } |