state.rs (874B)
1 use std::collections::HashMap; 2 3 use crate::cache::ConversationId; 4 use egui_virtual_list::VirtualList; 5 use notedeck::NoteRef; 6 7 /// Keep track of the UI state for conversations. Meant to be mutably accessed by UI 8 #[derive(Default)] 9 pub struct ConversationStates { 10 pub cache: HashMap<ConversationId, ConversationState>, 11 pub convos_list: VirtualList, 12 } 13 14 impl ConversationStates { 15 pub fn new() -> Self { 16 let mut convos_list = VirtualList::new(); 17 convos_list.hide_on_resize(None); 18 Self { 19 cache: Default::default(), 20 convos_list, 21 } 22 } 23 pub fn get_or_insert(&mut self, id: ConversationId) -> &mut ConversationState { 24 self.cache.entry(id).or_default() 25 } 26 } 27 28 #[derive(Default)] 29 pub struct ConversationState { 30 pub list: VirtualList, 31 pub last_read: Option<NoteRef>, 32 pub composer: String, 33 }