mirror of
https://github.com/ankitects/anki.git
synced 2025-11-06 12:47:11 -05:00
Support include_filtered=false, skip_default=true case
This commit is contained in:
parent
cc776bb0ca
commit
c112236dd9
3 changed files with 17 additions and 6 deletions
|
|
@ -102,11 +102,21 @@ impl Deck {
|
|||
}
|
||||
|
||||
impl Collection {
|
||||
pub fn get_all_normal_deck_names(&mut self) -> Result<Vec<(DeckId, String)>> {
|
||||
pub fn get_all_normal_deck_names(
|
||||
&mut self,
|
||||
skip_default: bool,
|
||||
) -> Result<Vec<(DeckId, String)>> {
|
||||
Ok(self
|
||||
.storage
|
||||
.get_all_deck_names()?
|
||||
.into_iter()
|
||||
.filter(|node| {
|
||||
if skip_default {
|
||||
node.0 != DeckId(1)
|
||||
} else {
|
||||
true
|
||||
}
|
||||
})
|
||||
.filter(|(id, _name)| match self.get_deck(*id) {
|
||||
Ok(Some(deck)) => !deck.is_filtered(),
|
||||
_ => true,
|
||||
|
|
@ -154,8 +164,8 @@ impl Collection {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn get_all_deck_names(&self, skip_empty_default: bool) -> Result<Vec<(DeckId, String)>> {
|
||||
if skip_empty_default && self.default_deck_is_empty()? {
|
||||
pub fn get_all_deck_names(&self, skip_default: bool) -> Result<Vec<(DeckId, String)>> {
|
||||
if skip_default {
|
||||
Ok(self
|
||||
.storage
|
||||
.get_all_deck_names()?
|
||||
|
|
|
|||
|
|
@ -135,10 +135,11 @@ impl crate::services::DecksService for Collection {
|
|||
&mut self,
|
||||
input: anki_proto::decks::GetDeckNamesRequest,
|
||||
) -> error::Result<anki_proto::decks::DeckNames> {
|
||||
let skip_default = input.skip_empty_default && self.default_deck_is_empty()?;
|
||||
let names = if input.include_filtered {
|
||||
self.get_all_deck_names(input.skip_empty_default)?
|
||||
self.get_all_deck_names(skip_default)?
|
||||
} else {
|
||||
self.get_all_normal_deck_names()?
|
||||
self.get_all_normal_deck_names(skip_default)?
|
||||
};
|
||||
Ok(deck_names_to_proto(names))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -146,7 +146,7 @@ impl Duplicate {
|
|||
impl DeckIdsByNameOrId {
|
||||
fn new(col: &mut Collection, default: &NameOrId) -> Result<Self> {
|
||||
let names: HashMap<String, DeckId> = col
|
||||
.get_all_normal_deck_names()?
|
||||
.get_all_normal_deck_names(false)?
|
||||
.into_iter()
|
||||
.map(|(id, name)| (name, id))
|
||||
.collect();
|
||||
|
|
|
|||
Loading…
Reference in a new issue