freechat/tui/src/cache.rs
shockrah cb5975f235 FULL REWORK AND PORT TO TERMION
This patch is simply meant to mark the beginning of the newest phase for the tui build.
I've 100% settled on using termion as the backend and marking what is done so far

Renderer side:
	Termion has a similar issue where moving data happens very quietly so its best
	if the two (renderer and cache) have the their data to use as they please

Cache Side:
	Basically we own the data we're using because we constantly have to mutate data
	ourselves

Config in the middle:
	Mutable but only from the rendering side because the cache is completely transient
	It technically to own its data but it does anyway because the render(backend)
	 likes to consume data like there's no tomorrow
2021-03-17 20:39:42 -07:00

59 lines
1.4 KiB
Rust

/**
* welcum to the cache zone
* Notes about data model here
* Basically none of the ever gets written to disk so its mutability is
*
* Memory Model things
* The cache should always own its own data and nothing else
* On calls where the cache system needs to take data it should actually
* make its own copy to not disturb the render side of things as it too requires
* ownership of its own data. For this reason all parts of this are basically
* going to be really selfish about its own data
*
*/
use crate::config::{ ServerMeta, UserConfig };
use crate::api_types::{Channel, Message};
use crate::command::Command;
use std::collections::HashMap;
struct ChannelCache {
meta: Channel,
messages: Vec<Message>
}
struct ServerCache {
meta: ServerMeta,
user: UserConfig,
channels: Vec<ChannelCache>
}
pub struct Cache {
// Hostname -> Cache
servers: HashMap<String, ServerCache>,
active_server: Option<String>
}
impl Default for Cache {
fn default() -> Cache {
Cache {
servers: HashMap::new(),
active_server: None
}
}
}
impl Cache {
pub async fn switch_channel(&mut self, id: u64) -> Command {
todo!()
}
pub async fn switch_server(&mut self, host: &str) -> Command {
todo!()
}
pub async fn send_message(&mut self, id: &str) -> Command {
todo!()
}
}