notedeck

One damus client to rule them all
git clone git://jb55.com/notedeck
Log | Files | Refs | README | LICENSE

state.rs (998B)


      1 use std::collections::HashMap;
      2 
      3 use crate::cache::ConversationId;
      4 use egui_virtual_list::VirtualList;
      5 use notedeck::NoteRef;
      6 
      7 /// Search state for the create conversation UI
      8 #[derive(Default)]
      9 pub struct CreateConvoState {
     10     pub query: String,
     11 }
     12 
     13 #[derive(Default)]
     14 pub struct ConversationStates {
     15     pub cache: HashMap<ConversationId, ConversationState>,
     16     pub convos_list: VirtualList,
     17     pub create_convo: CreateConvoState,
     18 }
     19 
     20 impl ConversationStates {
     21     pub fn new() -> Self {
     22         let mut convos_list = VirtualList::new();
     23         convos_list.hide_on_resize(None);
     24         Self {
     25             cache: Default::default(),
     26             convos_list,
     27             create_convo: Default::default(),
     28         }
     29     }
     30     pub fn get_or_insert(&mut self, id: ConversationId) -> &mut ConversationState {
     31         self.cache.entry(id).or_default()
     32     }
     33 }
     34 
     35 #[derive(Default)]
     36 pub struct ConversationState {
     37     pub list: VirtualList,
     38     pub last_read: Option<NoteRef>,
     39     pub composer: String,
     40 }