initial postbox for testing

not sure if we want to put this here yet, but it matches the design
and will be useful for testing

Fixes: https://github.com/damus-io/notedeck/issues/110
Suggested-by: Rob
This commit is contained in:
William Casarin
2024-06-25 13:16:13 -05:00
parent a6856867a9
commit 26c4d90be3
4 changed files with 97 additions and 58 deletions

View File

@@ -1,8 +1,30 @@
use std::collections::HashMap;
#[derive(Default)]
pub struct Draft {
pub buffer: String,
}
#[derive(Default)]
pub struct Drafts {
pub replies: HashMap<[u8; 32], Draft>,
pub compose: Draft,
}
pub enum DraftSource<'a> {
Compose,
Reply(&'a [u8; 32]), // note id
}
impl<'a> DraftSource<'a> {
pub fn draft(&self, drafts: &'a mut Drafts) -> &'a mut Draft {
match self {
DraftSource::Compose => &mut drafts.compose,
DraftSource::Reply(id) => drafts.replies.entry(**id).or_default(),
}
}
}
impl Draft {
pub fn new() -> Self {
Draft::default()