ui: fix wrong subscription status in folders
Subscription status was checked/modified in various places, whereas now the universal truth is the `BackendFolder::is_subscribed()` method set by the backend when a folder is created. The `Account` struct passes a closure to the backend constructor that determines whether the folder is subscribed or not according to the user configuration. - If subscribed_folders field is empty, then all folders are subscribed. - OR check explicit folder configuration - OR check if folder path matches to a glob in subscribed_folders.async
parent
9616fbb544
commit
0b4109dfdb
59
src/conf.rs
59
src/conf.rs
|
@ -51,7 +51,6 @@ use self::notifications::NotificationsSettings;
|
|||
use self::terminal::TerminalSettings;
|
||||
use crate::pager::PagerSettings;
|
||||
use crate::plugins::Plugin;
|
||||
use melib::backends::SpecialUsageMailbox;
|
||||
use melib::conf::{AccountSettings, FolderConf, ToggleFlag};
|
||||
use melib::error::*;
|
||||
|
||||
|
@ -115,6 +114,7 @@ pub struct FileAccount {
|
|||
|
||||
#[serde(default = "false_val")]
|
||||
read_only: bool,
|
||||
#[serde(default)]
|
||||
subscribed_folders: Vec<String>,
|
||||
#[serde(default)]
|
||||
folders: HashMap<String, FileFolderConf>,
|
||||
|
@ -141,7 +141,7 @@ impl From<FileAccount> for AccountConf {
|
|||
.map(|(k, v)| (k.clone(), v.folder_conf.clone()))
|
||||
.collect();
|
||||
|
||||
let mut acc = AccountSettings {
|
||||
let acc = AccountSettings {
|
||||
name: String::new(),
|
||||
root_folder,
|
||||
format,
|
||||
|
@ -154,60 +154,7 @@ impl From<FileAccount> for AccountConf {
|
|||
extra: x.extra.clone(),
|
||||
};
|
||||
|
||||
let root_path = PathBuf::from(acc.root_folder.as_str());
|
||||
let root_tmp = root_path
|
||||
.components()
|
||||
.last()
|
||||
.and_then(|c| c.as_os_str().to_str())
|
||||
.unwrap_or("")
|
||||
.to_string();
|
||||
if !acc.subscribed_folders.contains(&root_tmp) {
|
||||
acc.subscribed_folders.push(root_tmp);
|
||||
}
|
||||
let mut folder_confs = x.folders.clone();
|
||||
for s in &x.subscribed_folders {
|
||||
if !folder_confs.contains_key(s) {
|
||||
use melib::text_processing::GlobMatch;
|
||||
if s.is_glob() {
|
||||
continue;
|
||||
}
|
||||
folder_confs.insert(
|
||||
s.to_string(),
|
||||
FileFolderConf {
|
||||
folder_conf: FolderConf {
|
||||
subscribe: ToggleFlag::True,
|
||||
..FolderConf::default()
|
||||
},
|
||||
..FileFolderConf::default()
|
||||
},
|
||||
);
|
||||
} else {
|
||||
if !folder_confs[s].folder_conf().subscribe.is_unset() {
|
||||
continue;
|
||||
}
|
||||
folder_confs.get_mut(s).unwrap().folder_conf.subscribe = ToggleFlag::True;
|
||||
}
|
||||
|
||||
if folder_confs[s].folder_conf().usage.is_none() {
|
||||
let name = s
|
||||
.split(if s.contains('/') { '/' } else { '.' })
|
||||
.last()
|
||||
.unwrap_or("");
|
||||
folder_confs.get_mut(s).unwrap().folder_conf.usage =
|
||||
SpecialUsageMailbox::detect_usage(name);
|
||||
}
|
||||
|
||||
if folder_confs[s].folder_conf().ignore.is_unset() {
|
||||
use SpecialUsageMailbox::*;
|
||||
if [Junk, Sent, Trash]
|
||||
.contains(&folder_confs[s].folder_conf().usage.as_ref().unwrap())
|
||||
{
|
||||
folder_confs.get_mut(s).unwrap().folder_conf.ignore =
|
||||
ToggleFlag::InternalVal(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let folder_confs = x.folders.clone();
|
||||
AccountConf {
|
||||
account: acc,
|
||||
conf: x,
|
||||
|
|
|
@ -254,8 +254,9 @@ impl Account {
|
|||
let backend = map.get(settings.account().format())(
|
||||
settings.account(),
|
||||
Box::new(move |path: &str| {
|
||||
(s.folder_confs.contains_key(path)
|
||||
&& s.folder_confs[path].folder_conf().subscribe.is_true())
|
||||
s.account.subscribed_folders.is_empty()
|
||||
|| (s.folder_confs.contains_key(path)
|
||||
&& s.folder_confs[path].folder_conf().subscribe.is_true())
|
||||
|| s.account
|
||||
.subscribed_folders
|
||||
.iter()
|
||||
|
@ -328,22 +329,6 @@ impl Account {
|
|||
|
||||
let mut sent_folder = None;
|
||||
for f in ref_folders.values_mut() {
|
||||
if !((self.settings.folder_confs.contains_key(f.path())
|
||||
&& self.settings.folder_confs[f.path()]
|
||||
.folder_conf()
|
||||
.subscribe
|
||||
.is_true())
|
||||
|| self
|
||||
.settings
|
||||
.account
|
||||
.subscribed_folders
|
||||
.iter()
|
||||
.any(|m| f.path().matches_glob(m)))
|
||||
{
|
||||
/* Skip unsubscribed folder */
|
||||
continue;
|
||||
}
|
||||
|
||||
if let Some(conf) = self.settings.folder_confs.get_mut(f.path()) {
|
||||
conf.folder_conf.usage = if f.special_usage() != SpecialUsageMailbox::Normal {
|
||||
Some(f.special_usage())
|
||||
|
@ -368,7 +353,6 @@ impl Account {
|
|||
folder_confs.insert(f.hash(), conf.clone());
|
||||
} else {
|
||||
let mut new = FileFolderConf::default();
|
||||
new.folder_conf.subscribe = super::ToggleFlag::InternalVal(true);
|
||||
new.folder_conf.usage = if f.special_usage() != SpecialUsageMailbox::Normal {
|
||||
Some(f.special_usage())
|
||||
} else {
|
||||
|
@ -387,8 +371,10 @@ impl Account {
|
|||
let mut tree: Vec<FolderNode> = Vec::new();
|
||||
let mut collection: Collection = Collection::new(Default::default());
|
||||
for (h, f) in ref_folders.iter() {
|
||||
if !folder_confs.contains_key(&h) {
|
||||
if !f.is_subscribed() {
|
||||
/* Skip unsubscribed folder */
|
||||
folders.insert(*h, MailboxEntry::None);
|
||||
workers.insert(*h, None);
|
||||
continue;
|
||||
}
|
||||
folders.insert(
|
||||
|
|
Loading…
Reference in New Issue