Anki/rslib/src/sched/congrats.rs
2020-09-01 10:24:38 +10:00

38 lines
1.3 KiB
Rust

// Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
use crate::backend_proto as pb;
use crate::prelude::*;
pub(crate) struct CongratsInfo {
pub learn_count: u32,
pub next_learn_due: u32,
pub review_remaining: bool,
pub new_remaining: bool,
pub have_sched_buried: bool,
pub have_user_buried: bool,
}
impl Collection {
pub fn congrats_info(&mut self) -> Result<pb::CongratsInfoOut> {
let did = self.get_current_deck_id();
let deck = self.get_deck(did)?.ok_or(AnkiError::NotFound)?;
let today = self.timing_today()?.days_elapsed;
let info = self.storage.congrats_info(&deck, today)?;
let is_filtered_deck = deck.is_filtered();
let secs_until_next_learn = ((info.next_learn_due as i64)
- self.learn_ahead_secs() as i64
- TimestampSecs::now().0)
.max(0) as u32;
Ok(pb::CongratsInfoOut {
learn_remaining: info.learn_count,
review_remaining: info.review_remaining,
new_remaining: info.new_remaining,
have_sched_buried: info.have_sched_buried,
have_user_buried: info.have_user_buried,
is_filtered_deck,
secs_until_next_learn,
bridge_commands_supported: true,
})
}
}