use crate::core::auth0::UserDetails;
use super::{
command::Command,
connection_new::Connection,
input::{PostLocationData, SubscribeChannel, TalkMessage},
ConnId,
};
impl Connection {
pub fn fire_servertime(&self, msg: String) {
self.cmd_tx
.send(Command::Servertime { msg })
.unwrap_or_else(|e| {
log::error!("error={:?}", e);
});
}
pub fn fire_message(&self, conn: ConnId, msg: impl Into<String>) {
self.cmd_tx
.send(Command::Message {
msg: msg.into(),
conn,
})
.unwrap_or_else(|e| {
log::error!("error={:?}", e);
});
}
pub fn fire_autorization_message(&self, id: Option<String>, conn: ConnId, token: String) {
self.cmd_tx
.send(Command::Autorization { id, conn, token })
.unwrap_or_else(|e| {
log::error!("error={:?}", e);
});
}
pub fn fire_subscribe(&self, conn: ConnId, id: Option<String>, channel: SubscribeChannel) {
self.cmd_tx
.send(Command::Subscribe { id, conn, channel })
.unwrap_or_else(|e| {
log::error!("error={:?}", e);
});
}
pub fn fire_unsubscribe(&self, conn: ConnId, id: Option<String>, channel: SubscribeChannel) {
self.cmd_tx
.send(Command::Unsubscribe { id, conn, channel })
.unwrap_or_else(|e| {
log::error!("error={:?}", e);
});
}
pub fn fire_talk_message(
&self,
conn: ConnId,
curr_user: &UserDetails,
id: Option<String>,
msg: TalkMessage,
) {
if msg.msg.trim().is_empty() {
return;
}
self.cmd_tx
.send(Command::TalkMsg {
id,
conn,
curr_user: (
curr_user.user_id.to_owned(),
curr_user.user_name.to_owned(),
curr_user.user_role.to_owned(),
),
msg,
})
.unwrap_or_else(|e| {
log::error!("error={:?}", e);
});
}
pub fn fire_history_message(&self, id: Option<String>, conn: ConnId, to: String) {
self.cmd_tx
.send(Command::HistoryMsg { id, conn, to })
.unwrap_or_else(|e| {
log::error!("error={:?}", e);
});
}
pub fn fire_history_talk(&self, id: Option<String>, conn: ConnId) {
self.cmd_tx
.send(Command::HistoryTalk { id, conn })
.unwrap_or_else(|e| {
log::error!("error={:?}", e);
});
}
pub fn fire_location_message(&self, conn: ConnId, id: Option<String>, msg: PostLocationData) {
self.cmd_tx
.send(Command::Location { id, conn, msg })
.unwrap_or_else(|e| {
log::error!("error={:?}", e);
});
}
}