more stuff
This commit is contained in:
parent
7a3ce9f819
commit
cfc02ba368
4 changed files with 58 additions and 4 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1 +1,2 @@
|
||||||
/target
|
/target
|
||||||
|
.vimrc
|
||||||
|
|
15
src/bayou.rs
15
src/bayou.rs
|
@ -62,18 +62,29 @@ impl<S: BayouState> Bayou<S> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Re-reads the state from persistent storage backend
|
||||||
pub async fn sync(&mut self) -> Result<()> {
|
pub async fn sync(&mut self) -> Result<()> {
|
||||||
// 1. List checkpoints
|
// 1. List checkpoints
|
||||||
// 2. Load last checkpoint
|
// 2. Load last checkpoint if different from currently used one
|
||||||
// 3. List all operations starting from checkpoint
|
// 3. List all operations starting from checkpoint
|
||||||
// 4. Check that first operation has same timestamp as checkpoint (if not zero)
|
// 4. Check that first operation has same timestamp as checkpoint (if not zero)
|
||||||
// 5. Apply all operations in order
|
// 5. Apply all operations in order
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn state(&self) -> &S {
|
/// Applies a new operation on the state. Once this function returns,
|
||||||
|
/// the option has been safely persisted to storage backend
|
||||||
|
pub async fn push(&mut self, op: S::Op) -> Result<()> {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn state(&self) -> &S {
|
||||||
|
if let Some(last) = self.history.last() {
|
||||||
|
last.2.as_ref().unwrap()
|
||||||
|
} else {
|
||||||
|
&self.checkpoint.1
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
|
|
|
@ -8,9 +8,9 @@ mod cryptoblob;
|
||||||
mod time;
|
mod time;
|
||||||
mod uidindex;
|
mod uidindex;
|
||||||
|
|
||||||
use bayou::Bayou;
|
use bayou::*;
|
||||||
use cryptoblob::Key;
|
use cryptoblob::Key;
|
||||||
use uidindex::{UidIndex, UidIndexOp};
|
use uidindex::*;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
|
@ -43,5 +43,10 @@ async fn do_stuff() -> Result<()> {
|
||||||
|
|
||||||
mail_index.sync().await?;
|
mail_index.sync().await?;
|
||||||
|
|
||||||
|
let add_mail_op = mail_index
|
||||||
|
.state()
|
||||||
|
.op_mail_add(MailUuid([0xFFu8; 24]), vec!["\\Unseen".into()]);
|
||||||
|
mail_index.push(add_mail_op).await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,30 @@ pub struct UidIndex {
|
||||||
pub enum UidIndexOp {
|
pub enum UidIndexOp {
|
||||||
MailAdd(MailUuid, ImapUid, Vec<String>),
|
MailAdd(MailUuid, ImapUid, Vec<String>),
|
||||||
MailDel(MailUuid),
|
MailDel(MailUuid),
|
||||||
|
FlagAdd(MailUuid, Vec<String>),
|
||||||
|
FlagDel(MailUuid, Vec<String>),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl UidIndex {
|
||||||
|
#[must_use]
|
||||||
|
pub fn op_mail_add(&self, uuid: MailUuid, flags: Vec<String>) -> UidIndexOp {
|
||||||
|
UidIndexOp::MailAdd(uuid, self.internalseq, flags)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
|
pub fn op_mail_del(&self, uuid: MailUuid) -> UidIndexOp {
|
||||||
|
UidIndexOp::MailDel(uuid)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
|
pub fn op_flag_add(&self, uuid: MailUuid, flags: Vec<String>) -> UidIndexOp {
|
||||||
|
UidIndexOp::FlagAdd(uuid, flags)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
|
pub fn op_flag_del(&self, uuid: MailUuid, flags: Vec<String>) -> UidIndexOp {
|
||||||
|
UidIndexOp::FlagDel(uuid, flags)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for UidIndex {
|
impl Default for UidIndex {
|
||||||
|
@ -74,6 +98,19 @@ impl BayouState for UidIndex {
|
||||||
}
|
}
|
||||||
new.internalseq += 1;
|
new.internalseq += 1;
|
||||||
}
|
}
|
||||||
|
UidIndexOp::FlagAdd(uuid, new_flags) => {
|
||||||
|
let mail_flags = new.mail_flags.entry(*uuid).or_insert(vec![]);
|
||||||
|
for flag in new_flags {
|
||||||
|
if !mail_flags.contains(flag) {
|
||||||
|
mail_flags.push(flag.to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
UidIndexOp::FlagDel(uuid, rm_flags) => {
|
||||||
|
if let Some(mail_flags) = new.mail_flags.get_mut(uuid) {
|
||||||
|
mail_flags.retain(|x| !rm_flags.contains(x));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
new
|
new
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue