pub struct ChatStore { /* private fields */ }Expand description
In-memory store for established and pending secret chats.
When a path is set (see ChatStore::load), insert and remove flush all
established chats to that binary file. Pending exchanges are never persisted.
Implementations§
Source§impl ChatStore
impl ChatStore
Sourcepub fn load(path: PathBuf) -> Result<Self>
pub fn load(path: PathBuf) -> Result<Self>
Load the store from path, or start empty if the file doesn’t exist yet.
Fails with InvalidData if the file has the wrong magic or version, is
truncated, or does not match its checksum. Later changes are written back
to path.
Sourcepub fn try_save(&self) -> Result<()>
pub fn try_save(&self) -> Result<()>
Write all established chats to the configured path, atomically.
The data goes to a temporary file next to the target, is synced, and then renamed over it, so a crash never leaves a half-written store. Does nothing if no path is set.
Sourcepub fn save(&self)
pub fn save(&self)
Like ChatStore::try_save, but only logs a warning on failure.
Sourcepub fn insert(&mut self, state: SecretChatState) -> Result<(), E2eError>
pub fn insert(&mut self, state: SecretChatState) -> Result<(), E2eError>
Add an established chat; fails with ChatAlreadyExists if the id is taken.
Sourcepub fn get_mut(&mut self, id: i32) -> Result<&mut SecretChatState, E2eError>
pub fn get_mut(&mut self, id: i32) -> Result<&mut SecretChatState, E2eError>
Look up an established chat for modification.
Changes are not written to disk until ChatStore::save is called.
Sourcepub fn insert_pending(&mut self, state: TempChatState)
pub fn insert_pending(&mut self, state: TempChatState)
Remember the private exponent of an outgoing request until the peer accepts.
Sourcepub fn take_pending(&mut self, id: i32) -> Option<TempChatState>
pub fn take_pending(&mut self, id: i32) -> Option<TempChatState>
Take (and remove) the pending exchange for id, if any.