Gracefully fall back when capability echo-message is not supported
This commit is contained in:
parent
9006f53e4d
commit
a90df6ef31
2 changed files with 30 additions and 7 deletions
|
@ -8,8 +8,8 @@ use tokio::{
|
|||
|
||||
pub async fn connect() -> Result<irc::client::Client> {
|
||||
let client = irc::client::Client::new("config.toml").await?;
|
||||
client.send_cap_req(&[
|
||||
Capability::AccountTag,
|
||||
// TODO Base this on a CAP LS
|
||||
for capability in [
|
||||
Capability::Batch,
|
||||
Capability::EchoMessage,
|
||||
Capability::ServerTime,
|
||||
|
@ -17,7 +17,9 @@ pub async fn connect() -> Result<irc::client::Client> {
|
|||
Capability::Custom("draft/chathistory"),
|
||||
Capability::Custom("draft/event-playback"),
|
||||
Capability::Custom("draft/multiline"),
|
||||
])?;
|
||||
] {
|
||||
_ = client.send_cap_req(&[capability]);
|
||||
}
|
||||
Ok(client)
|
||||
}
|
||||
|
||||
|
@ -33,13 +35,13 @@ pub async fn message_loop(
|
|||
select! {
|
||||
val = irc_stream.next() => {
|
||||
if let Some(message) = val.transpose()? {
|
||||
println!("[Rx] {} {:?}", message.to_string().trim(), message.tags);
|
||||
println!("[Rx] {}", message.to_string().trim());
|
||||
message_tx.send(message)?;
|
||||
}
|
||||
}
|
||||
val = input_rx.recv() => {
|
||||
let message = val.unwrap();
|
||||
println!("[Tx] {} {:?}", message.to_string().trim(), message.tags);
|
||||
println!("[Tx] {}", message.to_string().trim());
|
||||
client.send(message)?;
|
||||
}
|
||||
}
|
||||
|
|
25
src/main.rs
25
src/main.rs
|
@ -11,7 +11,7 @@ use iced::{
|
|||
widget::{column, container, mouse_area, row, text, text_input},
|
||||
Application, Background, Color, Element, Length, Settings,
|
||||
};
|
||||
use irc::proto::{message::Tag, Command as IrcCommand, Response};
|
||||
use irc::proto::{message::Tag, CapSubCommand, Capability, Command as IrcCommand, Response};
|
||||
use irc_message::MessageDetail;
|
||||
use message_log::MessageLog;
|
||||
use once_cell::sync::Lazy;
|
||||
|
@ -60,14 +60,30 @@ struct Cri {
|
|||
message_log: MessageLog,
|
||||
input_value: String,
|
||||
nickname: String,
|
||||
capabilities: Vec<String>,
|
||||
}
|
||||
|
||||
impl Cri {
|
||||
fn send_message(&mut self, input_value: &str) {
|
||||
if let Some(active_channel) = &self.message_log.active_channel {
|
||||
let active_channel = self.message_log.active_channel.clone();
|
||||
if let Some(active_channel) = &active_channel {
|
||||
let command = IrcCommand::PRIVMSG(active_channel.to_string(), input_value.to_string());
|
||||
let message: irc::proto::Message = command.into();
|
||||
self.input_tx.borrow().send(message.clone()).unwrap();
|
||||
|
||||
let echo_message = self
|
||||
.capabilities
|
||||
.contains(&Capability::EchoMessage.as_ref().to_string());
|
||||
if !echo_message {
|
||||
self.message_log.on_privmsg(
|
||||
&self.nickname,
|
||||
active_channel,
|
||||
&self.nickname,
|
||||
input_value,
|
||||
None,
|
||||
&Local::now(),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -155,6 +171,7 @@ impl Application for Cri {
|
|||
message_log: MessageLog::new(),
|
||||
input_value: String::new(),
|
||||
nickname: "cri".to_string(), // TODO take default value from config
|
||||
capabilities: Vec::new(),
|
||||
},
|
||||
iced::Command::none(),
|
||||
)
|
||||
|
@ -193,6 +210,10 @@ impl Application for Cri {
|
|||
let message_id = message_id.as_deref();
|
||||
|
||||
match &message.command {
|
||||
IrcCommand::CAP(_, CapSubCommand::ACK, capability, _) => {
|
||||
let capability = capability.as_ref().unwrap();
|
||||
self.capabilities.push(capability.clone());
|
||||
}
|
||||
IrcCommand::JOIN(chanlist, _, _) => {
|
||||
let already_joined = self.message_log.has_channel(chanlist);
|
||||
self.message_log.on_join(
|
||||
|
|
Loading…
Reference in a new issue