+ Send message callback now implemented
+ channel switcher works as well, although it relies on /lc being ran prior to its invocation
This commit is contained in:
parent
9ad963f097
commit
6088b0836f
@ -65,12 +65,26 @@ impl Cache {
|
|||||||
|
|
||||||
impl Cache {
|
impl Cache {
|
||||||
pub async fn switch_channel(&mut self, id: u64) -> Command {
|
pub async fn switch_channel(&mut self, id: u64) -> Command {
|
||||||
if let Some(host) = self.active_server.as_ref() {
|
if let None = self.active_server {
|
||||||
Command::Failure(format!("Not implemented yet!"))
|
return Command::Failure("No active server set!".into())
|
||||||
|
}
|
||||||
|
// find the channel meta data
|
||||||
|
let mut msg = String::new();
|
||||||
|
for (_url, cache) in &self.servers {
|
||||||
|
if let Some(channel_cache) = cache.channels.get(&id) {
|
||||||
|
let meta = channel_cache.meta.clone();
|
||||||
|
msg = format!("Switched to channel: [{}]: {}", meta.id, meta.name);
|
||||||
|
self.active_text = Some(meta);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if msg.len() == 0 {
|
||||||
|
Command::Failure(format!("Channel not found in cache try /lc to refresh cache"))
|
||||||
} else {
|
} else {
|
||||||
Command::Failure(format!("No server selected yet"))
|
Command::Text(msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn switch_server(&mut self, host: &str) -> Command {
|
pub async fn switch_server(&mut self, host: &str) -> Command {
|
||||||
// TODO: implement some better fuzzy finding for better ergonomics
|
// TODO: implement some better fuzzy finding for better ergonomics
|
||||||
// Reallt though the ux is still pretty bad here
|
// Reallt though the ux is still pretty bad here
|
||||||
@ -111,13 +125,21 @@ impl Cache {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn send_message(&mut self, id: &str) -> Command {
|
pub async fn send_message(&self, msg: &str) -> Command {
|
||||||
if let Some(server) = self.active_server.as_ref() {
|
if let Some(channel) = &self.active_text {
|
||||||
Command::Failure(format!("Not implemented yet!"))
|
let config = self.active_server.as_ref().unwrap();
|
||||||
} else {
|
let chan = channel.id;
|
||||||
Command::Failure(format!("No active server+channel to send message to"))
|
let uid = config.user.id;
|
||||||
|
let jwt = config.user.jwt.as_ref().unwrap();
|
||||||
|
let url = config.server.url.as_str();
|
||||||
|
|
||||||
|
return match net::send_text(url, uid, jwt, chan).await {
|
||||||
|
Ok(_) => Command::Message(msg.into()),
|
||||||
|
Err(_) => Command::Failure("Couldn't send text message".into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Command::Text("yes".into())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn list_hosts(&self) -> Command {
|
pub fn list_hosts(&self) -> Command {
|
||||||
let mut hosts = String::from("Hosts: ");
|
let mut hosts = String::from("Hosts: ");
|
||||||
|
Loading…
Reference in New Issue
Block a user