Handle non-negotiated cap

This commit is contained in:
Mikhail 2024-05-30 20:12:50 +02:00
parent a3e41ad11d
commit ae0464b742
1 changed files with 36 additions and 27 deletions

View File

@ -27,8 +27,11 @@ use proto_irc::server::{AwayStatus, ServerMessage, ServerMessageBody};
use proto_irc::user::PrefixedNick;
use proto_irc::{Chan, Recipient, Tag};
use sasl::AuthBody;
mod cap;
use handler::Handler;
mod whois;
use crate::cap::Capabilities;
@ -861,35 +864,41 @@ async fn handle_incoming_message(
return Ok(HandleResult::Leave);
}
ClientMessage::ChatHistory { chan, limit } => {
let channel_name = match chan.clone() {
Chan::Global(chan) => chan,
Chan::Local(chan) => chan,
};
let room = core.get_room(&RoomId::try_from(channel_name.clone())?).await;
if let Some(room) = room {
let room_info = room.get_room_info().await;
let messages = user_handle.get_room_message_history(&room_info.id, limit).await?;
for message in messages {
let mut tags = vec![];
if user.enabled_capabilities.contains(Capabilities::ServerTime) {
let tag = Tag {
key: "time".into(),
value: Some(message.created_at.to_rfc3339_opts(SecondsFormat::Millis, true).into()),
};
tags.push(tag);
if user.enabled_capabilities.contains(Capabilities::ChatHistory) {
let channel_name = match chan.clone() {
Chan::Global(chan) => chan,
Chan::Local(chan) => chan,
};
let room = core.get_room(&RoomId::try_from(channel_name.clone())?).await;
if let Some(room) = room {
let room_info = room.get_room_info().await;
let messages = user_handle.get_room_message_history(&room_info.id, limit).await?;
for message in messages {
let mut tags = vec![];
if user.enabled_capabilities.contains(Capabilities::ServerTime) {
let tag = Tag {
key: "time".into(),
value: Some(message.created_at.to_rfc3339_opts(SecondsFormat::Millis, true).into()),
};
tags.push(tag);
}
ServerMessage {
tags,
sender: Some(message.author_name.into()),
body: ServerMessageBody::PrivateMessage {
target: Recipient::Chan(chan.clone()),
body: message.content.into(),
},
}
.write_async(writer)
.await?;
}
ServerMessage {
tags,
sender: Some(message.author_name.into()),
body: ServerMessageBody::PrivateMessage {
target: Recipient::Chan(chan.clone()),
body: message.content.into(),
},
}
.write_async(writer)
.await?;
writer.flush().await?;
} else {
log::warn!(
"Requested chat history for user {user:?} even though the capability was not negotiated"
);
}
writer.flush().await?;
}
}
cmd => {