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